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 "chromeos/dbus/bluetooth_gatt_characteristic_service_provider.h" | 5 #include "device/bluetooth/dbus/bluetooth_gatt_characteristic_service_provider.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/memory/weak_ptr.h" | 9 #include "base/memory/weak_ptr.h" |
10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
11 #include "base/threading/platform_thread.h" | 11 #include "base/threading/platform_thread.h" |
12 #include "chromeos/dbus/dbus_thread_manager.h" | |
13 #include "chromeos/dbus/fake_bluetooth_gatt_characteristic_service_provider.h" | |
14 #include "dbus/exported_object.h" | 12 #include "dbus/exported_object.h" |
15 #include "dbus/message.h" | 13 #include "dbus/message.h" |
| 14 #include "device/bluetooth/dbus/bluez_dbus_manager.h" |
| 15 #include "device/bluetooth/dbus/fake_bluetooth_gatt_characteristic_service_provi
der.h" |
16 #include "third_party/cros_system_api/dbus/service_constants.h" | 16 #include "third_party/cros_system_api/dbus/service_constants.h" |
17 | 17 |
18 namespace chromeos { | 18 namespace bluez { |
19 namespace { | 19 namespace { |
20 const char kErrorInvalidArgs[] = | 20 const char kErrorInvalidArgs[] = "org.freedesktop.DBus.Error.InvalidArgs"; |
21 "org.freedesktop.DBus.Error.InvalidArgs"; | |
22 const char kErrorPropertyReadOnly[] = | 21 const char kErrorPropertyReadOnly[] = |
23 "org.freedesktop.DBus.Error.PropertyReadOnly"; | 22 "org.freedesktop.DBus.Error.PropertyReadOnly"; |
24 const char kErrorFailed[] = | 23 const char kErrorFailed[] = "org.freedesktop.DBus.Error.Failed"; |
25 "org.freedesktop.DBus.Error.Failed"; | |
26 } // namespace | 24 } // namespace |
27 | 25 |
28 // The BluetoothGattCharacteristicServiceProvider implementation used in | 26 // The BluetoothGattCharacteristicServiceProvider implementation used in |
29 // production. | 27 // production. |
30 class BluetoothGattCharacteristicServiceProviderImpl | 28 class BluetoothGattCharacteristicServiceProviderImpl |
31 : public BluetoothGattCharacteristicServiceProvider { | 29 : public BluetoothGattCharacteristicServiceProvider { |
32 public: | 30 public: |
33 BluetoothGattCharacteristicServiceProviderImpl( | 31 BluetoothGattCharacteristicServiceProviderImpl( |
34 dbus::Bus* bus, | 32 dbus::Bus* bus, |
35 const dbus::ObjectPath& object_path, | 33 const dbus::ObjectPath& object_path, |
36 Delegate* delegate, | 34 Delegate* delegate, |
37 const std::string& uuid, | 35 const std::string& uuid, |
38 const std::vector<std::string>& flags, | 36 const std::vector<std::string>& flags, |
39 const std::vector<std::string>& permissions, | 37 const std::vector<std::string>& permissions, |
40 const dbus::ObjectPath& service_path) | 38 const dbus::ObjectPath& service_path) |
41 : origin_thread_id_(base::PlatformThread::CurrentId()), | 39 : origin_thread_id_(base::PlatformThread::CurrentId()), |
42 uuid_(uuid), | 40 uuid_(uuid), |
43 bus_(bus), | 41 bus_(bus), |
44 delegate_(delegate), | 42 delegate_(delegate), |
45 object_path_(object_path), | 43 object_path_(object_path), |
46 service_path_(service_path), | 44 service_path_(service_path), |
47 weak_ptr_factory_(this) { | 45 weak_ptr_factory_(this) { |
48 VLOG(1) << "Created Bluetooth GATT characteristic: " << object_path.value() | 46 VLOG(1) << "Created Bluetooth GATT characteristic: " << object_path.value() |
49 << " UUID: " << uuid; | 47 << " UUID: " << uuid; |
50 DCHECK(bus_); | 48 DCHECK(bus_); |
51 DCHECK(delegate_); | 49 DCHECK(delegate_); |
52 DCHECK(!uuid_.empty()); | 50 DCHECK(!uuid_.empty()); |
53 DCHECK(object_path_.IsValid()); | 51 DCHECK(object_path_.IsValid()); |
54 DCHECK(service_path_.IsValid()); | 52 DCHECK(service_path_.IsValid()); |
55 DCHECK(base::StartsWith(object_path_.value(), | 53 DCHECK(base::StartsWith(object_path_.value(), service_path_.value() + "/", |
56 service_path_.value() + "/", | |
57 base::CompareCase::SENSITIVE)); | 54 base::CompareCase::SENSITIVE)); |
58 | 55 |
59 exported_object_ = bus_->GetExportedObject(object_path_); | 56 exported_object_ = bus_->GetExportedObject(object_path_); |
60 | 57 |
61 exported_object_->ExportMethod( | 58 exported_object_->ExportMethod( |
62 dbus::kDBusPropertiesInterface, | 59 dbus::kDBusPropertiesInterface, dbus::kDBusPropertiesGet, |
63 dbus::kDBusPropertiesGet, | |
64 base::Bind(&BluetoothGattCharacteristicServiceProviderImpl::Get, | 60 base::Bind(&BluetoothGattCharacteristicServiceProviderImpl::Get, |
65 weak_ptr_factory_.GetWeakPtr()), | 61 weak_ptr_factory_.GetWeakPtr()), |
66 base::Bind(&BluetoothGattCharacteristicServiceProviderImpl::OnExported, | 62 base::Bind(&BluetoothGattCharacteristicServiceProviderImpl::OnExported, |
67 weak_ptr_factory_.GetWeakPtr())); | 63 weak_ptr_factory_.GetWeakPtr())); |
68 | 64 |
69 exported_object_->ExportMethod( | 65 exported_object_->ExportMethod( |
70 dbus::kDBusPropertiesInterface, | 66 dbus::kDBusPropertiesInterface, dbus::kDBusPropertiesSet, |
71 dbus::kDBusPropertiesSet, | |
72 base::Bind(&BluetoothGattCharacteristicServiceProviderImpl::Set, | 67 base::Bind(&BluetoothGattCharacteristicServiceProviderImpl::Set, |
73 weak_ptr_factory_.GetWeakPtr()), | 68 weak_ptr_factory_.GetWeakPtr()), |
74 base::Bind(&BluetoothGattCharacteristicServiceProviderImpl::OnExported, | 69 base::Bind(&BluetoothGattCharacteristicServiceProviderImpl::OnExported, |
75 weak_ptr_factory_.GetWeakPtr())); | 70 weak_ptr_factory_.GetWeakPtr())); |
76 | 71 |
77 exported_object_->ExportMethod( | 72 exported_object_->ExportMethod( |
78 dbus::kDBusPropertiesInterface, | 73 dbus::kDBusPropertiesInterface, dbus::kDBusPropertiesGetAll, |
79 dbus::kDBusPropertiesGetAll, | |
80 base::Bind(&BluetoothGattCharacteristicServiceProviderImpl::GetAll, | 74 base::Bind(&BluetoothGattCharacteristicServiceProviderImpl::GetAll, |
81 weak_ptr_factory_.GetWeakPtr()), | 75 weak_ptr_factory_.GetWeakPtr()), |
82 base::Bind(&BluetoothGattCharacteristicServiceProviderImpl::OnExported, | 76 base::Bind(&BluetoothGattCharacteristicServiceProviderImpl::OnExported, |
83 weak_ptr_factory_.GetWeakPtr())); | 77 weak_ptr_factory_.GetWeakPtr())); |
84 } | 78 } |
85 | 79 |
86 ~BluetoothGattCharacteristicServiceProviderImpl() override { | 80 ~BluetoothGattCharacteristicServiceProviderImpl() override { |
87 VLOG(1) << "Cleaning up Bluetooth GATT characteristic: " | 81 VLOG(1) << "Cleaning up Bluetooth GATT characteristic: " |
88 << object_path_.value(); | 82 << object_path_.value(); |
89 bus_->UnregisterExportedObject(object_path_); | 83 bus_->UnregisterExportedObject(object_path_); |
90 } | 84 } |
91 | 85 |
92 // BluetoothGattCharacteristicServiceProvider override. | 86 // BluetoothGattCharacteristicServiceProvider override. |
93 void SendValueChanged(const std::vector<uint8>& value) override { | 87 void SendValueChanged(const std::vector<uint8>& value) override { |
94 VLOG(2) << "Emitting a PropertiesChanged signal for characteristic value."; | 88 VLOG(2) << "Emitting a PropertiesChanged signal for characteristic value."; |
95 dbus::Signal signal( | 89 dbus::Signal signal(dbus::kDBusPropertiesInterface, |
96 dbus::kDBusPropertiesInterface, | 90 dbus::kDBusPropertiesChangedSignal); |
97 dbus::kDBusPropertiesChangedSignal); | |
98 dbus::MessageWriter writer(&signal); | 91 dbus::MessageWriter writer(&signal); |
99 dbus::MessageWriter array_writer(NULL); | 92 dbus::MessageWriter array_writer(NULL); |
100 dbus::MessageWriter dict_entry_writer(NULL); | 93 dbus::MessageWriter dict_entry_writer(NULL); |
101 dbus::MessageWriter variant_writer(NULL); | 94 dbus::MessageWriter variant_writer(NULL); |
102 | 95 |
103 // interface_name | 96 // interface_name |
104 writer.AppendString( | 97 writer.AppendString( |
105 bluetooth_gatt_characteristic::kBluetoothGattCharacteristicInterface); | 98 bluetooth_gatt_characteristic::kBluetoothGattCharacteristicInterface); |
106 | 99 |
107 // changed_properties | 100 // changed_properties |
(...skipping 26 matching lines...) Expand all Loading... |
134 dbus::ExportedObject::ResponseSender response_sender) { | 127 dbus::ExportedObject::ResponseSender response_sender) { |
135 VLOG(2) << "BluetoothGattCharacteristicServiceProvider::Get: " | 128 VLOG(2) << "BluetoothGattCharacteristicServiceProvider::Get: " |
136 << object_path_.value(); | 129 << object_path_.value(); |
137 DCHECK(OnOriginThread()); | 130 DCHECK(OnOriginThread()); |
138 | 131 |
139 dbus::MessageReader reader(method_call); | 132 dbus::MessageReader reader(method_call); |
140 | 133 |
141 std::string interface_name; | 134 std::string interface_name; |
142 std::string property_name; | 135 std::string property_name; |
143 if (!reader.PopString(&interface_name) || | 136 if (!reader.PopString(&interface_name) || |
144 !reader.PopString(&property_name) || | 137 !reader.PopString(&property_name) || reader.HasMoreData()) { |
145 reader.HasMoreData()) { | |
146 scoped_ptr<dbus::ErrorResponse> error_response = | 138 scoped_ptr<dbus::ErrorResponse> error_response = |
147 dbus::ErrorResponse::FromMethodCall( | 139 dbus::ErrorResponse::FromMethodCall(method_call, kErrorInvalidArgs, |
148 method_call, kErrorInvalidArgs, "Expected 'ss'."); | 140 "Expected 'ss'."); |
149 response_sender.Run(error_response.Pass()); | 141 response_sender.Run(error_response.Pass()); |
150 return; | 142 return; |
151 } | 143 } |
152 | 144 |
153 // Only the GATT characteristic interface is supported. | 145 // Only the GATT characteristic interface is supported. |
154 if (interface_name != | 146 if (interface_name != |
155 bluetooth_gatt_characteristic::kBluetoothGattCharacteristicInterface) { | 147 bluetooth_gatt_characteristic::kBluetoothGattCharacteristicInterface) { |
156 scoped_ptr<dbus::ErrorResponse> error_response = | 148 scoped_ptr<dbus::ErrorResponse> error_response = |
157 dbus::ErrorResponse::FromMethodCall( | 149 dbus::ErrorResponse::FromMethodCall( |
158 method_call, kErrorInvalidArgs, | 150 method_call, kErrorInvalidArgs, |
159 "No such interface: '" + interface_name + "'."); | 151 "No such interface: '" + interface_name + "'."); |
160 response_sender.Run(error_response.Pass()); | 152 response_sender.Run(error_response.Pass()); |
161 return; | 153 return; |
162 } | 154 } |
163 | 155 |
164 // If getting the "Value" property, obtain the value from the delegate. | 156 // If getting the "Value" property, obtain the value from the delegate. |
165 if (property_name == bluetooth_gatt_characteristic::kValueProperty) { | 157 if (property_name == bluetooth_gatt_characteristic::kValueProperty) { |
166 DCHECK(delegate_); | 158 DCHECK(delegate_); |
167 delegate_->GetCharacteristicValue( | 159 delegate_->GetCharacteristicValue( |
168 base::Bind(&BluetoothGattCharacteristicServiceProviderImpl::OnGet, | 160 base::Bind(&BluetoothGattCharacteristicServiceProviderImpl::OnGet, |
169 weak_ptr_factory_.GetWeakPtr(), | 161 weak_ptr_factory_.GetWeakPtr(), method_call, |
170 method_call, response_sender), | 162 response_sender), |
171 base::Bind(&BluetoothGattCharacteristicServiceProviderImpl::OnFailure, | 163 base::Bind(&BluetoothGattCharacteristicServiceProviderImpl::OnFailure, |
172 weak_ptr_factory_.GetWeakPtr(), | 164 weak_ptr_factory_.GetWeakPtr(), method_call, |
173 method_call, response_sender)); | 165 response_sender)); |
174 return; | 166 return; |
175 } | 167 } |
176 | 168 |
177 scoped_ptr<dbus::Response> response = | 169 scoped_ptr<dbus::Response> response = |
178 dbus::Response::FromMethodCall(method_call); | 170 dbus::Response::FromMethodCall(method_call); |
179 dbus::MessageWriter writer(response.get()); | 171 dbus::MessageWriter writer(response.get()); |
180 dbus::MessageWriter variant_writer(NULL); | 172 dbus::MessageWriter variant_writer(NULL); |
181 | 173 |
182 // TODO(armansito): Process the "Flags" and "Permissions" properties below. | 174 // TODO(armansito): Process the "Flags" and "Permissions" properties below. |
183 if (property_name == bluetooth_gatt_characteristic::kUUIDProperty) { | 175 if (property_name == bluetooth_gatt_characteristic::kUUIDProperty) { |
184 writer.OpenVariant("s", &variant_writer); | 176 writer.OpenVariant("s", &variant_writer); |
185 variant_writer.AppendString(uuid_); | 177 variant_writer.AppendString(uuid_); |
186 writer.CloseContainer(&variant_writer); | 178 writer.CloseContainer(&variant_writer); |
187 } else if (property_name == | 179 } else if (property_name == |
188 bluetooth_gatt_characteristic::kServiceProperty) { | 180 bluetooth_gatt_characteristic::kServiceProperty) { |
189 writer.OpenVariant("o", &variant_writer); | 181 writer.OpenVariant("o", &variant_writer); |
190 variant_writer.AppendObjectPath(service_path_); | 182 variant_writer.AppendObjectPath(service_path_); |
191 writer.CloseContainer(&variant_writer); | 183 writer.CloseContainer(&variant_writer); |
192 } else { | 184 } else { |
193 response = dbus::ErrorResponse::FromMethodCall( | 185 response = dbus::ErrorResponse::FromMethodCall( |
194 method_call, | 186 method_call, kErrorInvalidArgs, |
195 kErrorInvalidArgs, | |
196 "No such property: '" + property_name + "'."); | 187 "No such property: '" + property_name + "'."); |
197 } | 188 } |
198 | 189 |
199 response_sender.Run(response.Pass()); | 190 response_sender.Run(response.Pass()); |
200 } | 191 } |
201 | 192 |
202 // Called by dbus:: when the Bluetooth daemon sets a single property of the | 193 // Called by dbus:: when the Bluetooth daemon sets a single property of the |
203 // characteristic. | 194 // characteristic. |
204 void Set(dbus::MethodCall* method_call, | 195 void Set(dbus::MethodCall* method_call, |
205 dbus::ExportedObject::ResponseSender response_sender) { | 196 dbus::ExportedObject::ResponseSender response_sender) { |
206 VLOG(2) << "BluetoothGattCharacteristicServiceProvider::Set: " | 197 VLOG(2) << "BluetoothGattCharacteristicServiceProvider::Set: " |
207 << object_path_.value(); | 198 << object_path_.value(); |
208 DCHECK(OnOriginThread()); | 199 DCHECK(OnOriginThread()); |
209 | 200 |
210 dbus::MessageReader reader(method_call); | 201 dbus::MessageReader reader(method_call); |
211 | 202 |
212 std::string interface_name; | 203 std::string interface_name; |
213 std::string property_name; | 204 std::string property_name; |
214 dbus::MessageReader variant_reader(NULL); | 205 dbus::MessageReader variant_reader(NULL); |
215 if (!reader.PopString(&interface_name) || | 206 if (!reader.PopString(&interface_name) || |
216 !reader.PopString(&property_name) || | 207 !reader.PopString(&property_name) || |
217 !reader.PopVariant(&variant_reader) || | 208 !reader.PopVariant(&variant_reader) || reader.HasMoreData()) { |
218 reader.HasMoreData()) { | |
219 scoped_ptr<dbus::ErrorResponse> error_response = | 209 scoped_ptr<dbus::ErrorResponse> error_response = |
220 dbus::ErrorResponse::FromMethodCall( | 210 dbus::ErrorResponse::FromMethodCall(method_call, kErrorInvalidArgs, |
221 method_call, kErrorInvalidArgs, "Expected 'ssv'."); | 211 "Expected 'ssv'."); |
222 response_sender.Run(error_response.Pass()); | 212 response_sender.Run(error_response.Pass()); |
223 return; | 213 return; |
224 } | 214 } |
225 | 215 |
226 // Only the GATT characteristic interface is allowed. | 216 // Only the GATT characteristic interface is allowed. |
227 if (interface_name != | 217 if (interface_name != |
228 bluetooth_gatt_characteristic::kBluetoothGattCharacteristicInterface) { | 218 bluetooth_gatt_characteristic::kBluetoothGattCharacteristicInterface) { |
229 scoped_ptr<dbus::ErrorResponse> error_response = | 219 scoped_ptr<dbus::ErrorResponse> error_response = |
230 dbus::ErrorResponse::FromMethodCall( | 220 dbus::ErrorResponse::FromMethodCall( |
231 method_call, kErrorInvalidArgs, | 221 method_call, kErrorInvalidArgs, |
232 "No such interface: '" + interface_name + "'."); | 222 "No such interface: '" + interface_name + "'."); |
233 response_sender.Run(error_response.Pass()); | 223 response_sender.Run(error_response.Pass()); |
234 return; | 224 return; |
235 } | 225 } |
236 | 226 |
237 // Only the "Value" property is writeable. | 227 // Only the "Value" property is writeable. |
238 if (property_name != bluetooth_gatt_characteristic::kValueProperty) { | 228 if (property_name != bluetooth_gatt_characteristic::kValueProperty) { |
239 std::string error_name; | 229 std::string error_name; |
240 std::string error_message; | 230 std::string error_message; |
241 if (property_name == bluetooth_gatt_characteristic::kUUIDProperty || | 231 if (property_name == bluetooth_gatt_characteristic::kUUIDProperty || |
242 property_name == bluetooth_gatt_characteristic::kServiceProperty) { | 232 property_name == bluetooth_gatt_characteristic::kServiceProperty) { |
243 error_name = kErrorPropertyReadOnly; | 233 error_name = kErrorPropertyReadOnly; |
244 error_message = "Read-only property: '" + property_name + "'."; | 234 error_message = "Read-only property: '" + property_name + "'."; |
245 } else { | 235 } else { |
246 error_name = kErrorInvalidArgs; | 236 error_name = kErrorInvalidArgs; |
247 error_message = "No such property: '" + property_name + "'."; | 237 error_message = "No such property: '" + property_name + "'."; |
248 } | 238 } |
249 scoped_ptr<dbus::ErrorResponse> error_response = | 239 scoped_ptr<dbus::ErrorResponse> error_response = |
250 dbus::ErrorResponse::FromMethodCall( | 240 dbus::ErrorResponse::FromMethodCall(method_call, error_name, |
251 method_call, error_name, error_message); | 241 error_message); |
252 response_sender.Run(error_response.Pass()); | 242 response_sender.Run(error_response.Pass()); |
253 return; | 243 return; |
254 } | 244 } |
255 | 245 |
256 // Obtain the value. | 246 // Obtain the value. |
257 const uint8* bytes = NULL; | 247 const uint8* bytes = NULL; |
258 size_t length = 0; | 248 size_t length = 0; |
259 if (!variant_reader.PopArrayOfBytes(&bytes, &length)) { | 249 if (!variant_reader.PopArrayOfBytes(&bytes, &length)) { |
260 scoped_ptr<dbus::ErrorResponse> error_response = | 250 scoped_ptr<dbus::ErrorResponse> error_response = |
261 dbus::ErrorResponse::FromMethodCall( | 251 dbus::ErrorResponse::FromMethodCall( |
262 method_call, kErrorInvalidArgs, | 252 method_call, kErrorInvalidArgs, |
263 "Property '" + property_name + "' has type 'ay'."); | 253 "Property '" + property_name + "' has type 'ay'."); |
264 response_sender.Run(error_response.Pass()); | 254 response_sender.Run(error_response.Pass()); |
265 return; | 255 return; |
266 } | 256 } |
267 | 257 |
268 // Pass the set request onto the delegate. | 258 // Pass the set request onto the delegate. |
269 std::vector<uint8> value(bytes, bytes + length); | 259 std::vector<uint8> value(bytes, bytes + length); |
270 DCHECK(delegate_); | 260 DCHECK(delegate_); |
271 delegate_->SetCharacteristicValue( | 261 delegate_->SetCharacteristicValue( |
272 value, | 262 value, |
273 base::Bind(&BluetoothGattCharacteristicServiceProviderImpl::OnSet, | 263 base::Bind(&BluetoothGattCharacteristicServiceProviderImpl::OnSet, |
274 weak_ptr_factory_.GetWeakPtr(), | 264 weak_ptr_factory_.GetWeakPtr(), method_call, |
275 method_call, response_sender), | 265 response_sender), |
276 base::Bind(&BluetoothGattCharacteristicServiceProviderImpl::OnFailure, | 266 base::Bind(&BluetoothGattCharacteristicServiceProviderImpl::OnFailure, |
277 weak_ptr_factory_.GetWeakPtr(), | 267 weak_ptr_factory_.GetWeakPtr(), method_call, |
278 method_call, response_sender)); | 268 response_sender)); |
279 } | 269 } |
280 | 270 |
281 // Called by dbus:: when the Bluetooth daemon fetches all properties of the | 271 // Called by dbus:: when the Bluetooth daemon fetches all properties of the |
282 // characteristic. | 272 // characteristic. |
283 void GetAll(dbus::MethodCall* method_call, | 273 void GetAll(dbus::MethodCall* method_call, |
284 dbus::ExportedObject::ResponseSender response_sender) { | 274 dbus::ExportedObject::ResponseSender response_sender) { |
285 VLOG(2) << "BluetoothGattCharacteristicServiceProvider::GetAll: " | 275 VLOG(2) << "BluetoothGattCharacteristicServiceProvider::GetAll: " |
286 << object_path_.value(); | 276 << object_path_.value(); |
287 DCHECK(OnOriginThread()); | 277 DCHECK(OnOriginThread()); |
288 | 278 |
289 dbus::MessageReader reader(method_call); | 279 dbus::MessageReader reader(method_call); |
290 | 280 |
291 std::string interface_name; | 281 std::string interface_name; |
292 if (!reader.PopString(&interface_name) || reader.HasMoreData()) { | 282 if (!reader.PopString(&interface_name) || reader.HasMoreData()) { |
293 scoped_ptr<dbus::ErrorResponse> error_response = | 283 scoped_ptr<dbus::ErrorResponse> error_response = |
294 dbus::ErrorResponse::FromMethodCall( | 284 dbus::ErrorResponse::FromMethodCall(method_call, kErrorInvalidArgs, |
295 method_call, kErrorInvalidArgs, "Expected 's'."); | 285 "Expected 's'."); |
296 response_sender.Run(error_response.Pass()); | 286 response_sender.Run(error_response.Pass()); |
297 return; | 287 return; |
298 } | 288 } |
299 | 289 |
300 // Only the GATT characteristic interface is supported. | 290 // Only the GATT characteristic interface is supported. |
301 if (interface_name != | 291 if (interface_name != |
302 bluetooth_gatt_characteristic::kBluetoothGattCharacteristicInterface) { | 292 bluetooth_gatt_characteristic::kBluetoothGattCharacteristicInterface) { |
303 scoped_ptr<dbus::ErrorResponse> error_response = | 293 scoped_ptr<dbus::ErrorResponse> error_response = |
304 dbus::ErrorResponse::FromMethodCall( | 294 dbus::ErrorResponse::FromMethodCall( |
305 method_call, kErrorInvalidArgs, | 295 method_call, kErrorInvalidArgs, |
306 "No such interface: '" + interface_name + "'."); | 296 "No such interface: '" + interface_name + "'."); |
307 response_sender.Run(error_response.Pass()); | 297 response_sender.Run(error_response.Pass()); |
308 return; | 298 return; |
309 } | 299 } |
310 | 300 |
311 // Try to obtain the value from the delegate. We will construct the | 301 // Try to obtain the value from the delegate. We will construct the |
312 // response in the success callback. | 302 // response in the success callback. |
313 DCHECK(delegate_); | 303 DCHECK(delegate_); |
314 delegate_->GetCharacteristicValue( | 304 delegate_->GetCharacteristicValue( |
315 base::Bind(&BluetoothGattCharacteristicServiceProviderImpl::OnGetAll, | 305 base::Bind(&BluetoothGattCharacteristicServiceProviderImpl::OnGetAll, |
316 weak_ptr_factory_.GetWeakPtr(), | 306 weak_ptr_factory_.GetWeakPtr(), method_call, |
317 method_call, response_sender), | 307 response_sender), |
318 base::Bind(&BluetoothGattCharacteristicServiceProviderImpl::OnFailure, | 308 base::Bind(&BluetoothGattCharacteristicServiceProviderImpl::OnFailure, |
319 weak_ptr_factory_.GetWeakPtr(), | 309 weak_ptr_factory_.GetWeakPtr(), method_call, |
320 method_call, response_sender)); | 310 response_sender)); |
321 } | 311 } |
322 | 312 |
323 // Called by dbus:: when a method is exported. | 313 // Called by dbus:: when a method is exported. |
324 void OnExported(const std::string& interface_name, | 314 void OnExported(const std::string& interface_name, |
325 const std::string& method_name, | 315 const std::string& method_name, |
326 bool success) { | 316 bool success) { |
327 LOG_IF(WARNING, !success) << "Failed to export " | 317 LOG_IF(WARNING, !success) << "Failed to export " << interface_name << "." |
328 << interface_name << "." << method_name; | 318 << method_name; |
329 } | 319 } |
330 | 320 |
331 // Called by the Delegate in response to a method to call to get all | 321 // Called by the Delegate in response to a method to call to get all |
332 // properties, in which the delegate has successfully returned the | 322 // properties, in which the delegate has successfully returned the |
333 // characteristic value. | 323 // characteristic value. |
334 void OnGetAll(dbus::MethodCall* method_call, | 324 void OnGetAll(dbus::MethodCall* method_call, |
335 dbus::ExportedObject::ResponseSender response_sender, | 325 dbus::ExportedObject::ResponseSender response_sender, |
336 const std::vector<uint8>& value) { | 326 const std::vector<uint8>& value) { |
337 VLOG(2) << "Characteristic value obtained from delegate. Responding to " | 327 VLOG(2) << "Characteristic value obtained from delegate. Responding to " |
338 << "GetAll."; | 328 << "GetAll."; |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
441 // than we do. | 431 // than we do. |
442 // Note: This should remain the last member so it'll be destroyed and | 432 // Note: This should remain the last member so it'll be destroyed and |
443 // invalidate its weak pointers before any other members are destroyed. | 433 // invalidate its weak pointers before any other members are destroyed. |
444 base::WeakPtrFactory<BluetoothGattCharacteristicServiceProviderImpl> | 434 base::WeakPtrFactory<BluetoothGattCharacteristicServiceProviderImpl> |
445 weak_ptr_factory_; | 435 weak_ptr_factory_; |
446 | 436 |
447 DISALLOW_COPY_AND_ASSIGN(BluetoothGattCharacteristicServiceProviderImpl); | 437 DISALLOW_COPY_AND_ASSIGN(BluetoothGattCharacteristicServiceProviderImpl); |
448 }; | 438 }; |
449 | 439 |
450 BluetoothGattCharacteristicServiceProvider:: | 440 BluetoothGattCharacteristicServiceProvider:: |
451 BluetoothGattCharacteristicServiceProvider() { | 441 BluetoothGattCharacteristicServiceProvider() {} |
452 } | |
453 | 442 |
454 BluetoothGattCharacteristicServiceProvider:: | 443 BluetoothGattCharacteristicServiceProvider:: |
455 ~BluetoothGattCharacteristicServiceProvider() { | 444 ~BluetoothGattCharacteristicServiceProvider() {} |
456 } | |
457 | 445 |
458 // static | 446 // static |
459 BluetoothGattCharacteristicServiceProvider* | 447 BluetoothGattCharacteristicServiceProvider* |
460 BluetoothGattCharacteristicServiceProvider::Create( | 448 BluetoothGattCharacteristicServiceProvider::Create( |
461 dbus::Bus* bus, | 449 dbus::Bus* bus, |
462 const dbus::ObjectPath& object_path, | 450 const dbus::ObjectPath& object_path, |
463 Delegate* delegate, | 451 Delegate* delegate, |
464 const std::string& uuid, | 452 const std::string& uuid, |
465 const std::vector<std::string>& flags, | 453 const std::vector<std::string>& flags, |
466 const std::vector<std::string>& permissions, | 454 const std::vector<std::string>& permissions, |
467 const dbus::ObjectPath& service_path) { | 455 const dbus::ObjectPath& service_path) { |
468 if (!DBusThreadManager::Get()->IsUsingStub(DBusClientBundle::BLUETOOTH)) { | 456 if (!bluez::BluezDBusManager::Get()->IsUsingStub()) { |
469 return new BluetoothGattCharacteristicServiceProviderImpl( | 457 return new BluetoothGattCharacteristicServiceProviderImpl( |
470 bus, object_path, delegate, uuid, flags, permissions, service_path); | 458 bus, object_path, delegate, uuid, flags, permissions, service_path); |
471 } | 459 } |
472 return new FakeBluetoothGattCharacteristicServiceProvider( | 460 return new FakeBluetoothGattCharacteristicServiceProvider( |
473 object_path, delegate, uuid, flags, permissions, service_path); | 461 object_path, delegate, uuid, flags, permissions, service_path); |
474 } | 462 } |
475 | 463 |
476 } // namespace chromeos | 464 } // namespace bluez |
OLD | NEW |