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

Unified Diff: device/bluetooth/bluetooth_remote_gatt_characteristic_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_characteristic_bluez.cc
diff --git a/device/bluetooth/bluetooth_remote_gatt_characteristic_bluez.cc b/device/bluetooth/bluetooth_remote_gatt_characteristic_bluez.cc
index 07806f701d2619ee007ea08025c4a6a0736af4c4..3d7edfcdfe68083138e49476f14a4320517d4bb6 100644
--- a/device/bluetooth/bluetooth_remote_gatt_characteristic_bluez.cc
+++ b/device/bluetooth/bluetooth_remote_gatt_characteristic_bluez.cc
@@ -11,34 +11,18 @@
#include "base/strings/stringprintf.h"
#include "device/bluetooth/bluetooth_adapter_bluez.h"
#include "device/bluetooth/bluetooth_device.h"
+#include "device/bluetooth/bluetooth_gatt_descriptor_bluez.h"
#include "device/bluetooth/bluetooth_gatt_notify_session_bluez.h"
-#include "device/bluetooth/bluetooth_remote_gatt_characteristic_bluez.h"
-#include "device/bluetooth/bluetooth_remote_gatt_descriptor_bluez.h"
#include "device/bluetooth/bluetooth_remote_gatt_service_bluez.h"
#include "device/bluetooth/dbus/bluez_dbus_manager.h"
#include "third_party/cros_system_api/dbus/service_constants.h"
namespace bluez {
-namespace {
-
-// Stream operator for logging vector<uint8_t>.
-std::ostream& operator<<(std::ostream& out, const std::vector<uint8_t> bytes) {
- out << "[";
- for (std::vector<uint8_t>::const_iterator iter = bytes.begin();
- iter != bytes.end(); ++iter) {
- out << base::StringPrintf("%02X", *iter);
- }
- return out << "]";
-}
-
-} // namespace
-
BluetoothRemoteGattCharacteristicBlueZ::BluetoothRemoteGattCharacteristicBlueZ(
BluetoothRemoteGattServiceBlueZ* service,
const dbus::ObjectPath& object_path)
- : object_path_(object_path),
- service_(service),
+ : BluetoothGattCharacteristicBlueZ(service, object_path),
num_notify_sessions_(0),
notify_call_pending_(false),
weak_ptr_factory_(this) {
@@ -78,113 +62,10 @@ BluetoothRemoteGattCharacteristicBlueZ::
}
}
-std::string BluetoothRemoteGattCharacteristicBlueZ::GetIdentifier() const {
- return object_path_.value();
-}
-
-device::BluetoothUUID BluetoothRemoteGattCharacteristicBlueZ::GetUUID() const {
- bluez::BluetoothGattCharacteristicClient::Properties* properties =
- bluez::BluezDBusManager::Get()
- ->GetBluetoothGattCharacteristicClient()
- ->GetProperties(object_path_);
- DCHECK(properties);
- return device::BluetoothUUID(properties->uuid.value());
-}
-
bool BluetoothRemoteGattCharacteristicBlueZ::IsLocal() const {
return false;
}
-const std::vector<uint8_t>& BluetoothRemoteGattCharacteristicBlueZ::GetValue()
- const {
- bluez::BluetoothGattCharacteristicClient::Properties* properties =
- bluez::BluezDBusManager::Get()
- ->GetBluetoothGattCharacteristicClient()
- ->GetProperties(object_path_);
-
- DCHECK(properties);
-
- return properties->value.value();
-}
-
-device::BluetoothGattService*
-BluetoothRemoteGattCharacteristicBlueZ::GetService() const {
- return service_;
-}
-
-device::BluetoothGattCharacteristic::Properties
-BluetoothRemoteGattCharacteristicBlueZ::GetProperties() const {
- bluez::BluetoothGattCharacteristicClient::Properties* properties =
- bluez::BluezDBusManager::Get()
- ->GetBluetoothGattCharacteristicClient()
- ->GetProperties(object_path_);
- DCHECK(properties);
-
- Properties props = PROPERTY_NONE;
- const std::vector<std::string>& flags = properties->flags.value();
- for (std::vector<std::string>::const_iterator iter = flags.begin();
- iter != flags.end(); ++iter) {
- if (*iter == bluetooth_gatt_characteristic::kFlagBroadcast)
- props |= PROPERTY_BROADCAST;
- if (*iter == bluetooth_gatt_characteristic::kFlagRead)
- props |= PROPERTY_READ;
- if (*iter == bluetooth_gatt_characteristic::kFlagWriteWithoutResponse)
- props |= PROPERTY_WRITE_WITHOUT_RESPONSE;
- if (*iter == bluetooth_gatt_characteristic::kFlagWrite)
- props |= PROPERTY_WRITE;
- if (*iter == bluetooth_gatt_characteristic::kFlagNotify)
- props |= PROPERTY_NOTIFY;
- if (*iter == bluetooth_gatt_characteristic::kFlagIndicate)
- props |= PROPERTY_INDICATE;
- if (*iter == bluetooth_gatt_characteristic::kFlagAuthenticatedSignedWrites)
- props |= PROPERTY_AUTHENTICATED_SIGNED_WRITES;
- if (*iter == bluetooth_gatt_characteristic::kFlagExtendedProperties)
- props |= PROPERTY_EXTENDED_PROPERTIES;
- if (*iter == bluetooth_gatt_characteristic::kFlagReliableWrite)
- props |= PROPERTY_RELIABLE_WRITE;
- if (*iter == bluetooth_gatt_characteristic::kFlagWritableAuxiliaries)
- props |= PROPERTY_WRITABLE_AUXILIARIES;
- }
-
- return props;
-}
-
-device::BluetoothGattCharacteristic::Permissions
-BluetoothRemoteGattCharacteristicBlueZ::GetPermissions() const {
- // TODO(armansito): Once BlueZ defines the permissions, return the correct
- // values here.
- return PERMISSION_NONE;
-}
-
-bool BluetoothRemoteGattCharacteristicBlueZ::IsNotifying() const {
- bluez::BluetoothGattCharacteristicClient::Properties* properties =
- bluez::BluezDBusManager::Get()
- ->GetBluetoothGattCharacteristicClient()
- ->GetProperties(object_path_);
- DCHECK(properties);
-
- return properties->notifying.value();
-}
-
-std::vector<device::BluetoothGattDescriptor*>
-BluetoothRemoteGattCharacteristicBlueZ::GetDescriptors() const {
- std::vector<device::BluetoothGattDescriptor*> descriptors;
- for (DescriptorMap::const_iterator iter = descriptors_.begin();
- iter != descriptors_.end(); ++iter)
- descriptors.push_back(iter->second);
- return descriptors;
-}
-
-device::BluetoothGattDescriptor*
-BluetoothRemoteGattCharacteristicBlueZ::GetDescriptor(
- const std::string& identifier) const {
- DescriptorMap::const_iterator iter =
- descriptors_.find(dbus::ObjectPath(identifier));
- if (iter == descriptors_.end())
- return NULL;
- return iter->second;
-}
-
bool BluetoothRemoteGattCharacteristicBlueZ::AddDescriptor(
device::BluetoothGattDescriptor* descriptor) {
VLOG(1) << "Descriptors cannot be added to a remote GATT characteristic.";
@@ -197,35 +78,6 @@ bool BluetoothRemoteGattCharacteristicBlueZ::UpdateValue(
return false;
}
-void BluetoothRemoteGattCharacteristicBlueZ::ReadRemoteCharacteristic(
- const ValueCallback& callback,
- const ErrorCallback& error_callback) {
- VLOG(1) << "Sending GATT characteristic read request to characteristic: "
- << GetIdentifier() << ", UUID: " << GetUUID().canonical_value()
- << ".";
-
- bluez::BluezDBusManager::Get()
- ->GetBluetoothGattCharacteristicClient()
- ->ReadValue(object_path_, callback,
- base::Bind(&BluetoothRemoteGattCharacteristicBlueZ::OnError,
- weak_ptr_factory_.GetWeakPtr(), error_callback));
-}
-
-void BluetoothRemoteGattCharacteristicBlueZ::WriteRemoteCharacteristic(
- const std::vector<uint8_t>& new_value,
- const base::Closure& callback,
- const ErrorCallback& error_callback) {
- VLOG(1) << "Sending GATT characteristic write request to characteristic: "
- << GetIdentifier() << ", UUID: " << GetUUID().canonical_value()
- << ", with value: " << new_value << ".";
-
- bluez::BluezDBusManager::Get()
- ->GetBluetoothGattCharacteristicClient()
- ->WriteValue(object_path_, new_value, callback,
- base::Bind(&BluetoothRemoteGattCharacteristicBlueZ::OnError,
- weak_ptr_factory_.GetWeakPtr(), error_callback));
-}
-
void BluetoothRemoteGattCharacteristicBlueZ::StartNotifySession(
const NotifySessionCallback& callback,
const ErrorCallback& error_callback) {
@@ -336,8 +188,8 @@ void BluetoothRemoteGattCharacteristicBlueZ::GattDescriptorAdded(
VLOG(1) << "Adding new remote GATT descriptor for GATT characteristic: "
<< GetIdentifier() << ", UUID: " << GetUUID().canonical_value();
- BluetoothRemoteGattDescriptorBlueZ* descriptor =
- new BluetoothRemoteGattDescriptorBlueZ(this, object_path);
+ BluetoothGattDescriptorBlueZ* descriptor =
+ new BluetoothGattDescriptorBlueZ(this, object_path, false /* is_local */);
descriptors_[object_path] = descriptor;
DCHECK(descriptor->GetIdentifier() == object_path.value());
DCHECK(descriptor->GetUUID().IsValid());
@@ -357,7 +209,7 @@ void BluetoothRemoteGattCharacteristicBlueZ::GattDescriptorRemoved(
VLOG(1) << "Removing remote GATT descriptor from characteristic: "
<< GetIdentifier() << ", UUID: " << GetUUID().canonical_value();
- BluetoothRemoteGattDescriptorBlueZ* descriptor = iter->second;
+ BluetoothGattDescriptorBlueZ* descriptor = iter->second;
DCHECK(descriptor->object_path() == object_path);
descriptors_.erase(iter);
@@ -391,16 +243,6 @@ void BluetoothRemoteGattCharacteristicBlueZ::GattDescriptorPropertyChanged(
properties->value.value());
}
-void BluetoothRemoteGattCharacteristicBlueZ::OnError(
- const ErrorCallback& error_callback,
- const std::string& error_name,
- const std::string& error_message) {
- VLOG(1) << "Operation failed: " << error_name
- << ", message: " << error_message;
- error_callback.Run(
- BluetoothRemoteGattServiceBlueZ::DBusErrorToServiceError(error_name));
-}
-
void BluetoothRemoteGattCharacteristicBlueZ::OnStartNotifySuccess(
const NotifySessionCallback& callback) {
VLOG(1) << "Started notifications from characteristic: "

Powered by Google App Engine
This is Rietveld 408576698