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

Side by Side Diff: device/bluetooth/bluez/bluetooth_gatt_service_bluez.cc

Issue 1920693002: Complete //device/bt implementation for hosting local GATT attributes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "device/bluetooth/bluez/bluetooth_gatt_service_bluez.h" 5 #include "device/bluetooth/bluez/bluetooth_gatt_service_bluez.h"
6 6
7 #include "base/guid.h"
7 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/strings/string_util.h"
8 #include "device/bluetooth/bluez/bluetooth_adapter_bluez.h" 10 #include "device/bluetooth/bluez/bluetooth_adapter_bluez.h"
11 #include "third_party/cros_system_api/dbus/service_constants.h"
9 12
10 namespace bluez { 13 namespace bluez {
11 14
12 namespace {
13
14 // TODO(jamuraa) move these to cros_system_api later
15 const char kErrorFailed[] = "org.bluez.Error.Failed";
16 const char kErrorInProgress[] = "org.bluez.Error.InProgress";
17 const char kErrorInvalidValueLength[] = "org.bluez.Error.InvalidValueLength";
18 const char kErrorNotAuthorized[] = "org.bluez.Error.NotAuthorized";
19 const char kErrorNotPaired[] = "org.bluez.Error.NotPaired";
20 const char kErrorNotSupported[] = "org.bluez.Error.NotSupported";
21 const char kErrorNotPermitted[] = "org.bluez.Error.NotPermitted";
22
23 } // namespace
24
25 BluetoothGattServiceBlueZ::BluetoothGattServiceBlueZ( 15 BluetoothGattServiceBlueZ::BluetoothGattServiceBlueZ(
26 BluetoothAdapterBlueZ* adapter) 16 BluetoothAdapterBlueZ* adapter)
27 : adapter_(adapter) { 17 : adapter_(adapter) {
28 DCHECK(adapter_); 18 DCHECK(adapter_);
29 } 19 }
30 20
31 BluetoothGattServiceBlueZ::~BluetoothGattServiceBlueZ() {} 21 BluetoothGattServiceBlueZ::~BluetoothGattServiceBlueZ() {}
32 22
33 std::string BluetoothGattServiceBlueZ::GetIdentifier() const { 23 std::string BluetoothGattServiceBlueZ::GetIdentifier() const {
34 return object_path_.value(); 24 return object_path_.value();
35 } 25 }
36 26
37 // static 27 // static
38 device::BluetoothGattService::GattErrorCode 28 device::BluetoothGattService::GattErrorCode
39 BluetoothGattServiceBlueZ::DBusErrorToServiceError(std::string error_name) { 29 BluetoothGattServiceBlueZ::DBusErrorToServiceError(std::string error_name) {
40 device::BluetoothGattService::GattErrorCode code = GATT_ERROR_UNKNOWN; 30 device::BluetoothGattService::GattErrorCode code = GATT_ERROR_UNKNOWN;
41 if (error_name == kErrorFailed) { 31 if (error_name == bluetooth_gatt_service::kErrorFailed) {
42 code = GATT_ERROR_FAILED; 32 code = GATT_ERROR_FAILED;
43 } else if (error_name == kErrorInProgress) { 33 } else if (error_name == bluetooth_gatt_service::kErrorInProgress) {
44 code = GATT_ERROR_IN_PROGRESS; 34 code = GATT_ERROR_IN_PROGRESS;
45 } else if (error_name == kErrorInvalidValueLength) { 35 } else if (error_name == bluetooth_gatt_service::kErrorInvalidValueLength) {
46 code = GATT_ERROR_INVALID_LENGTH; 36 code = GATT_ERROR_INVALID_LENGTH;
47 } else if (error_name == kErrorNotPermitted) { 37 } else if (error_name == bluetooth_gatt_service::kErrorReadNotPermitted ||
38 error_name == bluetooth_gatt_service::kErrorWriteNotPermitted) {
48 code = GATT_ERROR_NOT_PERMITTED; 39 code = GATT_ERROR_NOT_PERMITTED;
49 } else if (error_name == kErrorNotAuthorized) { 40 } else if (error_name == bluetooth_gatt_service::kErrorNotAuthorized) {
50 code = GATT_ERROR_NOT_AUTHORIZED; 41 code = GATT_ERROR_NOT_AUTHORIZED;
51 } else if (error_name == kErrorNotPaired) { 42 } else if (error_name == bluetooth_gatt_service::kErrorNotPaired) {
52 code = GATT_ERROR_NOT_PAIRED; 43 code = GATT_ERROR_NOT_PAIRED;
53 } else if (error_name == kErrorNotSupported) { 44 } else if (error_name == bluetooth_gatt_service::kErrorNotSupported) {
54 code = GATT_ERROR_NOT_SUPPORTED; 45 code = GATT_ERROR_NOT_SUPPORTED;
55 } 46 }
56 return code; 47 return code;
57 } 48 }
58 49
59 BluetoothAdapterBlueZ* BluetoothGattServiceBlueZ::GetAdapter() const { 50 BluetoothAdapterBlueZ* BluetoothGattServiceBlueZ::GetAdapter() const {
60 return adapter_; 51 return adapter_;
61 } 52 }
62 53
54 dbus::ObjectPath BluetoothGattServiceBlueZ::GenerateAttributeObjectPath(
55 const std::string attribute_type) {
56 DCHECK(adapter_);
57
58 std::string GuidString = base::GenerateGUID();
59 base::RemoveChars(GuidString, "-", &GuidString);
60
61 return dbus::ObjectPath(adapter_->GetApplicationObjectPath().value() + "/" +
62 attribute_type + "/" + GuidString);
63 }
64
63 } // namespace bluez 65 } // namespace bluez
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698