objc2-virtualization 0.3.2

Bindings to the Virtualization framework
Documentation
//! This file has been automatically generated by `objc2`'s `header-translator`.
//! DO NOT EDIT
use core::ptr::NonNull;
use objc2::__framework_prelude::*;
use objc2_foundation::*;

use crate::*;

/// Whether the host caches disk image data.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/virtualization/vzdiskimagecachingmode?language=objc)
// NS_ENUM
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct VZDiskImageCachingMode(pub NSInteger);
impl VZDiskImageCachingMode {
    #[doc(alias = "VZDiskImageCachingModeAutomatic")]
    pub const Automatic: Self = Self(0);
    #[doc(alias = "VZDiskImageCachingModeUncached")]
    pub const Uncached: Self = Self(1);
    #[doc(alias = "VZDiskImageCachingModeCached")]
    pub const Cached: Self = Self(2);
}

unsafe impl Encode for VZDiskImageCachingMode {
    const ENCODING: Encoding = NSInteger::ENCODING;
}

unsafe impl RefEncode for VZDiskImageCachingMode {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

/// [Apple's documentation](https://developer.apple.com/documentation/virtualization/vzdiskimagesynchronizationmode?language=objc)
// NS_ENUM
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct VZDiskImageSynchronizationMode(pub NSInteger);
impl VZDiskImageSynchronizationMode {
    /// The data is synchronized to the permanent storage holding the disk image.
    /// No synchronized data is lost on panic or loss of power.
    #[doc(alias = "VZDiskImageSynchronizationModeFull")]
    pub const Full: Self = Self(1);
    /// Synchronize the data to the drive.
    ///
    /// This mode synchronizes the data with the drive, but does not ensure the data is moved from the disk's internal cache
    /// to permanent storage.
    ///
    /// This is a best-effort mode with the same guarantees as the fsync() system call.
    #[doc(alias = "VZDiskImageSynchronizationModeFsync")]
    pub const Fsync: Self = Self(2);
    /// Do not synchronize the data with the permanent storage.
    /// This option does not guarantee data integrity if any error condition occurs such as disk full on the host,
    /// panic, power loss, etc.
    ///
    /// This mode is useful when a virtual machine is only run once to perform a task to completion or failure.
    /// In that case, the disk image cannot safely be reused on failure.
    ///
    /// Using this mode may result in improved performance since no synchronization with the underlying storage is necessary.
    #[doc(alias = "VZDiskImageSynchronizationModeNone")]
    pub const None: Self = Self(3);
}

unsafe impl Encode for VZDiskImageSynchronizationMode {
    const ENCODING: Encoding = NSInteger::ENCODING;
}

unsafe impl RefEncode for VZDiskImageSynchronizationMode {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

extern_class!(
    /// Storage device attachment using a disk image to implement the storage.
    ///
    /// This storage device attachment uses a disk image on the host file system as the drive of the storage device.
    ///
    /// Only RAW data disk images are supported.
    ///
    /// An empty RAW disk image can be created with `FileDescriptor.resize(to:retryOnInterrupt:)` method in Swift,
    /// the `ftruncate()` function in Swift or Objective-C, or the `truncate` command on the command line.
    /// The size of the file must be a multiple of 512 bytes, the block size.
    ///
    /// See: VZNVMExpressControllerDeviceConfiguration
    ///
    /// See: VZUSBMassStorageDeviceConfiguration
    ///
    /// See: VZVirtioBlockDeviceConfiguration
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/virtualization/vzdiskimagestoragedeviceattachment?language=objc)
    #[unsafe(super(VZStorageDeviceAttachment, NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    #[cfg(feature = "VZStorageDeviceAttachment")]
    pub struct VZDiskImageStorageDeviceAttachment;
);

#[cfg(feature = "VZStorageDeviceAttachment")]
extern_conformance!(
    unsafe impl NSObjectProtocol for VZDiskImageStorageDeviceAttachment {}
);

#[cfg(feature = "VZStorageDeviceAttachment")]
impl VZDiskImageStorageDeviceAttachment {
    extern_methods!(
        /// Initialize the attachment from a local file url.
        ///
        /// Parameter `url`: Local file URL to the disk image in RAW format.
        ///
        /// Parameter `readOnly`: If YES, the device attachment is read-only, otherwise the device can write data to the disk image.
        ///
        /// Parameter `error`: If not nil, assigned with the error if the initialization failed.
        ///
        /// Returns: A newly initialized VZDiskImageStorageDeviceAttachment. If an error was encountered returns
        /// `nil,`and
        /// `error`contains the error.
        #[unsafe(method(initWithURL:readOnly:error:_))]
        #[unsafe(method_family = init)]
        pub unsafe fn initWithURL_readOnly_error(
            this: Allocated<Self>,
            url: &NSURL,
            read_only: bool,
        ) -> Result<Retained<Self>, Retained<NSError>>;

        /// Initialize the attachment from a local file url.
        ///
        /// Parameter `url`: Local file URL to the disk image in RAW format.
        ///
        /// Parameter `readOnly`: If YES, the device attachment is read-only, otherwise the device can write data to the disk image.
        ///
        /// Parameter `cachingMode`: Whether host data caching is enabled for the disk image.
        ///
        /// Parameter `synchronizationMode`: How the disk image synchronizes with the underlying storage when the guest operating system flushes data.
        ///
        /// Parameter `error`: If not nil, assigned with the error if the initialization failed.
        ///
        /// Returns: A newly initialized VZDiskImageStorageDeviceAttachment. If an error was encountered returns
        /// `nil,`and
        /// `error`contains the error.
        #[unsafe(method(initWithURL:readOnly:cachingMode:synchronizationMode:error:_))]
        #[unsafe(method_family = init)]
        pub unsafe fn initWithURL_readOnly_cachingMode_synchronizationMode_error(
            this: Allocated<Self>,
            url: &NSURL,
            read_only: bool,
            caching_mode: VZDiskImageCachingMode,
            synchronization_mode: VZDiskImageSynchronizationMode,
        ) -> Result<Retained<Self>, Retained<NSError>>;

        /// URL of the underlying disk image.
        #[unsafe(method(URL))]
        #[unsafe(method_family = none)]
        pub unsafe fn URL(&self) -> Retained<NSURL>;

        /// Whether the underlying disk image is read-only.
        #[unsafe(method(isReadOnly))]
        #[unsafe(method_family = none)]
        pub unsafe fn isReadOnly(&self) -> bool;

        /// How disk image data is cached by the host.
        #[unsafe(method(cachingMode))]
        #[unsafe(method_family = none)]
        pub unsafe fn cachingMode(&self) -> VZDiskImageCachingMode;

        /// The mode in which the disk image synchronizes data with the underlying storage device.
        #[unsafe(method(synchronizationMode))]
        #[unsafe(method_family = none)]
        pub unsafe fn synchronizationMode(&self) -> VZDiskImageSynchronizationMode;
    );
}

/// Methods declared on superclass `VZStorageDeviceAttachment`.
#[cfg(feature = "VZStorageDeviceAttachment")]
impl VZDiskImageStorageDeviceAttachment {
    extern_methods!(
        #[unsafe(method(new))]
        #[unsafe(method_family = new)]
        pub unsafe fn new() -> Retained<Self>;

        #[unsafe(method(init))]
        #[unsafe(method_family = init)]
        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
    );
}