-
-
Notifications
You must be signed in to change notification settings - Fork 42
/
shared_folder.go
131 lines (106 loc) · 3.57 KB
/
shared_folder.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
package vz
/*
#cgo darwin CFLAGS: -x objective-c -fno-objc-arc
#cgo darwin LDFLAGS: -lobjc -framework Foundation -framework Virtualization
# include "virtualization.h"
*/
import "C"
import "runtime"
// DirectorySharingDeviceConfiguration for a directory sharing device configuration.
type DirectorySharingDeviceConfiguration interface {
NSObject
directorySharingDeviceConfiguration()
}
type baseDirectorySharingDeviceConfiguration struct{}
func (*baseDirectorySharingDeviceConfiguration) directorySharingDeviceConfiguration() {}
var _ DirectorySharingDeviceConfiguration = (*VirtioFileSystemDeviceConfiguration)(nil)
// VirtioFileSystemDeviceConfiguration is a configuration of a Virtio file system device.
//
// see: https://developer.apple.com/documentation/virtualization/vzvirtiofilesystemdeviceconfiguration?language=objc
type VirtioFileSystemDeviceConfiguration struct {
pointer
*baseDirectorySharingDeviceConfiguration
}
// NewVirtioFileSystemDeviceConfiguration create a new VirtioFileSystemDeviceConfiguration.
func NewVirtioFileSystemDeviceConfiguration(tag string) *VirtioFileSystemDeviceConfiguration {
tagChar := charWithGoString(tag)
defer tagChar.Free()
fsdConfig := &VirtioFileSystemDeviceConfiguration{
pointer: pointer{
ptr: C.newVZVirtioFileSystemDeviceConfiguration(tagChar.CString()),
},
}
runtime.SetFinalizer(fsdConfig, func(self *VirtioFileSystemDeviceConfiguration) {
self.Release()
})
return fsdConfig
}
// SetDirectoryShare sets the directory share associated with this configuration.
func (c *VirtioFileSystemDeviceConfiguration) SetDirectoryShare(share DirectoryShare) {
C.setVZVirtioFileSystemDeviceConfigurationShare(c.Ptr(), share.Ptr())
}
// SharedDirectory is a shared directory.
type SharedDirectory struct {
pointer
}
// NewSharedDirectory creates a new shared directory.
func NewSharedDirectory(dirPath string, readOnly bool) *SharedDirectory {
dirPathChar := charWithGoString(dirPath)
defer dirPathChar.Free()
sd := &SharedDirectory{
pointer: pointer{
ptr: C.newVZSharedDirectory(dirPathChar.CString(), C.bool(readOnly)),
},
}
runtime.SetFinalizer(sd, func(self *SharedDirectory) {
self.Release()
})
return sd
}
// DirectoryShare is the base interface for a directory share.
type DirectoryShare interface {
NSObject
directoryShare()
}
type baseDirectoryShare struct{}
func (*baseDirectoryShare) directoryShare() {}
var _ DirectoryShare = (*SingleDirectoryShare)(nil)
// SingleDirectoryShare defines the directory share for a single directory.
type SingleDirectoryShare struct {
pointer
*baseDirectoryShare
}
// NewSingleDirectoryShare creates a new single directory share.
func NewSingleDirectoryShare(share *SharedDirectory) *SingleDirectoryShare {
config := &SingleDirectoryShare{
pointer: pointer{
ptr: C.newVZSingleDirectoryShare(share.Ptr()),
},
}
runtime.SetFinalizer(config, func(self *SingleDirectoryShare) {
self.Release()
})
return config
}
// MultipleDirectoryShare defines the directory share for multiple directories.
type MultipleDirectoryShare struct {
pointer
*baseDirectoryShare
}
// NewMultipleDirectoryShare creates a new multiple directories share.
func NewMultipleDirectoryShare(shares map[string]*SharedDirectory) *MultipleDirectoryShare {
directories := make(map[string]NSObject, len(shares))
for k, v := range shares {
directories[k] = v
}
dict := convertToNSMutableDictionary(directories)
config := &MultipleDirectoryShare{
pointer: pointer{
ptr: C.newVZMultipleDirectoryShare(dict.Ptr()),
},
}
runtime.SetFinalizer(config, func(self *SingleDirectoryShare) {
self.Release()
})
return config
}