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/dbus/bluetooth_gatt_characteristic_service_provider.h
" | 5 #include "device/bluetooth/dbus/bluetooth_gatt_characteristic_service_provider.h
" |
6 | 6 |
| 7 #include <stddef.h> |
| 8 |
7 #include "base/bind.h" | 9 #include "base/bind.h" |
8 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/macros.h" |
9 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
10 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
11 #include "base/threading/platform_thread.h" | 14 #include "base/threading/platform_thread.h" |
12 #include "dbus/exported_object.h" | 15 #include "dbus/exported_object.h" |
13 #include "dbus/message.h" | 16 #include "dbus/message.h" |
14 #include "device/bluetooth/dbus/bluez_dbus_manager.h" | 17 #include "device/bluetooth/dbus/bluez_dbus_manager.h" |
15 #include "device/bluetooth/dbus/fake_bluetooth_gatt_characteristic_service_provi
der.h" | 18 #include "device/bluetooth/dbus/fake_bluetooth_gatt_characteristic_service_provi
der.h" |
16 #include "third_party/cros_system_api/dbus/service_constants.h" | 19 #include "third_party/cros_system_api/dbus/service_constants.h" |
17 | 20 |
18 namespace bluez { | 21 namespace bluez { |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 weak_ptr_factory_.GetWeakPtr())); | 80 weak_ptr_factory_.GetWeakPtr())); |
78 } | 81 } |
79 | 82 |
80 ~BluetoothGattCharacteristicServiceProviderImpl() override { | 83 ~BluetoothGattCharacteristicServiceProviderImpl() override { |
81 VLOG(1) << "Cleaning up Bluetooth GATT characteristic: " | 84 VLOG(1) << "Cleaning up Bluetooth GATT characteristic: " |
82 << object_path_.value(); | 85 << object_path_.value(); |
83 bus_->UnregisterExportedObject(object_path_); | 86 bus_->UnregisterExportedObject(object_path_); |
84 } | 87 } |
85 | 88 |
86 // BluetoothGattCharacteristicServiceProvider override. | 89 // BluetoothGattCharacteristicServiceProvider override. |
87 void SendValueChanged(const std::vector<uint8>& value) override { | 90 void SendValueChanged(const std::vector<uint8_t>& value) override { |
88 VLOG(2) << "Emitting a PropertiesChanged signal for characteristic value."; | 91 VLOG(2) << "Emitting a PropertiesChanged signal for characteristic value."; |
89 dbus::Signal signal(dbus::kDBusPropertiesInterface, | 92 dbus::Signal signal(dbus::kDBusPropertiesInterface, |
90 dbus::kDBusPropertiesChangedSignal); | 93 dbus::kDBusPropertiesChangedSignal); |
91 dbus::MessageWriter writer(&signal); | 94 dbus::MessageWriter writer(&signal); |
92 dbus::MessageWriter array_writer(NULL); | 95 dbus::MessageWriter array_writer(NULL); |
93 dbus::MessageWriter dict_entry_writer(NULL); | 96 dbus::MessageWriter dict_entry_writer(NULL); |
94 dbus::MessageWriter variant_writer(NULL); | 97 dbus::MessageWriter variant_writer(NULL); |
95 | 98 |
96 // interface_name | 99 // interface_name |
97 writer.AppendString( | 100 writer.AppendString( |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 error_message = "No such property: '" + property_name + "'."; | 240 error_message = "No such property: '" + property_name + "'."; |
238 } | 241 } |
239 scoped_ptr<dbus::ErrorResponse> error_response = | 242 scoped_ptr<dbus::ErrorResponse> error_response = |
240 dbus::ErrorResponse::FromMethodCall(method_call, error_name, | 243 dbus::ErrorResponse::FromMethodCall(method_call, error_name, |
241 error_message); | 244 error_message); |
242 response_sender.Run(error_response.Pass()); | 245 response_sender.Run(error_response.Pass()); |
243 return; | 246 return; |
244 } | 247 } |
245 | 248 |
246 // Obtain the value. | 249 // Obtain the value. |
247 const uint8* bytes = NULL; | 250 const uint8_t* bytes = NULL; |
248 size_t length = 0; | 251 size_t length = 0; |
249 if (!variant_reader.PopArrayOfBytes(&bytes, &length)) { | 252 if (!variant_reader.PopArrayOfBytes(&bytes, &length)) { |
250 scoped_ptr<dbus::ErrorResponse> error_response = | 253 scoped_ptr<dbus::ErrorResponse> error_response = |
251 dbus::ErrorResponse::FromMethodCall( | 254 dbus::ErrorResponse::FromMethodCall( |
252 method_call, kErrorInvalidArgs, | 255 method_call, kErrorInvalidArgs, |
253 "Property '" + property_name + "' has type 'ay'."); | 256 "Property '" + property_name + "' has type 'ay'."); |
254 response_sender.Run(error_response.Pass()); | 257 response_sender.Run(error_response.Pass()); |
255 return; | 258 return; |
256 } | 259 } |
257 | 260 |
258 // Pass the set request onto the delegate. | 261 // Pass the set request onto the delegate. |
259 std::vector<uint8> value(bytes, bytes + length); | 262 std::vector<uint8_t> value(bytes, bytes + length); |
260 DCHECK(delegate_); | 263 DCHECK(delegate_); |
261 delegate_->SetCharacteristicValue( | 264 delegate_->SetCharacteristicValue( |
262 value, | 265 value, |
263 base::Bind(&BluetoothGattCharacteristicServiceProviderImpl::OnSet, | 266 base::Bind(&BluetoothGattCharacteristicServiceProviderImpl::OnSet, |
264 weak_ptr_factory_.GetWeakPtr(), method_call, | 267 weak_ptr_factory_.GetWeakPtr(), method_call, |
265 response_sender), | 268 response_sender), |
266 base::Bind(&BluetoothGattCharacteristicServiceProviderImpl::OnFailure, | 269 base::Bind(&BluetoothGattCharacteristicServiceProviderImpl::OnFailure, |
267 weak_ptr_factory_.GetWeakPtr(), method_call, | 270 weak_ptr_factory_.GetWeakPtr(), method_call, |
268 response_sender)); | 271 response_sender)); |
269 } | 272 } |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
316 bool success) { | 319 bool success) { |
317 LOG_IF(WARNING, !success) << "Failed to export " << interface_name << "." | 320 LOG_IF(WARNING, !success) << "Failed to export " << interface_name << "." |
318 << method_name; | 321 << method_name; |
319 } | 322 } |
320 | 323 |
321 // Called by the Delegate in response to a method to call to get all | 324 // Called by the Delegate in response to a method to call to get all |
322 // properties, in which the delegate has successfully returned the | 325 // properties, in which the delegate has successfully returned the |
323 // characteristic value. | 326 // characteristic value. |
324 void OnGetAll(dbus::MethodCall* method_call, | 327 void OnGetAll(dbus::MethodCall* method_call, |
325 dbus::ExportedObject::ResponseSender response_sender, | 328 dbus::ExportedObject::ResponseSender response_sender, |
326 const std::vector<uint8>& value) { | 329 const std::vector<uint8_t>& value) { |
327 VLOG(2) << "Characteristic value obtained from delegate. Responding to " | 330 VLOG(2) << "Characteristic value obtained from delegate. Responding to " |
328 << "GetAll."; | 331 << "GetAll."; |
329 | 332 |
330 scoped_ptr<dbus::Response> response = | 333 scoped_ptr<dbus::Response> response = |
331 dbus::Response::FromMethodCall(method_call); | 334 dbus::Response::FromMethodCall(method_call); |
332 dbus::MessageWriter writer(response.get()); | 335 dbus::MessageWriter writer(response.get()); |
333 dbus::MessageWriter array_writer(NULL); | 336 dbus::MessageWriter array_writer(NULL); |
334 dbus::MessageWriter dict_entry_writer(NULL); | 337 dbus::MessageWriter dict_entry_writer(NULL); |
335 dbus::MessageWriter variant_writer(NULL); | 338 dbus::MessageWriter variant_writer(NULL); |
336 | 339 |
(...skipping 23 matching lines...) Expand all Loading... |
360 | 363 |
361 writer.CloseContainer(&array_writer); | 364 writer.CloseContainer(&array_writer); |
362 | 365 |
363 response_sender.Run(response.Pass()); | 366 response_sender.Run(response.Pass()); |
364 } | 367 } |
365 | 368 |
366 // Called by the Delegate in response to a successful method call to get the | 369 // Called by the Delegate in response to a successful method call to get the |
367 // characteristic value. | 370 // characteristic value. |
368 void OnGet(dbus::MethodCall* method_call, | 371 void OnGet(dbus::MethodCall* method_call, |
369 dbus::ExportedObject::ResponseSender response_sender, | 372 dbus::ExportedObject::ResponseSender response_sender, |
370 const std::vector<uint8>& value) { | 373 const std::vector<uint8_t>& value) { |
371 VLOG(2) << "Returning characteristic value obtained from delegate."; | 374 VLOG(2) << "Returning characteristic value obtained from delegate."; |
372 scoped_ptr<dbus::Response> response = | 375 scoped_ptr<dbus::Response> response = |
373 dbus::Response::FromMethodCall(method_call); | 376 dbus::Response::FromMethodCall(method_call); |
374 dbus::MessageWriter writer(response.get()); | 377 dbus::MessageWriter writer(response.get()); |
375 dbus::MessageWriter variant_writer(NULL); | 378 dbus::MessageWriter variant_writer(NULL); |
376 | 379 |
377 writer.OpenVariant("ay", &variant_writer); | 380 writer.OpenVariant("ay", &variant_writer); |
378 variant_writer.AppendArrayOfBytes(value.data(), value.size()); | 381 variant_writer.AppendArrayOfBytes(value.data(), value.size()); |
379 writer.CloseContainer(&variant_writer); | 382 writer.CloseContainer(&variant_writer); |
380 | 383 |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
455 const dbus::ObjectPath& service_path) { | 458 const dbus::ObjectPath& service_path) { |
456 if (!bluez::BluezDBusManager::Get()->IsUsingStub()) { | 459 if (!bluez::BluezDBusManager::Get()->IsUsingStub()) { |
457 return new BluetoothGattCharacteristicServiceProviderImpl( | 460 return new BluetoothGattCharacteristicServiceProviderImpl( |
458 bus, object_path, delegate, uuid, flags, permissions, service_path); | 461 bus, object_path, delegate, uuid, flags, permissions, service_path); |
459 } | 462 } |
460 return new FakeBluetoothGattCharacteristicServiceProvider( | 463 return new FakeBluetoothGattCharacteristicServiceProvider( |
461 object_path, delegate, uuid, flags, permissions, service_path); | 464 object_path, delegate, uuid, flags, permissions, service_path); |
462 } | 465 } |
463 | 466 |
464 } // namespace bluez | 467 } // namespace bluez |
OLD | NEW |