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

Unified Diff: device/bluetooth/dbus/bluetooth_gatt_descriptor_service_provider.cc

Issue 1920693002: Complete //device/bt implementation for hosting local GATT attributes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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 side-by-side diff with in-line comments
Download patch
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..a0bce309daa129200ac0720de88b8a649eb73b38 100644
--- a/device/bluetooth/dbus/bluetooth_gatt_descriptor_service_provider.cc
+++ b/device/bluetooth/dbus/bluetooth_gatt_descriptor_service_provider.cc
@@ -5,18 +5,16 @@
#include "device/bluetooth/dbus/bluetooth_gatt_descriptor_service_provider.h"
#include <stddef.h>
-
-#include <memory>
-#include <utility>
+#include <iostream>
#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,7 +34,7 @@ class BluetoothGattDescriptorServiceProviderImpl
BluetoothGattDescriptorServiceProviderImpl(
dbus::Bus* bus,
const dbus::ObjectPath& object_path,
- Delegate* delegate,
+ BluetoothGattServiceBlueZ::AttributeValueDelegate* delegate,
const std::string& uuid,
const std::vector<std::string>& permissions,
const dbus::ObjectPath& characteristic_path)
@@ -160,7 +158,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 +260,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 +302,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 +331,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 +357,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 +407,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 +422,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_;
+ BluetoothGattServiceBlueZ::AttributeValueDelegate* delegate_;
// D-Bus object path of object we are exporting, kept so we can unregister
// again in our destructor.
@@ -448,7 +456,7 @@ BluetoothGattDescriptorServiceProvider*
BluetoothGattDescriptorServiceProvider::Create(
dbus::Bus* bus,
const dbus::ObjectPath& object_path,
- Delegate* delegate,
+ BluetoothGattServiceBlueZ::AttributeValueDelegate* delegate,
const std::string& uuid,
const std::vector<std::string>& permissions,
const dbus::ObjectPath& characteristic_path) {

Powered by Google App Engine
This is Rietveld 408576698