fake_bluetooth_gatt_characteristic_service_provider.h 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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
  3. // found in the LICENSE file.
  4. #ifndef DEVICE_BLUETOOTH_DBUS_FAKE_BLUETOOTH_GATT_CHARACTERISTIC_SERVICE_PROVIDER_H_
  5. #define DEVICE_BLUETOOTH_DBUS_FAKE_BLUETOOTH_GATT_CHARACTERISTIC_SERVICE_PROVIDER_H_
  6. #include <stdint.h>
  7. #include <string>
  8. #include <vector>
  9. #include "base/callback_forward.h"
  10. #include "dbus/object_path.h"
  11. #include "device/bluetooth/bluetooth_export.h"
  12. #include "device/bluetooth/bluetooth_local_gatt_service.h"
  13. #include "device/bluetooth/bluez/bluetooth_local_gatt_service_bluez.h"
  14. #include "device/bluetooth/dbus/bluetooth_gatt_characteristic_service_provider.h"
  15. namespace bluez {
  16. // FakeBluetoothGattCharacteristicServiceProvider simulates behavior of a local
  17. // GATT characteristic object and is used both in test cases in place of a mock
  18. // and on the Linux desktop.
  19. class DEVICE_BLUETOOTH_EXPORT FakeBluetoothGattCharacteristicServiceProvider
  20. : public BluetoothGattCharacteristicServiceProvider {
  21. public:
  22. FakeBluetoothGattCharacteristicServiceProvider(
  23. const dbus::ObjectPath& object_path,
  24. std::unique_ptr<BluetoothGattAttributeValueDelegate> delegate,
  25. const std::string& uuid,
  26. const std::vector<std::string>& flags,
  27. const dbus::ObjectPath& service_path);
  28. FakeBluetoothGattCharacteristicServiceProvider(
  29. const FakeBluetoothGattCharacteristicServiceProvider&) = delete;
  30. FakeBluetoothGattCharacteristicServiceProvider& operator=(
  31. const FakeBluetoothGattCharacteristicServiceProvider&) = delete;
  32. ~FakeBluetoothGattCharacteristicServiceProvider() override;
  33. // BluetoothGattCharacteristicServiceProvider override.
  34. void SendValueChanged(const std::vector<uint8_t>& value) override;
  35. // Methods to simulate value get/set requests issued from a remote device. The
  36. // methods do nothing, if the associated service was not registered with the
  37. // GATT manager.
  38. void GetValue(
  39. const dbus::ObjectPath& device_path,
  40. device::BluetoothLocalGattService::Delegate::ValueCallback callback);
  41. void SetValue(const dbus::ObjectPath& device_path,
  42. const std::vector<uint8_t>& value,
  43. base::OnceClosure callback,
  44. device::BluetoothLocalGattService::Delegate::ErrorCallback
  45. error_callback);
  46. void PrepareSetValue(
  47. const dbus::ObjectPath& device_path,
  48. const std::vector<uint8_t>& value,
  49. int offset,
  50. bool has_subsequent_write,
  51. base::OnceClosure callback,
  52. device::BluetoothLocalGattService::Delegate::ErrorCallback
  53. error_callback);
  54. // Method to simulate starting and stopping notifications.
  55. bool NotificationsChange(const dbus::ObjectPath& device_path, bool start);
  56. const dbus::ObjectPath& object_path() const override;
  57. const std::string& uuid() const { return uuid_; }
  58. const dbus::ObjectPath& service_path() const { return service_path_; }
  59. const std::vector<uint8_t>& sent_value() const { return sent_value_; }
  60. private:
  61. // D-Bus object path of the fake GATT characteristic.
  62. dbus::ObjectPath object_path_;
  63. // 128-bit GATT characteristic UUID.
  64. const std::string uuid_;
  65. // Properties for this characteristic.
  66. const std::vector<std::string> flags_;
  67. // Object path of the service that this characteristic belongs to.
  68. const dbus::ObjectPath service_path_;
  69. // Value that was sent to the fake remote device.
  70. std::vector<uint8_t> sent_value_;
  71. // The delegate that method calls are passed on to.
  72. std::unique_ptr<BluetoothGattAttributeValueDelegate> delegate_;
  73. };
  74. } // namespace bluez
  75. #endif // DEVICE_BLUETOOTH_DBUS_FAKE_BLUETOOTH_GATT_CHARACTERISTIC_SERVICE_PROVIDER_H_