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::*;

extern_class!(
    /// Storage device attachment using a disk block device to store data.
    ///
    /// The disk block device implements a storage attachment by using an actual disk rather than a disk image on a file system.
    ///
    /// For example, a disk block device on the disk at `/dev/rdisk42` would execute the I/O operations directly on that disk
    /// rather than through a file system.
    ///
    /// Note that if the disk has a file system formatted on it, the guest is able to destroy data in a way that is not recoverable.
    /// The disk passed to this attachment needs to be handled with caution.
    ///
    /// An example use of this API is:
    /// ```text
    /// NSFileHandle *fileHandle = [NSFileHandle fileHandleForReadingAtPath:
    /// "
    /// /dev/rdisk42"];
    /// if (!fileHandle) {
    /// // Handle errors.
    /// }
    ///
    /// NSError *error;
    /// VZDiskBlockDeviceStorageDeviceAttachment *attachment =
    /// [[VZDiskBlockDeviceStorageDeviceAttachment alloc] initWithFileHandle:fileHandle
    /// readOnly:YES
    /// synchronizationMode:VZDiskSynchronizationModeFull
    /// error:error];
    /// if (!attachment) {
    /// // Handle errors.
    /// }
    /// ```
    ///
    /// Disk file handles are typically only accessible by the `root` user unless permission is explicitly granted.
    /// Running virtual machines as root is not recommended. If `root` access is required to open the file descriptor, it is recommended to do that operation
    /// in a separate process then pass the file descriptor to a less privileged process running Virtualization framework.
    ///
    ///
    /// See: VZDiskImageStorageDeviceAttachment
    ///
    /// See: VZNVMExpressControllerDeviceConfiguration
    ///
    /// See: VZUSBMassStorageDeviceConfiguration
    ///
    /// See: VZVirtioBlockDeviceConfiguration
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/virtualization/vzdiskblockdevicestoragedeviceattachment?language=objc)
    #[unsafe(super(VZStorageDeviceAttachment, NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    #[cfg(feature = "VZStorageDeviceAttachment")]
    pub struct VZDiskBlockDeviceStorageDeviceAttachment;
);

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

#[cfg(feature = "VZStorageDeviceAttachment")]
impl VZDiskBlockDeviceStorageDeviceAttachment {
    extern_methods!(
        #[cfg(feature = "VZDiskSynchronizationMode")]
        /// Initialize the disk attachment from a file handle.
        ///
        /// Parameter `fileHandle`: File handle to a block device.
        ///
        /// Parameter `readOnly`: If YES, the disk attachment is read only, otherwise, if the file handle allows writes, the device can write data into it.
        ///
        /// Parameter `synchronizationMode`: Defines how the disk 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: An initialized `VZDiskBlockDeviceStorageDeviceAttachment` or nil if there was an error.
        ///
        /// The file handle is retained by the disk attachment.
        /// The handle must be open when the virtual machine starts.
        ///
        /// The `readOnly` parameter affects how the disk is exposed to the guest operating system
        /// by the storage controller. If the disk is intended to be used read-only, it is also recommended
        /// to open the file handle as read-only.
        #[unsafe(method(initWithFileHandle:readOnly:synchronizationMode:error:_))]
        #[unsafe(method_family = init)]
        pub unsafe fn initWithFileHandle_readOnly_synchronizationMode_error(
            this: Allocated<Self>,
            file_handle: &NSFileHandle,
            read_only: bool,
            synchronization_mode: VZDiskSynchronizationMode,
        ) -> Result<Retained<Self>, Retained<NSError>>;

        /// File handle to the underlying disk used for storage by the attachment.
        #[unsafe(method(fileHandle))]
        #[unsafe(method_family = none)]
        pub unsafe fn fileHandle(&self) -> Retained<NSFileHandle>;

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

        #[cfg(feature = "VZDiskSynchronizationMode")]
        /// 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) -> VZDiskSynchronizationMode;
    );
}

/// Methods declared on superclass `VZStorageDeviceAttachment`.
#[cfg(feature = "VZStorageDeviceAttachment")]
impl VZDiskBlockDeviceStorageDeviceAttachment {
    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>;
    );
}