Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(51)

Side by Side Diff: device/usb/usb_interface_impl.cc

Issue 562763002: Convert device::UsbConfigDescriptor and friends to structs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add interface and endpoint descriptor iterator typedefs. Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « device/usb/usb_interface_impl.h ('k') | extensions/browser/api/usb/usb_api.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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 #include "device/usb/usb_interface_impl.h"
6
7 #include "base/logging.h"
8 #include "third_party/libusb/src/libusb/libusb.h"
9
10 namespace device {
11
12 UsbEndpointDescriptorImpl::UsbEndpointDescriptorImpl(
13 scoped_refptr<const UsbConfigDescriptor> config,
14 PlatformUsbEndpointDescriptor descriptor)
15 : config_(config), descriptor_(descriptor) {
16 }
17
18 UsbEndpointDescriptorImpl::~UsbEndpointDescriptorImpl() {
19 }
20
21 int UsbEndpointDescriptorImpl::GetAddress() const {
22 return descriptor_->bEndpointAddress & LIBUSB_ENDPOINT_ADDRESS_MASK;
23 }
24
25 UsbEndpointDirection UsbEndpointDescriptorImpl::GetDirection() const {
26 switch (descriptor_->bEndpointAddress & LIBUSB_ENDPOINT_DIR_MASK) {
27 case LIBUSB_ENDPOINT_IN:
28 return USB_DIRECTION_INBOUND;
29 case LIBUSB_ENDPOINT_OUT:
30 return USB_DIRECTION_OUTBOUND;
31 default:
32 NOTREACHED();
33 return USB_DIRECTION_INBOUND;
34 }
35 }
36
37 int UsbEndpointDescriptorImpl::GetMaximumPacketSize() const {
38 return descriptor_->wMaxPacketSize;
39 }
40
41 UsbSynchronizationType UsbEndpointDescriptorImpl::GetSynchronizationType()
42 const {
43 switch (descriptor_->bmAttributes & LIBUSB_ISO_SYNC_TYPE_MASK) {
44 case LIBUSB_ISO_SYNC_TYPE_NONE:
45 return USB_SYNCHRONIZATION_NONE;
46 case LIBUSB_ISO_SYNC_TYPE_ASYNC:
47 return USB_SYNCHRONIZATION_ASYNCHRONOUS;
48 case LIBUSB_ISO_SYNC_TYPE_ADAPTIVE:
49 return USB_SYNCHRONIZATION_ADAPTIVE;
50 case LIBUSB_ISO_SYNC_TYPE_SYNC:
51 return USB_SYNCHRONIZATION_SYNCHRONOUS;
52 default:
53 NOTREACHED();
54 return USB_SYNCHRONIZATION_NONE;
55 }
56 }
57
58 UsbTransferType UsbEndpointDescriptorImpl::GetTransferType() const {
59 switch (descriptor_->bmAttributes & LIBUSB_TRANSFER_TYPE_MASK) {
60 case LIBUSB_TRANSFER_TYPE_CONTROL:
61 return USB_TRANSFER_CONTROL;
62 case LIBUSB_TRANSFER_TYPE_ISOCHRONOUS:
63 return USB_TRANSFER_ISOCHRONOUS;
64 case LIBUSB_TRANSFER_TYPE_BULK:
65 return USB_TRANSFER_BULK;
66 case LIBUSB_TRANSFER_TYPE_INTERRUPT:
67 return USB_TRANSFER_INTERRUPT;
68 default:
69 NOTREACHED();
70 return USB_TRANSFER_CONTROL;
71 }
72 }
73
74 UsbUsageType UsbEndpointDescriptorImpl::GetUsageType() const {
75 switch (descriptor_->bmAttributes & LIBUSB_ISO_USAGE_TYPE_MASK) {
76 case LIBUSB_ISO_USAGE_TYPE_DATA:
77 return USB_USAGE_DATA;
78 case LIBUSB_ISO_USAGE_TYPE_FEEDBACK:
79 return USB_USAGE_FEEDBACK;
80 case LIBUSB_ISO_USAGE_TYPE_IMPLICIT:
81 return USB_USAGE_EXPLICIT_FEEDBACK;
82 default:
83 NOTREACHED();
84 return USB_USAGE_DATA;
85 }
86 }
87
88 int UsbEndpointDescriptorImpl::GetPollingInterval() const {
89 return descriptor_->bInterval;
90 }
91
92 UsbInterfaceAltSettingDescriptorImpl::UsbInterfaceAltSettingDescriptorImpl(
93 scoped_refptr<const UsbConfigDescriptor> config,
94 PlatformUsbInterfaceDescriptor descriptor)
95 : config_(config), descriptor_(descriptor) {
96 }
97
98 UsbInterfaceAltSettingDescriptorImpl::~UsbInterfaceAltSettingDescriptorImpl() {
99 }
100
101 size_t UsbInterfaceAltSettingDescriptorImpl::GetNumEndpoints() const {
102 return descriptor_->bNumEndpoints;
103 }
104
105 scoped_refptr<const UsbEndpointDescriptor>
106 UsbInterfaceAltSettingDescriptorImpl::GetEndpoint(size_t index) const {
107 return new UsbEndpointDescriptorImpl(config_, &descriptor_->endpoint[index]);
108 }
109
110 int UsbInterfaceAltSettingDescriptorImpl::GetInterfaceNumber() const {
111 return descriptor_->bInterfaceNumber;
112 }
113
114 int UsbInterfaceAltSettingDescriptorImpl::GetAlternateSetting() const {
115 return descriptor_->bAlternateSetting;
116 }
117
118 int UsbInterfaceAltSettingDescriptorImpl::GetInterfaceClass() const {
119 return descriptor_->bInterfaceClass;
120 }
121
122 int UsbInterfaceAltSettingDescriptorImpl::GetInterfaceSubclass() const {
123 return descriptor_->bInterfaceSubClass;
124 }
125
126 int UsbInterfaceAltSettingDescriptorImpl::GetInterfaceProtocol() const {
127 return descriptor_->bInterfaceProtocol;
128 }
129
130 UsbInterfaceDescriptorImpl::UsbInterfaceDescriptorImpl(
131 scoped_refptr<const UsbConfigDescriptor> config,
132 PlatformUsbInterface usbInterface)
133 : config_(config), interface_(usbInterface) {
134 }
135
136 UsbInterfaceDescriptorImpl::~UsbInterfaceDescriptorImpl() {
137 }
138
139 size_t UsbInterfaceDescriptorImpl::GetNumAltSettings() const {
140 return interface_->num_altsetting;
141 }
142
143 scoped_refptr<const UsbInterfaceAltSettingDescriptor>
144 UsbInterfaceDescriptorImpl::GetAltSetting(size_t index) const {
145 return new UsbInterfaceAltSettingDescriptorImpl(
146 config_, &interface_->altsetting[index]);
147 }
148
149 UsbConfigDescriptorImpl::UsbConfigDescriptorImpl(
150 PlatformUsbConfigDescriptor config)
151 : config_(config) {
152 DCHECK(config);
153 }
154
155 UsbConfigDescriptorImpl::~UsbConfigDescriptorImpl() {
156 libusb_free_config_descriptor(config_);
157 }
158
159 size_t UsbConfigDescriptorImpl::GetNumInterfaces() const {
160 return config_->bNumInterfaces;
161 }
162
163 scoped_refptr<const UsbInterfaceDescriptor>
164 UsbConfigDescriptorImpl::GetInterface(size_t index) const {
165 return new UsbInterfaceDescriptorImpl(this, &config_->interface[index]);
166 }
167
168 } // namespace device
OLDNEW
« no previous file with comments | « device/usb/usb_interface_impl.h ('k') | extensions/browser/api/usb/usb_api.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698