IOHIDManager

Struct IOHIDManager 

Source
pub struct IOHIDManager { /* private fields */ }
Available on crate feature hid only.
Expand description

This is the type of a reference to the IOHIDManager.

See also Apple’s documentation

Implementations§

Source§

impl IOHIDManager

Source

pub fn new( allocator: Option<&CFAllocator>, options: IOOptionBits, ) -> CFRetained<IOHIDManager>

Creates an IOHIDManager object.

The IOHIDManager object is meant as a global management system for communicating with HID devices.

Parameter allocator: Allocator to be used during creation.

Parameter options: Supply

 kIOHIDManagerOptionUsePersistentProperties

to load properties from the default persistent property store. Otherwise supply

 kIOHIDManagerOptionNone

(or 0).

Returns: Returns a new IOHIDManagerRef.

Source

pub fn open(&self, options: IOOptionBits) -> IOReturn

Opens the IOHIDManager.

This will open both current and future devices that are enumerated. To establish an exclusive link use the kIOHIDOptionsTypeSeizeDevice option.

Parameter manager: Reference to an IOHIDManager.

Parameter options: Option bits to be sent down to the manager and device.

Returns: Returns kIOReturnSuccess if successful.

Source

pub fn close(&self, options: IOOptionBits) -> IOReturn

Closes the IOHIDManager.

This will also close all devices that are currently enumerated.

Parameter manager: Reference to an IOHIDManager.

Parameter options: Option bits to be sent down to the manager and device.

Returns: Returns kIOReturnSuccess if successful.

Source

pub fn property(&self, key: &CFString) -> Option<CFRetained<CFType>>

Obtains a property of an IOHIDManager.

Property keys are prefixed by kIOHIDDevice and declared in <IOKit /hid/IOHIDKeys.h>.

Parameter manager: Reference to an IOHIDManager.

Parameter key: CFStringRef containing key to be used when querying the manager.

Returns: Returns CFTypeRef containing the property.

Source

pub unsafe fn set_property(&self, key: &CFString, value: &CFType) -> bool

Sets a property for an IOHIDManager.

Property keys are prefixed by kIOHIDDevice and kIOHIDManager and declared in <IOKit /hid/IOHIDKeys.h>. This method will propagate any relevent properties to current and future devices that are enumerated.

Parameter manager: Reference to an IOHIDManager.

Parameter key: CFStringRef containing key to be used when modifiying the device property.

Parameter value: CFTypeRef containing the property value to be set.

Returns: Returns TRUE if successful.

§Safety

value should be of the correct type.

Source

pub unsafe fn schedule_with_run_loop( &self, run_loop: &CFRunLoop, run_loop_mode: &CFString, )

Schedules HID manager with run loop.

Formally associates manager with client’s run loop. Scheduling this device with the run loop is necessary before making use of any asynchronous APIs. This will propagate to current and future devices that are enumerated.

Parameter manager: Reference to an IOHIDManager.

Parameter runLoop: RunLoop to be used when scheduling any asynchronous activity.

Parameter runLoopMode: Run loop mode to be used when scheduling any asynchronous activity.

§Safety

run_loop possibly has additional threading requirements.

Source

pub unsafe fn unschedule_from_run_loop( &self, run_loop: &CFRunLoop, run_loop_mode: &CFString, )

Unschedules HID manager with run loop.

Formally disassociates device with client’s run loop. This will propagate to current devices that are enumerated.

Parameter manager: Reference to an IOHIDManager.

Parameter runLoop: RunLoop to be used when unscheduling any asynchronous activity.

Parameter runLoopMode: Run loop mode to be used when unscheduling any asynchronous activity.

§Safety

run_loop possibly has additional threading requirements.

Source

pub unsafe fn set_dispatch_queue(&self, queue: &DispatchQueue)

Available on crate feature dispatch2 only.

Sets the dispatch queue to be associated with the IOHIDManager. This is necessary in order to receive asynchronous events from the kernel.

An IOHIDManager should not be associated with both a runloop and dispatch queue. A call to IOHIDManagerSetDispatchQueue should only be made once.

After a dispatch queue is set, the IOHIDManager must make a call to activate via IOHIDManagerActivate and cancel via IOHIDManagerCancel. All calls to “Register” functions should be done before activation and not after cancellation.

Parameter manager: Reference to an IOHIDManager

Parameter queue: The dispatch queue to which the event handler block will be submitted.

§Safety

queue possibly has additional threading requirements.

Source

pub unsafe fn set_cancel_handler(&self, handler: dispatch_block_t)

Available on crate feature dispatch2 only.

Sets a cancellation handler for the dispatch queue associated with IOHIDManagerSetDispatchQueue.

The cancellation handler (if specified) will be will be submitted to the manager’s dispatch queue in response to a call to IOHIDManagerCancel after all the events have been handled.

IOHIDManagerSetCancelHandler should not be used when scheduling with a run loop.

The IOHIDManagerRef should only be released after the manager has been cancelled, and the cancel handler has been called. This is to ensure all asynchronous objects are released. For example:

dispatch_block_t cancelHandler = dispatch_block_create(0, ^{ CFRelease(manager); }); IOHIDManagerSetCancelHandler(manager, cancelHandler); IOHIDManagerActivate(manager); IOHIDManageCancel(manager);

Parameter manager: Reference to an IOHIDManager.

Parameter handler: The cancellation handler block to be associated with the dispatch queue.

§Safety

handler must be a valid pointer.

Source

pub fn activate(&self)

Activates the IOHIDManager object.

An IOHIDManager object associated with a dispatch queue is created in an inactive state. The object must be activated in order to receive asynchronous events from the kernel.

A dispatch queue must be set via IOHIDManagerSetDispatchQueue before activation.

An activated manager must be cancelled via IOHIDManagerCancel. All calls to “Register” functions should be done before activation and not after cancellation.

Calling IOHIDManagerActivate on an active IOHIDManager has no effect.

Parameter manager: Reference to an IOHIDManager

Source

pub fn cancel(&self)

Cancels the IOHIDManager preventing any further invocation of its event handler block.

Cancelling prevents any further invocation of the event handler block for the specified dispatch queue, but does not interrupt an event handler block that is already in progress.

Explicit cancellation of the IOHIDManager is required, no implicit cancellation takes place.

Calling IOHIDManagerCancel on an already cancelled queue has no effect.

The IOHIDManagerRef should only be released after the manager has been cancelled, and the cancel handler has been called. This is to ensure all asynchronous objects are released. For example:

dispatch_block_t cancelHandler = dispatch_block_create(0, ^{ CFRelease(manager); }); IOHIDManagerSetCancelHandler(manager, cancelHandler); IOHIDManagerActivate(manager); IOHIDManageCancel(manager);

Parameter manager: Reference to an IOHIDManager

Source

pub unsafe fn set_device_matching(&self, matching: Option<&CFDictionary>)

Sets matching criteria for device enumeration.

Matching keys are prefixed by kIOHIDDevice and declared in <IOKit /hid/IOHIDKeys.h>. Passing a NULL dictionary will result in all devices being enumerated. Any subsequent calls will cause the hid manager to release previously enumerated devices and restart the enuerate process using the revised criteria. If interested in multiple, specific device classes, please defer to using IOHIDManagerSetDeviceMatchingMultiple. If a dispatch queue is set, this call must occur before activation.

Parameter manager: Reference to an IOHIDManager.

Parameter matching: CFDictionaryRef containg device matching criteria.

§Safety

matching generics must be of the correct type.

Source

pub unsafe fn set_device_matching_multiple(&self, multiple: Option<&CFArray>)

Sets multiple matching criteria for device enumeration.

Matching keys are prefixed by kIOHIDDevice and declared in <IOKit /hid/IOHIDKeys.h>. This method is useful if interested in multiple, specific device classes. If a dispatch queue is set, this call must occur before activation.

Parameter manager: Reference to an IOHIDManager.

Parameter multiple: CFArrayRef containing multiple CFDictionaryRef objects containg device matching criteria.

§Safety

multiple generic must be of the correct type.

Source

pub fn devices(&self) -> Option<CFRetained<CFSet>>

Obtains currently enumerated devices.

Parameter manager: Reference to an IOHIDManager.

Returns: CFSetRef containing IOHIDDeviceRefs.

Source

pub unsafe fn register_device_matching_callback( &self, callback: IOHIDDeviceCallback, context: *mut c_void, )

Registers a callback to be used a device is enumerated.

Only device matching the set criteria will be enumerated. If a dispatch queue is set, this call must occur before activation. Devices provided in the callback will be scheduled with the same runloop/dispatch queue as the IOHIDManagerRef, and should not be rescheduled.

Parameter manager: Reference to an IOHIDManagerRef.

Parameter callback: Pointer to a callback method of type IOHIDDeviceCallback.

Parameter context: Pointer to data to be passed to the callback.

§Safety
  • callback must be implemented correctly.
  • context must be a valid pointer or null.
Source

pub unsafe fn register_device_removal_callback( &self, callback: IOHIDDeviceCallback, context: *mut c_void, )

Registers a callback to be used when any enumerated device is removed.

In most cases this occurs when a device is unplugged. If a dispatch queue is set, this call must occur before activation.

Parameter manager: Reference to an IOHIDManagerRef.

Parameter callback: Pointer to a callback method of type IOHIDDeviceCallback.

Parameter context: Pointer to data to be passed to the callback.

§Safety
  • callback must be implemented correctly.
  • context must be a valid pointer or null.
Source

pub unsafe fn register_input_report_callback( &self, callback: IOHIDReportCallback, context: *mut c_void, )

Registers a callback to be used when an input report is issued by any enumerated device.

An input report is an interrupt driver report issued by a device. If a dispatch queue is set, this call must occur before activation.

Parameter manager: Reference to an IOHIDManagerRef.

Parameter callback: Pointer to a callback method of type IOHIDReportCallback.

Parameter context: Pointer to data to be passed to the callback.

§Safety
  • callback must be implemented correctly.
  • context must be a valid pointer or null.
Source

pub unsafe fn register_input_report_with_time_stamp_callback( &self, callback: IOHIDReportWithTimeStampCallback, context: *mut c_void, )

Registers a callback to be used when an input report is issued by any enumerated device.

An input report is an interrupt driver report issued by a device. If a dispatch queue is set, this call must occur before activation.

Parameter manager: Reference to an IOHIDManagerRef.

Parameter callback: Pointer to a callback method of type IOHIDReportWithTimeStampCallback.

Parameter context: Pointer to data to be passed to the callback.

§Safety
  • callback must be implemented correctly.
  • context must be a valid pointer or null.
Source

pub unsafe fn register_input_value_callback( &self, callback: IOHIDValueCallback, context: *mut c_void, )

Registers a callback to be used when an input value is issued by any enumerated device.

An input element refers to any element of type kIOHIDElementTypeInput and is usually issued by interrupt driven reports. If a dispatch queue is set, this call must occur before activation.

Parameter manager: Reference to an IOHIDManagerRef.

Parameter callback: Pointer to a callback method of type IOHIDValueCallback.

Parameter context: Pointer to data to be passed to the callback.

§Safety
  • callback must be implemented correctly.
  • context must be a valid pointer or null.
Source

pub unsafe fn set_input_value_matching(&self, matching: Option<&CFDictionary>)

Sets matching criteria for input values received via IOHIDManagerRegisterInputValueCallback.

Matching keys are prefixed by kIOHIDElement and declared in <IOKit /hid/IOHIDKeys.h>. Passing a NULL dictionary will result in all devices being enumerated. Any subsequent calls will cause the hid manager to release previously matched input elements and restart the matching process using the revised criteria. If interested in multiple, specific device elements, please defer to using IOHIDManagerSetInputValueMatchingMultiple. If a dispatch queue is set, this call must occur before activation.

Parameter manager: Reference to an IOHIDManager.

Parameter matching: CFDictionaryRef containg device matching criteria.

§Safety

matching generics must be of the correct type.

Source

pub unsafe fn set_input_value_matching_multiple( &self, multiple: Option<&CFArray>, )

Sets multiple matching criteria for input values received via IOHIDManagerRegisterInputValueCallback.

Matching keys are prefixed by kIOHIDElement and declared in <IOKit /hid/IOHIDKeys.h>. This method is useful if interested in multiple, specific elements. If a dispatch queue is set, this call must occur before activation.

Parameter manager: Reference to an IOHIDManager.

Parameter multiple: CFArrayRef containing multiple CFDictionaryRef objects containing input element matching criteria.

§Safety

multiple generic must be of the correct type.

Source

pub fn save_to_property_domain( &self, application_id: &CFString, user_name: &CFString, host_name: &CFString, options: IOOptionBits, )

Used to write out the current properties to a specific domain.

Using this function will cause the persistent properties to be saved out replacing any properties that already existed in the specified domain. All arguments must be non-NULL except options.

Parameter manager: Reference to an IOHIDManager.

Parameter applicationID: Reference to a CFPreferences applicationID.

Parameter userName: Reference to a CFPreferences userName.

Parameter hostName: Reference to a CFPreferences hostName.

Parameter options: Reserved for future use.

Methods from Deref<Target = CFType>§

Source

pub fn downcast_ref<T>(&self) -> Option<&T>
where T: ConcreteType,

Attempt to downcast the type to that of type T.

This is the reference-variant. Use CFRetained::downcast if you want to convert a retained type. See also ConcreteType for more details on which types support being converted to.

Source

pub fn retain_count(&self) -> usize

Get the reference count of the object.

This function may be useful for debugging. You normally do not use this function otherwise.

Beware that some things (like CFNumbers, small CFStrings etc.) may not have a normal retain count for optimization purposes, and can return usize::MAX in that case.

Trait Implementations§

Source§

impl AsRef<AnyObject> for IOHIDManager

Source§

fn as_ref(&self) -> &AnyObject

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl AsRef<CFType> for IOHIDManager

Source§

fn as_ref(&self) -> &CFType

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl AsRef<IOHIDManager> for IOHIDManager

Source§

fn as_ref(&self) -> &Self

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl Borrow<AnyObject> for IOHIDManager

Source§

fn borrow(&self) -> &AnyObject

Immutably borrows from an owned value. Read more
Source§

impl Borrow<CFType> for IOHIDManager

Source§

fn borrow(&self) -> &CFType

Immutably borrows from an owned value. Read more
Source§

impl ConcreteType for IOHIDManager

Source§

fn type_id() -> CFTypeID

Returns the type identifier of all IOHIDManager instances.

Source§

impl Debug for IOHIDManager

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Deref for IOHIDManager

Source§

type Target = CFType

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl Hash for IOHIDManager

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Message for IOHIDManager

Source§

fn retain(&self) -> Retained<Self>
where Self: Sized,

Increment the reference count of the receiver. Read more
Source§

impl PartialEq for IOHIDManager

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl RefEncode for IOHIDManager

Source§

const ENCODING_REF: Encoding

The Objective-C type-encoding for a reference of this type. Read more
Source§

impl Type for IOHIDManager

Source§

fn retain(&self) -> CFRetained<Self>
where Self: Sized,

Increment the reference count of the receiver. Read more
Source§

fn as_concrete_TypeRef(&self) -> &Self

👎Deprecated: this is redundant
Helper for easier transition from the core-foundation crate.
Source§

unsafe fn wrap_under_get_rule(ptr: *const Self) -> CFRetained<Self>
where Self: Sized,

👎Deprecated: use CFRetained::retain
Helper for easier transition from the core-foundation crate. Read more
Source§

fn as_CFTypeRef(&self) -> &CFType
where Self: AsRef<CFType>,

👎Deprecated: this is redundant (CF types deref to CFType)
Helper for easier transition from the core-foundation crate.
Source§

unsafe fn wrap_under_create_rule(ptr: *const Self) -> CFRetained<Self>
where Self: Sized,

👎Deprecated: use CFRetained::from_raw
Helper for easier transition from the core-foundation crate. Read more
Source§

impl Eq for IOHIDManager

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> AutoreleaseSafe for T
where T: ?Sized,