1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef CHROME_BROWSER_USB_USB_INTERFACE_H_ 6 #define CHROME_BROWSER_USB_USB_INTERFACE_H_ 7 8 #include "base/memory/ref_counted.h" 9 #include "base/memory/scoped_ptr.h" 10 11 struct libusb_config_descriptor; 12 struct libusb_endpoint_descriptor; 13 struct libusb_interface; 14 struct libusb_interface_descriptor; 15 16 typedef libusb_config_descriptor* PlatformUsbConfigDescriptor; 17 typedef const libusb_endpoint_descriptor* PlatformUsbEndpointDescriptor; 18 typedef const libusb_interface* PlatformUsbInterface; 19 typedef const libusb_interface_descriptor* PlatformUsbInterfaceDescriptor; 20 21 class UsbDeviceHandle; 22 23 enum UsbTransferType { 24 USB_TRANSFER_CONTROL = 0, 25 USB_TRANSFER_ISOCHRONOUS, 26 USB_TRANSFER_BULK, 27 USB_TRANSFER_INTERRUPT, 28 }; 29 30 enum UsbEndpointDirection { 31 USB_DIRECTION_INBOUND = 0, 32 USB_DIRECTION_OUTBOUND, 33 }; 34 35 enum UsbSynchronizationType { 36 USB_SYNCHRONIZATION_NONE = 0, 37 USB_SYNCHRONIZATION_ASYNCHRONOUS, 38 USB_SYNCHRONIZATION_ADAPTIVE, 39 USB_SYNCHRONIZATION_SYNCHRONOUS, 40 }; 41 42 enum UsbUsageType { 43 USB_USAGE_DATA = 0, 44 USB_USAGE_FEEDBACK, 45 USB_USAGE_EXPLICIT_FEEDBACK 46 }; 47 48 class UsbConfigDescriptor; 49 50 class UsbEndpointDescriptor : public base::RefCounted<UsbEndpointDescriptor> { 51 public: 52 UsbEndpointDescriptor(scoped_refptr<const UsbConfigDescriptor> config, 53 PlatformUsbEndpointDescriptor descriptor); 54 55 int GetAddress() const; 56 UsbEndpointDirection GetDirection() const; 57 int GetMaximumPacketSize() const; 58 UsbSynchronizationType GetSynchronizationType() const; 59 UsbTransferType GetTransferType() const; 60 UsbUsageType GetUsageType() const; 61 int GetPollingInterval() const; 62 63 private: 64 friend class base::RefCounted<UsbEndpointDescriptor>; 65 ~UsbEndpointDescriptor(); 66 67 scoped_refptr<const UsbConfigDescriptor> config_; 68 PlatformUsbEndpointDescriptor descriptor_; 69 }; 70 71 class UsbInterfaceDescriptor 72 : public base::RefCounted<UsbInterfaceDescriptor> { 73 public: 74 UsbInterfaceDescriptor(scoped_refptr<const UsbConfigDescriptor> config, 75 PlatformUsbInterfaceDescriptor descriptor); 76 77 size_t GetNumEndpoints() const; 78 scoped_refptr<const UsbEndpointDescriptor> 79 GetEndpoint(size_t index) const; 80 81 int GetInterfaceNumber() const; 82 int GetAlternateSetting() const; 83 int GetInterfaceClass() const; 84 int GetInterfaceSubclass() const; 85 int GetInterfaceProtocol() const; 86 87 private: 88 friend class base::RefCounted<UsbInterfaceDescriptor>; 89 ~UsbInterfaceDescriptor(); 90 91 scoped_refptr<const UsbConfigDescriptor> config_; 92 PlatformUsbInterfaceDescriptor descriptor_; 93 }; 94 95 class UsbInterface : public base::RefCounted<UsbInterface> { 96 public: 97 UsbInterface(scoped_refptr<const UsbConfigDescriptor> config, 98 PlatformUsbInterface usbInterface); 99 100 size_t GetNumAltSettings() const; 101 scoped_refptr<const UsbInterfaceDescriptor> 102 GetAltSetting(size_t index) const; 103 104 private: 105 friend class base::RefCounted<UsbInterface>; 106 ~UsbInterface(); 107 108 scoped_refptr<const UsbConfigDescriptor> config_; 109 PlatformUsbInterface interface_; 110 }; 111 112 class UsbConfigDescriptor : public base::RefCounted<UsbConfigDescriptor> { 113 public: 114 UsbConfigDescriptor(); 115 116 void Reset(PlatformUsbConfigDescriptor config); 117 118 size_t GetNumInterfaces() const; 119 120 scoped_refptr<const UsbInterface> 121 GetInterface(size_t index) const; 122 123 private: 124 friend class base::RefCounted<UsbConfigDescriptor>; 125 ~UsbConfigDescriptor(); 126 127 PlatformUsbConfigDescriptor config_; 128 }; 129 130 #endif // CHROME_BROWSER_USB_USB_INTERFACE_H_ 131