| 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_descriptor_client.h" | 5 #include "device/bluetooth/dbus/bluetooth_gatt_descriptor_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 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 object_manager_->GetObjectProxy(object_path); | 92 object_manager_->GetObjectProxy(object_path); |
| 93 if (!object_proxy) { | 93 if (!object_proxy) { |
| 94 error_callback.Run(kUnknownDescriptorError, ""); | 94 error_callback.Run(kUnknownDescriptorError, ""); |
| 95 return; | 95 return; |
| 96 } | 96 } |
| 97 | 97 |
| 98 dbus::MethodCall method_call( | 98 dbus::MethodCall method_call( |
| 99 bluetooth_gatt_descriptor::kBluetoothGattDescriptorInterface, | 99 bluetooth_gatt_descriptor::kBluetoothGattDescriptorInterface, |
| 100 bluetooth_gatt_descriptor::kReadValue); | 100 bluetooth_gatt_descriptor::kReadValue); |
| 101 | 101 |
| 102 // Write offset option |
| 103 dbus::MessageWriter writer(&method_call); |
| 104 dbus::MessageWriter array_writer(NULL); |
| 105 dbus::MessageWriter dict_entry_writer(NULL); |
| 106 dbus::MessageWriter variant_writer(NULL); |
| 107 writer.OpenArray("{sv}", &array_writer); |
| 108 array_writer.OpenDictEntry(&dict_entry_writer); |
| 109 dict_entry_writer.AppendString( |
| 110 bluetooth_gatt_characteristic::kOptionOffset); |
| 111 dict_entry_writer.OpenVariant("as", &variant_writer); |
| 112 variant_writer.AppendInt16(0); |
| 113 dict_entry_writer.CloseContainer(&variant_writer); |
| 114 array_writer.CloseContainer(&dict_entry_writer); |
| 115 writer.CloseContainer(&array_writer); |
| 116 |
| 102 object_proxy->CallMethodWithErrorCallback( | 117 object_proxy->CallMethodWithErrorCallback( |
| 103 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 118 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
| 104 base::Bind(&BluetoothGattDescriptorClientImpl::OnValueSuccess, | 119 base::Bind(&BluetoothGattDescriptorClientImpl::OnValueSuccess, |
| 105 weak_ptr_factory_.GetWeakPtr(), callback), | 120 weak_ptr_factory_.GetWeakPtr(), callback), |
| 106 base::Bind(&BluetoothGattDescriptorClientImpl::OnError, | 121 base::Bind(&BluetoothGattDescriptorClientImpl::OnError, |
| 107 weak_ptr_factory_.GetWeakPtr(), error_callback)); | 122 weak_ptr_factory_.GetWeakPtr(), error_callback)); |
| 108 } | 123 } |
| 109 | 124 |
| 110 // BluetoothGattDescriptorClientImpl override. | 125 // BluetoothGattDescriptorClientImpl override. |
| 111 void WriteValue(const dbus::ObjectPath& object_path, | 126 void WriteValue(const dbus::ObjectPath& object_path, |
| 112 const std::vector<uint8_t>& value, | 127 const std::vector<uint8_t>& value, |
| 113 const base::Closure& callback, | 128 const base::Closure& callback, |
| 114 const ErrorCallback& error_callback) override { | 129 const ErrorCallback& error_callback) override { |
| 115 dbus::ObjectProxy* object_proxy = | 130 dbus::ObjectProxy* object_proxy = |
| 116 object_manager_->GetObjectProxy(object_path); | 131 object_manager_->GetObjectProxy(object_path); |
| 117 if (!object_proxy) { | 132 if (!object_proxy) { |
| 118 error_callback.Run(kUnknownDescriptorError, ""); | 133 error_callback.Run(kUnknownDescriptorError, ""); |
| 119 return; | 134 return; |
| 120 } | 135 } |
| 121 | 136 |
| 122 dbus::MethodCall method_call( | 137 dbus::MethodCall method_call( |
| 123 bluetooth_gatt_descriptor::kBluetoothGattDescriptorInterface, | 138 bluetooth_gatt_descriptor::kBluetoothGattDescriptorInterface, |
| 124 bluetooth_gatt_descriptor::kWriteValue); | 139 bluetooth_gatt_descriptor::kWriteValue); |
| 125 dbus::MessageWriter writer(&method_call); | 140 dbus::MessageWriter writer(&method_call); |
| 126 writer.AppendArrayOfBytes(value.data(), value.size()); | 141 writer.AppendArrayOfBytes(value.data(), value.size()); |
| 127 | 142 |
| 143 // Write offset option |
| 144 dbus::MessageWriter array_writer(NULL); |
| 145 dbus::MessageWriter dict_entry_writer(NULL); |
| 146 dbus::MessageWriter variant_writer(NULL); |
| 147 writer.OpenArray("{sv}", &array_writer); |
| 148 array_writer.OpenDictEntry(&dict_entry_writer); |
| 149 dict_entry_writer.AppendString( |
| 150 bluetooth_gatt_characteristic::kOptionOffset); |
| 151 dict_entry_writer.OpenVariant("as", &variant_writer); |
| 152 variant_writer.AppendInt16(0); |
| 153 dict_entry_writer.CloseContainer(&variant_writer); |
| 154 array_writer.CloseContainer(&dict_entry_writer); |
| 155 writer.CloseContainer(&array_writer); |
| 156 |
| 128 object_proxy->CallMethodWithErrorCallback( | 157 object_proxy->CallMethodWithErrorCallback( |
| 129 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 158 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
| 130 base::Bind(&BluetoothGattDescriptorClientImpl::OnSuccess, | 159 base::Bind(&BluetoothGattDescriptorClientImpl::OnSuccess, |
| 131 weak_ptr_factory_.GetWeakPtr(), callback), | 160 weak_ptr_factory_.GetWeakPtr(), callback), |
| 132 base::Bind(&BluetoothGattDescriptorClientImpl::OnError, | 161 base::Bind(&BluetoothGattDescriptorClientImpl::OnError, |
| 133 weak_ptr_factory_.GetWeakPtr(), error_callback)); | 162 weak_ptr_factory_.GetWeakPtr(), error_callback)); |
| 134 } | 163 } |
| 135 | 164 |
| 136 // dbus::ObjectManager::Interface override. | 165 // dbus::ObjectManager::Interface override. |
| 137 dbus::PropertySet* CreateProperties( | 166 dbus::PropertySet* CreateProperties( |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 245 BluetoothGattDescriptorClient::BluetoothGattDescriptorClient() {} | 274 BluetoothGattDescriptorClient::BluetoothGattDescriptorClient() {} |
| 246 | 275 |
| 247 BluetoothGattDescriptorClient::~BluetoothGattDescriptorClient() {} | 276 BluetoothGattDescriptorClient::~BluetoothGattDescriptorClient() {} |
| 248 | 277 |
| 249 // static | 278 // static |
| 250 BluetoothGattDescriptorClient* BluetoothGattDescriptorClient::Create() { | 279 BluetoothGattDescriptorClient* BluetoothGattDescriptorClient::Create() { |
| 251 return new BluetoothGattDescriptorClientImpl(); | 280 return new BluetoothGattDescriptorClientImpl(); |
| 252 } | 281 } |
| 253 | 282 |
| 254 } // namespace bluez | 283 } // namespace bluez |
| OLD | NEW |