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 |
(...skipping 700 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
722 // List of observers interested in event notifications from us. | 723 // List of observers interested in event notifications from us. |
723 ObserverList<BluetoothAdapterClient::Observer> observers_; | 724 ObserverList<BluetoothAdapterClient::Observer> observers_; |
724 | 725 |
725 DISALLOW_COPY_AND_ASSIGN(BluetoothAdapterClientImpl); | 726 DISALLOW_COPY_AND_ASSIGN(BluetoothAdapterClientImpl); |
726 }; | 727 }; |
727 | 728 |
728 // The BluetoothAdapterClient implementation used on Linux desktop, which does | 729 // The BluetoothAdapterClient implementation used on Linux desktop, which does |
729 // nothing. | 730 // nothing. |
730 class BluetoothAdapterClientStubImpl : public BluetoothAdapterClient { | 731 class BluetoothAdapterClientStubImpl : public BluetoothAdapterClient { |
731 public: | 732 public: |
733 struct Properties : public BluetoothAdapterClient::Properties { | |
734 explicit Properties(PropertyChangedCallback callback) | |
satorux1
2012/08/14 16:54:19
you can make it const PropertyChangedCallback&
keybuk
2012/08/14 17:40:32
Done.
| |
735 : BluetoothAdapterClient::Properties(NULL, callback) { | |
736 } | |
737 | |
738 virtual ~Properties() { | |
739 } | |
740 | |
741 virtual void Get(dbus::PropertyBase* property, | |
742 dbus::PropertySet::GetCallback callback) OVERRIDE { | |
743 VLOG(1) << "Get " << property->name(); | |
bryeung
2012/08/14 13:10:29
Probably better as DVLOG?
satorux1
2012/08/14 16:54:19
agreed
keybuk
2012/08/14 17:40:32
we've argued about this before - these are used on
satorux1
2012/08/14 17:52:04
IIRC, the reason why DVLOG(1) is preferred was tha
keybuk
2012/08/14 17:58:46
UI designers don't build anything
| |
744 callback.Run(false); | |
745 } | |
746 | |
747 virtual void GetAll() OVERRIDE { | |
748 VLOG(1) << "GetAll"; | |
satorux1
2012/08/14 16:54:19
ditto. please fix other places too.
| |
749 } | |
750 | |
751 virtual void Set(dbus::PropertyBase *property, | |
752 dbus::PropertySet::SetCallback callback) OVERRIDE { | |
753 VLOG(1) << "Set " << property->name(); | |
754 if (property->name() == "Powered") { | |
755 property->ReplaceValueWithSetValue(); | |
756 NotifyPropertyChanged(property->name()); | |
757 callback.Run(true); | |
758 } else { | |
759 callback.Run(false); | |
760 } | |
761 } | |
762 }; | |
763 | |
764 BluetoothAdapterClientStubImpl() { | |
765 properties_.reset(new Properties(base::Bind( | |
766 &BluetoothAdapterClientStubImpl::OnPropertyChanged, | |
767 base::Unretained(this)))); | |
768 | |
769 properties_->address.ReplaceValue("hci0"); | |
770 properties_->name.ReplaceValue("Fake Adapter"); | |
771 properties_->pairable.ReplaceValue(true); | |
772 | |
773 std::vector<dbus::ObjectPath> devices; | |
774 devices.push_back(dbus::ObjectPath("/fake/hci0/dev0")); | |
775 properties_->devices.ReplaceValue(devices); | |
776 } | |
777 | |
732 // BluetoothAdapterClient override. | 778 // BluetoothAdapterClient override. |
733 virtual void AddObserver(Observer* observer) OVERRIDE { | 779 virtual void AddObserver(Observer* observer) OVERRIDE { |
780 observers_.AddObserver(observer); | |
734 } | 781 } |
735 | 782 |
736 // BluetoothAdapterClient override. | 783 // BluetoothAdapterClient override. |
737 virtual void RemoveObserver(Observer* observer) OVERRIDE { | 784 virtual void RemoveObserver(Observer* observer) OVERRIDE { |
785 observers_.RemoveObserver(observer); | |
738 } | 786 } |
739 | 787 |
740 // BluetoothAdapterClient override. | 788 // BluetoothAdapterClient override. |
741 virtual Properties* GetProperties(const dbus::ObjectPath& object_path) | 789 virtual Properties* GetProperties(const dbus::ObjectPath& object_path) |
742 OVERRIDE { | 790 OVERRIDE { |
743 VLOG(1) << "GetProperties: " << object_path.value(); | 791 VLOG(1) << "GetProperties: " << object_path.value(); |
744 return NULL; | 792 if (object_path.value() == "/fake/hci0") |
793 return properties_.get(); | |
794 else | |
795 return NULL; | |
745 } | 796 } |
746 | 797 |
747 // BluetoothAdapterClient override. | 798 // BluetoothAdapterClient override. |
748 virtual void RequestSession(const dbus::ObjectPath& object_path, | 799 virtual void RequestSession(const dbus::ObjectPath& object_path, |
749 const AdapterCallback& callback) OVERRIDE { | 800 const AdapterCallback& callback) OVERRIDE { |
750 VLOG(1) << "RequestSession: " << object_path.value(); | 801 VLOG(1) << "RequestSession: " << object_path.value(); |
751 callback.Run(object_path, false); | 802 callback.Run(object_path, false); |
752 } | 803 } |
753 | 804 |
754 // BluetoothAdapterClient override. | 805 // BluetoothAdapterClient override. |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
830 } | 881 } |
831 | 882 |
832 // BluetoothAdapterClient override. | 883 // BluetoothAdapterClient override. |
833 virtual void UnregisterAgent(const dbus::ObjectPath& object_path, | 884 virtual void UnregisterAgent(const dbus::ObjectPath& object_path, |
834 const dbus::ObjectPath& agent_path, | 885 const dbus::ObjectPath& agent_path, |
835 const AdapterCallback& callback) OVERRIDE { | 886 const AdapterCallback& callback) OVERRIDE { |
836 VLOG(1) << "UnregisterAgent: " << object_path.value() | 887 VLOG(1) << "UnregisterAgent: " << object_path.value() |
837 << " " << agent_path.value(); | 888 << " " << agent_path.value(); |
838 callback.Run(object_path, false); | 889 callback.Run(object_path, false); |
839 } | 890 } |
891 | |
892 private: | |
893 // List of observers interested in event notifications from us. | |
bryeung
2012/08/14 13:10:29
looks like this belongs with the variable below
keybuk
2012/08/14 17:40:32
Done.
| |
894 void OnPropertyChanged(const std::string& property_name) { | |
895 FOR_EACH_OBSERVER(BluetoothAdapterClient::Observer, observers_, | |
896 AdapterPropertyChanged(dbus::ObjectPath("/fake/hci0"), | |
satorux1
2012/08/14 16:54:19
I saw this before. you might want to define consta
keybuk
2012/08/14 17:40:32
I couldn't find a useful place to put them, since
satorux1
2012/08/14 17:52:04
You could add a new file like bluetooth_stub_const
| |
897 property_name)); | |
898 } | |
899 | |
900 ObserverList<Observer> observers_; | |
901 | |
902 // Static properties we return. | |
903 scoped_ptr<Properties> properties_; | |
840 }; | 904 }; |
841 | 905 |
842 BluetoothAdapterClient::BluetoothAdapterClient() { | 906 BluetoothAdapterClient::BluetoothAdapterClient() { |
843 } | 907 } |
844 | 908 |
845 BluetoothAdapterClient::~BluetoothAdapterClient() { | 909 BluetoothAdapterClient::~BluetoothAdapterClient() { |
846 } | 910 } |
847 | 911 |
848 BluetoothAdapterClient* BluetoothAdapterClient::Create( | 912 BluetoothAdapterClient* BluetoothAdapterClient::Create( |
849 DBusClientImplementationType type, | 913 DBusClientImplementationType type, |
850 dbus::Bus* bus, | 914 dbus::Bus* bus, |
851 BluetoothManagerClient* manager_client) { | 915 BluetoothManagerClient* manager_client) { |
852 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) | 916 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) |
853 return new BluetoothAdapterClientImpl(bus, manager_client); | 917 return new BluetoothAdapterClientImpl(bus, manager_client); |
854 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); | 918 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); |
855 return new BluetoothAdapterClientStubImpl(); | 919 return new BluetoothAdapterClientStubImpl(); |
856 } | 920 } |
857 | 921 |
858 } // namespace chromeos | 922 } // namespace chromeos |
OLD | NEW |