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

Unified Diff: device/bluetooth/bluetooth_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_gatt_service_bluez.cc
diff --git a/device/bluetooth/bluetooth_gatt_service_bluez.cc b/device/bluetooth/bluetooth_gatt_service_bluez.cc
new file mode 100644
index 0000000000000000000000000000000000000000..38102a5bbc17891e960ef17f20d7339a419b2a7c
--- /dev/null
+++ b/device/bluetooth/bluetooth_gatt_service_bluez.cc
@@ -0,0 +1,122 @@
+// Copyright 2014 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_gatt_service_bluez.h"
+
+#include "base/logging.h"
+#include "base/strings/stringprintf.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/dbus/bluetooth_gatt_manager_client.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
+
+BluetoothGattServiceBlueZ::BluetoothGattServiceBlueZ(
+ BluetoothAdapterBlueZ* adapter,
+ BluetoothDeviceBlueZ* device,
+ const dbus::ObjectPath& object_path)
+ : object_path_(object_path), adapter_(adapter), device_(device) {
+ VLOG(1) << "Creating GATT service with identifier: " << object_path.value()
+ << ", UUID: " << GetUUID().canonical_value();
+ DCHECK(adapter_);
+}
+
+BluetoothGattServiceBlueZ::~BluetoothGattServiceBlueZ() {}
+
+std::string BluetoothGattServiceBlueZ::GetIdentifier() const {
+ return object_path_.value();
+}
+
+device::BluetoothUUID BluetoothGattServiceBlueZ::GetUUID() const {
+ bluez::BluetoothGattServiceClient::Properties* properties =
+ bluez::BluezDBusManager::Get()
+ ->GetBluetoothGattServiceClient()
+ ->GetProperties(object_path_);
+ DCHECK(properties);
+ return device::BluetoothUUID(properties->uuid.value());
+}
+
+bool BluetoothGattServiceBlueZ::IsPrimary() const {
+ bluez::BluetoothGattServiceClient::Properties* properties =
+ bluez::BluezDBusManager::Get()
+ ->GetBluetoothGattServiceClient()
+ ->GetProperties(object_path_);
+ DCHECK(properties);
+ return properties->primary.value();
+}
+
+device::BluetoothDevice* BluetoothGattServiceBlueZ::GetDevice() const {
+ return device_;
+}
+
+std::vector<device::BluetoothGattCharacteristic*>
+BluetoothGattServiceBlueZ::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*>
+BluetoothGattServiceBlueZ::GetIncludedServices() const {
+ // TODO(armansito): Return the actual included services here.
+ return std::vector<device::BluetoothGattService*>();
+}
+
+device::BluetoothGattCharacteristic*
+BluetoothGattServiceBlueZ::GetCharacteristic(
+ const std::string& identifier) const {
+ CharacteristicMap::const_iterator iter =
+ characteristics_.find(dbus::ObjectPath(identifier));
+ if (iter == characteristics_.end())
+ return NULL;
+ return iter->second;
+}
+
+// static
+device::BluetoothGattService::GattErrorCode
+BluetoothGattServiceBlueZ::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* BluetoothGattServiceBlueZ::GetAdapter() const {
+ return adapter_;
+}
+
+} // namespace bluez

Powered by Google App Engine
This is Rietveld 408576698