Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(40)

Side by Side Diff: device/bluetooth/dbus/bluetooth_gatt_descriptor_service_provider_impl.cc

Issue 1984723006: Add implementation for parsing device info in read/write attribute calls. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@devices_dbus_readwrite
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « device/bluetooth/dbus/bluetooth_gatt_descriptor_service_provider_impl.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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_service_provider_impl. h" 5 #include "device/bluetooth/dbus/bluetooth_gatt_descriptor_service_provider_impl. h"
6 6
7 #include <cstddef> 7 #include <cstddef>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/strings/string_util.h" 11 #include "base/strings/string_util.h"
12 #include "device/bluetooth/dbus/bluetooth_gatt_attribute_helpers.h"
12 #include "third_party/cros_system_api/dbus/service_constants.h" 13 #include "third_party/cros_system_api/dbus/service_constants.h"
13 14
14 namespace bluez { 15 namespace bluez {
15 16
16 namespace { 17 namespace {
17 18
18 const char kErrorInvalidArgs[] = "org.freedesktop.DBus.Error.InvalidArgs"; 19 const char kErrorInvalidArgs[] = "org.freedesktop.DBus.Error.InvalidArgs";
19 const char kErrorPropertyReadOnly[] = 20 const char kErrorPropertyReadOnly[] =
20 "org.freedesktop.DBus.Error.PropertyReadOnly"; 21 "org.freedesktop.DBus.Error.PropertyReadOnly";
21 const char kErrorFailed[] = "org.freedesktop.DBus.Error.Failed"; 22 const char kErrorFailed[] = "org.freedesktop.DBus.Error.Failed";
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 weak_ptr_factory_.GetWeakPtr()), 68 weak_ptr_factory_.GetWeakPtr()),
68 base::Bind(&BluetoothGattDescriptorServiceProviderImpl::OnExported, 69 base::Bind(&BluetoothGattDescriptorServiceProviderImpl::OnExported,
69 weak_ptr_factory_.GetWeakPtr())); 70 weak_ptr_factory_.GetWeakPtr()));
70 71
71 exported_object_->ExportMethod( 72 exported_object_->ExportMethod(
72 dbus::kDBusPropertiesInterface, dbus::kDBusPropertiesGetAll, 73 dbus::kDBusPropertiesInterface, dbus::kDBusPropertiesGetAll,
73 base::Bind(&BluetoothGattDescriptorServiceProviderImpl::GetAll, 74 base::Bind(&BluetoothGattDescriptorServiceProviderImpl::GetAll,
74 weak_ptr_factory_.GetWeakPtr()), 75 weak_ptr_factory_.GetWeakPtr()),
75 base::Bind(&BluetoothGattDescriptorServiceProviderImpl::OnExported, 76 base::Bind(&BluetoothGattDescriptorServiceProviderImpl::OnExported,
76 weak_ptr_factory_.GetWeakPtr())); 77 weak_ptr_factory_.GetWeakPtr()));
78
79 // org.bluez.GattDescriptor1 interface:
80 exported_object_->ExportMethod(
81 bluetooth_gatt_descriptor::kBluetoothGattDescriptorInterface,
82 bluetooth_gatt_descriptor::kReadValue,
83 base::Bind(&BluetoothGattDescriptorServiceProviderImpl::ReadValue,
84 weak_ptr_factory_.GetWeakPtr()),
85 base::Bind(&BluetoothGattDescriptorServiceProviderImpl::OnExported,
86 weak_ptr_factory_.GetWeakPtr()));
87 exported_object_->ExportMethod(
88 bluetooth_gatt_descriptor::kBluetoothGattDescriptorInterface,
89 bluetooth_gatt_descriptor::kWriteValue,
90 base::Bind(&BluetoothGattDescriptorServiceProviderImpl::WriteValue,
91 weak_ptr_factory_.GetWeakPtr()),
92 base::Bind(&BluetoothGattDescriptorServiceProviderImpl::OnExported,
93 weak_ptr_factory_.GetWeakPtr()));
77 } 94 }
78 95
79 BluetoothGattDescriptorServiceProviderImpl:: 96 BluetoothGattDescriptorServiceProviderImpl::
80 ~BluetoothGattDescriptorServiceProviderImpl() { 97 ~BluetoothGattDescriptorServiceProviderImpl() {
81 VLOG(1) << "Cleaning up Bluetooth GATT characteristic descriptor: " 98 VLOG(1) << "Cleaning up Bluetooth GATT characteristic descriptor: "
82 << object_path_.value(); 99 << object_path_.value();
83 if (bus_) 100 if (bus_)
84 bus_->UnregisterExportedObject(object_path_); 101 bus_->UnregisterExportedObject(object_path_);
85 } 102 }
86 103
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 return; 237 return;
221 } 238 }
222 239
223 std::unique_ptr<dbus::Response> response = 240 std::unique_ptr<dbus::Response> response =
224 dbus::Response::FromMethodCall(method_call); 241 dbus::Response::FromMethodCall(method_call);
225 dbus::MessageWriter writer(response.get()); 242 dbus::MessageWriter writer(response.get());
226 WriteProperties(&writer); 243 WriteProperties(&writer);
227 response_sender.Run(std::move(response)); 244 response_sender.Run(std::move(response));
228 } 245 }
229 246
247 void BluetoothGattDescriptorServiceProviderImpl::ReadValue(
248 dbus::MethodCall* method_call,
249 dbus::ExportedObject::ResponseSender response_sender) {
250 VLOG(3) << "BluetoothGattDescriptorServiceProvider::ReadValue: "
251 << object_path_.value();
252 DCHECK(OnOriginThread());
253
254 dbus::MessageReader reader(method_call);
255 dbus::ObjectPath device_path = ReadDevicePath(&reader);
256 if (device_path.value().empty()) {
257 LOG(WARNING) << "ReadValue called with incorrect parameters: "
258 << method_call->ToString();
259 // Continue on with an empty device path. This will return a null device to
260 // the delegate, which should know how to handle it.
261 }
262
263 DCHECK(delegate_);
264 delegate_->GetValue(
265 device_path,
266 base::Bind(&BluetoothGattDescriptorServiceProviderImpl::OnReadValue,
267 weak_ptr_factory_.GetWeakPtr(), method_call, response_sender),
268 base::Bind(&BluetoothGattDescriptorServiceProviderImpl::OnFailure,
269 weak_ptr_factory_.GetWeakPtr(), method_call, response_sender));
270 }
271
272 void BluetoothGattDescriptorServiceProviderImpl::WriteValue(
273 dbus::MethodCall* method_call,
274 dbus::ExportedObject::ResponseSender response_sender) {
275 VLOG(3) << "BluetoothGattDescriptorServiceProvider::WriteValue: "
276 << object_path_.value();
277 DCHECK(OnOriginThread());
278
279 dbus::MessageReader reader(method_call);
280 const uint8_t* bytes = NULL;
281 size_t length = 0;
282
283 std::vector<uint8_t> value;
284 if (!reader.PopArrayOfBytes(&bytes, &length)) {
285 LOG(WARNING) << "Error reading value parameter. WriteValue called with "
286 "incorrect parameters: "
287 << method_call->ToString();
288 }
289 if (bytes)
290 value.assign(bytes, bytes + length);
291
292 dbus::ObjectPath device_path = ReadDevicePath(&reader);
293 if (device_path.value().empty()) {
294 LOG(WARNING) << "WriteValue called with incorrect parameters: "
295 << method_call->ToString();
296 // Continue on with an empty device path. This will return a null device to
297 // the delegate, which should know how to handle it.
298 }
299
300 DCHECK(delegate_);
301 delegate_->SetValue(
302 device_path, value,
303 base::Bind(&BluetoothGattDescriptorServiceProviderImpl::OnWriteValue,
304 weak_ptr_factory_.GetWeakPtr(), method_call, response_sender),
305 base::Bind(&BluetoothGattDescriptorServiceProviderImpl::OnFailure,
306 weak_ptr_factory_.GetWeakPtr(), method_call, response_sender));
307 }
308
230 void BluetoothGattDescriptorServiceProviderImpl::OnExported( 309 void BluetoothGattDescriptorServiceProviderImpl::OnExported(
231 const std::string& interface_name, 310 const std::string& interface_name,
232 const std::string& method_name, 311 const std::string& method_name,
233 bool success) { 312 bool success) {
234 LOG_IF(WARNING, !success) << "Failed to export " << interface_name << "." 313 LOG_IF(WARNING, !success) << "Failed to export " << interface_name << "."
235 << method_name; 314 << method_name;
236 } 315 }
237 316
317 void BluetoothGattDescriptorServiceProviderImpl::OnReadValue(
318 dbus::MethodCall* method_call,
319 dbus::ExportedObject::ResponseSender response_sender,
320 const std::vector<uint8_t>& value) {
321 VLOG(3) << "Descriptor value obtained from delegate. Responding to "
322 "ReadValue.";
323
324 std::unique_ptr<dbus::Response> response =
325 dbus::Response::FromMethodCall(method_call);
326 dbus::MessageWriter writer(response.get());
327 writer.AppendArrayOfBytes(value.data(), value.size());
328 response_sender.Run(std::move(response));
329 }
330
331 void BluetoothGattDescriptorServiceProviderImpl::OnWriteValue(
332 dbus::MethodCall* method_call,
333 dbus::ExportedObject::ResponseSender response_sender) {
334 VLOG(3) << "Responding to WriteValue.";
335
336 std::unique_ptr<dbus::Response> response =
337 dbus::Response::FromMethodCall(method_call);
338 response_sender.Run(std::move(response));
339 }
340
238 void BluetoothGattDescriptorServiceProviderImpl::WriteProperties( 341 void BluetoothGattDescriptorServiceProviderImpl::WriteProperties(
239 dbus::MessageWriter* writer) { 342 dbus::MessageWriter* writer) {
240 dbus::MessageWriter array_writer(NULL); 343 dbus::MessageWriter array_writer(NULL);
241 dbus::MessageWriter dict_entry_writer(NULL); 344 dbus::MessageWriter dict_entry_writer(NULL);
242 dbus::MessageWriter variant_writer(NULL); 345 dbus::MessageWriter variant_writer(NULL);
243 346
244 writer->OpenArray("{sv}", &array_writer); 347 writer->OpenArray("{sv}", &array_writer);
245 348
246 // UUID: 349 // UUID:
247 array_writer.OpenDictEntry(&dict_entry_writer); 350 array_writer.OpenDictEntry(&dict_entry_writer);
(...skipping 28 matching lines...) Expand all
276 method_call, kErrorFailed, "Failed to get/set descriptor value."); 379 method_call, kErrorFailed, "Failed to get/set descriptor value.");
277 response_sender.Run(std::move(error_response)); 380 response_sender.Run(std::move(error_response));
278 } 381 }
279 382
280 const dbus::ObjectPath& 383 const dbus::ObjectPath&
281 BluetoothGattDescriptorServiceProviderImpl::object_path() const { 384 BluetoothGattDescriptorServiceProviderImpl::object_path() const {
282 return object_path_; 385 return object_path_;
283 } 386 }
284 387
285 } // namespace bluez 388 } // namespace bluez
OLDNEW
« no previous file with comments | « device/bluetooth/dbus/bluetooth_gatt_descriptor_service_provider_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698