OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/usb/usb_interface.h" | 5 #include "components/usb_service/usb_interface.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "third_party/libusb/src/libusb/libusb.h" | 8 #include "third_party/libusb/src/libusb/libusb.h" |
9 | 9 |
| 10 namespace usb_service { |
| 11 |
10 UsbEndpointDescriptor::UsbEndpointDescriptor( | 12 UsbEndpointDescriptor::UsbEndpointDescriptor( |
11 scoped_refptr<const UsbConfigDescriptor> config, | 13 scoped_refptr<const UsbConfigDescriptor> config, |
12 PlatformUsbEndpointDescriptor descriptor) | 14 PlatformUsbEndpointDescriptor descriptor) |
13 : config_(config), descriptor_(descriptor) { | 15 : config_(config), descriptor_(descriptor) { |
14 } | 16 } |
15 | 17 |
16 UsbEndpointDescriptor::~UsbEndpointDescriptor() {} | 18 UsbEndpointDescriptor::~UsbEndpointDescriptor() { |
| 19 } |
17 | 20 |
18 int UsbEndpointDescriptor::GetAddress() const { | 21 int UsbEndpointDescriptor::GetAddress() const { |
19 return descriptor_->bEndpointAddress & LIBUSB_ENDPOINT_ADDRESS_MASK; | 22 return descriptor_->bEndpointAddress & LIBUSB_ENDPOINT_ADDRESS_MASK; |
20 } | 23 } |
21 | 24 |
22 UsbEndpointDirection UsbEndpointDescriptor::GetDirection() const { | 25 UsbEndpointDirection UsbEndpointDescriptor::GetDirection() const { |
23 switch (descriptor_->bEndpointAddress & LIBUSB_ENDPOINT_DIR_MASK) { | 26 switch (descriptor_->bEndpointAddress & LIBUSB_ENDPOINT_DIR_MASK) { |
24 case LIBUSB_ENDPOINT_IN: | 27 case LIBUSB_ENDPOINT_IN: |
25 return USB_DIRECTION_INBOUND; | 28 return USB_DIRECTION_INBOUND; |
26 case LIBUSB_ENDPOINT_OUT: | 29 case LIBUSB_ENDPOINT_OUT: |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 int UsbEndpointDescriptor::GetPollingInterval() const { | 87 int UsbEndpointDescriptor::GetPollingInterval() const { |
85 return descriptor_->bInterval; | 88 return descriptor_->bInterval; |
86 } | 89 } |
87 | 90 |
88 UsbInterfaceAltSettingDescriptor::UsbInterfaceAltSettingDescriptor( | 91 UsbInterfaceAltSettingDescriptor::UsbInterfaceAltSettingDescriptor( |
89 scoped_refptr<const UsbConfigDescriptor> config, | 92 scoped_refptr<const UsbConfigDescriptor> config, |
90 PlatformUsbInterfaceDescriptor descriptor) | 93 PlatformUsbInterfaceDescriptor descriptor) |
91 : config_(config), descriptor_(descriptor) { | 94 : config_(config), descriptor_(descriptor) { |
92 } | 95 } |
93 | 96 |
94 UsbInterfaceAltSettingDescriptor::~UsbInterfaceAltSettingDescriptor() {} | 97 UsbInterfaceAltSettingDescriptor::~UsbInterfaceAltSettingDescriptor() { |
| 98 } |
95 | 99 |
96 size_t UsbInterfaceAltSettingDescriptor::GetNumEndpoints() const { | 100 size_t UsbInterfaceAltSettingDescriptor::GetNumEndpoints() const { |
97 return descriptor_->bNumEndpoints; | 101 return descriptor_->bNumEndpoints; |
98 } | 102 } |
99 | 103 |
100 scoped_refptr<const UsbEndpointDescriptor> | 104 scoped_refptr<const UsbEndpointDescriptor> |
101 UsbInterfaceAltSettingDescriptor::GetEndpoint(size_t index) const { | 105 UsbInterfaceAltSettingDescriptor::GetEndpoint(size_t index) const { |
102 return new UsbEndpointDescriptor(config_, &descriptor_->endpoint[index]); | 106 return new UsbEndpointDescriptor(config_, &descriptor_->endpoint[index]); |
103 } | 107 } |
104 | 108 |
105 int UsbInterfaceAltSettingDescriptor::GetInterfaceNumber() const { | 109 int UsbInterfaceAltSettingDescriptor::GetInterfaceNumber() const { |
106 return descriptor_->bInterfaceNumber; | 110 return descriptor_->bInterfaceNumber; |
107 } | 111 } |
108 | 112 |
109 int UsbInterfaceAltSettingDescriptor::GetAlternateSetting() const { | 113 int UsbInterfaceAltSettingDescriptor::GetAlternateSetting() const { |
110 return descriptor_->bAlternateSetting; | 114 return descriptor_->bAlternateSetting; |
111 } | 115 } |
112 | 116 |
113 int UsbInterfaceAltSettingDescriptor::GetInterfaceClass() const { | 117 int UsbInterfaceAltSettingDescriptor::GetInterfaceClass() const { |
114 return descriptor_->bInterfaceClass; | 118 return descriptor_->bInterfaceClass; |
115 } | 119 } |
116 | 120 |
117 int UsbInterfaceAltSettingDescriptor::GetInterfaceSubclass() const { | 121 int UsbInterfaceAltSettingDescriptor::GetInterfaceSubclass() const { |
118 return descriptor_->bInterfaceSubClass; | 122 return descriptor_->bInterfaceSubClass; |
119 } | 123 } |
120 | 124 |
121 int UsbInterfaceAltSettingDescriptor::GetInterfaceProtocol() const { | 125 int UsbInterfaceAltSettingDescriptor::GetInterfaceProtocol() const { |
122 return descriptor_->bInterfaceProtocol; | 126 return descriptor_->bInterfaceProtocol; |
123 } | 127 } |
124 | 128 |
125 UsbInterfaceDescriptor::UsbInterfaceDescriptor( | 129 UsbInterfaceDescriptor::UsbInterfaceDescriptor( |
126 scoped_refptr<const UsbConfigDescriptor> config, | 130 scoped_refptr<const UsbConfigDescriptor> config, |
127 PlatformUsbInterface usbInterface) | 131 PlatformUsbInterface usbInterface) |
128 : config_(config), interface_(usbInterface) { | 132 : config_(config), interface_(usbInterface) { |
129 } | 133 } |
130 | 134 |
131 UsbInterfaceDescriptor::~UsbInterfaceDescriptor() {} | 135 UsbInterfaceDescriptor::~UsbInterfaceDescriptor() { |
| 136 } |
132 | 137 |
133 size_t UsbInterfaceDescriptor::GetNumAltSettings() const { | 138 size_t UsbInterfaceDescriptor::GetNumAltSettings() const { |
134 return interface_->num_altsetting; | 139 return interface_->num_altsetting; |
135 } | 140 } |
136 | 141 |
137 scoped_refptr<const UsbInterfaceAltSettingDescriptor> | 142 scoped_refptr<const UsbInterfaceAltSettingDescriptor> |
138 UsbInterfaceDescriptor::GetAltSetting(size_t index) const { | 143 UsbInterfaceDescriptor::GetAltSetting(size_t index) const { |
139 return new UsbInterfaceAltSettingDescriptor(config_, | 144 return new UsbInterfaceAltSettingDescriptor(config_, |
140 &interface_->altsetting[index]); | 145 &interface_->altsetting[index]); |
141 } | 146 } |
142 | 147 |
143 UsbConfigDescriptor::UsbConfigDescriptor(PlatformUsbConfigDescriptor config) | 148 UsbConfigDescriptor::UsbConfigDescriptor(PlatformUsbConfigDescriptor config) |
144 : config_(config) { | 149 : config_(config) { |
145 } | 150 } |
146 | 151 |
147 UsbConfigDescriptor::~UsbConfigDescriptor() { | 152 UsbConfigDescriptor::~UsbConfigDescriptor() { |
148 if (config_ != NULL) { | 153 if (config_ != NULL) { |
149 libusb_free_config_descriptor(config_); | 154 libusb_free_config_descriptor(config_); |
150 config_ = NULL; | 155 config_ = NULL; |
151 } | 156 } |
152 } | 157 } |
153 | 158 |
154 size_t UsbConfigDescriptor::GetNumInterfaces() const { | 159 size_t UsbConfigDescriptor::GetNumInterfaces() const { |
155 return config_->bNumInterfaces; | 160 return config_->bNumInterfaces; |
156 } | 161 } |
157 | 162 |
158 scoped_refptr<const UsbInterfaceDescriptor> | 163 scoped_refptr<const UsbInterfaceDescriptor> UsbConfigDescriptor::GetInterface( |
159 UsbConfigDescriptor::GetInterface(size_t index) const { | 164 size_t index) const { |
160 return new UsbInterfaceDescriptor(this, &config_->interface[index]); | 165 return new UsbInterfaceDescriptor(this, &config_->interface[index]); |
161 } | 166 } |
| 167 |
| 168 } // namespace usb_service |
OLD | NEW |