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_adapter_client.h" | 5 #include "chromeos/dbus/bluetooth_adapter_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 "dbus/bus.h" | 9 #include "dbus/bus.h" |
10 #include "dbus/message.h" | 10 #include "dbus/message.h" |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 BluetoothAdapterClientImpl() | 53 BluetoothAdapterClientImpl() |
54 : object_manager_(NULL), weak_ptr_factory_(this) {} | 54 : object_manager_(NULL), weak_ptr_factory_(this) {} |
55 | 55 |
56 virtual ~BluetoothAdapterClientImpl() { | 56 virtual ~BluetoothAdapterClientImpl() { |
57 object_manager_->UnregisterInterface( | 57 object_manager_->UnregisterInterface( |
58 bluetooth_adapter::kBluetoothAdapterInterface); | 58 bluetooth_adapter::kBluetoothAdapterInterface); |
59 } | 59 } |
60 | 60 |
61 // BluetoothAdapterClient override. | 61 // BluetoothAdapterClient override. |
62 virtual void AddObserver(BluetoothAdapterClient::Observer* observer) | 62 virtual void AddObserver(BluetoothAdapterClient::Observer* observer) |
63 OVERRIDE { | 63 override { |
64 DCHECK(observer); | 64 DCHECK(observer); |
65 observers_.AddObserver(observer); | 65 observers_.AddObserver(observer); |
66 } | 66 } |
67 | 67 |
68 // BluetoothAdapterClient override. | 68 // BluetoothAdapterClient override. |
69 virtual void RemoveObserver(BluetoothAdapterClient::Observer* observer) | 69 virtual void RemoveObserver(BluetoothAdapterClient::Observer* observer) |
70 OVERRIDE { | 70 override { |
71 DCHECK(observer); | 71 DCHECK(observer); |
72 observers_.RemoveObserver(observer); | 72 observers_.RemoveObserver(observer); |
73 } | 73 } |
74 | 74 |
75 // Returns the list of adapter object paths known to the system. | 75 // Returns the list of adapter object paths known to the system. |
76 virtual std::vector<dbus::ObjectPath> GetAdapters() OVERRIDE { | 76 virtual std::vector<dbus::ObjectPath> GetAdapters() override { |
77 return object_manager_->GetObjectsWithInterface( | 77 return object_manager_->GetObjectsWithInterface( |
78 bluetooth_adapter::kBluetoothAdapterInterface); | 78 bluetooth_adapter::kBluetoothAdapterInterface); |
79 } | 79 } |
80 | 80 |
81 // dbus::ObjectManager::Interface override. | 81 // dbus::ObjectManager::Interface override. |
82 virtual dbus::PropertySet* CreateProperties( | 82 virtual dbus::PropertySet* CreateProperties( |
83 dbus::ObjectProxy* object_proxy, | 83 dbus::ObjectProxy* object_proxy, |
84 const dbus::ObjectPath& object_path, | 84 const dbus::ObjectPath& object_path, |
85 const std::string& interface_name) OVERRIDE { | 85 const std::string& interface_name) override { |
86 Properties* properties = new Properties( | 86 Properties* properties = new Properties( |
87 object_proxy, | 87 object_proxy, |
88 interface_name, | 88 interface_name, |
89 base::Bind(&BluetoothAdapterClientImpl::OnPropertyChanged, | 89 base::Bind(&BluetoothAdapterClientImpl::OnPropertyChanged, |
90 weak_ptr_factory_.GetWeakPtr(), | 90 weak_ptr_factory_.GetWeakPtr(), |
91 object_path)); | 91 object_path)); |
92 return static_cast<dbus::PropertySet*>(properties); | 92 return static_cast<dbus::PropertySet*>(properties); |
93 } | 93 } |
94 | 94 |
95 // BluetoothAdapterClient override. | 95 // BluetoothAdapterClient override. |
96 virtual Properties* GetProperties(const dbus::ObjectPath& object_path) | 96 virtual Properties* GetProperties(const dbus::ObjectPath& object_path) |
97 OVERRIDE { | 97 override { |
98 return static_cast<Properties*>( | 98 return static_cast<Properties*>( |
99 object_manager_->GetProperties( | 99 object_manager_->GetProperties( |
100 object_path, | 100 object_path, |
101 bluetooth_adapter::kBluetoothAdapterInterface)); | 101 bluetooth_adapter::kBluetoothAdapterInterface)); |
102 } | 102 } |
103 | 103 |
104 // BluetoothAdapterClient override. | 104 // BluetoothAdapterClient override. |
105 virtual void StartDiscovery(const dbus::ObjectPath& object_path, | 105 virtual void StartDiscovery(const dbus::ObjectPath& object_path, |
106 const base::Closure& callback, | 106 const base::Closure& callback, |
107 const ErrorCallback& error_callback) OVERRIDE { | 107 const ErrorCallback& error_callback) override { |
108 dbus::MethodCall method_call( | 108 dbus::MethodCall method_call( |
109 bluetooth_adapter::kBluetoothAdapterInterface, | 109 bluetooth_adapter::kBluetoothAdapterInterface, |
110 bluetooth_adapter::kStartDiscovery); | 110 bluetooth_adapter::kStartDiscovery); |
111 | 111 |
112 dbus::ObjectProxy* object_proxy = | 112 dbus::ObjectProxy* object_proxy = |
113 object_manager_->GetObjectProxy(object_path); | 113 object_manager_->GetObjectProxy(object_path); |
114 if (!object_proxy) { | 114 if (!object_proxy) { |
115 error_callback.Run(kUnknownAdapterError, ""); | 115 error_callback.Run(kUnknownAdapterError, ""); |
116 return; | 116 return; |
117 } | 117 } |
118 | 118 |
119 object_proxy->CallMethodWithErrorCallback( | 119 object_proxy->CallMethodWithErrorCallback( |
120 &method_call, | 120 &method_call, |
121 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 121 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
122 base::Bind(&BluetoothAdapterClientImpl::OnSuccess, | 122 base::Bind(&BluetoothAdapterClientImpl::OnSuccess, |
123 weak_ptr_factory_.GetWeakPtr(), callback), | 123 weak_ptr_factory_.GetWeakPtr(), callback), |
124 base::Bind(&BluetoothAdapterClientImpl::OnError, | 124 base::Bind(&BluetoothAdapterClientImpl::OnError, |
125 weak_ptr_factory_.GetWeakPtr(), error_callback)); | 125 weak_ptr_factory_.GetWeakPtr(), error_callback)); |
126 } | 126 } |
127 | 127 |
128 // BluetoothAdapterClient override. | 128 // BluetoothAdapterClient override. |
129 virtual void StopDiscovery(const dbus::ObjectPath& object_path, | 129 virtual void StopDiscovery(const dbus::ObjectPath& object_path, |
130 const base::Closure& callback, | 130 const base::Closure& callback, |
131 const ErrorCallback& error_callback) OVERRIDE { | 131 const ErrorCallback& error_callback) override { |
132 dbus::MethodCall method_call( | 132 dbus::MethodCall method_call( |
133 bluetooth_adapter::kBluetoothAdapterInterface, | 133 bluetooth_adapter::kBluetoothAdapterInterface, |
134 bluetooth_adapter::kStopDiscovery); | 134 bluetooth_adapter::kStopDiscovery); |
135 | 135 |
136 dbus::ObjectProxy* object_proxy = | 136 dbus::ObjectProxy* object_proxy = |
137 object_manager_->GetObjectProxy(object_path); | 137 object_manager_->GetObjectProxy(object_path); |
138 if (!object_proxy) { | 138 if (!object_proxy) { |
139 error_callback.Run(kUnknownAdapterError, ""); | 139 error_callback.Run(kUnknownAdapterError, ""); |
140 return; | 140 return; |
141 } | 141 } |
142 | 142 |
143 object_proxy->CallMethodWithErrorCallback( | 143 object_proxy->CallMethodWithErrorCallback( |
144 &method_call, | 144 &method_call, |
145 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 145 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
146 base::Bind(&BluetoothAdapterClientImpl::OnSuccess, | 146 base::Bind(&BluetoothAdapterClientImpl::OnSuccess, |
147 weak_ptr_factory_.GetWeakPtr(), callback), | 147 weak_ptr_factory_.GetWeakPtr(), callback), |
148 base::Bind(&BluetoothAdapterClientImpl::OnError, | 148 base::Bind(&BluetoothAdapterClientImpl::OnError, |
149 weak_ptr_factory_.GetWeakPtr(), error_callback)); | 149 weak_ptr_factory_.GetWeakPtr(), error_callback)); |
150 } | 150 } |
151 | 151 |
152 // BluetoothAdapterClient override. | 152 // BluetoothAdapterClient override. |
153 virtual void RemoveDevice(const dbus::ObjectPath& object_path, | 153 virtual void RemoveDevice(const dbus::ObjectPath& object_path, |
154 const dbus::ObjectPath& device_path, | 154 const dbus::ObjectPath& device_path, |
155 const base::Closure& callback, | 155 const base::Closure& callback, |
156 const ErrorCallback& error_callback) OVERRIDE { | 156 const ErrorCallback& error_callback) override { |
157 dbus::MethodCall method_call( | 157 dbus::MethodCall method_call( |
158 bluetooth_adapter::kBluetoothAdapterInterface, | 158 bluetooth_adapter::kBluetoothAdapterInterface, |
159 bluetooth_adapter::kRemoveDevice); | 159 bluetooth_adapter::kRemoveDevice); |
160 | 160 |
161 dbus::MessageWriter writer(&method_call); | 161 dbus::MessageWriter writer(&method_call); |
162 writer.AppendObjectPath(device_path); | 162 writer.AppendObjectPath(device_path); |
163 | 163 |
164 dbus::ObjectProxy* object_proxy = | 164 dbus::ObjectProxy* object_proxy = |
165 object_manager_->GetObjectProxy(object_path); | 165 object_manager_->GetObjectProxy(object_path); |
166 if (!object_proxy) { | 166 if (!object_proxy) { |
167 error_callback.Run(kUnknownAdapterError, ""); | 167 error_callback.Run(kUnknownAdapterError, ""); |
168 return; | 168 return; |
169 } | 169 } |
170 | 170 |
171 object_proxy->CallMethodWithErrorCallback( | 171 object_proxy->CallMethodWithErrorCallback( |
172 &method_call, | 172 &method_call, |
173 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 173 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
174 base::Bind(&BluetoothAdapterClientImpl::OnSuccess, | 174 base::Bind(&BluetoothAdapterClientImpl::OnSuccess, |
175 weak_ptr_factory_.GetWeakPtr(), callback), | 175 weak_ptr_factory_.GetWeakPtr(), callback), |
176 base::Bind(&BluetoothAdapterClientImpl::OnError, | 176 base::Bind(&BluetoothAdapterClientImpl::OnError, |
177 weak_ptr_factory_.GetWeakPtr(), error_callback)); | 177 weak_ptr_factory_.GetWeakPtr(), error_callback)); |
178 } | 178 } |
179 | 179 |
180 protected: | 180 protected: |
181 virtual void Init(dbus::Bus* bus) OVERRIDE { | 181 virtual void Init(dbus::Bus* bus) override { |
182 object_manager_ = bus->GetObjectManager( | 182 object_manager_ = bus->GetObjectManager( |
183 bluetooth_object_manager::kBluetoothObjectManagerServiceName, | 183 bluetooth_object_manager::kBluetoothObjectManagerServiceName, |
184 dbus::ObjectPath( | 184 dbus::ObjectPath( |
185 bluetooth_object_manager::kBluetoothObjectManagerServicePath)); | 185 bluetooth_object_manager::kBluetoothObjectManagerServicePath)); |
186 object_manager_->RegisterInterface( | 186 object_manager_->RegisterInterface( |
187 bluetooth_adapter::kBluetoothAdapterInterface, this); | 187 bluetooth_adapter::kBluetoothAdapterInterface, this); |
188 } | 188 } |
189 | 189 |
190 private: | 190 private: |
191 // Called by dbus::ObjectManager when an object with the adapter interface | 191 // Called by dbus::ObjectManager when an object with the adapter interface |
192 // is created. Informs observers. | 192 // is created. Informs observers. |
193 virtual void ObjectAdded(const dbus::ObjectPath& object_path, | 193 virtual void ObjectAdded(const dbus::ObjectPath& object_path, |
194 const std::string& interface_name) OVERRIDE { | 194 const std::string& interface_name) override { |
195 FOR_EACH_OBSERVER(BluetoothAdapterClient::Observer, observers_, | 195 FOR_EACH_OBSERVER(BluetoothAdapterClient::Observer, observers_, |
196 AdapterAdded(object_path)); | 196 AdapterAdded(object_path)); |
197 } | 197 } |
198 | 198 |
199 // Called by dbus::ObjectManager when an object with the adapter interface | 199 // Called by dbus::ObjectManager when an object with the adapter interface |
200 // is removed. Informs observers. | 200 // is removed. Informs observers. |
201 virtual void ObjectRemoved(const dbus::ObjectPath& object_path, | 201 virtual void ObjectRemoved(const dbus::ObjectPath& object_path, |
202 const std::string& interface_name) OVERRIDE { | 202 const std::string& interface_name) override { |
203 FOR_EACH_OBSERVER(BluetoothAdapterClient::Observer, observers_, | 203 FOR_EACH_OBSERVER(BluetoothAdapterClient::Observer, observers_, |
204 AdapterRemoved(object_path)); | 204 AdapterRemoved(object_path)); |
205 } | 205 } |
206 | 206 |
207 // Called by dbus::PropertySet when a property value is changed, | 207 // Called by dbus::PropertySet when a property value is changed, |
208 // either by result of a signal or response to a GetAll() or Get() | 208 // either by result of a signal or response to a GetAll() or Get() |
209 // call. Informs observers. | 209 // call. Informs observers. |
210 void OnPropertyChanged(const dbus::ObjectPath& object_path, | 210 void OnPropertyChanged(const dbus::ObjectPath& object_path, |
211 const std::string& property_name) { | 211 const std::string& property_name) { |
212 FOR_EACH_OBSERVER(BluetoothAdapterClient::Observer, observers_, | 212 FOR_EACH_OBSERVER(BluetoothAdapterClient::Observer, observers_, |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
256 } | 256 } |
257 | 257 |
258 BluetoothAdapterClient::~BluetoothAdapterClient() { | 258 BluetoothAdapterClient::~BluetoothAdapterClient() { |
259 } | 259 } |
260 | 260 |
261 BluetoothAdapterClient* BluetoothAdapterClient::Create() { | 261 BluetoothAdapterClient* BluetoothAdapterClient::Create() { |
262 return new BluetoothAdapterClientImpl; | 262 return new BluetoothAdapterClientImpl; |
263 } | 263 } |
264 | 264 |
265 } // namespace chromeos | 265 } // namespace chromeos |
OLD | NEW |