1
1
//
2
2
// virtualization_15.m
3
3
//
4
+ // Created by codehex.
5
+ //
4
6
#import " virtualization_15.h"
5
7
6
8
/* !
@@ -57,3 +59,132 @@ void setUSBControllersVZVirtualMachineConfiguration(void *config, void *usbContr
57
59
#endif
58
60
RAISE_UNSUPPORTED_MACOS_EXCEPTION ();
59
61
}
62
+
63
+ /* !
64
+ @abstract Device UUID.
65
+ @discussion
66
+ Device UUID from device configuration objects that conform to `VZUSBDeviceConfiguration`.
67
+ @see VZUSBDeviceConfiguration
68
+ */
69
+ const char *getUUIDUSBDevice (void *usbDevice)
70
+ {
71
+ #ifdef INCLUDE_TARGET_OSX_15
72
+ if (@available (macOS 15 , *)) {
73
+ NSString *uuid = [[(id <VZUSBDevice>)usbDevice uuid ] UUIDString ];
74
+ return [uuid UTF8String ];
75
+ }
76
+ #endif
77
+ RAISE_UNSUPPORTED_MACOS_EXCEPTION ();
78
+ }
79
+
80
+ /* !
81
+ @abstract Return a list of USB devices attached to controller.
82
+ @discussion
83
+ If corresponding USB controller configuration included in VZVirtualMachineConfiguration contained any USB devices,
84
+ those devices will appear here when virtual machine is started.
85
+ @see VZUSBDevice
86
+ @see VZUSBDeviceConfiguration
87
+ @see VZUSBControllerConfiguration
88
+ @see VZVirtualMachineConfiguration
89
+ */
90
+ void *usbDevicesVZUSBController (void *usbController)
91
+ {
92
+ #ifdef INCLUDE_TARGET_OSX_15
93
+ if (@available (macOS 15 , *)) {
94
+ return [(VZUSBController *)usbController usbDevices ];
95
+ }
96
+ #endif
97
+ RAISE_UNSUPPORTED_MACOS_EXCEPTION ();
98
+ }
99
+
100
+ /* !
101
+ @abstract Return the list of USB controllers configured on this virtual machine. Return an empty array if no USB controller is configured.
102
+ @see VZUSBControllerConfiguration
103
+ @see VZVirtualMachineConfiguration
104
+ */
105
+ void *VZVirtualMachine_usbControllers (void *machine)
106
+ {
107
+ #ifdef INCLUDE_TARGET_OSX_15
108
+ if (@available (macOS 15 , *)) {
109
+ return [(VZVirtualMachine *)machine usbControllers ]; // NSArray<VZUSBController *>
110
+ }
111
+ #endif
112
+ RAISE_UNSUPPORTED_MACOS_EXCEPTION ();
113
+ }
114
+
115
+ /* !
116
+ @abstract Attach a USB device.
117
+ @discussion
118
+ If the device is successfully attached to the controller, it will appear in the usbDevices property,
119
+ its usbController property will be set to point to the USB controller that it is attached to
120
+ and completion handler will return nil.
121
+ If the device was previously attached to this or another USB controller, attach function will fail
122
+ with the `VZErrorDeviceAlreadyAttached`. If the device cannot be initialized correctly, attach
123
+ function will fail with `VZErrorDeviceInitializationFailure`.
124
+ This method must be called on the virtual machine's queue.
125
+ @param device USB device to attach.
126
+ @param completionHandler Block called after the device has been attached or on error.
127
+ The error parameter passed to the block is nil if the attach was successful.
128
+ It will be also invoked on an virtual machine's queue.
129
+ @see VZUSBDevice
130
+ */
131
+ void attachDeviceVZUSBController (void *usbController, void *usbDevice, void *queue, uintptr_t cgoHandle)
132
+ {
133
+ #ifdef INCLUDE_TARGET_OSX_15
134
+ if (@available (macOS 15 , *)) {
135
+ dispatch_sync ((dispatch_queue_t )queue, ^{
136
+ [(VZUSBController *)usbController attachDevice: (id <VZUSBDevice>)usbDevice
137
+ completionHandler: ^(NSError *error) {
138
+ usbAttachDetachCompletionHandler (cgoHandle, error);
139
+ }];
140
+ });
141
+ return ;
142
+ }
143
+ #endif
144
+ RAISE_UNSUPPORTED_MACOS_EXCEPTION ();
145
+ }
146
+
147
+ /* !
148
+ @abstract Detach a USB device.
149
+ @discussion
150
+ If the device is successfully detached from the controller, it will disappear from the usbDevices property,
151
+ its usbController property will be set to nil and completion handler will return nil.
152
+ If the device wasn't attached to the controller at the time of calling detach method, it will fail
153
+ with the `VZErrorDeviceNotFound` error.
154
+ This method must be called on the virtual machine's queue.
155
+ @param device USB device to detach.
156
+ @param completionHandler Block called after the device has been detached or on error.
157
+ The error parameter passed to the block is nil if the detach was successful.
158
+ It will be also invoked on an virtual machine's queue.
159
+ @see VZUSBDevice
160
+ */
161
+ void detachDeviceVZUSBController (void *usbController, void *usbDevice, void *queue, uintptr_t cgoHandle)
162
+ {
163
+ #ifdef INCLUDE_TARGET_OSX_15
164
+ if (@available (macOS 15 , *)) {
165
+ dispatch_sync ((dispatch_queue_t )queue, ^{
166
+ [(VZUSBController *)usbController detachDevice: (id <VZUSBDevice>)usbDevice
167
+ completionHandler: ^(NSError *error) {
168
+ usbAttachDetachCompletionHandler (cgoHandle, error);
169
+ }];
170
+ });
171
+ return ;
172
+ }
173
+ #endif
174
+ RAISE_UNSUPPORTED_MACOS_EXCEPTION ();
175
+ }
176
+
177
+ /* !
178
+ @abstract Initialize the runtime USB Mass Storage device object.
179
+ @param configuration The configuration of the USB Mass Storage device.
180
+ @see VZUSBMassStorageDeviceConfiguration
181
+ */
182
+ void *newVZUSBMassStorageDeviceWithConfiguration (void *config)
183
+ {
184
+ #ifdef INCLUDE_TARGET_OSX_15
185
+ if (@available (macOS 15 , *)) {
186
+ return [[VZUSBMassStorageDevice alloc ] initWithConfiguration: (VZUSBMassStorageDeviceConfiguration *)config];
187
+ }
188
+ #endif
189
+ RAISE_UNSUPPORTED_MACOS_EXCEPTION ();
190
+ }
0 commit comments