| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef DEVICE_BLUETOOTH_BLUETOOTH_GATT_NOTIFY_SESSION_H_ | 5 #ifndef DEVICE_BLUETOOTH_BLUETOOTH_GATT_NOTIFY_SESSION_H_ |
| 6 #define DEVICE_BLUETOOTH_BLUETOOTH_GATT_NOTIFY_SESSION_H_ | 6 #define DEVICE_BLUETOOTH_BLUETOOTH_GATT_NOTIFY_SESSION_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/memory/weak_ptr.h" |
| 12 #include "device/bluetooth/bluetooth_export.h" | 13 #include "device/bluetooth/bluetooth_export.h" |
| 13 | 14 |
| 14 namespace device { | 15 namespace device { |
| 15 | 16 |
| 17 class BluetoothRemoteGattCharacteristic; |
| 18 |
| 16 // A BluetoothGattNotifySession represents an active session for listening | 19 // A BluetoothGattNotifySession represents an active session for listening |
| 17 // to value updates from GATT characteristics that support notifications and/or | 20 // to value updates from GATT characteristics that support notifications and/or |
| 18 // indications. Instances are obtained by calling | 21 // indications. Instances are obtained by calling |
| 19 // BluetoothRemoteGattCharacteristic::StartNotifySession. | 22 // BluetoothRemoteGattCharacteristic::StartNotifySession. |
| 20 class DEVICE_BLUETOOTH_EXPORT BluetoothGattNotifySession { | 23 class DEVICE_BLUETOOTH_EXPORT BluetoothGattNotifySession { |
| 21 public: | 24 public: |
| 25 explicit BluetoothGattNotifySession( |
| 26 base::WeakPtr<BluetoothRemoteGattCharacteristic> characteristic); |
| 27 |
| 22 // Destructor automatically stops this session. | 28 // Destructor automatically stops this session. |
| 23 virtual ~BluetoothGattNotifySession(); | 29 virtual ~BluetoothGattNotifySession(); |
| 24 | 30 |
| 25 // Returns the identifier of the associated characteristic. | 31 // Returns the identifier of the associated characteristic. |
| 26 virtual std::string GetCharacteristicIdentifier() const = 0; | 32 virtual std::string GetCharacteristicIdentifier() const; |
| 27 | 33 |
| 28 // Returns true if this session is active. | 34 // Returns the associated characteristic. This function will return nullptr |
| 29 virtual bool IsActive() = 0; | 35 // if the associated characteristic is deleted. |
| 36 virtual BluetoothRemoteGattCharacteristic* GetCharacteristic() const; |
| 37 |
| 38 // Returns true if this session is active. Notify sessions are active from |
| 39 // the time of creation, until they have been stopped, either explicitly, or |
| 40 // because the remote device disconnects. |
| 41 virtual bool IsActive(); |
| 30 | 42 |
| 31 // Stops this session and calls |callback| upon completion. This won't | 43 // Stops this session and calls |callback| upon completion. This won't |
| 32 // necessarily stop value updates from the characteristic -- since updates | 44 // necessarily stop value updates from the characteristic -- since updates |
| 33 // are shared among BluetoothGattNotifySession instances -- but it will | 45 // are shared among BluetoothGattNotifySession instances -- but it will |
| 34 // terminate this session. | 46 // terminate this session. |
| 35 virtual void Stop(const base::Closure& callback) = 0; | 47 virtual void Stop(const base::Closure& callback); |
| 36 | |
| 37 protected: | |
| 38 BluetoothGattNotifySession(); | |
| 39 | 48 |
| 40 private: | 49 private: |
| 50 // The associated characteristic. |
| 51 base::WeakPtr<BluetoothRemoteGattCharacteristic> characteristic_; |
| 52 std::string characteristic_id_; |
| 53 bool active_; |
| 54 |
| 41 DISALLOW_COPY_AND_ASSIGN(BluetoothGattNotifySession); | 55 DISALLOW_COPY_AND_ASSIGN(BluetoothGattNotifySession); |
| 42 }; | 56 }; |
| 43 | 57 |
| 44 } // namespace device | 58 } // namespace device |
| 45 | 59 |
| 46 #endif // DEVICE_BLUETOOTH_BLUETOOTH_GATT_NOTIFY_SESSION_H_ | 60 #endif // DEVICE_BLUETOOTH_BLUETOOTH_GATT_NOTIFY_SESSION_H_ |
| OLD | NEW |