| 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_descriptor_bluez.h" | 5 #include "device/bluetooth/bluetooth_remote_gatt_descriptor_bluez.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
| 10 #include "device/bluetooth/bluetooth_remote_gatt_characteristic_bluez.h" | 10 #include "device/bluetooth/bluetooth_remote_gatt_characteristic_bluez.h" |
| 11 #include "device/bluetooth/bluetooth_remote_gatt_service_bluez.h" | 11 #include "device/bluetooth/bluetooth_remote_gatt_service_bluez.h" |
| 12 #include "device/bluetooth/dbus/bluetooth_gatt_descriptor_client.h" | 12 #include "device/bluetooth/dbus/bluetooth_gatt_descriptor_client.h" |
| 13 #include "device/bluetooth/dbus/bluez_dbus_manager.h" | 13 #include "device/bluetooth/dbus/bluez_dbus_manager.h" |
| 14 | 14 |
| 15 namespace bluez { | 15 namespace bluez { |
| 16 | 16 |
| 17 namespace { | 17 namespace { |
| 18 | 18 |
| 19 // Stream operator for logging vector<uint8>. | 19 // Stream operator for logging vector<uint8_t>. |
| 20 std::ostream& operator<<(std::ostream& out, const std::vector<uint8> bytes) { | 20 std::ostream& operator<<(std::ostream& out, const std::vector<uint8_t> bytes) { |
| 21 out << "["; | 21 out << "["; |
| 22 for (std::vector<uint8>::const_iterator iter = bytes.begin(); | 22 for (std::vector<uint8_t>::const_iterator iter = bytes.begin(); |
| 23 iter != bytes.end(); ++iter) { | 23 iter != bytes.end(); ++iter) { |
| 24 out << base::StringPrintf("%02X", *iter); | 24 out << base::StringPrintf("%02X", *iter); |
| 25 } | 25 } |
| 26 return out << "]"; | 26 return out << "]"; |
| 27 } | 27 } |
| 28 | 28 |
| 29 } // namespace | 29 } // namespace |
| 30 | 30 |
| 31 BluetoothRemoteGattDescriptorBlueZ::BluetoothRemoteGattDescriptorBlueZ( | 31 BluetoothRemoteGattDescriptorBlueZ::BluetoothRemoteGattDescriptorBlueZ( |
| 32 BluetoothRemoteGattCharacteristicBlueZ* characteristic, | 32 BluetoothRemoteGattCharacteristicBlueZ* characteristic, |
| (...skipping 17 matching lines...) Expand all Loading... |
| 50 ->GetBluetoothGattDescriptorClient() | 50 ->GetBluetoothGattDescriptorClient() |
| 51 ->GetProperties(object_path_); | 51 ->GetProperties(object_path_); |
| 52 DCHECK(properties); | 52 DCHECK(properties); |
| 53 return device::BluetoothUUID(properties->uuid.value()); | 53 return device::BluetoothUUID(properties->uuid.value()); |
| 54 } | 54 } |
| 55 | 55 |
| 56 bool BluetoothRemoteGattDescriptorBlueZ::IsLocal() const { | 56 bool BluetoothRemoteGattDescriptorBlueZ::IsLocal() const { |
| 57 return false; | 57 return false; |
| 58 } | 58 } |
| 59 | 59 |
| 60 const std::vector<uint8>& BluetoothRemoteGattDescriptorBlueZ::GetValue() const { | 60 const std::vector<uint8_t>& BluetoothRemoteGattDescriptorBlueZ::GetValue() |
| 61 const { |
| 61 bluez::BluetoothGattDescriptorClient::Properties* properties = | 62 bluez::BluetoothGattDescriptorClient::Properties* properties = |
| 62 bluez::BluezDBusManager::Get() | 63 bluez::BluezDBusManager::Get() |
| 63 ->GetBluetoothGattDescriptorClient() | 64 ->GetBluetoothGattDescriptorClient() |
| 64 ->GetProperties(object_path_); | 65 ->GetProperties(object_path_); |
| 65 | 66 |
| 66 DCHECK(properties); | 67 DCHECK(properties); |
| 67 | 68 |
| 68 return properties->value.value(); | 69 return properties->value.value(); |
| 69 } | 70 } |
| 70 | 71 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 87 << "descriptor: " << GetIdentifier() | 88 << "descriptor: " << GetIdentifier() |
| 88 << ", UUID: " << GetUUID().canonical_value(); | 89 << ", UUID: " << GetUUID().canonical_value(); |
| 89 | 90 |
| 90 bluez::BluezDBusManager::Get()->GetBluetoothGattDescriptorClient()->ReadValue( | 91 bluez::BluezDBusManager::Get()->GetBluetoothGattDescriptorClient()->ReadValue( |
| 91 object_path_, callback, | 92 object_path_, callback, |
| 92 base::Bind(&BluetoothRemoteGattDescriptorBlueZ::OnError, | 93 base::Bind(&BluetoothRemoteGattDescriptorBlueZ::OnError, |
| 93 weak_ptr_factory_.GetWeakPtr(), error_callback)); | 94 weak_ptr_factory_.GetWeakPtr(), error_callback)); |
| 94 } | 95 } |
| 95 | 96 |
| 96 void BluetoothRemoteGattDescriptorBlueZ::WriteRemoteDescriptor( | 97 void BluetoothRemoteGattDescriptorBlueZ::WriteRemoteDescriptor( |
| 97 const std::vector<uint8>& new_value, | 98 const std::vector<uint8_t>& new_value, |
| 98 const base::Closure& callback, | 99 const base::Closure& callback, |
| 99 const ErrorCallback& error_callback) { | 100 const ErrorCallback& error_callback) { |
| 100 VLOG(1) << "Sending GATT characteristic descriptor write request to " | 101 VLOG(1) << "Sending GATT characteristic descriptor write request to " |
| 101 << "characteristic: " << GetIdentifier() | 102 << "characteristic: " << GetIdentifier() |
| 102 << ", UUID: " << GetUUID().canonical_value() | 103 << ", UUID: " << GetUUID().canonical_value() |
| 103 << ", with value: " << new_value << "."; | 104 << ", with value: " << new_value << "."; |
| 104 | 105 |
| 105 bluez::BluezDBusManager::Get() | 106 bluez::BluezDBusManager::Get() |
| 106 ->GetBluetoothGattDescriptorClient() | 107 ->GetBluetoothGattDescriptorClient() |
| 107 ->WriteValue(object_path_, new_value, callback, | 108 ->WriteValue(object_path_, new_value, callback, |
| 108 base::Bind(&BluetoothRemoteGattDescriptorBlueZ::OnError, | 109 base::Bind(&BluetoothRemoteGattDescriptorBlueZ::OnError, |
| 109 weak_ptr_factory_.GetWeakPtr(), error_callback)); | 110 weak_ptr_factory_.GetWeakPtr(), error_callback)); |
| 110 } | 111 } |
| 111 | 112 |
| 112 void BluetoothRemoteGattDescriptorBlueZ::OnError( | 113 void BluetoothRemoteGattDescriptorBlueZ::OnError( |
| 113 const ErrorCallback& error_callback, | 114 const ErrorCallback& error_callback, |
| 114 const std::string& error_name, | 115 const std::string& error_name, |
| 115 const std::string& error_message) { | 116 const std::string& error_message) { |
| 116 VLOG(1) << "Operation failed: " << error_name | 117 VLOG(1) << "Operation failed: " << error_name |
| 117 << ", message: " << error_message; | 118 << ", message: " << error_message; |
| 118 | 119 |
| 119 error_callback.Run( | 120 error_callback.Run( |
| 120 BluetoothRemoteGattServiceBlueZ::DBusErrorToServiceError(error_name)); | 121 BluetoothRemoteGattServiceBlueZ::DBusErrorToServiceError(error_name)); |
| 121 } | 122 } |
| 122 | 123 |
| 123 } // namespace bluez | 124 } // namespace bluez |
| OLD | NEW |