OLD | NEW |
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/optional.h" |
10 #include "base/stl_util.h" | 11 #include "base/stl_util.h" |
11 #include "dbus/bus.h" | 12 #include "dbus/bus.h" |
12 #include "dbus/message.h" | 13 #include "dbus/message.h" |
13 #include "dbus/object_manager.h" | 14 #include "dbus/object_manager.h" |
14 #include "dbus/object_proxy.h" | 15 #include "dbus/object_proxy.h" |
15 #include "third_party/cros_system_api/dbus/service_constants.h" | 16 #include "third_party/cros_system_api/dbus/service_constants.h" |
16 | 17 |
17 namespace bluez { | 18 namespace bluez { |
18 | 19 |
19 namespace { | |
20 | |
21 // Value returned for the the RSSI or TX power if it cannot be read. | |
22 const int kUnknownPower = 127; | |
23 | |
24 } // namespace | |
25 | |
26 const char BluetoothDeviceClient::kNoResponseError[] = | 20 const char BluetoothDeviceClient::kNoResponseError[] = |
27 "org.chromium.Error.NoResponse"; | 21 "org.chromium.Error.NoResponse"; |
28 const char BluetoothDeviceClient::kUnknownDeviceError[] = | 22 const char BluetoothDeviceClient::kUnknownDeviceError[] = |
29 "org.chromium.Error.UnknownDevice"; | 23 "org.chromium.Error.UnknownDevice"; |
30 | 24 |
31 BluetoothDeviceClient::Properties::Properties( | 25 BluetoothDeviceClient::Properties::Properties( |
32 dbus::ObjectProxy* object_proxy, | 26 dbus::ObjectProxy* object_proxy, |
33 const std::string& interface_name, | 27 const std::string& interface_name, |
34 const PropertyChangedCallback& callback) | 28 const PropertyChangedCallback& callback) |
35 : dbus::PropertySet(object_proxy, interface_name, callback) { | 29 : dbus::PropertySet(object_proxy, interface_name, callback) { |
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
313 | 307 |
314 // Called when a response for successful method call is received. | 308 // Called when a response for successful method call is received. |
315 void OnSuccess(const base::Closure& callback, dbus::Response* response) { | 309 void OnSuccess(const base::Closure& callback, dbus::Response* response) { |
316 DCHECK(response); | 310 DCHECK(response); |
317 callback.Run(); | 311 callback.Run(); |
318 } | 312 } |
319 | 313 |
320 // Called when a response for the GetConnInfo method is received. | 314 // Called when a response for the GetConnInfo method is received. |
321 void OnGetConnInfoSuccess(const ConnInfoCallback& callback, | 315 void OnGetConnInfoSuccess(const ConnInfoCallback& callback, |
322 dbus::Response* response) { | 316 dbus::Response* response) { |
323 int16_t rssi = kUnknownPower; | |
324 int16_t transmit_power = kUnknownPower; | |
325 int16_t max_transmit_power = kUnknownPower; | |
326 | |
327 if (!response) { | 317 if (!response) { |
328 LOG(ERROR) << "GetConnInfo succeeded, but no response received."; | 318 LOG(ERROR) << "GetConnInfo succeeded, but no response received."; |
329 callback.Run(rssi, transmit_power, max_transmit_power); | 319 callback.Run(base::nullopt /* rssi */, base::nullopt /* transmit_power */, |
| 320 base::nullopt /* max_tx_power */); |
330 return; | 321 return; |
331 } | 322 } |
332 | 323 |
| 324 int16_t rssi; |
| 325 int16_t transmit_power; |
| 326 int16_t max_transmit_power; |
| 327 |
333 dbus::MessageReader reader(response); | 328 dbus::MessageReader reader(response); |
334 if (!reader.PopInt16(&rssi) || !reader.PopInt16(&transmit_power) || | 329 if (!reader.PopInt16(&rssi) || !reader.PopInt16(&transmit_power) || |
335 !reader.PopInt16(&max_transmit_power)) { | 330 !reader.PopInt16(&max_transmit_power)) { |
336 LOG(ERROR) << "Arguments for GetConnInfo invalid."; | 331 LOG(ERROR) << "Arguments for GetConnInfo invalid."; |
337 } | 332 } |
338 callback.Run(rssi, transmit_power, max_transmit_power); | 333 callback.Run(base::make_optional(rssi), base::make_optional(transmit_power), |
| 334 base::make_optional(max_transmit_power)); |
339 } | 335 } |
340 | 336 |
341 // Called when a response for a failed method call is received. | 337 // Called when a response for a failed method call is received. |
342 void OnError(const ErrorCallback& error_callback, | 338 void OnError(const ErrorCallback& error_callback, |
343 dbus::ErrorResponse* response) { | 339 dbus::ErrorResponse* response) { |
344 // Error response has optional error message argument. | 340 // Error response has optional error message argument. |
345 std::string error_name; | 341 std::string error_name; |
346 std::string error_message; | 342 std::string error_message; |
347 if (response) { | 343 if (response) { |
348 dbus::MessageReader reader(response); | 344 dbus::MessageReader reader(response); |
(...skipping 22 matching lines...) Expand all Loading... |
371 | 367 |
372 BluetoothDeviceClient::BluetoothDeviceClient() {} | 368 BluetoothDeviceClient::BluetoothDeviceClient() {} |
373 | 369 |
374 BluetoothDeviceClient::~BluetoothDeviceClient() {} | 370 BluetoothDeviceClient::~BluetoothDeviceClient() {} |
375 | 371 |
376 BluetoothDeviceClient* BluetoothDeviceClient::Create() { | 372 BluetoothDeviceClient* BluetoothDeviceClient::Create() { |
377 return new BluetoothDeviceClientImpl(); | 373 return new BluetoothDeviceClientImpl(); |
378 } | 374 } |
379 | 375 |
380 } // namespace bluez | 376 } // namespace bluez |
OLD | NEW |