OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 #include "device/bluetooth/bluetooth_discovery_filter.h" | 5 #include "device/bluetooth/bluetooth_discovery_filter.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "device/bluetooth/bluetooth_common.h" | |
10 | |
9 namespace device { | 11 namespace device { |
10 | 12 |
11 BluetoothDiscoveryFilter::BluetoothDiscoveryFilter(TransportMask transport) { | 13 BluetoothDiscoveryFilter::BluetoothDiscoveryFilter( |
14 BluetoothTransport transport) { | |
12 SetTransport(transport); | 15 SetTransport(transport); |
13 } | 16 } |
14 | 17 |
15 BluetoothDiscoveryFilter::~BluetoothDiscoveryFilter() { | 18 BluetoothDiscoveryFilter::~BluetoothDiscoveryFilter() { |
16 } | 19 } |
17 | 20 |
18 bool BluetoothDiscoveryFilter::GetRSSI(int16_t* out_rssi) const { | 21 bool BluetoothDiscoveryFilter::GetRSSI(int16_t* out_rssi) const { |
19 DCHECK(out_rssi); | 22 DCHECK(out_rssi); |
20 if (!rssi_.get()) | 23 if (!rssi_.get()) |
21 return false; | 24 return false; |
(...skipping 18 matching lines...) Expand all Loading... | |
40 return true; | 43 return true; |
41 } | 44 } |
42 | 45 |
43 void BluetoothDiscoveryFilter::SetPathloss(uint16_t pathloss) { | 46 void BluetoothDiscoveryFilter::SetPathloss(uint16_t pathloss) { |
44 if (!pathloss_.get()) | 47 if (!pathloss_.get()) |
45 pathloss_.reset(new uint16_t()); | 48 pathloss_.reset(new uint16_t()); |
46 | 49 |
47 *pathloss_ = pathloss; | 50 *pathloss_ = pathloss; |
48 } | 51 } |
49 | 52 |
50 BluetoothDiscoveryFilter::TransportMask BluetoothDiscoveryFilter::GetTransport() | 53 BluetoothTransport BluetoothDiscoveryFilter::GetTransport() const { |
51 const { | |
52 return transport_; | 54 return transport_; |
53 } | 55 } |
54 | 56 |
55 void BluetoothDiscoveryFilter::SetTransport(TransportMask transport) { | 57 void BluetoothDiscoveryFilter::SetTransport(BluetoothTransport transport) { |
56 DCHECK(transport > 0 && transport < 4); | 58 DCHECK(transport > 0 && transport < 4); |
57 transport_ = transport; | 59 transport_ = transport; |
58 } | 60 } |
59 | 61 |
60 void BluetoothDiscoveryFilter::GetUUIDs( | 62 void BluetoothDiscoveryFilter::GetUUIDs( |
61 std::set<device::BluetoothUUID>& out_uuids) const { | 63 std::set<device::BluetoothUUID>& out_uuids) const { |
62 out_uuids.clear(); | 64 out_uuids.clear(); |
63 | 65 |
64 for (auto& uuid : uuids_) | 66 for (auto& uuid : uuids_) |
65 out_uuids.insert(*uuid); | 67 out_uuids.insert(*uuid); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
99 std::unique_ptr<device::BluetoothDiscoveryFilter> | 101 std::unique_ptr<device::BluetoothDiscoveryFilter> |
100 BluetoothDiscoveryFilter::Merge( | 102 BluetoothDiscoveryFilter::Merge( |
101 const device::BluetoothDiscoveryFilter* filter_a, | 103 const device::BluetoothDiscoveryFilter* filter_a, |
102 const device::BluetoothDiscoveryFilter* filter_b) { | 104 const device::BluetoothDiscoveryFilter* filter_b) { |
103 std::unique_ptr<BluetoothDiscoveryFilter> result; | 105 std::unique_ptr<BluetoothDiscoveryFilter> result; |
104 | 106 |
105 if (!filter_a && !filter_b) { | 107 if (!filter_a && !filter_b) { |
106 return result; | 108 return result; |
107 } | 109 } |
108 | 110 |
109 result.reset(new BluetoothDiscoveryFilter(Transport::TRANSPORT_DUAL)); | 111 result.reset(new BluetoothDiscoveryFilter(BLUETOOTH_TRANSPORT_DUAL)); |
110 | 112 |
111 if (!filter_a || !filter_b || filter_a->IsDefault() || | 113 if (!filter_a || !filter_b || filter_a->IsDefault() || |
112 filter_b->IsDefault()) { | 114 filter_b->IsDefault()) { |
113 return result; | 115 return result; |
114 } | 116 } |
115 | 117 |
116 // both filters are not empty, so they must have transport set. | 118 // both filters are not empty, so they must have transport set. |
117 result->SetTransport(filter_a->transport_ | filter_b->transport_); | 119 result->SetTransport(static_cast<BluetoothTransport>(filter_a->transport_ | |
ortuno
2016/06/15 23:09:31
Why do you need this static_cast?
| |
120 filter_b->transport_)); | |
118 | 121 |
119 // if both filters have uuids, them merge them. Otherwise uuids filter should | 122 // if both filters have uuids, them merge them. Otherwise uuids filter should |
120 // be left empty | 123 // be left empty |
121 if (filter_a->uuids_.size() && filter_b->uuids_.size()) { | 124 if (filter_a->uuids_.size() && filter_b->uuids_.size()) { |
122 std::set<device::BluetoothUUID> uuids; | 125 std::set<device::BluetoothUUID> uuids; |
123 filter_a->GetUUIDs(uuids); | 126 filter_a->GetUUIDs(uuids); |
124 for (auto& uuid : uuids) | 127 for (auto& uuid : uuids) |
125 result->AddUUID(uuid); | 128 result->AddUUID(uuid); |
126 | 129 |
127 filter_b->GetUUIDs(uuids); | 130 filter_b->GetUUIDs(uuids); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
166 GetUUIDs(uuids_a); | 169 GetUUIDs(uuids_a); |
167 other.GetUUIDs(uuids_b); | 170 other.GetUUIDs(uuids_b); |
168 if (uuids_a != uuids_b) | 171 if (uuids_a != uuids_b) |
169 return false; | 172 return false; |
170 | 173 |
171 return true; | 174 return true; |
172 } | 175 } |
173 | 176 |
174 bool BluetoothDiscoveryFilter::IsDefault() const { | 177 bool BluetoothDiscoveryFilter::IsDefault() const { |
175 return !(rssi_.get() || pathloss_.get() || uuids_.size() || | 178 return !(rssi_.get() || pathloss_.get() || uuids_.size() || |
176 transport_ != Transport::TRANSPORT_DUAL); | 179 transport_ != BLUETOOTH_TRANSPORT_DUAL); |
177 } | 180 } |
178 | 181 |
179 } // namespace device | 182 } // namespace device |
OLD | NEW |