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_H_
6 #define COMPONENTS_USB_SERVICE_USB_INTERFACE_H_
8 #include "base/memory/ref_counted.h"
9 #include "components/usb_service/usb_service_export.h"
11 struct libusb_config_descriptor
;
12 struct libusb_endpoint_descriptor
;
13 struct libusb_interface
;
14 struct libusb_interface_descriptor
;
16 namespace usb_service
{
18 typedef libusb_config_descriptor
* PlatformUsbConfigDescriptor
;
19 typedef const libusb_endpoint_descriptor
* PlatformUsbEndpointDescriptor
;
20 typedef const libusb_interface
* PlatformUsbInterface
;
21 typedef const libusb_interface_descriptor
* PlatformUsbInterfaceDescriptor
;
23 enum UsbTransferType
{
24 USB_TRANSFER_CONTROL
= 0,
25 USB_TRANSFER_ISOCHRONOUS
,
27 USB_TRANSFER_INTERRUPT
,
30 enum UsbEndpointDirection
{
31 USB_DIRECTION_INBOUND
= 0,
32 USB_DIRECTION_OUTBOUND
,
35 enum UsbSynchronizationType
{
36 USB_SYNCHRONIZATION_NONE
= 0,
37 USB_SYNCHRONIZATION_ASYNCHRONOUS
,
38 USB_SYNCHRONIZATION_ADAPTIVE
,
39 USB_SYNCHRONIZATION_SYNCHRONOUS
,
45 USB_USAGE_EXPLICIT_FEEDBACK
49 class UsbConfigDescriptor
;
50 class UsbInterfaceDescriptor
;
51 class UsbInterfaceAltSettingDescriptor
;
53 class USB_SERVICE_EXPORT UsbEndpointDescriptor
54 : public base::RefCounted
<const UsbEndpointDescriptor
> {
56 int GetAddress() const;
57 UsbEndpointDirection
GetDirection() const;
58 int GetMaximumPacketSize() const;
59 UsbSynchronizationType
GetSynchronizationType() const;
60 UsbTransferType
GetTransferType() const;
61 UsbUsageType
GetUsageType() const;
62 int GetPollingInterval() const;
65 friend class base::RefCounted
<const UsbEndpointDescriptor
>;
66 friend class UsbInterfaceAltSettingDescriptor
;
68 UsbEndpointDescriptor(scoped_refptr
<const UsbConfigDescriptor
> config
,
69 PlatformUsbEndpointDescriptor descriptor
);
70 ~UsbEndpointDescriptor();
72 scoped_refptr
<const UsbConfigDescriptor
> config_
;
73 PlatformUsbEndpointDescriptor descriptor_
;
75 DISALLOW_COPY_AND_ASSIGN(UsbEndpointDescriptor
);
78 class USB_SERVICE_EXPORT UsbInterfaceAltSettingDescriptor
79 : public base::RefCounted
<const UsbInterfaceAltSettingDescriptor
> {
81 size_t GetNumEndpoints() const;
82 scoped_refptr
<const UsbEndpointDescriptor
> GetEndpoint(size_t index
) const;
84 int GetInterfaceNumber() const;
85 int GetAlternateSetting() const;
86 int GetInterfaceClass() const;
87 int GetInterfaceSubclass() const;
88 int GetInterfaceProtocol() const;
91 friend class base::RefCounted
<const UsbInterfaceAltSettingDescriptor
>;
92 friend class UsbInterfaceDescriptor
;
94 UsbInterfaceAltSettingDescriptor(
95 scoped_refptr
<const UsbConfigDescriptor
> config
,
96 PlatformUsbInterfaceDescriptor descriptor
);
97 ~UsbInterfaceAltSettingDescriptor();
99 scoped_refptr
<const UsbConfigDescriptor
> config_
;
100 PlatformUsbInterfaceDescriptor descriptor_
;
102 DISALLOW_COPY_AND_ASSIGN(UsbInterfaceAltSettingDescriptor
);
105 class USB_SERVICE_EXPORT UsbInterfaceDescriptor
106 : public base::RefCounted
<const UsbInterfaceDescriptor
> {
108 size_t GetNumAltSettings() const;
109 scoped_refptr
<const UsbInterfaceAltSettingDescriptor
> GetAltSetting(
113 friend class base::RefCounted
<const UsbInterfaceDescriptor
>;
114 friend class UsbConfigDescriptor
;
116 UsbInterfaceDescriptor(scoped_refptr
<const UsbConfigDescriptor
> config
,
117 PlatformUsbInterface usbInterface
);
118 ~UsbInterfaceDescriptor();
120 scoped_refptr
<const UsbConfigDescriptor
> config_
;
121 PlatformUsbInterface interface_
;
123 DISALLOW_COPY_AND_ASSIGN(UsbInterfaceDescriptor
);
126 class USB_SERVICE_EXPORT UsbConfigDescriptor
127 : public base::RefCounted
<UsbConfigDescriptor
> {
129 size_t GetNumInterfaces() const;
130 scoped_refptr
<const UsbInterfaceDescriptor
> GetInterface(size_t index
) const;
133 friend class base::RefCounted
<UsbConfigDescriptor
>;
134 friend class UsbDevice
;
136 explicit UsbConfigDescriptor(PlatformUsbConfigDescriptor config
);
137 ~UsbConfigDescriptor();
139 PlatformUsbConfigDescriptor config_
;
141 DISALLOW_COPY_AND_ASSIGN(UsbConfigDescriptor
);
144 } // namespace usb_service;
146 #endif // COMPONENTS_USB_SERVICE_USB_INTERFACE_H_