| 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_input_client.h" | 5 #include "chromeos/dbus/bluetooth_input_client.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 public: | 36 public: |
| 37 BluetoothInputClientImpl() : object_manager_(NULL), weak_ptr_factory_(this) {} | 37 BluetoothInputClientImpl() : object_manager_(NULL), weak_ptr_factory_(this) {} |
| 38 | 38 |
| 39 virtual ~BluetoothInputClientImpl() { | 39 virtual ~BluetoothInputClientImpl() { |
| 40 object_manager_->UnregisterInterface( | 40 object_manager_->UnregisterInterface( |
| 41 bluetooth_input::kBluetoothInputInterface); | 41 bluetooth_input::kBluetoothInputInterface); |
| 42 } | 42 } |
| 43 | 43 |
| 44 // BluetoothInputClient override. | 44 // BluetoothInputClient override. |
| 45 virtual void AddObserver(BluetoothInputClient::Observer* observer) | 45 virtual void AddObserver(BluetoothInputClient::Observer* observer) |
| 46 OVERRIDE { | 46 override { |
| 47 DCHECK(observer); | 47 DCHECK(observer); |
| 48 observers_.AddObserver(observer); | 48 observers_.AddObserver(observer); |
| 49 } | 49 } |
| 50 | 50 |
| 51 // BluetoothInputClient override. | 51 // BluetoothInputClient override. |
| 52 virtual void RemoveObserver(BluetoothInputClient::Observer* observer) | 52 virtual void RemoveObserver(BluetoothInputClient::Observer* observer) |
| 53 OVERRIDE { | 53 override { |
| 54 DCHECK(observer); | 54 DCHECK(observer); |
| 55 observers_.RemoveObserver(observer); | 55 observers_.RemoveObserver(observer); |
| 56 } | 56 } |
| 57 | 57 |
| 58 // dbus::ObjectManager::Interface override. | 58 // dbus::ObjectManager::Interface override. |
| 59 virtual dbus::PropertySet* CreateProperties( | 59 virtual dbus::PropertySet* CreateProperties( |
| 60 dbus::ObjectProxy* object_proxy, | 60 dbus::ObjectProxy* object_proxy, |
| 61 const dbus::ObjectPath& object_path, | 61 const dbus::ObjectPath& object_path, |
| 62 const std::string& interface_name) OVERRIDE { | 62 const std::string& interface_name) override { |
| 63 Properties* properties = new Properties( | 63 Properties* properties = new Properties( |
| 64 object_proxy, | 64 object_proxy, |
| 65 interface_name, | 65 interface_name, |
| 66 base::Bind(&BluetoothInputClientImpl::OnPropertyChanged, | 66 base::Bind(&BluetoothInputClientImpl::OnPropertyChanged, |
| 67 weak_ptr_factory_.GetWeakPtr(), | 67 weak_ptr_factory_.GetWeakPtr(), |
| 68 object_path)); | 68 object_path)); |
| 69 return static_cast<dbus::PropertySet*>(properties); | 69 return static_cast<dbus::PropertySet*>(properties); |
| 70 } | 70 } |
| 71 | 71 |
| 72 // BluetoothInputClient override. | 72 // BluetoothInputClient override. |
| 73 virtual Properties* GetProperties(const dbus::ObjectPath& object_path) | 73 virtual Properties* GetProperties(const dbus::ObjectPath& object_path) |
| 74 OVERRIDE { | 74 override { |
| 75 return static_cast<Properties*>( | 75 return static_cast<Properties*>( |
| 76 object_manager_->GetProperties( | 76 object_manager_->GetProperties( |
| 77 object_path, | 77 object_path, |
| 78 bluetooth_input::kBluetoothInputInterface)); | 78 bluetooth_input::kBluetoothInputInterface)); |
| 79 } | 79 } |
| 80 | 80 |
| 81 protected: | 81 protected: |
| 82 virtual void Init(dbus::Bus* bus) OVERRIDE { | 82 virtual void Init(dbus::Bus* bus) override { |
| 83 object_manager_ = bus->GetObjectManager( | 83 object_manager_ = bus->GetObjectManager( |
| 84 bluetooth_object_manager::kBluetoothObjectManagerServiceName, | 84 bluetooth_object_manager::kBluetoothObjectManagerServiceName, |
| 85 dbus::ObjectPath( | 85 dbus::ObjectPath( |
| 86 bluetooth_object_manager::kBluetoothObjectManagerServicePath)); | 86 bluetooth_object_manager::kBluetoothObjectManagerServicePath)); |
| 87 object_manager_->RegisterInterface( | 87 object_manager_->RegisterInterface( |
| 88 bluetooth_input::kBluetoothInputInterface, this); | 88 bluetooth_input::kBluetoothInputInterface, this); |
| 89 } | 89 } |
| 90 | 90 |
| 91 private: | 91 private: |
| 92 // Called by dbus::ObjectManager when an object with the input interface | 92 // Called by dbus::ObjectManager when an object with the input interface |
| 93 // is created. Informs observers. | 93 // is created. Informs observers. |
| 94 virtual void ObjectAdded(const dbus::ObjectPath& object_path, | 94 virtual void ObjectAdded(const dbus::ObjectPath& object_path, |
| 95 const std::string& interface_name) OVERRIDE { | 95 const std::string& interface_name) override { |
| 96 FOR_EACH_OBSERVER(BluetoothInputClient::Observer, observers_, | 96 FOR_EACH_OBSERVER(BluetoothInputClient::Observer, observers_, |
| 97 InputAdded(object_path)); | 97 InputAdded(object_path)); |
| 98 } | 98 } |
| 99 | 99 |
| 100 // Called by dbus::ObjectManager when an object with the input interface | 100 // Called by dbus::ObjectManager when an object with the input interface |
| 101 // is removed. Informs observers. | 101 // is removed. Informs observers. |
| 102 virtual void ObjectRemoved(const dbus::ObjectPath& object_path, | 102 virtual void ObjectRemoved(const dbus::ObjectPath& object_path, |
| 103 const std::string& interface_name) OVERRIDE { | 103 const std::string& interface_name) override { |
| 104 FOR_EACH_OBSERVER(BluetoothInputClient::Observer, observers_, | 104 FOR_EACH_OBSERVER(BluetoothInputClient::Observer, observers_, |
| 105 InputRemoved(object_path)); | 105 InputRemoved(object_path)); |
| 106 } | 106 } |
| 107 | 107 |
| 108 // Called by BluetoothPropertySet when a property value is changed, | 108 // Called by BluetoothPropertySet when a property value is changed, |
| 109 // either by result of a signal or response to a GetAll() or Get() | 109 // either by result of a signal or response to a GetAll() or Get() |
| 110 // call. Informs observers. | 110 // call. Informs observers. |
| 111 void OnPropertyChanged(const dbus::ObjectPath& object_path, | 111 void OnPropertyChanged(const dbus::ObjectPath& object_path, |
| 112 const std::string& property_name) { | 112 const std::string& property_name) { |
| 113 FOR_EACH_OBSERVER(BluetoothInputClient::Observer, observers_, | 113 FOR_EACH_OBSERVER(BluetoothInputClient::Observer, observers_, |
| (...skipping 18 matching lines...) Expand all Loading... |
| 132 } | 132 } |
| 133 | 133 |
| 134 BluetoothInputClient::~BluetoothInputClient() { | 134 BluetoothInputClient::~BluetoothInputClient() { |
| 135 } | 135 } |
| 136 | 136 |
| 137 BluetoothInputClient* BluetoothInputClient::Create() { | 137 BluetoothInputClient* BluetoothInputClient::Create() { |
| 138 return new BluetoothInputClientImpl(); | 138 return new BluetoothInputClientImpl(); |
| 139 } | 139 } |
| 140 | 140 |
| 141 } // namespace chromeos | 141 } // namespace chromeos |
| OLD | NEW |