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_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_chromeos.h" | 10 #include "device/bluetooth/bluetooth_remote_gatt_characteristic_bluez.h" |
11 #include "device/bluetooth/bluetooth_remote_gatt_service_chromeos.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 chromeos { | 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>. |
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) { |
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 BluetoothRemoteGattDescriptorChromeOS::BluetoothRemoteGattDescriptorChromeOS( | 31 BluetoothRemoteGattDescriptorBlueZ::BluetoothRemoteGattDescriptorBlueZ( |
32 BluetoothRemoteGattCharacteristicChromeOS* characteristic, | 32 BluetoothRemoteGattCharacteristicBlueZ* characteristic, |
33 const dbus::ObjectPath& object_path) | 33 const dbus::ObjectPath& object_path) |
34 : object_path_(object_path), | 34 : object_path_(object_path), |
35 characteristic_(characteristic), | 35 characteristic_(characteristic), |
36 weak_ptr_factory_(this) { | 36 weak_ptr_factory_(this) { |
37 VLOG(1) << "Creating remote GATT descriptor with identifier: " | 37 VLOG(1) << "Creating remote GATT descriptor with identifier: " |
38 << GetIdentifier() << ", UUID: " << GetUUID().canonical_value(); | 38 << GetIdentifier() << ", UUID: " << GetUUID().canonical_value(); |
39 } | 39 } |
40 | 40 |
41 BluetoothRemoteGattDescriptorChromeOS:: | 41 BluetoothRemoteGattDescriptorBlueZ::~BluetoothRemoteGattDescriptorBlueZ() {} |
42 ~BluetoothRemoteGattDescriptorChromeOS() { | |
43 } | |
44 | 42 |
45 std::string BluetoothRemoteGattDescriptorChromeOS::GetIdentifier() const { | 43 std::string BluetoothRemoteGattDescriptorBlueZ::GetIdentifier() const { |
46 return object_path_.value(); | 44 return object_path_.value(); |
47 } | 45 } |
48 | 46 |
49 device::BluetoothUUID BluetoothRemoteGattDescriptorChromeOS::GetUUID() const { | 47 device::BluetoothUUID BluetoothRemoteGattDescriptorBlueZ::GetUUID() const { |
50 bluez::BluetoothGattDescriptorClient::Properties* properties = | 48 bluez::BluetoothGattDescriptorClient::Properties* properties = |
51 bluez::BluezDBusManager::Get() | 49 bluez::BluezDBusManager::Get() |
52 ->GetBluetoothGattDescriptorClient() | 50 ->GetBluetoothGattDescriptorClient() |
53 ->GetProperties(object_path_); | 51 ->GetProperties(object_path_); |
54 DCHECK(properties); | 52 DCHECK(properties); |
55 return device::BluetoothUUID(properties->uuid.value()); | 53 return device::BluetoothUUID(properties->uuid.value()); |
56 } | 54 } |
57 | 55 |
58 bool BluetoothRemoteGattDescriptorChromeOS::IsLocal() const { | 56 bool BluetoothRemoteGattDescriptorBlueZ::IsLocal() const { |
59 return false; | 57 return false; |
60 } | 58 } |
61 | 59 |
62 const std::vector<uint8>& | 60 const std::vector<uint8>& BluetoothRemoteGattDescriptorBlueZ::GetValue() const { |
63 BluetoothRemoteGattDescriptorChromeOS::GetValue() const { | |
64 bluez::BluetoothGattDescriptorClient::Properties* properties = | 61 bluez::BluetoothGattDescriptorClient::Properties* properties = |
65 bluez::BluezDBusManager::Get() | 62 bluez::BluezDBusManager::Get() |
66 ->GetBluetoothGattDescriptorClient() | 63 ->GetBluetoothGattDescriptorClient() |
67 ->GetProperties(object_path_); | 64 ->GetProperties(object_path_); |
68 | 65 |
69 DCHECK(properties); | 66 DCHECK(properties); |
70 | 67 |
71 return properties->value.value(); | 68 return properties->value.value(); |
72 } | 69 } |
73 | 70 |
74 device::BluetoothGattCharacteristic* | 71 device::BluetoothGattCharacteristic* |
75 BluetoothRemoteGattDescriptorChromeOS::GetCharacteristic() const { | 72 BluetoothRemoteGattDescriptorBlueZ::GetCharacteristic() const { |
76 return characteristic_; | 73 return characteristic_; |
77 } | 74 } |
78 | 75 |
79 device::BluetoothGattCharacteristic::Permissions | 76 device::BluetoothGattCharacteristic::Permissions |
80 BluetoothRemoteGattDescriptorChromeOS::GetPermissions() const { | 77 BluetoothRemoteGattDescriptorBlueZ::GetPermissions() const { |
81 // TODO(armansito): Once BlueZ defines the permissions, return the correct | 78 // TODO(armansito): Once BlueZ defines the permissions, return the correct |
82 // values here. | 79 // values here. |
83 return device::BluetoothGattCharacteristic::PERMISSION_NONE; | 80 return device::BluetoothGattCharacteristic::PERMISSION_NONE; |
84 } | 81 } |
85 | 82 |
86 void BluetoothRemoteGattDescriptorChromeOS::ReadRemoteDescriptor( | 83 void BluetoothRemoteGattDescriptorBlueZ::ReadRemoteDescriptor( |
87 const ValueCallback& callback, | 84 const ValueCallback& callback, |
88 const ErrorCallback& error_callback) { | 85 const ErrorCallback& error_callback) { |
89 VLOG(1) << "Sending GATT characteristic descriptor read request to " | 86 VLOG(1) << "Sending GATT characteristic descriptor read request to " |
90 << "descriptor: " << GetIdentifier() << ", UUID: " | 87 << "descriptor: " << GetIdentifier() |
91 << GetUUID().canonical_value(); | 88 << ", UUID: " << GetUUID().canonical_value(); |
92 | 89 |
93 bluez::BluezDBusManager::Get()->GetBluetoothGattDescriptorClient()->ReadValue( | 90 bluez::BluezDBusManager::Get()->GetBluetoothGattDescriptorClient()->ReadValue( |
94 object_path_, callback, | 91 object_path_, callback, |
95 base::Bind(&BluetoothRemoteGattDescriptorChromeOS::OnError, | 92 base::Bind(&BluetoothRemoteGattDescriptorBlueZ::OnError, |
96 weak_ptr_factory_.GetWeakPtr(), error_callback)); | 93 weak_ptr_factory_.GetWeakPtr(), error_callback)); |
97 } | 94 } |
98 | 95 |
99 void BluetoothRemoteGattDescriptorChromeOS::WriteRemoteDescriptor( | 96 void BluetoothRemoteGattDescriptorBlueZ::WriteRemoteDescriptor( |
100 const std::vector<uint8>& new_value, | 97 const std::vector<uint8>& new_value, |
101 const base::Closure& callback, | 98 const base::Closure& callback, |
102 const ErrorCallback& error_callback) { | 99 const ErrorCallback& error_callback) { |
103 VLOG(1) << "Sending GATT characteristic descriptor write request to " | 100 VLOG(1) << "Sending GATT characteristic descriptor write request to " |
104 << "characteristic: " << GetIdentifier() << ", UUID: " | 101 << "characteristic: " << GetIdentifier() |
105 << GetUUID().canonical_value() << ", with value: " | 102 << ", UUID: " << GetUUID().canonical_value() |
106 << new_value << "."; | 103 << ", with value: " << new_value << "."; |
107 | 104 |
108 bluez::BluezDBusManager::Get() | 105 bluez::BluezDBusManager::Get() |
109 ->GetBluetoothGattDescriptorClient() | 106 ->GetBluetoothGattDescriptorClient() |
110 ->WriteValue(object_path_, new_value, callback, | 107 ->WriteValue(object_path_, new_value, callback, |
111 base::Bind(&BluetoothRemoteGattDescriptorChromeOS::OnError, | 108 base::Bind(&BluetoothRemoteGattDescriptorBlueZ::OnError, |
112 weak_ptr_factory_.GetWeakPtr(), error_callback)); | 109 weak_ptr_factory_.GetWeakPtr(), error_callback)); |
113 } | 110 } |
114 | 111 |
115 void BluetoothRemoteGattDescriptorChromeOS::OnError( | 112 void BluetoothRemoteGattDescriptorBlueZ::OnError( |
116 const ErrorCallback& error_callback, | 113 const ErrorCallback& error_callback, |
117 const std::string& error_name, | 114 const std::string& error_name, |
118 const std::string& error_message) { | 115 const std::string& error_message) { |
119 VLOG(1) << "Operation failed: " << error_name | 116 VLOG(1) << "Operation failed: " << error_name |
120 << ", message: " << error_message; | 117 << ", message: " << error_message; |
121 | 118 |
122 error_callback.Run( | 119 error_callback.Run( |
123 BluetoothRemoteGattServiceChromeOS::DBusErrorToServiceError(error_name)); | 120 BluetoothRemoteGattServiceBlueZ::DBusErrorToServiceError(error_name)); |
124 } | 121 } |
125 | 122 |
126 } // namespace chromeos | 123 } // namespace bluez |
OLD | NEW |