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