Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(676)

Unified Diff: device/bluetooth/bluez/bluetooth_device_bluez.cc

Issue 2228953003: bluetooth: Change GetInquiryTxPower and GetInquiryRSSI to return optional. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@my-origin
Patch Set: TIL value_or Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « device/bluetooth/bluez/bluetooth_device_bluez.h ('k') | device/bluetooth/test/mock_bluetooth_device.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: device/bluetooth/bluez/bluetooth_device_bluez.cc
diff --git a/device/bluetooth/bluez/bluetooth_device_bluez.cc b/device/bluetooth/bluez/bluetooth_device_bluez.cc
index 7cd7041a2cf270f5be9e23ed660c9b7184c91c98..222a47fecba07aa38ffc2f79b4a682d8d9a94336 100644
--- a/device/bluetooth/bluez/bluetooth_device_bluez.cc
+++ b/device/bluetooth/bluez/bluetooth_device_bluez.cc
@@ -6,6 +6,7 @@
#include <stdio.h>
+#include <algorithm>
#include <memory>
#include <utility>
@@ -87,6 +88,16 @@ void ParseModalias(const dbus::ObjectPath& object_path,
*device_id = device_value;
}
+int8_t ClampPower(int16_t power) {
+ if (power < INT8_MIN) {
+ return INT8_MIN;
+ }
+ if (power > INT8_MAX) {
+ return INT8_MAX;
+ }
+ return static_cast<int8_t>(power);
+}
+
void RecordPairingResult(BluetoothDevice::ConnectErrorCode error_code) {
UMAPairingResult pairing_result;
switch (error_code) {
@@ -353,28 +364,34 @@ BluetoothDeviceBlueZ::UUIDList BluetoothDeviceBlueZ::GetUUIDs() const {
return uuids;
}
-int16_t BluetoothDeviceBlueZ::GetInquiryRSSI() const {
+base::Optional<int8_t> BluetoothDeviceBlueZ::GetInquiryRSSI() const {
bluez::BluetoothDeviceClient::Properties* properties =
bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->GetProperties(
object_path_);
DCHECK(properties);
if (!properties->rssi.is_valid())
- return kUnknownPower;
+ return base::nullopt;
- return properties->rssi.value();
+ // BlueZ uses int16_t because there is no int8_t for DBus, so we should never
+ // get an int16_t that cannot be represented by an int8_t. But just in case
+ // clamp the value.
+ return ClampPower(properties->rssi.value());
}
-int16_t BluetoothDeviceBlueZ::GetInquiryTxPower() const {
+base::Optional<int8_t> BluetoothDeviceBlueZ::GetInquiryTxPower() const {
bluez::BluetoothDeviceClient::Properties* properties =
bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->GetProperties(
object_path_);
DCHECK(properties);
if (!properties->tx_power.is_valid())
- return kUnknownPower;
+ return base::nullopt;
- return properties->tx_power.value();
+ // BlueZ uses int16_t because there is no int8_t for DBus, so we should never
+ // get an int16_t that cannot be represented by an int8_t. But just in case
+ // clamp the value.
+ return ClampPower(properties->tx_power.value());
}
bool BluetoothDeviceBlueZ::ExpectingPinCode() const {
« no previous file with comments | « device/bluetooth/bluez/bluetooth_device_bluez.h ('k') | device/bluetooth/test/mock_bluetooth_device.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698