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::ffi::*;
use core::ptr::NonNull;
use objc2::__framework_prelude::*;
use objc2_foundation::*;

use crate::*;

extern_class!(
    /// Storage device attachment backed by a Network Block Device (NBD) client.
    ///
    /// This storage device attachment provides an NBD client implementation. The NBD client is connected
    /// to an NBD server referred to by an NBD Uniform Resource Indicator (URI), represented as an URL in
    /// this API. The NBD server runs outside of Virtualization framework and is not controlled by
    /// Virtualization framework. The NBD client forwards the guest's I/O operations to the NBD server,
    /// where the I/O operations are handled.
    ///
    /// The NBD client will attempt to connect to the NBD server referred to by the URL when you start the virtual
    /// machine (e.g. when `[VZVirtualMachine startWithCompletionHandler:]` is called). A connection attempt is NOT
    /// made when the attachment object is initialized. Reconnection attempts will take place throughout the life
    /// cycle of the virtual machine when the NBD client encounters a recoverable error such as connection timeout
    /// and unexpected connection errors. The NBD client will disconnect from the server when the virtual machine
    /// shuts down.
    ///
    /// Using this attachment requires the app to have the "com.apple.security.network.client" entitlement as this attachment opens an outgoing
    /// network connection.
    ///
    /// For more information about NBD, see https://github.com/NetworkBlockDevice/nbd/blob/master/doc/proto.md.
    /// For more information about the NBD URL format, see https://github.com/NetworkBlockDevice/nbd/blob/master/doc/uri.md.
    ///
    /// An example use of this API is:
    /// ```text
    /// NSURL *url = [[NSURL alloc] initWithString:
    /// "
    /// nbd://localhost:10809/myDisk"]
    /// NSError *error = nil;
    /// VZNetworkBlockDeviceStorageDeviceAttachment *attachment =
    /// [[VZNetworkBlockDeviceStorageDeviceAttachment alloc] initWithURL:url
    /// timeout:5.0
    /// forcedReadOnly:NO
    /// synchronizationMode:VZDiskSynchronizationModeFull
    /// error:
    /// &error
    /// ];
    ///
    /// if (!attachment) {
    /// // Handle the `error`.
    /// }
    ///
    /// VZVirtioBlockDeviceConfiguration *blockDevice = [[VZVirtioBlockDeviceConfiguration alloc] initWithAttachment:attachment];
    /// ```
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/virtualization/vznetworkblockdevicestoragedeviceattachment?language=objc)
    #[unsafe(super(VZStorageDeviceAttachment, NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    #[cfg(feature = "VZStorageDeviceAttachment")]
    pub struct VZNetworkBlockDeviceStorageDeviceAttachment;
);

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

#[cfg(feature = "VZStorageDeviceAttachment")]
impl VZNetworkBlockDeviceStorageDeviceAttachment {
    extern_methods!(
        #[cfg(feature = "VZDiskSynchronizationMode")]
        /// Initialize the attachment from an NBD Uniform Resource Indicator (URI) represented as an URL.
        ///
        /// Parameter `URL`: The URL referring to the NBD server to which the NBD client is to be connected.
        ///
        /// Parameter `timeout`: The timeout value in seconds for the connection between the client and server. When the timeout expires, an attempt to reconnect with the server will take place.
        ///
        /// Parameter `forcedReadOnly`: If YES, the disk attachment is forced to be read-only, regardless of whether or not the NBD server supports write requests.
        ///
        /// Parameter `error`: If not nil, assigned with the error if the initialization failed.
        ///
        /// Returns: An initialized `VZNetworkBlockDeviceStorageDeviceAttachment` or nil if there was an error.
        ///
        /// The `forcedReadOnly` parameter affects how the NBD client is exposed to the guest operating system
        /// by the storage controller. As part of the NBD protocol, whether or not the disk exposed by the NBD client is
        /// read-only is advertised by the NBD server during the handshake phase of the protocol. Setting `forcedReadOnly`
        /// to YES will force the NBD client to show up as read-only to the guest regardless of whether or not the NBD
        /// server advertises itself as read-only.
        #[unsafe(method(initWithURL:timeout:forcedReadOnly:synchronizationMode:error:_))]
        #[unsafe(method_family = init)]
        pub unsafe fn initWithURL_timeout_forcedReadOnly_synchronizationMode_error(
            this: Allocated<Self>,
            url: &NSURL,
            timeout: NSTimeInterval,
            forced_read_only: bool,
            synchronization_mode: VZDiskSynchronizationMode,
        ) -> Result<Retained<Self>, Retained<NSError>>;

        /// Convenience initializer to create the attachment from an NBD URL.
        ///
        /// Parameter `URL`: The URL referring to the NBD server to which the NBD client is to be connected.
        ///
        /// Parameter `error`: If not nil, assigned with the error if the initialization failed.
        ///
        /// Returns: An initialized `VZNetworkBlockDeviceStorageDeviceAttachment` or nil if there was an error.
        ///
        /// This initializer automatically assigns optimized default values for the `timeout`,
        /// `forcedReadOnly`, and `synchronizationMode` properties.
        #[unsafe(method(initWithURL:error:_))]
        #[unsafe(method_family = init)]
        pub unsafe fn initWithURL_error(
            this: Allocated<Self>,
            url: &NSURL,
        ) -> Result<Retained<Self>, Retained<NSError>>;

        /// Check if URL is a valid NBD URL.
        ///
        /// Parameter `URL`: The NBD URL to validate.
        ///
        /// Parameter `error`: If not nil, assigned with an error describing why the URL is not valid.
        ///
        /// See https://github.com/NetworkBlockDevice/nbd/blob/master/doc/uri.md for more detailed descriptions
        /// of valid URIs.
        ///
        /// This method checks that the URL is well-formed, it does not attempt to access the URL.
        #[unsafe(method(validateURL:error:_))]
        #[unsafe(method_family = none)]
        pub unsafe fn validateURL_error(url: &NSURL) -> Result<(), Retained<NSError>>;

        /// URL referring to the NBD server to which the NBD client is to be connected.
        #[unsafe(method(URL))]
        #[unsafe(method_family = none)]
        pub unsafe fn URL(&self) -> Retained<NSURL>;

        /// The timeout value in seconds for the connection between the client and server. When the timeout expires, an attempt to reconnect with the server will take place.
        #[unsafe(method(timeout))]
        #[unsafe(method_family = none)]
        pub unsafe fn timeout(&self) -> NSTimeInterval;

        /// Whether the underlying disk attachment is forced to be read-only.
        ///
        /// The `forcedReadOnly` parameter affects how the NBD client is exposed to the guest operating system
        /// by the storage controller. As part of the NBD protocol, whether or not the disk exposed by the NBD client
        /// is read-only is advertised by the NBD server during the handshake phase of the protocol. Setting
        /// `forcedReadOnly` to YES will force the NBD client to show up as read-only to the
        /// guest regardless of whether or not the NBD server advertises itself as read-only.
        #[unsafe(method(isForcedReadOnly))]
        #[unsafe(method_family = none)]
        pub unsafe fn isForcedReadOnly(&self) -> bool;

        #[cfg(feature = "VZDiskSynchronizationMode")]
        /// The mode in which the NBD client synchronizes data with the NBD server.
        #[unsafe(method(synchronizationMode))]
        #[unsafe(method_family = none)]
        pub unsafe fn synchronizationMode(&self) -> VZDiskSynchronizationMode;

        /// The attachment's delegate.
        #[unsafe(method(delegate))]
        #[unsafe(method_family = none)]
        pub unsafe fn delegate(
            &self,
        ) -> Option<Retained<ProtocolObject<dyn VZNetworkBlockDeviceStorageDeviceAttachmentDelegate>>>;

        /// Setter for [`delegate`][Self::delegate].
        ///
        /// This is a [weak property][objc2::topics::weak_property].
        #[unsafe(method(setDelegate:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setDelegate(
            &self,
            delegate: Option<
                &ProtocolObject<dyn VZNetworkBlockDeviceStorageDeviceAttachmentDelegate>,
            >,
        );
    );
}

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

extern_protocol!(
    /// A class conforming to VZNetworkBlockDeviceStorageDeviceAttachmentDelegate can provide
    /// methods for tracking the attachment's state.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/virtualization/vznetworkblockdevicestoragedeviceattachmentdelegate?language=objc)
    pub unsafe trait VZNetworkBlockDeviceStorageDeviceAttachmentDelegate:
        NSObjectProtocol
    {
        #[cfg(feature = "VZStorageDeviceAttachment")]
        /// Invoked when the NBD client has successfully connected/reconnected with the server.
        ///
        /// Parameter `attachment`: The attachment object invoking the delegate method.
        ///
        /// Connection with the server will take place when the virtual machine is first started, and reconnection
        /// attempts will take place when the connection times out or when the NBD client has encountered a recoverable
        /// error, such as an I/O error from the server. The method may be invoked multiple times during a virtual
        /// machine's life cycle. Reconnections are transparent to the guest.
        #[optional]
        #[unsafe(method(attachmentWasConnected:))]
        #[unsafe(method_family = none)]
        unsafe fn attachmentWasConnected(
            &self,
            attachment: &VZNetworkBlockDeviceStorageDeviceAttachment,
        );

        #[cfg(feature = "VZStorageDeviceAttachment")]
        /// Invoked when the NBD client has encountered a non-recoverable error.
        ///
        /// Parameter `attachment`: The attachment object invoking the delegate method.
        ///
        /// Parameter `error`: The error.
        ///
        /// The NBD client will be in a non-functional state after this method is invoked.
        #[optional]
        #[unsafe(method(attachment:didEncounterError:))]
        #[unsafe(method_family = none)]
        unsafe fn attachment_didEncounterError(
            &self,
            attachment: &VZNetworkBlockDeviceStorageDeviceAttachment,
            error: &NSError,
        );
    }
);