OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <map> | 7 #include <map> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/stl_util.h" | 12 #include "base/stl_util.h" |
13 #include "chromeos/dbus/bluetooth_adapter_client.h" | 13 #include "chromeos/dbus/bluetooth_adapter_client.h" |
14 #include "chromeos/dbus/bluetooth_property.h" | 14 #include "chromeos/dbus/bluetooth_property.h" |
15 #include "dbus/bus.h" | 15 #include "dbus/bus.h" |
16 #include "dbus/message.h" | 16 #include "dbus/message.h" |
17 #include "dbus/object_path.h" | 17 #include "dbus/object_path.h" |
18 #include "dbus/object_proxy.h" | 18 #include "dbus/object_proxy.h" |
19 #include "third_party/cros_system_api/dbus/service_constants.h" | 19 #include "third_party/cros_system_api/dbus/service_constants.h" |
20 | 20 |
21 namespace chromeos { | 21 namespace chromeos { |
22 | 22 |
23 BluetoothDeviceClient::Properties::Properties(dbus::ObjectProxy* object_proxy, | 23 BluetoothDeviceClient::Properties::Properties( |
24 PropertyChangedCallback callback) | 24 dbus::ObjectProxy* object_proxy, |
| 25 const PropertyChangedCallback& callback) |
25 : BluetoothPropertySet(object_proxy, | 26 : BluetoothPropertySet(object_proxy, |
26 bluetooth_device::kBluetoothDeviceInterface, | 27 bluetooth_device::kBluetoothDeviceInterface, |
27 callback) { | 28 callback) { |
28 RegisterProperty(bluetooth_device::kAddressProperty, &address); | 29 RegisterProperty(bluetooth_device::kAddressProperty, &address); |
29 RegisterProperty(bluetooth_device::kNameProperty, &name); | 30 RegisterProperty(bluetooth_device::kNameProperty, &name); |
30 RegisterProperty(bluetooth_device::kVendorProperty, &vendor); | 31 RegisterProperty(bluetooth_device::kVendorProperty, &vendor); |
31 RegisterProperty(bluetooth_device::kProductProperty, &product); | 32 RegisterProperty(bluetooth_device::kProductProperty, &product); |
32 RegisterProperty(bluetooth_device::kVersionProperty, &version); | 33 RegisterProperty(bluetooth_device::kVersionProperty, &version); |
33 RegisterProperty(bluetooth_device::kIconProperty, &icon); | 34 RegisterProperty(bluetooth_device::kIconProperty, &icon); |
34 RegisterProperty(bluetooth_device::kClassProperty, &bluetooth_class); | 35 RegisterProperty(bluetooth_device::kClassProperty, &bluetooth_class); |
(...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
457 // List of observers interested in event notifications from us. | 458 // List of observers interested in event notifications from us. |
458 ObserverList<BluetoothDeviceClient::Observer> observers_; | 459 ObserverList<BluetoothDeviceClient::Observer> observers_; |
459 | 460 |
460 DISALLOW_COPY_AND_ASSIGN(BluetoothDeviceClientImpl); | 461 DISALLOW_COPY_AND_ASSIGN(BluetoothDeviceClientImpl); |
461 }; | 462 }; |
462 | 463 |
463 // The BluetoothDeviceClient implementation used on Linux desktop, which does | 464 // The BluetoothDeviceClient implementation used on Linux desktop, which does |
464 // nothing. | 465 // nothing. |
465 class BluetoothDeviceClientStubImpl : public BluetoothDeviceClient { | 466 class BluetoothDeviceClientStubImpl : public BluetoothDeviceClient { |
466 public: | 467 public: |
| 468 struct Properties : public BluetoothDeviceClient::Properties { |
| 469 explicit Properties(const PropertyChangedCallback& callback) |
| 470 : BluetoothDeviceClient::Properties(NULL, callback) { |
| 471 } |
| 472 |
| 473 virtual ~Properties() { |
| 474 } |
| 475 |
| 476 virtual void Get(dbus::PropertyBase* property, |
| 477 dbus::PropertySet::GetCallback callback) OVERRIDE { |
| 478 VLOG(1) << "Get " << property->name(); |
| 479 callback.Run(false); |
| 480 } |
| 481 |
| 482 virtual void GetAll() OVERRIDE { |
| 483 VLOG(1) << "GetAll"; |
| 484 } |
| 485 |
| 486 virtual void Set(dbus::PropertyBase *property, |
| 487 dbus::PropertySet::SetCallback callback) OVERRIDE { |
| 488 VLOG(1) << "Set " << property->name(); |
| 489 callback.Run(false); |
| 490 } |
| 491 }; |
| 492 |
| 493 BluetoothDeviceClientStubImpl() { |
| 494 dbus::ObjectPath dev0("/fake/hci0/dev0"); |
| 495 |
| 496 Properties* properties = new Properties(base::Bind( |
| 497 &BluetoothDeviceClientStubImpl::OnPropertyChanged, |
| 498 base::Unretained(this), |
| 499 dev0)); |
| 500 properties->address.ReplaceValue("00:11:22:33:44:55"); |
| 501 properties->name.ReplaceValue("Fake Device"); |
| 502 properties->paired.ReplaceValue(true); |
| 503 properties->trusted.ReplaceValue(true); |
| 504 |
| 505 properties_map_[dev0] = properties; |
| 506 } |
| 507 |
| 508 virtual ~BluetoothDeviceClientStubImpl() { |
| 509 // Clean up Properties structures |
| 510 STLDeleteValues(&properties_map_); |
| 511 } |
| 512 |
467 // BluetoothDeviceClient override. | 513 // BluetoothDeviceClient override. |
468 virtual void AddObserver(Observer* observer) OVERRIDE { | 514 virtual void AddObserver(Observer* observer) OVERRIDE { |
| 515 observers_.AddObserver(observer); |
469 } | 516 } |
470 | 517 |
471 // BluetoothDeviceClient override. | 518 // BluetoothDeviceClient override. |
472 virtual void RemoveObserver(Observer* observer) OVERRIDE { | 519 virtual void RemoveObserver(Observer* observer) OVERRIDE { |
| 520 observers_.RemoveObserver(observer); |
473 } | 521 } |
474 | 522 |
475 // BluetoothDeviceClient override. | 523 // BluetoothDeviceClient override. |
476 virtual Properties* GetProperties(const dbus::ObjectPath& object_path) | 524 virtual Properties* GetProperties(const dbus::ObjectPath& object_path) |
477 OVERRIDE { | 525 OVERRIDE { |
478 VLOG(1) << "GetProperties: " << object_path.value(); | 526 VLOG(1) << "GetProperties: " << object_path.value(); |
| 527 PropertiesMap::iterator iter = properties_map_.find(object_path); |
| 528 if (iter != properties_map_.end()) |
| 529 return iter->second; |
479 return NULL; | 530 return NULL; |
480 } | 531 } |
481 | 532 |
482 // BluetoothDeviceClient override. | 533 // BluetoothDeviceClient override. |
483 virtual void DiscoverServices(const dbus::ObjectPath& object_path, | 534 virtual void DiscoverServices(const dbus::ObjectPath& object_path, |
484 const std::string& pattern, | 535 const std::string& pattern, |
485 const ServicesCallback& callback) OVERRIDE { | 536 const ServicesCallback& callback) OVERRIDE { |
486 VLOG(1) << "DiscoverServices: " << object_path.value() << " " << pattern; | 537 VLOG(1) << "DiscoverServices: " << object_path.value() << " " << pattern; |
487 | 538 |
488 ServiceMap services; | 539 ServiceMap services; |
(...skipping 23 matching lines...) Expand all Loading... |
512 } | 563 } |
513 | 564 |
514 // BluetoothDeviceClient override. | 565 // BluetoothDeviceClient override. |
515 virtual void RemoveNode(const dbus::ObjectPath& object_path, | 566 virtual void RemoveNode(const dbus::ObjectPath& object_path, |
516 const dbus::ObjectPath& node_path, | 567 const dbus::ObjectPath& node_path, |
517 const DeviceCallback& callback) OVERRIDE { | 568 const DeviceCallback& callback) OVERRIDE { |
518 VLOG(1) << "RemoveNode: " << object_path.value() | 569 VLOG(1) << "RemoveNode: " << object_path.value() |
519 << " " << node_path.value(); | 570 << " " << node_path.value(); |
520 callback.Run(object_path, false); | 571 callback.Run(object_path, false); |
521 } | 572 } |
| 573 |
| 574 private: |
| 575 void OnPropertyChanged(dbus::ObjectPath object_path, |
| 576 const std::string& property_name) { |
| 577 FOR_EACH_OBSERVER(BluetoothDeviceClient::Observer, observers_, |
| 578 DevicePropertyChanged(object_path, property_name)); |
| 579 } |
| 580 |
| 581 // List of observers interested in event notifications from us. |
| 582 ObserverList<Observer> observers_; |
| 583 |
| 584 // Static properties we typedef. |
| 585 typedef std::map<const dbus::ObjectPath, Properties *> PropertiesMap; |
| 586 PropertiesMap properties_map_; |
522 }; | 587 }; |
523 | 588 |
524 BluetoothDeviceClient::BluetoothDeviceClient() { | 589 BluetoothDeviceClient::BluetoothDeviceClient() { |
525 } | 590 } |
526 | 591 |
527 BluetoothDeviceClient::~BluetoothDeviceClient() { | 592 BluetoothDeviceClient::~BluetoothDeviceClient() { |
528 } | 593 } |
529 | 594 |
530 BluetoothDeviceClient* BluetoothDeviceClient::Create( | 595 BluetoothDeviceClient* BluetoothDeviceClient::Create( |
531 DBusClientImplementationType type, | 596 DBusClientImplementationType type, |
532 dbus::Bus* bus, | 597 dbus::Bus* bus, |
533 BluetoothAdapterClient* adapter_client) { | 598 BluetoothAdapterClient* adapter_client) { |
534 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) | 599 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) |
535 return new BluetoothDeviceClientImpl(bus, adapter_client); | 600 return new BluetoothDeviceClientImpl(bus, adapter_client); |
536 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); | 601 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); |
537 return new BluetoothDeviceClientStubImpl(); | 602 return new BluetoothDeviceClientStubImpl(); |
538 } | 603 } |
539 | 604 |
540 } // namespace chromeos | 605 } // namespace chromeos |
OLD | NEW |