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

Unified Diff: device/bluetooth/bluez/bluetooth_remote_gatt_characteristic_bluez.cc

Issue 1898643002: Refactor device::BluetoothGattXXX classes to split into remote/local. (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/bluez/bluetooth_remote_gatt_characteristic_bluez.cc
diff --git a/device/bluetooth/bluetooth_remote_gatt_characteristic_bluez.cc b/device/bluetooth/bluez/bluetooth_remote_gatt_characteristic_bluez.cc
similarity index 88%
rename from device/bluetooth/bluetooth_remote_gatt_characteristic_bluez.cc
rename to device/bluetooth/bluez/bluetooth_remote_gatt_characteristic_bluez.cc
index 71201fdf9699005f7721d0d88cc7f6fdba69a46b..b1d6a0ef80fae257db6831d27233915019a03b52 100644
--- a/device/bluetooth/bluetooth_remote_gatt_characteristic_bluez.cc
+++ b/device/bluetooth/bluez/bluetooth_remote_gatt_characteristic_bluez.cc
@@ -1,26 +1,24 @@
-// Copyright 2014 The Chromium Authors. All rights reserved.
+// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "device/bluetooth/bluetooth_remote_gatt_characteristic_bluez.h"
+#include "device/bluetooth/bluez/bluetooth_remote_gatt_characteristic_bluez.h"
#include <iterator>
#include <limits>
-#include <ostream>
#include "base/bind.h"
#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.h"
#include "device/bluetooth/bluetooth_gatt_characteristic.h"
-#include "device/bluetooth/bluetooth_gatt_descriptor_bluez.h"
-#include "device/bluetooth/bluetooth_gatt_notify_session_bluez.h"
#include "device/bluetooth/bluetooth_gatt_service.h"
-#include "device/bluetooth/bluetooth_remote_gatt_service_bluez.h"
+#include "device/bluetooth/bluez/bluetooth_adapter_bluez.h"
+#include "device/bluetooth/bluez/bluetooth_gatt_notify_session_bluez.h"
+#include "device/bluetooth/bluez/bluetooth_remote_gatt_descriptor_bluez.h"
+#include "device/bluetooth/bluez/bluetooth_remote_gatt_service_bluez.h"
#include "device/bluetooth/dbus/bluetooth_gatt_characteristic_client.h"
#include "device/bluetooth/dbus/bluez_dbus_manager.h"
#include "third_party/cros_system_api/dbus/service_constants.h"
@@ -44,9 +42,10 @@ std::ostream& operator<<(std::ostream& out, const std::vector<uint8_t> bytes) {
BluetoothRemoteGattCharacteristicBlueZ::BluetoothRemoteGattCharacteristicBlueZ(
BluetoothRemoteGattServiceBlueZ* service,
const dbus::ObjectPath& object_path)
- : BluetoothGattCharacteristicBlueZ(service, object_path),
+ : BluetoothGattCharacteristicBlueZ(object_path),
num_notify_sessions_(0),
notify_call_pending_(false),
+ service_(service),
weak_ptr_factory_(this) {
VLOG(1) << "Creating remote GATT characteristic with identifier: "
<< GetIdentifier() << ", UUID: " << GetUUID().canonical_value();
@@ -80,7 +79,7 @@ BluetoothRemoteGattCharacteristicBlueZ::
while (!pending_start_notify_calls_.empty()) {
PendingStartNotifyCall callbacks = pending_start_notify_calls_.front();
pending_start_notify_calls_.pop();
- callbacks.second.Run(device::BluetoothGattService::GATT_ERROR_FAILED);
+ callbacks.second.Run(device::BluetoothRemoteGattService::GATT_ERROR_FAILED);
}
}
@@ -93,23 +92,7 @@ device::BluetoothUUID BluetoothRemoteGattCharacteristicBlueZ::GetUUID() const {
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::BluetoothGattCharacteristic::Properties
+device::BluetoothRemoteGattCharacteristic::Properties
BluetoothRemoteGattCharacteristicBlueZ::GetProperties() const {
bluez::BluetoothGattCharacteristicClient::Properties* properties =
bluez::BluezDBusManager::Get()
@@ -146,6 +129,30 @@ BluetoothRemoteGattCharacteristicBlueZ::GetProperties() const {
return props;
}
+device::BluetoothRemoteGattCharacteristic::Permissions
+BluetoothRemoteGattCharacteristicBlueZ::GetPermissions() const {
+ // TODO(armansito): Once BlueZ defines the permissions, return the correct
+ // values here.
+ return PERMISSION_NONE;
+}
+
+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::BluetoothRemoteGattService*
+BluetoothRemoteGattCharacteristicBlueZ::GetService() const {
+ return service_;
+}
+
bool BluetoothRemoteGattCharacteristicBlueZ::IsNotifying() const {
bluez::BluetoothGattCharacteristicClient::Properties* properties =
bluez::BluezDBusManager::Get()
@@ -156,16 +163,23 @@ bool BluetoothRemoteGattCharacteristicBlueZ::IsNotifying() const {
return properties->notifying.value();
}
-bool BluetoothRemoteGattCharacteristicBlueZ::AddDescriptor(
- device::BluetoothGattDescriptor* descriptor) {
- VLOG(1) << "Descriptors cannot be added to a remote GATT characteristic.";
- return false;
+std::vector<device::BluetoothRemoteGattDescriptor*>
+BluetoothRemoteGattCharacteristicBlueZ::GetDescriptors() const {
+ std::vector<device::BluetoothRemoteGattDescriptor*> descriptors;
+ for (DescriptorMap::const_iterator iter = descriptors_.begin();
+ iter != descriptors_.end(); ++iter)
+ descriptors.push_back(iter->second);
+ return descriptors;
}
-bool BluetoothRemoteGattCharacteristicBlueZ::UpdateValue(
- const std::vector<uint8_t>& value) {
- VLOG(1) << "Cannot update the value of a remote GATT characteristic.";
- return false;
+device::BluetoothRemoteGattDescriptor*
+BluetoothRemoteGattCharacteristicBlueZ::GetDescriptor(
+ const std::string& identifier) const {
+ DescriptorMap::const_iterator iter =
+ descriptors_.find(dbus::ObjectPath(identifier));
+ if (iter == descriptors_.end())
+ return nullptr;
+ return iter->second;
}
void BluetoothRemoteGattCharacteristicBlueZ::StartNotifySession(
@@ -182,7 +196,8 @@ void BluetoothRemoteGattCharacteristicBlueZ::StartNotifySession(
if (IsNotifying()) {
// Check for overflows, though unlikely.
if (num_notify_sessions_ == std::numeric_limits<size_t>::max()) {
- error_callback.Run(device::BluetoothGattService::GATT_ERROR_FAILED);
+ error_callback.Run(
+ device::BluetoothRemoteGattService::GATT_ERROR_FAILED);
return;
}
@@ -307,8 +322,8 @@ void BluetoothRemoteGattCharacteristicBlueZ::GattDescriptorAdded(
VLOG(1) << "Adding new remote GATT descriptor for GATT characteristic: "
<< GetIdentifier() << ", UUID: " << GetUUID().canonical_value();
- BluetoothGattDescriptorBlueZ* descriptor =
- new BluetoothGattDescriptorBlueZ(this, object_path, false /* is_local */);
+ BluetoothRemoteGattDescriptorBlueZ* descriptor =
+ new BluetoothRemoteGattDescriptorBlueZ(this, object_path);
descriptors_[object_path] = descriptor;
DCHECK(descriptor->GetIdentifier() == object_path.value());
DCHECK(descriptor->GetUUID().IsValid());
@@ -329,7 +344,7 @@ void BluetoothRemoteGattCharacteristicBlueZ::GattDescriptorRemoved(
VLOG(1) << "Removing remote GATT descriptor from characteristic: "
<< GetIdentifier() << ", UUID: " << GetUUID().canonical_value();
- BluetoothGattDescriptorBlueZ* descriptor = iter->second;
+ BluetoothRemoteGattDescriptorBlueZ* descriptor = iter->second;
DCHECK(descriptor->object_path() == object_path);
descriptors_.erase(iter);

Powered by Google App Engine
This is Rietveld 408576698