libusb_hotplug_register_callback method

int libusb_hotplug_register_callback(
  1. Pointer<libusb_context> ctx,
  2. int events,
  3. int flags,
  4. int vendor_id,
  5. int product_id,
  6. int dev_class,
  7. libusb_hotplug_callback_fn cb_fn,
  8. Pointer<Void> user_data,
  9. Pointer<libusb_hotplug_callback_handle> callback_handle,
)

\ingroup libusb_hotplug Register a hotplug callback function

Register a callback with the libusb_context. The callback will fire when a matching event occurs on a matching device. The callback is armed until either it is deregistered with libusb_hotplug_deregister_callback() or the supplied callback returns 1 to indicate it is finished processing events.

If the \ref LIBUSB_HOTPLUG_ENUMERATE is passed the callback will be called with a \ref LIBUSB_HOTPLUG_EVENT_DEVICE_ARRIVED for all devices already plugged into the machine. Note that libusb modifies its internal device list from a separate thread, while calling hotplug callbacks from libusb_handle_events(), so it is possible for a device to already be present on, or removed from, its internal device list, while the hotplug callbacks still need to be dispatched. This means that when using \ref LIBUSB_HOTPLUG_ENUMERATE, your callback may be called twice for the arrival of the same device, once from libusb_hotplug_register_callback() and once from libusb_handle_events(); and/or your callback may be called for the removal of a device for which an arrived call was never made.

Since version 1.0.16, \ref LIBUSB_API_VERSION >= 0x01000102

\paramin ctx context to register this callback with \paramin events bitwise or of events that will trigger this callback. See \ref libusb_hotplug_event \paramin flags hotplug callback flags. See \ref libusb_hotplug_flag \paramin vendor_id the vendor id to match or \ref LIBUSB_HOTPLUG_MATCH_ANY \paramin product_id the product id to match or \ref LIBUSB_HOTPLUG_MATCH_ANY \paramin dev_class the device class to match or \ref LIBUSB_HOTPLUG_MATCH_ANY \paramin cb_fn the function to be invoked on a matching event/device \paramin user_data user data to pass to the callback function \paramout callback_handle pointer to store the handle of the allocated callback (can be NULL) \returns LIBUSB_SUCCESS on success LIBUSB_ERROR code on failure

Implementation

int libusb_hotplug_register_callback(
  ffi.Pointer<libusb_context> ctx,
  int events,
  int flags,
  int vendor_id,
  int product_id,
  int dev_class,
  libusb_hotplug_callback_fn cb_fn,
  ffi.Pointer<ffi.Void> user_data,
  ffi.Pointer<libusb_hotplug_callback_handle> callback_handle,
) {
  return _libusb_hotplug_register_callback(
    ctx,
    events,
    flags,
    vendor_id,
    product_id,
    dev_class,
    cb_fn,
    user_data,
    callback_handle,
  );
}