| 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_adapter_client.h" | 5 #include "chromeos/dbus/bluetooth_adapter_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/memory/scoped_ptr.h" |
| 12 #include "base/stl_util.h" | 13 #include "base/stl_util.h" |
| 13 #include "chromeos/dbus/bluetooth_device_client.h" | 14 #include "chromeos/dbus/bluetooth_device_client.h" |
| 14 #include "chromeos/dbus/bluetooth_manager_client.h" | 15 #include "chromeos/dbus/bluetooth_manager_client.h" |
| 15 #include "chromeos/dbus/bluetooth_property.h" | 16 #include "chromeos/dbus/bluetooth_property.h" |
| 16 #include "dbus/bus.h" | 17 #include "dbus/bus.h" |
| 17 #include "dbus/message.h" | 18 #include "dbus/message.h" |
| 18 #include "dbus/object_path.h" | 19 #include "dbus/object_path.h" |
| 19 #include "dbus/object_proxy.h" | 20 #include "dbus/object_proxy.h" |
| 20 #include "third_party/cros_system_api/dbus/service_constants.h" | 21 #include "third_party/cros_system_api/dbus/service_constants.h" |
| 21 | 22 |
| 22 namespace chromeos { | 23 namespace chromeos { |
| 23 | 24 |
| 24 const char BluetoothAdapterClient::kNoResponseError[] = | 25 const char BluetoothAdapterClient::kNoResponseError[] = |
| 25 "org.chromium.Error.NoResponse"; | 26 "org.chromium.Error.NoResponse"; |
| 26 const char BluetoothAdapterClient::kBadResponseError[] = | 27 const char BluetoothAdapterClient::kBadResponseError[] = |
| 27 "org.chromium.Error.BadResponse"; | 28 "org.chromium.Error.BadResponse"; |
| 28 | 29 |
| 29 BluetoothAdapterClient::Properties::Properties(dbus::ObjectProxy* object_proxy, | 30 BluetoothAdapterClient::Properties::Properties( |
| 30 PropertyChangedCallback callback) | 31 dbus::ObjectProxy* object_proxy, |
| 32 const PropertyChangedCallback& callback) |
| 31 : BluetoothPropertySet(object_proxy, | 33 : BluetoothPropertySet(object_proxy, |
| 32 bluetooth_adapter::kBluetoothAdapterInterface, | 34 bluetooth_adapter::kBluetoothAdapterInterface, |
| 33 callback) { | 35 callback) { |
| 34 RegisterProperty(bluetooth_adapter::kAddressProperty, &address); | 36 RegisterProperty(bluetooth_adapter::kAddressProperty, &address); |
| 35 RegisterProperty(bluetooth_adapter::kNameProperty, &name); | 37 RegisterProperty(bluetooth_adapter::kNameProperty, &name); |
| 36 RegisterProperty(bluetooth_adapter::kClassProperty, &bluetooth_class); | 38 RegisterProperty(bluetooth_adapter::kClassProperty, &bluetooth_class); |
| 37 RegisterProperty(bluetooth_adapter::kPoweredProperty, &powered); | 39 RegisterProperty(bluetooth_adapter::kPoweredProperty, &powered); |
| 38 RegisterProperty(bluetooth_adapter::kDiscoverableProperty, &discoverable); | 40 RegisterProperty(bluetooth_adapter::kDiscoverableProperty, &discoverable); |
| 39 RegisterProperty(bluetooth_adapter::kPairableProperty, &pairable); | 41 RegisterProperty(bluetooth_adapter::kPairableProperty, &pairable); |
| 40 RegisterProperty(bluetooth_adapter::kPairableTimeoutProperty, | 42 RegisterProperty(bluetooth_adapter::kPairableTimeoutProperty, |
| (...skipping 681 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 722 // List of observers interested in event notifications from us. | 724 // List of observers interested in event notifications from us. |
| 723 ObserverList<BluetoothAdapterClient::Observer> observers_; | 725 ObserverList<BluetoothAdapterClient::Observer> observers_; |
| 724 | 726 |
| 725 DISALLOW_COPY_AND_ASSIGN(BluetoothAdapterClientImpl); | 727 DISALLOW_COPY_AND_ASSIGN(BluetoothAdapterClientImpl); |
| 726 }; | 728 }; |
| 727 | 729 |
| 728 // The BluetoothAdapterClient implementation used on Linux desktop, which does | 730 // The BluetoothAdapterClient implementation used on Linux desktop, which does |
| 729 // nothing. | 731 // nothing. |
| 730 class BluetoothAdapterClientStubImpl : public BluetoothAdapterClient { | 732 class BluetoothAdapterClientStubImpl : public BluetoothAdapterClient { |
| 731 public: | 733 public: |
| 734 struct Properties : public BluetoothAdapterClient::Properties { |
| 735 explicit Properties(const PropertyChangedCallback& callback) |
| 736 : BluetoothAdapterClient::Properties(NULL, callback) { |
| 737 } |
| 738 |
| 739 virtual ~Properties() { |
| 740 } |
| 741 |
| 742 virtual void Get(dbus::PropertyBase* property, |
| 743 dbus::PropertySet::GetCallback callback) OVERRIDE { |
| 744 VLOG(1) << "Get " << property->name(); |
| 745 callback.Run(false); |
| 746 } |
| 747 |
| 748 virtual void GetAll() OVERRIDE { |
| 749 VLOG(1) << "GetAll"; |
| 750 } |
| 751 |
| 752 virtual void Set(dbus::PropertyBase *property, |
| 753 dbus::PropertySet::SetCallback callback) OVERRIDE { |
| 754 VLOG(1) << "Set " << property->name(); |
| 755 if (property->name() == "Powered") { |
| 756 property->ReplaceValueWithSetValue(); |
| 757 NotifyPropertyChanged(property->name()); |
| 758 callback.Run(true); |
| 759 } else { |
| 760 callback.Run(false); |
| 761 } |
| 762 } |
| 763 }; |
| 764 |
| 765 BluetoothAdapterClientStubImpl() { |
| 766 properties_.reset(new Properties(base::Bind( |
| 767 &BluetoothAdapterClientStubImpl::OnPropertyChanged, |
| 768 base::Unretained(this)))); |
| 769 |
| 770 properties_->address.ReplaceValue("hci0"); |
| 771 properties_->name.ReplaceValue("Fake Adapter"); |
| 772 properties_->pairable.ReplaceValue(true); |
| 773 |
| 774 std::vector<dbus::ObjectPath> devices; |
| 775 devices.push_back(dbus::ObjectPath("/fake/hci0/dev0")); |
| 776 properties_->devices.ReplaceValue(devices); |
| 777 } |
| 778 |
| 732 // BluetoothAdapterClient override. | 779 // BluetoothAdapterClient override. |
| 733 virtual void AddObserver(Observer* observer) OVERRIDE { | 780 virtual void AddObserver(Observer* observer) OVERRIDE { |
| 781 observers_.AddObserver(observer); |
| 734 } | 782 } |
| 735 | 783 |
| 736 // BluetoothAdapterClient override. | 784 // BluetoothAdapterClient override. |
| 737 virtual void RemoveObserver(Observer* observer) OVERRIDE { | 785 virtual void RemoveObserver(Observer* observer) OVERRIDE { |
| 786 observers_.RemoveObserver(observer); |
| 738 } | 787 } |
| 739 | 788 |
| 740 // BluetoothAdapterClient override. | 789 // BluetoothAdapterClient override. |
| 741 virtual Properties* GetProperties(const dbus::ObjectPath& object_path) | 790 virtual Properties* GetProperties(const dbus::ObjectPath& object_path) |
| 742 OVERRIDE { | 791 OVERRIDE { |
| 743 VLOG(1) << "GetProperties: " << object_path.value(); | 792 VLOG(1) << "GetProperties: " << object_path.value(); |
| 744 return NULL; | 793 if (object_path.value() == "/fake/hci0") |
| 794 return properties_.get(); |
| 795 else |
| 796 return NULL; |
| 745 } | 797 } |
| 746 | 798 |
| 747 // BluetoothAdapterClient override. | 799 // BluetoothAdapterClient override. |
| 748 virtual void RequestSession(const dbus::ObjectPath& object_path, | 800 virtual void RequestSession(const dbus::ObjectPath& object_path, |
| 749 const AdapterCallback& callback) OVERRIDE { | 801 const AdapterCallback& callback) OVERRIDE { |
| 750 VLOG(1) << "RequestSession: " << object_path.value(); | 802 VLOG(1) << "RequestSession: " << object_path.value(); |
| 751 callback.Run(object_path, false); | 803 callback.Run(object_path, false); |
| 752 } | 804 } |
| 753 | 805 |
| 754 // BluetoothAdapterClient override. | 806 // BluetoothAdapterClient override. |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 830 } | 882 } |
| 831 | 883 |
| 832 // BluetoothAdapterClient override. | 884 // BluetoothAdapterClient override. |
| 833 virtual void UnregisterAgent(const dbus::ObjectPath& object_path, | 885 virtual void UnregisterAgent(const dbus::ObjectPath& object_path, |
| 834 const dbus::ObjectPath& agent_path, | 886 const dbus::ObjectPath& agent_path, |
| 835 const AdapterCallback& callback) OVERRIDE { | 887 const AdapterCallback& callback) OVERRIDE { |
| 836 VLOG(1) << "UnregisterAgent: " << object_path.value() | 888 VLOG(1) << "UnregisterAgent: " << object_path.value() |
| 837 << " " << agent_path.value(); | 889 << " " << agent_path.value(); |
| 838 callback.Run(object_path, false); | 890 callback.Run(object_path, false); |
| 839 } | 891 } |
| 892 |
| 893 private: |
| 894 void OnPropertyChanged(const std::string& property_name) { |
| 895 FOR_EACH_OBSERVER(BluetoothAdapterClient::Observer, observers_, |
| 896 AdapterPropertyChanged(dbus::ObjectPath("/fake/hci0"), |
| 897 property_name)); |
| 898 } |
| 899 |
| 900 // List of observers interested in event notifications from us. |
| 901 ObserverList<Observer> observers_; |
| 902 |
| 903 // Static properties we return. |
| 904 scoped_ptr<Properties> properties_; |
| 840 }; | 905 }; |
| 841 | 906 |
| 842 BluetoothAdapterClient::BluetoothAdapterClient() { | 907 BluetoothAdapterClient::BluetoothAdapterClient() { |
| 843 } | 908 } |
| 844 | 909 |
| 845 BluetoothAdapterClient::~BluetoothAdapterClient() { | 910 BluetoothAdapterClient::~BluetoothAdapterClient() { |
| 846 } | 911 } |
| 847 | 912 |
| 848 BluetoothAdapterClient* BluetoothAdapterClient::Create( | 913 BluetoothAdapterClient* BluetoothAdapterClient::Create( |
| 849 DBusClientImplementationType type, | 914 DBusClientImplementationType type, |
| 850 dbus::Bus* bus, | 915 dbus::Bus* bus, |
| 851 BluetoothManagerClient* manager_client) { | 916 BluetoothManagerClient* manager_client) { |
| 852 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) | 917 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) |
| 853 return new BluetoothAdapterClientImpl(bus, manager_client); | 918 return new BluetoothAdapterClientImpl(bus, manager_client); |
| 854 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); | 919 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); |
| 855 return new BluetoothAdapterClientStubImpl(); | 920 return new BluetoothAdapterClientStubImpl(); |
| 856 } | 921 } |
| 857 | 922 |
| 858 } // namespace chromeos | 923 } // namespace chromeos |
| OLD | NEW |