| 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" |
| 11 #include "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
| 12 #include "base/observer_list.h" | 12 #include "base/observer_list.h" |
| 13 #include "base/values.h" |
| 13 #include "dbus/bus.h" | 14 #include "dbus/bus.h" |
| 14 #include "dbus/object_manager.h" | 15 #include "dbus/object_manager.h" |
| 16 #include "dbus/values_util.h" |
| 15 #include "third_party/cros_system_api/dbus/service_constants.h" | 17 #include "third_party/cros_system_api/dbus/service_constants.h" |
| 16 | 18 |
| 17 namespace bluez { | 19 namespace bluez { |
| 18 | 20 |
| 19 // static | 21 // static |
| 20 const char BluetoothGattCharacteristicClient::kNoResponseError[] = | 22 const char BluetoothGattCharacteristicClient::kNoResponseError[] = |
| 21 "org.chromium.Error.NoResponse"; | 23 "org.chromium.Error.NoResponse"; |
| 22 // static | 24 // static |
| 23 const char BluetoothGattCharacteristicClient::kUnknownCharacteristicError[] = | 25 const char BluetoothGattCharacteristicClient::kUnknownCharacteristicError[] = |
| 24 "org.chromium.Error.UnknownCharacteristic"; | 26 "org.chromium.Error.UnknownCharacteristic"; |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 object_manager_->GetObjectProxy(object_path); | 90 object_manager_->GetObjectProxy(object_path); |
| 89 if (!object_proxy) { | 91 if (!object_proxy) { |
| 90 error_callback.Run(kUnknownCharacteristicError, ""); | 92 error_callback.Run(kUnknownCharacteristicError, ""); |
| 91 return; | 93 return; |
| 92 } | 94 } |
| 93 | 95 |
| 94 dbus::MethodCall method_call( | 96 dbus::MethodCall method_call( |
| 95 bluetooth_gatt_characteristic::kBluetoothGattCharacteristicInterface, | 97 bluetooth_gatt_characteristic::kBluetoothGattCharacteristicInterface, |
| 96 bluetooth_gatt_characteristic::kReadValue); | 98 bluetooth_gatt_characteristic::kReadValue); |
| 97 | 99 |
| 100 // Append empty option dict |
| 101 dbus::MessageWriter writer(&method_call); |
| 102 base::DictionaryValue dict; |
| 103 dbus::AppendValueData(&writer, dict); |
| 104 |
| 98 object_proxy->CallMethodWithErrorCallback( | 105 object_proxy->CallMethodWithErrorCallback( |
| 99 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 106 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
| 100 base::Bind(&BluetoothGattCharacteristicClientImpl::OnValueSuccess, | 107 base::Bind(&BluetoothGattCharacteristicClientImpl::OnValueSuccess, |
| 101 weak_ptr_factory_.GetWeakPtr(), callback), | 108 weak_ptr_factory_.GetWeakPtr(), callback), |
| 102 base::Bind(&BluetoothGattCharacteristicClientImpl::OnError, | 109 base::Bind(&BluetoothGattCharacteristicClientImpl::OnError, |
| 103 weak_ptr_factory_.GetWeakPtr(), error_callback)); | 110 weak_ptr_factory_.GetWeakPtr(), error_callback)); |
| 104 } | 111 } |
| 105 | 112 |
| 106 // BluetoothGattCharacteristicClient override. | 113 // BluetoothGattCharacteristicClient override. |
| 107 void WriteValue(const dbus::ObjectPath& object_path, | 114 void WriteValue(const dbus::ObjectPath& object_path, |
| 108 const std::vector<uint8_t>& value, | 115 const std::vector<uint8_t>& value, |
| 109 const base::Closure& callback, | 116 const base::Closure& callback, |
| 110 const ErrorCallback& error_callback) override { | 117 const ErrorCallback& error_callback) override { |
| 111 dbus::ObjectProxy* object_proxy = | 118 dbus::ObjectProxy* object_proxy = |
| 112 object_manager_->GetObjectProxy(object_path); | 119 object_manager_->GetObjectProxy(object_path); |
| 113 if (!object_proxy) { | 120 if (!object_proxy) { |
| 114 error_callback.Run(kUnknownCharacteristicError, ""); | 121 error_callback.Run(kUnknownCharacteristicError, ""); |
| 115 return; | 122 return; |
| 116 } | 123 } |
| 117 | 124 |
| 118 dbus::MethodCall method_call( | 125 dbus::MethodCall method_call( |
| 119 bluetooth_gatt_characteristic::kBluetoothGattCharacteristicInterface, | 126 bluetooth_gatt_characteristic::kBluetoothGattCharacteristicInterface, |
| 120 bluetooth_gatt_characteristic::kWriteValue); | 127 bluetooth_gatt_characteristic::kWriteValue); |
| 121 dbus::MessageWriter writer(&method_call); | 128 dbus::MessageWriter writer(&method_call); |
| 122 writer.AppendArrayOfBytes(value.data(), value.size()); | 129 writer.AppendArrayOfBytes(value.data(), value.size()); |
| 123 | 130 |
| 131 // Append empty option dict |
| 132 base::DictionaryValue dict; |
| 133 dbus::AppendValueData(&writer, dict); |
| 134 |
| 124 object_proxy->CallMethodWithErrorCallback( | 135 object_proxy->CallMethodWithErrorCallback( |
| 125 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 136 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
| 126 base::Bind(&BluetoothGattCharacteristicClientImpl::OnSuccess, | 137 base::Bind(&BluetoothGattCharacteristicClientImpl::OnSuccess, |
| 127 weak_ptr_factory_.GetWeakPtr(), callback), | 138 weak_ptr_factory_.GetWeakPtr(), callback), |
| 128 base::Bind(&BluetoothGattCharacteristicClientImpl::OnError, | 139 base::Bind(&BluetoothGattCharacteristicClientImpl::OnError, |
| 129 weak_ptr_factory_.GetWeakPtr(), error_callback)); | 140 weak_ptr_factory_.GetWeakPtr(), error_callback)); |
| 130 } | 141 } |
| 131 | 142 |
| 132 // BluetoothGattCharacteristicClient override. | 143 // BluetoothGattCharacteristicClient override. |
| 133 void StartNotify(const dbus::ObjectPath& object_path, | 144 void StartNotify(const dbus::ObjectPath& object_path, |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 288 BluetoothGattCharacteristicClient::BluetoothGattCharacteristicClient() {} | 299 BluetoothGattCharacteristicClient::BluetoothGattCharacteristicClient() {} |
| 289 | 300 |
| 290 BluetoothGattCharacteristicClient::~BluetoothGattCharacteristicClient() {} | 301 BluetoothGattCharacteristicClient::~BluetoothGattCharacteristicClient() {} |
| 291 | 302 |
| 292 // static | 303 // static |
| 293 BluetoothGattCharacteristicClient* BluetoothGattCharacteristicClient::Create() { | 304 BluetoothGattCharacteristicClient* BluetoothGattCharacteristicClient::Create() { |
| 294 return new BluetoothGattCharacteristicClientImpl(); | 305 return new BluetoothGattCharacteristicClientImpl(); |
| 295 } | 306 } |
| 296 | 307 |
| 297 } // namespace bluez | 308 } // namespace bluez |
| OLD | NEW |