| OLD | NEW |
| 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::mojom::UsbTransferDirection TypeConverter< | |
| 21 device::mojom::UsbTransferDirection, | |
| 22 device::UsbEndpointDirection>::Convert(const device::UsbEndpointDirection& | |
| 23 direction) { | |
| 24 if (direction == device::USB_DIRECTION_INBOUND) | |
| 25 return device::mojom::UsbTransferDirection::INBOUND; | |
| 26 DCHECK(direction == device::USB_DIRECTION_OUTBOUND); | |
| 27 return device::mojom::UsbTransferDirection::OUTBOUND; | |
| 28 } | |
| 29 | |
| 30 // static | |
| 31 device::mojom::UsbTransferStatus | |
| 32 TypeConverter<device::mojom::UsbTransferStatus, device::UsbTransferStatus>:: | |
| 33 Convert(const device::UsbTransferStatus& status) { | |
| 34 switch (status) { | |
| 35 case device::USB_TRANSFER_COMPLETED: | |
| 36 return device::mojom::UsbTransferStatus::COMPLETED; | |
| 37 case device::USB_TRANSFER_ERROR: | |
| 38 return device::mojom::UsbTransferStatus::TRANSFER_ERROR; | |
| 39 case device::USB_TRANSFER_TIMEOUT: | |
| 40 return device::mojom::UsbTransferStatus::TIMEOUT; | |
| 41 case device::USB_TRANSFER_CANCELLED: | |
| 42 return device::mojom::UsbTransferStatus::CANCELLED; | |
| 43 case device::USB_TRANSFER_STALLED: | |
| 44 return device::mojom::UsbTransferStatus::STALLED; | |
| 45 case device::USB_TRANSFER_DISCONNECT: | |
| 46 return device::mojom::UsbTransferStatus::DISCONNECT; | |
| 47 case device::USB_TRANSFER_OVERFLOW: | |
| 48 return device::mojom::UsbTransferStatus::BABBLE; | |
| 49 case device::USB_TRANSFER_LENGTH_SHORT: | |
| 50 return device::mojom::UsbTransferStatus::SHORT_PACKET; | |
| 51 default: | |
| 52 NOTREACHED(); | |
| 53 return device::mojom::UsbTransferStatus::TRANSFER_ERROR; | |
| 54 } | |
| 55 } | |
| 56 | |
| 57 // static | |
| 58 device::UsbDeviceHandle::TransferRequestType | |
| 59 TypeConverter<device::UsbDeviceHandle::TransferRequestType, | |
| 60 device::mojom::UsbControlTransferType>:: | |
| 61 Convert(const device::mojom::UsbControlTransferType& type) { | |
| 62 switch (type) { | |
| 63 case device::mojom::UsbControlTransferType::STANDARD: | |
| 64 return device::UsbDeviceHandle::STANDARD; | |
| 65 case device::mojom::UsbControlTransferType::CLASS: | |
| 66 return device::UsbDeviceHandle::CLASS; | |
| 67 case device::mojom::UsbControlTransferType::VENDOR: | |
| 68 return device::UsbDeviceHandle::VENDOR; | |
| 69 case device::mojom::UsbControlTransferType::RESERVED: | |
| 70 return device::UsbDeviceHandle::RESERVED; | |
| 71 default: | |
| 72 NOTREACHED(); | |
| 73 return device::UsbDeviceHandle::RESERVED; | |
| 74 } | |
| 75 } | |
| 76 | |
| 77 // static | |
| 78 device::UsbDeviceHandle::TransferRecipient | |
| 79 TypeConverter<device::UsbDeviceHandle::TransferRecipient, | |
| 80 device::mojom::UsbControlTransferRecipient>:: | |
| 81 Convert(const device::mojom::UsbControlTransferRecipient& recipient) { | |
| 82 switch (recipient) { | |
| 83 case device::mojom::UsbControlTransferRecipient::DEVICE: | |
| 84 return device::UsbDeviceHandle::DEVICE; | |
| 85 case device::mojom::UsbControlTransferRecipient::INTERFACE: | |
| 86 return device::UsbDeviceHandle::INTERFACE; | |
| 87 case device::mojom::UsbControlTransferRecipient::ENDPOINT: | |
| 88 return device::UsbDeviceHandle::ENDPOINT; | |
| 89 case device::mojom::UsbControlTransferRecipient::OTHER: | |
| 90 return device::UsbDeviceHandle::OTHER; | |
| 91 default: | |
| 92 NOTREACHED(); | |
| 93 return device::UsbDeviceHandle::OTHER; | |
| 94 } | |
| 95 } | |
| 96 | |
| 97 // static | |
| 98 device::mojom::UsbEndpointType | |
| 99 TypeConverter<device::mojom::UsbEndpointType, device::UsbTransferType>::Convert( | |
| 100 const device::UsbTransferType& type) { | |
| 101 switch (type) { | |
| 102 case device::USB_TRANSFER_ISOCHRONOUS: | |
| 103 return device::mojom::UsbEndpointType::ISOCHRONOUS; | |
| 104 case device::USB_TRANSFER_BULK: | |
| 105 return device::mojom::UsbEndpointType::BULK; | |
| 106 case device::USB_TRANSFER_INTERRUPT: | |
| 107 return device::mojom::UsbEndpointType::INTERRUPT; | |
| 108 // Note that we do not expose control transfer in the public interface | |
| 109 // because control endpoints are implied rather than explicitly enumerated | |
| 110 // there. | |
| 111 default: | |
| 112 NOTREACHED(); | |
| 113 return device::mojom::UsbEndpointType::BULK; | |
| 114 } | |
| 115 } | |
| 116 | |
| 117 // static | |
| 118 device::mojom::UsbEndpointInfoPtr TypeConverter< | 20 device::mojom::UsbEndpointInfoPtr TypeConverter< |
| 119 device::mojom::UsbEndpointInfoPtr, | 21 device::mojom::UsbEndpointInfoPtr, |
| 120 device::UsbEndpointDescriptor>::Convert(const device::UsbEndpointDescriptor& | 22 device::UsbEndpointDescriptor>::Convert(const device::UsbEndpointDescriptor& |
| 121 endpoint) { | 23 endpoint) { |
| 122 auto info = device::mojom::UsbEndpointInfo::New(); | 24 auto info = device::mojom::UsbEndpointInfo::New(); |
| 123 info->endpoint_number = endpoint.address & 0xf; | 25 info->endpoint_number = endpoint.address & 0xf; |
| 124 info->direction = | 26 info->direction = endpoint.direction; |
| 125 ConvertTo<device::mojom::UsbTransferDirection>(endpoint.direction); | 27 info->type = endpoint.transfer_type; |
| 126 info->type = | |
| 127 ConvertTo<device::mojom::UsbEndpointType>(endpoint.transfer_type); | |
| 128 info->packet_size = static_cast<uint32_t>(endpoint.maximum_packet_size); | 28 info->packet_size = static_cast<uint32_t>(endpoint.maximum_packet_size); |
| 129 return info; | 29 return info; |
| 130 } | 30 } |
| 131 | 31 |
| 132 // static | 32 // static |
| 133 device::mojom::UsbAlternateInterfaceInfoPtr | 33 device::mojom::UsbAlternateInterfaceInfoPtr |
| 134 TypeConverter<device::mojom::UsbAlternateInterfaceInfoPtr, | 34 TypeConverter<device::mojom::UsbAlternateInterfaceInfoPtr, |
| 135 device::UsbInterfaceDescriptor>:: | 35 device::UsbInterfaceDescriptor>:: |
| 136 Convert(const device::UsbInterfaceDescriptor& interface) { | 36 Convert(const device::UsbInterfaceDescriptor& interface) { |
| 137 auto info = device::mojom::UsbAlternateInterfaceInfo::New(); | 37 auto info = device::mojom::UsbAlternateInterfaceInfo::New(); |
| 138 info->alternate_setting = interface.alternate_setting; | 38 info->alternate_setting = interface.alternate_setting; |
| 139 info->class_code = interface.interface_class; | 39 info->class_code = interface.interface_class; |
| 140 info->subclass_code = interface.interface_subclass; | 40 info->subclass_code = interface.interface_subclass; |
| 141 info->protocol_code = interface.interface_protocol; | 41 info->protocol_code = interface.interface_protocol; |
| 142 | 42 |
| 143 // Filter out control endpoints for the public interface. | 43 // Filter out control endpoints for the public interface. |
| 144 info->endpoints.reserve(interface.endpoints.size()); | 44 info->endpoints.reserve(interface.endpoints.size()); |
| 145 for (const auto& endpoint : interface.endpoints) { | 45 for (const auto& endpoint : interface.endpoints) { |
| 146 if (endpoint.transfer_type != device::USB_TRANSFER_CONTROL) | 46 if (endpoint.transfer_type != device::UsbTransferType::CONTROL) |
| 147 info->endpoints.push_back(device::mojom::UsbEndpointInfo::From(endpoint)); | 47 info->endpoints.push_back(device::mojom::UsbEndpointInfo::From(endpoint)); |
| 148 } | 48 } |
| 149 | 49 |
| 150 return info; | 50 return info; |
| 151 } | 51 } |
| 152 | 52 |
| 153 // static | 53 // static |
| 154 std::vector<device::mojom::UsbInterfaceInfoPtr> | 54 std::vector<device::mojom::UsbInterfaceInfoPtr> |
| 155 TypeConverter<std::vector<device::mojom::UsbInterfaceInfoPtr>, | 55 TypeConverter<std::vector<device::mojom::UsbInterfaceInfoPtr>, |
| 156 std::vector<device::UsbInterfaceDescriptor>>:: | 56 std::vector<device::UsbInterfaceDescriptor>>:: |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 229 Convert(const device::UsbDeviceHandle::IsochronousPacket& packet) { | 129 Convert(const device::UsbDeviceHandle::IsochronousPacket& packet) { |
| 230 auto info = device::mojom::UsbIsochronousPacket::New(); | 130 auto info = device::mojom::UsbIsochronousPacket::New(); |
| 231 info->length = packet.length; | 131 info->length = packet.length; |
| 232 info->transferred_length = packet.transferred_length; | 132 info->transferred_length = packet.transferred_length; |
| 233 info->status = | 133 info->status = |
| 234 mojo::ConvertTo<device::mojom::UsbTransferStatus>(packet.status); | 134 mojo::ConvertTo<device::mojom::UsbTransferStatus>(packet.status); |
| 235 return info; | 135 return info; |
| 236 } | 136 } |
| 237 | 137 |
| 238 } // namespace mojo | 138 } // namespace mojo |
| OLD | NEW |