bluetooth_local_gatt_characteristic.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. #ifndef DEVICE_BLUETOOTH_BLUETOOTH_LOCAL_GATT_CHARACTERISTIC_H_
  5. #define DEVICE_BLUETOOTH_BLUETOOTH_LOCAL_GATT_CHARACTERISTIC_H_
  6. #include <stdint.h>
  7. #include <vector>
  8. #include "device/bluetooth/bluetooth_export.h"
  9. #include "device/bluetooth/bluetooth_gatt_characteristic.h"
  10. #include "device/bluetooth/bluetooth_local_gatt_service.h"
  11. #include "device/bluetooth/public/cpp/bluetooth_uuid.h"
  12. namespace device {
  13. // BluetoothLocalGattCharacteristic represents a local GATT characteristic. This
  14. // class is used to represent GATT characteristics that belong to a locally
  15. // hosted service. To achieve this, users need to specify the instance of the
  16. // GATT service that contains this characteristic during construction.
  17. //
  18. // Note: We use virtual inheritance on the GATT characteristic since it will be
  19. // inherited by platform specific versions of the GATT characteristic classes
  20. // also. The platform specific remote GATT characteristic classes will inherit
  21. // both this class and their GATT characteristic class, hence causing an
  22. // inheritance diamond.
  23. class DEVICE_BLUETOOTH_EXPORT BluetoothLocalGattCharacteristic
  24. : public virtual BluetoothGattCharacteristic {
  25. public:
  26. enum NotificationStatus {
  27. NOTIFICATION_SUCCESS = 0,
  28. NOTIFY_PROPERTY_NOT_SET,
  29. INDICATE_PROPERTY_NOT_SET,
  30. SERVICE_NOT_REGISTERED,
  31. };
  32. // Constructs a BluetoothLocalGattCharacteristic associated with a local GATT
  33. // service when the adapter is in the peripheral role.
  34. //
  35. // This method constructs a characteristic with UUID |uuid|, initial cached
  36. // value |value|, properties |properties|, and permissions |permissions|.
  37. // |value| will be cached and returned for read requests and automatically set
  38. // for write requests by default, unless an instance of
  39. // BluetoothRemoteGattService::Delegate has been provided to the associated
  40. // BluetoothRemoteGattService instance, in which case the delegate will handle
  41. // read and write requests. The service instance will contain this
  42. // characteristic.
  43. // TODO(rkc): Investigate how to handle |PROPERTY_EXTENDED_PROPERTIES|
  44. // correctly.
  45. static base::WeakPtr<BluetoothLocalGattCharacteristic> Create(
  46. const BluetoothUUID& uuid,
  47. Properties properties,
  48. Permissions permissions,
  49. BluetoothLocalGattService* service);
  50. BluetoothLocalGattCharacteristic(const BluetoothLocalGattCharacteristic&) =
  51. delete;
  52. BluetoothLocalGattCharacteristic& operator=(
  53. const BluetoothLocalGattCharacteristic&) = delete;
  54. // Notify the remote device |device| that the value of characteristic
  55. // |characteristic| has changed and the new value is |new_value|. |indicate|
  56. // should be set to true if we want to use an indication instead of a
  57. // notification. An indication waits for a response from the remote, making
  58. // it more reliable but notifications may be faster.
  59. virtual NotificationStatus NotifyValueChanged(
  60. const BluetoothDevice* device,
  61. const std::vector<uint8_t>& new_value,
  62. bool indicate) = 0;
  63. virtual BluetoothLocalGattService* GetService() const = 0;
  64. protected:
  65. BluetoothLocalGattCharacteristic();
  66. ~BluetoothLocalGattCharacteristic() override;
  67. };
  68. } // namespace device
  69. #endif // DEVICE_BLUETOOTH_BLUETOOTH_LOCAL_GATT_CHARACTERISTIC_H_