openusb_set_event_callback, openusb_coldplug_callbacks_done

OpenUSB Developers Guide
Prev |  | Next

# `openusb_set_event_callback, openusb_coldplug_callbacks_done`

## Name

`openusb_set_event_callback, openusb_coldplug_callbacks_done` -- Set event callbacks or Waiting for coldplug events completion

## Synopsis

``int32_t openusb_set_event_callback`(openusb_handle_t handle , openusb_event_t type , openusb_event_callback_t callback , void *arg );`

``void openusb_coldplug_callbacks_done`(openusb_handle_t handle);`

## Parameters

`handle` - An openusb instance handle, obtained in `openusb_init`.

`type` - Event type.

`callback` - Pointer to callback function.

`arg` - Arguments passed to `callback`

## Description

Application can call `openusb_set_event_callback()` to register with openusb for events and corresponding callbacks. When these events occur, the `callback` will be called with `arg`, if any, as the parameter.

The supported events type:

              typedef enum openusb_event {
                    USB_ATTACH = 0,     /* attachment of device */
                    USB_REMOVE,         /* detachment of device */
                    USB_SUSPEND,        /* device suspend */
                    USB_RESUME,         /* device resume */
                    USB_HC_ATTACH,      /* host controller attachment */
                    USB_HC_REMOVE,      /* host controller detachment */
                    USB_COLDPLUG_COMPLETED, /* first scan of device completed */
              } openusb_event_t;

openusb_event_callback_t has this prototype:

              typedef void    (*openusb_event_callback_t)(openusb_handle_t handle,
                  openusb_devid_t devid, openusb_event_t event, void *arg);

Application can call openusb_coldplug_callbacks_done() to block execution until end of coldplug events.

## Return Value

`openusb_set_event_callback` returns 0 if succeed. Otherwise, a openusb error will be returned.

OPENUSB_SUCCESS - Callback was successfully set.

OPENUSB_BADARG - Invalid arguments, either invalid type or callback.

OPENUSB_INVALID_HANDLE - Invalid handle.

OPENUSB_NO_RESOURCES - Memory allocation failure.

## See Also

`openusb_init, openusb_fini`

Prev | Home | Next
`openusb_set_debug` | Up | `openusb_set_default_timeout`