| Index: device/bluetooth/dbus/bluetooth_gatt_descriptor_service_provider.cc
|
| diff --git a/device/bluetooth/dbus/bluetooth_gatt_descriptor_service_provider.cc b/device/bluetooth/dbus/bluetooth_gatt_descriptor_service_provider.cc
|
| index 239be9ccc133a7015739d2da101c971336b72e32..bd818f4d0157baf533862be16b031a7fb71e9282 100644
|
| --- a/device/bluetooth/dbus/bluetooth_gatt_descriptor_service_provider.cc
|
| +++ b/device/bluetooth/dbus/bluetooth_gatt_descriptor_service_provider.cc
|
| @@ -6,17 +6,14 @@
|
|
|
| #include <stddef.h>
|
|
|
| -#include <memory>
|
| -#include <utility>
|
| -
|
| #include "base/bind.h"
|
| +#include "base/callback.h"
|
| #include "base/logging.h"
|
| -#include "base/macros.h"
|
| +#include "base/memory/ref_counted.h"
|
| #include "base/memory/weak_ptr.h"
|
| #include "base/strings/string_util.h"
|
| #include "base/threading/platform_thread.h"
|
| #include "dbus/exported_object.h"
|
| -#include "dbus/message.h"
|
| #include "device/bluetooth/dbus/bluez_dbus_manager.h"
|
| #include "device/bluetooth/dbus/fake_bluetooth_gatt_descriptor_service_provider.h"
|
| #include "third_party/cros_system_api/dbus/service_constants.h"
|
| @@ -36,14 +33,14 @@ class BluetoothGattDescriptorServiceProviderImpl
|
| BluetoothGattDescriptorServiceProviderImpl(
|
| dbus::Bus* bus,
|
| const dbus::ObjectPath& object_path,
|
| - Delegate* delegate,
|
| + std::unique_ptr<BluetoothGattAttributeValueDelegate> delegate,
|
| const std::string& uuid,
|
| const std::vector<std::string>& permissions,
|
| const dbus::ObjectPath& characteristic_path)
|
| : origin_thread_id_(base::PlatformThread::CurrentId()),
|
| uuid_(uuid),
|
| bus_(bus),
|
| - delegate_(delegate),
|
| + delegate_(std::move(delegate)),
|
| object_path_(object_path),
|
| characteristic_path_(characteristic_path),
|
| weak_ptr_factory_(this) {
|
| @@ -160,7 +157,7 @@ class BluetoothGattDescriptorServiceProviderImpl
|
| // If getting the "Value" property, obtain the value from the delegate.
|
| if (property_name == bluetooth_gatt_descriptor::kValueProperty) {
|
| DCHECK(delegate_);
|
| - delegate_->GetDescriptorValue(
|
| + delegate_->GetValue(
|
| base::Bind(&BluetoothGattDescriptorServiceProviderImpl::OnGet,
|
| weak_ptr_factory_.GetWeakPtr(), method_call,
|
| response_sender),
|
| @@ -262,7 +259,7 @@ class BluetoothGattDescriptorServiceProviderImpl
|
| // Pass the set request onto the delegate.
|
| std::vector<uint8_t> value(bytes, bytes + length);
|
| DCHECK(delegate_);
|
| - delegate_->SetDescriptorValue(
|
| + delegate_->SetValue(
|
| value, base::Bind(&BluetoothGattDescriptorServiceProviderImpl::OnSet,
|
| weak_ptr_factory_.GetWeakPtr(), method_call,
|
| response_sender),
|
| @@ -304,7 +301,7 @@ class BluetoothGattDescriptorServiceProviderImpl
|
| // Try to obtain the value from the delegate. We will construct the
|
| // response in the success callback.
|
| DCHECK(delegate_);
|
| - delegate_->GetDescriptorValue(
|
| + delegate_->GetValue(
|
| base::Bind(&BluetoothGattDescriptorServiceProviderImpl::OnGetAll,
|
| weak_ptr_factory_.GetWeakPtr(), method_call,
|
| response_sender),
|
| @@ -333,11 +330,20 @@ class BluetoothGattDescriptorServiceProviderImpl
|
| std::unique_ptr<dbus::Response> response =
|
| dbus::Response::FromMethodCall(method_call);
|
| dbus::MessageWriter writer(response.get());
|
| + WriteProperties(&writer, &value);
|
| + response_sender.Run(std::move(response));
|
| + }
|
| +
|
| + // Writes the characteristics's properties into the provided writer. If
|
| + // value is not null, it is written also, otherwise no value property is
|
| + // written.
|
| + void WriteProperties(dbus::MessageWriter* writer,
|
| + const std::vector<uint8_t>* value) override {
|
| dbus::MessageWriter array_writer(NULL);
|
| dbus::MessageWriter dict_entry_writer(NULL);
|
| dbus::MessageWriter variant_writer(NULL);
|
|
|
| - writer.OpenArray("{sv}", &array_writer);
|
| + writer->OpenArray("{sv}", &array_writer);
|
|
|
| array_writer.OpenDictEntry(&dict_entry_writer);
|
| dict_entry_writer.AppendString(bluetooth_gatt_descriptor::kUUIDProperty);
|
| @@ -350,18 +356,17 @@ class BluetoothGattDescriptorServiceProviderImpl
|
| dict_entry_writer.AppendVariantOfObjectPath(characteristic_path_);
|
| array_writer.CloseContainer(&dict_entry_writer);
|
|
|
| - array_writer.OpenDictEntry(&dict_entry_writer);
|
| - dict_entry_writer.AppendString(bluetooth_gatt_descriptor::kValueProperty);
|
| - dict_entry_writer.OpenVariant("ay", &variant_writer);
|
| - variant_writer.AppendArrayOfBytes(value.data(), value.size());
|
| - dict_entry_writer.CloseContainer(&variant_writer);
|
| - array_writer.CloseContainer(&dict_entry_writer);
|
| + if (value) {
|
| + array_writer.OpenDictEntry(&dict_entry_writer);
|
| + dict_entry_writer.AppendString(bluetooth_gatt_descriptor::kValueProperty);
|
| + dict_entry_writer.OpenVariant("ay", &variant_writer);
|
| + variant_writer.AppendArrayOfBytes(value->data(), value->size());
|
| + dict_entry_writer.CloseContainer(&variant_writer);
|
| + array_writer.CloseContainer(&dict_entry_writer);
|
| + }
|
|
|
| // TODO(armansito): Process "Permissions" property.
|
| -
|
| - writer.CloseContainer(&array_writer);
|
| -
|
| - response_sender.Run(std::move(response));
|
| + writer->CloseContainer(&array_writer);
|
| }
|
|
|
| // Called by the Delegate in response to a successful method call to get the
|
| @@ -401,6 +406,8 @@ class BluetoothGattDescriptorServiceProviderImpl
|
| response_sender.Run(std::move(error_response));
|
| }
|
|
|
| + const dbus::ObjectPath& object_path() const override { return object_path_; }
|
| +
|
| // Origin thread (i.e. the UI thread in production).
|
| base::PlatformThreadId origin_thread_id_;
|
|
|
| @@ -414,7 +421,7 @@ class BluetoothGattDescriptorServiceProviderImpl
|
| // Incoming methods to get and set the "Value" property are passed on to the
|
| // delegate and callbacks passed to generate a reply. |delegate_| is generally
|
| // the object that owns this one and must outlive it.
|
| - Delegate* delegate_;
|
| + std::unique_ptr<BluetoothGattAttributeValueDelegate> delegate_;
|
|
|
| // D-Bus object path of object we are exporting, kept so we can unregister
|
| // again in our destructor.
|
| @@ -448,16 +455,17 @@ BluetoothGattDescriptorServiceProvider*
|
| BluetoothGattDescriptorServiceProvider::Create(
|
| dbus::Bus* bus,
|
| const dbus::ObjectPath& object_path,
|
| - Delegate* delegate,
|
| + std::unique_ptr<BluetoothGattAttributeValueDelegate> delegate,
|
| const std::string& uuid,
|
| const std::vector<std::string>& permissions,
|
| const dbus::ObjectPath& characteristic_path) {
|
| if (!bluez::BluezDBusManager::Get()->IsUsingFakes()) {
|
| return new BluetoothGattDescriptorServiceProviderImpl(
|
| - bus, object_path, delegate, uuid, permissions, characteristic_path);
|
| + bus, object_path, std::move(delegate), uuid, permissions,
|
| + characteristic_path);
|
| }
|
| return new FakeBluetoothGattDescriptorServiceProvider(
|
| - object_path, delegate, uuid, permissions, characteristic_path);
|
| + object_path, std::move(delegate), uuid, permissions, characteristic_path);
|
| }
|
|
|
| } // namespace bluez
|
|
|