Chromium Code Reviews| 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 #ifndef DEVICE_USB_MOJO_TYPE_CONVERTERS_H_ | 5 #ifndef DEVICE_USB_MOJO_TYPE_CONVERTERS_H_ |
| 6 #define DEVICE_USB_MOJO_TYPE_CONVERTERS_H_ | 6 #define DEVICE_USB_MOJO_TYPE_CONVERTERS_H_ |
| 7 | 7 |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "device/usb/public/interfaces/device.mojom.h" | 10 #include "device/usb/public/interfaces/device.mojom.h" |
| 11 #include "device/usb/public/interfaces/device_manager.mojom.h" | 11 #include "device/usb/public/interfaces/device_manager.mojom.h" |
| 12 #include "device/usb/usb_descriptors.h" | 12 #include "device/usb/usb_descriptors.h" |
| 13 #include "device/usb/usb_device_filter.h" | 13 #include "device/usb/usb_device_filter.h" |
| 14 #include "device/usb/usb_device_handle.h" | 14 #include "device/usb/usb_device_handle.h" |
| 15 #include "mojo/public/cpp/bindings/array.h" | |
| 16 #include "mojo/public/cpp/bindings/type_converter.h" | 15 #include "mojo/public/cpp/bindings/type_converter.h" |
| 17 | 16 |
| 18 // Type converters to translate between internal device/usb data types and | 17 // Type converters to translate between internal device/usb data types and |
| 19 // public Mojo interface data types. This must be included by any source file | 18 // public Mojo interface data types. This must be included by any source file |
| 20 // that uses these conversions explicitly or implicitly. | 19 // that uses these conversions explicitly or implicitly. |
| 21 | 20 |
| 22 namespace device { | 21 namespace device { |
| 23 class UsbDevice; | 22 class UsbDevice; |
| 24 } | 23 } |
| 25 | 24 |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 75 device::UsbInterfaceDescriptor> { | 74 device::UsbInterfaceDescriptor> { |
| 76 static device::usb::AlternateInterfaceInfoPtr Convert( | 75 static device::usb::AlternateInterfaceInfoPtr Convert( |
| 77 const device::UsbInterfaceDescriptor& iface); | 76 const device::UsbInterfaceDescriptor& iface); |
| 78 }; | 77 }; |
| 79 | 78 |
| 80 // Note that this is an explicit vector-to-array conversion, as | 79 // Note that this is an explicit vector-to-array conversion, as |
| 81 // UsbInterfaceDescriptor collections are flattened to contain all alternate | 80 // UsbInterfaceDescriptor collections are flattened to contain all alternate |
| 82 // settings, whereas InterfaceInfos contain their own sets of alternates with | 81 // settings, whereas InterfaceInfos contain their own sets of alternates with |
| 83 // a different structure type. | 82 // a different structure type. |
| 84 template <> | 83 template <> |
| 85 struct TypeConverter<mojo::Array<device::usb::InterfaceInfoPtr>, | 84 struct TypeConverter<std::vector<device::usb::InterfaceInfoPtr>, |
| 86 std::vector<device::UsbInterfaceDescriptor>> { | 85 std::vector<device::UsbInterfaceDescriptor>> { |
| 87 static mojo::Array<device::usb::InterfaceInfoPtr> Convert( | 86 static std::vector<device::usb::InterfaceInfoPtr> Convert( |
| 88 const std::vector<device::UsbInterfaceDescriptor>& interfaces); | 87 const std::vector<device::UsbInterfaceDescriptor>& interfaces); |
| 89 }; | 88 }; |
| 90 | 89 |
| 91 template <> | 90 template <> |
| 92 struct TypeConverter<device::usb::ConfigurationInfoPtr, | 91 struct TypeConverter<device::usb::ConfigurationInfoPtr, |
| 93 device::UsbConfigDescriptor> { | 92 device::UsbConfigDescriptor> { |
| 94 static device::usb::ConfigurationInfoPtr Convert( | 93 static device::usb::ConfigurationInfoPtr Convert( |
| 95 const device::UsbConfigDescriptor& config); | 94 const device::UsbConfigDescriptor& config); |
| 96 }; | 95 }; |
| 97 | 96 |
| 98 template <> | 97 template <> |
| 99 struct TypeConverter<device::usb::DeviceInfoPtr, device::UsbDevice> { | 98 struct TypeConverter<device::usb::DeviceInfoPtr, device::UsbDevice> { |
| 100 static device::usb::DeviceInfoPtr Convert(const device::UsbDevice& device); | 99 static device::usb::DeviceInfoPtr Convert(const device::UsbDevice& device); |
| 101 }; | 100 }; |
| 102 | 101 |
| 103 template <> | 102 template <> |
| 104 struct TypeConverter<device::usb::IsochronousPacketPtr, | 103 struct TypeConverter<device::usb::IsochronousPacketPtr, |
| 105 device::UsbDeviceHandle::IsochronousPacket> { | 104 device::UsbDeviceHandle::IsochronousPacket> { |
| 106 static device::usb::IsochronousPacketPtr Convert( | 105 static device::usb::IsochronousPacketPtr Convert( |
| 107 const device::UsbDeviceHandle::IsochronousPacket& packet); | 106 const device::UsbDeviceHandle::IsochronousPacket& packet); |
| 108 }; | 107 }; |
| 109 | 108 |
| 109 template <typename A, typename B> | |
|
dcheng
2016/08/15 21:41:28
The main thing I'm worried about is this leading t
| |
| 110 struct TypeConverter<std::vector<A>, std::vector<B>> { | |
| 111 static std::vector<A> Convert(const std::vector<B>& input) { | |
| 112 std::vector<A> result; | |
| 113 result.reserve(input.size()); | |
| 114 for (const B& item : input) | |
| 115 result.push_back(mojo::ConvertTo<A>(item)); | |
| 116 return result; | |
| 117 }; | |
| 118 }; | |
| 119 | |
| 110 } // namespace mojo | 120 } // namespace mojo |
| 111 | 121 |
| 112 #endif // DEVICE_DEVICES_APP_USB_TYPE_CONVERTERS_H_ | 122 #endif // DEVICE_DEVICES_APP_USB_TYPE_CONVERTERS_H_ |
| OLD | NEW |