summaryrefslogtreecommitdiffstats
path: root/device
diff options
context:
space:
mode:
authorkrstnmnlsn <krstnmnlsn@chromium.org>2015-06-01 23:42:18 -0700
committerCommit bot <commit-bot@chromium.org>2015-06-02 06:42:40 +0000
commit7f9715680150b2f0c3ae46a227075859c73042b2 (patch)
tree19ecdb9e8519855c3398092176adf8f5c9b17cca /device
parenta843217c8765f7768cc8d732c1284fcd303f3274 (diff)
downloadchromium_src-7f9715680150b2f0c3ae46a227075859c73042b2.zip
chromium_src-7f9715680150b2f0c3ae46a227075859c73042b2.tar.gz
chromium_src-7f9715680150b2f0c3ae46a227075859c73042b2.tar.bz2
Moving BluetoothDiscoveryFilter into its own file.
Extracting the BluetoothDiscoveryFilter class from bluetooth_discovery_session.h and bluetooth_discovery_session.cc into its own files: bluetooth_discovery_filter.h and bluetooth_discovery_filter.cc. BUG=495305 Review URL: https://codereview.chromium.org/1163843005 Cr-Commit-Position: refs/heads/master@{#332351}
Diffstat (limited to 'device')
-rw-r--r--device/bluetooth/BUILD.gn2
-rw-r--r--device/bluetooth/bluetooth.gyp2
-rw-r--r--device/bluetooth/bluetooth_discovery_filter.cc176
-rw-r--r--device/bluetooth/bluetooth_discovery_filter.h75
-rw-r--r--device/bluetooth/bluetooth_discovery_session.cc168
-rw-r--r--device/bluetooth/bluetooth_discovery_session.h58
6 files changed, 257 insertions, 224 deletions
diff --git a/device/bluetooth/BUILD.gn b/device/bluetooth/BUILD.gn
index 31b54e17..4f0dca3 100644
--- a/device/bluetooth/BUILD.gn
+++ b/device/bluetooth/BUILD.gn
@@ -57,6 +57,8 @@ component("bluetooth") {
"bluetooth_device_mac.mm",
"bluetooth_device_win.cc",
"bluetooth_device_win.h",
+ "bluetooth_discovery_filter.cc",
+ "bluetooth_discovery_filter.h",
"bluetooth_discovery_manager_mac.h",
"bluetooth_discovery_manager_mac.mm",
"bluetooth_discovery_session.cc",
diff --git a/device/bluetooth/bluetooth.gyp b/device/bluetooth/bluetooth.gyp
index 21bb6eb..2f62154 100644
--- a/device/bluetooth/bluetooth.gyp
+++ b/device/bluetooth/bluetooth.gyp
@@ -55,6 +55,8 @@
'bluetooth_device_mac.mm',
'bluetooth_device_win.cc',
'bluetooth_device_win.h',
+ 'bluetooth_discovery_filter.cc',
+ 'bluetooth_discovery_filter.h',
'bluetooth_discovery_manager_mac.mm',
'bluetooth_discovery_manager_mac.h',
'bluetooth_discovery_session.cc',
diff --git a/device/bluetooth/bluetooth_discovery_filter.cc b/device/bluetooth/bluetooth_discovery_filter.cc
new file mode 100644
index 0000000..fe89b6a
--- /dev/null
+++ b/device/bluetooth/bluetooth_discovery_filter.cc
@@ -0,0 +1,176 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "device/bluetooth/bluetooth_discovery_filter.h"
+
+namespace device {
+
+BluetoothDiscoveryFilter::BluetoothDiscoveryFilter(TransportMask transport) {
+ SetTransport(transport);
+}
+
+BluetoothDiscoveryFilter::~BluetoothDiscoveryFilter() {
+}
+
+bool BluetoothDiscoveryFilter::GetRSSI(int16_t* out_rssi) const {
+ DCHECK(out_rssi);
+ if (!rssi_.get())
+ return false;
+
+ *out_rssi = *rssi_;
+ return true;
+}
+
+void BluetoothDiscoveryFilter::SetRSSI(int16_t rssi) {
+ if (!rssi_.get())
+ rssi_.reset(new int16_t());
+
+ *rssi_ = rssi;
+}
+
+bool BluetoothDiscoveryFilter::GetPathloss(uint16_t* out_pathloss) const {
+ DCHECK(out_pathloss);
+ if (!pathloss_.get())
+ return false;
+
+ *out_pathloss = *pathloss_;
+ return true;
+}
+
+void BluetoothDiscoveryFilter::SetPathloss(uint16_t pathloss) {
+ if (!pathloss_.get())
+ pathloss_.reset(new uint16_t());
+
+ *pathloss_ = pathloss;
+}
+
+BluetoothDiscoveryFilter::TransportMask BluetoothDiscoveryFilter::GetTransport()
+ const {
+ return transport_;
+}
+
+void BluetoothDiscoveryFilter::SetTransport(TransportMask transport) {
+ DCHECK(transport > 0 && transport < 4);
+ transport_ = transport;
+}
+
+void BluetoothDiscoveryFilter::GetUUIDs(
+ std::set<device::BluetoothUUID>& out_uuids) const {
+ out_uuids.clear();
+
+ for (auto& uuid : uuids_)
+ out_uuids.insert(*uuid);
+}
+
+void BluetoothDiscoveryFilter::AddUUID(const device::BluetoothUUID& uuid) {
+ DCHECK(uuid.IsValid());
+ for (auto& uuid_it : uuids_) {
+ if (*uuid_it == uuid)
+ return;
+ }
+
+ uuids_.push_back(new device::BluetoothUUID(uuid));
+}
+
+void BluetoothDiscoveryFilter::CopyFrom(
+ const BluetoothDiscoveryFilter& filter) {
+ transport_ = filter.transport_;
+
+ if (filter.uuids_.size()) {
+ for (auto& uuid : filter.uuids_)
+ AddUUID(*uuid);
+ } else
+ uuids_.clear();
+
+ if (filter.rssi_.get()) {
+ SetRSSI(*filter.rssi_);
+ } else
+ rssi_.reset();
+
+ if (filter.pathloss_.get()) {
+ SetPathloss(*filter.pathloss_);
+ } else
+ pathloss_.reset();
+}
+
+scoped_ptr<device::BluetoothDiscoveryFilter> BluetoothDiscoveryFilter::Merge(
+ const device::BluetoothDiscoveryFilter* filter_a,
+ const device::BluetoothDiscoveryFilter* filter_b) {
+ scoped_ptr<BluetoothDiscoveryFilter> result;
+
+ if (!filter_a && !filter_b) {
+ return result;
+ }
+
+ result.reset(new BluetoothDiscoveryFilter(Transport::TRANSPORT_DUAL));
+
+ if (!filter_a || !filter_b || filter_a->IsDefault() ||
+ filter_b->IsDefault()) {
+ return result;
+ }
+
+ // both filters are not empty, so they must have transport set.
+ result->SetTransport(filter_a->transport_ | filter_b->transport_);
+
+ // if both filters have uuids, them merge them. Otherwise uuids filter should
+ // be left empty
+ if (filter_a->uuids_.size() && filter_b->uuids_.size()) {
+ std::set<device::BluetoothUUID> uuids;
+ filter_a->GetUUIDs(uuids);
+ for (auto& uuid : uuids)
+ result->AddUUID(uuid);
+
+ filter_b->GetUUIDs(uuids);
+ for (auto& uuid : uuids)
+ result->AddUUID(uuid);
+ }
+
+ if ((filter_a->rssi_.get() && filter_b->pathloss_.get()) ||
+ (filter_a->pathloss_.get() && filter_b->rssi_.get())) {
+ // if both rssi and pathloss filtering is enabled in two different
+ // filters, we can't tell which filter is more generic, and we don't set
+ // proximity filtering on merged filter.
+ return result;
+ }
+
+ if (filter_a->rssi_.get() && filter_b->rssi_.get()) {
+ result->SetRSSI(std::min(*filter_a->rssi_, *filter_b->rssi_));
+ } else if (filter_a->pathloss_.get() && filter_b->pathloss_.get()) {
+ result->SetPathloss(std::max(*filter_a->pathloss_, *filter_b->pathloss_));
+ }
+
+ return result;
+}
+
+bool BluetoothDiscoveryFilter::Equals(
+ const BluetoothDiscoveryFilter& other) const {
+ if (((!!rssi_.get()) != (!!other.rssi_.get())) ||
+ (rssi_.get() && other.rssi_.get() && *rssi_ != *other.rssi_)) {
+ return false;
+ }
+
+ if (((!!pathloss_.get()) != (!!other.pathloss_.get())) ||
+ (pathloss_.get() && other.pathloss_.get() &&
+ *pathloss_ != *other.pathloss_)) {
+ return false;
+ }
+
+ if (transport_ != other.transport_)
+ return false;
+
+ std::set<device::BluetoothUUID> uuids_a, uuids_b;
+ GetUUIDs(uuids_a);
+ other.GetUUIDs(uuids_b);
+ if (uuids_a != uuids_b)
+ return false;
+
+ return true;
+}
+
+bool BluetoothDiscoveryFilter::IsDefault() const {
+ return !(rssi_.get() || pathloss_.get() || uuids_.size() ||
+ transport_ != Transport::TRANSPORT_DUAL);
+}
+
+} // namespace device
diff --git a/device/bluetooth/bluetooth_discovery_filter.h b/device/bluetooth/bluetooth_discovery_filter.h
new file mode 100644
index 0000000..f93198b
--- /dev/null
+++ b/device/bluetooth/bluetooth_discovery_filter.h
@@ -0,0 +1,75 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef DEVICE_BLUETOOTH_BLUETOOTH_DISCOVERY_FILTER_H_
+#define DEVICE_BLUETOOTH_BLUETOOTH_DISCOVERY_FILTER_H_
+
+#include <set>
+
+#include "base/memory/scoped_vector.h"
+#include "device/bluetooth/bluetooth_export.h"
+#include "device/bluetooth/bluetooth_uuid.h"
+
+namespace device {
+
+// Used to keep a discovery filter that can be used to limit reported devices.
+class DEVICE_BLUETOOTH_EXPORT BluetoothDiscoveryFilter {
+ public:
+ // Possible transports to use for scan filter.
+ enum Transport {
+ TRANSPORT_CLASSIC = 0x01,
+ TRANSPORT_LE = 0x02,
+ TRANSPORT_DUAL = (TRANSPORT_CLASSIC | TRANSPORT_LE)
+ };
+ using TransportMask = uint8_t;
+
+ BluetoothDiscoveryFilter(TransportMask transport);
+ ~BluetoothDiscoveryFilter();
+
+ // These getters return true when given field is set in filter, and copy this
+ // value to |out_*| parameter. If value is not set, returns false.
+ // Thes setters assign given value to proper filter field.
+ bool GetRSSI(int16_t* out_rssi) const;
+ void SetRSSI(int16_t rssi);
+ bool GetPathloss(uint16_t* out_pathloss) const;
+ void SetPathloss(uint16_t pathloss);
+
+ // Return and set transport field of this filter.
+ TransportMask GetTransport() const;
+ void SetTransport(TransportMask transport);
+
+ // Make |out_uuids| represent all uuids assigned to this filter.
+ void GetUUIDs(std::set<device::BluetoothUUID>& out_uuids) const;
+
+ // Add UUID to internal UUIDs filter. If UUIDs filter doesn't exist, it will
+ // be created.
+ void AddUUID(const device::BluetoothUUID& uuid);
+
+ // Copy content of |filter| and assigns it to this filter.
+ void CopyFrom(const BluetoothDiscoveryFilter& filter);
+
+ // Check if two filters are equal.
+ bool Equals(const BluetoothDiscoveryFilter& filter) const;
+
+ // Returns true if all fields in filter are empty
+ bool IsDefault() const;
+
+ // Returns result of merging two filters together. If at least one of the
+ // filters is NULL this will return an empty filter
+ static scoped_ptr<device::BluetoothDiscoveryFilter> Merge(
+ const device::BluetoothDiscoveryFilter* filter_a,
+ const device::BluetoothDiscoveryFilter* filter_b);
+
+ private:
+ scoped_ptr<int16_t> rssi_;
+ scoped_ptr<uint16_t> pathloss_;
+ TransportMask transport_;
+ ScopedVector<device::BluetoothUUID> uuids_;
+
+ DISALLOW_COPY_AND_ASSIGN(BluetoothDiscoveryFilter);
+};
+
+} // namespace device
+
+#endif // DEVICE_BLUETOOTH_BLUETOOTH_DISCOVERY_FILTER_H_
diff --git a/device/bluetooth/bluetooth_discovery_session.cc b/device/bluetooth/bluetooth_discovery_session.cc
index c80012e..aa348a2 100644
--- a/device/bluetooth/bluetooth_discovery_session.cc
+++ b/device/bluetooth/bluetooth_discovery_session.cc
@@ -6,176 +6,10 @@
#include "base/bind.h"
#include "device/bluetooth/bluetooth_adapter.h"
+#include "device/bluetooth/bluetooth_discovery_filter.h"
namespace device {
-BluetoothDiscoveryFilter::BluetoothDiscoveryFilter(TransportMask transport) {
- SetTransport(transport);
-}
-
-BluetoothDiscoveryFilter::~BluetoothDiscoveryFilter() {
-}
-
-bool BluetoothDiscoveryFilter::GetRSSI(int16_t* out_rssi) const {
- DCHECK(out_rssi);
- if (!rssi_.get())
- return false;
-
- *out_rssi = *rssi_;
- return true;
-}
-
-void BluetoothDiscoveryFilter::SetRSSI(int16_t rssi) {
- if (!rssi_.get())
- rssi_.reset(new int16_t());
-
- *rssi_ = rssi;
-}
-
-bool BluetoothDiscoveryFilter::GetPathloss(uint16_t* out_pathloss) const {
- DCHECK(out_pathloss);
- if (!pathloss_.get())
- return false;
-
- *out_pathloss = *pathloss_;
- return true;
-}
-
-void BluetoothDiscoveryFilter::SetPathloss(uint16_t pathloss) {
- if (!pathloss_.get())
- pathloss_.reset(new uint16_t());
-
- *pathloss_ = pathloss;
-}
-
-BluetoothDiscoveryFilter::TransportMask BluetoothDiscoveryFilter::GetTransport()
- const {
- return transport_;
-}
-
-void BluetoothDiscoveryFilter::SetTransport(TransportMask transport) {
- DCHECK(transport > 0 && transport < 4);
- transport_ = transport;
-}
-
-void BluetoothDiscoveryFilter::GetUUIDs(
- std::set<device::BluetoothUUID>& out_uuids) const {
- out_uuids.clear();
-
- for (auto& uuid : uuids_)
- out_uuids.insert(*uuid);
-}
-
-void BluetoothDiscoveryFilter::AddUUID(const device::BluetoothUUID& uuid) {
- DCHECK(uuid.IsValid());
- for (auto& uuid_it : uuids_) {
- if (*uuid_it == uuid)
- return;
- }
-
- uuids_.push_back(new device::BluetoothUUID(uuid));
-}
-
-void BluetoothDiscoveryFilter::CopyFrom(
- const BluetoothDiscoveryFilter& filter) {
- transport_ = filter.transport_;
-
- if (filter.uuids_.size()) {
- for (auto& uuid : filter.uuids_)
- AddUUID(*uuid);
- } else
- uuids_.clear();
-
- if (filter.rssi_.get()) {
- SetRSSI(*filter.rssi_);
- } else
- rssi_.reset();
-
- if (filter.pathloss_.get()) {
- SetPathloss(*filter.pathloss_);
- } else
- pathloss_.reset();
-}
-
-scoped_ptr<device::BluetoothDiscoveryFilter> BluetoothDiscoveryFilter::Merge(
- const device::BluetoothDiscoveryFilter* filter_a,
- const device::BluetoothDiscoveryFilter* filter_b) {
- scoped_ptr<BluetoothDiscoveryFilter> result;
-
- if (!filter_a && !filter_b) {
- return result;
- }
-
- result.reset(new BluetoothDiscoveryFilter(Transport::TRANSPORT_DUAL));
-
- if (!filter_a || !filter_b || filter_a->IsDefault() ||
- filter_b->IsDefault()) {
- return result;
- }
-
- // both filters are not empty, so they must have transport set.
- result->SetTransport(filter_a->transport_ | filter_b->transport_);
-
- // if both filters have uuids, them merge them. Otherwise uuids filter should
- // be left empty
- if (filter_a->uuids_.size() && filter_b->uuids_.size()) {
- std::set<device::BluetoothUUID> uuids;
- filter_a->GetUUIDs(uuids);
- for (auto& uuid : uuids)
- result->AddUUID(uuid);
-
- filter_b->GetUUIDs(uuids);
- for (auto& uuid : uuids)
- result->AddUUID(uuid);
- }
-
- if ((filter_a->rssi_.get() && filter_b->pathloss_.get()) ||
- (filter_a->pathloss_.get() && filter_b->rssi_.get())) {
- // if both rssi and pathloss filtering is enabled in two different
- // filters, we can't tell which filter is more generic, and we don't set
- // proximity filtering on merged filter.
- return result;
- }
-
- if (filter_a->rssi_.get() && filter_b->rssi_.get()) {
- result->SetRSSI(std::min(*filter_a->rssi_, *filter_b->rssi_));
- } else if (filter_a->pathloss_.get() && filter_b->pathloss_.get()) {
- result->SetPathloss(std::max(*filter_a->pathloss_, *filter_b->pathloss_));
- }
-
- return result;
-}
-
-bool BluetoothDiscoveryFilter::Equals(
- const BluetoothDiscoveryFilter& other) const {
- if (((!!rssi_.get()) != (!!other.rssi_.get())) ||
- (rssi_.get() && other.rssi_.get() && *rssi_ != *other.rssi_)) {
- return false;
- }
-
- if (((!!pathloss_.get()) != (!!other.pathloss_.get())) ||
- (pathloss_.get() && other.pathloss_.get() &&
- *pathloss_ != *other.pathloss_)) {
- return false;
- }
-
- if (transport_ != other.transport_)
- return false;
-
- std::set<device::BluetoothUUID> uuids_a, uuids_b;
- GetUUIDs(uuids_a);
- other.GetUUIDs(uuids_b);
- if (uuids_a != uuids_b)
- return false;
-
- return true;
-}
-
-bool BluetoothDiscoveryFilter::IsDefault() const {
- return !(rssi_.get() || pathloss_.get() || uuids_.size() ||
- transport_ != Transport::TRANSPORT_DUAL);
-}
-
BluetoothDiscoverySession::BluetoothDiscoverySession(
scoped_refptr<BluetoothAdapter> adapter,
scoped_ptr<BluetoothDiscoveryFilter> discovery_filter)
diff --git a/device/bluetooth/bluetooth_discovery_session.h b/device/bluetooth/bluetooth_discovery_session.h
index fe1c8f0..8e9b302 100644
--- a/device/bluetooth/bluetooth_discovery_session.h
+++ b/device/bluetooth/bluetooth_discovery_session.h
@@ -9,67 +9,11 @@
#include "base/memory/ref_counted.h"
#include "base/memory/weak_ptr.h"
#include "device/bluetooth/bluetooth_adapter.h"
+#include "device/bluetooth/bluetooth_discovery_filter.h"
#include "device/bluetooth/bluetooth_export.h"
namespace device {
-// used to keep discovery filter that might be Used to limit reported devices.
-class DEVICE_BLUETOOTH_EXPORT BluetoothDiscoveryFilter {
- public:
- // Possible transports to use for scan filter.
- enum Transport {
- TRANSPORT_CLASSIC = 0x01,
- TRANSPORT_LE = 0x02,
- TRANSPORT_DUAL = (TRANSPORT_CLASSIC | TRANSPORT_LE)
- };
- using TransportMask = uint8_t;
-
- BluetoothDiscoveryFilter(TransportMask transport);
- ~BluetoothDiscoveryFilter();
-
- // These getters return true when given field is set in filter, and copy this
- // value to |out_*| parameter. If value is not set, returns false.
- // Thes setters assign given value to proper filter field.
- bool GetRSSI(int16_t* out_rssi) const;
- void SetRSSI(int16_t rssi);
- bool GetPathloss(uint16_t* out_pathloss) const;
- void SetPathloss(uint16_t pathloss);
-
- // Return and set transport field of this filter.
- TransportMask GetTransport() const;
- void SetTransport(TransportMask transport);
-
- // Make |out_uuids| represent all uuids assigned to this filter.
- void GetUUIDs(std::set<device::BluetoothUUID>& out_uuids) const;
-
- // Add UUID to internal UUIDs filter. If UUIDs filter doesn't exist, it will
- // be created.
- void AddUUID(const device::BluetoothUUID& uuid);
-
- // Copy content of |filter| and assigns it to this filter.
- void CopyFrom(const BluetoothDiscoveryFilter& filter);
-
- // Check if two filters are equal.
- bool Equals(const BluetoothDiscoveryFilter& filter) const;
-
- // Returns true if all fields in filter are empty
- bool IsDefault() const;
-
- // Returns result of merging two filters together. If at least one of the
- // filters is NULL this will return an empty filter
- static scoped_ptr<device::BluetoothDiscoveryFilter> Merge(
- const device::BluetoothDiscoveryFilter* filter_a,
- const device::BluetoothDiscoveryFilter* filter_b);
-
- private:
- scoped_ptr<int16_t> rssi_;
- scoped_ptr<uint16_t> pathloss_;
- TransportMask transport_;
- ScopedVector<device::BluetoothUUID> uuids_;
-
- DISALLOW_COPY_AND_ASSIGN(BluetoothDiscoveryFilter);
-};
-
// BluetoothDiscoverySession represents a current active or inactive device
// discovery session. Instances of this class are obtained by calling
// BluetoothAdapter::StartDiscoverySession. The Bluetooth adapter will be