objc2_virtualization/generated/VZNetworkBlockDeviceStorageDeviceAttachment.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
10extern_class!(
11 /// Storage device attachment backed by a Network Block Device (NBD) client.
12 ///
13 /// This storage device attachment provides an NBD client implementation. The NBD client is connected
14 /// to an NBD server referred to by an NBD Uniform Resource Indicator (URI), represented as an URL in
15 /// this API. The NBD server runs outside of Virtualization framework and is not controlled by
16 /// Virtualization framework. The NBD client forwards the guest's I/O operations to the NBD server,
17 /// where the I/O operations are handled.
18 ///
19 /// The NBD client will attempt to connect to the NBD server referred to by the URL when you start the virtual
20 /// machine (e.g. when `[VZVirtualMachine startWithCompletionHandler:]` is called). A connection attempt is NOT
21 /// made when the attachment object is initialized. Reconnection attempts will take place throughout the life
22 /// cycle of the virtual machine when the NBD client encounters a recoverable error such as connection timeout
23 /// and unexpected connection errors. The NBD client will disconnect from the server when the virtual machine
24 /// shuts down.
25 ///
26 /// Using this attachment requires the app to have the "com.apple.security.network.client" entitlement as this attachment opens an outgoing
27 /// network connection.
28 ///
29 /// For more information about NBD, see https://github.com/NetworkBlockDevice/nbd/blob/master/doc/proto.md.
30 /// For more information about the NBD URL format, see https://github.com/NetworkBlockDevice/nbd/blob/master/doc/uri.md.
31 ///
32 /// An example use of this API is:
33 /// ```text
34 /// NSURL *url = [[NSURL alloc] initWithString:
35 /// "
36 /// nbd://localhost:10809/myDisk"]
37 /// NSError *error = nil;
38 /// VZNetworkBlockDeviceStorageDeviceAttachment *attachment =
39 /// [[VZNetworkBlockDeviceStorageDeviceAttachment alloc] initWithURL:url
40 /// timeout:5.0
41 /// forcedReadOnly:NO
42 /// synchronizationMode:VZDiskSynchronizationModeFull
43 /// error:
44 /// &error
45 /// ];
46 ///
47 /// if (!attachment) {
48 /// // Handle the `error`.
49 /// }
50 ///
51 /// VZVirtioBlockDeviceConfiguration *blockDevice = [[VZVirtioBlockDeviceConfiguration alloc] initWithAttachment:attachment];
52 /// ```
53 ///
54 /// See also [Apple's documentation](https://developer.apple.com/documentation/virtualization/vznetworkblockdevicestoragedeviceattachment?language=objc)
55 #[unsafe(super(VZStorageDeviceAttachment, NSObject))]
56 #[derive(Debug, PartialEq, Eq, Hash)]
57 #[cfg(feature = "VZStorageDeviceAttachment")]
58 pub struct VZNetworkBlockDeviceStorageDeviceAttachment;
59);
60
61#[cfg(feature = "VZStorageDeviceAttachment")]
62unsafe impl NSObjectProtocol for VZNetworkBlockDeviceStorageDeviceAttachment {}
63
64#[cfg(feature = "VZStorageDeviceAttachment")]
65impl VZNetworkBlockDeviceStorageDeviceAttachment {
66 extern_methods!(
67 #[cfg(feature = "VZDiskSynchronizationMode")]
68 /// Initialize the attachment from an NBD Uniform Resource Indicator (URI) represented as an URL.
69 ///
70 /// Parameter `URL`: The URL referring to the NBD server to which the NBD client is to be connected.
71 ///
72 /// 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.
73 ///
74 /// Parameter `forcedReadOnly`: If YES, the disk attachment is forced to be read-only, regardless of whether or not the NBD server supports write requests.
75 ///
76 /// Parameter `error`: If not nil, assigned with the error if the initialization failed.
77 ///
78 /// Returns: An initialized `VZNetworkBlockDeviceStorageDeviceAttachment` or nil if there was an error.
79 ///
80 /// The `forcedReadOnly` parameter affects how the NBD client is exposed to the guest operating system
81 /// by the storage controller. As part of the NBD protocol, whether or not the disk exposed by the NBD client is
82 /// read-only is advertised by the NBD server during the handshake phase of the protocol. Setting `forcedReadOnly`
83 /// to YES will force the NBD client to show up as read-only to the guest regardless of whether or not the NBD
84 /// server advertises itself as read-only.
85 #[unsafe(method(initWithURL:timeout:forcedReadOnly:synchronizationMode:error:_))]
86 #[unsafe(method_family = init)]
87 pub unsafe fn initWithURL_timeout_forcedReadOnly_synchronizationMode_error(
88 this: Allocated<Self>,
89 url: &NSURL,
90 timeout: NSTimeInterval,
91 forced_read_only: bool,
92 synchronization_mode: VZDiskSynchronizationMode,
93 ) -> Result<Retained<Self>, Retained<NSError>>;
94
95 /// Convenience initializer to create the attachment from an NBD URL.
96 ///
97 /// Parameter `URL`: The URL referring to the NBD server to which the NBD client is to be connected.
98 ///
99 /// Parameter `error`: If not nil, assigned with the error if the initialization failed.
100 ///
101 /// Returns: An initialized `VZNetworkBlockDeviceStorageDeviceAttachment` or nil if there was an error.
102 ///
103 /// This initializer automatically assigns optimized default values for the `timeout`,
104 /// `forcedReadOnly`, and `synchronizationMode` properties.
105 #[unsafe(method(initWithURL:error:_))]
106 #[unsafe(method_family = init)]
107 pub unsafe fn initWithURL_error(
108 this: Allocated<Self>,
109 url: &NSURL,
110 ) -> Result<Retained<Self>, Retained<NSError>>;
111
112 /// Check if URL is a valid NBD URL.
113 ///
114 /// Parameter `URL`: The NBD URL to validate.
115 ///
116 /// Parameter `error`: If not nil, assigned with an error describing why the URL is not valid.
117 ///
118 /// See https://github.com/NetworkBlockDevice/nbd/blob/master/doc/uri.md for more detailed descriptions
119 /// of valid URIs.
120 ///
121 /// This method checks that the URL is well-formed, it does not attempt to access the URL.
122 #[unsafe(method(validateURL:error:_))]
123 #[unsafe(method_family = none)]
124 pub unsafe fn validateURL_error(url: &NSURL) -> Result<(), Retained<NSError>>;
125
126 /// URL referring to the NBD server to which the NBD client is to be connected.
127 #[unsafe(method(URL))]
128 #[unsafe(method_family = none)]
129 pub unsafe fn URL(&self) -> Retained<NSURL>;
130
131 /// 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.
132 #[unsafe(method(timeout))]
133 #[unsafe(method_family = none)]
134 pub unsafe fn timeout(&self) -> NSTimeInterval;
135
136 /// Whether the underlying disk attachment is forced to be read-only.
137 ///
138 /// The `forcedReadOnly` parameter affects how the NBD client is exposed to the guest operating system
139 /// by the storage controller. As part of the NBD protocol, whether or not the disk exposed by the NBD client
140 /// is read-only is advertised by the NBD server during the handshake phase of the protocol. Setting
141 /// `forcedReadOnly` to YES will force the NBD client to show up as read-only to the
142 /// guest regardless of whether or not the NBD server advertises itself as read-only.
143 #[unsafe(method(isForcedReadOnly))]
144 #[unsafe(method_family = none)]
145 pub unsafe fn isForcedReadOnly(&self) -> bool;
146
147 #[cfg(feature = "VZDiskSynchronizationMode")]
148 /// The mode in which the NBD client synchronizes data with the NBD server.
149 #[unsafe(method(synchronizationMode))]
150 #[unsafe(method_family = none)]
151 pub unsafe fn synchronizationMode(&self) -> VZDiskSynchronizationMode;
152
153 /// The attachment's delegate.
154 #[unsafe(method(delegate))]
155 #[unsafe(method_family = none)]
156 pub unsafe fn delegate(
157 &self,
158 ) -> Option<Retained<ProtocolObject<dyn VZNetworkBlockDeviceStorageDeviceAttachmentDelegate>>>;
159
160 /// This is a [weak property][objc2::topics::weak_property].
161 /// Setter for [`delegate`][Self::delegate].
162 #[unsafe(method(setDelegate:))]
163 #[unsafe(method_family = none)]
164 pub unsafe fn setDelegate(
165 &self,
166 delegate: Option<
167 &ProtocolObject<dyn VZNetworkBlockDeviceStorageDeviceAttachmentDelegate>,
168 >,
169 );
170 );
171}
172
173/// Methods declared on superclass `VZStorageDeviceAttachment`.
174#[cfg(feature = "VZStorageDeviceAttachment")]
175impl VZNetworkBlockDeviceStorageDeviceAttachment {
176 extern_methods!(
177 #[unsafe(method(new))]
178 #[unsafe(method_family = new)]
179 pub unsafe fn new() -> Retained<Self>;
180
181 #[unsafe(method(init))]
182 #[unsafe(method_family = init)]
183 pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
184 );
185}
186
187extern_protocol!(
188 /// A class conforming to VZNetworkBlockDeviceStorageDeviceAttachmentDelegate can provide
189 /// methods for tracking the attachment's state.
190 ///
191 /// See also [Apple's documentation](https://developer.apple.com/documentation/virtualization/vznetworkblockdevicestoragedeviceattachmentdelegate?language=objc)
192 pub unsafe trait VZNetworkBlockDeviceStorageDeviceAttachmentDelegate:
193 NSObjectProtocol
194 {
195 #[cfg(feature = "VZStorageDeviceAttachment")]
196 /// Invoked when the NBD client has successfully connected/reconnected with the server.
197 ///
198 /// Parameter `attachment`: The attachment object invoking the delegate method.
199 ///
200 /// Connection with the server will take place when the virtual machine is first started, and reconnection
201 /// attempts will take place when the connection times out or when the NBD client has encountered a recoverable
202 /// error, such as an I/O error from the server. The method may be invoked multiple times during a virtual
203 /// machine's life cycle. Reconnections are transparent to the guest.
204 #[optional]
205 #[unsafe(method(attachmentWasConnected:))]
206 #[unsafe(method_family = none)]
207 unsafe fn attachmentWasConnected(
208 &self,
209 attachment: &VZNetworkBlockDeviceStorageDeviceAttachment,
210 );
211
212 #[cfg(feature = "VZStorageDeviceAttachment")]
213 /// Invoked when the NBD client has encountered a non-recoverable error.
214 ///
215 /// Parameter `attachment`: The attachment object invoking the delegate method.
216 ///
217 /// Parameter `error`: The error.
218 ///
219 /// The NBD client will be in a non-functional state after this method is invoked.
220 #[optional]
221 #[unsafe(method(attachment:didEncounterError:))]
222 #[unsafe(method_family = none)]
223 unsafe fn attachment_didEncounterError(
224 &self,
225 attachment: &VZNetworkBlockDeviceStorageDeviceAttachment,
226 error: &NSError,
227 );
228 }
229);