libusb
Typedefs | Enumerations | Functions
Device hotplug event notification

This page details how to use the libusb hotplug interface. More...

Typedefs

typedef int libusb_hotplug_callback_handle
 Callback handle.
typedef int(* libusb_hotplug_callback_fn )(libusb_context *ctx, libusb_device *device, libusb_hotplug_event event, void *user_data)
 Hotplug callback function type.

Enumerations

enum  libusb_hotplug_flag { LIBUSB_HOTPLUG_ENUMERATE = 1 }
 Flags for hotplug events. More...
enum  libusb_hotplug_event { LIBUSB_HOTPLUG_EVENT_DEVICE_ARRIVED = 0x01, LIBUSB_HOTPLUG_EVENT_DEVICE_LEFT = 0x02 }
 Hotplug events. More...
enum  { LIBUSB_HOTPLUG_CLASS_ANY = -1, LIBUSB_HOTPLUG_VENDORID_ANY = -2, LIBUSB_HOTPLUG_PRODUCTID_ANY = -3 }
 Wildcard matching for hotplug events. More...

Functions

int libusb_hotplug_register_callback (libusb_context *ctx, libusb_hotplug_event events, libusb_hotplug_flag flags, int vendor_id, int product_id, int dev_class, libusb_hotplug_callback_fn cb_fn, void *user_data, libusb_hotplug_callback_handle *handle)
 Register a hotplug callback function.
void libusb_hotplug_deregister_callback (libusb_context *ctx, libusb_hotplug_callback_handle handle)
 Deregisters a hotplug callback.

Detailed Description

This page details how to use the libusb hotplug interface.


Typedef Documentation

Callback handle.

Callbacks handles are generated by libusb_hotplug_register_callback() and returned by libusb_hotplug_deregister_callback() or returning 1 from the callback function.

For more information, see Device hotplug event notification.

typedef int( * libusb_hotplug_callback_fn)(libusb_context *ctx, libusb_device *device, libusb_hotplug_event event, void *user_data)

Hotplug callback function type.

When requesting hotplug support, you pass a pointer to a callback function of this type. This callback may be called by an internal event thread and as such should do minimal processing before returning. libusb will call this function later, when a matching device has been connected. See Device hotplug event notification for more information.

Parameters:
libusb_contextcontext of this notification
devicelibusb_device this event occurred on
eventevent that occurred
user_datauser data provided when this callback was registered
Returns:
bool whether this callback is finished processing events. returning 1 will cause this callback to be deregistered

Enumeration Type Documentation

Flags for hotplug events.

Enumerator:
LIBUSB_HOTPLUG_ENUMERATE 

Arm the callback and fire it for all matching attached devices.

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

anonymous enum

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

int libusb_hotplug_register_callback ( libusb_context ctx,
libusb_hotplug_event  events,
libusb_hotplug_flag  flags,
int  vendor_id,
int  product_id,
int  dev_class,
libusb_hotplug_callback_fn  cb_fn,
void *  user_data,
libusb_hotplug_callback_handle handle 
)

Register a hotplug callback function.

Parameters:
[in]ctxcontext to register this callback with
[in]eventsthe events that will trigger this callback
[in]flagshotplug callback flags (described above)
[in]vendor_idthe vendor id to match or LIBUSB_HOTPLUG_PRODUCTID_ANY
[in]product_idthe product id to match or LIBUSB_HOTPLUG_PRODUCTID_ANY
[in]dev_classthe device class to match or LIBUSB_HOTPLUG_CLASS_ANY
[in]cb_fnthe function to be invoked on a matching event/device
[in]user_datauser data to pass to the callback function
[out]handlepointer to store the handle of the allocated callback (can be NULL)
Returns:
LIBUSB_SUCCESS on success LIBUSB_ERROR code on failure
void libusb_hotplug_deregister_callback ( libusb_context ctx,
libusb_hotplug_callback_handle  handle 
)

Deregisters a hotplug callback.

Do not call this function from within a callback function. This will result in deadlock.

Parameters:
[in]ctxcontext this callback is registered with
[in]handlethe handle of the callback to deregister