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

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

Powered by Google App Engine
This is Rietveld 408576698