diff options
author | armansito@chromium.org <armansito@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-06-08 02:09:56 +0000 |
---|---|---|
committer | armansito@chromium.org <armansito@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-06-08 02:09:56 +0000 |
commit | 0f647935a95f078fa796035eb7c737b56d001759 (patch) | |
tree | 47fea216485f869035b51fa336eb413e480f6427 | |
parent | c9427af61756f046a118d37b7c801c987bf7687c (diff) | |
download | chromium_src-0f647935a95f078fa796035eb7c737b56d001759.zip chromium_src-0f647935a95f078fa796035eb7c737b56d001759.tar.gz chromium_src-0f647935a95f078fa796035eb7c737b56d001759.tar.bz2 |
device/bluetooth: Update GATT descriptor value D-Bus bindings.
This CL updates the Chrome D-Bus bindings and modifies the device/bluetooth
GATT Chrome OS code to use the new bindings defined in crbug.com/378182 for
descriptor value reads and writes.
BUG=378182
TEST=device_unittests; manual tests using custom bluetoothd
Review URL: https://codereview.chromium.org/309623002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@275718 0039d316-1c4b-4281-b951-d872f2087c98
10 files changed, 255 insertions, 123 deletions
diff --git a/chromeos/dbus/bluetooth_gatt_descriptor_client.cc b/chromeos/dbus/bluetooth_gatt_descriptor_client.cc index 9ec73e7..850b228 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. diff --git a/chromeos/dbus/bluetooth_gatt_descriptor_client.h b/chromeos/dbus/bluetooth_gatt_descriptor_client.h index 3a7a26f..c3f24ac 100644 --- a/chromeos/dbus/bluetooth_gatt_descriptor_client.h +++ b/chromeos/dbus/bluetooth_gatt_descriptor_client.h @@ -8,6 +8,7 @@ #include <string> #include "base/basictypes.h" +#include "base/callback.h" #include "chromeos/chromeos_export.h" #include "chromeos/dbus/dbus_client.h" #include "dbus/object_path.h" @@ -28,11 +29,6 @@ class CHROMEOS_EXPORT BluetoothGattDescriptorClient : public DBusClient { // [read-only] dbus::Property<dbus::ObjectPath> characteristic; - // Raw characteristic descriptor value read from the remote Bluetooth - // device. Setting the value sends a write request to the remote device. - // [read-write] - dbus::Property<std::vector<uint8> > value; - Properties(dbus::ObjectProxy* object_proxy, const std::string& interface_name, const PropertyChangedCallback& callback); @@ -60,6 +56,11 @@ class CHROMEOS_EXPORT BluetoothGattDescriptorClient : public DBusClient { const std::string& property_name) {} }; + // Callbacks used to report the result of asynchronous methods. + typedef base::Callback<void(const std::string& error_name, + const std::string& error_message)> ErrorCallback; + typedef base::Callback<void(const std::vector<uint8>& value)> ValueCallback; + virtual ~BluetoothGattDescriptorClient(); // Adds and removes observers for events on all remote GATT descriptors. Check @@ -75,9 +76,28 @@ class CHROMEOS_EXPORT BluetoothGattDescriptorClient : public DBusClient { // |object_path|. Values should be copied if needed. virtual Properties* GetProperties(const dbus::ObjectPath& object_path) = 0; + // Issues a request to read the value of GATT descriptor with object path + // |object_path| and returns the value in |callback| on success. On error, + // invokes |error_callback|. + virtual void ReadValue(const dbus::ObjectPath& object_path, + const ValueCallback& callback, + const ErrorCallback& error_callback) = 0; + + // Issues a request to write the value of GATT descriptor with object path + // |object_path| with value |value|. Invokes |callback| on success and + // |error_callback| on failure. + virtual void WriteValue(const dbus::ObjectPath& object_path, + const std::vector<uint8>& value, + const base::Closure& callback, + const ErrorCallback& error_callback) = 0; + // Creates the instance. static BluetoothGattDescriptorClient* Create(); + // Constants used to indicate exceptional error conditions. + static const char kNoResponseError[]; + static const char kUnknownDescriptorError[]; + protected: BluetoothGattDescriptorClient(); diff --git a/chromeos/dbus/fake_bluetooth_gatt_descriptor_client.cc b/chromeos/dbus/fake_bluetooth_gatt_descriptor_client.cc index 4bb5255..a39a160 100644 --- a/chromeos/dbus/fake_bluetooth_gatt_descriptor_client.cc +++ b/chromeos/dbus/fake_bluetooth_gatt_descriptor_client.cc @@ -42,19 +42,13 @@ void FakeBluetoothGattDescriptorClient::Properties::Set( dbus::PropertyBase* property, dbus::PropertySet::SetCallback callback) { VLOG(1) << "Set " << property->name(); - if (property->name() != value.name()) { - callback.Run(false); - return; - } + callback.Run(false); +} - // TODO(armansito): Setting the "Value" property should be allowed based - // on permissions. - if (uuid.value() != kClientCharacteristicConfigurationUUID) { - callback.Run(false); - return; - } - callback.Run(true); - property->ReplaceValueWithSetValue(); +FakeBluetoothGattDescriptorClient::DescriptorData::DescriptorData() { +} + +FakeBluetoothGattDescriptorClient::DescriptorData::~DescriptorData() { } FakeBluetoothGattDescriptorClient::FakeBluetoothGattDescriptorClient() @@ -91,7 +85,37 @@ FakeBluetoothGattDescriptorClient::GetProperties( PropertiesMap::const_iterator iter = properties_.find(object_path); if (iter == properties_.end()) return NULL; - return iter->second; + return iter->second->properties.get(); +} + +void FakeBluetoothGattDescriptorClient::ReadValue( + const dbus::ObjectPath& object_path, + const ValueCallback& callback, + const ErrorCallback& error_callback) { + PropertiesMap::iterator iter = properties_.find(object_path); + if (iter == properties_.end()) { + error_callback.Run(kUnknownDescriptorError, ""); + return; + } + + callback.Run(iter->second->value); +} + +void FakeBluetoothGattDescriptorClient::WriteValue( + const dbus::ObjectPath& object_path, + const std::vector<uint8>& value, + const base::Closure& callback, + const ErrorCallback& error_callback) { + if (properties_.find(object_path) == properties_.end()) { + error_callback.Run(kUnknownDescriptorError, ""); + return; + } + + // Since the only fake descriptor is "Client Characteristic Configuration" + // and BlueZ doesn't allow writing to it, return failure. + error_callback.Run("org.bluez.Error.Failed", + "Writing to the Client Characteristic Configuration " + "descriptor not allowed"); } dbus::ObjectPath FakeBluetoothGattDescriptorClient::ExposeDescriptor( @@ -118,14 +142,16 @@ dbus::ObjectPath FakeBluetoothGattDescriptorClient::ExposeDescriptor( &FakeBluetoothGattDescriptorClient::OnPropertyChanged, weak_ptr_factory_.GetWeakPtr(), object_path)); - properties_[object_path] = properties; properties->uuid.ReplaceValue(uuid); properties->characteristic.ReplaceValue(characteristic_path); - std::vector<uint8> value; - value.push_back(0); // Notifications/Indications disabled. - value.push_back(0); - properties->value.ReplaceValue(value); + DescriptorData* data = new DescriptorData(); + data->properties.reset(properties); + + data->value.push_back(1); // Notifications enabled. + data->value.push_back(0); + + properties_[object_path] = data; NotifyDescriptorAdded(object_path); @@ -154,9 +180,6 @@ void FakeBluetoothGattDescriptorClient::OnPropertyChanged( FOR_EACH_OBSERVER(BluetoothGattDescriptorClient::Observer, observers_, GattDescriptorPropertyChanged(object_path, property_name)); - - // TODO(armansito): Implement CCC behavior (enable/disable notifications - // or indications characteristics). } void FakeBluetoothGattDescriptorClient::NotifyDescriptorAdded( diff --git a/chromeos/dbus/fake_bluetooth_gatt_descriptor_client.h b/chromeos/dbus/fake_bluetooth_gatt_descriptor_client.h index 3676983..ce3f2d4 100644 --- a/chromeos/dbus/fake_bluetooth_gatt_descriptor_client.h +++ b/chromeos/dbus/fake_bluetooth_gatt_descriptor_client.h @@ -46,6 +46,13 @@ class CHROMEOS_EXPORT FakeBluetoothGattDescriptorClient virtual std::vector<dbus::ObjectPath> GetDescriptors() OVERRIDE; virtual Properties* GetProperties(const dbus::ObjectPath& object_path) OVERRIDE; + virtual void ReadValue(const dbus::ObjectPath& object_path, + const ValueCallback& callback, + const ErrorCallback& error_callback) OVERRIDE; + virtual void WriteValue(const dbus::ObjectPath& object_path, + const std::vector<uint8>& value, + const base::Closure& callback, + const ErrorCallback& error_callback) OVERRIDE; // Makes the descriptor with the UUID |uuid| visible under the characteristic // with object path |characteristic_path|. Descriptor object paths are @@ -71,7 +78,14 @@ class CHROMEOS_EXPORT FakeBluetoothGattDescriptorClient void NotifyDescriptorRemoved(const dbus::ObjectPath& object_path); // Mapping from object paths to Properties structures. - typedef std::map<dbus::ObjectPath, Properties*> PropertiesMap; + struct DescriptorData { + DescriptorData(); + ~DescriptorData(); + + scoped_ptr<Properties> properties; + std::vector<uint8> value; + }; + typedef std::map<dbus::ObjectPath, DescriptorData*> PropertiesMap; PropertiesMap properties_; // List of observers interested in event notifications from us. diff --git a/device/bluetooth/bluetooth_gatt_chromeos_unittest.cc b/device/bluetooth/bluetooth_gatt_chromeos_unittest.cc index 814b163..235cc72 100644 --- a/device/bluetooth/bluetooth_gatt_chromeos_unittest.cc +++ b/device/bluetooth/bluetooth_gatt_chromeos_unittest.cc @@ -944,15 +944,19 @@ TEST_F(BluetoothGattChromeOSTest, GattDescriptorValue) { descriptor->GetUUID()); std::vector<uint8> desc_value; + desc_value.push_back(1); desc_value.push_back(0); - desc_value.push_back(0); - EXPECT_TRUE(ValuesEqual(desc_value, descriptor->GetValue())); + + /* The cached value will be empty until the first read request */ + EXPECT_FALSE(ValuesEqual(desc_value, descriptor->GetValue())); + EXPECT_TRUE(descriptor->GetValue().empty()); EXPECT_EQ(0, success_callback_count_); EXPECT_EQ(0, error_callback_count_); EXPECT_TRUE(last_read_value_.empty()); - // Read value. + // Read value. GattDescriptorValueChanged event will be sent after a + // successful read. descriptor->ReadRemoteDescriptor( base::Bind(&BluetoothGattChromeOSTest::ValueCallback, base::Unretained(this)), @@ -961,10 +965,11 @@ TEST_F(BluetoothGattChromeOSTest, GattDescriptorValue) { EXPECT_EQ(1, success_callback_count_); EXPECT_EQ(0, error_callback_count_); EXPECT_TRUE(ValuesEqual(last_read_value_, descriptor->GetValue())); + EXPECT_TRUE(ValuesEqual(desc_value, descriptor->GetValue())); EXPECT_EQ(4, service_observer.gatt_service_changed_count_); - EXPECT_EQ(0, service_observer.gatt_descriptor_value_changed_count_); + EXPECT_EQ(1, service_observer.gatt_descriptor_value_changed_count_); - // Write value. + // Write value. Writes to this descriptor will fail. desc_value[0] = 0x03; descriptor->WriteRemoteDescriptor( desc_value, @@ -972,10 +977,10 @@ TEST_F(BluetoothGattChromeOSTest, GattDescriptorValue) { base::Unretained(this)), base::Bind(&BluetoothGattChromeOSTest::ErrorCallback, base::Unretained(this))); - EXPECT_EQ(2, success_callback_count_); - EXPECT_EQ(0, error_callback_count_); - EXPECT_FALSE(ValuesEqual(last_read_value_, descriptor->GetValue())); - EXPECT_TRUE(ValuesEqual(desc_value, descriptor->GetValue())); + EXPECT_EQ(1, success_callback_count_); + EXPECT_EQ(1, error_callback_count_); + EXPECT_TRUE(ValuesEqual(last_read_value_, descriptor->GetValue())); + EXPECT_FALSE(ValuesEqual(desc_value, descriptor->GetValue())); EXPECT_EQ(4, service_observer.gatt_service_changed_count_); EXPECT_EQ(1, service_observer.gatt_descriptor_value_changed_count_); @@ -985,12 +990,12 @@ TEST_F(BluetoothGattChromeOSTest, GattDescriptorValue) { base::Unretained(this)), base::Bind(&BluetoothGattChromeOSTest::ErrorCallback, base::Unretained(this))); - EXPECT_EQ(3, success_callback_count_); - EXPECT_EQ(0, error_callback_count_); + EXPECT_EQ(2, success_callback_count_); + EXPECT_EQ(1, error_callback_count_); EXPECT_TRUE(ValuesEqual(last_read_value_, descriptor->GetValue())); - EXPECT_TRUE(ValuesEqual(desc_value, descriptor->GetValue())); + EXPECT_FALSE(ValuesEqual(desc_value, descriptor->GetValue())); EXPECT_EQ(4, service_observer.gatt_service_changed_count_); - EXPECT_EQ(1, service_observer.gatt_descriptor_value_changed_count_); + EXPECT_EQ(2, service_observer.gatt_descriptor_value_changed_count_); } } // namespace chromeos diff --git a/device/bluetooth/bluetooth_remote_gatt_characteristic_chromeos.cc b/device/bluetooth/bluetooth_remote_gatt_characteristic_chromeos.cc index 0a8a225..e3de615 100644 --- a/device/bluetooth/bluetooth_remote_gatt_characteristic_chromeos.cc +++ b/device/bluetooth/bluetooth_remote_gatt_characteristic_chromeos.cc @@ -268,30 +268,6 @@ void BluetoothRemoteGattCharacteristicChromeOS::GattDescriptorRemoved( service_->NotifyServiceChanged(); } -void BluetoothRemoteGattCharacteristicChromeOS::GattDescriptorPropertyChanged( - const dbus::ObjectPath& object_path, - const std::string& property_name) { - DescriptorMap::const_iterator iter = descriptors_.find(object_path); - if (iter == descriptors_.end()) - return; - - // Ignore all property changes except for "Value". - BluetoothGattDescriptorClient::Properties* properties = - DBusThreadManager::Get()->GetBluetoothGattDescriptorClient()-> - GetProperties(object_path); - DCHECK(properties); - if (property_name != properties->value.name()) - return; - - VLOG(1) << "GATT descriptor property changed: " << object_path.value() - << ", property: " << property_name; - - DCHECK(service_); - - service_->NotifyDescriptorValueChanged( - this, iter->second, properties->value.value()); -} - void BluetoothRemoteGattCharacteristicChromeOS::OnValueSuccess( const ValueCallback& callback, const std::vector<uint8>& value) { diff --git a/device/bluetooth/bluetooth_remote_gatt_characteristic_chromeos.h b/device/bluetooth/bluetooth_remote_gatt_characteristic_chromeos.h index 91c3f62..35a0884 100644 --- a/device/bluetooth/bluetooth_remote_gatt_characteristic_chromeos.h +++ b/device/bluetooth/bluetooth_remote_gatt_characteristic_chromeos.h @@ -80,9 +80,6 @@ class BluetoothRemoteGattCharacteristicChromeOS const dbus::ObjectPath& object_path) OVERRIDE; virtual void GattDescriptorRemoved( const dbus::ObjectPath& object_path) OVERRIDE; - virtual void GattDescriptorPropertyChanged( - const dbus::ObjectPath& object_path, - const std::string& property_name) OVERRIDE; // Called by dbus:: on successful completion of a request to read // the characteristic value. diff --git a/device/bluetooth/bluetooth_remote_gatt_descriptor_chromeos.cc b/device/bluetooth/bluetooth_remote_gatt_descriptor_chromeos.cc index 0027173..8978cc5 100644 --- a/device/bluetooth/bluetooth_remote_gatt_descriptor_chromeos.cc +++ b/device/bluetooth/bluetooth_remote_gatt_descriptor_chromeos.cc @@ -10,6 +10,7 @@ #include "chromeos/dbus/bluetooth_gatt_descriptor_client.h" #include "chromeos/dbus/dbus_thread_manager.h" #include "device/bluetooth/bluetooth_remote_gatt_characteristic_chromeos.h" +#include "device/bluetooth/bluetooth_remote_gatt_service_chromeos.h" namespace chromeos { @@ -59,11 +60,7 @@ bool BluetoothRemoteGattDescriptorChromeOS::IsLocal() const { const std::vector<uint8>& BluetoothRemoteGattDescriptorChromeOS::GetValue() const { - BluetoothGattDescriptorClient::Properties* properties = - DBusThreadManager::Get()->GetBluetoothGattDescriptorClient()-> - GetProperties(object_path_); - DCHECK(properties); - return properties->value.value(); + return cached_value_; } device::BluetoothGattCharacteristic* @@ -84,14 +81,15 @@ void BluetoothRemoteGattDescriptorChromeOS::ReadRemoteDescriptor( VLOG(1) << "Sending GATT characteristic descriptor read request to " << "descriptor: " << GetIdentifier() << ", UUID: " << GetUUID().canonical_value(); - BluetoothGattDescriptorClient::Properties* properties = - DBusThreadManager::Get()->GetBluetoothGattDescriptorClient()-> - GetProperties(object_path_); - DCHECK(properties); - properties->value.Get( - base::Bind(&BluetoothRemoteGattDescriptorChromeOS::OnGetValue, + + DBusThreadManager::Get()->GetBluetoothGattDescriptorClient()->ReadValue( + object_path_, + base::Bind(&BluetoothRemoteGattDescriptorChromeOS::OnValueSuccess, + weak_ptr_factory_.GetWeakPtr(), + callback), + base::Bind(&BluetoothRemoteGattDescriptorChromeOS::OnError, weak_ptr_factory_.GetWeakPtr(), - callback, error_callback)); + error_callback)); } void BluetoothRemoteGattDescriptorChromeOS::WriteRemoteDescriptor( @@ -102,47 +100,38 @@ void BluetoothRemoteGattDescriptorChromeOS::WriteRemoteDescriptor( << "characteristic: " << GetIdentifier() << ", UUID: " << GetUUID().canonical_value() << ", with value: " << new_value << "."; - BluetoothGattDescriptorClient::Properties* properties = - DBusThreadManager::Get()->GetBluetoothGattDescriptorClient()-> - GetProperties(object_path_); - DCHECK(properties); - properties->value.Set( + + DBusThreadManager::Get()->GetBluetoothGattDescriptorClient()->WriteValue( + object_path_, new_value, - base::Bind(&BluetoothRemoteGattDescriptorChromeOS::OnSetValue, + callback, + base::Bind(&BluetoothRemoteGattDescriptorChromeOS::OnError, weak_ptr_factory_.GetWeakPtr(), - callback, error_callback)); + error_callback)); } -void BluetoothRemoteGattDescriptorChromeOS::OnGetValue( +void BluetoothRemoteGattDescriptorChromeOS::OnValueSuccess( const ValueCallback& callback, - const ErrorCallback& error_callback, - bool success) { - if (!success) { - VLOG(1) << "Failed to read the value from the remote descriptor."; - error_callback.Run(); - return; - } - - VLOG(1) << "Read value of remote descriptor."; - BluetoothGattDescriptorClient::Properties* properties = - DBusThreadManager::Get()->GetBluetoothGattDescriptorClient()-> - GetProperties(object_path_); - DCHECK(properties); - callback.Run(properties->value.value()); + const std::vector<uint8>& value) { + VLOG(1) << "Descriptor value read: " << value; + cached_value_ = value; + + DCHECK(characteristic_); + BluetoothRemoteGattServiceChromeOS* service = + static_cast<BluetoothRemoteGattServiceChromeOS*>( + characteristic_->GetService()); + DCHECK(service); + service->NotifyDescriptorValueChanged(characteristic_, this, value); + callback.Run(value); } -void BluetoothRemoteGattDescriptorChromeOS::OnSetValue( - const base::Closure& callback, +void BluetoothRemoteGattDescriptorChromeOS::OnError( const ErrorCallback& error_callback, - bool success) { - if (!success) { - VLOG(1) << "Failed to write the value of remote descriptor."; - error_callback.Run(); - return; - } - - VLOG(1) << "Wrote value of remote descriptor."; - callback.Run(); + const std::string& error_name, + const std::string& error_message) { + VLOG(1) << "Operation failed: " << error_name + << ", message: " << error_message; + error_callback.Run(); } } // namespace chromeos diff --git a/device/bluetooth/bluetooth_remote_gatt_descriptor_chromeos.h b/device/bluetooth/bluetooth_remote_gatt_descriptor_chromeos.h index 129daea..d4ea1e6 100644 --- a/device/bluetooth/bluetooth_remote_gatt_descriptor_chromeos.h +++ b/device/bluetooth/bluetooth_remote_gatt_descriptor_chromeos.h @@ -57,15 +57,16 @@ class BluetoothRemoteGattDescriptorChromeOS const dbus::ObjectPath& object_path); virtual ~BluetoothRemoteGattDescriptorChromeOS(); - // Called by dbus:: on completion of the request to get the descriptor value. - void OnGetValue(const ValueCallback& callback, - const ErrorCallback& error_callback, - bool success); + // Called by dbus:: on successful completion of a request to read + // the descriptor value. + void OnValueSuccess(const ValueCallback& callback, + const std::vector<uint8>& value); - // Called by dbus:: on completion of the request to set the descriptor value. - void OnSetValue(const base::Closure& callback, - const ErrorCallback& error_callback, - bool success); + // Called by dbus:: on unsuccessful completion of a request to read or write + // the descriptor value. + void OnError(const ErrorCallback& error_callback, + const std::string& error_name, + const std::string& error_message); // Object path of the D-Bus descriptor object. dbus::ObjectPath object_path_; @@ -73,6 +74,9 @@ class BluetoothRemoteGattDescriptorChromeOS // The GATT characteristic this descriptor belongs to. BluetoothRemoteGattCharacteristicChromeOS* characteristic_; + // The cached characteristic value based on the most recent read request. + std::vector<uint8> cached_value_; + // Note: This should remain the last member so it'll be destroyed and // invalidate its weak pointers before any other members are destroyed. base::WeakPtrFactory<BluetoothRemoteGattDescriptorChromeOS> weak_ptr_factory_; diff --git a/device/bluetooth/bluetooth_remote_gatt_service_chromeos.h b/device/bluetooth/bluetooth_remote_gatt_service_chromeos.h index db42ecf..e490ffc 100644 --- a/device/bluetooth/bluetooth_remote_gatt_service_chromeos.h +++ b/device/bluetooth/bluetooth_remote_gatt_service_chromeos.h @@ -89,8 +89,8 @@ class BluetoothRemoteGattServiceChromeOS bool added); // Notifies its observers that the value of a descriptor has changed. Called - // by BluetoothRemoteGattCharacteristicChromeOS instances to notify service - // observers when the value of one of their descriptors gets updated. + // by BluetoothRemoteGattDescriptorChromeOS instances to notify service + // observers when their cached value gets updated after a read request. void NotifyDescriptorValueChanged( BluetoothRemoteGattCharacteristicChromeOS* characteristic, BluetoothRemoteGattDescriptorChromeOS* descriptor, |