objc2_virtualization/generated/VZVirtualMachine.rs
1//! This file has been automatically generated by `objc2`'s `header-translator`.
2//! DO NOT EDIT
3use core::ffi::*;
4use core::ptr::NonNull;
5#[cfg(feature = "dispatch2")]
6use dispatch2::*;
7use objc2::__framework_prelude::*;
8use objc2_foundation::*;
9
10use crate::*;
11
12/// Execution state of the virtual machine.
13///
14/// See also [Apple's documentation](https://developer.apple.com/documentation/virtualization/vzvirtualmachinestate?language=objc)
15// NS_ENUM
16#[repr(transparent)]
17#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
18pub struct VZVirtualMachineState(pub NSInteger);
19impl VZVirtualMachineState {
20 /// Initial state before the virtual machine is started.
21 #[doc(alias = "VZVirtualMachineStateStopped")]
22 pub const Stopped: Self = Self(0);
23 /// Running virtual machine.
24 #[doc(alias = "VZVirtualMachineStateRunning")]
25 pub const Running: Self = Self(1);
26 /// A started virtual machine is paused. This state can only be transitioned from VZVirtualMachineStatePausing.
27 #[doc(alias = "VZVirtualMachineStatePaused")]
28 pub const Paused: Self = Self(2);
29 /// The virtual machine has encountered an internal error.
30 #[doc(alias = "VZVirtualMachineStateError")]
31 pub const Error: Self = Self(3);
32 /// The virtual machine is configuring the hardware and starting.
33 #[doc(alias = "VZVirtualMachineStateStarting")]
34 pub const Starting: Self = Self(4);
35 /// The virtual machine is being paused. This is the intermediate state between VZVirtualMachineStateRunning and VZVirtualMachineStatePaused.
36 #[doc(alias = "VZVirtualMachineStatePausing")]
37 pub const Pausing: Self = Self(5);
38 /// The virtual machine is being resumed. This is the intermediate state between VZVirtualMachineStatePaused and VZVirtualMachineStateRunning.
39 #[doc(alias = "VZVirtualMachineStateResuming")]
40 pub const Resuming: Self = Self(6);
41 /// The virtual machine is being stopped. This is the intermediate state between VZVirtualMachineStateRunning and VZVirtualMachineStateStop.
42 #[doc(alias = "VZVirtualMachineStateStopping")]
43 pub const Stopping: Self = Self(7);
44 /// The virtual machine is being saved. This is the intermediate state between VZVirtualMachineStatePaused and VZVirtualMachineStatePaused.
45 #[doc(alias = "VZVirtualMachineStateSaving")]
46 pub const Saving: Self = Self(8);
47 /// The virtual machine is being restored. This is the intermediate state between VZVirtualMachineStateStopped and either VZVirtualMachineStatePaused on success or VZVirtualMachineStateStopped on failure.
48 #[doc(alias = "VZVirtualMachineStateRestoring")]
49 pub const Restoring: Self = Self(9);
50}
51
52unsafe impl Encode for VZVirtualMachineState {
53 const ENCODING: Encoding = NSInteger::ENCODING;
54}
55
56unsafe impl RefEncode for VZVirtualMachineState {
57 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
58}
59
60extern_class!(
61 /// VZVirtualMachine represents the entire state of a single virtual machine.
62 ///
63 /// A Virtual Machine is the emulation of a complete hardware machine of the same architecture as the real hardware machine.
64 /// When executing the Virtual Machine, the Virtualization framework uses certain hardware resources and emulates others to provide isolation
65 /// and great performance.
66 ///
67 /// The definition of a virtual machine starts with its configuration. This is done by setting up a VZVirtualMachineConfiguration object.
68 /// Once configured, the virtual machine can be started with [VZVirtualMachine startWithCompletionHandler:].
69 ///
70 /// To install macOS on a virtual machine, configure a new virtual machine with a suitable VZMacPlatformConfiguration, then use a VZMacOSInstaller
71 /// to install the restore image on it.
72 ///
73 /// Creating a virtual machine using the Virtualization framework requires the app to have the "com.apple.security.virtualization" entitlement.
74 ///
75 /// See also: VZVirtualMachineConfiguration
76 ///
77 /// See also: VZMacOSInstaller
78 ///
79 /// See also [Apple's documentation](https://developer.apple.com/documentation/virtualization/vzvirtualmachine?language=objc)
80 #[unsafe(super(NSObject))]
81 #[derive(Debug, PartialEq, Eq, Hash)]
82 pub struct VZVirtualMachine;
83);
84
85extern_conformance!(
86 unsafe impl NSObjectProtocol for VZVirtualMachine {}
87);
88
89impl VZVirtualMachine {
90 extern_methods!(
91 #[unsafe(method(new))]
92 #[unsafe(method_family = new)]
93 pub unsafe fn new() -> Retained<Self>;
94
95 #[unsafe(method(init))]
96 #[unsafe(method_family = init)]
97 pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
98
99 #[cfg(feature = "VZVirtualMachineConfiguration")]
100 /// Initialize the virtual machine.
101 ///
102 /// This initializer uses the main queue to operate the virtual machine. Every call must be done on the main queue and the callbacks are invoked
103 /// on the main queue.
104 ///
105 /// Parameter `configuration`: The configuration of the virtual machine.
106 /// The configuration must be valid. Validation can be performed at runtime with [VZVirtualMachineConfiguration validateWithError:].
107 /// The configuration is copied by the initializer.
108 #[unsafe(method(initWithConfiguration:))]
109 #[unsafe(method_family = init)]
110 pub unsafe fn initWithConfiguration(
111 this: Allocated<Self>,
112 configuration: &VZVirtualMachineConfiguration,
113 ) -> Retained<Self>;
114
115 #[cfg(all(feature = "VZVirtualMachineConfiguration", feature = "dispatch2"))]
116 /// Initialize the virtual machine.
117 ///
118 /// Parameter `configuration`: The configuration of the virtual machine.
119 /// The configuration must be valid. Validation can be performed at runtime with [VZVirtualMachineConfiguration validateWithError:].
120 /// The configuration is copied by the initializer.
121 ///
122 /// Parameter `queue`: The serial queue on which the virtual machine operates.
123 /// Every operation on the virtual machine must be done on that queue. The callbacks and delegate methods are invoked on that queue.
124 /// If the queue is not serial, the behavior is undefined.
125 ///
126 /// # Safety
127 ///
128 /// `queue` possibly has additional threading requirements.
129 #[unsafe(method(initWithConfiguration:queue:))]
130 #[unsafe(method_family = init)]
131 pub unsafe fn initWithConfiguration_queue(
132 this: Allocated<Self>,
133 configuration: &VZVirtualMachineConfiguration,
134 queue: &DispatchQueue,
135 ) -> Retained<Self>;
136
137 #[cfg(feature = "dispatch2")]
138 /// The queue associated with this virtual machine.
139 ///
140 /// This property is a reference to the queue used to create the virtual machine.
141 /// If no queue was passed, the default queue is the main queue.
142 ///
143 /// The property can be accessed from any queue or actor.
144 ///
145 /// Other properties or function calls on the VZVirtualMachine must happen on this queue.
146 /// The completion handlers from the asynchronous functions are also invoked on this queue.
147 #[unsafe(method(queue))]
148 #[unsafe(method_family = none)]
149 pub unsafe fn queue(&self) -> Retained<DispatchQueue>;
150
151 /// Indicate whether or not virtualization is available.
152 ///
153 /// If virtualization is unavailable, no VZVirtualMachineConfiguration will validate.
154 /// The validation error of the VZVirtualMachineConfiguration provides more information about why virtualization is unavailable.
155 #[unsafe(method(isSupported))]
156 #[unsafe(method_family = none)]
157 pub unsafe fn isSupported() -> bool;
158
159 /// Execution state of the virtual machine.
160 #[unsafe(method(state))]
161 #[unsafe(method_family = none)]
162 pub unsafe fn state(&self) -> VZVirtualMachineState;
163
164 #[cfg(feature = "VZVirtualMachineDelegate")]
165 /// The virtual machine delegate.
166 #[unsafe(method(delegate))]
167 #[unsafe(method_family = none)]
168 pub unsafe fn delegate(
169 &self,
170 ) -> Option<Retained<ProtocolObject<dyn VZVirtualMachineDelegate>>>;
171
172 #[cfg(feature = "VZVirtualMachineDelegate")]
173 /// Setter for [`delegate`][Self::delegate].
174 ///
175 /// This is a [weak property][objc2::topics::weak_property].
176 #[unsafe(method(setDelegate:))]
177 #[unsafe(method_family = none)]
178 pub unsafe fn setDelegate(
179 &self,
180 delegate: Option<&ProtocolObject<dyn VZVirtualMachineDelegate>>,
181 );
182
183 /// Return YES if the machine is in a state that can be started.
184 ///
185 /// See: -[VZVirtualMachine startWithCompletionHandler:].
186 ///
187 /// See: -[VZVirtualMachine state]
188 #[unsafe(method(canStart))]
189 #[unsafe(method_family = none)]
190 pub unsafe fn canStart(&self) -> bool;
191
192 /// Return YES if the machine is in a state that can be stopped.
193 ///
194 /// See: -[VZVirtualMachine stopWithCompletionHandler:]
195 ///
196 /// See: -[VZVirtualMachine state]
197 #[unsafe(method(canStop))]
198 #[unsafe(method_family = none)]
199 pub unsafe fn canStop(&self) -> bool;
200
201 /// Return YES if the machine is in a state that can be paused.
202 ///
203 /// See: -[VZVirtualMachine pauseWithCompletionHandler:]
204 ///
205 /// See: -[VZVirtualMachine state]
206 #[unsafe(method(canPause))]
207 #[unsafe(method_family = none)]
208 pub unsafe fn canPause(&self) -> bool;
209
210 /// Return YES if the machine is in a state that can be resumed.
211 ///
212 /// See: -[VZVirtualMachine resumeWithCompletionHandler:]
213 ///
214 /// See: -[VZVirtualMachine state]
215 #[unsafe(method(canResume))]
216 #[unsafe(method_family = none)]
217 pub unsafe fn canResume(&self) -> bool;
218
219 /// Returns whether the machine is in a state where the guest can be asked to stop.
220 ///
221 /// See: -[VZVirtualMachine requestStopWithError:]
222 ///
223 /// See: -[VZVirtualMachine state]
224 #[unsafe(method(canRequestStop))]
225 #[unsafe(method_family = none)]
226 pub unsafe fn canRequestStop(&self) -> bool;
227
228 #[cfg(feature = "VZConsoleDevice")]
229 /// Return the list of console devices configured on this virtual machine. Return an empty array if no console device is configured.
230 ///
231 /// See: VZVirtioConsoleDeviceConfiguration
232 ///
233 /// See: VZVirtualMachineConfiguration
234 #[unsafe(method(consoleDevices))]
235 #[unsafe(method_family = none)]
236 pub unsafe fn consoleDevices(&self) -> Retained<NSArray<VZConsoleDevice>>;
237
238 #[cfg(feature = "VZDirectorySharingDevice")]
239 /// Return the list of directory sharing devices configured on this virtual machine. Return an empty array if no directory sharing device is configured.
240 ///
241 /// See: VZVirtioFileSystemDeviceConfiguration
242 ///
243 /// See: VZVirtualMachineConfiguration
244 #[unsafe(method(directorySharingDevices))]
245 #[unsafe(method_family = none)]
246 pub unsafe fn directorySharingDevices(&self)
247 -> Retained<NSArray<VZDirectorySharingDevice>>;
248
249 #[cfg(feature = "VZGraphicsDevice")]
250 /// Return the list of graphics devices configured on this virtual machine. Return an empty array if no graphics device is configured.
251 ///
252 /// See: VZGraphicsDeviceConfiguration
253 ///
254 /// See: VZVirtualMachineConfiguration
255 #[unsafe(method(graphicsDevices))]
256 #[unsafe(method_family = none)]
257 pub unsafe fn graphicsDevices(&self) -> Retained<NSArray<VZGraphicsDevice>>;
258
259 #[cfg(feature = "VZMemoryBalloonDevice")]
260 /// Return the list of memory balloon devices configured on this virtual machine. Return an empty array if no memory balloon device is configured.
261 ///
262 /// See: VZVirtioTraditionalMemoryBalloonDeviceConfiguration
263 ///
264 /// See: VZVirtualMachineConfiguration
265 #[unsafe(method(memoryBalloonDevices))]
266 #[unsafe(method_family = none)]
267 pub unsafe fn memoryBalloonDevices(&self) -> Retained<NSArray<VZMemoryBalloonDevice>>;
268
269 #[cfg(feature = "VZNetworkDevice")]
270 /// Return the list of network devices configured on this virtual machine. Return an empty array if no network device is configured.
271 ///
272 /// See: VZVirtioNetworkDeviceConfiguration
273 ///
274 /// See: VZVirtualMachineConfiguration
275 #[unsafe(method(networkDevices))]
276 #[unsafe(method_family = none)]
277 pub unsafe fn networkDevices(&self) -> Retained<NSArray<VZNetworkDevice>>;
278
279 #[cfg(feature = "VZSocketDevice")]
280 /// Return the list of socket devices configured on this virtual machine. Return an empty array if no socket device is configured.
281 ///
282 /// See: VZVirtioSocketDeviceConfiguration
283 ///
284 /// See: VZVirtualMachineConfiguration
285 #[unsafe(method(socketDevices))]
286 #[unsafe(method_family = none)]
287 pub unsafe fn socketDevices(&self) -> Retained<NSArray<VZSocketDevice>>;
288
289 #[cfg(feature = "VZUSBController")]
290 /// Return the list of USB controllers configured on this virtual machine. Return an empty array if no USB controller is configured.
291 ///
292 /// See: VZUSBControllerConfiguration
293 ///
294 /// See: VZVirtualMachineConfiguration
295 #[unsafe(method(usbControllers))]
296 #[unsafe(method_family = none)]
297 pub unsafe fn usbControllers(&self) -> Retained<NSArray<VZUSBController>>;
298
299 #[cfg(feature = "block2")]
300 /// Start a virtual machine.
301 ///
302 /// Start a virtual machine that is in either Stopped or Error state.
303 ///
304 /// Parameter `completionHandler`: Block called after the virtual machine has been successfully started or on error.
305 /// The error parameter passed to the block is nil if the start was successful.
306 #[unsafe(method(startWithCompletionHandler:))]
307 #[unsafe(method_family = none)]
308 pub unsafe fn startWithCompletionHandler(
309 &self,
310 completion_handler: &block2::DynBlock<dyn Fn(*mut NSError)>,
311 );
312
313 #[cfg(all(feature = "VZVirtualMachineStartOptions", feature = "block2"))]
314 /// Start a virtual machine with options.
315 ///
316 /// Start a virtual machine that is in either Stopped or Error state.
317 ///
318 /// Parameter `options`: Options used to control how the virtual machine is started.
319 ///
320 /// Parameter `completionHandler`: Block called after the virtual machine has been successfully started or on error.
321 /// The error parameter passed to the block is nil if the start was successful.
322 ///
323 /// See also: VZMacOSVirtualMachineStartOptions
324 #[unsafe(method(startWithOptions:completionHandler:))]
325 #[unsafe(method_family = none)]
326 pub unsafe fn startWithOptions_completionHandler(
327 &self,
328 options: &VZVirtualMachineStartOptions,
329 completion_handler: &block2::DynBlock<dyn Fn(*mut NSError)>,
330 );
331
332 #[cfg(feature = "block2")]
333 /// Stop a virtual machine.
334 ///
335 /// Stop a virtual machine that is in either Running or Paused state.
336 ///
337 /// Parameter `completionHandler`: Block called after the virtual machine has been successfully stopped or on error.
338 /// The error parameter passed to the block is nil if the stop was successful.
339 ///
340 /// This is a destructive operation. It stops the virtual machine without giving the guest a chance to stop cleanly.
341 ///
342 /// See also: -[VZVirtualMachine requestStopWithError:]
343 #[unsafe(method(stopWithCompletionHandler:))]
344 #[unsafe(method_family = none)]
345 pub unsafe fn stopWithCompletionHandler(
346 &self,
347 completion_handler: &block2::DynBlock<dyn Fn(*mut NSError)>,
348 );
349
350 #[cfg(feature = "block2")]
351 /// Pause a virtual machine.
352 ///
353 /// Pause a virtual machine that is in Running state.
354 ///
355 /// Parameter `completionHandler`: Block called after the virtual machine has been successfully paused or on error.
356 /// The error parameter passed to the block is nil if the pause was successful.
357 #[unsafe(method(pauseWithCompletionHandler:))]
358 #[unsafe(method_family = none)]
359 pub unsafe fn pauseWithCompletionHandler(
360 &self,
361 completion_handler: &block2::DynBlock<dyn Fn(*mut NSError)>,
362 );
363
364 #[cfg(feature = "block2")]
365 /// Resume a virtual machine.
366 ///
367 /// Resume a virtual machine that is in the Paused state.
368 ///
369 /// Parameter `completionHandler`: Block called after the virtual machine has been successfully resumed or on error.
370 /// The error parameter passed to the block is nil if the resumption was successful.
371 #[unsafe(method(resumeWithCompletionHandler:))]
372 #[unsafe(method_family = none)]
373 pub unsafe fn resumeWithCompletionHandler(
374 &self,
375 completion_handler: &block2::DynBlock<dyn Fn(*mut NSError)>,
376 );
377
378 #[cfg(feature = "block2")]
379 /// Restore a virtual machine.
380 ///
381 /// Restore a stopped virtual machine to a state previously saved to file through `saveMachineStateToURL:completionHandler:`.
382 ///
383 /// If the file cannot be read, or contains otherwise invalid contents, this operation will fail with a `VZErrorRestore` error.
384 /// If the virtual machine is not in the stopped state, this operation will fail with a `VZErrorInvalidVirtualMachineStateTransition` error.
385 /// If the virtual machine cannot be started due to an internal error, this operation will fail with a `VZErrorInternal` error.
386 /// The `VZVirtualMachineConfiguration` must also support restoring, which can be checked with `-[VZVirtualMachineConfiguration validateSaveRestoreSupportWithError:]`.
387 ///
388 /// If this operation fails, the virtual machine state is unchanged.
389 /// If successful, the virtual machine is restored and placed in the paused state.
390 ///
391 /// Parameter `saveFileURL`: URL to file containing saved state of a suspended virtual machine.
392 /// The file must have been generated by `saveMachineStateToURL:completionHandler:` on the same host.
393 /// Otherwise, this operation will fail with a `VZErrorRestore` error indicating a permission denied failure reason.
394 ///
395 /// The virtual machine must also be configured compatibly with the state contained in the file.
396 /// If the `VZVirtualMachineConfiguration` is not compatible with the content of the file, this operation will fail with a `VZErrorRestore` error indicating an invalid argument failure reason.
397 ///
398 /// Files generated with `saveMachineStateToURL:completionHandler:` on a software version that is newer than the current version will also be rejected with an invalid argument failure reason.
399 /// In some cases, `restoreMachineStateFromURL:completionHandler:` can fail if a software update has changed the host in a way that would be incompatible with the previous format.
400 /// In this case, an invalid argument error will be surfaced. In most cases, the virtual machine should be restarted with `startWithCompletionHandler:`.
401 ///
402 /// Parameter `completionHandler`: Block called after the virtual machine has been successfully started or on error.
403 /// The error parameter passed to the block is nil if the restore was successful.
404 ///
405 /// See: -[VZVirtualMachineConfiguration validateSaveRestoreSupportWithError:]
406 #[unsafe(method(restoreMachineStateFromURL:completionHandler:))]
407 #[unsafe(method_family = none)]
408 pub unsafe fn restoreMachineStateFromURL_completionHandler(
409 &self,
410 save_file_url: &NSURL,
411 completion_handler: &block2::DynBlock<dyn Fn(*mut NSError)>,
412 );
413
414 #[cfg(feature = "block2")]
415 /// Save a virtual machine.
416 ///
417 /// Save a paused virtual machine to file.
418 /// The contents of this file can be used later to restore the state of the paused virtual machine.
419 ///
420 /// If the virtual machine is not paused, this operation will fail with a `VZErrorInvalidVirtualMachineState` error.
421 /// If the virtual machine cannot be saved, this operation will fail with a `VZErrorSave` error.
422 /// The `VZVirtualMachineConfiguration` must also support saving, which can be checked with `-[VZVirtualMachineConfiguration validateSaveRestoreSupportWithError:]`.
423 ///
424 /// If this operation fails, the virtual machine state is unchanged.
425 /// If successful, the file is written out and the virtual machine state is unchanged.
426 ///
427 /// Parameter `saveFileURL`: URL to location where the saved state of the virtual machine is to be written.
428 /// Each file is protected by an encryption key that is tied to the host on which it is created.
429 ///
430 /// Parameter `completionHandler`: Block called after the virtual machine has been successfully saved or on error.
431 /// The error parameter passed to the block is nil if the save was successful.
432 ///
433 /// See: -[VZVirtualMachineConfiguration validateSaveRestoreSupportWithError:]
434 #[unsafe(method(saveMachineStateToURL:completionHandler:))]
435 #[unsafe(method_family = none)]
436 pub unsafe fn saveMachineStateToURL_completionHandler(
437 &self,
438 save_file_url: &NSURL,
439 completion_handler: &block2::DynBlock<dyn Fn(*mut NSError)>,
440 );
441
442 /// Request that the guest turns itself off.
443 ///
444 /// Parameter `error`: If not nil, assigned with the error if the request failed.
445 ///
446 /// Returns: YES if the request was made successfully.
447 ///
448 /// The -[VZVirtualMachineDelegate guestDidStopVirtualMachine:] delegate method is invoked when the guest has turned itself off.
449 ///
450 /// See also: -[VZVirtualMachineDelegate guestDidStopVirtualMachine:].
451 #[unsafe(method(requestStopWithError:_))]
452 #[unsafe(method_family = none)]
453 pub unsafe fn requestStopWithError(&self) -> Result<(), Retained<NSError>>;
454 );
455}