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