Skip to main content

Module async_api

Module async_api 

Source
Available on crate feature async only.
Expand description

Executor-agnostic async stream wrappers for IOKit HID callback APIs.

Each function on an IOHIDManager, IOHIDDevice, or IOHIDQueue that accepts a C callback is wrapped here as a doom_fish_utils::stream::BoundedAsyncStream of typed events.

§Run-loop convention

Each stream subscription spawns a dedicated background thread that runs a CFRunLoop. The IOKit source (manager / device / queue) is scheduled on that thread’s run loop, so callbacks fire independently of any async executor or the caller’s run loop. When the stream handle is dropped the run loop is stopped, the thread is joined, and all IOKit resources are released in the background thread before drop returns.

§Stream surfaces

Stream typeIOKit registrationEvent payload
ManagerInputValueStreamIOHIDManagerRegisterInputValueCallbackInputValueEvent
ManagerDeviceMatchingStreamIOHIDManagerRegisterDeviceMatchingCallbackDeviceMatchingEvent
ManagerDeviceRemovalStreamIOHIDManagerRegisterDeviceRemovalCallbackDeviceRemovalEvent
ManagerInputReportStreamIOHIDManagerRegisterInputReportCallbackInputReportEvent
DeviceRemovalStreamIOHIDDeviceRegisterRemovalCallback()
DeviceInputValueStreamIOHIDDeviceRegisterInputValueCallbackHidValue
QueueValueStreamIOHIDQueueRegisterValueAvailableCallback()

§Prerequisites for manager-level streams

Before calling ManagerInputValueStream::subscribe, ManagerDeviceMatchingStream::subscribe, ManagerDeviceRemovalStream::subscribe, or ManagerInputReportStream::subscribe you must call crate::HidManager::set_device_matching (or its _dict / _multiple variants) on the manager. Scheduling an IOHIDManager on a CFRunLoop without a device-matching filter causes IOKit to raise SIGTRAP; passing None matches all devices.

use iohidmanager::prelude::*;
use iohidmanager::async_api::ManagerDeviceMatchingStream;

let manager = HidManager::new().unwrap();
manager.set_device_matching(None).unwrap(); // required before any subscribe call
let stream = ManagerDeviceMatchingStream::subscribe(&manager, 32);

Structs§

DeviceInputValueStream
Async stream of HidValue events from IOHIDDeviceRegisterInputValueCallback.
DeviceMatchingEvent
Event emitted by ManagerDeviceMatchingStream.
DeviceRemovalEvent
Event emitted by ManagerDeviceRemovalStream.
DeviceRemovalStream
Async stream of () events from IOHIDDeviceRegisterRemovalCallback.
InputReportEvent
Event emitted by ManagerInputReportStream.
InputValueEvent
Event emitted by ManagerInputValueStream and DeviceInputValueStream.
ManagerDeviceMatchingStream
Async stream of DeviceMatchingEvents from IOHIDManagerRegisterDeviceMatchingCallback.
ManagerDeviceRemovalStream
Async stream of DeviceRemovalEvents from IOHIDManagerRegisterDeviceRemovalCallback.
ManagerInputReportStream
Async stream of InputReportEvents from IOHIDManagerRegisterInputReportCallback.
ManagerInputValueStream
Async stream of InputValueEvents from IOHIDManagerRegisterInputValueCallback.
QueueValueStream
Async stream of () notifications from IOHIDQueueRegisterValueAvailableCallback.