| 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 #ifndef DEVICE_BLUETOOTH_BLUETOOTH_DISCOVERY_FILTER_H_ | 5 #ifndef DEVICE_BLUETOOTH_BLUETOOTH_DISCOVERY_FILTER_H_ |
| 6 #define DEVICE_BLUETOOTH_BLUETOOTH_DISCOVERY_FILTER_H_ | 6 #define DEVICE_BLUETOOTH_BLUETOOTH_DISCOVERY_FILTER_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| 11 #include <set> | 11 #include <set> |
| 12 | 12 |
| 13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "base/memory/scoped_vector.h" | 14 #include "base/memory/scoped_vector.h" |
| 15 #include "device/bluetooth/bluetooth_common.h" |
| 15 #include "device/bluetooth/bluetooth_export.h" | 16 #include "device/bluetooth/bluetooth_export.h" |
| 16 #include "device/bluetooth/bluetooth_uuid.h" | 17 #include "device/bluetooth/bluetooth_uuid.h" |
| 17 | 18 |
| 18 namespace device { | 19 namespace device { |
| 19 | 20 |
| 20 // Used to keep a discovery filter that can be used to limit reported devices. | 21 // Used to keep a discovery filter that can be used to limit reported devices. |
| 21 class DEVICE_BLUETOOTH_EXPORT BluetoothDiscoveryFilter { | 22 class DEVICE_BLUETOOTH_EXPORT BluetoothDiscoveryFilter { |
| 22 public: | 23 public: |
| 23 // Possible transports to use for scan filter. | 24 BluetoothDiscoveryFilter(BluetoothTransport transport); |
| 24 enum Transport { | |
| 25 TRANSPORT_CLASSIC = 0x01, | |
| 26 TRANSPORT_LE = 0x02, | |
| 27 TRANSPORT_DUAL = (TRANSPORT_CLASSIC | TRANSPORT_LE) | |
| 28 }; | |
| 29 using TransportMask = uint8_t; | |
| 30 | |
| 31 BluetoothDiscoveryFilter(TransportMask transport); | |
| 32 ~BluetoothDiscoveryFilter(); | 25 ~BluetoothDiscoveryFilter(); |
| 33 | 26 |
| 34 // These getters return true when given field is set in filter, and copy this | 27 // These getters return true when given field is set in filter, and copy this |
| 35 // value to |out_*| parameter. If value is not set, returns false. | 28 // value to |out_*| parameter. If value is not set, returns false. |
| 36 // Thes setters assign given value to proper filter field. | 29 // Thes setters assign given value to proper filter field. |
| 37 bool GetRSSI(int16_t* out_rssi) const; | 30 bool GetRSSI(int16_t* out_rssi) const; |
| 38 void SetRSSI(int16_t rssi); | 31 void SetRSSI(int16_t rssi); |
| 39 bool GetPathloss(uint16_t* out_pathloss) const; | 32 bool GetPathloss(uint16_t* out_pathloss) const; |
| 40 void SetPathloss(uint16_t pathloss); | 33 void SetPathloss(uint16_t pathloss); |
| 41 | 34 |
| 42 // Return and set transport field of this filter. | 35 // Return and set transport field of this filter. |
| 43 TransportMask GetTransport() const; | 36 BluetoothTransport GetTransport() const; |
| 44 void SetTransport(TransportMask transport); | 37 void SetTransport(BluetoothTransport transport); |
| 45 | 38 |
| 46 // Make |out_uuids| represent all uuids assigned to this filter. | 39 // Make |out_uuids| represent all uuids assigned to this filter. |
| 47 void GetUUIDs(std::set<device::BluetoothUUID>& out_uuids) const; | 40 void GetUUIDs(std::set<device::BluetoothUUID>& out_uuids) const; |
| 48 | 41 |
| 49 // Add UUID to internal UUIDs filter. If UUIDs filter doesn't exist, it will | 42 // Add UUID to internal UUIDs filter. If UUIDs filter doesn't exist, it will |
| 50 // be created. | 43 // be created. |
| 51 void AddUUID(const device::BluetoothUUID& uuid); | 44 void AddUUID(const device::BluetoothUUID& uuid); |
| 52 | 45 |
| 53 // Copy content of |filter| and assigns it to this filter. | 46 // Copy content of |filter| and assigns it to this filter. |
| 54 void CopyFrom(const BluetoothDiscoveryFilter& filter); | 47 void CopyFrom(const BluetoothDiscoveryFilter& filter); |
| 55 | 48 |
| 56 // Check if two filters are equal. | 49 // Check if two filters are equal. |
| 57 bool Equals(const BluetoothDiscoveryFilter& filter) const; | 50 bool Equals(const BluetoothDiscoveryFilter& filter) const; |
| 58 | 51 |
| 59 // Returns true if all fields in filter are empty | 52 // Returns true if all fields in filter are empty |
| 60 bool IsDefault() const; | 53 bool IsDefault() const; |
| 61 | 54 |
| 62 // Returns result of merging two filters together. If at least one of the | 55 // Returns result of merging two filters together. If at least one of the |
| 63 // filters is NULL this will return an empty filter | 56 // filters is NULL this will return an empty filter |
| 64 static std::unique_ptr<device::BluetoothDiscoveryFilter> Merge( | 57 static std::unique_ptr<device::BluetoothDiscoveryFilter> Merge( |
| 65 const device::BluetoothDiscoveryFilter* filter_a, | 58 const device::BluetoothDiscoveryFilter* filter_a, |
| 66 const device::BluetoothDiscoveryFilter* filter_b); | 59 const device::BluetoothDiscoveryFilter* filter_b); |
| 67 | 60 |
| 68 private: | 61 private: |
| 69 std::unique_ptr<int16_t> rssi_; | 62 std::unique_ptr<int16_t> rssi_; |
| 70 std::unique_ptr<uint16_t> pathloss_; | 63 std::unique_ptr<uint16_t> pathloss_; |
| 71 TransportMask transport_; | 64 BluetoothTransport transport_; |
| 72 ScopedVector<device::BluetoothUUID> uuids_; | 65 ScopedVector<device::BluetoothUUID> uuids_; |
| 73 | 66 |
| 74 DISALLOW_COPY_AND_ASSIGN(BluetoothDiscoveryFilter); | 67 DISALLOW_COPY_AND_ASSIGN(BluetoothDiscoveryFilter); |
| 75 }; | 68 }; |
| 76 | 69 |
| 77 } // namespace device | 70 } // namespace device |
| 78 | 71 |
| 79 #endif // DEVICE_BLUETOOTH_BLUETOOTH_DISCOVERY_FILTER_H_ | 72 #endif // DEVICE_BLUETOOTH_BLUETOOTH_DISCOVERY_FILTER_H_ |
| OLD | NEW |