This page details how to use the libusb hotplug interface.
More...
Detailed Description
This page details how to use the libusb hotplug interface.
Typedef Documentation
Hotplug callback function type.
When requesting hotplug support, you pass a pointer to a callback function of this type. libusb will call this function later, when a matching device has been connected. See Device hotplug event notification for more information.
- Parameters:
-
libusb_context | context of this notification |
device | libusb_device this event occurred on |
event | event that occurred |
user_data | user data provided when this callback was registered |
Enumeration Type Documentation
Flags for hotplug events.
- Enumerator:
LIBUSB_HOTPLUG_PERSIST |
The hotplug event will persist until removed with libusb_hotplug_deregister_callback() or libusb_exit()
|
LIBUSB_HOTPLUG_ONCE |
The hotplug callback will fire once and be deregistered.
It is safe to free the callback in the callback function if this flag is set.
|
Hotplug events.
- Enumerator:
LIBUSB_HOTPLUG_EVENT_DEVICE_ARRIVED |
A device has been plugged in and is ready to use.
|
LIBUSB_HOTPLUG_EVENT_DEVICE_LEFT |
A device has left and is no longer available.
It is the user's responsibility to call libusb_close on any handle associated with a disconnected device. It is safe to call libusb_get_device_descriptor on a device that has left
|
Wildcard matching for hotplug events.
- Enumerator:
LIBUSB_HOTPLUG_CLASS_ANY |
Match any device class.
|
LIBUSB_HOTPLUG_VENDORID_ANY |
Match any vendor id.
|
LIBUSB_HOTPLUG_PRODUCTID_ANY |
Match any product id.
|
Function Documentation
Helper function to populate the required libusb_hotplug_callback fields for hotplug event notification.
- Parameters:
-
cb | the callback to polulate |
ctx | the context associated with this callback |
event | the events that will trigger this callback |
flags | hotplug callback flags (described above) |
vendor_id | the vendor id to match or LIBUSB_HOTPLUG_PRODUCTID_ANY |
product_id | the product id to match or LIBUSB_HOTPLUG_PRODUCTID_ANY |
dev_class | the device class to match or LIBUSB_HOTPLUG_CLASS_ANY |
cb_fn | the function to be invoked on a matching event/device |
user_data | user data to pass to the callback function |
Registers a prepared hotplug callback.
- Parameters:
-
cb | the callback to register |
Deregisters a hotplug callback.
Do not call this function from within a callback function. This will result in deadlock.
- Parameters:
-
cb | the callback to deregister |