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

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

Issue 1956513002: Export Read/WriteValue from the GATT characteristic service provider. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@chrome_api_changes_for_properties
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_characteristic_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_characteristic_service_provider_i mpl.h" 5 #include "device/bluetooth/dbus/bluetooth_gatt_characteristic_service_provider_i mpl.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/logging.h" 10 #include "base/logging.h"
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 DCHECK(bus_); 43 DCHECK(bus_);
44 DCHECK(delegate_); 44 DCHECK(delegate_);
45 DCHECK(!uuid_.empty()); 45 DCHECK(!uuid_.empty());
46 DCHECK(object_path_.IsValid()); 46 DCHECK(object_path_.IsValid());
47 DCHECK(service_path_.IsValid()); 47 DCHECK(service_path_.IsValid());
48 DCHECK(base::StartsWith(object_path_.value(), service_path_.value() + "/", 48 DCHECK(base::StartsWith(object_path_.value(), service_path_.value() + "/",
49 base::CompareCase::SENSITIVE)); 49 base::CompareCase::SENSITIVE));
50 50
51 exported_object_ = bus_->GetExportedObject(object_path_); 51 exported_object_ = bus_->GetExportedObject(object_path_);
52 52
53 // org.freedesktop.DBus.Properties interface:
53 exported_object_->ExportMethod( 54 exported_object_->ExportMethod(
54 dbus::kDBusPropertiesInterface, dbus::kDBusPropertiesGet, 55 dbus::kDBusPropertiesInterface, dbus::kDBusPropertiesGet,
55 base::Bind(&BluetoothGattCharacteristicServiceProviderImpl::Get, 56 base::Bind(&BluetoothGattCharacteristicServiceProviderImpl::Get,
56 weak_ptr_factory_.GetWeakPtr()), 57 weak_ptr_factory_.GetWeakPtr()),
57 base::Bind(&BluetoothGattCharacteristicServiceProviderImpl::OnExported, 58 base::Bind(&BluetoothGattCharacteristicServiceProviderImpl::OnExported,
58 weak_ptr_factory_.GetWeakPtr())); 59 weak_ptr_factory_.GetWeakPtr()));
59
60 exported_object_->ExportMethod( 60 exported_object_->ExportMethod(
61 dbus::kDBusPropertiesInterface, dbus::kDBusPropertiesSet, 61 dbus::kDBusPropertiesInterface, dbus::kDBusPropertiesSet,
62 base::Bind(&BluetoothGattCharacteristicServiceProviderImpl::Set, 62 base::Bind(&BluetoothGattCharacteristicServiceProviderImpl::Set,
63 weak_ptr_factory_.GetWeakPtr()), 63 weak_ptr_factory_.GetWeakPtr()),
64 base::Bind(&BluetoothGattCharacteristicServiceProviderImpl::OnExported, 64 base::Bind(&BluetoothGattCharacteristicServiceProviderImpl::OnExported,
65 weak_ptr_factory_.GetWeakPtr())); 65 weak_ptr_factory_.GetWeakPtr()));
66
67 exported_object_->ExportMethod( 66 exported_object_->ExportMethod(
68 dbus::kDBusPropertiesInterface, dbus::kDBusPropertiesGetAll, 67 dbus::kDBusPropertiesInterface, dbus::kDBusPropertiesGetAll,
69 base::Bind(&BluetoothGattCharacteristicServiceProviderImpl::GetAll, 68 base::Bind(&BluetoothGattCharacteristicServiceProviderImpl::GetAll,
70 weak_ptr_factory_.GetWeakPtr()), 69 weak_ptr_factory_.GetWeakPtr()),
71 base::Bind(&BluetoothGattCharacteristicServiceProviderImpl::OnExported, 70 base::Bind(&BluetoothGattCharacteristicServiceProviderImpl::OnExported,
72 weak_ptr_factory_.GetWeakPtr())); 71 weak_ptr_factory_.GetWeakPtr()));
72
73 // org.bluez.GattCharacteristic1 interface:
74 exported_object_->ExportMethod(
75 bluetooth_gatt_characteristic::kBluetoothGattCharacteristicInterface,
76 bluetooth_gatt_characteristic::kReadValue,
77 base::Bind(&BluetoothGattCharacteristicServiceProviderImpl::ReadValue,
78 weak_ptr_factory_.GetWeakPtr()),
79 base::Bind(&BluetoothGattCharacteristicServiceProviderImpl::OnExported,
80 weak_ptr_factory_.GetWeakPtr()));
81 exported_object_->ExportMethod(
82 bluetooth_gatt_characteristic::kBluetoothGattCharacteristicInterface,
83 bluetooth_gatt_characteristic::kWriteValue,
84 base::Bind(&BluetoothGattCharacteristicServiceProviderImpl::WriteValue,
85 weak_ptr_factory_.GetWeakPtr()),
86 base::Bind(&BluetoothGattCharacteristicServiceProviderImpl::OnExported,
87 weak_ptr_factory_.GetWeakPtr()));
73 } 88 }
74 89
75 BluetoothGattCharacteristicServiceProviderImpl:: 90 BluetoothGattCharacteristicServiceProviderImpl::
76 ~BluetoothGattCharacteristicServiceProviderImpl() { 91 ~BluetoothGattCharacteristicServiceProviderImpl() {
77 VLOG(1) << "Cleaning up Bluetooth GATT characteristic: " 92 VLOG(1) << "Cleaning up Bluetooth GATT characteristic: "
78 << object_path_.value(); 93 << object_path_.value();
79 if (bus_) 94 if (bus_)
80 bus_->UnregisterExportedObject(object_path_); 95 bus_->UnregisterExportedObject(object_path_);
81 } 96 }
82 97
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 // Try to obtain the value from the delegate. We will construct the 317 // Try to obtain the value from the delegate. We will construct the
303 // response in the success callback. 318 // response in the success callback.
304 DCHECK(delegate_); 319 DCHECK(delegate_);
305 delegate_->GetValue( 320 delegate_->GetValue(
306 base::Bind(&BluetoothGattCharacteristicServiceProviderImpl::OnGetAll, 321 base::Bind(&BluetoothGattCharacteristicServiceProviderImpl::OnGetAll,
307 weak_ptr_factory_.GetWeakPtr(), method_call, response_sender), 322 weak_ptr_factory_.GetWeakPtr(), method_call, response_sender),
308 base::Bind(&BluetoothGattCharacteristicServiceProviderImpl::OnFailure, 323 base::Bind(&BluetoothGattCharacteristicServiceProviderImpl::OnFailure,
309 weak_ptr_factory_.GetWeakPtr(), method_call, response_sender)); 324 weak_ptr_factory_.GetWeakPtr(), method_call, response_sender));
310 } 325 }
311 326
327 void BluetoothGattCharacteristicServiceProviderImpl::ReadValue(
328 dbus::MethodCall* method_call,
329 dbus::ExportedObject::ResponseSender response_sender) {
330 VLOG(3) << "BluetoothGattCharacteristicServiceProvider::ReadValue: "
331 << object_path_.value();
332 DCHECK(OnOriginThread());
333 DCHECK(delegate_);
334 delegate_->GetValue(
335 base::Bind(&BluetoothGattCharacteristicServiceProviderImpl::OnReadValue,
336 weak_ptr_factory_.GetWeakPtr(), method_call, response_sender),
337 base::Bind(&BluetoothGattCharacteristicServiceProviderImpl::OnFailure,
338 weak_ptr_factory_.GetWeakPtr(), method_call, response_sender));
339 }
340
341 void BluetoothGattCharacteristicServiceProviderImpl::WriteValue(
342 dbus::MethodCall* method_call,
343 dbus::ExportedObject::ResponseSender response_sender) {
344 VLOG(3) << "BluetoothGattCharacteristicServiceProvider::WriteValue: "
345 << object_path_.value();
346 DCHECK(OnOriginThread());
347
348 dbus::MessageReader reader(method_call);
349 const uint8_t* bytes = NULL;
350 size_t length = 0;
351
352 if (!reader.PopArrayOfBytes(&bytes, &length))
353 VLOG(2) << "Error reading array of bytes in in WriteValue";
354 std::vector<uint8_t> value;
355 if (bytes)
356 value.assign(bytes, bytes + length);
357
358 DCHECK(delegate_);
359 delegate_->SetValue(
360 value,
361 base::Bind(&BluetoothGattCharacteristicServiceProviderImpl::OnWriteValue,
362 weak_ptr_factory_.GetWeakPtr(), method_call, response_sender),
363 base::Bind(&BluetoothGattCharacteristicServiceProviderImpl::OnFailure,
364 weak_ptr_factory_.GetWeakPtr(), method_call, response_sender));
365 }
366
312 void BluetoothGattCharacteristicServiceProviderImpl::OnExported( 367 void BluetoothGattCharacteristicServiceProviderImpl::OnExported(
313 const std::string& interface_name, 368 const std::string& interface_name,
314 const std::string& method_name, 369 const std::string& method_name,
315 bool success) { 370 bool success) {
316 LOG_IF(WARNING, !success) << "Failed to export " << interface_name << "." 371 LOG_IF(WARNING, !success) << "Failed to export " << interface_name << "."
317 << method_name; 372 << method_name;
318 } 373 }
319 374
320 void BluetoothGattCharacteristicServiceProviderImpl::OnGetAll( 375 void BluetoothGattCharacteristicServiceProviderImpl::OnGetAll(
321 dbus::MethodCall* method_call, 376 dbus::MethodCall* method_call,
322 dbus::ExportedObject::ResponseSender response_sender, 377 dbus::ExportedObject::ResponseSender response_sender,
323 const std::vector<uint8_t>& value) { 378 const std::vector<uint8_t>& value) {
324 VLOG(2) << "Characteristic value obtained from delegate. Responding to " 379 VLOG(2) << "Characteristic value obtained from delegate. Responding to "
325 << "GetAll."; 380 << "GetAll.";
326 381
327 std::unique_ptr<dbus::Response> response = 382 std::unique_ptr<dbus::Response> response =
328 dbus::Response::FromMethodCall(method_call); 383 dbus::Response::FromMethodCall(method_call);
329 dbus::MessageWriter writer(response.get()); 384 dbus::MessageWriter writer(response.get());
330 WriteProperties(&writer, &value); 385 WriteProperties(&writer, &value);
331 response_sender.Run(std::move(response)); 386 response_sender.Run(std::move(response));
332 } 387 }
333 388
389 void BluetoothGattCharacteristicServiceProviderImpl::OnReadValue(
390 dbus::MethodCall* method_call,
391 dbus::ExportedObject::ResponseSender response_sender,
392 const std::vector<uint8_t>& value) {
393 VLOG(3) << "Characteristic value obtained from delegate. Responding to "
394 "ReadValue.";
395
396 std::unique_ptr<dbus::Response> response =
397 dbus::Response::FromMethodCall(method_call);
398 dbus::MessageWriter writer(response.get());
399 writer.AppendArrayOfBytes(value.data(), value.size());
400 response_sender.Run(std::move(response));
401 }
402
403 void BluetoothGattCharacteristicServiceProviderImpl::OnWriteValue(
404 dbus::MethodCall* method_call,
405 dbus::ExportedObject::ResponseSender response_sender) {
406 VLOG(3) << "Responding to WriteValue.";
407
408 std::unique_ptr<dbus::Response> response =
409 dbus::Response::FromMethodCall(method_call);
410 response_sender.Run(std::move(response));
411 }
412
334 void BluetoothGattCharacteristicServiceProviderImpl::WriteProperties( 413 void BluetoothGattCharacteristicServiceProviderImpl::WriteProperties(
335 dbus::MessageWriter* writer, 414 dbus::MessageWriter* writer,
336 const std::vector<uint8_t>* value) { 415 const std::vector<uint8_t>* value) {
337 dbus::MessageWriter array_writer(NULL); 416 dbus::MessageWriter array_writer(NULL);
338 dbus::MessageWriter dict_entry_writer(NULL); 417 dbus::MessageWriter dict_entry_writer(NULL);
339 dbus::MessageWriter variant_writer(NULL); 418 dbus::MessageWriter variant_writer(NULL);
340 419
341 writer->OpenArray("{sv}", &array_writer); 420 writer->OpenArray("{sv}", &array_writer);
342 421
343 array_writer.OpenDictEntry(&dict_entry_writer); 422 array_writer.OpenDictEntry(&dict_entry_writer);
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 method_call, kErrorFailed, "Failed to get/set characteristic value."); 478 method_call, kErrorFailed, "Failed to get/set characteristic value.");
400 response_sender.Run(std::move(error_response)); 479 response_sender.Run(std::move(error_response));
401 } 480 }
402 481
403 const dbus::ObjectPath& 482 const dbus::ObjectPath&
404 BluetoothGattCharacteristicServiceProviderImpl::object_path() const { 483 BluetoothGattCharacteristicServiceProviderImpl::object_path() const {
405 return object_path_; 484 return object_path_;
406 } 485 }
407 486
408 } // namespace bluez 487 } // namespace bluez
OLDNEW
« no previous file with comments | « device/bluetooth/dbus/bluetooth_gatt_characteristic_service_provider_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698