OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/browser/chromeos/dbus/bluetooth_adapter_client.h" | 5 #include "chrome/browser/chromeos/dbus/bluetooth_adapter_client.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
255 VLOG(1) << "AddObjectProxyForPath: " << object_path; | 255 VLOG(1) << "AddObjectProxyForPath: " << object_path; |
256 | 256 |
257 DCHECK(bus_); | 257 DCHECK(bus_); |
258 dbus::ObjectProxy* adapter_proxy = bus_->GetObjectProxy( | 258 dbus::ObjectProxy* adapter_proxy = bus_->GetObjectProxy( |
259 bluetooth_adapter::kBluetoothAdapterServiceName, object_path); | 259 bluetooth_adapter::kBluetoothAdapterServiceName, object_path); |
260 | 260 |
261 proxy_map_[object_path] = adapter_proxy; | 261 proxy_map_[object_path] = adapter_proxy; |
262 | 262 |
263 adapter_proxy->ConnectToSignal( | 263 adapter_proxy->ConnectToSignal( |
264 bluetooth_adapter::kBluetoothAdapterInterface, | 264 bluetooth_adapter::kBluetoothAdapterInterface, |
265 bluetooth_adapter::kDeviceCreatedSignal, | |
266 base::Bind(&BluetoothAdapterClientImpl::DeviceCreatedReceived, | |
267 weak_ptr_factory_.GetWeakPtr(), object_path), | |
268 base::Bind(&BluetoothAdapterClientImpl::DeviceCreatedConnected, | |
269 weak_ptr_factory_.GetWeakPtr(), object_path)); | |
270 | |
271 adapter_proxy->ConnectToSignal( | |
272 bluetooth_adapter::kBluetoothAdapterInterface, | |
273 bluetooth_adapter::kDeviceRemovedSignal, | |
274 base::Bind(&BluetoothAdapterClientImpl::DeviceRemovedReceived, | |
275 weak_ptr_factory_.GetWeakPtr(), object_path), | |
276 base::Bind(&BluetoothAdapterClientImpl::DeviceRemovedConnected, | |
277 weak_ptr_factory_.GetWeakPtr(), object_path)); | |
278 | |
279 adapter_proxy->ConnectToSignal( | |
280 bluetooth_adapter::kBluetoothAdapterInterface, | |
265 bluetooth_adapter::kPropertyChangedSignal, | 281 bluetooth_adapter::kPropertyChangedSignal, |
266 base::Bind(&BluetoothAdapterClientImpl::PropertyChangedReceived, | 282 base::Bind(&BluetoothAdapterClientImpl::PropertyChangedReceived, |
267 weak_ptr_factory_.GetWeakPtr(), object_path), | 283 weak_ptr_factory_.GetWeakPtr(), object_path), |
268 base::Bind(&BluetoothAdapterClientImpl::PropertyChangedConnected, | 284 base::Bind(&BluetoothAdapterClientImpl::PropertyChangedConnected, |
269 weak_ptr_factory_.GetWeakPtr(), object_path)); | 285 weak_ptr_factory_.GetWeakPtr(), object_path)); |
270 | 286 |
271 adapter_proxy->ConnectToSignal( | 287 adapter_proxy->ConnectToSignal( |
272 bluetooth_adapter::kBluetoothAdapterInterface, | 288 bluetooth_adapter::kBluetoothAdapterInterface, |
273 bluetooth_adapter::kDeviceFoundSignal, | 289 bluetooth_adapter::kDeviceFoundSignal, |
274 base::Bind(&BluetoothAdapterClientImpl::DeviceFoundReceived, | 290 base::Bind(&BluetoothAdapterClientImpl::DeviceFoundReceived, |
(...skipping 10 matching lines...) Expand all Loading... | |
285 weak_ptr_factory_.GetWeakPtr(), object_path)); | 301 weak_ptr_factory_.GetWeakPtr(), object_path)); |
286 } | 302 } |
287 | 303 |
288 // Removes the dbus object proxy for the adapter with dbus object path | 304 // Removes the dbus object proxy for the adapter with dbus object path |
289 // |object_path| from our |proxy_map_| map. | 305 // |object_path| from our |proxy_map_| map. |
290 void RemoveObjectProxyForPath(const std::string& object_path) { | 306 void RemoveObjectProxyForPath(const std::string& object_path) { |
291 VLOG(1) << "RemoveObjectProxyForPath: " << object_path; | 307 VLOG(1) << "RemoveObjectProxyForPath: " << object_path; |
292 proxy_map_.erase(object_path); | 308 proxy_map_.erase(object_path); |
293 } | 309 } |
294 | 310 |
311 // Called by dbus:: when a DeviceCreated signal is received. | |
mukesh agrawal
2012/02/01 00:48:42
why "dbus::" (trailing colons)?
(same for other fu
keybuk
2012/02/04 00:35:47
referring to "code in the dbus namespace", ie the
| |
312 void DeviceCreatedReceived(const std::string& object_path, | |
mukesh agrawal
2012/02/01 00:48:42
you might consider "using std::string" and shorten
satorux1
2012/02/01 17:45:18
Please don't do this in Chrome's code for consiste
| |
313 dbus::Signal* signal) { | |
314 DCHECK(signal); | |
315 dbus::MessageReader reader(signal); | |
316 std::string device_path; | |
317 if (!reader.PopString(&device_path)) { | |
318 LOG(ERROR) << object_path | |
319 << ": DeviceCreated signal has incorrect parameters: " | |
320 << signal->ToString(); | |
321 return; | |
322 } | |
323 VLOG(1) << object_path << ": Device created: " << device_path; | |
324 | |
325 FOR_EACH_OBSERVER(BluetoothAdapterClient::Observer, observers_, | |
326 DeviceCreated(object_path, device_path)); | |
mukesh agrawal
2012/02/01 00:48:42
are the arguments in the correct order? prototype
keybuk
2012/02/04 00:35:47
yes, the "object_path" here refers to the adapter
| |
327 } | |
328 | |
329 // Called by dbus:: when the DeviceCreated signal is initially connected. | |
330 void DeviceCreatedConnected(const std::string& object_path, | |
331 const std::string& interface_name, | |
mukesh agrawal
2012/02/01 00:48:42
google style comments out unused parameters. |inte
keybuk
2012/02/04 00:35:47
Chrome style seems to not do that afaict?
| |
332 const std::string& signal_name, | |
333 bool success) { | |
334 LOG_IF(WARNING, !success) << object_path | |
335 << ": Failed to connect to DeviceCreated signal."; | |
336 } | |
337 | |
338 // Called by dbus:: when a DeviceRemoved signal is received. | |
339 void DeviceRemovedReceived(const std::string& object_path, | |
340 dbus::Signal* signal) { | |
341 DCHECK(signal); | |
342 dbus::MessageReader reader(signal); | |
343 std::string device_path; | |
344 if (!reader.PopString(&device_path)) { | |
345 LOG(ERROR) << object_path | |
346 << ": DeviceRemoved signal has incorrect parameters: " | |
347 << signal->ToString(); | |
348 return; | |
349 } | |
350 VLOG(1) << object_path << ": Device created: " << device_path; | |
351 | |
352 FOR_EACH_OBSERVER(BluetoothAdapterClient::Observer, observers_, | |
353 DeviceRemoved(object_path, device_path)); | |
mukesh agrawal
2012/02/01 00:48:42
as in DeviceAddedReceived: check callback paramete
| |
354 } | |
355 | |
356 // Called by dbus:: when the DeviceRemoved signal is initially connected. | |
357 void DeviceRemovedConnected(const std::string& object_path, | |
358 const std::string& interface_name, | |
mukesh agrawal
2012/02/01 00:48:42
as above (comment out unused parameters).
| |
359 const std::string& signal_name, | |
360 bool success) { | |
361 LOG_IF(WARNING, !success) << object_path | |
362 << ": Failed to connect to DeviceRemoved signal."; | |
363 } | |
364 | |
295 // Called by dbus:: when a PropertyChanged signal is received. | 365 // Called by dbus:: when a PropertyChanged signal is received. |
296 void PropertyChangedReceived(const std::string& object_path, | 366 void PropertyChangedReceived(const std::string& object_path, |
297 dbus::Signal* signal) { | 367 dbus::Signal* signal) { |
298 DCHECK(signal); | 368 DCHECK(signal); |
299 dbus::MessageReader reader(signal); | 369 dbus::MessageReader reader(signal); |
300 std::string property_name; | 370 std::string property_name; |
301 if (!reader.PopString(&property_name)) { | 371 if (!reader.PopString(&property_name)) { |
302 LOG(ERROR) << object_path | 372 LOG(ERROR) << object_path |
303 << ": PropertyChanged signal has incorrect parameters: " | 373 << ": PropertyChanged signal has incorrect parameters: " |
304 << signal->ToString(); | 374 << signal->ToString(); |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
459 | 529 |
460 BluetoothAdapterClient* BluetoothAdapterClient::Create(dbus::Bus* bus) { | 530 BluetoothAdapterClient* BluetoothAdapterClient::Create(dbus::Bus* bus) { |
461 if (system::runtime_environment::IsRunningOnChromeOS()) { | 531 if (system::runtime_environment::IsRunningOnChromeOS()) { |
462 return new BluetoothAdapterClientImpl(bus); | 532 return new BluetoothAdapterClientImpl(bus); |
463 } else { | 533 } else { |
464 return new BluetoothAdapterClientStubImpl(); | 534 return new BluetoothAdapterClientStubImpl(); |
465 } | 535 } |
466 } | 536 } |
467 | 537 |
468 } // namespace chromeos | 538 } // namespace chromeos |
OLD | NEW |