Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 Loading... | |
| 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 Loading... | |
| 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( | |
|
xiyuan
2016/05/12 18:33:18
Silly question: Why StartNotify do delegate_->GetV
rkc
2016/05/12 19:51:50
Ugh, this is really stupid of me. I apologize! Thi
| |
| 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_->GetValue( | |
| 385 base::Bind(&BluetoothGattCharacteristicServiceProviderImpl::OnReadValue, | |
| 386 weak_ptr_factory_.GetWeakPtr(), method_call, response_sender), | |
| 387 base::Bind(&BluetoothGattCharacteristicServiceProviderImpl::OnFailure, | |
| 388 weak_ptr_factory_.GetWeakPtr(), method_call, response_sender)); | |
| 389 } | |
| 390 | |
| 391 void BluetoothGattCharacteristicServiceProviderImpl::StopNotify( | |
| 392 dbus::MethodCall* method_call, | |
| 393 dbus::ExportedObject::ResponseSender response_sender) { | |
| 394 VLOG(3) << "BluetoothGattCharacteristicServiceProvider::WriteValue: " | |
|
xiyuan
2016/05/12 18:33:18
nit: update the message, WriteValue -> StopNotify?
rkc
2016/05/12 19:51:50
Done.
| |
| 395 << object_path_.value(); | |
| 396 DCHECK(OnOriginThread()); | |
| 397 | |
| 398 dbus::MessageReader reader(method_call); | |
| 399 const uint8_t* bytes = NULL; | |
| 400 size_t length = 0; | |
| 401 | |
| 402 if (!reader.PopArrayOfBytes(&bytes, &length)) | |
| 403 VLOG(2) << "Error reading array of bytes in in WriteValue"; | |
|
xiyuan
2016/05/12 18:33:18
nit: update the message
rkc
2016/05/12 19:51:50
Done.
| |
| 404 std::vector<uint8_t> value; | |
| 405 if (bytes) | |
| 406 value.assign(bytes, bytes + length); | |
| 407 | |
| 408 DCHECK(delegate_); | |
| 409 delegate_->SetValue( | |
| 410 value, | |
| 411 base::Bind(&BluetoothGattCharacteristicServiceProviderImpl::OnWriteValue, | |
| 412 weak_ptr_factory_.GetWeakPtr(), method_call, response_sender), | |
| 413 base::Bind(&BluetoothGattCharacteristicServiceProviderImpl::OnFailure, | |
| 414 weak_ptr_factory_.GetWeakPtr(), method_call, response_sender)); | |
| 415 } | |
| 416 | |
| 362 void BluetoothGattCharacteristicServiceProviderImpl::OnExported( | 417 void BluetoothGattCharacteristicServiceProviderImpl::OnExported( |
| 363 const std::string& interface_name, | 418 const std::string& interface_name, |
| 364 const std::string& method_name, | 419 const std::string& method_name, |
| 365 bool success) { | 420 bool success) { |
| 366 LOG_IF(WARNING, !success) << "Failed to export " << interface_name << "." | 421 LOG_IF(WARNING, !success) << "Failed to export " << interface_name << "." |
| 367 << method_name; | 422 << method_name; |
| 368 } | 423 } |
| 369 | 424 |
| 370 void BluetoothGattCharacteristicServiceProviderImpl::OnGetAll( | 425 void BluetoothGattCharacteristicServiceProviderImpl::OnGetAll( |
| 371 dbus::MethodCall* method_call, | 426 dbus::MethodCall* method_call, |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 482 method_call, kErrorFailed, "Failed to get/set characteristic value."); | 537 method_call, kErrorFailed, "Failed to get/set characteristic value."); |
| 483 response_sender.Run(std::move(error_response)); | 538 response_sender.Run(std::move(error_response)); |
| 484 } | 539 } |
| 485 | 540 |
| 486 const dbus::ObjectPath& | 541 const dbus::ObjectPath& |
| 487 BluetoothGattCharacteristicServiceProviderImpl::object_path() const { | 542 BluetoothGattCharacteristicServiceProviderImpl::object_path() const { |
| 488 return object_path_; | 543 return object_path_; |
| 489 } | 544 } |
| 490 | 545 |
| 491 } // namespace bluez | 546 } // namespace bluez |
| OLD | NEW |