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

Side by Side Diff: device/bluetooth/bluetooth_remote_gatt_descriptor_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_remote_gatt_descriptor_bluez.h"
6
7 #include "base/bind.h"
8 #include "base/logging.h"
9 #include "base/strings/stringprintf.h"
10 #include "device/bluetooth/bluetooth_remote_gatt_characteristic_bluez.h"
11 #include "device/bluetooth/bluetooth_remote_gatt_service_bluez.h"
12 #include "device/bluetooth/dbus/bluetooth_gatt_descriptor_client.h"
13 #include "device/bluetooth/dbus/bluez_dbus_manager.h"
14
15 namespace bluez {
16
17 namespace {
18
19 // Stream operator for logging vector<uint8_t>.
20 std::ostream& operator<<(std::ostream& out, const std::vector<uint8_t> bytes) {
21 out << "[";
22 for (std::vector<uint8_t>::const_iterator iter = bytes.begin();
23 iter != bytes.end(); ++iter) {
24 out << base::StringPrintf("%02X", *iter);
25 }
26 return out << "]";
27 }
28
29 } // namespace
30
31 BluetoothRemoteGattDescriptorBlueZ::BluetoothRemoteGattDescriptorBlueZ(
32 BluetoothRemoteGattCharacteristicBlueZ* characteristic,
33 const dbus::ObjectPath& object_path)
34 : object_path_(object_path),
35 characteristic_(characteristic),
36 weak_ptr_factory_(this) {
37 VLOG(1) << "Creating remote GATT descriptor with identifier: "
38 << GetIdentifier() << ", UUID: " << GetUUID().canonical_value();
39 }
40
41 BluetoothRemoteGattDescriptorBlueZ::~BluetoothRemoteGattDescriptorBlueZ() {}
42
43 std::string BluetoothRemoteGattDescriptorBlueZ::GetIdentifier() const {
44 return object_path_.value();
45 }
46
47 device::BluetoothUUID BluetoothRemoteGattDescriptorBlueZ::GetUUID() const {
48 bluez::BluetoothGattDescriptorClient::Properties* properties =
49 bluez::BluezDBusManager::Get()
50 ->GetBluetoothGattDescriptorClient()
51 ->GetProperties(object_path_);
52 DCHECK(properties);
53 return device::BluetoothUUID(properties->uuid.value());
54 }
55
56 bool BluetoothRemoteGattDescriptorBlueZ::IsLocal() const {
57 return false;
58 }
59
60 const std::vector<uint8_t>& BluetoothRemoteGattDescriptorBlueZ::GetValue()
61 const {
62 bluez::BluetoothGattDescriptorClient::Properties* properties =
63 bluez::BluezDBusManager::Get()
64 ->GetBluetoothGattDescriptorClient()
65 ->GetProperties(object_path_);
66
67 DCHECK(properties);
68
69 return properties->value.value();
70 }
71
72 device::BluetoothGattCharacteristic*
73 BluetoothRemoteGattDescriptorBlueZ::GetCharacteristic() const {
74 return characteristic_;
75 }
76
77 device::BluetoothGattCharacteristic::Permissions
78 BluetoothRemoteGattDescriptorBlueZ::GetPermissions() const {
79 // TODO(armansito): Once BlueZ defines the permissions, return the correct
80 // values here.
81 return device::BluetoothGattCharacteristic::PERMISSION_NONE;
82 }
83
84 void BluetoothRemoteGattDescriptorBlueZ::ReadRemoteDescriptor(
85 const ValueCallback& callback,
86 const ErrorCallback& error_callback) {
87 VLOG(1) << "Sending GATT characteristic descriptor read request to "
88 << "descriptor: " << GetIdentifier()
89 << ", UUID: " << GetUUID().canonical_value();
90
91 bluez::BluezDBusManager::Get()->GetBluetoothGattDescriptorClient()->ReadValue(
92 object_path_, callback,
93 base::Bind(&BluetoothRemoteGattDescriptorBlueZ::OnError,
94 weak_ptr_factory_.GetWeakPtr(), error_callback));
95 }
96
97 void BluetoothRemoteGattDescriptorBlueZ::WriteRemoteDescriptor(
98 const std::vector<uint8_t>& new_value,
99 const base::Closure& callback,
100 const ErrorCallback& error_callback) {
101 VLOG(1) << "Sending GATT characteristic descriptor write request to "
102 << "characteristic: " << GetIdentifier()
103 << ", UUID: " << GetUUID().canonical_value()
104 << ", with value: " << new_value << ".";
105
106 bluez::BluezDBusManager::Get()
107 ->GetBluetoothGattDescriptorClient()
108 ->WriteValue(object_path_, new_value, callback,
109 base::Bind(&BluetoothRemoteGattDescriptorBlueZ::OnError,
110 weak_ptr_factory_.GetWeakPtr(), error_callback));
111 }
112
113 void BluetoothRemoteGattDescriptorBlueZ::OnError(
114 const ErrorCallback& error_callback,
115 const std::string& error_name,
116 const std::string& error_message) {
117 VLOG(1) << "Operation failed: " << error_name
118 << ", message: " << error_message;
119
120 error_callback.Run(
121 BluetoothRemoteGattServiceBlueZ::DBusErrorToServiceError(error_name));
122 }
123
124 } // namespace bluez
OLDNEW
« no previous file with comments | « device/bluetooth/bluetooth_remote_gatt_descriptor_bluez.h ('k') | device/bluetooth/bluetooth_remote_gatt_service_android.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698