OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_USB_DEVICE_FILTER_H_ | 5 #ifndef DEVICE_USB_USB_DEVICE_FILTER_H_ |
6 #define DEVICE_USB_USB_DEVICE_FILTER_H_ | 6 #define DEVICE_USB_USB_DEVICE_FILTER_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 14 #include "base/optional.h" |
14 | 15 |
15 namespace base { | 16 namespace base { |
16 class Value; | 17 class Value; |
17 } | 18 } |
18 | 19 |
19 namespace device { | 20 namespace device { |
20 | 21 |
21 class UsbDevice; | 22 class UsbDevice; |
22 | 23 |
23 class UsbDeviceFilter { | 24 struct UsbDeviceFilter { |
24 public: | |
25 UsbDeviceFilter(); | 25 UsbDeviceFilter(); |
26 UsbDeviceFilter(const UsbDeviceFilter& other); | 26 UsbDeviceFilter(const UsbDeviceFilter& other); |
27 ~UsbDeviceFilter(); | 27 ~UsbDeviceFilter(); |
28 | 28 |
29 void SetVendorId(uint16_t vendor_id); | |
30 void SetProductId(uint16_t product_id); | |
31 void SetInterfaceClass(uint8_t interface_class); | |
32 void SetInterfaceSubclass(uint8_t interface_subclass); | |
33 void SetInterfaceProtocol(uint8_t interface_protocol); | |
34 | |
35 bool Matches(scoped_refptr<UsbDevice> device) const; | 29 bool Matches(scoped_refptr<UsbDevice> device) const; |
36 std::unique_ptr<base::Value> ToValue() const; | 30 std::unique_ptr<base::Value> ToValue() const; |
37 | 31 |
38 static bool MatchesAny(scoped_refptr<UsbDevice> device, | 32 static bool MatchesAny(scoped_refptr<UsbDevice> device, |
39 const std::vector<UsbDeviceFilter>& filters); | 33 const std::vector<UsbDeviceFilter>& filters); |
40 | 34 |
41 private: | 35 base::Optional<uint16_t> vendor_id; |
42 uint16_t vendor_id_; | 36 base::Optional<uint16_t> product_id; |
43 uint16_t product_id_; | 37 base::Optional<uint8_t> interface_class; |
44 uint8_t interface_class_; | 38 base::Optional<uint8_t> interface_subclass; |
45 uint8_t interface_subclass_; | 39 base::Optional<uint8_t> interface_protocol; |
46 uint8_t interface_protocol_; | |
47 bool vendor_id_set_ : 1; | |
48 bool product_id_set_ : 1; | |
49 bool interface_class_set_ : 1; | |
50 bool interface_subclass_set_ : 1; | |
51 bool interface_protocol_set_ : 1; | |
52 }; | 40 }; |
53 | 41 |
54 } // namespace device | 42 } // namespace device |
55 | 43 |
56 #endif // DEVICE_USB_USB_DEVICE_FILTER_H_ | 44 #endif // DEVICE_USB_USB_DEVICE_FILTER_H_ |
OLD | NEW |