Use Optional for Discovery Filter's RSSI and Pathloss
RSSI and Pathloss were unique pointers so that we can check for null. This was done before we had base::Optional. Now that we have Optional it is best to use that so this switches them to use optional. Bug: N/A Change-Id: Ic37c80132d27e2c1334aea320e66cdc7feb7f722 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1459777 Commit-Queue: James Hollyer <jameshollyer@chromium.org> Reviewed-by: Reilly Grant <reillyg@chromium.org> Cr-Commit-Position: refs/heads/master@{#645103}
This commit is contained in:

committed by
Commit Bot

parent
a30c821dfe
commit
38537d42ce
device/bluetooth
@ -21,7 +21,7 @@ BluetoothDiscoveryFilter::~BluetoothDiscoveryFilter() = default;
|
||||
|
||||
bool BluetoothDiscoveryFilter::GetRSSI(int16_t* out_rssi) const {
|
||||
DCHECK(out_rssi);
|
||||
if (!rssi_.get())
|
||||
if (!rssi_)
|
||||
return false;
|
||||
|
||||
*out_rssi = *rssi_;
|
||||
@ -29,15 +29,12 @@ bool BluetoothDiscoveryFilter::GetRSSI(int16_t* out_rssi) const {
|
||||
}
|
||||
|
||||
void BluetoothDiscoveryFilter::SetRSSI(int16_t rssi) {
|
||||
if (!rssi_.get())
|
||||
rssi_.reset(new int16_t());
|
||||
|
||||
*rssi_ = rssi;
|
||||
rssi_ = rssi;
|
||||
}
|
||||
|
||||
bool BluetoothDiscoveryFilter::GetPathloss(uint16_t* out_pathloss) const {
|
||||
DCHECK(out_pathloss);
|
||||
if (!pathloss_.get())
|
||||
if (!pathloss_)
|
||||
return false;
|
||||
|
||||
*out_pathloss = *pathloss_;
|
||||
@ -45,10 +42,7 @@ bool BluetoothDiscoveryFilter::GetPathloss(uint16_t* out_pathloss) const {
|
||||
}
|
||||
|
||||
void BluetoothDiscoveryFilter::SetPathloss(uint16_t pathloss) {
|
||||
if (!pathloss_.get())
|
||||
pathloss_.reset(new uint16_t());
|
||||
|
||||
*pathloss_ = pathloss;
|
||||
pathloss_ = pathloss;
|
||||
}
|
||||
|
||||
BluetoothTransport BluetoothDiscoveryFilter::GetTransport() const {
|
||||
@ -88,15 +82,8 @@ void BluetoothDiscoveryFilter::CopyFrom(
|
||||
} else
|
||||
uuids_.clear();
|
||||
|
||||
if (filter.rssi_.get()) {
|
||||
SetRSSI(*filter.rssi_);
|
||||
} else
|
||||
rssi_.reset();
|
||||
|
||||
if (filter.pathloss_.get()) {
|
||||
SetPathloss(*filter.pathloss_);
|
||||
} else
|
||||
pathloss_.reset();
|
||||
rssi_ = filter.rssi_;
|
||||
pathloss_ = filter.pathloss_;
|
||||
}
|
||||
|
||||
std::unique_ptr<device::BluetoothDiscoveryFilter>
|
||||
@ -133,17 +120,17 @@ BluetoothDiscoveryFilter::Merge(
|
||||
result->AddUUID(uuid);
|
||||
}
|
||||
|
||||
if ((filter_a->rssi_.get() && filter_b->pathloss_.get()) ||
|
||||
(filter_a->pathloss_.get() && filter_b->rssi_.get())) {
|
||||
if ((filter_a->rssi_ && filter_b->pathloss_) ||
|
||||
(filter_a->pathloss_ && filter_b->rssi_)) {
|
||||
// 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()) {
|
||||
if (filter_a->rssi_ && filter_b->rssi_) {
|
||||
result->SetRSSI(std::min(*filter_a->rssi_, *filter_b->rssi_));
|
||||
} else if (filter_a->pathloss_.get() && filter_b->pathloss_.get()) {
|
||||
} else if (filter_a->pathloss_ && filter_b->pathloss_) {
|
||||
result->SetPathloss(std::max(*filter_a->pathloss_, *filter_b->pathloss_));
|
||||
}
|
||||
|
||||
@ -152,14 +139,13 @@ BluetoothDiscoveryFilter::Merge(
|
||||
|
||||
bool BluetoothDiscoveryFilter::Equals(
|
||||
const BluetoothDiscoveryFilter& other) const {
|
||||
if (((!!rssi_.get()) != (!!other.rssi_.get())) ||
|
||||
(rssi_.get() && other.rssi_.get() && *rssi_ != *other.rssi_)) {
|
||||
if ((rssi_.has_value() != other.rssi_.has_value()) ||
|
||||
(rssi_ && other.rssi_ && *rssi_ != *other.rssi_)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (((!!pathloss_.get()) != (!!other.pathloss_.get())) ||
|
||||
(pathloss_.get() && other.pathloss_.get() &&
|
||||
*pathloss_ != *other.pathloss_)) {
|
||||
if ((pathloss_.has_value() != other.pathloss_.has_value()) ||
|
||||
(pathloss_ && other.pathloss_ && *pathloss_ != *other.pathloss_)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -176,7 +162,7 @@ bool BluetoothDiscoveryFilter::Equals(
|
||||
}
|
||||
|
||||
bool BluetoothDiscoveryFilter::IsDefault() const {
|
||||
return !(rssi_.get() || pathloss_.get() || uuids_.size() ||
|
||||
return !(rssi_ || pathloss_ || uuids_.size() ||
|
||||
transport_ != BLUETOOTH_TRANSPORT_DUAL);
|
||||
}
|
||||
|
||||
|
@ -12,6 +12,7 @@
|
||||
#include <vector>
|
||||
|
||||
#include "base/macros.h"
|
||||
#include "base/optional.h"
|
||||
#include "device/bluetooth/bluetooth_common.h"
|
||||
#include "device/bluetooth/bluetooth_export.h"
|
||||
#include "device/bluetooth/bluetooth_uuid.h"
|
||||
@ -59,8 +60,8 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothDiscoveryFilter {
|
||||
const device::BluetoothDiscoveryFilter* filter_b);
|
||||
|
||||
private:
|
||||
std::unique_ptr<int16_t> rssi_;
|
||||
std::unique_ptr<uint16_t> pathloss_;
|
||||
base::Optional<int16_t> rssi_;
|
||||
base::Optional<uint16_t> pathloss_;
|
||||
BluetoothTransport transport_;
|
||||
std::vector<std::unique_ptr<device::BluetoothUUID>> uuids_;
|
||||
|
||||
|
Reference in New Issue
Block a user