1 // Copyright 2014 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 COMPONENTS_USB_SERVICE_USB_INTERFACE_IMPL_H_ 6 #define COMPONENTS_USB_SERVICE_USB_INTERFACE_IMPL_H_ 7 8 #include "base/memory/ref_counted.h" 9 #include "components/usb_service/usb_interface.h" 10 #include "components/usb_service/usb_service_export.h" 11 12 struct libusb_config_descriptor; 13 struct libusb_endpoint_descriptor; 14 struct libusb_interface; 15 struct libusb_interface_descriptor; 16 17 namespace usb_service { 18 19 typedef libusb_config_descriptor* PlatformUsbConfigDescriptor; 20 typedef const libusb_endpoint_descriptor* PlatformUsbEndpointDescriptor; 21 typedef const libusb_interface* PlatformUsbInterface; 22 typedef const libusb_interface_descriptor* PlatformUsbInterfaceDescriptor; 23 24 class UsbConfigDescriptorImpl; 25 class UsbInterfaceAltSettingDescriptor; 26 27 class UsbEndpointDescriptorImpl : public UsbEndpointDescriptor { 28 public: 29 virtual int GetAddress() const OVERRIDE; 30 virtual UsbEndpointDirection GetDirection() const OVERRIDE; 31 virtual int GetMaximumPacketSize() const OVERRIDE; 32 virtual UsbSynchronizationType GetSynchronizationType() const OVERRIDE; 33 virtual UsbTransferType GetTransferType() const OVERRIDE; 34 virtual UsbUsageType GetUsageType() const OVERRIDE; 35 virtual int GetPollingInterval() const OVERRIDE; 36 37 private: 38 friend class base::RefCounted<const UsbEndpointDescriptorImpl>; 39 friend class UsbInterfaceAltSettingDescriptorImpl; 40 41 UsbEndpointDescriptorImpl(scoped_refptr<const UsbConfigDescriptor> config, 42 PlatformUsbEndpointDescriptor descriptor); 43 virtual ~UsbEndpointDescriptorImpl(); 44 45 scoped_refptr<const UsbConfigDescriptor> config_; 46 PlatformUsbEndpointDescriptor descriptor_; 47 48 DISALLOW_COPY_AND_ASSIGN(UsbEndpointDescriptorImpl); 49 }; 50 51 class UsbInterfaceAltSettingDescriptorImpl 52 : public UsbInterfaceAltSettingDescriptor { 53 public: 54 virtual size_t GetNumEndpoints() const OVERRIDE; 55 virtual scoped_refptr<const UsbEndpointDescriptor> GetEndpoint( 56 size_t index) const OVERRIDE; 57 58 virtual int GetInterfaceNumber() const OVERRIDE; 59 virtual int GetAlternateSetting() const OVERRIDE; 60 virtual int GetInterfaceClass() const OVERRIDE; 61 virtual int GetInterfaceSubclass() const OVERRIDE; 62 virtual int GetInterfaceProtocol() const OVERRIDE; 63 64 private: 65 friend class UsbInterfaceDescriptorImpl; 66 67 UsbInterfaceAltSettingDescriptorImpl( 68 scoped_refptr<const UsbConfigDescriptor> config, 69 PlatformUsbInterfaceDescriptor descriptor); 70 virtual ~UsbInterfaceAltSettingDescriptorImpl(); 71 72 scoped_refptr<const UsbConfigDescriptor> config_; 73 PlatformUsbInterfaceDescriptor descriptor_; 74 75 DISALLOW_COPY_AND_ASSIGN(UsbInterfaceAltSettingDescriptorImpl); 76 }; 77 78 class UsbInterfaceDescriptorImpl : public UsbInterfaceDescriptor { 79 public: 80 virtual size_t GetNumAltSettings() const OVERRIDE; 81 virtual scoped_refptr<const UsbInterfaceAltSettingDescriptor> GetAltSetting( 82 size_t index) const OVERRIDE; 83 84 private: 85 friend class base::RefCounted<const UsbInterfaceDescriptorImpl>; 86 friend class UsbConfigDescriptorImpl; 87 88 UsbInterfaceDescriptorImpl(scoped_refptr<const UsbConfigDescriptor> config, 89 PlatformUsbInterface usbInterface); 90 virtual ~UsbInterfaceDescriptorImpl(); 91 92 scoped_refptr<const UsbConfigDescriptor> config_; 93 PlatformUsbInterface interface_; 94 95 DISALLOW_COPY_AND_ASSIGN(UsbInterfaceDescriptorImpl); 96 }; 97 98 class UsbConfigDescriptorImpl : public UsbConfigDescriptor { 99 public: 100 virtual size_t GetNumInterfaces() const OVERRIDE; 101 virtual scoped_refptr<const UsbInterfaceDescriptor> GetInterface( 102 size_t index) const OVERRIDE; 103 104 private: 105 friend class base::RefCounted<UsbConfigDescriptor>; 106 friend class UsbDeviceImpl; 107 108 explicit UsbConfigDescriptorImpl(PlatformUsbConfigDescriptor config); 109 virtual ~UsbConfigDescriptorImpl(); 110 111 PlatformUsbConfigDescriptor config_; 112 113 DISALLOW_COPY_AND_ASSIGN(UsbConfigDescriptorImpl); 114 }; 115 116 } // namespace usb_service; 117 118 #endif // COMPONENTS_USB_SERVICE_USB_INTERFACE_IMPL_H_ 119