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

Side by Side Diff: device/bluetooth/bluetooth_remote_gatt_descriptor_chromeos.cc

Issue 1415573014: Reland "Add Linux support for the Bluetooth API" (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: build fix. Created 5 years, 1 month 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_chromeos.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_chromeos.h"
11 #include "device/bluetooth/bluetooth_remote_gatt_service_chromeos.h"
12 #include "device/bluetooth/dbus/bluetooth_gatt_descriptor_client.h"
13 #include "device/bluetooth/dbus/bluez_dbus_manager.h"
14
15 namespace chromeos {
16
17 namespace {
18
19 // Stream operator for logging vector<uint8>.
20 std::ostream& operator<<(std::ostream& out, const std::vector<uint8> bytes) {
21 out << "[";
22 for (std::vector<uint8>::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 BluetoothRemoteGattDescriptorChromeOS::BluetoothRemoteGattDescriptorChromeOS(
32 BluetoothRemoteGattCharacteristicChromeOS* 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 BluetoothRemoteGattDescriptorChromeOS::
42 ~BluetoothRemoteGattDescriptorChromeOS() {
43 }
44
45 std::string BluetoothRemoteGattDescriptorChromeOS::GetIdentifier() const {
46 return object_path_.value();
47 }
48
49 device::BluetoothUUID BluetoothRemoteGattDescriptorChromeOS::GetUUID() const {
50 bluez::BluetoothGattDescriptorClient::Properties* properties =
51 bluez::BluezDBusManager::Get()
52 ->GetBluetoothGattDescriptorClient()
53 ->GetProperties(object_path_);
54 DCHECK(properties);
55 return device::BluetoothUUID(properties->uuid.value());
56 }
57
58 bool BluetoothRemoteGattDescriptorChromeOS::IsLocal() const {
59 return false;
60 }
61
62 const std::vector<uint8>&
63 BluetoothRemoteGattDescriptorChromeOS::GetValue() const {
64 bluez::BluetoothGattDescriptorClient::Properties* properties =
65 bluez::BluezDBusManager::Get()
66 ->GetBluetoothGattDescriptorClient()
67 ->GetProperties(object_path_);
68
69 DCHECK(properties);
70
71 return properties->value.value();
72 }
73
74 device::BluetoothGattCharacteristic*
75 BluetoothRemoteGattDescriptorChromeOS::GetCharacteristic() const {
76 return characteristic_;
77 }
78
79 device::BluetoothGattCharacteristic::Permissions
80 BluetoothRemoteGattDescriptorChromeOS::GetPermissions() const {
81 // TODO(armansito): Once BlueZ defines the permissions, return the correct
82 // values here.
83 return device::BluetoothGattCharacteristic::PERMISSION_NONE;
84 }
85
86 void BluetoothRemoteGattDescriptorChromeOS::ReadRemoteDescriptor(
87 const ValueCallback& callback,
88 const ErrorCallback& error_callback) {
89 VLOG(1) << "Sending GATT characteristic descriptor read request to "
90 << "descriptor: " << GetIdentifier() << ", UUID: "
91 << GetUUID().canonical_value();
92
93 bluez::BluezDBusManager::Get()->GetBluetoothGattDescriptorClient()->ReadValue(
94 object_path_, callback,
95 base::Bind(&BluetoothRemoteGattDescriptorChromeOS::OnError,
96 weak_ptr_factory_.GetWeakPtr(), error_callback));
97 }
98
99 void BluetoothRemoteGattDescriptorChromeOS::WriteRemoteDescriptor(
100 const std::vector<uint8>& new_value,
101 const base::Closure& callback,
102 const ErrorCallback& error_callback) {
103 VLOG(1) << "Sending GATT characteristic descriptor write request to "
104 << "characteristic: " << GetIdentifier() << ", UUID: "
105 << GetUUID().canonical_value() << ", with value: "
106 << new_value << ".";
107
108 bluez::BluezDBusManager::Get()
109 ->GetBluetoothGattDescriptorClient()
110 ->WriteValue(object_path_, new_value, callback,
111 base::Bind(&BluetoothRemoteGattDescriptorChromeOS::OnError,
112 weak_ptr_factory_.GetWeakPtr(), error_callback));
113 }
114
115 void BluetoothRemoteGattDescriptorChromeOS::OnError(
116 const ErrorCallback& error_callback,
117 const std::string& error_name,
118 const std::string& error_message) {
119 VLOG(1) << "Operation failed: " << error_name
120 << ", message: " << error_message;
121
122 error_callback.Run(
123 BluetoothRemoteGattServiceChromeOS::DBusErrorToServiceError(error_name));
124 }
125
126 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698