Open Lighting Architecture: ola::usb::BaseLibUsbAdaptor Class Reference

| Open Lighting Architecture 0.10.9

Loading...
Searching...
No Matches
Public Member Functions | List of all members
ola::usb::BaseLibUsbAdaptor Class Reference

## Detailed Description

The base LibUsbAdaptor that passes most calls through to libusb.

Inheritance diagram for ola::usb::BaseLibUsbAdaptor:

## Public Member Functions
libusb_device * | RefDevice (libusb_device *dev)
| Wraps libusb_ref_device.
void | UnrefDevice (libusb_device *dev)
| Wraps libusb_unref_device.
int | SetConfiguration (libusb_device_handle *dev, int configuration)
| Wraps libusb_set_configuration.
int | ClaimInterface (libusb_device_handle *dev, int interface_number)
| Wraps libusb_claim_interface.
int | DetachKernelDriver (libusb_device_handle *dev, int interface_number)
| Detach a kernel driver.
int | GetDeviceDescriptor (libusb_device *dev, struct libusb_device_descriptor *descriptor)
| Wraps libusb_get_device_descriptor.
int | GetActiveConfigDescriptor (libusb_device *dev, struct libusb_config_descriptor **config)
| Wraps libusb_get_active_config_descriptor.
int | GetConfigDescriptor (libusb_device *dev, uint8_t config_index, struct libusb_config_descriptor **config)
| Wraps libusb_get_config_descriptor.
void | FreeConfigDescriptor (struct libusb_config_descriptor *config)
| Wraps busb_free_config_descriptor.
bool | GetStringDescriptor (libusb_device_handle *usb_handle, uint8_t descriptor_index, std::string *data)
| Get the value of a string descriptor.
struct libusb_transfer * | AllocTransfer (int iso_packets)
| Wraps libusb_alloc_transfer.
void | FreeTransfer (struct libusb_transfer *transfer)
| Wraps libusb_free_transfer.
int | SubmitTransfer (struct libusb_transfer *transfer)
| Wraps libusb_submit_transfer.
int | CancelTransfer (struct libusb_transfer *transfer)
| Wraps libusb_cancel_transfer.
void | FillControlSetup (unsigned char *buffer, uint8_t bmRequestType, uint8_t bRequest, uint16_t wValue, uint16_t wIndex, uint16_t wLength)
| Wraps libusb_fill_control_setup.
void | FillControlTransfer (struct libusb_transfer *transfer, libusb_device_handle *dev_handle, unsigned char *buffer, libusb_transfer_cb_fn callback, void *user_data, unsigned int timeout)
| Wraps libusb_fill_control_transfer.
void | FillBulkTransfer (struct libusb_transfer *transfer, libusb_device_handle *dev_handle, unsigned char endpoint, unsigned char *buffer, int length, libusb_transfer_cb_fn callback, void *user_data, unsigned int timeout)
| Wraps libusb_fill_bulk_transfer.
void | FillInterruptTransfer (struct libusb_transfer *transfer, libusb_device_handle *dev_handle, unsigned char endpoint, unsigned char *buffer, int length, libusb_transfer_cb_fn callback, void *user_data, unsigned int timeout)
| Wraps libusb_fill_interrupt_transfer.
int | ControlTransfer (libusb_device_handle *dev_handle, uint8_t bmRequestType, uint8_t bRequest, uint16_t wValue, uint16_t wIndex, unsigned char *data, uint16_t wLength, unsigned int timeout)
| Wraps libusb_control_transfer().
int | BulkTransfer (struct libusb_device_handle *dev_handle, unsigned char endpoint, unsigned char *data, int length, int *transferred, unsigned int timeout)
| Wraps libusb_bulk_transfer.
int | InterruptTransfer (libusb_device_handle *dev_handle, unsigned char endpoint, unsigned char *data, int length, int *actual_length, unsigned int timeout)
| Wraps libusb_interrupt_transfer.
USBDeviceID | GetDeviceId (libusb_device *device) const
| Get the USBDeviceID for a device.
Public Member Functions inherited from ola::usb::LibUsbAdaptor
virtual bool | OpenDevice (libusb_device *usb_device, libusb_device_handle **usb_handle)=0
| Open a libusb device.
virtual bool | OpenDeviceAndClaimInterface (libusb_device *usb_device, int interface, libusb_device_handle **usb_handle)=0
| Open a libusb device and claim an interface.
virtual void | Close (libusb_device_handle *usb_handle)=0
| Close a libusb handle.

## Additional Inherited Members
Static Public Member Functions inherited from ola::usb::LibUsbAdaptor
static bool | Initialize (struct libusb_context **context)
| Initialize a new libusb context.
static bool | GetDeviceInfo (struct libusb_device *usb_device, const struct libusb_device_descriptor &device_descriptor, DeviceInformation *device_info)
| Fetch the manufacturer, product and serial strings from a device.
static bool | CheckManufacturer (const std::string &expected, const DeviceInformation &device_info)
| Check if the manufacturer string matches the expected value.
static bool | CheckProduct (const std::string &expected, const DeviceInformation &device_info)
| Check if the product string matches the expected value.
static bool | HotplugSupported ()
| Check if this platform supports hotplug.
static std::string | ErrorCodeToString (const int error_code)
| Try and convert an error code to a string.

## Member Function Documentation

## ◆ AllocTransfer()

struct libusb_transfer * ola::usb::BaseLibUsbAdaptor::AllocTransfer | ( | int | iso_packets | ) |
| virtual

Wraps libusb_alloc_transfer.

Parameters

  iso_packets | number of isochronous packet descriptors to allocate

Returns
  a newly allocated transfer, or NULL on error

Implements ola::usb::LibUsbAdaptor.

## ◆ BulkTransfer()

int ola::usb::BaseLibUsbAdaptor::BulkTransfer | ( | struct libusb_device_handle * | dev_handle,
|  | unsigned char | endpoint,
|  | unsigned char * | data,
|  | int | length,
|  | int * | transferred,
|  | unsigned int | timeout )
| virtual

Wraps libusb_bulk_transfer.

Returns
  0 on success and populates transferred
  LIBUSB_ERROR_TIMEOUT if the transfer timed out (and populates transferred)
  LIBUSB_ERROR_PIPE if the endpoint halted
  LIBUSB_ERROR_OVERFLOW if the device offered more data, see
  LIBUSB_ERROR_NO_DEVICE if the device has been disconnected
  another LIBUSB_ERROR code on other failures

Implements ola::usb::LibUsbAdaptor.

## ◆ CancelTransfer()

int ola::usb::BaseLibUsbAdaptor::CancelTransfer | ( | struct libusb_transfer * | transfer | ) |
| virtual

Wraps libusb_cancel_transfer.

Parameters

  transfer | the transfer to cancel

Returns
  0 on success
  LIBUSB_ERROR_NOT_FOUND if the transfer is already complete or cancelled.
  a LIBUSB_ERROR code on failure

Implements ola::usb::LibUsbAdaptor.

## ◆ ClaimInterface()

int ola::usb::BaseLibUsbAdaptor::ClaimInterface | ( | libusb_device_handle * | dev,
|  | int | interface_number )
| virtual

Wraps libusb_claim_interface.

Parameters

  dev | a device handle
  interface_number | the bInterfaceNumber of the interface you wish to claim

Returns
  0 on success
  LIBUSB_ERROR_NOT_FOUND if the requested interface does not exist
  LIBUSB_ERROR_BUSY if another program or driver has claimed the interface
  LIBUSB_ERROR_NO_DEVICE if the device has been disconnected
  a LIBUSB_ERROR code on other failure

Implements ola::usb::LibUsbAdaptor.

## ◆ ControlTransfer()

int ola::usb::BaseLibUsbAdaptor::ControlTransfer | ( | libusb_device_handle * | dev_handle,
|  | uint8_t | bmRequestType,
|  | uint8_t | bRequest,
|  | uint16_t | wValue,
|  | uint16_t | wIndex,
|  | unsigned char * | data,
|  | uint16_t | wLength,
|  | unsigned int | timeout )
| virtual

Wraps libusb_control_transfer().

Parameters

  | dev_handle | a handle for the device to communicate with
  | bmRequestType | the request type field for the setup packet
  | bRequest | the request field for the setup packet
  | wValue | the value field for the setup packet
  | wIndex | the index field for the setup packet
  [in,out] | data | a suitably-sized data buffer for either input or output (depending on direction bits within bmRequestType)
  | wLength | the length field for the setup packet. The data buffer should be at least this size.
  | timeout | timeout (in milliseconds) that this function should wait before giving up due to no response being received. For an unlimited timeout, use value 0.

Returns
  on success, the number of bytes actually transferred

Implements ola::usb::LibUsbAdaptor.

## ◆ DetachKernelDriver()

int ola::usb::BaseLibUsbAdaptor::DetachKernelDriver | ( | libusb_device_handle * | dev,
|  | int | interface_number )
| virtual

Detach a kernel driver.

Parameters

  dev | a device handle
  interface_number | the interface to detach the driver from

Returns
  0 on success
  LIBUSB_ERROR_NOT_FOUND if no kernel driver was active
  LIBUSB_ERROR_INVALID_PARAM if the interface does not exist
  LIBUSB_ERROR_NO_DEVICE if the device has been disconnected
  LIBUSB_ERROR_NOT_SUPPORTED on platforms where the functionality is not available
  another LIBUSB_ERROR code on other failure

Implements ola::usb::LibUsbAdaptor.

## ◆ FillBulkTransfer()

void ola::usb::BaseLibUsbAdaptor::FillBulkTransfer | ( | struct libusb_transfer * | transfer,
|  | libusb_device_handle * | dev_handle,
|  | unsigned char | endpoint,
|  | unsigned char * | buffer,
|  | int | length,
|  | libusb_transfer_cb_fn | callback,
|  | void * | user_data,
|  | unsigned int | timeout )
| virtual

Wraps libusb_fill_bulk_transfer.

Parameters

  [out] | transfer | the transfer to populate
  | dev_handle | handle of the device that will handle the transfer
  | endpoint | address of the endpoint where this transfer will be sent
  | buffer | data buffer. If provided, this function will interpret the first 8 bytes as a setup packet and infer the transfer length from that. This pointer must be aligned to at least 2 bytes boundary.
  | length | length of data buffer
  | callback | callback function to be invoked on transfer completion
  | user_data | user data to pass to callback function
  | timeout | timeout for the transfer in milliseconds

Implements ola::usb::LibUsbAdaptor.

## ◆ FillControlSetup()

void ola::usb::BaseLibUsbAdaptor::FillControlSetup | ( | unsigned char * | buffer,
|  | uint8_t | bmRequestType,
|  | uint8_t | bRequest,
|  | uint16_t | wValue,
|  | uint16_t | wIndex,
|  | uint16_t | wLength )
| virtual

Wraps libusb_fill_control_setup.

Parameters

  [out] | buffer | buffer to output the setup packet into This pointer must be aligned to at least 2 bytes boundary.
  | bmRequestType | the request type field for the setup packet
  | bRequest | the request field for the setup packet
  | wValue | the value field for the setup packet
  | wIndex | the index field for the setup packet
  | wLength | the length field for the setup packet. The data buffer should be at least this size.

Implements ola::usb::LibUsbAdaptor.

## ◆ FillControlTransfer()

void ola::usb::BaseLibUsbAdaptor::FillControlTransfer | ( | struct libusb_transfer * | transfer,
|  | libusb_device_handle * | dev_handle,
|  | unsigned char * | buffer,
|  | libusb_transfer_cb_fn | callback,
|  | void * | user_data,
|  | unsigned int | timeout )
| virtual

Wraps libusb_fill_control_transfer.

Parameters

  [out] | transfer | the transfer to populate
  | dev_handle | handle of the device that will handle the transfer
  | buffer | data buffer. If provided, this function will interpret the first 8 bytes as a setup packet and infer the transfer length from that. This pointer must be aligned to at least 2 bytes boundary.
  | callback | callback function to be invoked on transfer completion
  | user_data | user data to pass to callback function
  | timeout | timeout for the transfer in milliseconds

Implements ola::usb::LibUsbAdaptor.

## ◆ FillInterruptTransfer()

void ola::usb::BaseLibUsbAdaptor::FillInterruptTransfer | ( | struct libusb_transfer * | transfer,
|  | libusb_device_handle * | dev_handle,
|  | unsigned char | endpoint,
|  | unsigned char * | buffer,
|  | int | length,
|  | libusb_transfer_cb_fn | callback,
|  | void * | user_data,
|  | unsigned int | timeout )
| virtual

Wraps libusb_fill_interrupt_transfer.

Parameters

  [out] | transfer | the transfer to populate
  | dev_handle | handle of the device that will handle the transfer
  | endpoint | address of the endpoint where this transfer will be sent
  | buffer | data buffer
  | length | length of data buffer
  | callback | callback function to be invoked on transfer completion
  | user_data | user data to pass to callback function
  | timeout | timeout for the transfer in milliseconds

Implements ola::usb::LibUsbAdaptor.

## ◆ FreeConfigDescriptor()

void ola::usb::BaseLibUsbAdaptor::FreeConfigDescriptor | ( | struct libusb_config_descriptor * | config | ) |
| virtual

Wraps busb_free_config_descriptor.

Parameters

  config | the configuration descriptor to free

Implements ola::usb::LibUsbAdaptor.

## ◆ FreeTransfer()

void ola::usb::BaseLibUsbAdaptor::FreeTransfer | ( | struct libusb_transfer * | transfer | ) |
| virtual

Wraps libusb_free_transfer.

Parameters

  transfer | the transfer to free

Implements ola::usb::LibUsbAdaptor.

## ◆ GetActiveConfigDescriptor()

int ola::usb::BaseLibUsbAdaptor::GetActiveConfigDescriptor | ( | libusb_device * | dev,
|  | struct libusb_config_descriptor ** | config )
| virtual

Wraps libusb_get_active_config_descriptor.

Parameters

  | dev | a device
  [out] | config | output location for the USB configuration descriptor. Only valid if 0 was returned. Must be freed with libusb_free_config_descriptor() after use.

Returns
  0 on success
  LIBUSB_ERROR_NOT_FOUND if the device is in unconfigured state
  another LIBUSB_ERROR code on error

Implements ola::usb::LibUsbAdaptor.

## ◆ GetConfigDescriptor()

int ola::usb::BaseLibUsbAdaptor::GetConfigDescriptor | ( | libusb_device * | dev,
|  | uint8_t | config_index,
|  | struct libusb_config_descriptor ** | config )
| virtual

Wraps libusb_get_config_descriptor.

Parameters

  | dev | a device
  | config_index | the index of the configuration you wish to retrieve
  [out] | config | output location for the USB configuration descriptor. Only valid if 0 was returned. Must be freed with libusb_free_config_descriptor() after use.

Returns
  0 on success
  LIBUSB_ERROR_NOT_FOUND if the configuration does not exist
  another LIBUSB_ERROR code on error

Implements ola::usb::LibUsbAdaptor.

## ◆ GetDeviceDescriptor()

int ola::usb::BaseLibUsbAdaptor::GetDeviceDescriptor | ( | libusb_device * | dev,
|  | struct libusb_device_descriptor * | descriptor )
| virtual

Wraps libusb_get_device_descriptor.

Parameters

  | dev | a device
  [out] | descriptor | The device descriptor.

Returns
  0 on success
  another LIBUSB_ERROR code on error

Implements ola::usb::LibUsbAdaptor.

## ◆ GetDeviceId()

USBDeviceID ola::usb::BaseLibUsbAdaptor::GetDeviceId | ( | libusb_device * | device | ) | const
| virtual

Get the USBDeviceID for a device.

Parameters

  device | The libusb device to get the ID of.

Returns
  The USBDeviceID for this device.

Implements ola::usb::LibUsbAdaptor.

## ◆ GetStringDescriptor()

bool ola::usb::BaseLibUsbAdaptor::GetStringDescriptor | ( | libusb_device_handle * | usb_handle,
|  | uint8_t | descriptor_index,
|  | std::string * | data )
| virtual

Get the value of a string descriptor.

Parameters

  | usb_handle | The USB device handle
  | descriptor_index | The index of the string descriptor to fetch.
  [out] | data | The value of the string descriptor.

Returns
  true if the string descriptor was retrieved, false otherwise.

Implements ola::usb::LibUsbAdaptor.

## ◆ InterruptTransfer()

int ola::usb::BaseLibUsbAdaptor::InterruptTransfer | ( | libusb_device_handle * | dev_handle,
|  | unsigned char | endpoint,
|  | unsigned char * | data,
|  | int | length,
|  | int * | actual_length,
|  | unsigned int | timeout )
| virtual

Wraps libusb_interrupt_transfer.

Returns
  0 on success and populates transferred
  LIBUSB_ERROR_TIMEOUT if the transfer timed out
  LIBUSB_ERROR_PIPE if the endpoint halted
  LIBUSB_ERROR_OVERFLOW if the device offered more data, see
  LIBUSB_ERROR_NO_DEVICE if the device has been disconnected
  another LIBUSB_ERROR code on other error

Implements ola::usb::LibUsbAdaptor.

## ◆ RefDevice()

libusb_device * ola::usb::BaseLibUsbAdaptor::RefDevice | ( | libusb_device * | dev | ) |
| virtual

Wraps libusb_ref_device.

Parameters

  dev | the device to reference

Returns
  the same device

Implements ola::usb::LibUsbAdaptor.

## ◆ SetConfiguration()

int ola::usb::BaseLibUsbAdaptor::SetConfiguration | ( | libusb_device_handle * | dev,
|  | int | configuration )
| virtual

Wraps libusb_set_configuration.

Parameters

  dev | a device handle
  configuration | the bConfigurationValue of the configuration you wish to activate, or -1 if you wish to put the device in an unconfigured state.

Returns
  0 on success
  LIBUSB_ERROR_NOT_FOUND if the requested configuration does not exist.
  LIBUSB_ERROR_BUSY if interfaces are currently claimed
  LIBUSB_ERROR_NO_DEVICE if the device has been disconnected
  another LIBUSB_ERROR code on other failure

Implements ola::usb::LibUsbAdaptor.

## ◆ SubmitTransfer()

int ola::usb::BaseLibUsbAdaptor::SubmitTransfer | ( | struct libusb_transfer * | transfer | ) |
| virtual

Wraps libusb_submit_transfer.

Parameters

  transfer | the transfer to submit

Returns
  0 on success
  LIBUSB_ERROR_NO_DEVICE if the device has been disconnected
  LIBUSB_ERROR_BUSY if the transfer has already been submitted.
  LIBUSB_ERROR_NOT_SUPPORTED if the transfer flags are not supported by the operating system.
  another LIBUSB_ERROR code on other failure

Implements ola::usb::LibUsbAdaptor.

## ◆ UnrefDevice()

void ola::usb::BaseLibUsbAdaptor::UnrefDevice | ( | libusb_device * | dev | ) |
| virtual

Wraps libusb_unref_device.

Parameters

  dev | the device to unreference.

Implements ola::usb::LibUsbAdaptor.

The documentation for this class was generated from the following files:

- libs/usb/LibUsbAdaptor.h
- libs/usb/LibUsbAdaptor.cpp