OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "device/hid/hid_device_filter.h" | |
6 | |
7 #include "device/hid/hid_device_info.h" | |
8 | |
9 namespace device { | |
10 | |
11 HidDeviceFilter::HidDeviceFilter() | |
12 : vendor_id_set_(false), | |
13 product_id_set_(false), | |
14 usage_page_set_(false), | |
15 usage_set_(false) { | |
16 } | |
17 | |
18 HidDeviceFilter::~HidDeviceFilter() { | |
19 } | |
20 | |
21 void HidDeviceFilter::SetVendorId(uint16_t vendor_id) { | |
22 vendor_id_set_ = true; | |
23 vendor_id_ = vendor_id; | |
24 } | |
25 | |
26 void HidDeviceFilter::SetProductId(uint16_t product_id) { | |
27 product_id_set_ = true; | |
28 product_id_ = product_id; | |
29 } | |
30 | |
31 void HidDeviceFilter::SetUsagePage(uint16_t usage_page) { | |
32 usage_page_set_ = true; | |
33 usage_page_ = usage_page; | |
34 } | |
35 | |
36 void HidDeviceFilter::SetUsage(uint16_t usage) { | |
37 usage_set_ = true; | |
38 usage_ = usage; | |
39 } | |
40 | |
41 bool HidDeviceFilter::Matches(const HidDeviceInfo& device_info) const { | |
42 if (vendor_id_set_) { | |
43 if (device_info.vendor_id != vendor_id_) { | |
44 return false; | |
45 } | |
46 | |
47 if (product_id_set_ && device_info.product_id != product_id_) { | |
48 return false; | |
49 } | |
50 } | |
51 | |
52 if (usage_page_set_) { | |
53 bool found_matching_collection = false; | |
54 for (std::vector<HidCollectionInfo>::const_iterator i = | |
55 device_info.collections.begin(); | |
56 i != device_info.collections.end() && !found_matching_collection; | |
57 ++i) { | |
58 const HidCollectionInfo& collection = *i; | |
59 if (collection.usage.usage_page != usage_page_) { | |
60 continue; | |
61 } | |
62 if (usage_set_ && collection.usage.usage != usage_) { | |
63 continue; | |
64 } | |
65 found_matching_collection = true; | |
66 } | |
67 if (!found_matching_collection) { | |
68 return false; | |
69 } | |
70 } | |
71 | |
72 return true; | |
73 } | |
74 | |
75 /* static */ bool HidDeviceFilter::MatchesAny( | |
Ken Rockot(use gerrit already)
2014/08/28 22:48:10
/* static */ on its own line.
| |
76 const HidDeviceInfo& device_info, | |
77 const std::vector<HidDeviceFilter>& filters) { | |
78 for (std::vector<HidDeviceFilter>::const_iterator i = filters.begin(); | |
79 i != filters.end(); | |
80 ++i) { | |
81 if (i->Matches(device_info)) { | |
82 return true; | |
83 } | |
84 } | |
85 return false; | |
86 } | |
87 | |
88 } // namespace device | |
OLD | NEW |