| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "device/bluetooth/dbus/bluetooth_gatt_service_client.h" | 5 #include "device/bluetooth/dbus/bluetooth_gatt_service_client.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "base/memory/weak_ptr.h" | 9 #include "base/memory/weak_ptr.h" |
| 10 #include "base/observer_list.h" | 10 #include "base/observer_list.h" |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 object_proxy, interface_name, | 74 object_proxy, interface_name, |
| 75 base::Bind(&BluetoothGattServiceClientImpl::OnPropertyChanged, | 75 base::Bind(&BluetoothGattServiceClientImpl::OnPropertyChanged, |
| 76 weak_ptr_factory_.GetWeakPtr(), object_path)); | 76 weak_ptr_factory_.GetWeakPtr(), object_path)); |
| 77 return static_cast<dbus::PropertySet*>(properties); | 77 return static_cast<dbus::PropertySet*>(properties); |
| 78 } | 78 } |
| 79 | 79 |
| 80 // dbus::ObjectManager::Interface override. | 80 // dbus::ObjectManager::Interface override. |
| 81 void ObjectAdded(const dbus::ObjectPath& object_path, | 81 void ObjectAdded(const dbus::ObjectPath& object_path, |
| 82 const std::string& interface_name) override { | 82 const std::string& interface_name) override { |
| 83 VLOG(2) << "Remote GATT service added: " << object_path.value(); | 83 VLOG(2) << "Remote GATT service added: " << object_path.value(); |
| 84 FOR_EACH_OBSERVER(BluetoothGattServiceClient::Observer, observers_, | 84 for (auto& observer : observers_) |
| 85 GattServiceAdded(object_path)); | 85 observer.GattServiceAdded(object_path); |
| 86 } | 86 } |
| 87 | 87 |
| 88 // dbus::ObjectManager::Interface override. | 88 // dbus::ObjectManager::Interface override. |
| 89 void ObjectRemoved(const dbus::ObjectPath& object_path, | 89 void ObjectRemoved(const dbus::ObjectPath& object_path, |
| 90 const std::string& interface_name) override { | 90 const std::string& interface_name) override { |
| 91 VLOG(2) << "Remote GATT service removed: " << object_path.value(); | 91 VLOG(2) << "Remote GATT service removed: " << object_path.value(); |
| 92 FOR_EACH_OBSERVER(BluetoothGattServiceClient::Observer, observers_, | 92 for (auto& observer : observers_) |
| 93 GattServiceRemoved(object_path)); | 93 observer.GattServiceRemoved(object_path); |
| 94 } | 94 } |
| 95 | 95 |
| 96 protected: | 96 protected: |
| 97 // bluez::DBusClient override. | 97 // bluez::DBusClient override. |
| 98 void Init(dbus::Bus* bus) override { | 98 void Init(dbus::Bus* bus) override { |
| 99 object_manager_ = bus->GetObjectManager( | 99 object_manager_ = bus->GetObjectManager( |
| 100 bluetooth_object_manager::kBluetoothObjectManagerServiceName, | 100 bluetooth_object_manager::kBluetoothObjectManagerServiceName, |
| 101 dbus::ObjectPath( | 101 dbus::ObjectPath( |
| 102 bluetooth_object_manager::kBluetoothObjectManagerServicePath)); | 102 bluetooth_object_manager::kBluetoothObjectManagerServicePath)); |
| 103 object_manager_->RegisterInterface( | 103 object_manager_->RegisterInterface( |
| 104 bluetooth_gatt_service::kBluetoothGattServiceInterface, this); | 104 bluetooth_gatt_service::kBluetoothGattServiceInterface, this); |
| 105 } | 105 } |
| 106 | 106 |
| 107 private: | 107 private: |
| 108 // Called by dbus::PropertySet when a property value is changed, either by | 108 // Called by dbus::PropertySet when a property value is changed, either by |
| 109 // result of a signal or response to a GetAll() or Get() call. Informs | 109 // result of a signal or response to a GetAll() or Get() call. Informs |
| 110 // observers. | 110 // observers. |
| 111 virtual void OnPropertyChanged(const dbus::ObjectPath& object_path, | 111 virtual void OnPropertyChanged(const dbus::ObjectPath& object_path, |
| 112 const std::string& property_name) { | 112 const std::string& property_name) { |
| 113 VLOG(2) << "Remote GATT service property changed: " << object_path.value() | 113 VLOG(2) << "Remote GATT service property changed: " << object_path.value() |
| 114 << ": " << property_name; | 114 << ": " << property_name; |
| 115 FOR_EACH_OBSERVER(BluetoothGattServiceClient::Observer, observers_, | 115 for (auto& observer : observers_) |
| 116 GattServicePropertyChanged(object_path, property_name)); | 116 observer.GattServicePropertyChanged(object_path, property_name); |
| 117 } | 117 } |
| 118 | 118 |
| 119 dbus::ObjectManager* object_manager_; | 119 dbus::ObjectManager* object_manager_; |
| 120 | 120 |
| 121 // List of observers interested in event notifications from us. | 121 // List of observers interested in event notifications from us. |
| 122 base::ObserverList<BluetoothGattServiceClient::Observer> observers_; | 122 base::ObserverList<BluetoothGattServiceClient::Observer> observers_; |
| 123 | 123 |
| 124 // Weak pointer factory for generating 'this' pointers that might live longer | 124 // Weak pointer factory for generating 'this' pointers that might live longer |
| 125 // than we do. | 125 // than we do. |
| 126 // Note: This should remain the last member so it'll be destroyed and | 126 // Note: This should remain the last member so it'll be destroyed and |
| 127 // invalidate its weak pointers before any other members are destroyed. | 127 // invalidate its weak pointers before any other members are destroyed. |
| 128 base::WeakPtrFactory<BluetoothGattServiceClientImpl> weak_ptr_factory_; | 128 base::WeakPtrFactory<BluetoothGattServiceClientImpl> weak_ptr_factory_; |
| 129 | 129 |
| 130 DISALLOW_COPY_AND_ASSIGN(BluetoothGattServiceClientImpl); | 130 DISALLOW_COPY_AND_ASSIGN(BluetoothGattServiceClientImpl); |
| 131 }; | 131 }; |
| 132 | 132 |
| 133 BluetoothGattServiceClient::BluetoothGattServiceClient() {} | 133 BluetoothGattServiceClient::BluetoothGattServiceClient() {} |
| 134 | 134 |
| 135 BluetoothGattServiceClient::~BluetoothGattServiceClient() {} | 135 BluetoothGattServiceClient::~BluetoothGattServiceClient() {} |
| 136 | 136 |
| 137 // static | 137 // static |
| 138 BluetoothGattServiceClient* BluetoothGattServiceClient::Create() { | 138 BluetoothGattServiceClient* BluetoothGattServiceClient::Create() { |
| 139 return new BluetoothGattServiceClientImpl(); | 139 return new BluetoothGattServiceClientImpl(); |
| 140 } | 140 } |
| 141 | 141 |
| 142 } // namespace bluez | 142 } // namespace bluez |
| OLD | NEW |