Index: device/bluetooth/bluetooth_remote_gatt_characteristic_chromeos.cc |
diff --git a/device/bluetooth/bluetooth_remote_gatt_characteristic_chromeos.cc b/device/bluetooth/bluetooth_remote_gatt_characteristic_chromeos.cc |
index 3d3e15ccf56ed198081d14c483bdca63186e0ed0..0a8a2253fb735501d18ce23f00cdf7a7467d0f70 100644 |
--- a/device/bluetooth/bluetooth_remote_gatt_characteristic_chromeos.cc |
+++ b/device/bluetooth/bluetooth_remote_gatt_characteristic_chromeos.cc |
@@ -6,7 +6,6 @@ |
#include "base/logging.h" |
#include "base/strings/stringprintf.h" |
-#include "chromeos/dbus/bluetooth_gatt_characteristic_client.h" |
#include "chromeos/dbus/dbus_thread_manager.h" |
#include "device/bluetooth/bluetooth_remote_gatt_descriptor_chromeos.h" |
#include "device/bluetooth/bluetooth_remote_gatt_service_chromeos.h" |
@@ -37,6 +36,8 @@ BluetoothRemoteGattCharacteristicChromeOS:: |
weak_ptr_factory_(this) { |
VLOG(1) << "Creating remote GATT characteristic with identifier: " |
<< GetIdentifier() << ", UUID: " << GetUUID().canonical_value(); |
+ DBusThreadManager::Get()->GetBluetoothGattCharacteristicClient()-> |
+ AddObserver(this); |
DBusThreadManager::Get()->GetBluetoothGattDescriptorClient()-> |
AddObserver(this); |
@@ -53,6 +54,8 @@ BluetoothRemoteGattCharacteristicChromeOS:: |
~BluetoothRemoteGattCharacteristicChromeOS() { |
DBusThreadManager::Get()->GetBluetoothGattDescriptorClient()-> |
RemoveObserver(this); |
+ DBusThreadManager::Get()->GetBluetoothGattCharacteristicClient()-> |
+ RemoveObserver(this); |
// Clean up all the descriptors. There isn't much point in notifying service |
// observers for each descriptor that gets removed, so just delete them. |
@@ -80,11 +83,7 @@ bool BluetoothRemoteGattCharacteristicChromeOS::IsLocal() const { |
const std::vector<uint8>& |
BluetoothRemoteGattCharacteristicChromeOS::GetValue() const { |
- BluetoothGattCharacteristicClient::Properties* properties = |
- DBusThreadManager::Get()->GetBluetoothGattCharacteristicClient()-> |
- GetProperties(object_path_); |
- DCHECK(properties); |
- return properties->value.value(); |
+ return cached_value_; |
} |
device::BluetoothGattService* |
@@ -173,14 +172,15 @@ void BluetoothRemoteGattCharacteristicChromeOS::ReadRemoteCharacteristic( |
VLOG(1) << "Sending GATT characteristic read request to characteristic: " |
<< GetIdentifier() << ", UUID: " << GetUUID().canonical_value() |
<< "."; |
- BluetoothGattCharacteristicClient::Properties* properties = |
- DBusThreadManager::Get()->GetBluetoothGattCharacteristicClient()-> |
- GetProperties(object_path_); |
- DCHECK(properties); |
- properties->value.Get( |
- base::Bind(&BluetoothRemoteGattCharacteristicChromeOS::OnGetValue, |
+ |
+ DBusThreadManager::Get()->GetBluetoothGattCharacteristicClient()->ReadValue( |
+ object_path_, |
+ base::Bind(&BluetoothRemoteGattCharacteristicChromeOS::OnValueSuccess, |
weak_ptr_factory_.GetWeakPtr(), |
- callback, error_callback)); |
+ callback), |
+ base::Bind(&BluetoothRemoteGattCharacteristicChromeOS::OnError, |
+ weak_ptr_factory_.GetWeakPtr(), |
+ error_callback)); |
} |
void BluetoothRemoteGattCharacteristicChromeOS::WriteRemoteCharacteristic( |
@@ -191,22 +191,27 @@ void BluetoothRemoteGattCharacteristicChromeOS::WriteRemoteCharacteristic( |
<< GetIdentifier() << ", UUID: " << GetUUID().canonical_value() |
<< ", with value: " << new_value << "."; |
- // Permission and bonding are handled by BlueZ so no need check it here. |
- if (new_value.empty()) { |
- VLOG(1) << "Nothing to write."; |
- error_callback.Run(); |
- return; |
- } |
- |
- BluetoothGattCharacteristicClient::Properties* properties = |
- DBusThreadManager::Get()->GetBluetoothGattCharacteristicClient()-> |
- GetProperties(object_path_); |
- DCHECK(properties); |
- properties->value.Set( |
+ DBusThreadManager::Get()->GetBluetoothGattCharacteristicClient()->WriteValue( |
+ object_path_, |
new_value, |
- base::Bind(&BluetoothRemoteGattCharacteristicChromeOS::OnSetValue, |
+ callback, |
+ base::Bind(&BluetoothRemoteGattCharacteristicChromeOS::OnError, |
weak_ptr_factory_.GetWeakPtr(), |
- callback, error_callback)); |
+ error_callback)); |
+} |
+ |
+void BluetoothRemoteGattCharacteristicChromeOS::GattCharacteristicValueUpdated( |
+ const dbus::ObjectPath& object_path, |
+ const std::vector<uint8>& value) { |
+ if (object_path != object_path_) |
+ return; |
+ |
+ cached_value_ = value; |
+ |
+ VLOG(1) << "GATT characteristic value has changed: " << object_path.value() |
+ << ": " << value; |
+ DCHECK(service_); |
+ service_->NotifyCharacteristicValueChanged(this, value); |
} |
void BluetoothRemoteGattCharacteristicChromeOS::GattDescriptorAdded( |
@@ -287,36 +292,25 @@ void BluetoothRemoteGattCharacteristicChromeOS::GattDescriptorPropertyChanged( |
this, iter->second, properties->value.value()); |
} |
-void BluetoothRemoteGattCharacteristicChromeOS::OnGetValue( |
+void BluetoothRemoteGattCharacteristicChromeOS::OnValueSuccess( |
const ValueCallback& callback, |
- const ErrorCallback& error_callback, |
- bool success) { |
- if (!success) { |
- VLOG(1) << "Failed to read the value from the remote characteristic."; |
- error_callback.Run(); |
- return; |
- } |
+ const std::vector<uint8>& value) { |
+ VLOG(1) << "Characteristic value read: " << value; |
+ cached_value_ = value; |
- VLOG(1) << "Read value of remote characteristic."; |
- BluetoothGattCharacteristicClient::Properties* properties = |
- DBusThreadManager::Get()->GetBluetoothGattCharacteristicClient()-> |
- GetProperties(object_path_); |
- DCHECK(properties); |
- callback.Run(properties->value.value()); |
+ DCHECK(service_); |
+ service_->NotifyCharacteristicValueChanged(this, cached_value_); |
+ |
+ callback.Run(value); |
} |
-void BluetoothRemoteGattCharacteristicChromeOS::OnSetValue( |
- const base::Closure& callback, |
+void BluetoothRemoteGattCharacteristicChromeOS::OnError( |
const ErrorCallback& error_callback, |
- bool success) { |
- if (!success) { |
- VLOG(1) << "Failed to write the value of remote characteristic."; |
- error_callback.Run(); |
- return; |
- } |
- |
- VLOG(1) << "Wrote value of remote characteristic."; |
- 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 |