| 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_characteristic_client.h" | 5 #include "device/bluetooth/dbus/bluetooth_gatt_characteristic_client.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 object_proxy, interface_name, | 195 object_proxy, interface_name, |
| 196 base::Bind(&BluetoothGattCharacteristicClientImpl::OnPropertyChanged, | 196 base::Bind(&BluetoothGattCharacteristicClientImpl::OnPropertyChanged, |
| 197 weak_ptr_factory_.GetWeakPtr(), object_path)); | 197 weak_ptr_factory_.GetWeakPtr(), object_path)); |
| 198 return static_cast<dbus::PropertySet*>(properties); | 198 return static_cast<dbus::PropertySet*>(properties); |
| 199 } | 199 } |
| 200 | 200 |
| 201 // dbus::ObjectManager::Interface override. | 201 // dbus::ObjectManager::Interface override. |
| 202 void ObjectAdded(const dbus::ObjectPath& object_path, | 202 void ObjectAdded(const dbus::ObjectPath& object_path, |
| 203 const std::string& interface_name) override { | 203 const std::string& interface_name) override { |
| 204 VLOG(2) << "Remote GATT characteristic added: " << object_path.value(); | 204 VLOG(2) << "Remote GATT characteristic added: " << object_path.value(); |
| 205 FOR_EACH_OBSERVER(BluetoothGattCharacteristicClient::Observer, observers_, | 205 for (auto& observer : observers_) |
| 206 GattCharacteristicAdded(object_path)); | 206 observer.GattCharacteristicAdded(object_path); |
| 207 } | 207 } |
| 208 | 208 |
| 209 // dbus::ObjectManager::Interface override. | 209 // dbus::ObjectManager::Interface override. |
| 210 void ObjectRemoved(const dbus::ObjectPath& object_path, | 210 void ObjectRemoved(const dbus::ObjectPath& object_path, |
| 211 const std::string& interface_name) override { | 211 const std::string& interface_name) override { |
| 212 VLOG(2) << "Remote GATT characteristic removed: " << object_path.value(); | 212 VLOG(2) << "Remote GATT characteristic removed: " << object_path.value(); |
| 213 FOR_EACH_OBSERVER(BluetoothGattCharacteristicClient::Observer, observers_, | 213 for (auto& observer : observers_) |
| 214 GattCharacteristicRemoved(object_path)); | 214 observer.GattCharacteristicRemoved(object_path); |
| 215 } | 215 } |
| 216 | 216 |
| 217 protected: | 217 protected: |
| 218 // bluez::DBusClient override. | 218 // bluez::DBusClient override. |
| 219 void Init(dbus::Bus* bus) override { | 219 void Init(dbus::Bus* bus) override { |
| 220 object_manager_ = bus->GetObjectManager( | 220 object_manager_ = bus->GetObjectManager( |
| 221 bluetooth_object_manager::kBluetoothObjectManagerServiceName, | 221 bluetooth_object_manager::kBluetoothObjectManagerServiceName, |
| 222 dbus::ObjectPath( | 222 dbus::ObjectPath( |
| 223 bluetooth_object_manager::kBluetoothObjectManagerServicePath)); | 223 bluetooth_object_manager::kBluetoothObjectManagerServicePath)); |
| 224 object_manager_->RegisterInterface( | 224 object_manager_->RegisterInterface( |
| 225 bluetooth_gatt_characteristic::kBluetoothGattCharacteristicInterface, | 225 bluetooth_gatt_characteristic::kBluetoothGattCharacteristicInterface, |
| 226 this); | 226 this); |
| 227 } | 227 } |
| 228 | 228 |
| 229 private: | 229 private: |
| 230 // Called by dbus::PropertySet when a property value is changed, either by | 230 // Called by dbus::PropertySet when a property value is changed, either by |
| 231 // result of a signal or response to a GetAll() or Get() call. Informs | 231 // result of a signal or response to a GetAll() or Get() call. Informs |
| 232 // observers. | 232 // observers. |
| 233 virtual void OnPropertyChanged(const dbus::ObjectPath& object_path, | 233 virtual void OnPropertyChanged(const dbus::ObjectPath& object_path, |
| 234 const std::string& property_name) { | 234 const std::string& property_name) { |
| 235 VLOG(2) << "Remote GATT characteristic property changed: " | 235 VLOG(2) << "Remote GATT characteristic property changed: " |
| 236 << object_path.value() << ": " << property_name; | 236 << object_path.value() << ": " << property_name; |
| 237 FOR_EACH_OBSERVER( | 237 for (auto& observer : observers_) |
| 238 BluetoothGattCharacteristicClient::Observer, observers_, | 238 observer.GattCharacteristicPropertyChanged(object_path, property_name); |
| 239 GattCharacteristicPropertyChanged(object_path, property_name)); | |
| 240 } | 239 } |
| 241 | 240 |
| 242 // Called when a response for successful method call is received. | 241 // Called when a response for successful method call is received. |
| 243 void OnSuccess(const base::Closure& callback, dbus::Response* response) { | 242 void OnSuccess(const base::Closure& callback, dbus::Response* response) { |
| 244 DCHECK(response); | 243 DCHECK(response); |
| 245 callback.Run(); | 244 callback.Run(); |
| 246 } | 245 } |
| 247 | 246 |
| 248 // Called when a characteristic value response for a successful method call | 247 // Called when a characteristic value response for a successful method call |
| 249 // is received. | 248 // is received. |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 299 BluetoothGattCharacteristicClient::BluetoothGattCharacteristicClient() {} | 298 BluetoothGattCharacteristicClient::BluetoothGattCharacteristicClient() {} |
| 300 | 299 |
| 301 BluetoothGattCharacteristicClient::~BluetoothGattCharacteristicClient() {} | 300 BluetoothGattCharacteristicClient::~BluetoothGattCharacteristicClient() {} |
| 302 | 301 |
| 303 // static | 302 // static |
| 304 BluetoothGattCharacteristicClient* BluetoothGattCharacteristicClient::Create() { | 303 BluetoothGattCharacteristicClient* BluetoothGattCharacteristicClient::Create() { |
| 305 return new BluetoothGattCharacteristicClientImpl(); | 304 return new BluetoothGattCharacteristicClientImpl(); |
| 306 } | 305 } |
| 307 | 306 |
| 308 } // namespace bluez | 307 } // namespace bluez |
| OLD | NEW |