Some additional network settings cleanup
[chromium-blink-merge.git] / device / hid / hid_device_filter.cc
blob70ebcf4927d03ea2ce09ac082dd63fe08ce54a26
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.
5 #include "device/hid/hid_device_filter.h"
7 #include "device/hid/hid_device_info.h"
9 namespace device {
11 HidDeviceFilter::HidDeviceFilter()
12 : vendor_id_set_(false),
13 product_id_set_(false),
14 usage_page_set_(false),
15 usage_set_(false) {
18 HidDeviceFilter::~HidDeviceFilter() {
21 void HidDeviceFilter::SetVendorId(uint16_t vendor_id) {
22 vendor_id_set_ = true;
23 vendor_id_ = vendor_id;
26 void HidDeviceFilter::SetProductId(uint16_t product_id) {
27 product_id_set_ = true;
28 product_id_ = product_id;
31 void HidDeviceFilter::SetUsagePage(uint16_t usage_page) {
32 usage_page_set_ = true;
33 usage_page_ = usage_page;
36 void HidDeviceFilter::SetUsage(uint16_t usage) {
37 usage_set_ = true;
38 usage_ = usage;
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;
47 if (product_id_set_ && device_info.product_id != product_id_) {
48 return false;
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;
62 if (usage_set_ && collection.usage.usage != usage_) {
63 continue;
65 found_matching_collection = true;
67 if (!found_matching_collection) {
68 return false;
72 return true;
75 // static
76 bool HidDeviceFilter::MatchesAny(
77 const HidDeviceInfo& device_info,
78 const std::vector<HidDeviceFilter>& filters) {
79 for (std::vector<HidDeviceFilter>::const_iterator i = filters.begin();
80 i != filters.end();
81 ++i) {
82 if (i->Matches(device_info)) {
83 return true;
86 return false;
89 } // namespace device