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

Side by Side Diff: device/usb/mojo/type_converters.cc

Issue 2821723002: Move classes in the device.usb Mojo namespace to device.mojom (Closed)
Patch Set: mcasas@ nits Created 3 years, 8 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/mojo/type_converters.h ('k') | device/usb/public/interfaces/OWNERS » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "device/usb/mojo/type_converters.h" 5 #include "device/usb/mojo/type_converters.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <map> 10 #include <map>
11 #include <utility> 11 #include <utility>
12 12
13 #include "base/logging.h" 13 #include "base/logging.h"
14 #include "base/strings/utf_string_conversions.h" 14 #include "base/strings/utf_string_conversions.h"
15 #include "device/usb/usb_device.h" 15 #include "device/usb/usb_device.h"
16 16
17 namespace mojo { 17 namespace mojo {
18 18
19 // static 19 // static
20 device::usb::TransferDirection 20 device::mojom::UsbTransferDirection TypeConverter<
21 TypeConverter<device::usb::TransferDirection, device::UsbEndpointDirection>:: 21 device::mojom::UsbTransferDirection,
22 Convert(const device::UsbEndpointDirection& direction) { 22 device::UsbEndpointDirection>::Convert(const device::UsbEndpointDirection&
23 direction) {
23 if (direction == device::USB_DIRECTION_INBOUND) 24 if (direction == device::USB_DIRECTION_INBOUND)
24 return device::usb::TransferDirection::INBOUND; 25 return device::mojom::UsbTransferDirection::INBOUND;
25 DCHECK(direction == device::USB_DIRECTION_OUTBOUND); 26 DCHECK(direction == device::USB_DIRECTION_OUTBOUND);
26 return device::usb::TransferDirection::OUTBOUND; 27 return device::mojom::UsbTransferDirection::OUTBOUND;
27 } 28 }
28 29
29 // static 30 // static
30 device::usb::TransferStatus 31 device::mojom::UsbTransferStatus
31 TypeConverter<device::usb::TransferStatus, device::UsbTransferStatus>::Convert( 32 TypeConverter<device::mojom::UsbTransferStatus, device::UsbTransferStatus>::
32 const device::UsbTransferStatus& status) { 33 Convert(const device::UsbTransferStatus& status) {
33 switch (status) { 34 switch (status) {
34 case device::USB_TRANSFER_COMPLETED: 35 case device::USB_TRANSFER_COMPLETED:
35 return device::usb::TransferStatus::COMPLETED; 36 return device::mojom::UsbTransferStatus::COMPLETED;
36 case device::USB_TRANSFER_ERROR: 37 case device::USB_TRANSFER_ERROR:
37 return device::usb::TransferStatus::TRANSFER_ERROR; 38 return device::mojom::UsbTransferStatus::TRANSFER_ERROR;
38 case device::USB_TRANSFER_TIMEOUT: 39 case device::USB_TRANSFER_TIMEOUT:
39 return device::usb::TransferStatus::TIMEOUT; 40 return device::mojom::UsbTransferStatus::TIMEOUT;
40 case device::USB_TRANSFER_CANCELLED: 41 case device::USB_TRANSFER_CANCELLED:
41 return device::usb::TransferStatus::CANCELLED; 42 return device::mojom::UsbTransferStatus::CANCELLED;
42 case device::USB_TRANSFER_STALLED: 43 case device::USB_TRANSFER_STALLED:
43 return device::usb::TransferStatus::STALLED; 44 return device::mojom::UsbTransferStatus::STALLED;
44 case device::USB_TRANSFER_DISCONNECT: 45 case device::USB_TRANSFER_DISCONNECT:
45 return device::usb::TransferStatus::DISCONNECT; 46 return device::mojom::UsbTransferStatus::DISCONNECT;
46 case device::USB_TRANSFER_OVERFLOW: 47 case device::USB_TRANSFER_OVERFLOW:
47 return device::usb::TransferStatus::BABBLE; 48 return device::mojom::UsbTransferStatus::BABBLE;
48 case device::USB_TRANSFER_LENGTH_SHORT: 49 case device::USB_TRANSFER_LENGTH_SHORT:
49 return device::usb::TransferStatus::SHORT_PACKET; 50 return device::mojom::UsbTransferStatus::SHORT_PACKET;
50 default: 51 default:
51 NOTREACHED(); 52 NOTREACHED();
52 return device::usb::TransferStatus::TRANSFER_ERROR; 53 return device::mojom::UsbTransferStatus::TRANSFER_ERROR;
53 } 54 }
54 } 55 }
55 56
56 // static 57 // static
57 device::UsbDeviceHandle::TransferRequestType 58 device::UsbDeviceHandle::TransferRequestType
58 TypeConverter<device::UsbDeviceHandle::TransferRequestType, 59 TypeConverter<device::UsbDeviceHandle::TransferRequestType,
59 device::usb::ControlTransferType>:: 60 device::mojom::UsbControlTransferType>::
60 Convert(const device::usb::ControlTransferType& type) { 61 Convert(const device::mojom::UsbControlTransferType& type) {
61 switch (type) { 62 switch (type) {
62 case device::usb::ControlTransferType::STANDARD: 63 case device::mojom::UsbControlTransferType::STANDARD:
63 return device::UsbDeviceHandle::STANDARD; 64 return device::UsbDeviceHandle::STANDARD;
64 case device::usb::ControlTransferType::CLASS: 65 case device::mojom::UsbControlTransferType::CLASS:
65 return device::UsbDeviceHandle::CLASS; 66 return device::UsbDeviceHandle::CLASS;
66 case device::usb::ControlTransferType::VENDOR: 67 case device::mojom::UsbControlTransferType::VENDOR:
67 return device::UsbDeviceHandle::VENDOR; 68 return device::UsbDeviceHandle::VENDOR;
68 case device::usb::ControlTransferType::RESERVED: 69 case device::mojom::UsbControlTransferType::RESERVED:
69 return device::UsbDeviceHandle::RESERVED; 70 return device::UsbDeviceHandle::RESERVED;
70 default: 71 default:
71 NOTREACHED(); 72 NOTREACHED();
72 return device::UsbDeviceHandle::RESERVED; 73 return device::UsbDeviceHandle::RESERVED;
73 } 74 }
74 } 75 }
75 76
76 // static 77 // static
77 device::UsbDeviceHandle::TransferRecipient 78 device::UsbDeviceHandle::TransferRecipient
78 TypeConverter<device::UsbDeviceHandle::TransferRecipient, 79 TypeConverter<device::UsbDeviceHandle::TransferRecipient,
79 device::usb::ControlTransferRecipient>:: 80 device::mojom::UsbControlTransferRecipient>::
80 Convert(const device::usb::ControlTransferRecipient& recipient) { 81 Convert(const device::mojom::UsbControlTransferRecipient& recipient) {
81 switch (recipient) { 82 switch (recipient) {
82 case device::usb::ControlTransferRecipient::DEVICE: 83 case device::mojom::UsbControlTransferRecipient::DEVICE:
83 return device::UsbDeviceHandle::DEVICE; 84 return device::UsbDeviceHandle::DEVICE;
84 case device::usb::ControlTransferRecipient::INTERFACE: 85 case device::mojom::UsbControlTransferRecipient::INTERFACE:
85 return device::UsbDeviceHandle::INTERFACE; 86 return device::UsbDeviceHandle::INTERFACE;
86 case device::usb::ControlTransferRecipient::ENDPOINT: 87 case device::mojom::UsbControlTransferRecipient::ENDPOINT:
87 return device::UsbDeviceHandle::ENDPOINT; 88 return device::UsbDeviceHandle::ENDPOINT;
88 case device::usb::ControlTransferRecipient::OTHER: 89 case device::mojom::UsbControlTransferRecipient::OTHER:
89 return device::UsbDeviceHandle::OTHER; 90 return device::UsbDeviceHandle::OTHER;
90 default: 91 default:
91 NOTREACHED(); 92 NOTREACHED();
92 return device::UsbDeviceHandle::OTHER; 93 return device::UsbDeviceHandle::OTHER;
93 } 94 }
94 } 95 }
95 96
96 // static 97 // static
97 device::usb::EndpointType 98 device::mojom::UsbEndpointType
98 TypeConverter<device::usb::EndpointType, device::UsbTransferType>::Convert( 99 TypeConverter<device::mojom::UsbEndpointType, device::UsbTransferType>::Convert(
99 const device::UsbTransferType& type) { 100 const device::UsbTransferType& type) {
100 switch (type) { 101 switch (type) {
101 case device::USB_TRANSFER_ISOCHRONOUS: 102 case device::USB_TRANSFER_ISOCHRONOUS:
102 return device::usb::EndpointType::ISOCHRONOUS; 103 return device::mojom::UsbEndpointType::ISOCHRONOUS;
103 case device::USB_TRANSFER_BULK: 104 case device::USB_TRANSFER_BULK:
104 return device::usb::EndpointType::BULK; 105 return device::mojom::UsbEndpointType::BULK;
105 case device::USB_TRANSFER_INTERRUPT: 106 case device::USB_TRANSFER_INTERRUPT:
106 return device::usb::EndpointType::INTERRUPT; 107 return device::mojom::UsbEndpointType::INTERRUPT;
107 // Note that we do not expose control transfer in the public interface 108 // Note that we do not expose control transfer in the public interface
108 // because control endpoints are implied rather than explicitly enumerated 109 // because control endpoints are implied rather than explicitly enumerated
109 // there. 110 // there.
110 default: 111 default:
111 NOTREACHED(); 112 NOTREACHED();
112 return device::usb::EndpointType::BULK; 113 return device::mojom::UsbEndpointType::BULK;
113 } 114 }
114 } 115 }
115 116
116 // static 117 // static
117 device::usb::EndpointInfoPtr 118 device::mojom::UsbEndpointInfoPtr TypeConverter<
118 TypeConverter<device::usb::EndpointInfoPtr, device::UsbEndpointDescriptor>:: 119 device::mojom::UsbEndpointInfoPtr,
119 Convert(const device::UsbEndpointDescriptor& endpoint) { 120 device::UsbEndpointDescriptor>::Convert(const device::UsbEndpointDescriptor&
120 device::usb::EndpointInfoPtr info = device::usb::EndpointInfo::New(); 121 endpoint) {
122 auto info = device::mojom::UsbEndpointInfo::New();
121 info->endpoint_number = endpoint.address & 0xf; 123 info->endpoint_number = endpoint.address & 0xf;
122 info->direction = 124 info->direction =
123 ConvertTo<device::usb::TransferDirection>(endpoint.direction); 125 ConvertTo<device::mojom::UsbTransferDirection>(endpoint.direction);
124 info->type = ConvertTo<device::usb::EndpointType>(endpoint.transfer_type); 126 info->type =
127 ConvertTo<device::mojom::UsbEndpointType>(endpoint.transfer_type);
125 info->packet_size = static_cast<uint32_t>(endpoint.maximum_packet_size); 128 info->packet_size = static_cast<uint32_t>(endpoint.maximum_packet_size);
126 return info; 129 return info;
127 } 130 }
128 131
129 // static 132 // static
130 device::usb::AlternateInterfaceInfoPtr 133 device::mojom::UsbAlternateInterfaceInfoPtr
131 TypeConverter<device::usb::AlternateInterfaceInfoPtr, 134 TypeConverter<device::mojom::UsbAlternateInterfaceInfoPtr,
132 device::UsbInterfaceDescriptor>:: 135 device::UsbInterfaceDescriptor>::
133 Convert(const device::UsbInterfaceDescriptor& interface) { 136 Convert(const device::UsbInterfaceDescriptor& interface) {
134 device::usb::AlternateInterfaceInfoPtr info = 137 auto info = device::mojom::UsbAlternateInterfaceInfo::New();
135 device::usb::AlternateInterfaceInfo::New();
136 info->alternate_setting = interface.alternate_setting; 138 info->alternate_setting = interface.alternate_setting;
137 info->class_code = interface.interface_class; 139 info->class_code = interface.interface_class;
138 info->subclass_code = interface.interface_subclass; 140 info->subclass_code = interface.interface_subclass;
139 info->protocol_code = interface.interface_protocol; 141 info->protocol_code = interface.interface_protocol;
140 142
141 // Filter out control endpoints for the public interface. 143 // Filter out control endpoints for the public interface.
142 info->endpoints.reserve(interface.endpoints.size()); 144 info->endpoints.reserve(interface.endpoints.size());
143 for (const auto& endpoint : interface.endpoints) { 145 for (const auto& endpoint : interface.endpoints) {
144 if (endpoint.transfer_type != device::USB_TRANSFER_CONTROL) 146 if (endpoint.transfer_type != device::USB_TRANSFER_CONTROL)
145 info->endpoints.push_back(device::usb::EndpointInfo::From(endpoint)); 147 info->endpoints.push_back(device::mojom::UsbEndpointInfo::From(endpoint));
146 } 148 }
147 149
148 return info; 150 return info;
149 } 151 }
150 152
151 // static 153 // static
152 std::vector<device::usb::InterfaceInfoPtr> 154 std::vector<device::mojom::UsbInterfaceInfoPtr>
153 TypeConverter<std::vector<device::usb::InterfaceInfoPtr>, 155 TypeConverter<std::vector<device::mojom::UsbInterfaceInfoPtr>,
154 std::vector<device::UsbInterfaceDescriptor>>:: 156 std::vector<device::UsbInterfaceDescriptor>>::
155 Convert(const std::vector<device::UsbInterfaceDescriptor>& interfaces) { 157 Convert(const std::vector<device::UsbInterfaceDescriptor>& interfaces) {
156 std::vector<device::usb::InterfaceInfoPtr> infos; 158 std::vector<device::mojom::UsbInterfaceInfoPtr> infos;
157 159
158 // Aggregate each alternate setting into an InterfaceInfo corresponding to its 160 // Aggregate each alternate setting into an InterfaceInfo corresponding to its
159 // interface number. 161 // interface number.
160 std::map<uint8_t, device::usb::InterfaceInfo*> interface_map; 162 std::map<uint8_t, device::mojom::UsbInterfaceInfo*> interface_map;
161 for (size_t i = 0; i < interfaces.size(); ++i) { 163 for (size_t i = 0; i < interfaces.size(); ++i) {
162 auto alternate = device::usb::AlternateInterfaceInfo::From(interfaces[i]); 164 auto alternate =
165 device::mojom::UsbAlternateInterfaceInfo::From(interfaces[i]);
163 auto iter = interface_map.find(interfaces[i].interface_number); 166 auto iter = interface_map.find(interfaces[i].interface_number);
164 if (iter == interface_map.end()) { 167 if (iter == interface_map.end()) {
165 // This is the first time we're seeing an alternate with this interface 168 // This is the first time we're seeing an alternate with this interface
166 // number, so add a new InterfaceInfo to the array and map the number. 169 // number, so add a new InterfaceInfo to the array and map the number.
167 auto info = device::usb::InterfaceInfo::New(); 170 auto info = device::mojom::UsbInterfaceInfo::New();
168 info->interface_number = interfaces[i].interface_number; 171 info->interface_number = interfaces[i].interface_number;
169 iter = interface_map 172 iter = interface_map
170 .insert( 173 .insert(
171 std::make_pair(interfaces[i].interface_number, info.get())) 174 std::make_pair(interfaces[i].interface_number, info.get()))
172 .first; 175 .first;
173 infos.push_back(std::move(info)); 176 infos.push_back(std::move(info));
174 } 177 }
175 iter->second->alternates.push_back(std::move(alternate)); 178 iter->second->alternates.push_back(std::move(alternate));
176 } 179 }
177 180
178 return infos; 181 return infos;
179 } 182 }
180 183
181 // static 184 // static
182 device::usb::ConfigurationInfoPtr 185 device::mojom::UsbConfigurationInfoPtr TypeConverter<
183 TypeConverter<device::usb::ConfigurationInfoPtr, device::UsbConfigDescriptor>:: 186 device::mojom::UsbConfigurationInfoPtr,
184 Convert(const device::UsbConfigDescriptor& config) { 187 device::UsbConfigDescriptor>::Convert(const device::UsbConfigDescriptor&
185 device::usb::ConfigurationInfoPtr info = 188 config) {
186 device::usb::ConfigurationInfo::New(); 189 auto info = device::mojom::UsbConfigurationInfo::New();
187 info->configuration_value = config.configuration_value; 190 info->configuration_value = config.configuration_value;
188 info->interfaces = 191 info->interfaces =
189 mojo::ConvertTo<std::vector<device::usb::InterfaceInfoPtr>>( 192 mojo::ConvertTo<std::vector<device::mojom::UsbInterfaceInfoPtr>>(
190 config.interfaces); 193 config.interfaces);
191 return info; 194 return info;
192 } 195 }
193 196
194 // static 197 // static
195 device::usb::DeviceInfoPtr 198 device::mojom::UsbDeviceInfoPtr
196 TypeConverter<device::usb::DeviceInfoPtr, device::UsbDevice>::Convert( 199 TypeConverter<device::mojom::UsbDeviceInfoPtr, device::UsbDevice>::Convert(
197 const device::UsbDevice& device) { 200 const device::UsbDevice& device) {
198 device::usb::DeviceInfoPtr info = device::usb::DeviceInfo::New(); 201 auto info = device::mojom::UsbDeviceInfo::New();
199 info->guid = device.guid(); 202 info->guid = device.guid();
200 info->usb_version_major = device.usb_version() >> 8; 203 info->usb_version_major = device.usb_version() >> 8;
201 info->usb_version_minor = device.usb_version() >> 4 & 0xf; 204 info->usb_version_minor = device.usb_version() >> 4 & 0xf;
202 info->usb_version_subminor = device.usb_version() & 0xf; 205 info->usb_version_subminor = device.usb_version() & 0xf;
203 info->class_code = device.device_class(); 206 info->class_code = device.device_class();
204 info->subclass_code = device.device_subclass(); 207 info->subclass_code = device.device_subclass();
205 info->protocol_code = device.device_protocol(); 208 info->protocol_code = device.device_protocol();
206 info->vendor_id = device.vendor_id(); 209 info->vendor_id = device.vendor_id();
207 info->product_id = device.product_id(); 210 info->product_id = device.product_id();
208 info->device_version_major = device.device_version() >> 8; 211 info->device_version_major = device.device_version() >> 8;
209 info->device_version_minor = device.device_version() >> 4 & 0xf; 212 info->device_version_minor = device.device_version() >> 4 & 0xf;
210 info->device_version_subminor = device.device_version() & 0xf; 213 info->device_version_subminor = device.device_version() & 0xf;
211 info->manufacturer_name = base::UTF16ToUTF8(device.manufacturer_string()); 214 info->manufacturer_name = base::UTF16ToUTF8(device.manufacturer_string());
212 info->product_name = base::UTF16ToUTF8(device.product_string()); 215 info->product_name = base::UTF16ToUTF8(device.product_string());
213 info->serial_number = base::UTF16ToUTF8(device.serial_number()); 216 info->serial_number = base::UTF16ToUTF8(device.serial_number());
214 const device::UsbConfigDescriptor* config = device.active_configuration(); 217 const device::UsbConfigDescriptor* config = device.active_configuration();
215 info->active_configuration = config ? config->configuration_value : 0; 218 info->active_configuration = config ? config->configuration_value : 0;
216 info->configurations = 219 info->configurations =
217 mojo::ConvertTo<std::vector<device::usb::ConfigurationInfoPtr>>( 220 mojo::ConvertTo<std::vector<device::mojom::UsbConfigurationInfoPtr>>(
218 device.configurations()); 221 device.configurations());
219 return info; 222 return info;
220 } 223 }
221 224
222 // static 225 // static
223 device::usb::IsochronousPacketPtr 226 device::mojom::UsbIsochronousPacketPtr
224 TypeConverter<device::usb::IsochronousPacketPtr, 227 TypeConverter<device::mojom::UsbIsochronousPacketPtr,
225 device::UsbDeviceHandle::IsochronousPacket>:: 228 device::UsbDeviceHandle::IsochronousPacket>::
226 Convert(const device::UsbDeviceHandle::IsochronousPacket& packet) { 229 Convert(const device::UsbDeviceHandle::IsochronousPacket& packet) {
227 device::usb::IsochronousPacketPtr info = 230 auto info = device::mojom::UsbIsochronousPacket::New();
228 device::usb::IsochronousPacket::New();
229 info->length = packet.length; 231 info->length = packet.length;
230 info->transferred_length = packet.transferred_length; 232 info->transferred_length = packet.transferred_length;
231 info->status = mojo::ConvertTo<device::usb::TransferStatus>(packet.status); 233 info->status =
234 mojo::ConvertTo<device::mojom::UsbTransferStatus>(packet.status);
232 return info; 235 return info;
233 } 236 }
234 237
235 } // namespace mojo 238 } // namespace mojo
OLDNEW
« no previous file with comments | « device/usb/mojo/type_converters.h ('k') | device/usb/public/interfaces/OWNERS » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698