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

Side by Side Diff: device/bluetooth/dbus/bluetooth_device_client.cc

Issue 1941923002: bluetooth: Return int8_t and use -128 for unknown tx power. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@my-origin
Patch Set: Moar fixes Created 4 years, 7 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 unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/dbus/bluetooth_device_client.h" 5 #include "device/bluetooth/dbus/bluetooth_device_client.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/stl_util.h" 10 #include "base/stl_util.h"
11 #include "dbus/bus.h" 11 #include "dbus/bus.h"
12 #include "dbus/message.h" 12 #include "dbus/message.h"
13 #include "dbus/object_manager.h" 13 #include "dbus/object_manager.h"
14 #include "dbus/object_proxy.h" 14 #include "dbus/object_proxy.h"
15 #include "third_party/cros_system_api/dbus/service_constants.h" 15 #include "third_party/cros_system_api/dbus/service_constants.h"
16 16
17 namespace bluez { 17 namespace bluez {
18 18
19 namespace { 19 namespace {
20 20
21 // Value returned for the the RSSI or TX power if it cannot be read. 21 // The value returned if the RSSI cannot be read.
22 const int kUnknownPower = 127; 22 constexpr int8_t kUnknownRSSI = 127;
scheib 2016/05/04 01:18:38 Let's use the constants from bluetootn_device.h
ortuno 2016/05/04 16:44:12 I don't think we are allowed to depend on device/b
23 // The value returned if the TxPower cannot be read.
24 constexpr int8_t kUnknownTxPower = -128;
23 25
24 } // namespace 26 } // namespace
25 27
26 const char BluetoothDeviceClient::kNoResponseError[] = 28 const char BluetoothDeviceClient::kNoResponseError[] =
27 "org.chromium.Error.NoResponse"; 29 "org.chromium.Error.NoResponse";
28 const char BluetoothDeviceClient::kUnknownDeviceError[] = 30 const char BluetoothDeviceClient::kUnknownDeviceError[] =
29 "org.chromium.Error.UnknownDevice"; 31 "org.chromium.Error.UnknownDevice";
30 32
31 BluetoothDeviceClient::Properties::Properties( 33 BluetoothDeviceClient::Properties::Properties(
32 dbus::ObjectProxy* object_proxy, 34 dbus::ObjectProxy* object_proxy,
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 315
314 // Called when a response for successful method call is received. 316 // Called when a response for successful method call is received.
315 void OnSuccess(const base::Closure& callback, dbus::Response* response) { 317 void OnSuccess(const base::Closure& callback, dbus::Response* response) {
316 DCHECK(response); 318 DCHECK(response);
317 callback.Run(); 319 callback.Run();
318 } 320 }
319 321
320 // Called when a response for the GetConnInfo method is received. 322 // Called when a response for the GetConnInfo method is received.
321 void OnGetConnInfoSuccess(const ConnInfoCallback& callback, 323 void OnGetConnInfoSuccess(const ConnInfoCallback& callback,
322 dbus::Response* response) { 324 dbus::Response* response) {
323 int16_t rssi = kUnknownPower; 325 int16_t rssi = kUnknownRSSI;
324 int16_t transmit_power = kUnknownPower; 326 int16_t transmit_power = kUnknownTxPower;
325 int16_t max_transmit_power = kUnknownPower; 327 int16_t max_transmit_power = kUnknownTxPower;
326 328
327 if (!response) { 329 if (!response) {
328 LOG(ERROR) << "GetConnInfo succeeded, but no response received."; 330 LOG(ERROR) << "GetConnInfo succeeded, but no response received.";
329 callback.Run(rssi, transmit_power, max_transmit_power); 331 callback.Run(rssi, transmit_power, max_transmit_power);
330 return; 332 return;
331 } 333 }
332 334
333 dbus::MessageReader reader(response); 335 dbus::MessageReader reader(response);
334 if (!reader.PopInt16(&rssi) || !reader.PopInt16(&transmit_power) || 336 if (!reader.PopInt16(&rssi) || !reader.PopInt16(&transmit_power) ||
335 !reader.PopInt16(&max_transmit_power)) { 337 !reader.PopInt16(&max_transmit_power)) {
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 373
372 BluetoothDeviceClient::BluetoothDeviceClient() {} 374 BluetoothDeviceClient::BluetoothDeviceClient() {}
373 375
374 BluetoothDeviceClient::~BluetoothDeviceClient() {} 376 BluetoothDeviceClient::~BluetoothDeviceClient() {}
375 377
376 BluetoothDeviceClient* BluetoothDeviceClient::Create() { 378 BluetoothDeviceClient* BluetoothDeviceClient::Create() {
377 return new BluetoothDeviceClientImpl(); 379 return new BluetoothDeviceClientImpl();
378 } 380 }
379 381
380 } // namespace bluez 382 } // namespace bluez
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698