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" |
(...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
457 // List of observers interested in event notifications from us. | 457 // List of observers interested in event notifications from us. |
458 ObserverList<BluetoothDeviceClient::Observer> observers_; | 458 ObserverList<BluetoothDeviceClient::Observer> observers_; |
459 | 459 |
460 DISALLOW_COPY_AND_ASSIGN(BluetoothDeviceClientImpl); | 460 DISALLOW_COPY_AND_ASSIGN(BluetoothDeviceClientImpl); |
461 }; | 461 }; |
462 | 462 |
463 // The BluetoothDeviceClient implementation used on Linux desktop, which does | 463 // The BluetoothDeviceClient implementation used on Linux desktop, which does |
464 // nothing. | 464 // nothing. |
465 class BluetoothDeviceClientStubImpl : public BluetoothDeviceClient { | 465 class BluetoothDeviceClientStubImpl : public BluetoothDeviceClient { |
466 public: | 466 public: |
467 struct Properties : public BluetoothDeviceClient::Properties { | |
468 explicit Properties(PropertyChangedCallback callback) | |
satorux1
2012/08/14 16:54:19
const PropertyChangedCallback&
keybuk
2012/08/14 17:40:32
Done.
| |
469 : BluetoothDeviceClient::Properties(NULL, callback) { | |
470 } | |
471 | |
472 virtual ~Properties() { | |
473 } | |
474 | |
475 virtual void Get(dbus::PropertyBase* property, | |
476 dbus::PropertySet::GetCallback callback) OVERRIDE { | |
477 VLOG(1) << "Get " << property->name(); | |
478 callback.Run(false); | |
479 } | |
480 | |
481 virtual void GetAll() OVERRIDE { | |
482 VLOG(1) << "GetAll"; | |
483 } | |
484 | |
485 virtual void Set(dbus::PropertyBase *property, | |
486 dbus::PropertySet::SetCallback callback) OVERRIDE { | |
487 VLOG(1) << "Set " << property->name(); | |
488 callback.Run(false); | |
489 } | |
490 }; | |
491 | |
492 BluetoothDeviceClientStubImpl() { | |
493 dbus::ObjectPath dev0("/fake/hci0/dev0"); | |
494 | |
495 Properties* properties = new Properties(base::Bind( | |
496 &BluetoothDeviceClientStubImpl::OnPropertyChanged, | |
497 base::Unretained(this), | |
498 dev0)); | |
499 properties->address.ReplaceValue("00:11:22:33:44:55"); | |
500 properties->name.ReplaceValue("Fake Device"); | |
501 properties->paired.ReplaceValue(true); | |
502 properties->trusted.ReplaceValue(true); | |
503 | |
504 properties_map_[dev0] = properties; | |
505 } | |
506 | |
507 virtual ~BluetoothDeviceClientStubImpl() { | |
508 // Clean up Properties structures | |
bryeung
2012/08/14 13:10:30
This could be done with STLDeleteContainerPairSeco
satorux1
2012/08/14 16:54:19
You meant STLDeleteValues?
keybuk
2012/08/14 17:40:32
Done.
| |
509 for (PropertiesMap::iterator iter = properties_map_.begin(); | |
510 iter != properties_map_.end(); ++iter) | |
511 delete iter->second; | |
512 } | |
513 | |
467 // BluetoothDeviceClient override. | 514 // BluetoothDeviceClient override. |
468 virtual void AddObserver(Observer* observer) OVERRIDE { | 515 virtual void AddObserver(Observer* observer) OVERRIDE { |
516 observers_.AddObserver(observer); | |
469 } | 517 } |
470 | 518 |
471 // BluetoothDeviceClient override. | 519 // BluetoothDeviceClient override. |
472 virtual void RemoveObserver(Observer* observer) OVERRIDE { | 520 virtual void RemoveObserver(Observer* observer) OVERRIDE { |
521 observers_.RemoveObserver(observer); | |
473 } | 522 } |
474 | 523 |
475 // BluetoothDeviceClient override. | 524 // BluetoothDeviceClient override. |
476 virtual Properties* GetProperties(const dbus::ObjectPath& object_path) | 525 virtual Properties* GetProperties(const dbus::ObjectPath& object_path) |
477 OVERRIDE { | 526 OVERRIDE { |
478 VLOG(1) << "GetProperties: " << object_path.value(); | 527 VLOG(1) << "GetProperties: " << object_path.value(); |
528 PropertiesMap::iterator iter = properties_map_.find(object_path); | |
529 if (iter != properties_map_.end()) | |
530 return iter->second; | |
479 return NULL; | 531 return NULL; |
480 } | 532 } |
481 | 533 |
482 // BluetoothDeviceClient override. | 534 // BluetoothDeviceClient override. |
483 virtual void DiscoverServices(const dbus::ObjectPath& object_path, | 535 virtual void DiscoverServices(const dbus::ObjectPath& object_path, |
484 const std::string& pattern, | 536 const std::string& pattern, |
485 const ServicesCallback& callback) OVERRIDE { | 537 const ServicesCallback& callback) OVERRIDE { |
486 VLOG(1) << "DiscoverServices: " << object_path.value() << " " << pattern; | 538 VLOG(1) << "DiscoverServices: " << object_path.value() << " " << pattern; |
487 | 539 |
488 ServiceMap services; | 540 ServiceMap services; |
(...skipping 23 matching lines...) Expand all Loading... | |
512 } | 564 } |
513 | 565 |
514 // BluetoothDeviceClient override. | 566 // BluetoothDeviceClient override. |
515 virtual void RemoveNode(const dbus::ObjectPath& object_path, | 567 virtual void RemoveNode(const dbus::ObjectPath& object_path, |
516 const dbus::ObjectPath& node_path, | 568 const dbus::ObjectPath& node_path, |
517 const DeviceCallback& callback) OVERRIDE { | 569 const DeviceCallback& callback) OVERRIDE { |
518 VLOG(1) << "RemoveNode: " << object_path.value() | 570 VLOG(1) << "RemoveNode: " << object_path.value() |
519 << " " << node_path.value(); | 571 << " " << node_path.value(); |
520 callback.Run(object_path, false); | 572 callback.Run(object_path, false); |
521 } | 573 } |
574 | |
575 private: | |
576 // List of observers interested in event notifications from us. | |
satorux1
2012/08/14 16:54:19
move this to |observers_|; below?
keybuk
2012/08/14 17:40:32
Done.
| |
577 void OnPropertyChanged(dbus::ObjectPath object_path, | |
578 const std::string& property_name) { | |
579 FOR_EACH_OBSERVER(BluetoothDeviceClient::Observer, observers_, | |
580 DevicePropertyChanged(object_path, property_name)); | |
581 } | |
582 | |
583 ObserverList<Observer> observers_; | |
584 | |
585 // Static properties we typedef. | |
586 typedef std::map<const dbus::ObjectPath, Properties *> PropertiesMap; | |
587 PropertiesMap properties_map_; | |
522 }; | 588 }; |
523 | 589 |
524 BluetoothDeviceClient::BluetoothDeviceClient() { | 590 BluetoothDeviceClient::BluetoothDeviceClient() { |
525 } | 591 } |
526 | 592 |
527 BluetoothDeviceClient::~BluetoothDeviceClient() { | 593 BluetoothDeviceClient::~BluetoothDeviceClient() { |
528 } | 594 } |
529 | 595 |
530 BluetoothDeviceClient* BluetoothDeviceClient::Create( | 596 BluetoothDeviceClient* BluetoothDeviceClient::Create( |
531 DBusClientImplementationType type, | 597 DBusClientImplementationType type, |
532 dbus::Bus* bus, | 598 dbus::Bus* bus, |
533 BluetoothAdapterClient* adapter_client) { | 599 BluetoothAdapterClient* adapter_client) { |
534 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) | 600 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) |
535 return new BluetoothDeviceClientImpl(bus, adapter_client); | 601 return new BluetoothDeviceClientImpl(bus, adapter_client); |
536 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); | 602 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); |
537 return new BluetoothDeviceClientStubImpl(); | 603 return new BluetoothDeviceClientStubImpl(); |
538 } | 604 } |
539 | 605 |
540 } // namespace chromeos | 606 } // namespace chromeos |
OLD | NEW |