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,
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.
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
Detach a kernel driver.
static bool CheckManufacturer(const std::string &expected, const DeviceInformation &device_info)
Check if the manufacturer string matches the expected value.
Definition: LibUsbAdaptor.cpp:147
#define DISALLOW_COPY_AND_ASSIGN(TypeName)
Creates dummy copy constructor and assignment operator declarations.
Definition: Macro.h:44
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.
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.
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.
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:116
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.
virtual int SubmitTransfer(struct libusb_transfer *transfer)=0
Wraps libusb_submit_transfer.
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:175
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.
static bool Initialize(struct libusb_context **context)
Initialize a new libusb context.
Definition: LibUsbAdaptor.cpp:107
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:167
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:157
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.
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
A LibUsbAdaptor for use with Synchronous widgets.
Definition: LibUsbAdaptor.h:540
A LibUsbAdaptor for use with Asynchronous widgets.
Definition: LibUsbAdaptor.h:563
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.
virtual struct libusb_transfer * AllocTransfer(int iso_packets)=0
Wraps libusb_alloc_transfer.
Wraps calls to libusb so we can test the code.
Definition: LibUsbAdaptor.h:36