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"
11 HidDeviceFilter::HidDeviceFilter()
12 : vendor_id_set_(false),
13 product_id_set_(false),
14 usage_page_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
) {
41 bool HidDeviceFilter::Matches(const HidDeviceInfo
& device_info
) const {
43 if (device_info
.vendor_id
!= vendor_id_
) {
47 if (product_id_set_
&& device_info
.product_id
!= product_id_
) {
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
;
58 const HidCollectionInfo
& collection
= *i
;
59 if (collection
.usage
.usage_page
!= usage_page_
) {
62 if (usage_set_
&& collection
.usage
.usage
!= usage_
) {
65 found_matching_collection
= true;
67 if (!found_matching_collection
) {
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();
82 if (i
->Matches(device_info
)) {