21 #ifndef LIBS_USB_LIBUSBADAPTOR_H_
22 #define LIBS_USB_LIBUSBADAPTOR_H_
28 #include "libs/usb/Types.h"
39 std::string manufacturer;
53 virtual libusb_device*
RefDevice(libusb_device *dev) = 0;
67 virtual bool OpenDevice(libusb_device *usb_device,
68 libusb_device_handle **usb_handle) = 0;
79 libusb_device *usb_device,
81 libusb_device_handle **usb_handle) = 0;
87 virtual void Close(libusb_device_handle *usb_handle) = 0;
103 int configuration) = 0;
118 int interface_number) = 0;
134 int interface_number) = 0;
146 struct libusb_device_descriptor *descriptor) = 0;
160 struct libusb_config_descriptor **config) = 0;
174 uint8_t config_index,
175 struct libusb_config_descriptor **config) = 0;
182 struct libusb_config_descriptor *config) = 0;
192 uint8_t descriptor_index,
193 std::string *data) = 0;
202 virtual struct libusb_transfer*
AllocTransfer(
int iso_packets) = 0;
208 virtual void FreeTransfer(
struct libusb_transfer *transfer) = 0;
244 uint8_t bmRequestType,
248 uint16_t wLength) = 0;
262 libusb_device_handle *dev_handle,
263 unsigned char *buffer,
264 libusb_transfer_cb_fn callback,
266 unsigned int timeout) = 0;
282 libusb_device_handle *dev_handle,
283 unsigned char endpoint,
284 unsigned char *buffer,
286 libusb_transfer_cb_fn callback,
288 unsigned int timeout) = 0;
302 libusb_device_handle *dev_handle,
303 unsigned char endpoint,
304 unsigned char *buffer,
306 libusb_transfer_cb_fn callback,
308 unsigned int timeout) = 0;
330 uint8_t bmRequestType,
336 unsigned int timeout) = 0;
348 virtual int BulkTransfer(
struct libusb_device_handle *dev_handle,
349 unsigned char endpoint,
353 unsigned int timeout) = 0;
365 unsigned char endpoint,
369 unsigned int timeout) = 0;
385 static bool Initialize(
struct libusb_context **context);
395 struct libusb_device *usb_device,
396 const struct libusb_device_descriptor &device_descriptor,
397 DeviceInformation *device_info);
406 const DeviceInformation &device_info);
415 const DeviceInformation &device_info);
438 libusb_device*
RefDevice(libusb_device *dev);
444 int ClaimInterface(libusb_device_handle *dev,
int interface_number);
450 struct libusb_device_descriptor *descriptor);
454 struct libusb_config_descriptor **config);
457 uint8_t config_index,
458 struct libusb_config_descriptor **config);
463 uint8_t descriptor_index,
476 uint8_t bmRequestType,
483 libusb_device_handle *dev_handle,
484 unsigned char *buffer,
485 libusb_transfer_cb_fn callback,
487 unsigned int timeout);
490 libusb_device_handle *dev_handle,
491 unsigned char endpoint,
492 unsigned char *buffer,
494 libusb_transfer_cb_fn callback,
496 unsigned int timeout);
499 libusb_device_handle *dev_handle,
500 unsigned char endpoint,
501 unsigned char *buffer,
503 libusb_transfer_cb_fn callback,
505 unsigned int timeout);
509 uint8_t bmRequestType,
515 unsigned int timeout);
517 int BulkTransfer(
struct libusb_device_handle *dev_handle,
518 unsigned char endpoint,
522 unsigned int timeout);
525 unsigned char endpoint,
529 unsigned int timeout);
545 libusb_device_handle **usb_handle);
549 libusb_device_handle **usb_handle);
551 void Close(libusb_device_handle *usb_handle);
570 libusb_device_handle **usb_handle);
574 libusb_device_handle **usb_handle);
576 void Close(libusb_device_handle *usb_handle);
579 uint8_t bmRequestType,
585 unsigned int timeout);
587 int BulkTransfer(
struct libusb_device_handle *dev_handle,
588 unsigned char endpoint,
592 unsigned int timeout);
595 unsigned char endpoint,
599 unsigned int timeout);
608 #endif // LIBS_USB_LIBUSBADAPTOR_H_
virtual 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)=0
Wraps libusb_fill_interrupt_transfer.
virtual void Close(libusb_device_handle *usb_handle)=0
Close a libusb handle.
int ClaimInterface(libusb_device_handle *dev, int interface_number)
Wraps libusb_claim_interface.
Definition: LibUsbAdaptor.cpp:191
virtual int SetConfiguration(libusb_device_handle *dev, int configuration)=0
Wraps libusb_set_configuration.
virtual int InterruptTransfer(libusb_device_handle *dev_handle, unsigned char endpoint, unsigned char *data, int length, int *actual_length, unsigned int timeout)=0
Wraps libusb_interrupt_transfer.
virtual int DetachKernelDriver(libusb_device_handle *dev, int interface_number)=0
Detatch a kernel driver.
bool OpenDevice(libusb_device *usb_device, libusb_device_handle **usb_handle)
Open a libusb device.
Definition: LibUsbAdaptor.cpp:357
static bool CheckManufacturer(const std::string &expected, const DeviceInformation &device_info)
Check if the manufacturer string matches the expected value.
Definition: LibUsbAdaptor.cpp:138
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.
Definition: LibUsbAdaptor.cpp:414
#define DISALLOW_COPY_AND_ASSIGN(TypeName)
Creates dummy copy constructor and assignment operator declarations.
Definition: Macro.h:44
void Close(libusb_device_handle *usb_handle)
Close a libusb handle.
Definition: LibUsbAdaptor.cpp:395
The base LibUsbAdaptor that passes most calls through to libusb.
Definition: LibUsbAdaptor.h:435
virtual int ClaimInterface(libusb_device_handle *dev, int interface_number)=0
Wraps libusb_claim_interface.
virtual void UnrefDevice(libusb_device *dev)=0
Wraps libusb_unref_device.
A LibUsbAdaptor for use with Syncronous widgets.
Definition: LibUsbAdaptor.h:540
virtual int BulkTransfer(struct libusb_device_handle *dev_handle, unsigned char endpoint, unsigned char *data, int length, int *transferred, unsigned int timeout)=0
Wraps libusb_bulk_transfer.
virtual void FreeConfigDescriptor(struct libusb_config_descriptor *config)=0
Wraps busb_free_config_descriptor.
virtual int CancelTransfer(struct libusb_transfer *transfer)=0
Wraps libusb_cancel_transfer.
int SubmitTransfer(struct libusb_transfer *transfer)
Wraps libusb_submit_transfer.
Definition: LibUsbAdaptor.cpp:264
virtual USBDeviceID GetDeviceId(libusb_device *device) const =0
Get the USBDeviceID for a device.
virtual 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)=0
Wraps libusb_control_transfer().
virtual int GetActiveConfigDescriptor(libusb_device *dev, struct libusb_config_descriptor **config)=0
Wraps libusb_get_active_config_descriptor.
virtual libusb_device * RefDevice(libusb_device *dev)=0
Wraps libusb_ref_device.
void UnrefDevice(libusb_device *dev)
Wraps libusb_unref_device.
Definition: LibUsbAdaptor.cpp:182
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.
Definition: LibUsbAdaptor.cpp:272
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.
Definition: LibUsbAdaptor.cpp:107
void FreeTransfer(struct libusb_transfer *transfer)
Wraps libusb_free_transfer.
Definition: LibUsbAdaptor.cpp:260
void FreeConfigDescriptor(struct libusb_config_descriptor *config)
Wraps busb_free_config_descriptor.
Definition: LibUsbAdaptor.cpp:244
virtual 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)=0
Wraps libusb_fill_control_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().
Definition: LibUsbAdaptor.cpp:399
virtual int SubmitTransfer(struct libusb_transfer *transfer)=0
Wraps libusb_submit_transfer.
A LibUsbAdaptor for use with Asyncronous widgets.
Definition: LibUsbAdaptor.h:563
bool OpenDeviceAndClaimInterface(libusb_device *usb_device, int interface, libusb_device_handle **usb_handle)
Open a libusb device and claim an interface.
Definition: LibUsbAdaptor.cpp:362
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.
Definition: LibUsbAdaptor.cpp:293
The base class for the dedicated libusb thread.
Definition: LibUsbThread.h:55
static std::string ErrorCodeToString(const int error_code)
Try and convert an error code to a string.
Definition: LibUsbAdaptor.cpp:166
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().
Definition: LibUsbAdaptor.cpp:317
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.
Definition: LibUsbAdaptor.cpp:282
int DetachKernelDriver(libusb_device_handle *dev, int interface_number)
Detatch a kernel driver.
Definition: LibUsbAdaptor.cpp:196
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.
Definition: LibUsbAdaptor.cpp:330
virtual int GetConfigDescriptor(libusb_device *dev, uint8_t config_index, struct libusb_config_descriptor **config)=0
Wraps libusb_get_config_descriptor.
virtual bool OpenDevice(libusb_device *usb_device, libusb_device_handle **usb_handle)=0
Open a libusb device.
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.
Definition: LibUsbAdaptor.cpp:305
int SetConfiguration(libusb_device_handle *dev, int configuration)
Wraps libusb_set_configuration.
Definition: LibUsbAdaptor.cpp:186
static bool Initialize(struct libusb_context **context)
Initialize a new libusb context.
Definition: LibUsbAdaptor.cpp:98
int CancelTransfer(struct libusb_transfer *transfer)
Wraps libusb_cancel_transfer.
Definition: LibUsbAdaptor.cpp:268
int GetActiveConfigDescriptor(libusb_device *dev, struct libusb_config_descriptor **config)
Wraps libusb_get_active_config_descriptor.
Definition: LibUsbAdaptor.cpp:210
virtual bool GetStringDescriptor(libusb_device_handle *usb_handle, uint8_t descriptor_index, std::string *data)=0
Get the value of a string descriptor.
static bool HotplugSupported()
Check if this platform supports hotplug.
Definition: LibUsbAdaptor.cpp:158
struct libusb_transfer * AllocTransfer(int iso_packets)
Wraps libusb_alloc_transfer.
Definition: LibUsbAdaptor.cpp:256
virtual void FreeTransfer(struct libusb_transfer *transfer)=0
Wraps libusb_free_transfer.
static bool CheckProduct(const std::string &expected, const DeviceInformation &device_info)
Check if the product string matches the expected value.
Definition: LibUsbAdaptor.cpp:148
bool OpenDevice(libusb_device *usb_device, libusb_device_handle **usb_handle)
Open a libusb device.
Definition: LibUsbAdaptor.cpp:375
virtual 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)=0
Wraps libusb_fill_bulk_transfer.
USBDeviceID GetDeviceId(libusb_device *device) const
Get the USBDeviceID for a device.
Definition: LibUsbAdaptor.cpp:350
virtual bool OpenDeviceAndClaimInterface(libusb_device *usb_device, int interface, libusb_device_handle **usb_handle)=0
Open a libusb device and claim an interface.
The namespace containing all OLA symbols.
Definition: Credentials.cpp:44
bool GetStringDescriptor(libusb_device_handle *usb_handle, uint8_t descriptor_index, std::string *data)
Get the value of a string descriptor.
Definition: LibUsbAdaptor.cpp:249
int GetDeviceDescriptor(libusb_device *dev, struct libusb_device_descriptor *descriptor)
Wraps libusb_get_device_descriptor.
Definition: LibUsbAdaptor.cpp:221
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.
Definition: LibUsbAdaptor.cpp:340
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.
Definition: LibUsbAdaptor.cpp:426
libusb_device * RefDevice(libusb_device *dev)
Wraps libusb_ref_device.
Definition: LibUsbAdaptor.cpp:178
virtual int GetDeviceDescriptor(libusb_device *dev, struct libusb_device_descriptor *descriptor)=0
Wraps libusb_get_device_descriptor.
virtual void FillControlSetup(unsigned char *buffer, uint8_t bmRequestType, uint8_t bRequest, uint16_t wValue, uint16_t wIndex, uint16_t wLength)=0
Wraps libusb_fill_control_setup.
int GetConfigDescriptor(libusb_device *dev, uint8_t config_index, struct libusb_config_descriptor **config)
Wraps libusb_get_config_descriptor.
Definition: LibUsbAdaptor.cpp:232
void Close(libusb_device_handle *usb_handle)
Close a libusb handle.
Definition: LibUsbAdaptor.cpp:369
virtual struct libusb_transfer * AllocTransfer(int iso_packets)=0
Wraps libusb_alloc_transfer.
bool OpenDeviceAndClaimInterface(libusb_device *usb_device, int interface, libusb_device_handle **usb_handle)
Open a libusb device and claim an interface.
Definition: LibUsbAdaptor.cpp:384
Wraps calls to libusb so we can test the code.
Definition: LibUsbAdaptor.h:36