bluetooth_gatt_characteristic_service_provider.h 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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_BLUETOOTH_GATT_CHARACTERISTIC_SERVICE_PROVIDER_H_
  5. #define DEVICE_BLUETOOTH_DBUS_BLUETOOTH_GATT_CHARACTERISTIC_SERVICE_PROVIDER_H_
  6. #include <stdint.h>
  7. #include <string>
  8. #include <vector>
  9. #include "dbus/bus.h"
  10. #include "dbus/message.h"
  11. #include "dbus/object_path.h"
  12. #include "device/bluetooth/bluetooth_export.h"
  13. #include "device/bluetooth/dbus/bluetooth_gatt_attribute_value_delegate.h"
  14. namespace bluez {
  15. // BluetoothGattCharacteristicServiceProvider is used to provide a D-Bus object
  16. // that represents a local GATT characteristic that the Bluetooth daemon can
  17. // communicate with.
  18. //
  19. // Instantiate with a chosen D-Bus object path, delegate, and other fields.
  20. // The Bluetooth daemon communicates with a GATT characteristic using the
  21. // standard DBus.Properties interface. While most properties of the GATT
  22. // characteristic interface are read-only and don't change throughout the
  23. // life-time of the object, the "Value" property is both writeable and its
  24. // value can change. Both Get and Set operations performed on the "Value"
  25. // property are delegated to the Delegate object, an instance of which is
  26. // mandatory during initialization. In addition, a "SendValueChanged" method is
  27. // provided, which emits a DBus.Properties.PropertyChanged signal for the
  28. // "Value" property.
  29. class DEVICE_BLUETOOTH_EXPORT BluetoothGattCharacteristicServiceProvider {
  30. public:
  31. BluetoothGattCharacteristicServiceProvider(
  32. const BluetoothGattCharacteristicServiceProvider&) = delete;
  33. BluetoothGattCharacteristicServiceProvider& operator=(
  34. const BluetoothGattCharacteristicServiceProvider&) = delete;
  35. virtual ~BluetoothGattCharacteristicServiceProvider();
  36. // Send a PropertyChanged signal to notify the Bluetooth daemon that the value
  37. // of the "Value" property has changed to |value|.
  38. virtual void SendValueChanged(const std::vector<uint8_t>& value) = 0;
  39. // Writes the characteristics's properties into the provided writer. If
  40. // value is not null, it is written also, otherwise no value property is
  41. // written.
  42. virtual void WriteProperties(dbus::MessageWriter* writer) {}
  43. virtual const dbus::ObjectPath& object_path() const = 0;
  44. // Creates the instance, where |bus| is the D-Bus bus connection to export
  45. // the object onto, |uuid| is the 128-bit GATT characteristic UUID,
  46. // |flags| is the list of GATT characteristic properties, |flags| is the
  47. // list of flags for this characteristic, |service_path| is the object path
  48. // of the exported GATT service the characteristic belongs to, |object_path|
  49. // is the object path that the characteristic should have, and |delegate| is
  50. // the object that "Value" Get/Set requests will be passed to and responses
  51. // generated from.
  52. //
  53. // Object paths of GATT characteristics must be hierarchical to the path of
  54. // the GATT service they belong to. Hence, |object_path| must have
  55. // |service_path| as its prefix. Ownership of |delegate| is not taken, thus
  56. // the delegate should outlive this instance. A delegate should handle only
  57. // a single exported characteristic and own it.
  58. static BluetoothGattCharacteristicServiceProvider* Create(
  59. dbus::Bus* bus,
  60. const dbus::ObjectPath& object_path,
  61. std::unique_ptr<BluetoothGattAttributeValueDelegate> delegate,
  62. const std::string& uuid,
  63. const std::vector<std::string>& flags,
  64. const dbus::ObjectPath& service_path);
  65. protected:
  66. BluetoothGattCharacteristicServiceProvider();
  67. };
  68. } // namespace bluez
  69. #endif // DEVICE_BLUETOOTH_DBUS_BLUETOOTH_GATT_CHARACTERISTIC_SERVICE_PROVIDER_H_