bluetooth_gatt_notify_session.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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_BLUETOOTH_GATT_NOTIFY_SESSION_H_
  5. #define DEVICE_BLUETOOTH_BLUETOOTH_GATT_NOTIFY_SESSION_H_
  6. #include <string>
  7. #include "base/callback.h"
  8. #include "base/memory/weak_ptr.h"
  9. #include "device/bluetooth/bluetooth_export.h"
  10. namespace device {
  11. class BluetoothRemoteGattCharacteristic;
  12. // A BluetoothGattNotifySession represents an active session for listening
  13. // to value updates from GATT characteristics that support notifications and/or
  14. // indications. Instances are obtained by calling
  15. // BluetoothRemoteGattCharacteristic::StartNotifySession.
  16. class DEVICE_BLUETOOTH_EXPORT BluetoothGattNotifySession {
  17. public:
  18. explicit BluetoothGattNotifySession(
  19. base::WeakPtr<BluetoothRemoteGattCharacteristic> characteristic);
  20. BluetoothGattNotifySession(const BluetoothGattNotifySession&) = delete;
  21. BluetoothGattNotifySession& operator=(const BluetoothGattNotifySession&) =
  22. delete;
  23. // Destructor automatically stops this session.
  24. virtual ~BluetoothGattNotifySession();
  25. // Returns the identifier of the associated characteristic.
  26. virtual std::string GetCharacteristicIdentifier() const;
  27. // Returns the associated characteristic. This function will return nullptr
  28. // if the associated characteristic is deleted.
  29. virtual BluetoothRemoteGattCharacteristic* GetCharacteristic() const;
  30. // Returns true if this session is active. Notify sessions are active from
  31. // the time of creation, until they have been stopped, either explicitly, or
  32. // because the remote device disconnects.
  33. virtual bool IsActive();
  34. // Stops this session and calls |callback| upon completion. This won't
  35. // necessarily stop value updates from the characteristic -- since updates
  36. // are shared among BluetoothGattNotifySession instances -- but it will
  37. // terminate this session.
  38. virtual void Stop(base::OnceClosure callback);
  39. private:
  40. // The associated characteristic.
  41. base::WeakPtr<BluetoothRemoteGattCharacteristic> characteristic_;
  42. std::string characteristic_id_;
  43. bool active_;
  44. };
  45. } // namespace device
  46. #endif // DEVICE_BLUETOOTH_BLUETOOTH_GATT_NOTIFY_SESSION_H_