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.
5 #ifndef COMPONENTS_USB_SERVICE_USB_INTERFACE_IMPL_H_
6 #define COMPONENTS_USB_SERVICE_USB_INTERFACE_IMPL_H_
8 #include "base/memory/ref_counted.h"
9 #include "components/usb_service/usb_interface.h"
10 #include "components/usb_service/usb_service_export.h"
12 struct libusb_config_descriptor
;
13 struct libusb_endpoint_descriptor
;
14 struct libusb_interface
;
15 struct libusb_interface_descriptor
;
17 namespace usb_service
{
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
;
24 class UsbConfigDescriptorImpl
;
25 class UsbInterfaceAltSettingDescriptor
;
27 class UsbEndpointDescriptorImpl
: public UsbEndpointDescriptor
{
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
;
38 friend class base::RefCounted
<const UsbEndpointDescriptorImpl
>;
39 friend class UsbInterfaceAltSettingDescriptorImpl
;
41 UsbEndpointDescriptorImpl(scoped_refptr
<const UsbConfigDescriptor
> config
,
42 PlatformUsbEndpointDescriptor descriptor
);
43 virtual ~UsbEndpointDescriptorImpl();
45 scoped_refptr
<const UsbConfigDescriptor
> config_
;
46 PlatformUsbEndpointDescriptor descriptor_
;
48 DISALLOW_COPY_AND_ASSIGN(UsbEndpointDescriptorImpl
);
51 class UsbInterfaceAltSettingDescriptorImpl
52 : public UsbInterfaceAltSettingDescriptor
{
54 virtual size_t GetNumEndpoints() const OVERRIDE
;
55 virtual scoped_refptr
<const UsbEndpointDescriptor
> GetEndpoint(
56 size_t index
) const OVERRIDE
;
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
;
65 friend class UsbInterfaceDescriptorImpl
;
67 UsbInterfaceAltSettingDescriptorImpl(
68 scoped_refptr
<const UsbConfigDescriptor
> config
,
69 PlatformUsbInterfaceDescriptor descriptor
);
70 virtual ~UsbInterfaceAltSettingDescriptorImpl();
72 scoped_refptr
<const UsbConfigDescriptor
> config_
;
73 PlatformUsbInterfaceDescriptor descriptor_
;
75 DISALLOW_COPY_AND_ASSIGN(UsbInterfaceAltSettingDescriptorImpl
);
78 class UsbInterfaceDescriptorImpl
: public UsbInterfaceDescriptor
{
80 virtual size_t GetNumAltSettings() const OVERRIDE
;
81 virtual scoped_refptr
<const UsbInterfaceAltSettingDescriptor
> GetAltSetting(
82 size_t index
) const OVERRIDE
;
85 friend class base::RefCounted
<const UsbInterfaceDescriptorImpl
>;
86 friend class UsbConfigDescriptorImpl
;
88 UsbInterfaceDescriptorImpl(scoped_refptr
<const UsbConfigDescriptor
> config
,
89 PlatformUsbInterface usbInterface
);
90 virtual ~UsbInterfaceDescriptorImpl();
92 scoped_refptr
<const UsbConfigDescriptor
> config_
;
93 PlatformUsbInterface interface_
;
95 DISALLOW_COPY_AND_ASSIGN(UsbInterfaceDescriptorImpl
);
98 class UsbConfigDescriptorImpl
: public UsbConfigDescriptor
{
100 virtual size_t GetNumInterfaces() const OVERRIDE
;
101 virtual scoped_refptr
<const UsbInterfaceDescriptor
> GetInterface(
102 size_t index
) const OVERRIDE
;
105 friend class base::RefCounted
<UsbConfigDescriptor
>;
106 friend class UsbDeviceImpl
;
108 explicit UsbConfigDescriptorImpl(PlatformUsbConfigDescriptor config
);
109 virtual ~UsbConfigDescriptorImpl();
111 PlatformUsbConfigDescriptor config_
;
113 DISALLOW_COPY_AND_ASSIGN(UsbConfigDescriptorImpl
);
116 } // namespace usb_service;
118 #endif // COMPONENTS_USB_SERVICE_USB_INTERFACE_IMPL_H_