/*
* Author: Sven Gothel
* BT Core Spec v5.2: Vol 3, Part G GATT: 3.3.1 Characteristic Declaration Attribute Value
*
* BT Core Spec v5.2: Vol 3, Part G GATT: 4.6.1 Discover All Characteristics of a Service
*
* Here the handle is a service's characteristics-declaration
* and the value the Characteristics Property, Characteristics Value Handle _and_ Characteristics UUID.
*
* Attribute handles are unique for each device (server) (BT Core Spec v5.2: Vol 3, Part F Protocol..: 3.2.2 Attribute Handle).
*
* Attribute handles are unique for each device (server) (BT Core Spec v5.2: Vol 3, Part F Protocol..: 3.2.2 Attribute Handle).
*
* Attribute handles are unique for each device (server) (BT Core Spec v5.2: Vol 3, Part F Protocol..: 3.2.2 Attribute Handle).
*
* Method enables notification and/or indication for this characteristic at BLE level.
*
* Implementation masks this Characteristic properties PropertyBitVal::Notify and PropertyBitVal::Indicate
* with the respective user request parameters, hence removes unsupported requests.
*
* Notification and/or indication configuration is only performed per characteristic if changed.
*
* It is recommended to utilize notification over indication, as its link-layer handshake
* and higher potential bandwidth may deliver material higher performance.
*
* Method will attempt to enable notification on the BLE level, if available,
* otherwise indication if available.
*
* Notification and/or indication configuration is only performed per characteristic if changed.
*
* It is recommended to utilize notification over indication, as its link-layer handshake
* and higher potential bandwidth may deliver material higher performance.
*
* Occurring notifications and indications, if enabled via configNotificationIndication(bool, bool, bool[])
* or enableNotificationOrIndication(bool[]),
* will call the respective BTGattCharListener callback method.
*
* Returns true if the given listener is not element of the list and has been newly added,
* otherwise false.
*
* Convenience delegation call to BTGattHandler via BTDevice
*
* To restrict the listener to listen only to this BTGattChar instance,
* user has to implement BTGattCharListener::match(BTGattCharRef) accordingly.
*
* Implementation will attempt to enable notification only, if available,
* otherwise indication if available.
* Occurring notifications and indications will call the respective BTGattCharListener
* callback method.
*
* Returns true if enabling the notification and/or indication was successful
* and if the given listener is not element of the list and has been newly added,
* otherwise false.
*
* To restrict the listener to listen only to this BTGattChar instance,
* user has to implement BTGattCharListener::match(BTGattCharRef) accordingly.
*
* Returns true if the given listener is an element of the list and has been removed,
* otherwise false.
*
* Convenience delegation call to BTGattHandler via BTDevice
* performing addCharListener(..)
* and {@link #configNotificationIndication(bool, bool, bool[]) if {@code disableIndicationNotification == true}.
*
* If the BTDevice's BTGattHandler is null, i.e. not connected, {@code false} is being returned.
*
* Returns the number of removed event listener.
*
* Convenience delegation call to BTGattHandler via BTDevice
* performing addCharListener(..)
* and configNotificationIndication(..) if {@code disableIndicationNotification == true}.
*
* If the BTDevice's BTGattHandler is null, i.e. not connected, {@code zero} is being returned.
*
* BT Core Spec v5.2: Vol 3, Part G GATT: 4.8.3 Read Long Characteristic Value
*
* If expectedLength = 0, then only one ATT_READ_REQ/RSP will be used.
*
* If expectedLength < 0, then long values using multiple ATT_READ_BLOB_REQ/RSP will be used until
* the response returns zero. This is the default parameter.
*
* If expectedLength > 0, then long values using multiple ATT_READ_BLOB_REQ/RSP will be used
* if required until the response returns zero.
*
* Convenience delegation call to BTGattHandler via BTDevice
*
*
* org.bluez.GattCharacteristic1 :: array{string} Flags [read-only]
*
*/
static std::string getPropertyString(const PropertyBitVal prop) noexcept;
static std::string getPropertiesString(const PropertyBitVal properties) noexcept;
static jau::darray
* For this purpose, use may derive from AssociatedBTGattCharListener,
* which provides these simple matching filter facilities.
*
* Notification and/or indication configuration is only performed per characteristic if changed.
*
* Implementation uses enableNotificationOrIndication(bool[]) to enable either.
*
* For this purpose, use may derive from AssociatedBTGattCharListener,
* which provides these simple matching filter facilities.
*
* Convenience delegation call to BTGattHandler via BTDevice *
*
* If the BTDevice's BTGattHandler is null, i.e. not connected, an IllegalStateException is thrown. * */ bool writeValue(const TROOctets & value); /** * BT Core Spec v5.2: Vol 3, Part G GATT: 4.9.1 Write Characteristic Value Without Response ** Convenience delegation call to BTGattHandler via BTDevice *
*
* If the BTDevice's BTGattHandler is null, i.e. not connected, an IllegalStateException is thrown. * */ bool writeValueNoResp(const TROOctets & value); }; typedef std::shared_ptr
* A listener instance may be attached to a {@link BTGattChar} via
* {@link BTGattChar::addCharListener(std::shared_ptr
* User may utilize {@link AssociatedBTGattCharListener} to listen to only one {@link BTGattChar}. *
*
* A listener instance may be attached to a {@link BTGattHandler} via
* {@link BTGattHandler::addCharListener(std::shared_ptr
* The listener receiver maintains a unique set of listener instances without duplicates. *
*/ class BTGattCharListener { public: /** * Custom filter for all event methods, * which will not be called if this method returns false. ** User may override this method to test whether the methods shall be called * for the given BTGattChar. *
** Defaults to true; *
*/ virtual bool match(const BTGattChar & characteristic) noexcept { (void)characteristic; return true; } /** * Called from native BLE stack, initiated by a received notification associated * with the given {@link BTGattChar}. * @param charDecl {@link BTGattChar} related to this notification * @param charValue the notification value * @param timestamp the indication monotonic timestamp, see getCurrentMilliseconds() */ virtual void notificationReceived(BTGattCharRef charDecl, const TROOctets& charValue, const uint64_t timestamp) = 0; /** * Called from native BLE stack, initiated by a received indication associated * with the given {@link BTGattChar}. * @param charDecl {@link BTGattChar} related to this indication * @param charValue the indication value * @param timestamp the indication monotonic timestamp, see {@link BluetoothUtils#getCurrentMilliseconds()} * @param confirmationSent if true, the native stack has sent the confirmation, otherwise user is required to do so. */ virtual void indicationReceived(BTGattCharRef charDecl, const TROOctets& charValue, const uint64_t timestamp, const bool confirmationSent) = 0; virtual ~BTGattCharListener() noexcept {} /** * Default comparison operator, merely testing for same memory reference. ** Specializations may override. *
*/ virtual bool operator==(const BTGattCharListener& rhs) const noexcept { return this == &rhs; } bool operator!=(const BTGattCharListener& rhs) const noexcept { return !(*this == rhs); } }; class AssociatedBTGattCharListener : public BTGattCharListener{ private: const BTGattChar * associatedChar; public: /** * Passing the associated BTGattChar to filter out non matching events. */ AssociatedBTGattCharListener(const BTGattChar * characteristicMatch) noexcept : associatedChar(characteristicMatch) { } bool match(const BTGattChar & characteristic) noexcept override { if( nullptr == associatedChar ) { return true; } return *associatedChar == characteristic; } }; } // namespace direct_bt #endif /* BT_GATT_CHARACTERISTIC_HPP_ */