bluetooth_gatt_characteristic_delegate_wrapper.cc 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. // Copyright 2016 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "device/bluetooth/dbus/bluetooth_gatt_characteristic_delegate_wrapper.h"
  5. #include "base/logging.h"
  6. #include "device/bluetooth/bluez/bluetooth_local_gatt_characteristic_bluez.h"
  7. namespace bluez {
  8. BluetoothGattCharacteristicDelegateWrapper::
  9. BluetoothGattCharacteristicDelegateWrapper(
  10. BluetoothLocalGattServiceBlueZ* service,
  11. BluetoothLocalGattCharacteristicBlueZ* characteristic)
  12. : BluetoothGattAttributeValueDelegate(service),
  13. characteristic_(characteristic) {}
  14. void BluetoothGattCharacteristicDelegateWrapper::GetValue(
  15. const dbus::ObjectPath& device_path,
  16. device::BluetoothLocalGattService::Delegate::ValueCallback callback) {
  17. device::BluetoothDevice* device = GetDeviceWithPath(device_path);
  18. if (!device) {
  19. LOG(WARNING) << "Bluetooth device not found: " << device_path.value();
  20. return;
  21. }
  22. service()->GetDelegate()->OnCharacteristicReadRequest(device, characteristic_,
  23. 0, std::move(callback));
  24. }
  25. void BluetoothGattCharacteristicDelegateWrapper::SetValue(
  26. const dbus::ObjectPath& device_path,
  27. const std::vector<uint8_t>& value,
  28. base::OnceClosure callback,
  29. device::BluetoothLocalGattService::Delegate::ErrorCallback error_callback) {
  30. device::BluetoothDevice* device = GetDeviceWithPath(device_path);
  31. if (!device) {
  32. LOG(WARNING) << "Bluetooth device not found: " << device_path.value();
  33. return;
  34. }
  35. service()->GetDelegate()->OnCharacteristicWriteRequest(
  36. device, characteristic_, value, 0, std::move(callback),
  37. std::move(error_callback));
  38. }
  39. void BluetoothGattCharacteristicDelegateWrapper::StartNotifications(
  40. const dbus::ObjectPath& device_path,
  41. device::BluetoothGattCharacteristic::NotificationType notification_type) {
  42. device::BluetoothDevice* device = GetDeviceWithPath(device_path);
  43. if (!device) {
  44. LOG(WARNING) << "Bluetooth device not found: " << device_path.value();
  45. return;
  46. }
  47. service()->GetDelegate()->OnNotificationsStart(device, notification_type,
  48. characteristic_);
  49. }
  50. void BluetoothGattCharacteristicDelegateWrapper::StopNotifications(
  51. const dbus::ObjectPath& device_path) {
  52. device::BluetoothDevice* device = GetDeviceWithPath(device_path);
  53. if (!device) {
  54. LOG(WARNING) << "Bluetooth device not found: " << device_path.value();
  55. return;
  56. }
  57. service()->GetDelegate()->OnNotificationsStop(device, characteristic_);
  58. }
  59. void BluetoothGattCharacteristicDelegateWrapper::PrepareSetValue(
  60. const dbus::ObjectPath& device_path,
  61. const std::vector<uint8_t>& value,
  62. int offset,
  63. bool has_subsequent_request,
  64. base::OnceClosure callback,
  65. device::BluetoothLocalGattService::Delegate::ErrorCallback error_callback) {
  66. device::BluetoothDevice* device = GetDeviceWithPath(device_path);
  67. if (!device) {
  68. LOG(WARNING) << "Bluetooth device not found: " << device_path.value();
  69. return;
  70. }
  71. service()->GetDelegate()->OnCharacteristicPrepareWriteRequest(
  72. device, characteristic_, value, offset, has_subsequent_request,
  73. std::move(callback), std::move(error_callback));
  74. }
  75. } // namespace bluez