Chromium Code Reviews| 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 bb175e3f375fb2df4f9006dd3ea056aed119443f..cae834b0157e8e0cca1f10a3c250e319befcc894 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" |
|
keybuk
2014/05/30 22:22:40
this seems to be still needed given the code below
armansito
2014/05/30 22:37:20
It moved to the header.
|
| #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" |
| @@ -36,6 +35,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); |
| @@ -52,6 +53,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. |
| @@ -79,11 +82,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* |
| @@ -142,14 +141,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( |
| @@ -160,22 +160,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( |
| @@ -256,36 +261,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 |