Chromium Code Reviews| 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 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 88 object_manager_->GetObjectProxy(object_path); | 88 object_manager_->GetObjectProxy(object_path); |
| 89 if (!object_proxy) { | 89 if (!object_proxy) { |
| 90 error_callback.Run(kUnknownCharacteristicError, ""); | 90 error_callback.Run(kUnknownCharacteristicError, ""); |
| 91 return; | 91 return; |
| 92 } | 92 } |
| 93 | 93 |
| 94 dbus::MethodCall method_call( | 94 dbus::MethodCall method_call( |
| 95 bluetooth_gatt_characteristic::kBluetoothGattCharacteristicInterface, | 95 bluetooth_gatt_characteristic::kBluetoothGattCharacteristicInterface, |
| 96 bluetooth_gatt_characteristic::kReadValue); | 96 bluetooth_gatt_characteristic::kReadValue); |
| 97 | 97 |
| 98 // Write offset option | |
| 99 dbus::MessageWriter writer(&method_call); | |
| 100 dbus::MessageWriter array_writer(NULL); | |
| 101 dbus::MessageWriter dict_entry_writer(NULL); | |
| 102 dbus::MessageWriter variant_writer(NULL); | |
| 103 writer.OpenArray("{sv}", &array_writer); | |
| 104 array_writer.OpenDictEntry(&dict_entry_writer); | |
| 105 dict_entry_writer.AppendString( | |
| 106 bluetooth_gatt_characteristic::kOptionOffset); | |
|
rkc
2016/05/27 04:01:12
The whole purpose of having an options/flags dicti
| |
| 107 dict_entry_writer.OpenVariant("as", &variant_writer); | |
| 108 variant_writer.AppendInt16(0); | |
| 109 dict_entry_writer.CloseContainer(&variant_writer); | |
| 110 array_writer.CloseContainer(&dict_entry_writer); | |
| 111 writer.CloseContainer(&array_writer); | |
| 112 | |
| 98 object_proxy->CallMethodWithErrorCallback( | 113 object_proxy->CallMethodWithErrorCallback( |
| 99 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 114 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
| 100 base::Bind(&BluetoothGattCharacteristicClientImpl::OnValueSuccess, | 115 base::Bind(&BluetoothGattCharacteristicClientImpl::OnValueSuccess, |
| 101 weak_ptr_factory_.GetWeakPtr(), callback), | 116 weak_ptr_factory_.GetWeakPtr(), callback), |
| 102 base::Bind(&BluetoothGattCharacteristicClientImpl::OnError, | 117 base::Bind(&BluetoothGattCharacteristicClientImpl::OnError, |
| 103 weak_ptr_factory_.GetWeakPtr(), error_callback)); | 118 weak_ptr_factory_.GetWeakPtr(), error_callback)); |
| 104 } | 119 } |
| 105 | 120 |
| 106 // BluetoothGattCharacteristicClient override. | 121 // BluetoothGattCharacteristicClient override. |
| 107 void WriteValue(const dbus::ObjectPath& object_path, | 122 void WriteValue(const dbus::ObjectPath& object_path, |
| 108 const std::vector<uint8_t>& value, | 123 const std::vector<uint8_t>& value, |
| 109 const base::Closure& callback, | 124 const base::Closure& callback, |
| 110 const ErrorCallback& error_callback) override { | 125 const ErrorCallback& error_callback) override { |
| 111 dbus::ObjectProxy* object_proxy = | 126 dbus::ObjectProxy* object_proxy = |
| 112 object_manager_->GetObjectProxy(object_path); | 127 object_manager_->GetObjectProxy(object_path); |
| 113 if (!object_proxy) { | 128 if (!object_proxy) { |
| 114 error_callback.Run(kUnknownCharacteristicError, ""); | 129 error_callback.Run(kUnknownCharacteristicError, ""); |
| 115 return; | 130 return; |
| 116 } | 131 } |
| 117 | 132 |
| 118 dbus::MethodCall method_call( | 133 dbus::MethodCall method_call( |
| 119 bluetooth_gatt_characteristic::kBluetoothGattCharacteristicInterface, | 134 bluetooth_gatt_characteristic::kBluetoothGattCharacteristicInterface, |
| 120 bluetooth_gatt_characteristic::kWriteValue); | 135 bluetooth_gatt_characteristic::kWriteValue); |
| 121 dbus::MessageWriter writer(&method_call); | 136 dbus::MessageWriter writer(&method_call); |
| 122 writer.AppendArrayOfBytes(value.data(), value.size()); | 137 writer.AppendArrayOfBytes(value.data(), value.size()); |
| 123 | 138 |
| 139 // Write offset option | |
| 140 dbus::MessageWriter array_writer(NULL); | |
| 141 dbus::MessageWriter dict_entry_writer(NULL); | |
| 142 dbus::MessageWriter variant_writer(NULL); | |
| 143 writer.OpenArray("{sv}", &array_writer); | |
| 144 array_writer.OpenDictEntry(&dict_entry_writer); | |
| 145 dict_entry_writer.AppendString( | |
| 146 bluetooth_gatt_characteristic::kOptionOffset); | |
| 147 dict_entry_writer.OpenVariant("as", &variant_writer); | |
| 148 variant_writer.AppendInt16(0); | |
| 149 dict_entry_writer.CloseContainer(&variant_writer); | |
| 150 array_writer.CloseContainer(&dict_entry_writer); | |
| 151 writer.CloseContainer(&array_writer); | |
| 152 | |
| 124 object_proxy->CallMethodWithErrorCallback( | 153 object_proxy->CallMethodWithErrorCallback( |
| 125 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 154 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
| 126 base::Bind(&BluetoothGattCharacteristicClientImpl::OnSuccess, | 155 base::Bind(&BluetoothGattCharacteristicClientImpl::OnSuccess, |
| 127 weak_ptr_factory_.GetWeakPtr(), callback), | 156 weak_ptr_factory_.GetWeakPtr(), callback), |
| 128 base::Bind(&BluetoothGattCharacteristicClientImpl::OnError, | 157 base::Bind(&BluetoothGattCharacteristicClientImpl::OnError, |
| 129 weak_ptr_factory_.GetWeakPtr(), error_callback)); | 158 weak_ptr_factory_.GetWeakPtr(), error_callback)); |
| 130 } | 159 } |
| 131 | 160 |
| 132 // BluetoothGattCharacteristicClient override. | 161 // BluetoothGattCharacteristicClient override. |
| 133 void StartNotify(const dbus::ObjectPath& object_path, | 162 void StartNotify(const dbus::ObjectPath& object_path, |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 288 BluetoothGattCharacteristicClient::BluetoothGattCharacteristicClient() {} | 317 BluetoothGattCharacteristicClient::BluetoothGattCharacteristicClient() {} |
| 289 | 318 |
| 290 BluetoothGattCharacteristicClient::~BluetoothGattCharacteristicClient() {} | 319 BluetoothGattCharacteristicClient::~BluetoothGattCharacteristicClient() {} |
| 291 | 320 |
| 292 // static | 321 // static |
| 293 BluetoothGattCharacteristicClient* BluetoothGattCharacteristicClient::Create() { | 322 BluetoothGattCharacteristicClient* BluetoothGattCharacteristicClient::Create() { |
| 294 return new BluetoothGattCharacteristicClientImpl(); | 323 return new BluetoothGattCharacteristicClientImpl(); |
| 295 } | 324 } |
| 296 | 325 |
| 297 } // namespace bluez | 326 } // namespace bluez |
| OLD | NEW |