| Index: device/bluetooth/bluetooth_remote_gatt_service_bluez.cc
|
| diff --git a/device/bluetooth/bluetooth_remote_gatt_service_bluez.cc b/device/bluetooth/bluetooth_remote_gatt_service_bluez.cc
|
| index 4906aaf7e001fabe7d5e5da3cc1e1fc2480fac75..b2bdee2b83fea94c4ea96685cf5b8189504d444d 100644
|
| --- a/device/bluetooth/bluetooth_remote_gatt_service_bluez.cc
|
| +++ b/device/bluetooth/bluetooth_remote_gatt_service_bluez.cc
|
| @@ -8,8 +8,9 @@
|
| #include "base/strings/stringprintf.h"
|
| #include "device/bluetooth/bluetooth_adapter_bluez.h"
|
| #include "device/bluetooth/bluetooth_device_bluez.h"
|
| +#include "device/bluetooth/bluetooth_gatt_descriptor_bluez.h"
|
| #include "device/bluetooth/bluetooth_remote_gatt_characteristic_bluez.h"
|
| -#include "device/bluetooth/bluetooth_remote_gatt_descriptor_bluez.h"
|
| +#include "device/bluetooth/dbus/bluetooth_gatt_manager_client.h"
|
| #include "device/bluetooth/dbus/bluetooth_gatt_service_client.h"
|
| #include "device/bluetooth/dbus/bluez_dbus_manager.h"
|
|
|
| @@ -32,14 +33,12 @@ BluetoothRemoteGattServiceBlueZ::BluetoothRemoteGattServiceBlueZ(
|
| BluetoothAdapterBlueZ* adapter,
|
| BluetoothDeviceBlueZ* device,
|
| const dbus::ObjectPath& object_path)
|
| - : object_path_(object_path),
|
| - adapter_(adapter),
|
| - device_(device),
|
| + : BluetoothGattServiceBlueZ(adapter, device, object_path),
|
| discovery_complete_(false),
|
| weak_ptr_factory_(this) {
|
| VLOG(1) << "Creating remote GATT service with identifier: "
|
| << object_path.value() << ", UUID: " << GetUUID().canonical_value();
|
| - DCHECK(adapter_);
|
| + DCHECK(GetAdapter());
|
|
|
| bluez::BluezDBusManager::Get()->GetBluetoothGattServiceClient()->AddObserver(
|
| this);
|
| @@ -72,69 +71,17 @@ BluetoothRemoteGattServiceBlueZ::~BluetoothRemoteGattServiceBlueZ() {
|
| characteristics_.clear();
|
| for (CharacteristicMap::iterator iter = characteristics.begin();
|
| iter != characteristics.end(); ++iter) {
|
| - DCHECK(adapter_);
|
| - adapter_->NotifyGattCharacteristicRemoved(iter->second);
|
| + DCHECK(GetAdapter());
|
| + GetAdapter()->NotifyGattCharacteristicRemoved(iter->second);
|
|
|
| delete iter->second;
|
| }
|
| }
|
|
|
| -std::string BluetoothRemoteGattServiceBlueZ::GetIdentifier() const {
|
| - return object_path_.value();
|
| -}
|
| -
|
| -device::BluetoothUUID BluetoothRemoteGattServiceBlueZ::GetUUID() const {
|
| - bluez::BluetoothGattServiceClient::Properties* properties =
|
| - bluez::BluezDBusManager::Get()
|
| - ->GetBluetoothGattServiceClient()
|
| - ->GetProperties(object_path_);
|
| - DCHECK(properties);
|
| - return device::BluetoothUUID(properties->uuid.value());
|
| -}
|
| -
|
| bool BluetoothRemoteGattServiceBlueZ::IsLocal() const {
|
| return false;
|
| }
|
|
|
| -bool BluetoothRemoteGattServiceBlueZ::IsPrimary() const {
|
| - bluez::BluetoothGattServiceClient::Properties* properties =
|
| - bluez::BluezDBusManager::Get()
|
| - ->GetBluetoothGattServiceClient()
|
| - ->GetProperties(object_path_);
|
| - DCHECK(properties);
|
| - return properties->primary.value();
|
| -}
|
| -
|
| -device::BluetoothDevice* BluetoothRemoteGattServiceBlueZ::GetDevice() const {
|
| - return device_;
|
| -}
|
| -
|
| -std::vector<device::BluetoothGattCharacteristic*>
|
| -BluetoothRemoteGattServiceBlueZ::GetCharacteristics() const {
|
| - std::vector<device::BluetoothGattCharacteristic*> characteristics;
|
| - for (CharacteristicMap::const_iterator iter = characteristics_.begin();
|
| - iter != characteristics_.end(); ++iter) {
|
| - characteristics.push_back(iter->second);
|
| - }
|
| - return characteristics;
|
| -}
|
| -
|
| -std::vector<device::BluetoothGattService*>
|
| -BluetoothRemoteGattServiceBlueZ::GetIncludedServices() const {
|
| - // TODO(armansito): Return the actual included services here.
|
| - return std::vector<device::BluetoothGattService*>();
|
| -}
|
| -
|
| -device::BluetoothGattCharacteristic*
|
| -BluetoothRemoteGattServiceBlueZ::GetCharacteristic(
|
| - const std::string& identifier) const {
|
| - CharacteristicMap::const_iterator iter =
|
| - characteristics_.find(dbus::ObjectPath(identifier));
|
| - if (iter == characteristics_.end())
|
| - return NULL;
|
| - return iter->second;
|
| -}
|
| -
|
| bool BluetoothRemoteGattServiceBlueZ::AddCharacteristic(
|
| device::BluetoothGattCharacteristic* characteristic) {
|
| VLOG(1) << "Characteristics cannot be added to a remote GATT service.";
|
| @@ -151,14 +98,14 @@ void BluetoothRemoteGattServiceBlueZ::Register(
|
| const base::Closure& callback,
|
| const ErrorCallback& error_callback) {
|
| VLOG(1) << "A remote GATT service cannot be registered.";
|
| - error_callback.Run();
|
| + error_callback.Run("Invalid", "Register is invalid for remote services.");
|
| }
|
|
|
| void BluetoothRemoteGattServiceBlueZ::Unregister(
|
| const base::Closure& callback,
|
| const ErrorCallback& error_callback) {
|
| VLOG(1) << "A remote GATT service cannot be unregistered.";
|
| - error_callback.Run();
|
| + error_callback.Run("Invalid", "Unregister is invalid for remote services.");
|
| }
|
|
|
| // static
|
| @@ -184,10 +131,6 @@ BluetoothRemoteGattServiceBlueZ::DBusErrorToServiceError(
|
| return code;
|
| }
|
|
|
| -BluetoothAdapterBlueZ* BluetoothRemoteGattServiceBlueZ::GetAdapter() const {
|
| - return adapter_;
|
| -}
|
| -
|
| void BluetoothRemoteGattServiceBlueZ::NotifyServiceChanged() {
|
| // Don't send service changed unless we know that all characteristics have
|
| // already been discovered. This is to prevent spammy events before sending
|
| @@ -195,40 +138,40 @@ void BluetoothRemoteGattServiceBlueZ::NotifyServiceChanged() {
|
| if (!discovery_complete_)
|
| return;
|
|
|
| - DCHECK(adapter_);
|
| - adapter_->NotifyGattServiceChanged(this);
|
| + DCHECK(GetAdapter());
|
| + GetAdapter()->NotifyGattServiceChanged(this);
|
| }
|
|
|
| void BluetoothRemoteGattServiceBlueZ::NotifyDescriptorAddedOrRemoved(
|
| BluetoothRemoteGattCharacteristicBlueZ* characteristic,
|
| - BluetoothRemoteGattDescriptorBlueZ* descriptor,
|
| + BluetoothGattDescriptorBlueZ* descriptor,
|
| bool added) {
|
| DCHECK(characteristic->GetService() == this);
|
| DCHECK(descriptor->GetCharacteristic() == characteristic);
|
| - DCHECK(adapter_);
|
| + DCHECK(GetAdapter());
|
|
|
| if (added) {
|
| - adapter_->NotifyGattDescriptorAdded(descriptor);
|
| + GetAdapter()->NotifyGattDescriptorAdded(descriptor);
|
| return;
|
| }
|
|
|
| - adapter_->NotifyGattDescriptorRemoved(descriptor);
|
| + GetAdapter()->NotifyGattDescriptorRemoved(descriptor);
|
| }
|
|
|
| void BluetoothRemoteGattServiceBlueZ::NotifyDescriptorValueChanged(
|
| BluetoothRemoteGattCharacteristicBlueZ* characteristic,
|
| - BluetoothRemoteGattDescriptorBlueZ* descriptor,
|
| + BluetoothGattDescriptorBlueZ* descriptor,
|
| const std::vector<uint8_t>& value) {
|
| DCHECK(characteristic->GetService() == this);
|
| DCHECK(descriptor->GetCharacteristic() == characteristic);
|
| - DCHECK(adapter_);
|
| - adapter_->NotifyGattDescriptorValueChanged(descriptor, value);
|
| + DCHECK(GetAdapter());
|
| + GetAdapter()->NotifyGattDescriptorValueChanged(descriptor, value);
|
| }
|
|
|
| void BluetoothRemoteGattServiceBlueZ::GattServicePropertyChanged(
|
| const dbus::ObjectPath& object_path,
|
| const std::string& property_name) {
|
| - if (object_path != object_path_)
|
| + if (object_path != this->object_path())
|
| return;
|
|
|
| VLOG(1) << "Service property changed: \"" << property_name << "\", "
|
| @@ -250,8 +193,8 @@ void BluetoothRemoteGattServiceBlueZ::GattServicePropertyChanged(
|
| VLOG(1) << "All characteristics were discovered for service: "
|
| << object_path.value();
|
| discovery_complete_ = true;
|
| - DCHECK(adapter_);
|
| - adapter_->NotifyGattDiscoveryComplete(this);
|
| + DCHECK(GetAdapter());
|
| + GetAdapter()->NotifyGattDiscoveryComplete(this);
|
| }
|
|
|
| void BluetoothRemoteGattServiceBlueZ::GattCharacteristicAdded(
|
| @@ -267,7 +210,7 @@ void BluetoothRemoteGattServiceBlueZ::GattCharacteristicAdded(
|
| ->GetBluetoothGattCharacteristicClient()
|
| ->GetProperties(object_path);
|
| DCHECK(properties);
|
| - if (properties->service.value() != object_path_) {
|
| + if (properties->service.value() != this->object_path()) {
|
| VLOG(2) << "Remote GATT characteristic does not belong to this service.";
|
| return;
|
| }
|
| @@ -281,8 +224,8 @@ void BluetoothRemoteGattServiceBlueZ::GattCharacteristicAdded(
|
| DCHECK(characteristic->GetIdentifier() == object_path.value());
|
| DCHECK(characteristic->GetUUID().IsValid());
|
|
|
| - DCHECK(adapter_);
|
| - adapter_->NotifyGattCharacteristicAdded(characteristic);
|
| + DCHECK(GetAdapter());
|
| + GetAdapter()->NotifyGattCharacteristicAdded(characteristic);
|
| }
|
|
|
| void BluetoothRemoteGattServiceBlueZ::GattCharacteristicRemoved(
|
| @@ -300,8 +243,8 @@ void BluetoothRemoteGattServiceBlueZ::GattCharacteristicRemoved(
|
| DCHECK(characteristic->object_path() == object_path);
|
| characteristics_.erase(iter);
|
|
|
| - DCHECK(adapter_);
|
| - adapter_->NotifyGattCharacteristicRemoved(characteristic);
|
| + DCHECK(GetAdapter());
|
| + GetAdapter()->NotifyGattCharacteristicRemoved(characteristic);
|
|
|
| delete characteristic;
|
| }
|
| @@ -326,13 +269,13 @@ void BluetoothRemoteGattServiceBlueZ::GattCharacteristicPropertyChanged(
|
| ->GetProperties(object_path);
|
|
|
| DCHECK(properties);
|
| - DCHECK(adapter_);
|
| + DCHECK(GetAdapter());
|
|
|
| if (property_name == properties->flags.name())
|
| NotifyServiceChanged();
|
| else if (property_name == properties->value.name())
|
| - adapter_->NotifyGattCharacteristicValueChanged(iter->second,
|
| - properties->value.value());
|
| + GetAdapter()->NotifyGattCharacteristicValueChanged(
|
| + iter->second, properties->value.value());
|
| }
|
|
|
| } // namespace bluez
|
|
|