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

Unified Diff: device/bluetooth/bluetooth_remote_gatt_service_bluez.cc

Issue 1872943002: Add support for local services/characteristics/descriptors. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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: 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..bd6b203dee807f92a453ad76a86039d9ab8818d8 100644
--- a/device/bluetooth/bluetooth_remote_gatt_service_bluez.cc
+++ b/device/bluetooth/bluetooth_remote_gatt_service_bluez.cc
@@ -4,42 +4,34 @@
#include "device/bluetooth/bluetooth_remote_gatt_service_bluez.h"
+#include <iostream>
+#include <iterator>
+
+#include "base/callback.h"
+#include "base/callback_forward.h"
#include "base/logging.h"
-#include "base/strings/stringprintf.h"
+#include "dbus/property.h"
#include "device/bluetooth/bluetooth_adapter_bluez.h"
#include "device/bluetooth/bluetooth_device_bluez.h"
+#include "device/bluetooth/bluetooth_gatt_characteristic_bluez.h"
+#include "device/bluetooth/bluetooth_gatt_descriptor_bluez.h"
+#include "device/bluetooth/bluetooth_gatt_service.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_service_client.h"
#include "device/bluetooth/dbus/bluez_dbus_manager.h"
namespace bluez {
-namespace {
-
-// TODO(jamuraa) move these to cros_system_api later
-const char kErrorFailed[] = "org.bluez.Error.Failed";
-const char kErrorInProgress[] = "org.bluez.Error.InProgress";
-const char kErrorInvalidValueLength[] = "org.bluez.Error.InvalidValueLength";
-const char kErrorNotAuthorized[] = "org.bluez.Error.NotAuthorized";
-const char kErrorNotPaired[] = "org.bluez.Error.NotPaired";
-const char kErrorNotSupported[] = "org.bluez.Error.NotSupported";
-const char kErrorNotPermitted[] = "org.bluez.Error.NotPermitted";
-
-} // namespace
-
BluetoothRemoteGattServiceBlueZ::BluetoothRemoteGattServiceBlueZ(
BluetoothAdapterBlueZ* adapter,
BluetoothDeviceBlueZ* device,
const dbus::ObjectPath& object_path)
- : object_path_(object_path),
- adapter_(adapter),
+ : BluetoothGattServiceBlueZ(adapter, object_path),
device_(device),
discovery_complete_(false),
weak_ptr_factory_(this) {
VLOG(1) << "Creating remote GATT service with identifier: "
- << object_path.value() << ", UUID: " << GetUUID().canonical_value();
- DCHECK(adapter_);
+ << object_path.value();
+ DCHECK(GetAdapter());
bluez::BluezDBusManager::Get()->GetBluetoothGattServiceClient()->AddObserver(
this);
@@ -72,22 +64,18 @@ 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_);
+ ->GetProperties(object_path());
DCHECK(properties);
return device::BluetoothUUID(properties->uuid.value());
}
@@ -100,7 +88,7 @@ bool BluetoothRemoteGattServiceBlueZ::IsPrimary() const {
bluez::BluetoothGattServiceClient::Properties* properties =
bluez::BluezDBusManager::Get()
->GetBluetoothGattServiceClient()
- ->GetProperties(object_path_);
+ ->GetProperties(object_path());
DCHECK(properties);
return properties->primary.value();
}
@@ -109,32 +97,6 @@ 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,41 +113,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(GATT_ERROR_NOT_SUPPORTED);
}
void BluetoothRemoteGattServiceBlueZ::Unregister(
const base::Closure& callback,
const ErrorCallback& error_callback) {
VLOG(1) << "A remote GATT service cannot be unregistered.";
- error_callback.Run();
-}
-
-// static
-device::BluetoothGattService::GattErrorCode
-BluetoothRemoteGattServiceBlueZ::DBusErrorToServiceError(
- std::string error_name) {
- device::BluetoothGattService::GattErrorCode code = GATT_ERROR_UNKNOWN;
- if (error_name == kErrorFailed) {
- code = GATT_ERROR_FAILED;
- } else if (error_name == kErrorInProgress) {
- code = GATT_ERROR_IN_PROGRESS;
- } else if (error_name == kErrorInvalidValueLength) {
- code = GATT_ERROR_INVALID_LENGTH;
- } else if (error_name == kErrorNotPermitted) {
- code = GATT_ERROR_NOT_PERMITTED;
- } else if (error_name == kErrorNotAuthorized) {
- code = GATT_ERROR_NOT_AUTHORIZED;
- } else if (error_name == kErrorNotPaired) {
- code = GATT_ERROR_NOT_PAIRED;
- } else if (error_name == kErrorNotSupported) {
- code = GATT_ERROR_NOT_SUPPORTED;
- }
- return code;
-}
-
-BluetoothAdapterBlueZ* BluetoothRemoteGattServiceBlueZ::GetAdapter() const {
- return adapter_;
+ error_callback.Run(GATT_ERROR_NOT_SUPPORTED);
}
void BluetoothRemoteGattServiceBlueZ::NotifyServiceChanged() {
@@ -195,40 +130,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 +185,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 +202,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 +216,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(
@@ -296,12 +231,12 @@ void BluetoothRemoteGattServiceBlueZ::GattCharacteristicRemoved(
VLOG(1) << "Removing remote GATT characteristic from service: "
<< GetIdentifier() << ", UUID: " << GetUUID().canonical_value();
- BluetoothRemoteGattCharacteristicBlueZ* characteristic = iter->second;
+ BluetoothGattCharacteristicBlueZ* characteristic = iter->second;
DCHECK(characteristic->object_path() == object_path);
characteristics_.erase(iter);
- DCHECK(adapter_);
- adapter_->NotifyGattCharacteristicRemoved(characteristic);
+ DCHECK(GetAdapter());
+ GetAdapter()->NotifyGattCharacteristicRemoved(characteristic);
delete characteristic;
}
@@ -326,13 +261,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
« no previous file with comments | « device/bluetooth/bluetooth_remote_gatt_service_bluez.h ('k') | device/bluetooth/bluetooth_remote_gatt_service_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698