| 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> |
| 8 |
| 7 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/macros.h" |
| 8 #include "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
| 9 #include "base/observer_list.h" | 12 #include "base/observer_list.h" |
| 10 #include "dbus/bus.h" | 13 #include "dbus/bus.h" |
| 11 #include "dbus/object_manager.h" | 14 #include "dbus/object_manager.h" |
| 12 #include "third_party/cros_system_api/dbus/service_constants.h" | 15 #include "third_party/cros_system_api/dbus/service_constants.h" |
| 13 | 16 |
| 14 namespace bluez { | 17 namespace bluez { |
| 15 | 18 |
| 16 namespace { | 19 namespace { |
| 17 | 20 |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 object_proxy->CallMethodWithErrorCallback( | 107 object_proxy->CallMethodWithErrorCallback( |
| 105 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 108 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
| 106 base::Bind(&BluetoothGattCharacteristicClientImpl::OnValueSuccess, | 109 base::Bind(&BluetoothGattCharacteristicClientImpl::OnValueSuccess, |
| 107 weak_ptr_factory_.GetWeakPtr(), callback), | 110 weak_ptr_factory_.GetWeakPtr(), callback), |
| 108 base::Bind(&BluetoothGattCharacteristicClientImpl::OnError, | 111 base::Bind(&BluetoothGattCharacteristicClientImpl::OnError, |
| 109 weak_ptr_factory_.GetWeakPtr(), error_callback)); | 112 weak_ptr_factory_.GetWeakPtr(), error_callback)); |
| 110 } | 113 } |
| 111 | 114 |
| 112 // BluetoothGattCharacteristicClient override. | 115 // BluetoothGattCharacteristicClient override. |
| 113 void WriteValue(const dbus::ObjectPath& object_path, | 116 void WriteValue(const dbus::ObjectPath& object_path, |
| 114 const std::vector<uint8>& value, | 117 const std::vector<uint8_t>& value, |
| 115 const base::Closure& callback, | 118 const base::Closure& callback, |
| 116 const ErrorCallback& error_callback) override { | 119 const ErrorCallback& error_callback) override { |
| 117 dbus::ObjectProxy* object_proxy = | 120 dbus::ObjectProxy* object_proxy = |
| 118 object_manager_->GetObjectProxy(object_path); | 121 object_manager_->GetObjectProxy(object_path); |
| 119 if (!object_proxy) { | 122 if (!object_proxy) { |
| 120 error_callback.Run(kUnknownCharacteristicError, ""); | 123 error_callback.Run(kUnknownCharacteristicError, ""); |
| 121 return; | 124 return; |
| 122 } | 125 } |
| 123 | 126 |
| 124 dbus::MethodCall method_call( | 127 dbus::MethodCall method_call( |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 239 DCHECK(response); | 242 DCHECK(response); |
| 240 callback.Run(); | 243 callback.Run(); |
| 241 } | 244 } |
| 242 | 245 |
| 243 // Called when a characteristic value response for a successful method call | 246 // Called when a characteristic value response for a successful method call |
| 244 // is received. | 247 // is received. |
| 245 void OnValueSuccess(const ValueCallback& callback, dbus::Response* response) { | 248 void OnValueSuccess(const ValueCallback& callback, dbus::Response* response) { |
| 246 DCHECK(response); | 249 DCHECK(response); |
| 247 dbus::MessageReader reader(response); | 250 dbus::MessageReader reader(response); |
| 248 | 251 |
| 249 const uint8* bytes = NULL; | 252 const uint8_t* bytes = NULL; |
| 250 size_t length = 0; | 253 size_t length = 0; |
| 251 | 254 |
| 252 if (!reader.PopArrayOfBytes(&bytes, &length)) | 255 if (!reader.PopArrayOfBytes(&bytes, &length)) |
| 253 VLOG(2) << "Error reading array of bytes in ValueCallback"; | 256 VLOG(2) << "Error reading array of bytes in ValueCallback"; |
| 254 | 257 |
| 255 std::vector<uint8> value; | 258 std::vector<uint8_t> value; |
| 256 | 259 |
| 257 if (bytes) | 260 if (bytes) |
| 258 value.assign(bytes, bytes + length); | 261 value.assign(bytes, bytes + length); |
| 259 | 262 |
| 260 callback.Run(value); | 263 callback.Run(value); |
| 261 } | 264 } |
| 262 | 265 |
| 263 // Called when a response for a failed method call is received. | 266 // Called when a response for a failed method call is received. |
| 264 void OnError(const ErrorCallback& error_callback, | 267 void OnError(const ErrorCallback& error_callback, |
| 265 dbus::ErrorResponse* response) { | 268 dbus::ErrorResponse* response) { |
| (...skipping 28 matching lines...) Expand all Loading... |
| 294 BluetoothGattCharacteristicClient::BluetoothGattCharacteristicClient() {} | 297 BluetoothGattCharacteristicClient::BluetoothGattCharacteristicClient() {} |
| 295 | 298 |
| 296 BluetoothGattCharacteristicClient::~BluetoothGattCharacteristicClient() {} | 299 BluetoothGattCharacteristicClient::~BluetoothGattCharacteristicClient() {} |
| 297 | 300 |
| 298 // static | 301 // static |
| 299 BluetoothGattCharacteristicClient* BluetoothGattCharacteristicClient::Create() { | 302 BluetoothGattCharacteristicClient* BluetoothGattCharacteristicClient::Create() { |
| 300 return new BluetoothGattCharacteristicClientImpl(); | 303 return new BluetoothGattCharacteristicClientImpl(); |
| 301 } | 304 } |
| 302 | 305 |
| 303 } // namespace bluez | 306 } // namespace bluez |
| OLD | NEW |