OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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/bluetooth_remote_gatt_characteristic_bluez.h" | 5 #include "device/bluetooth/bluetooth_remote_gatt_characteristic_bluez.h" |
6 | 6 |
7 #include <limits> | 7 #include <limits> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
11 #include "device/bluetooth/bluetooth_adapter_bluez.h" | 11 #include "device/bluetooth/bluetooth_adapter_bluez.h" |
12 #include "device/bluetooth/bluetooth_device.h" | 12 #include "device/bluetooth/bluetooth_device.h" |
13 #include "device/bluetooth/bluetooth_gatt_notify_session_bluez.h" | 13 #include "device/bluetooth/bluetooth_gatt_notify_session_bluez.h" |
14 #include "device/bluetooth/bluetooth_remote_gatt_characteristic_bluez.h" | 14 #include "device/bluetooth/bluetooth_remote_gatt_characteristic_bluez.h" |
15 #include "device/bluetooth/bluetooth_remote_gatt_descriptor_bluez.h" | 15 #include "device/bluetooth/bluetooth_remote_gatt_descriptor_bluez.h" |
16 #include "device/bluetooth/bluetooth_remote_gatt_service_bluez.h" | 16 #include "device/bluetooth/bluetooth_remote_gatt_service_bluez.h" |
17 #include "device/bluetooth/dbus/bluez_dbus_manager.h" | 17 #include "device/bluetooth/dbus/bluez_dbus_manager.h" |
18 #include "third_party/cros_system_api/dbus/service_constants.h" | 18 #include "third_party/cros_system_api/dbus/service_constants.h" |
19 | 19 |
20 namespace bluez { | 20 namespace bluez { |
21 | 21 |
22 namespace { | 22 namespace { |
23 | 23 |
24 // Stream operator for logging vector<uint8>. | 24 // Stream operator for logging vector<uint8_t>. |
25 std::ostream& operator<<(std::ostream& out, const std::vector<uint8> bytes) { | 25 std::ostream& operator<<(std::ostream& out, const std::vector<uint8_t> bytes) { |
26 out << "["; | 26 out << "["; |
27 for (std::vector<uint8>::const_iterator iter = bytes.begin(); | 27 for (std::vector<uint8_t>::const_iterator iter = bytes.begin(); |
28 iter != bytes.end(); ++iter) { | 28 iter != bytes.end(); ++iter) { |
29 out << base::StringPrintf("%02X", *iter); | 29 out << base::StringPrintf("%02X", *iter); |
30 } | 30 } |
31 return out << "]"; | 31 return out << "]"; |
32 } | 32 } |
33 | 33 |
34 } // namespace | 34 } // namespace |
35 | 35 |
36 BluetoothRemoteGattCharacteristicBlueZ::BluetoothRemoteGattCharacteristicBlueZ( | 36 BluetoothRemoteGattCharacteristicBlueZ::BluetoothRemoteGattCharacteristicBlueZ( |
37 BluetoothRemoteGattServiceBlueZ* service, | 37 BluetoothRemoteGattServiceBlueZ* service, |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 ->GetBluetoothGattCharacteristicClient() | 87 ->GetBluetoothGattCharacteristicClient() |
88 ->GetProperties(object_path_); | 88 ->GetProperties(object_path_); |
89 DCHECK(properties); | 89 DCHECK(properties); |
90 return device::BluetoothUUID(properties->uuid.value()); | 90 return device::BluetoothUUID(properties->uuid.value()); |
91 } | 91 } |
92 | 92 |
93 bool BluetoothRemoteGattCharacteristicBlueZ::IsLocal() const { | 93 bool BluetoothRemoteGattCharacteristicBlueZ::IsLocal() const { |
94 return false; | 94 return false; |
95 } | 95 } |
96 | 96 |
97 const std::vector<uint8>& BluetoothRemoteGattCharacteristicBlueZ::GetValue() | 97 const std::vector<uint8_t>& BluetoothRemoteGattCharacteristicBlueZ::GetValue() |
98 const { | 98 const { |
99 bluez::BluetoothGattCharacteristicClient::Properties* properties = | 99 bluez::BluetoothGattCharacteristicClient::Properties* properties = |
100 bluez::BluezDBusManager::Get() | 100 bluez::BluezDBusManager::Get() |
101 ->GetBluetoothGattCharacteristicClient() | 101 ->GetBluetoothGattCharacteristicClient() |
102 ->GetProperties(object_path_); | 102 ->GetProperties(object_path_); |
103 | 103 |
104 DCHECK(properties); | 104 DCHECK(properties); |
105 | 105 |
106 return properties->value.value(); | 106 return properties->value.value(); |
107 } | 107 } |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 return iter->second; | 184 return iter->second; |
185 } | 185 } |
186 | 186 |
187 bool BluetoothRemoteGattCharacteristicBlueZ::AddDescriptor( | 187 bool BluetoothRemoteGattCharacteristicBlueZ::AddDescriptor( |
188 device::BluetoothGattDescriptor* descriptor) { | 188 device::BluetoothGattDescriptor* descriptor) { |
189 VLOG(1) << "Descriptors cannot be added to a remote GATT characteristic."; | 189 VLOG(1) << "Descriptors cannot be added to a remote GATT characteristic."; |
190 return false; | 190 return false; |
191 } | 191 } |
192 | 192 |
193 bool BluetoothRemoteGattCharacteristicBlueZ::UpdateValue( | 193 bool BluetoothRemoteGattCharacteristicBlueZ::UpdateValue( |
194 const std::vector<uint8>& value) { | 194 const std::vector<uint8_t>& value) { |
195 VLOG(1) << "Cannot update the value of a remote GATT characteristic."; | 195 VLOG(1) << "Cannot update the value of a remote GATT characteristic."; |
196 return false; | 196 return false; |
197 } | 197 } |
198 | 198 |
199 void BluetoothRemoteGattCharacteristicBlueZ::ReadRemoteCharacteristic( | 199 void BluetoothRemoteGattCharacteristicBlueZ::ReadRemoteCharacteristic( |
200 const ValueCallback& callback, | 200 const ValueCallback& callback, |
201 const ErrorCallback& error_callback) { | 201 const ErrorCallback& error_callback) { |
202 VLOG(1) << "Sending GATT characteristic read request to characteristic: " | 202 VLOG(1) << "Sending GATT characteristic read request to characteristic: " |
203 << GetIdentifier() << ", UUID: " << GetUUID().canonical_value() | 203 << GetIdentifier() << ", UUID: " << GetUUID().canonical_value() |
204 << "."; | 204 << "."; |
205 | 205 |
206 bluez::BluezDBusManager::Get() | 206 bluez::BluezDBusManager::Get() |
207 ->GetBluetoothGattCharacteristicClient() | 207 ->GetBluetoothGattCharacteristicClient() |
208 ->ReadValue(object_path_, callback, | 208 ->ReadValue(object_path_, callback, |
209 base::Bind(&BluetoothRemoteGattCharacteristicBlueZ::OnError, | 209 base::Bind(&BluetoothRemoteGattCharacteristicBlueZ::OnError, |
210 weak_ptr_factory_.GetWeakPtr(), error_callback)); | 210 weak_ptr_factory_.GetWeakPtr(), error_callback)); |
211 } | 211 } |
212 | 212 |
213 void BluetoothRemoteGattCharacteristicBlueZ::WriteRemoteCharacteristic( | 213 void BluetoothRemoteGattCharacteristicBlueZ::WriteRemoteCharacteristic( |
214 const std::vector<uint8>& new_value, | 214 const std::vector<uint8_t>& new_value, |
215 const base::Closure& callback, | 215 const base::Closure& callback, |
216 const ErrorCallback& error_callback) { | 216 const ErrorCallback& error_callback) { |
217 VLOG(1) << "Sending GATT characteristic write request to characteristic: " | 217 VLOG(1) << "Sending GATT characteristic write request to characteristic: " |
218 << GetIdentifier() << ", UUID: " << GetUUID().canonical_value() | 218 << GetIdentifier() << ", UUID: " << GetUUID().canonical_value() |
219 << ", with value: " << new_value << "."; | 219 << ", with value: " << new_value << "."; |
220 | 220 |
221 bluez::BluezDBusManager::Get() | 221 bluez::BluezDBusManager::Get() |
222 ->GetBluetoothGattCharacteristicClient() | 222 ->GetBluetoothGattCharacteristicClient() |
223 ->WriteValue(object_path_, new_value, callback, | 223 ->WriteValue(object_path_, new_value, callback, |
224 base::Bind(&BluetoothRemoteGattCharacteristicBlueZ::OnError, | 224 base::Bind(&BluetoothRemoteGattCharacteristicBlueZ::OnError, |
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
466 | 466 |
467 void BluetoothRemoteGattCharacteristicBlueZ::ProcessStartNotifyQueue() { | 467 void BluetoothRemoteGattCharacteristicBlueZ::ProcessStartNotifyQueue() { |
468 while (!pending_start_notify_calls_.empty()) { | 468 while (!pending_start_notify_calls_.empty()) { |
469 PendingStartNotifyCall callbacks = pending_start_notify_calls_.front(); | 469 PendingStartNotifyCall callbacks = pending_start_notify_calls_.front(); |
470 pending_start_notify_calls_.pop(); | 470 pending_start_notify_calls_.pop(); |
471 StartNotifySession(callbacks.first, callbacks.second); | 471 StartNotifySession(callbacks.first, callbacks.second); |
472 } | 472 } |
473 } | 473 } |
474 | 474 |
475 } // namespace bluez | 475 } // namespace bluez |
OLD | NEW |