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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "device/bluetooth/bluetooth_gatt_service_bluez.h"
6
7 #include "base/logging.h"
8 #include "base/strings/stringprintf.h"
9 #include "device/bluetooth/bluetooth_adapter_bluez.h"
10 #include "device/bluetooth/bluetooth_device_bluez.h"
11 #include "device/bluetooth/bluetooth_gatt_characteristic_bluez.h"
12 #include "device/bluetooth/bluetooth_gatt_descriptor_bluez.h"
13 #include "device/bluetooth/dbus/bluetooth_gatt_manager_client.h"
14 #include "device/bluetooth/dbus/bluetooth_gatt_service_client.h"
15 #include "device/bluetooth/dbus/bluez_dbus_manager.h"
16
17 namespace bluez {
18
19 namespace {
20
21 // TODO(jamuraa) move these to cros_system_api later
22 const char kErrorFailed[] = "org.bluez.Error.Failed";
23 const char kErrorInProgress[] = "org.bluez.Error.InProgress";
24 const char kErrorInvalidValueLength[] = "org.bluez.Error.InvalidValueLength";
25 const char kErrorNotAuthorized[] = "org.bluez.Error.NotAuthorized";
26 const char kErrorNotPaired[] = "org.bluez.Error.NotPaired";
27 const char kErrorNotSupported[] = "org.bluez.Error.NotSupported";
28 const char kErrorNotPermitted[] = "org.bluez.Error.NotPermitted";
29
30 } // namespace
31
32 BluetoothGattServiceBlueZ::BluetoothGattServiceBlueZ(
33 BluetoothAdapterBlueZ* adapter,
34 BluetoothDeviceBlueZ* device,
35 const dbus::ObjectPath& object_path)
36 : object_path_(object_path), adapter_(adapter), device_(device) {
37 VLOG(1) << "Creating GATT service with identifier: " << object_path.value()
38 << ", UUID: " << GetUUID().canonical_value();
39 DCHECK(adapter_);
40 }
41
42 BluetoothGattServiceBlueZ::~BluetoothGattServiceBlueZ() {}
43
44 std::string BluetoothGattServiceBlueZ::GetIdentifier() const {
45 return object_path_.value();
46 }
47
48 device::BluetoothUUID BluetoothGattServiceBlueZ::GetUUID() const {
49 bluez::BluetoothGattServiceClient::Properties* properties =
50 bluez::BluezDBusManager::Get()
51 ->GetBluetoothGattServiceClient()
52 ->GetProperties(object_path_);
53 DCHECK(properties);
54 return device::BluetoothUUID(properties->uuid.value());
55 }
56
57 bool BluetoothGattServiceBlueZ::IsPrimary() const {
58 bluez::BluetoothGattServiceClient::Properties* properties =
59 bluez::BluezDBusManager::Get()
60 ->GetBluetoothGattServiceClient()
61 ->GetProperties(object_path_);
62 DCHECK(properties);
63 return properties->primary.value();
64 }
65
66 device::BluetoothDevice* BluetoothGattServiceBlueZ::GetDevice() const {
67 return device_;
68 }
69
70 std::vector<device::BluetoothGattCharacteristic*>
71 BluetoothGattServiceBlueZ::GetCharacteristics() const {
72 std::vector<device::BluetoothGattCharacteristic*> characteristics;
73 for (CharacteristicMap::const_iterator iter = characteristics_.begin();
74 iter != characteristics_.end(); ++iter) {
75 characteristics.push_back(iter->second);
76 }
77 return characteristics;
78 }
79
80 std::vector<device::BluetoothGattService*>
81 BluetoothGattServiceBlueZ::GetIncludedServices() const {
82 // TODO(armansito): Return the actual included services here.
83 return std::vector<device::BluetoothGattService*>();
84 }
85
86 device::BluetoothGattCharacteristic*
87 BluetoothGattServiceBlueZ::GetCharacteristic(
88 const std::string& identifier) const {
89 CharacteristicMap::const_iterator iter =
90 characteristics_.find(dbus::ObjectPath(identifier));
91 if (iter == characteristics_.end())
92 return NULL;
93 return iter->second;
94 }
95
96 // static
97 device::BluetoothGattService::GattErrorCode
98 BluetoothGattServiceBlueZ::DBusErrorToServiceError(std::string error_name) {
99 device::BluetoothGattService::GattErrorCode code = GATT_ERROR_UNKNOWN;
100 if (error_name == kErrorFailed) {
101 code = GATT_ERROR_FAILED;
102 } else if (error_name == kErrorInProgress) {
103 code = GATT_ERROR_IN_PROGRESS;
104 } else if (error_name == kErrorInvalidValueLength) {
105 code = GATT_ERROR_INVALID_LENGTH;
106 } else if (error_name == kErrorNotPermitted) {
107 code = GATT_ERROR_NOT_PERMITTED;
108 } else if (error_name == kErrorNotAuthorized) {
109 code = GATT_ERROR_NOT_AUTHORIZED;
110 } else if (error_name == kErrorNotPaired) {
111 code = GATT_ERROR_NOT_PAIRED;
112 } else if (error_name == kErrorNotSupported) {
113 code = GATT_ERROR_NOT_SUPPORTED;
114 }
115 return code;
116 }
117
118 BluetoothAdapterBlueZ* BluetoothGattServiceBlueZ::GetAdapter() const {
119 return adapter_;
120 }
121
122 } // namespace bluez
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698