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 "chromeos/dbus/bluetooth_device_client.h" | 5 #include "chromeos/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/stl_util.h" | 9 #include "base/stl_util.h" |
10 #include "dbus/bus.h" | 10 #include "dbus/bus.h" |
(...skipping 23 matching lines...) Expand all Loading... |
34 RegisterProperty(bluetooth_device::kUUIDsProperty, &uuids); | 34 RegisterProperty(bluetooth_device::kUUIDsProperty, &uuids); |
35 RegisterProperty(bluetooth_device::kPairedProperty, &paired); | 35 RegisterProperty(bluetooth_device::kPairedProperty, &paired); |
36 RegisterProperty(bluetooth_device::kConnectedProperty, &connected); | 36 RegisterProperty(bluetooth_device::kConnectedProperty, &connected); |
37 RegisterProperty(bluetooth_device::kTrustedProperty, &trusted); | 37 RegisterProperty(bluetooth_device::kTrustedProperty, &trusted); |
38 RegisterProperty(bluetooth_device::kBlockedProperty, &blocked); | 38 RegisterProperty(bluetooth_device::kBlockedProperty, &blocked); |
39 RegisterProperty(bluetooth_device::kAliasProperty, &alias); | 39 RegisterProperty(bluetooth_device::kAliasProperty, &alias); |
40 RegisterProperty(bluetooth_device::kAdapterProperty, &adapter); | 40 RegisterProperty(bluetooth_device::kAdapterProperty, &adapter); |
41 RegisterProperty(bluetooth_device::kLegacyPairingProperty, &legacy_pairing); | 41 RegisterProperty(bluetooth_device::kLegacyPairingProperty, &legacy_pairing); |
42 RegisterProperty(bluetooth_device::kModaliasProperty, &modalias); | 42 RegisterProperty(bluetooth_device::kModaliasProperty, &modalias); |
43 RegisterProperty(bluetooth_device::kRSSIProperty, &rssi); | 43 RegisterProperty(bluetooth_device::kRSSIProperty, &rssi); |
| 44 RegisterProperty(bluetooth_device::kConnectionRSSI, &connection_rssi); |
| 45 RegisterProperty(bluetooth_device::kConnectionTXPower, &connection_tx_power); |
| 46 RegisterProperty(bluetooth_device::kConnectionTXPowerMax, |
| 47 &connection_tx_power_max); |
44 } | 48 } |
45 | 49 |
46 BluetoothDeviceClient::Properties::~Properties() { | 50 BluetoothDeviceClient::Properties::~Properties() { |
47 } | 51 } |
48 | 52 |
49 | 53 |
50 // The BluetoothDeviceClient implementation used in production. | 54 // The BluetoothDeviceClient implementation used in production. |
51 class BluetoothDeviceClientImpl | 55 class BluetoothDeviceClientImpl |
52 : public BluetoothDeviceClient, | 56 : public BluetoothDeviceClient, |
53 public dbus::ObjectManager::Interface { | 57 public dbus::ObjectManager::Interface { |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
260 } | 264 } |
261 object_proxy->CallMethodWithErrorCallback( | 265 object_proxy->CallMethodWithErrorCallback( |
262 &method_call, | 266 &method_call, |
263 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 267 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
264 base::Bind(&BluetoothDeviceClientImpl::OnSuccess, | 268 base::Bind(&BluetoothDeviceClientImpl::OnSuccess, |
265 weak_ptr_factory_.GetWeakPtr(), callback), | 269 weak_ptr_factory_.GetWeakPtr(), callback), |
266 base::Bind(&BluetoothDeviceClientImpl::OnError, | 270 base::Bind(&BluetoothDeviceClientImpl::OnError, |
267 weak_ptr_factory_.GetWeakPtr(), error_callback)); | 271 weak_ptr_factory_.GetWeakPtr(), error_callback)); |
268 } | 272 } |
269 | 273 |
| 274 // BluetoothDeviceClient override. |
| 275 virtual void StartConnectionMonitor( |
| 276 const dbus::ObjectPath& object_path, |
| 277 const base::Closure& callback, |
| 278 const ErrorCallback& error_callback) OVERRIDE { |
| 279 dbus::MethodCall method_call(bluetooth_device::kBluetoothDeviceInterface, |
| 280 bluetooth_device::kStartConnectionMonitor); |
| 281 |
| 282 dbus::ObjectProxy* object_proxy = |
| 283 object_manager_->GetObjectProxy(object_path); |
| 284 if (!object_proxy) { |
| 285 error_callback.Run(kUnknownDeviceError, ""); |
| 286 return; |
| 287 } |
| 288 object_proxy->CallMethodWithErrorCallback( |
| 289 &method_call, |
| 290 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
| 291 base::Bind(&BluetoothDeviceClientImpl::OnSuccess, |
| 292 weak_ptr_factory_.GetWeakPtr(), |
| 293 callback), |
| 294 base::Bind(&BluetoothDeviceClientImpl::OnError, |
| 295 weak_ptr_factory_.GetWeakPtr(), |
| 296 error_callback)); |
| 297 } |
| 298 |
| 299 // BluetoothDeviceClient override. |
| 300 virtual void StopConnectionMonitor(const dbus::ObjectPath& object_path, |
| 301 const base::Closure& callback, |
| 302 const ErrorCallback& error_callback) { |
| 303 dbus::MethodCall method_call(bluetooth_device::kBluetoothDeviceInterface, |
| 304 bluetooth_device::kStopConnectionMonitor); |
| 305 |
| 306 dbus::ObjectProxy* object_proxy = |
| 307 object_manager_->GetObjectProxy(object_path); |
| 308 if (!object_proxy) { |
| 309 error_callback.Run(kUnknownDeviceError, ""); |
| 310 return; |
| 311 } |
| 312 object_proxy->CallMethodWithErrorCallback( |
| 313 &method_call, |
| 314 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
| 315 base::Bind(&BluetoothDeviceClientImpl::OnSuccess, |
| 316 weak_ptr_factory_.GetWeakPtr(), |
| 317 callback), |
| 318 base::Bind(&BluetoothDeviceClientImpl::OnError, |
| 319 weak_ptr_factory_.GetWeakPtr(), |
| 320 error_callback)); |
| 321 } |
| 322 |
270 protected: | 323 protected: |
271 virtual void Init(dbus::Bus* bus) OVERRIDE { | 324 virtual void Init(dbus::Bus* bus) OVERRIDE { |
272 object_manager_ = bus->GetObjectManager( | 325 object_manager_ = bus->GetObjectManager( |
273 bluetooth_object_manager::kBluetoothObjectManagerServiceName, | 326 bluetooth_object_manager::kBluetoothObjectManagerServiceName, |
274 dbus::ObjectPath( | 327 dbus::ObjectPath( |
275 bluetooth_object_manager::kBluetoothObjectManagerServicePath)); | 328 bluetooth_object_manager::kBluetoothObjectManagerServicePath)); |
276 object_manager_->RegisterInterface( | 329 object_manager_->RegisterInterface( |
277 bluetooth_device::kBluetoothDeviceInterface, this); | 330 bluetooth_device::kBluetoothDeviceInterface, this); |
278 } | 331 } |
279 | 332 |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
345 } | 398 } |
346 | 399 |
347 BluetoothDeviceClient::~BluetoothDeviceClient() { | 400 BluetoothDeviceClient::~BluetoothDeviceClient() { |
348 } | 401 } |
349 | 402 |
350 BluetoothDeviceClient* BluetoothDeviceClient::Create() { | 403 BluetoothDeviceClient* BluetoothDeviceClient::Create() { |
351 return new BluetoothDeviceClientImpl(); | 404 return new BluetoothDeviceClientImpl(); |
352 } | 405 } |
353 | 406 |
354 } // namespace chromeos | 407 } // namespace chromeos |
OLD | NEW |