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

Unified Diff: chromeos/dbus/bluetooth_gatt_descriptor_client.cc

Issue 309623002: device/bluetooth: Update GATT descriptor value D-Bus bindings. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed clang error Created 6 years, 6 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: chromeos/dbus/bluetooth_gatt_descriptor_client.cc
diff --git a/chromeos/dbus/bluetooth_gatt_descriptor_client.cc b/chromeos/dbus/bluetooth_gatt_descriptor_client.cc
index 9ec73e7315ad22a16ee890cf0682f8c2f4056c26..850b228e756ca9efbaf6457de10898784041f5b4 100644
--- a/chromeos/dbus/bluetooth_gatt_descriptor_client.cc
+++ b/chromeos/dbus/bluetooth_gatt_descriptor_client.cc
@@ -13,6 +13,13 @@
namespace chromeos {
+// static
+const char BluetoothGattDescriptorClient::kNoResponseError[] =
+ "org.chromium.Error.NoResponse";
+// static
+const char BluetoothGattDescriptorClient::kUnknownDescriptorError[] =
+ "org.chromium.Error.UnknownDescriptor";
+
BluetoothGattDescriptorClient::Properties::Properties(
dbus::ObjectProxy* object_proxy,
const std::string& interface_name,
@@ -21,7 +28,6 @@ BluetoothGattDescriptorClient::Properties::Properties(
RegisterProperty(bluetooth_gatt_descriptor::kUUIDProperty, &uuid);
RegisterProperty(bluetooth_gatt_descriptor::kCharacteristicProperty,
&characteristic);
- RegisterProperty(bluetooth_gatt_descriptor::kValueProperty, &value);
}
BluetoothGattDescriptorClient::Properties::~Properties() {
@@ -73,6 +79,61 @@ class BluetoothGattDescriptorClientImpl
bluetooth_gatt_descriptor::kBluetoothGattDescriptorInterface));
}
+ // BluetoothGattDescriptorClientImpl override.
+ virtual void ReadValue(const dbus::ObjectPath& object_path,
+ const ValueCallback& callback,
+ const ErrorCallback& error_callback) OVERRIDE {
+ dbus::ObjectProxy* object_proxy =
+ object_manager_->GetObjectProxy(object_path);
+ if (!object_proxy) {
+ error_callback.Run(kUnknownDescriptorError, "");
+ return;
+ }
+
+ dbus::MethodCall method_call(
+ bluetooth_gatt_descriptor::kBluetoothGattDescriptorInterface,
+ bluetooth_gatt_descriptor::kReadValue);
+
+ object_proxy->CallMethodWithErrorCallback(
+ &method_call,
+ dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
+ base::Bind(&BluetoothGattDescriptorClientImpl::OnValueSuccess,
+ weak_ptr_factory_.GetWeakPtr(),
+ callback),
+ base::Bind(&BluetoothGattDescriptorClientImpl::OnError,
+ weak_ptr_factory_.GetWeakPtr(),
+ error_callback));
+ }
+
+ // BluetoothGattDescriptorClientImpl override.
+ virtual void WriteValue(const dbus::ObjectPath& object_path,
+ const std::vector<uint8>& value,
+ const base::Closure& callback,
+ const ErrorCallback& error_callback) OVERRIDE {
+ dbus::ObjectProxy* object_proxy =
+ object_manager_->GetObjectProxy(object_path);
+ if (!object_proxy) {
+ error_callback.Run(kUnknownDescriptorError, "");
+ return;
+ }
+
+ dbus::MethodCall method_call(
+ bluetooth_gatt_descriptor::kBluetoothGattDescriptorInterface,
+ bluetooth_gatt_descriptor::kWriteValue);
+ dbus::MessageWriter writer(&method_call);
+ writer.AppendArrayOfBytes(value.data(), value.size());
+
+ object_proxy->CallMethodWithErrorCallback(
+ &method_call,
+ dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
+ base::Bind(&BluetoothGattDescriptorClientImpl::OnSuccess,
+ weak_ptr_factory_.GetWeakPtr(),
+ callback),
+ base::Bind(&BluetoothGattDescriptorClientImpl::OnError,
+ weak_ptr_factory_.GetWeakPtr(),
+ error_callback));
+ }
+
// dbus::ObjectManager::Interface override.
virtual dbus::PropertySet* CreateProperties(
dbus::ObjectProxy *object_proxy,
@@ -128,6 +189,49 @@ class BluetoothGattDescriptorClientImpl
property_name));
}
+ // Called when a response for a successful method call is received.
+ void OnSuccess(const base::Closure& callback, dbus::Response* response) {
+ DCHECK(response);
+ callback.Run();
+ }
+
+ // Called when a descriptor value response for a successful method call is
+ // received.
+ void OnValueSuccess(const ValueCallback& callback, dbus::Response* response) {
+ DCHECK(response);
+ dbus::MessageReader reader(response);
+
+ const uint8* bytes = NULL;
+ size_t length = 0;
+
+ if (!reader.PopArrayOfBytes(&bytes, &length))
+ VLOG(2) << "Error reading array of bytes in ValueCallback";
+
+ std::vector<uint8> value;
+
+ if (bytes)
+ value.assign(bytes, bytes + length);
+
+ callback.Run(value);
+ }
+
+ // Called when a response for a failed method call is received.
+ void OnError(const ErrorCallback& error_callback,
+ dbus::ErrorResponse* response) {
+ // Error response has optional error message argument.
+ std::string error_name;
+ std::string error_message;
+ if (response) {
+ dbus::MessageReader reader(response);
+ error_name = response->GetErrorName();
+ reader.PopString(&error_message);
+ } else {
+ error_name = kNoResponseError;
+ error_message = "";
+ }
+ error_callback.Run(error_name, error_message);
+ }
+
dbus::ObjectManager* object_manager_;
// List of observers interested in event notifications from us.
« no previous file with comments | « chromeos/dbus/bluetooth_gatt_descriptor_client.h ('k') | chromeos/dbus/fake_bluetooth_gatt_descriptor_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698