OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2017 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 #ifndef DEVICE_USB_PUBLIC_INTERFACES_DEVICE_MANAGER_STRUCT_TRAITS_H_ | |
6 #define DEVICE_USB_PUBLIC_INTERFACES_DEVICE_MANAGER_STRUCT_TRAITS_H_ | |
7 | |
8 #include "device/usb/public/interfaces/device_manager.mojom.h" | |
9 #include "device/usb/usb_device_filter.h" | |
10 | |
11 namespace mojo { | |
12 | |
13 template <> | |
14 struct StructTraits<device::usb::DeviceFilterDataView, | |
15 device::UsbDeviceFilter> { | |
16 static bool has_vendor_id(const device::UsbDeviceFilter& filter) { | |
17 return filter.vendor_id.has_value(); | |
18 } | |
19 | |
20 static uint16_t vendor_id(const device::UsbDeviceFilter& filter) { | |
21 return filter.vendor_id.value_or(0); | |
22 } | |
23 | |
24 static bool has_product_id(const device::UsbDeviceFilter& filter) { | |
25 return filter.product_id.has_value(); | |
26 } | |
27 | |
28 static uint16_t product_id(const device::UsbDeviceFilter& filter) { | |
29 return filter.product_id.value_or(0); | |
30 } | |
31 | |
32 static bool has_class_code(const device::UsbDeviceFilter& filter) { | |
33 return filter.interface_class.has_value(); | |
34 } | |
35 | |
36 static uint8_t class_code(const device::UsbDeviceFilter& filter) { | |
37 return filter.interface_class.value_or(0); | |
38 } | |
39 | |
40 static bool has_subclass_code(const device::UsbDeviceFilter& filter) { | |
41 return filter.interface_subclass.has_value(); | |
42 } | |
43 | |
44 static uint8_t subclass_code(const device::UsbDeviceFilter& filter) { | |
45 return filter.interface_subclass.value_or(0); | |
46 } | |
47 | |
48 static bool has_protocol_code(const device::UsbDeviceFilter& filter) { | |
49 return filter.interface_protocol.has_value(); | |
50 } | |
51 | |
52 static uint8_t protocol_code(const device::UsbDeviceFilter& filter) { | |
53 return filter.interface_protocol.value_or(0); | |
54 } | |
55 | |
56 static bool Read(device::usb::DeviceFilterDataView input, | |
57 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.
| |
58 if (input.has_vendor_id()) | |
59 output->vendor_id = input.vendor_id(); | |
60 if (input.has_product_id()) | |
61 output->product_id = input.product_id(); | |
62 if (input.has_class_code()) | |
63 output->interface_class = input.class_code(); | |
64 if (input.has_subclass_code()) | |
65 output->interface_subclass = input.subclass_code(); | |
66 if (input.has_protocol_code()) | |
67 output->interface_protocol = input.protocol_code(); | |
68 return true; | |
69 } | |
70 }; | |
71 | |
72 } // namespace mojo | |
73 | |
74 #endif // DEVICE_USB_PUBLIC_INTERFACES_DEVICE_MANAGER_STRUCT_TRAITS_H_ | |
OLD | NEW |