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

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

Issue 1974633002: Implement DBus changes needed for notifications. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
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
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 <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"
(...skipping 22 matching lines...) Expand all
33 : origin_thread_id_(base::PlatformThread::CurrentId()), 33 : origin_thread_id_(base::PlatformThread::CurrentId()),
34 uuid_(uuid), 34 uuid_(uuid),
35 flags_(flags), 35 flags_(flags),
36 bus_(bus), 36 bus_(bus),
37 delegate_(std::move(delegate)), 37 delegate_(std::move(delegate)),
38 object_path_(object_path), 38 object_path_(object_path),
39 service_path_(service_path), 39 service_path_(service_path),
40 weak_ptr_factory_(this) { 40 weak_ptr_factory_(this) {
41 VLOG(1) << "Created Bluetooth GATT characteristic: " << object_path.value() 41 VLOG(1) << "Created Bluetooth GATT characteristic: " << object_path.value()
42 << " UUID: " << uuid; 42 << " UUID: " << uuid;
43
44 // If we have a null bus, this means that this is being initialized for a
45 // test, hence we shouldn't do any other setup.
46 if (!bus_) 43 if (!bus_)
47 return; 44 return;
48 45
49 DCHECK(delegate_); 46 DCHECK(delegate_);
50 DCHECK(!uuid_.empty()); 47 DCHECK(!uuid_.empty());
51 DCHECK(object_path_.IsValid()); 48 DCHECK(object_path_.IsValid());
52 DCHECK(service_path_.IsValid()); 49 DCHECK(service_path_.IsValid());
53 DCHECK(base::StartsWith(object_path_.value(), service_path_.value() + "/", 50 DCHECK(base::StartsWith(object_path_.value(), service_path_.value() + "/",
54 base::CompareCase::SENSITIVE)); 51 base::CompareCase::SENSITIVE));
55 52
(...skipping 27 matching lines...) Expand all
83 weak_ptr_factory_.GetWeakPtr()), 80 weak_ptr_factory_.GetWeakPtr()),
84 base::Bind(&BluetoothGattCharacteristicServiceProviderImpl::OnExported, 81 base::Bind(&BluetoothGattCharacteristicServiceProviderImpl::OnExported,
85 weak_ptr_factory_.GetWeakPtr())); 82 weak_ptr_factory_.GetWeakPtr()));
86 exported_object_->ExportMethod( 83 exported_object_->ExportMethod(
87 bluetooth_gatt_characteristic::kBluetoothGattCharacteristicInterface, 84 bluetooth_gatt_characteristic::kBluetoothGattCharacteristicInterface,
88 bluetooth_gatt_characteristic::kWriteValue, 85 bluetooth_gatt_characteristic::kWriteValue,
89 base::Bind(&BluetoothGattCharacteristicServiceProviderImpl::WriteValue, 86 base::Bind(&BluetoothGattCharacteristicServiceProviderImpl::WriteValue,
90 weak_ptr_factory_.GetWeakPtr()), 87 weak_ptr_factory_.GetWeakPtr()),
91 base::Bind(&BluetoothGattCharacteristicServiceProviderImpl::OnExported, 88 base::Bind(&BluetoothGattCharacteristicServiceProviderImpl::OnExported,
92 weak_ptr_factory_.GetWeakPtr())); 89 weak_ptr_factory_.GetWeakPtr()));
90 exported_object_->ExportMethod(
91 bluetooth_gatt_characteristic::kBluetoothGattCharacteristicInterface,
92 bluetooth_gatt_characteristic::kStartNotify,
93 base::Bind(&BluetoothGattCharacteristicServiceProviderImpl::StartNotify,
94 weak_ptr_factory_.GetWeakPtr()),
95 base::Bind(&BluetoothGattCharacteristicServiceProviderImpl::OnExported,
96 weak_ptr_factory_.GetWeakPtr()));
97 exported_object_->ExportMethod(
98 bluetooth_gatt_characteristic::kBluetoothGattCharacteristicInterface,
99 bluetooth_gatt_characteristic::kStopNotify,
100 base::Bind(&BluetoothGattCharacteristicServiceProviderImpl::StopNotify,
101 weak_ptr_factory_.GetWeakPtr()),
102 base::Bind(&BluetoothGattCharacteristicServiceProviderImpl::OnExported,
103 weak_ptr_factory_.GetWeakPtr()));
93 } 104 }
94 105
95 BluetoothGattCharacteristicServiceProviderImpl:: 106 BluetoothGattCharacteristicServiceProviderImpl::
96 ~BluetoothGattCharacteristicServiceProviderImpl() { 107 ~BluetoothGattCharacteristicServiceProviderImpl() {
97 VLOG(1) << "Cleaning up Bluetooth GATT characteristic: " 108 VLOG(1) << "Cleaning up Bluetooth GATT characteristic: "
98 << object_path_.value(); 109 << object_path_.value();
99 if (bus_) 110 if (bus_)
100 bus_->UnregisterExportedObject(object_path_); 111 bus_->UnregisterExportedObject(object_path_);
101 } 112 }
102 113
103 void BluetoothGattCharacteristicServiceProviderImpl::SendValueChanged( 114 void BluetoothGattCharacteristicServiceProviderImpl::SendValueChanged(
104 const std::vector<uint8_t>& value) { 115 const std::vector<uint8_t>& value) {
116 // Running a test, don't actually try to write to use DBus.
117 if (!bus_)
118 return;
119
105 VLOG(2) << "Emitting a PropertiesChanged signal for characteristic value."; 120 VLOG(2) << "Emitting a PropertiesChanged signal for characteristic value.";
106 dbus::Signal signal(dbus::kDBusPropertiesInterface, 121 dbus::Signal signal(dbus::kDBusPropertiesInterface,
107 dbus::kDBusPropertiesChangedSignal); 122 dbus::kDBusPropertiesChangedSignal);
108 dbus::MessageWriter writer(&signal); 123 dbus::MessageWriter writer(&signal);
109 dbus::MessageWriter array_writer(NULL); 124 dbus::MessageWriter array_writer(NULL);
110 dbus::MessageWriter dict_entry_writer(NULL); 125 dbus::MessageWriter dict_entry_writer(NULL);
111 dbus::MessageWriter variant_writer(NULL); 126 dbus::MessageWriter variant_writer(NULL);
112 127
113 // interface_name 128 // interface_name
114 writer.AppendString( 129 writer.AppendString(
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
352 367
353 DCHECK(delegate_); 368 DCHECK(delegate_);
354 delegate_->SetValue( 369 delegate_->SetValue(
355 value, 370 value,
356 base::Bind(&BluetoothGattCharacteristicServiceProviderImpl::OnWriteValue, 371 base::Bind(&BluetoothGattCharacteristicServiceProviderImpl::OnWriteValue,
357 weak_ptr_factory_.GetWeakPtr(), method_call, response_sender), 372 weak_ptr_factory_.GetWeakPtr(), method_call, response_sender),
358 base::Bind(&BluetoothGattCharacteristicServiceProviderImpl::OnFailure, 373 base::Bind(&BluetoothGattCharacteristicServiceProviderImpl::OnFailure,
359 weak_ptr_factory_.GetWeakPtr(), method_call, response_sender)); 374 weak_ptr_factory_.GetWeakPtr(), method_call, response_sender));
360 } 375 }
361 376
377 void BluetoothGattCharacteristicServiceProviderImpl::StartNotify(
378 dbus::MethodCall* method_call,
379 dbus::ExportedObject::ResponseSender response_sender) {
380 VLOG(3) << "BluetoothGattCharacteristicServiceProvider::StartNotify: "
381 << object_path_.value();
382 DCHECK(OnOriginThread());
383 DCHECK(delegate_);
384 delegate_->StartNotifications();
385 }
386
387 void BluetoothGattCharacteristicServiceProviderImpl::StopNotify(
388 dbus::MethodCall* method_call,
389 dbus::ExportedObject::ResponseSender response_sender) {
390 VLOG(3) << "BluetoothGattCharacteristicServiceProvider::StopNotify: "
391 << object_path_.value();
392 DCHECK(OnOriginThread());
393
394 DCHECK(delegate_);
395 delegate_->StopNotifications();
396 }
397
362 void BluetoothGattCharacteristicServiceProviderImpl::OnExported( 398 void BluetoothGattCharacteristicServiceProviderImpl::OnExported(
363 const std::string& interface_name, 399 const std::string& interface_name,
364 const std::string& method_name, 400 const std::string& method_name,
365 bool success) { 401 bool success) {
366 LOG_IF(WARNING, !success) << "Failed to export " << interface_name << "." 402 LOG_IF(WARNING, !success) << "Failed to export " << interface_name << "."
367 << method_name; 403 << method_name;
368 } 404 }
369 405
370 void BluetoothGattCharacteristicServiceProviderImpl::OnGetAll( 406 void BluetoothGattCharacteristicServiceProviderImpl::OnGetAll(
371 dbus::MethodCall* method_call, 407 dbus::MethodCall* method_call,
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
482 method_call, kErrorFailed, "Failed to get/set characteristic value."); 518 method_call, kErrorFailed, "Failed to get/set characteristic value.");
483 response_sender.Run(std::move(error_response)); 519 response_sender.Run(std::move(error_response));
484 } 520 }
485 521
486 const dbus::ObjectPath& 522 const dbus::ObjectPath&
487 BluetoothGattCharacteristicServiceProviderImpl::object_path() const { 523 BluetoothGattCharacteristicServiceProviderImpl::object_path() const {
488 return object_path_; 524 return object_path_;
489 } 525 }
490 526
491 } // namespace bluez 527 } // namespace bluez
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698