| 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_chromeos.h" | 5 #include "device/bluetooth/bluetooth_remote_gatt_descriptor_chromeos.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 "chromeos/dbus/bluetooth_gatt_descriptor_client.h" | |
| 11 #include "chromeos/dbus/dbus_thread_manager.h" | |
| 12 #include "device/bluetooth/bluetooth_remote_gatt_characteristic_chromeos.h" | 10 #include "device/bluetooth/bluetooth_remote_gatt_characteristic_chromeos.h" |
| 13 #include "device/bluetooth/bluetooth_remote_gatt_service_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 | 14 |
| 15 namespace chromeos { | 15 namespace chromeos { |
| 16 | 16 |
| 17 namespace { | 17 namespace { |
| 18 | 18 |
| 19 // Stream operator for logging vector<uint8>. | 19 // Stream operator for logging vector<uint8>. |
| 20 std::ostream& operator<<(std::ostream& out, const std::vector<uint8> bytes) { | 20 std::ostream& operator<<(std::ostream& out, const std::vector<uint8> bytes) { |
| 21 out << "["; | 21 out << "["; |
| 22 for (std::vector<uint8>::const_iterator iter = bytes.begin(); | 22 for (std::vector<uint8>::const_iterator iter = bytes.begin(); |
| 23 iter != bytes.end(); ++iter) { | 23 iter != bytes.end(); ++iter) { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 40 | 40 |
| 41 BluetoothRemoteGattDescriptorChromeOS:: | 41 BluetoothRemoteGattDescriptorChromeOS:: |
| 42 ~BluetoothRemoteGattDescriptorChromeOS() { | 42 ~BluetoothRemoteGattDescriptorChromeOS() { |
| 43 } | 43 } |
| 44 | 44 |
| 45 std::string BluetoothRemoteGattDescriptorChromeOS::GetIdentifier() const { | 45 std::string BluetoothRemoteGattDescriptorChromeOS::GetIdentifier() const { |
| 46 return object_path_.value(); | 46 return object_path_.value(); |
| 47 } | 47 } |
| 48 | 48 |
| 49 device::BluetoothUUID BluetoothRemoteGattDescriptorChromeOS::GetUUID() const { | 49 device::BluetoothUUID BluetoothRemoteGattDescriptorChromeOS::GetUUID() const { |
| 50 BluetoothGattDescriptorClient::Properties* properties = | 50 bluez::BluetoothGattDescriptorClient::Properties* properties = |
| 51 DBusThreadManager::Get()->GetBluetoothGattDescriptorClient()-> | 51 bluez::BluezDBusManager::Get() |
| 52 GetProperties(object_path_); | 52 ->GetBluetoothGattDescriptorClient() |
| 53 ->GetProperties(object_path_); |
| 53 DCHECK(properties); | 54 DCHECK(properties); |
| 54 return device::BluetoothUUID(properties->uuid.value()); | 55 return device::BluetoothUUID(properties->uuid.value()); |
| 55 } | 56 } |
| 56 | 57 |
| 57 bool BluetoothRemoteGattDescriptorChromeOS::IsLocal() const { | 58 bool BluetoothRemoteGattDescriptorChromeOS::IsLocal() const { |
| 58 return false; | 59 return false; |
| 59 } | 60 } |
| 60 | 61 |
| 61 const std::vector<uint8>& | 62 const std::vector<uint8>& |
| 62 BluetoothRemoteGattDescriptorChromeOS::GetValue() const { | 63 BluetoothRemoteGattDescriptorChromeOS::GetValue() const { |
| 63 BluetoothGattDescriptorClient::Properties* properties = | 64 bluez::BluetoothGattDescriptorClient::Properties* properties = |
| 64 DBusThreadManager::Get() | 65 bluez::BluezDBusManager::Get() |
| 65 ->GetBluetoothGattDescriptorClient() | 66 ->GetBluetoothGattDescriptorClient() |
| 66 ->GetProperties(object_path_); | 67 ->GetProperties(object_path_); |
| 67 | 68 |
| 68 DCHECK(properties); | 69 DCHECK(properties); |
| 69 | 70 |
| 70 return properties->value.value(); | 71 return properties->value.value(); |
| 71 } | 72 } |
| 72 | 73 |
| 73 device::BluetoothGattCharacteristic* | 74 device::BluetoothGattCharacteristic* |
| 74 BluetoothRemoteGattDescriptorChromeOS::GetCharacteristic() const { | 75 BluetoothRemoteGattDescriptorChromeOS::GetCharacteristic() const { |
| 75 return characteristic_; | 76 return characteristic_; |
| 76 } | 77 } |
| 77 | 78 |
| 78 device::BluetoothGattCharacteristic::Permissions | 79 device::BluetoothGattCharacteristic::Permissions |
| 79 BluetoothRemoteGattDescriptorChromeOS::GetPermissions() const { | 80 BluetoothRemoteGattDescriptorChromeOS::GetPermissions() const { |
| 80 // TODO(armansito): Once BlueZ defines the permissions, return the correct | 81 // TODO(armansito): Once BlueZ defines the permissions, return the correct |
| 81 // values here. | 82 // values here. |
| 82 return device::BluetoothGattCharacteristic::PERMISSION_NONE; | 83 return device::BluetoothGattCharacteristic::PERMISSION_NONE; |
| 83 } | 84 } |
| 84 | 85 |
| 85 void BluetoothRemoteGattDescriptorChromeOS::ReadRemoteDescriptor( | 86 void BluetoothRemoteGattDescriptorChromeOS::ReadRemoteDescriptor( |
| 86 const ValueCallback& callback, | 87 const ValueCallback& callback, |
| 87 const ErrorCallback& error_callback) { | 88 const ErrorCallback& error_callback) { |
| 88 VLOG(1) << "Sending GATT characteristic descriptor read request to " | 89 VLOG(1) << "Sending GATT characteristic descriptor read request to " |
| 89 << "descriptor: " << GetIdentifier() << ", UUID: " | 90 << "descriptor: " << GetIdentifier() << ", UUID: " |
| 90 << GetUUID().canonical_value(); | 91 << GetUUID().canonical_value(); |
| 91 | 92 |
| 92 DBusThreadManager::Get()->GetBluetoothGattDescriptorClient()->ReadValue( | 93 bluez::BluezDBusManager::Get()->GetBluetoothGattDescriptorClient()->ReadValue( |
| 93 object_path_, callback, | 94 object_path_, callback, |
| 94 base::Bind(&BluetoothRemoteGattDescriptorChromeOS::OnError, | 95 base::Bind(&BluetoothRemoteGattDescriptorChromeOS::OnError, |
| 95 weak_ptr_factory_.GetWeakPtr(), error_callback)); | 96 weak_ptr_factory_.GetWeakPtr(), error_callback)); |
| 96 } | 97 } |
| 97 | 98 |
| 98 void BluetoothRemoteGattDescriptorChromeOS::WriteRemoteDescriptor( | 99 void BluetoothRemoteGattDescriptorChromeOS::WriteRemoteDescriptor( |
| 99 const std::vector<uint8>& new_value, | 100 const std::vector<uint8>& new_value, |
| 100 const base::Closure& callback, | 101 const base::Closure& callback, |
| 101 const ErrorCallback& error_callback) { | 102 const ErrorCallback& error_callback) { |
| 102 VLOG(1) << "Sending GATT characteristic descriptor write request to " | 103 VLOG(1) << "Sending GATT characteristic descriptor write request to " |
| 103 << "characteristic: " << GetIdentifier() << ", UUID: " | 104 << "characteristic: " << GetIdentifier() << ", UUID: " |
| 104 << GetUUID().canonical_value() << ", with value: " | 105 << GetUUID().canonical_value() << ", with value: " |
| 105 << new_value << "."; | 106 << new_value << "."; |
| 106 | 107 |
| 107 DBusThreadManager::Get()->GetBluetoothGattDescriptorClient()->WriteValue( | 108 bluez::BluezDBusManager::Get() |
| 108 object_path_, | 109 ->GetBluetoothGattDescriptorClient() |
| 109 new_value, | 110 ->WriteValue(object_path_, new_value, callback, |
| 110 callback, | 111 base::Bind(&BluetoothRemoteGattDescriptorChromeOS::OnError, |
| 111 base::Bind(&BluetoothRemoteGattDescriptorChromeOS::OnError, | 112 weak_ptr_factory_.GetWeakPtr(), error_callback)); |
| 112 weak_ptr_factory_.GetWeakPtr(), | |
| 113 error_callback)); | |
| 114 } | 113 } |
| 115 | 114 |
| 116 void BluetoothRemoteGattDescriptorChromeOS::OnError( | 115 void BluetoothRemoteGattDescriptorChromeOS::OnError( |
| 117 const ErrorCallback& error_callback, | 116 const ErrorCallback& error_callback, |
| 118 const std::string& error_name, | 117 const std::string& error_name, |
| 119 const std::string& error_message) { | 118 const std::string& error_message) { |
| 120 VLOG(1) << "Operation failed: " << error_name | 119 VLOG(1) << "Operation failed: " << error_name |
| 121 << ", message: " << error_message; | 120 << ", message: " << error_message; |
| 122 | 121 |
| 123 error_callback.Run( | 122 error_callback.Run( |
| 124 BluetoothRemoteGattServiceChromeOS::DBusErrorToServiceError(error_name)); | 123 BluetoothRemoteGattServiceChromeOS::DBusErrorToServiceError(error_name)); |
| 125 } | 124 } |
| 126 | 125 |
| 127 } // namespace chromeos | 126 } // namespace chromeos |
| OLD | NEW |