Chromium Code Reviews| Index: device/usb/public/interfaces/device_manager_struct_traits.h |
| diff --git a/device/usb/public/interfaces/device_manager_struct_traits.h b/device/usb/public/interfaces/device_manager_struct_traits.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..b13ea2340c0bc5681631dc37fd254c32ed357f18 |
| --- /dev/null |
| +++ b/device/usb/public/interfaces/device_manager_struct_traits.h |
| @@ -0,0 +1,74 @@ |
| +// Copyright 2017 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef DEVICE_USB_PUBLIC_INTERFACES_DEVICE_MANAGER_STRUCT_TRAITS_H_ |
| +#define DEVICE_USB_PUBLIC_INTERFACES_DEVICE_MANAGER_STRUCT_TRAITS_H_ |
| + |
| +#include "device/usb/public/interfaces/device_manager.mojom.h" |
| +#include "device/usb/usb_device_filter.h" |
| + |
| +namespace mojo { |
| + |
| +template <> |
| +struct StructTraits<device::usb::DeviceFilterDataView, |
| + device::UsbDeviceFilter> { |
| + static bool has_vendor_id(const device::UsbDeviceFilter& filter) { |
| + return filter.vendor_id.has_value(); |
| + } |
| + |
| + static uint16_t vendor_id(const device::UsbDeviceFilter& filter) { |
| + return filter.vendor_id.value_or(0); |
| + } |
| + |
| + static bool has_product_id(const device::UsbDeviceFilter& filter) { |
| + return filter.product_id.has_value(); |
| + } |
| + |
| + static uint16_t product_id(const device::UsbDeviceFilter& filter) { |
| + return filter.product_id.value_or(0); |
| + } |
| + |
| + static bool has_class_code(const device::UsbDeviceFilter& filter) { |
| + return filter.interface_class.has_value(); |
| + } |
| + |
| + static uint8_t class_code(const device::UsbDeviceFilter& filter) { |
| + return filter.interface_class.value_or(0); |
| + } |
| + |
| + static bool has_subclass_code(const device::UsbDeviceFilter& filter) { |
| + return filter.interface_subclass.has_value(); |
| + } |
| + |
| + static uint8_t subclass_code(const device::UsbDeviceFilter& filter) { |
| + return filter.interface_subclass.value_or(0); |
| + } |
| + |
| + static bool has_protocol_code(const device::UsbDeviceFilter& filter) { |
| + return filter.interface_protocol.has_value(); |
| + } |
| + |
| + static uint8_t protocol_code(const device::UsbDeviceFilter& filter) { |
| + return filter.interface_protocol.value_or(0); |
| + } |
| + |
| + static bool Read(device::usb::DeviceFilterDataView input, |
| + device::UsbDeviceFilter* output) { |
|
juncai
2017/01/12 00:50:23
nit: move this function to .cpp file?
Reilly Grant (use Gerrit)
2017/01/12 02:18:44
Done.
|
| + if (input.has_vendor_id()) |
| + output->vendor_id = input.vendor_id(); |
| + if (input.has_product_id()) |
| + output->product_id = input.product_id(); |
| + if (input.has_class_code()) |
| + output->interface_class = input.class_code(); |
| + if (input.has_subclass_code()) |
| + output->interface_subclass = input.subclass_code(); |
| + if (input.has_protocol_code()) |
| + output->interface_protocol = input.protocol_code(); |
| + return true; |
| + } |
| +}; |
| + |
| +} // namespace mojo |
| + |
| +#endif // DEVICE_USB_PUBLIC_INTERFACES_DEVICE_MANAGER_STRUCT_TRAITS_H_ |