pub struct IOUSBHostObject { /* private fields */ }IOUSBHostObject only.Expand description
The Abstract class IOUSBHostDevice and IOUSBHostInterface derive from.
Defines common methods that are shared between IOUSBHostDevice and IOUSBHostInterface including instance management.
See also Apple’s documentation
Implementations§
Source§impl IOUSBHostObject
impl IOUSBHostObject
pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>
Sourcepub unsafe fn initWithIOService_options_queue_error_interestHandler(
this: Allocated<Self>,
io_service: io_service_t,
options: IOUSBHostObjectInitOptions,
queue: Option<&DispatchQueue>,
error: Option<&mut Option<Retained<NSError>>>,
interest_handler: IOUSBHostInterestHandler,
) -> Option<Retained<Self>>
Available on crate features IOUSBHostDefinitions and block2 and dispatch2 and objc2-io-kit only.
pub unsafe fn initWithIOService_options_queue_error_interestHandler( this: Allocated<Self>, io_service: io_service_t, options: IOUSBHostObjectInitOptions, queue: Option<&DispatchQueue>, error: Option<&mut Option<Retained<NSError>>>, interest_handler: IOUSBHostInterestHandler, ) -> Option<Retained<Self>>
IOUSBHostDefinitions and block2 and dispatch2 and objc2-io-kit only.Initializes IOUSBHostObject object along with user client
If the io_service_t is not found nil will be returned. If an IOUSBHostDevice or IOUSBHostInterface user client is already created, nil will be returned. Upon creation, exclusive ownership of the IOService will be established. When done using the object destroy must be called on the object.
Parameter ioService: io_service_t of the IOUSBHostDevice or IOUSBHostInterface
the user client is for. The IOUSBHostObject will keep a reference to the io_service_t
and release it after the IOUSBHostObject has been released.
Parameter options: IOUSBHostObjectInitOptions. Default value is IOUSBHostObjectInitOptionsNone
Parameter queue: A serial queue that all asynchronous io will be serviced. By
default a serial queue will be created on behalf of the client. Setting
a queue will create a dispatch source event handler for the target queue to service
all underlying io.
Parameter interestHandler: IOUSBHostInterestHandler a generalInterest IOService handler. This is
to handle underlying service state changes such as termination. See
IOServiceAddInterestNotification in IOKitLib for more details. All notifications will be serviced
on an internal serial queue separate from the IO queue.
Returns: An IOUSBHostDevice or IOUSBHostInterface. The object is to be released by the caller. An IOReturn error code will be reported on failure.
§Safety
queuepossibly has additional threading requirements.interest_handlermust be a valid pointer or null.
Sourcepub unsafe fn initWithIOService_queue_error_interestHandler(
this: Allocated<Self>,
io_service: io_service_t,
queue: Option<&DispatchQueue>,
error: Option<&mut Option<Retained<NSError>>>,
interest_handler: IOUSBHostInterestHandler,
) -> Option<Retained<Self>>
Available on crate features block2 and dispatch2 and objc2-io-kit only.
pub unsafe fn initWithIOService_queue_error_interestHandler( this: Allocated<Self>, io_service: io_service_t, queue: Option<&DispatchQueue>, error: Option<&mut Option<Retained<NSError>>>, interest_handler: IOUSBHostInterestHandler, ) -> Option<Retained<Self>>
block2 and dispatch2 and objc2-io-kit only.Initializes IOUSBHostObject object along with user client
This method should be called from either IOUSBHostDevice or IOUSBHostInterface. If the io_service_t is not found nil will be returned. If an IOUSBHostDevice or IOUSBHostInterface user client is already created, nil will be returned. Upon creation, exclusive ownership of the IOService will be established. When done using the object destroy must be called on the object.
Parameter ioService: io_service_t of the IOUSBHostDevice or IOUSBHostInterface
the user client is for. The IOUSBHostObject will keep a reference to the io_service_t
and release it after the IOUSBHostObject has been released.
Parameter queue: A serial queue that all asynchronous io will be serviced. By
default a serial queue will be created on behalf of the client. Setting
a queue will create a dispatch source event handler for the target queue to service
all underlying io.
Parameter interestHandler: IOUSBHostInterestHandler a generalInterest IOService handler. This is
to handle underlying service state changes such as termination. See
IOServiceAddInterestNotification in IOKitLib for more details. All notifications will be serviced
on an internal serial queue separate from the IO queue.
Returns: An IOUSBHostDevice or IOUSBHostInterface. The object is to be released by the caller. An IOReturn error code will be reported on failure.
§Safety
queuepossibly has additional threading requirements.interest_handlermust be a valid pointer or null.
Sourcepub unsafe fn destroy(&self)
pub unsafe fn destroy(&self)
Removes underlying allocations of the IOUSBHostObject object along with user client
When the IOUSBHostObject is no longer needed, destroy must be called. This will destroy the connection with the user client and de-register interest on the service. If the object is free’d destroy will be called automatically. Calling destroy multiple times has no effect.
Sourcepub unsafe fn destroyWithOptions(&self, options: IOUSBHostObjectDestroyOptions)
Available on crate feature IOUSBHostDefinitions only.
pub unsafe fn destroyWithOptions(&self, options: IOUSBHostObjectDestroyOptions)
IOUSBHostDefinitions only.Removes underlying allocations of the IOUSBHostObject object along with user client
Extends
destroy
to take an options to modify the destroy behavior. Currently only the
IOUSBHostObjectDestroyOptionsDeviceSurrender
is defined to support surrendering ownersip of
the kernel service. To be used when accepting the
kUSBHostMessageDeviceIsRequestingClose
message.
Sourcepub unsafe fn ioService(&self) -> io_service_t
Available on crate feature objc2-io-kit only.
pub unsafe fn ioService(&self) -> io_service_t
objc2-io-kit only.Retrieve the IOUSBHostObject’s io_service_t.
Sourcepub unsafe fn queue(&self) -> Retained<DispatchQueue>
Available on crate feature dispatch2 only.
pub unsafe fn queue(&self) -> Retained<DispatchQueue>
dispatch2 only.The dispatch queue that all asynchronous io will be serviced.
Sourcepub unsafe fn sendDeviceRequest_data_bytesTransferred_completionTimeout_error(
&self,
request: IOUSBDeviceRequest,
data: Option<&NSMutableData>,
bytes_transferred: *mut NSUInteger,
completion_timeout: NSTimeInterval,
) -> Result<(), Retained<NSError>>
Available on crate feature objc2-io-kit only.
pub unsafe fn sendDeviceRequest_data_bytesTransferred_completionTimeout_error( &self, request: IOUSBDeviceRequest, data: Option<&NSMutableData>, bytes_transferred: *mut NSUInteger, completion_timeout: NSTimeInterval, ) -> Result<(), Retained<NSError>>
objc2-io-kit only.Send a request on the default control endpoint
This method will send a synchronous request on the default control endpoint, and will not return until the request is complete.
Parameter request: IOUSBDeviceRequest structure.
Parameter data: An NSMutableData* defining the memory to use for the request’s data phase.
Parameter bytesTransferred: Optional NSUInteger reference which will be updated with the byte
count of the completed data phase.
Parameter completionTimeout: Timeout of the request. If 0, the request will never timeout. By
default this value is IOUSBHostDefaultControlCompletionTimeout.
Returns: YES on success, an IOReturn error code will be reported on failure.
§Safety
bytes_transferred must be a valid pointer or null.
Sourcepub unsafe fn sendDeviceRequest_data_bytesTransferred_error(
&self,
request: IOUSBDeviceRequest,
data: Option<&NSMutableData>,
bytes_transferred: *mut NSUInteger,
) -> Result<(), Retained<NSError>>
Available on crate feature objc2-io-kit only.
pub unsafe fn sendDeviceRequest_data_bytesTransferred_error( &self, request: IOUSBDeviceRequest, data: Option<&NSMutableData>, bytes_transferred: *mut NSUInteger, ) -> Result<(), Retained<NSError>>
objc2-io-kit only.Send a request on the default control endpoint
This method will send a synchronous request on the default control endpoint, and will not return until the request is complete.
Parameter request: IOUSBDeviceRequest structure.
Parameter data: An NSMutableData* defining the memory to use for the request’s data phase.
Parameter bytesTransferred: Optional NSUInteger reference which will be updated with the byte
count of the completed data phase.
Returns: YES on success, an IOReturn error code will be reported on failure.
§Safety
bytes_transferred must be a valid pointer or null.
Sourcepub unsafe fn sendDeviceRequest_error(
&self,
request: IOUSBDeviceRequest,
) -> Result<(), Retained<NSError>>
Available on crate feature objc2-io-kit only.
pub unsafe fn sendDeviceRequest_error( &self, request: IOUSBDeviceRequest, ) -> Result<(), Retained<NSError>>
objc2-io-kit only.Send a request on the default control endpoint
This method will send a synchronous request on the default control endpoint, and will not return until the request is complete.
Parameter request: IOUSBDeviceRequest structure.
Returns: YES on success, an IOReturn error code will be reported on failure.
Sourcepub unsafe fn enqueueDeviceRequest_data_completionTimeout_error_completionHandler(
&self,
request: IOUSBDeviceRequest,
data: Option<&NSMutableData>,
completion_timeout: NSTimeInterval,
error: Option<&mut Option<Retained<NSError>>>,
completion_handler: IOUSBHostCompletionHandler,
) -> bool
Available on crate features IOUSBHostDefinitions and block2 and objc2-io-kit only.
pub unsafe fn enqueueDeviceRequest_data_completionTimeout_error_completionHandler( &self, request: IOUSBDeviceRequest, data: Option<&NSMutableData>, completion_timeout: NSTimeInterval, error: Option<&mut Option<Retained<NSError>>>, completion_handler: IOUSBHostCompletionHandler, ) -> bool
IOUSBHostDefinitions and block2 and objc2-io-kit only.Enqueue a request on the default control endpoint
This method will enqueue an asynchronous request on the default control endpoint. If successful, the provided completionHandler will be called to report the status of the completed IO.
Parameter data: An NSMutableData* defining the memory to use for the request’s data phase.
Parameter completionTimeout: Timeout of the request. If 0, the request will never timeout. By
default this value is IOUSBHostDefaultControlCompletionTimeout
Parameter completionHandler: an IOUSBHostCompletionHandler
Returns: YES on success, an IOReturn error code will be reported on failure
§Safety
completion_handler must be a valid pointer or null.
Sourcepub unsafe fn enqueueDeviceRequest_data_error_completionHandler(
&self,
request: IOUSBDeviceRequest,
data: Option<&NSMutableData>,
error: Option<&mut Option<Retained<NSError>>>,
completion_handler: IOUSBHostCompletionHandler,
) -> bool
Available on crate features IOUSBHostDefinitions and block2 and objc2-io-kit only.
pub unsafe fn enqueueDeviceRequest_data_error_completionHandler( &self, request: IOUSBDeviceRequest, data: Option<&NSMutableData>, error: Option<&mut Option<Retained<NSError>>>, completion_handler: IOUSBHostCompletionHandler, ) -> bool
IOUSBHostDefinitions and block2 and objc2-io-kit only.Enqueue a request on the default control endpoint
This method will enqueue an asynchronous request on the default control endpoint. If successful, the provided completionHandler will be called to report the status of the completed IO.
Parameter data: An NSMutableData* defining the memory to use for the request’s data phase.
Parameter completionHandler: an IOUSBHostCompletionHandler
Returns: YES on success, an IOReturn error code will be reported on failure
§Safety
completion_handler must be a valid pointer or null.
Sourcepub unsafe fn enqueueDeviceRequest_error_completionHandler(
&self,
request: IOUSBDeviceRequest,
error: Option<&mut Option<Retained<NSError>>>,
completion_handler: IOUSBHostCompletionHandler,
) -> bool
Available on crate features IOUSBHostDefinitions and block2 and objc2-io-kit only.
pub unsafe fn enqueueDeviceRequest_error_completionHandler( &self, request: IOUSBDeviceRequest, error: Option<&mut Option<Retained<NSError>>>, completion_handler: IOUSBHostCompletionHandler, ) -> bool
IOUSBHostDefinitions and block2 and objc2-io-kit only.Enqueue a request on the default control endpoint
This method will enqueue an asynchronous request on the default control endpoint. If successful, the provided completionHandler will be called to report the status of the completed IO. default this value is IOUSBHostDefaultControlCompletionTimeout
Parameter completionHandler: an IOUSBHostCompletionHandler
Returns: YES on success, an IOReturn error code will be reported on failure
§Safety
completion_handler must be a valid pointer or null.
Sourcepub unsafe fn abortDeviceRequestsWithOption_error(
&self,
option: IOUSBHostAbortOption,
) -> Result<(), Retained<NSError>>
Available on crate feature IOUSBHostDefinitions only.
pub unsafe fn abortDeviceRequestsWithOption_error( &self, option: IOUSBHostAbortOption, ) -> Result<(), Retained<NSError>>
IOUSBHostDefinitions only.Abort device requests
This method will abort any requests made via the
sendDeviceRequestand
enqueueDeviceRequestmethods.
Parameter option: IOUSBHostAbortOption by default IOUSBHostAbortOptionSynchronous is used
Returns: YES on success, an IOReturn error code will be reported on failure
Sourcepub unsafe fn abortDeviceRequestsWithError(
&self,
) -> Result<(), Retained<NSError>>
pub unsafe fn abortDeviceRequestsWithError( &self, ) -> Result<(), Retained<NSError>>
Abort device requests
This method will abort any requests made via the
sendDeviceRequestand
enqueueDeviceRequestmethods.
Returns: YES on success, an IOReturn error code will be reported on failure
Sourcepub unsafe fn descriptorWithType_length_index_languageID_requestType_requestRecipient_error(
&self,
type: tIOUSBDescriptorType,
length: NonNull<NSUInteger>,
index: NSUInteger,
language_id: NSUInteger,
request_type: tIOUSBDeviceRequestTypeValue,
request_recipient: tIOUSBDeviceRequestRecipientValue,
error: Option<&mut Option<Retained<NSError>>>,
) -> *const IOUSBDescriptor
Available on crate feature objc2-io-kit only.
pub unsafe fn descriptorWithType_length_index_languageID_requestType_requestRecipient_error( &self, type: tIOUSBDescriptorType, length: NonNull<NSUInteger>, index: NSUInteger, language_id: NSUInteger, request_type: tIOUSBDeviceRequestTypeValue, request_recipient: tIOUSBDeviceRequestRecipientValue, error: Option<&mut Option<Retained<NSError>>>, ) -> *const IOUSBDescriptor
objc2-io-kit only.Retrieve a descriptor from the cache or the device
This method will search the descriptor cache for the descriptor that matches the input arguments. If the descriptor is not in the cache, a GET_DESCRIPTOR control request (USB 2.0 9.4.3) will be issued to retrieve the descriptor from the device. If the device request is successful, the retrieved descriptor will be added to the cache.
Parameter type:
bDescriptorType
of the descriptor to find.
Parameter length: Reference to a NSUInteger which will be updated with the length of the
descriptor. As input, used as
wLength
when fetching variable-length
configuration or BOS descriptors, or when fetching nonstandard descriptor types.
Parameter index: Descriptor index value. Low byte of
wValue
of the SET_DESCRIPTOR
control request (USB 2.0 9.4.8). By default the value is 0
Parameter languageID: Descriptor language ID.
wIndex
of the SET_DESCRIPTOR
control request (USB 2.0 9.4.8). By default the value is 0
Parameter requestType: tDeviceRequestType to be used for a GET_DESCRIPTOR control request.
By default the value is IOUSBRequestTypeStandard
Parameter requestRecipient: tDeviceRequestRecipient to be used for a GET_DESCRIPTOR control
request. By default the value is IOUSBRequestRecipientDevice
Returns: Pointer to the cached descriptor if found, otherwise nil. An IOReturn error code will be reported on failure.
§Safety
length must be a valid pointer.
Sourcepub unsafe fn descriptorWithType_length_index_languageID_error(
&self,
type: tIOUSBDescriptorType,
length: NonNull<NSUInteger>,
index: NSUInteger,
language_id: NSUInteger,
error: Option<&mut Option<Retained<NSError>>>,
) -> *const IOUSBDescriptor
Available on crate feature objc2-io-kit only.
pub unsafe fn descriptorWithType_length_index_languageID_error( &self, type: tIOUSBDescriptorType, length: NonNull<NSUInteger>, index: NSUInteger, language_id: NSUInteger, error: Option<&mut Option<Retained<NSError>>>, ) -> *const IOUSBDescriptor
objc2-io-kit only.Retrieve a descriptor from the cache or the device
This method will search the descriptor cache for the descriptor that matches the input arguments. If the descriptor is not in the cache, a GET_DESCRIPTOR control request (USB 2.0 9.4.3) will be issued to retrieve the descriptor from the device. If the device request is successful, the retrieved descriptor will be added to the cache.
Parameter type:
bDescriptorType
of the descriptor to find.
Parameter length: Reference to a NSUInteger which will be updated with the length of the
descriptor. As input, used as
wLength
when fetching variable-length
configuration or BOS descriptors, or when fetching nonstandard descriptor types.
Parameter index: Descriptor index value. Low byte of
wValue
of the SET_DESCRIPTOR
control request (USB 2.0 9.4.8). By default the value is 0
Parameter languageID: Descriptor language ID.
wIndex
of the SET_DESCRIPTOR
control request (USB 2.0 9.4.8). By default the value is 0
Returns: Pointer to the cached descriptor if found, otherwise nil. An IOReturn error code will be reported on failure.
§Safety
length must be a valid pointer.
Sourcepub unsafe fn descriptorWithType_length_error(
&self,
type: tIOUSBDescriptorType,
length: NonNull<NSUInteger>,
error: Option<&mut Option<Retained<NSError>>>,
) -> *const IOUSBDescriptor
Available on crate feature objc2-io-kit only.
pub unsafe fn descriptorWithType_length_error( &self, type: tIOUSBDescriptorType, length: NonNull<NSUInteger>, error: Option<&mut Option<Retained<NSError>>>, ) -> *const IOUSBDescriptor
objc2-io-kit only.Retrieve a descriptor from the cache or the device
This method will search the descriptor cache for the descriptor that matches the input arguments. If the descriptor is not in the cache, a GET_DESCRIPTOR control request (USB 2.0 9.4.3) will be issued to retrieve the descriptor from the device. If the device request is successful, the retrieved descriptor will be added to the cache.
Parameter type:
bDescriptorType
of the descriptor to find.
Parameter length: Reference to a NSUInteger which will be updated with the length of the
descriptor. As input, used as
wLength
when fetching variable-length
configuration or BOS descriptors, or when fetching nonstandard descriptor types.
By default the value is 0
Returns: Pointer to the cached descriptor if found, otherwise nil. An IOReturn error code will be reported on failure.
§Safety
length must be a valid pointer.
Sourcepub unsafe fn deviceDescriptor(&self) -> *const IOUSBDeviceDescriptor
Available on crate feature objc2-io-kit only.
pub unsafe fn deviceDescriptor(&self) -> *const IOUSBDeviceDescriptor
objc2-io-kit only.Return the device descriptor
This method uses descriptorWithType to retrieve the device descriptor.
Returns: Pointer to the device descriptor.
Sourcepub unsafe fn capabilityDescriptors(&self) -> *const IOUSBBOSDescriptor
Available on crate feature objc2-io-kit only.
pub unsafe fn capabilityDescriptors(&self) -> *const IOUSBBOSDescriptor
objc2-io-kit only.Return the capability descriptors of the device
This method uses descriptorWithType to return the device’s BOS descriptors
Returns: Pointer to the BOS descriptor if found, otherwise nil.
Sourcepub unsafe fn configurationDescriptorWithIndex_error(
&self,
index: NSUInteger,
error: Option<&mut Option<Retained<NSError>>>,
) -> *const IOUSBConfigurationDescriptor
Available on crate feature objc2-io-kit only.
pub unsafe fn configurationDescriptorWithIndex_error( &self, index: NSUInteger, error: Option<&mut Option<Retained<NSError>>>, ) -> *const IOUSBConfigurationDescriptor
objc2-io-kit only.Return the configuration descriptor at a specified index
This method uses descriptorWithType to retrieve the configuration descriptor.
Parameter index: Descriptor index value
Returns: Pointer of the configuration descriptor if found, otherwise nil. An IOReturn error code will be reported on failure.
Sourcepub unsafe fn configurationDescriptorWithConfigurationValue_error(
&self,
configuration_value: NSUInteger,
error: Option<&mut Option<Retained<NSError>>>,
) -> *const IOUSBConfigurationDescriptor
Available on crate feature objc2-io-kit only.
pub unsafe fn configurationDescriptorWithConfigurationValue_error( &self, configuration_value: NSUInteger, error: Option<&mut Option<Retained<NSError>>>, ) -> *const IOUSBConfigurationDescriptor
objc2-io-kit only.Return the configuration descriptor with a specified value
This method uses descriptorWithType to search for a configuration descriptor with a
specific
bConfigurationValue
field.
Parameter configurationValue: Value to match
Returns: Pointer of the configuration descriptor if found, otherwise nil. An IOReturn error code will be reported on failure.
Sourcepub unsafe fn stringWithIndex_languageID_error(
&self,
index: NSUInteger,
language_id: NSUInteger,
) -> Result<Retained<NSString>, Retained<NSError>>
pub unsafe fn stringWithIndex_languageID_error( &self, index: NSUInteger, language_id: NSUInteger, ) -> Result<Retained<NSString>, Retained<NSError>>
Returns the string from a string descriptor
This method uses descriptorWithType to retrieve the string descriptor.
Parameter index: Descriptor index value. Low byte of
wValue
of the
SET_DESCRIPTOR control request (USB 2.0 9.4.8).
Parameter languageID: Descriptor language ID.
wIndex
of the SET_DESCRIPTOR
control request (USB 2.0 9.4.8). By default this value is kLanguageIDEnglishUS
Returns: NSString reference to string from descriptor, an IOReturn error code will be reported on failure.
Sourcepub unsafe fn stringWithIndex_error(
&self,
index: NSUInteger,
) -> Result<Retained<NSString>, Retained<NSError>>
pub unsafe fn stringWithIndex_error( &self, index: NSUInteger, ) -> Result<Retained<NSString>, Retained<NSError>>
Returns the string from a string descriptor
This method uses descriptorWithType to retrieve the string descriptor.
Parameter index: Descriptor index value. Low byte of
wValue
of the
SET_DESCRIPTOR control request (USB 2.0 9.4.8).
Returns: NSString reference to string from descriptor, an IOReturn error code will be reported on failure.
Sourcepub unsafe fn deviceAddress(&self) -> NSUInteger
pub unsafe fn deviceAddress(&self) -> NSUInteger
Retrieve the current address of the device.
Sourcepub unsafe fn frameNumberWithTime(&self, time: *mut IOUSBHostTime) -> u64
Available on crate feature IOUSBHostDefinitions only.
pub unsafe fn frameNumberWithTime(&self, time: *mut IOUSBHostTime) -> u64
IOUSBHostDefinitions only.Return the current frame number of the USB controller
This method will return the current frame number of the USB controller, omitting micro frame. This is most useful for scheduling future isochronous requests.
Parameter time: If not nil, this will be updated with the current system time
Returns: The current frame number
§Safety
time must be a valid pointer or null.
Sourcepub unsafe fn currentMicroframeWithTime_error(
&self,
time: *mut IOUSBHostTime,
error: Option<&mut Option<Retained<NSError>>>,
) -> u64
Available on crate feature IOUSBHostDefinitions only.
pub unsafe fn currentMicroframeWithTime_error( &self, time: *mut IOUSBHostTime, error: Option<&mut Option<Retained<NSError>>>, ) -> u64
IOUSBHostDefinitions only.Return the current microframe number of the USB controller
This method will return the current microframe number of the USB controller. This is most useful for scheduling future isochronous requests.
Parameter time: If not nil, this will be updated with system time associated with the microframe.
Returns: The current microframe number. Returns 0 on failure, with NSError populated with the IOReturn error code.
§Safety
time must be a valid pointer or null.
Sourcepub unsafe fn referenceMicroframeWithTime_error(
&self,
time: *mut IOUSBHostTime,
error: Option<&mut Option<Retained<NSError>>>,
) -> u64
Available on crate feature IOUSBHostDefinitions only.
pub unsafe fn referenceMicroframeWithTime_error( &self, time: *mut IOUSBHostTime, error: Option<&mut Option<Retained<NSError>>>, ) -> u64
IOUSBHostDefinitions only.Return a recent microframe number of the USB controller
This method will return a recent microframe number of the USB controller. This is most useful for scheduling future isochronous requests.
Parameter time: If not nil, this will be updated with system time associated with the microframe.
Returns: A recent microframe number. Returns 0 on failure, with NSError populated with the IOReturn error code.
§Safety
time must be a valid pointer or null.
Sourcepub unsafe fn ioDataWithCapacity_error(
&self,
capacity: NSUInteger,
) -> Result<Retained<NSMutableData>, Retained<NSError>>
pub unsafe fn ioDataWithCapacity_error( &self, capacity: NSUInteger, ) -> Result<Retained<NSMutableData>, Retained<NSError>>
Allocate a buffer to be used for I/O
This method will allocate and map an IOBufferMemoryDescriptor optimized for use by the underlying controller hardware. A buffer allocated by this method will not be bounced to perform DMA operations. Because the NSMutableData is backed by kernel memory, the length and capacity are not mutable. Any changes to the length or capacity will cause an exception to be thrown.
Parameter capacity: Size of the buffer to allocate
Returns: NSMutableData of memory mapped to user space of an IOBufferMemoryDescriptor if successful, otherwise nil. An IOReturn error code will be reported on failure. The result is to be released by the caller
Methods from Deref<Target = NSObject>§
Sourcepub fn doesNotRecognizeSelector(&self, sel: Sel) -> !
pub fn doesNotRecognizeSelector(&self, sel: Sel) -> !
Handle messages the object doesn’t recognize.
See Apple’s documentation for details.
Methods from Deref<Target = AnyObject>§
Sourcepub fn class(&self) -> &'static AnyClass
pub fn class(&self) -> &'static AnyClass
Dynamically find the class of this object.
§Panics
May panic if the object is invalid (which may be the case for objects
returned from unavailable init/new methods).
§Example
Check that an instance of NSObject has the precise class NSObject.
use objc2::ClassType;
use objc2::runtime::NSObject;
let obj = NSObject::new();
assert_eq!(obj.class(), NSObject::class());Sourcepub unsafe fn get_ivar<T>(&self, name: &str) -> &Twhere
T: Encode,
👎Deprecated: this is difficult to use correctly, use Ivar::load instead.
pub unsafe fn get_ivar<T>(&self, name: &str) -> &Twhere
T: Encode,
Ivar::load instead.Use Ivar::load instead.
§Safety
The object must have an instance variable with the given name, and it
must be of type T.
See Ivar::load_ptr for details surrounding this.
Sourcepub fn downcast_ref<T>(&self) -> Option<&T>where
T: DowncastTarget,
pub fn downcast_ref<T>(&self) -> Option<&T>where
T: DowncastTarget,
Attempt to downcast the object to a class of type T.
This is the reference-variant. Use Retained::downcast if you want
to convert a retained object to another type.
§Mutable classes
Some classes have immutable and mutable variants, such as NSString
and NSMutableString.
When some Objective-C API signature says it gives you an immutable class, it generally expects you to not mutate that, even though it may technically be mutable “under the hood”.
So using this method to convert a NSString to a NSMutableString,
while not unsound, is generally frowned upon unless you created the
string yourself, or the API explicitly documents the string to be
mutable.
See Apple’s documentation on mutability and on
isKindOfClass: for more details.
§Generic classes
Objective-C generics are called “lightweight generics”, and that’s because they aren’t exposed in the runtime. This makes it impossible to safely downcast to generic collections, so this is disallowed by this method.
You can, however, safely downcast to generic collections where all the
type-parameters are AnyObject.
§Panics
This works internally by calling isKindOfClass:. That means that the
object must have the instance method of that name, and an exception
will be thrown (if CoreFoundation is linked) or the process will abort
if that is not the case. In the vast majority of cases, you don’t need
to worry about this, since both root objects NSObject and
NSProxy implement this method.
§Examples
Cast an NSString back and forth from NSObject.
use objc2::rc::Retained;
use objc2_foundation::{NSObject, NSString};
let obj: Retained<NSObject> = NSString::new().into_super();
let string = obj.downcast_ref::<NSString>().unwrap();
// Or with `downcast`, if we do not need the object afterwards
let string = obj.downcast::<NSString>().unwrap();Try (and fail) to cast an NSObject to an NSString.
use objc2_foundation::{NSObject, NSString};
let obj = NSObject::new();
assert!(obj.downcast_ref::<NSString>().is_none());Try to cast to an array of strings.
use objc2_foundation::{NSArray, NSObject, NSString};
let arr = NSArray::from_retained_slice(&[NSObject::new()]);
// This is invalid and doesn't type check.
let arr = arr.downcast_ref::<NSArray<NSString>>();This fails to compile, since it would require enumerating over the array to ensure that each element is of the desired type, which is a performance pitfall.
Downcast when processing each element instead.
use objc2_foundation::{NSArray, NSObject, NSString};
let arr = NSArray::from_retained_slice(&[NSObject::new()]);
for elem in arr {
if let Some(data) = elem.downcast_ref::<NSString>() {
// handle `data`
}
}Trait Implementations§
Source§impl AsRef<AnyObject> for IOUSBHostObject
impl AsRef<AnyObject> for IOUSBHostObject
Source§impl AsRef<IOUSBHostObject> for IOUSBHostDevice
Available on crate feature IOUSBHostDevice only.
impl AsRef<IOUSBHostObject> for IOUSBHostDevice
IOUSBHostDevice only.Source§fn as_ref(&self) -> &IOUSBHostObject
fn as_ref(&self) -> &IOUSBHostObject
Source§impl AsRef<IOUSBHostObject> for IOUSBHostInterface
Available on crate feature IOUSBHostInterface only.
impl AsRef<IOUSBHostObject> for IOUSBHostInterface
IOUSBHostInterface only.Source§fn as_ref(&self) -> &IOUSBHostObject
fn as_ref(&self) -> &IOUSBHostObject
Source§impl AsRef<IOUSBHostObject> for IOUSBHostObject
impl AsRef<IOUSBHostObject> for IOUSBHostObject
Source§impl AsRef<NSObject> for IOUSBHostObject
impl AsRef<NSObject> for IOUSBHostObject
Source§impl Borrow<AnyObject> for IOUSBHostObject
impl Borrow<AnyObject> for IOUSBHostObject
Source§impl Borrow<IOUSBHostObject> for IOUSBHostDevice
Available on crate feature IOUSBHostDevice only.
impl Borrow<IOUSBHostObject> for IOUSBHostDevice
IOUSBHostDevice only.Source§fn borrow(&self) -> &IOUSBHostObject
fn borrow(&self) -> &IOUSBHostObject
Source§impl Borrow<IOUSBHostObject> for IOUSBHostInterface
Available on crate feature IOUSBHostInterface only.
impl Borrow<IOUSBHostObject> for IOUSBHostInterface
IOUSBHostInterface only.Source§fn borrow(&self) -> &IOUSBHostObject
fn borrow(&self) -> &IOUSBHostObject
Source§impl Borrow<NSObject> for IOUSBHostObject
impl Borrow<NSObject> for IOUSBHostObject
Source§impl ClassType for IOUSBHostObject
impl ClassType for IOUSBHostObject
Source§const NAME: &'static str = "IOUSBHostObject"
const NAME: &'static str = "IOUSBHostObject"
Source§type ThreadKind = <<IOUSBHostObject as ClassType>::Super as ClassType>::ThreadKind
type ThreadKind = <<IOUSBHostObject as ClassType>::Super as ClassType>::ThreadKind
Source§impl Debug for IOUSBHostObject
impl Debug for IOUSBHostObject
Source§impl Deref for IOUSBHostObject
impl Deref for IOUSBHostObject
Source§impl Hash for IOUSBHostObject
impl Hash for IOUSBHostObject
Source§impl Message for IOUSBHostObject
impl Message for IOUSBHostObject
Source§impl NSObjectProtocol for IOUSBHostObject
impl NSObjectProtocol for IOUSBHostObject
Source§fn isEqual(&self, other: Option<&AnyObject>) -> bool
fn isEqual(&self, other: Option<&AnyObject>) -> bool
Source§fn hash(&self) -> usize
fn hash(&self) -> usize
Source§fn isKindOfClass(&self, cls: &AnyClass) -> bool
fn isKindOfClass(&self, cls: &AnyClass) -> bool
Source§fn is_kind_of<T>(&self) -> bool
fn is_kind_of<T>(&self) -> bool
isKindOfClass directly, or cast your objects with AnyObject::downcast_ref