Direct-BT v3.3.0-1-gc2d430c
Direct-BT - Direct Bluetooth Programming.
Classes | Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
direct_bt::BTGattHandler Class Reference

A thread safe GATT handler associated to one device via one L2CAP connection. More...

#include <BTGattHandler.hpp>

Collaboration diagram for direct_bt::BTGattHandler:

Classes

class  GattServerHandler
 Internal handler implementation for given DBGattServer instance matching its DBGattServer::Mode. More...
 
class  NativeGattCharListener
 Native GATT characteristic event listener for notification and indication events received from a GATT server. More...
 

Public Types

enum class  Defaults : uint16_t { MAX_ATT_MTU = 512 + 1 , MIN_ATT_MTU = 23 }
 
typedef jau::darray< BTGattServiceRef, size_typeGattServiceList_t
 
typedef jau::cow_darray< NativeGattCharListenerRef, size_typeNativeGattCharListenerList_t
 
typedef std::shared_ptr< NativeGattCharListenerNativeGattCharListenerRef
 
typedef jau::darray< NativeGattCharListener::Section, size_typeNativeGattCharSections_t
 
typedef jau::nsize_t size_type
 
typedef jau::snsize_t ssize_type
 

Public Member Functions

 BTGattHandler (const BTDeviceRef &device, L2CAPClient &l2cap_att, const int32_t supervision_timeout) noexcept
 Constructing a new BTGattHandler instance with its opened and connected L2CAP channel. More...
 
 BTGattHandler (const BTGattHandler &)=delete
 
 ~BTGattHandler () noexcept
 Destructor closing this instance including L2CAP channel, see disconnect(). More...
 
bool addCharListener (const BTGattCharListenerRef &l) noexcept
 Add the given listener to the list if not already present. More...
 
bool addCharListener (const BTGattCharListenerRef &l, const BTGattCharRef &d) noexcept
 Please use BTGattChar::addCharListener() for clarity, merely existing here to allow JNI access. More...
 
bool addCharListener (const NativeGattCharListenerRef &l) noexcept
 Add the given listener to the list if not already present. More...
 
bool configNotificationIndication (BTGattDesc &cd, const bool enableNotification, const bool enableIndication) noexcept
 BT Core Spec v5.2: Vol 3, Part G GATT: 3.3.3.3 Client Characteristic Configuration. More...
 
bool disconnect (const bool disconnect_device, const bool ioerr_cause) noexcept
 Disconnect this BTGattHandler and optionally the associated device. More...
 
BTGattCharRef findCharacterisicsByValueHandle (const BTGattServiceRef &service, const uint16_t charValueHandle) noexcept
 Find and return the BTGattChar within given primary service via given characteristic value handle. More...
 
BTGattCharRef findCharacterisicsByValueHandle (const GattServiceList_t &services_, const uint16_t charValueHandle) noexcept
 Find and return the BTGattChar within given list of primary services via given characteristic value handle. More...
 
jau::nsize_t getCharListenerCount () const noexcept
 Return event listener count. More...
 
BTDeviceRef getDeviceChecked () const
 
std::shared_ptr< GattDeviceInformationSvcgetDeviceInformation (GattServiceList_t &primServices) noexcept
 
std::shared_ptr< GattDeviceInformationSvcgetDeviceInformation (jau::darray< BTGattCharRef > &deviceInfoCharDeclList) noexcept
 
BTDeviceRef getDeviceUnchecked () const noexcept
 
std::shared_ptr< GattGenericAccessSvcgetGenericAccess () noexcept
 Returns the internal kept shared GattGenericAccessSvc instance. More...
 
std::shared_ptr< GattGenericAccessSvcgetGenericAccess (GattServiceList_t &primServices) noexcept
 Higher level semantic functionality. More...
 
std::shared_ptr< GattGenericAccessSvcgetGenericAccess (jau::darray< BTGattCharRef > &genericAccessCharDeclList) noexcept
 
GATTRole getRole () const noexcept
 Return the local GATTRole to the remote BTDevice. More...
 
bool getSendIndicationConfirmation () noexcept
 Returns whether sending an immediate confirmation for received indication events from the device is enabled. More...
 
uint16_t getServerMTU () const noexcept
 
GattServiceList_tgetServices () noexcept
 Returns a reference of the internal kept BTGattService list. More...
 
std::string getStateString () const noexcept
 
uint16_t getUsedMTU () const noexcept
 
bool hasIOError () const noexcept
 
bool initClientGatt (const std::shared_ptr< BTGattHandler > &shared_this, bool &already_init) noexcept
 Initialize the connection and internal data set for GATT client operations: More...
 
bool isConnected () const noexcept
 
void notifyNativeMTUResponse (const uint16_t clientMTU, const AttPDUMsg &pduReply, const AttErrorRsp::ErrorCode error_reply, const uint16_t serverMTU, const uint16_t usedMTU, const BTDeviceRef &clientRequester) noexcept
 Notify all NativeGattCharListener about a completed MTU exchange request and response to and from this GATTRole::Server. More...
 
void notifyNativeReadResponse (const uint16_t handle, const uint16_t value_offset, const AttPDUMsg &pduReply, const AttErrorRsp::ErrorCode error_reply, const jau::TROOctets &data_reply, const BTDeviceRef &clientRequester) noexcept
 Notify all NativeGattCharListener about a completed read request and response to and from this GATTRole::Server. More...
 
void notifyNativeReplyReceived (const AttPDUMsg &pduReply, const BTDeviceRef &clientDest) noexcept
 Notify all NativeGattCharListener about a low-level AttPDUMsg reply being received from this GATTRole::Server. More...
 
void notifyNativeRequestSent (const AttPDUMsg &pduRequest, const BTDeviceRef &clientSource) noexcept
 Notify all NativeGattCharListener about a low-level AttPDUMsg request being sent to this GATTRole::Server. More...
 
void notifyNativeWriteRequest (const uint16_t handle, const jau::TROOctets &data, const NativeGattCharSections_t &sections, const bool with_response, const BTDeviceRef &clientSource) noexcept
 Notify all NativeGattCharListener about a completed write request sent to this GATTRole::Server. More...
 
void notifyNativeWriteResponse (const AttPDUMsg &pduReply, const AttErrorRsp::ErrorCode error_code, const BTDeviceRef &clientDest) noexcept
 Notify all NativeGattCharListener about a write response received from this GATTRole::Server. More...
 
void operator= (const BTGattHandler &)=delete
 
bool ping () noexcept
 Issues a ping to the device, validating whether it is still reachable. More...
 
void printCharListener () noexcept
 Print a list of all BTGattCharListener and NativeGattCharListener. More...
 
bool readCharacteristicValue (const BTGattChar &c, jau::POctets &res, ssize_type expectedLength=-1) noexcept
 BT Core Spec v5.2: Vol 3, Part G GATT: 4.8.1 Read Characteristic Value. More...
 
bool readDescriptorValue (BTGattDesc &cd, ssize_type expectedLength=-1) noexcept
 BT Core Spec v5.2: Vol 3, Part G GATT: 4.12.1 Read Characteristic Descriptor. More...
 
bool readValue (const uint16_t handle, jau::POctets &res, ssize_type expectedLength=-1) noexcept
 Generic read GATT value and long value. More...
 
size_type removeAllAssociatedCharListener (const BTGattChar *associatedChar) noexcept
 
size_type removeAllAssociatedCharListener (const BTGattCharRef &associatedChar) noexcept
 Remove all BTGattCharListener from the list, which are associated to the given BTGattChar when added via BTGattChar::addCharListener(). More...
 
size_type removeAllCharListener () noexcept
 Remove all event listener from the list. More...
 
bool removeCharListener (const BTGattCharListener *l) noexcept
 Remove the given listener from the list. More...
 
bool removeCharListener (const BTGattCharListenerRef &l) noexcept
 Remove the given listener from the list. More...
 
bool removeCharListener (const NativeGattCharListenerRef &l) noexcept
 Remove the given listener from the list. More...
 
bool send (const AttPDUMsg &msg) noexcept
 Sends the given AttPDUMsg to the connected device via l2cap. More...
 
bool sendIndication (const uint16_t char_value_handle, const jau::TROOctets &value) noexcept
 Send an indication event consisting out of the given value representing the given characteristic value handle to the connected BTRole::Master. More...
 
bool sendNotification (const uint16_t char_value_handle, const jau::TROOctets &value) noexcept
 Send a notification event consisting out of the given value representing the given characteristic value handle to the connected BTRole::Master. More...
 
std::unique_ptr< const AttPDUMsgsendWithReply (const AttPDUMsg &msg, const jau::fraction_i64 &timeout) noexcept
 Sends the given AttPDUMsg to the connected device via l2cap using send(). More...
 
void setSendIndicationConfirmation (const bool v) noexcept
 Enable or disable sending an immediate confirmation for received indication events from the device. More...
 
void setUsedMTU (const uint16_t mtu) noexcept
 
std::string toString () const noexcept
 
bool writeCharacteristicValue (const BTGattChar &c, const jau::TROOctets &value) noexcept
 BT Core Spec v5.2: Vol 3, Part G GATT: 4.9.3 Write Characteristic Value. More...
 
bool writeCharacteristicValueNoResp (const BTGattChar &c, const jau::TROOctets &value) noexcept
 BT Core Spec v5.2: Vol 3, Part G GATT: 4.9.1 Write Characteristic Value Without Response. More...
 
bool writeDescriptorValue (const BTGattDesc &cd) noexcept
 BT Core Spec v5.2: Vol 3, Part G GATT: 4.12.3 Write Characteristic Descriptors. More...
 
bool writeValue (const uint16_t handle, const jau::TROOctets &value, const bool withResponse) noexcept
 Generic write GATT value and long value. More...
 

Static Public Member Functions

static constexpr uint16_t number (const Defaults d)
 

Public Attributes

const BTGattEnvenv
 Environment runtime configuration, usually used internally only. More...
 
const jau::fraction_i64 read_cmd_reply_timeout
 Derived environment runtime configuration, usually used internally only. More...
 
const int32_t supervision_timeout
 Supervison timeout of the connection. More...
 
const jau::fraction_i64 write_cmd_reply_timeout
 Derived environment runtime configuration, usually used internally only. More...
 

Detailed Description

A thread safe GATT handler associated to one device via one L2CAP connection.

Implementation utilizes a lock free ringbuffer receiving data within its separate thread.

Controlling Environment variables, see BTGattEnv.

Local GATTRole to a remote BTDevice, (see getRole()):

See BTDevice roles and BTAdapter roles.

See also
GATTRole
BTAdapter roles.
BTDevice roles.
BTGattHandler roles.
Bluetooth Specification

Definition at line 169 of file BTGattHandler.hpp.

Member Typedef Documentation

◆ size_type

Definition at line 443 of file BTGattHandler.hpp.

◆ ssize_type

Definition at line 444 of file BTGattHandler.hpp.

◆ NativeGattCharListenerRef

Definition at line 446 of file BTGattHandler.hpp.

◆ NativeGattCharListenerList_t

Definition at line 447 of file BTGattHandler.hpp.

◆ NativeGattCharSections_t

Definition at line 448 of file BTGattHandler.hpp.

◆ GattServiceList_t

Definition at line 449 of file BTGattHandler.hpp.

Member Enumeration Documentation

◆ Defaults

enum class direct_bt::BTGattHandler::Defaults : uint16_t
strong
Enumerator
MAX_ATT_MTU 

BT Core Spec v5.2: Vol 3, Part F 3.2.8: Maximum length of an attribute value.

We add +1 for opcode, but don't add for different PDU type's parameter upfront the attribute value.

MIN_ATT_MTU 

Definition at line 171 of file BTGattHandler.hpp.

Constructor & Destructor Documentation

◆ BTGattHandler() [1/2]

BTGattHandler::BTGattHandler ( const BTDeviceRef device,
L2CAPClient l2cap_att,
const int32_t  supervision_timeout 
)
noexcept

Constructing a new BTGattHandler instance with its opened and connected L2CAP channel.

After successful l2cap connection, the MTU will be exchanged. See getServerMTU() and getUsedMTU(), the latter is in use.

Parameters
devicethe connected remote device
l2cap_attthe underlying used L2CAP
supervision_timeoutthe connection supervising timeout in [ms]

Definition at line 594 of file BTGattHandler.cpp.

◆ BTGattHandler() [2/2]

direct_bt::BTGattHandler::BTGattHandler ( const BTGattHandler )
delete

◆ ~BTGattHandler()

BTGattHandler::~BTGattHandler ( )
noexcept

Destructor closing this instance including L2CAP channel, see disconnect().

Definition at line 660 of file BTGattHandler.cpp.

Member Function Documentation

◆ number()

static constexpr uint16_t direct_bt::BTGattHandler::number ( const Defaults  d)
inlinestaticconstexpr

Definition at line 183 of file BTGattHandler.hpp.

◆ operator=()

void direct_bt::BTGattHandler::operator= ( const BTGattHandler )
delete

◆ getDeviceUnchecked()

BTDeviceRef direct_bt::BTGattHandler::getDeviceUnchecked ( ) const
inlinenoexcept

Definition at line 599 of file BTGattHandler.hpp.

Here is the caller graph for this function:

◆ getDeviceChecked()

BTDeviceRef BTGattHandler::getDeviceChecked ( ) const

Definition at line 78 of file BTGattHandler.cpp.

◆ getRole()

GATTRole direct_bt::BTGattHandler::getRole ( ) const
inlinenoexcept

Return the local GATTRole to the remote BTDevice.

See also
GATTRole
BTGattHandler roles.
Since
2.4.0

Definition at line 608 of file BTGattHandler.hpp.

Here is the caller graph for this function:

◆ isConnected()

bool direct_bt::BTGattHandler::isConnected ( ) const
inlinenoexcept

Definition at line 610 of file BTGattHandler.hpp.

◆ hasIOError()

bool direct_bt::BTGattHandler::hasIOError ( ) const
inlinenoexcept

Definition at line 611 of file BTGattHandler.hpp.

◆ getStateString()

std::string BTGattHandler::getStateString ( ) const
noexcept

Definition at line 670 of file BTGattHandler.cpp.

Here is the caller graph for this function:

◆ disconnect()

bool BTGattHandler::disconnect ( const bool  disconnect_device,
const bool  ioerr_cause 
)
noexcept

Disconnect this BTGattHandler and optionally the associated device.

Parameters
disconnect_deviceif true, associated device will also be disconnected, otherwise not.
ioerr_causeif true, reason for disconnection is an IO error
Returns
true if successful, otherwise false

Definition at line 674 of file BTGattHandler.cpp.

Here is the caller graph for this function:

◆ getServerMTU()

uint16_t direct_bt::BTGattHandler::getServerMTU ( ) const
inlinenoexcept

Definition at line 622 of file BTGattHandler.hpp.

Here is the caller graph for this function:

◆ getUsedMTU()

uint16_t direct_bt::BTGattHandler::getUsedMTU ( ) const
inlinenoexcept

Definition at line 623 of file BTGattHandler.hpp.

Here is the caller graph for this function:

◆ setUsedMTU()

void direct_bt::BTGattHandler::setUsedMTU ( const uint16_t  mtu)
inlinenoexcept

Definition at line 624 of file BTGattHandler.hpp.

Here is the caller graph for this function:

◆ findCharacterisicsByValueHandle() [1/2]

BTGattCharRef direct_bt::BTGattHandler::findCharacterisicsByValueHandle ( const GattServiceList_t services_,
const uint16_t  charValueHandle 
)
noexcept

Find and return the BTGattChar within given list of primary services via given characteristic value handle.

Returns nullptr if not found.

◆ findCharacterisicsByValueHandle() [2/2]

BTGattCharRef BTGattHandler::findCharacterisicsByValueHandle ( const BTGattServiceRef service,
const uint16_t  charValueHandle 
)
noexcept

Find and return the BTGattChar within given primary service via given characteristic value handle.

Returns nullptr if not found.

Definition at line 899 of file BTGattHandler.cpp.

◆ initClientGatt()

bool BTGattHandler::initClientGatt ( const std::shared_ptr< BTGattHandler > &  shared_this,
bool &  already_init 
)
noexcept

Initialize the connection and internal data set for GATT client operations:

Service discovery may consume 500ms - 2000ms, depending on bandwidth.

Parameters
shared_thisthe shared BTGattHandler reference
already_initif already initialized true, will hold true, otherwise false
Returns
true if already initialized or successfully newly initialized with at least GattGenericAccessSvc available, otherwise false
See also
clientMTUExchange()
discoverCompletePrimaryServices()

Definition at line 908 of file BTGattHandler.cpp.

◆ getServices()

GattServiceList_t & direct_bt::BTGattHandler::getServices ( )
inlinenoexcept

Returns a reference of the internal kept BTGattService list.

The internal list should have been populated via initClientGatt() once.

See also
initClientGatt()

Definition at line 667 of file BTGattHandler.hpp.

◆ getGenericAccess() [1/3]

std::shared_ptr< GattGenericAccessSvc > direct_bt::BTGattHandler::getGenericAccess ( )
inlinenoexcept

Returns the internal kept shared GattGenericAccessSvc instance.

This instance is created via initClientGatt().

See also
initClientGatt()

Definition at line 676 of file BTGattHandler.hpp.

◆ send()

bool BTGattHandler::send ( const AttPDUMsg msg)
noexcept

Sends the given AttPDUMsg to the connected device via l2cap.

ATT_MTU range

  • ATT_MTU minimum is 23 bytes (Vol 3, Part G: 5.2.1)
  • ATT_MTU is negotiated, maximum attribute value length is 512 bytes (Vol 3, Part F: 3.2.8-9)
  • ATT Value sent: [1 .. ATT_MTU-1] (Vol 3, Part F: 3.2.8-9)

Implementation disconnect() and returns false if an unexpected l2cap write errors occurs.

Parameters
msgthe message to be send
Returns
true if successful otherwise false if write error, not connected or if message size exceeds usedMTU-1.

Definition at line 727 of file BTGattHandler.cpp.

Here is the caller graph for this function:

◆ sendWithReply()

std::unique_ptr< const AttPDUMsg > BTGattHandler::sendWithReply ( const AttPDUMsg msg,
const jau::fraction_i64 timeout 
)
noexcept

Sends the given AttPDUMsg to the connected device via l2cap using send().

Implementation waits for timeout milliseconds receiving the response from the ringbuffer, filled from the reader-thread.

Implementation disconnect() and returns nullptr if no matching reply has been received within timeout milliseconds.

In case method completes successfully, the message has been send out and a reply has also been received and is returned as the result.

Parameters
msgthe message to be send
timeoutfractions of seconds to wait for a reply
Returns
non nullptr for a valid reply, otherwise nullptr

Definition at line 766 of file BTGattHandler.cpp.

◆ readValue()

bool BTGattHandler::readValue ( const uint16_t  handle,
jau::POctets res,
ssize_type  expectedLength = -1 
)
noexcept

Generic read GATT value and long 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.

Definition at line 1238 of file BTGattHandler.cpp.

◆ readCharacteristicValue()

bool BTGattHandler::readCharacteristicValue ( const BTGattChar c,
jau::POctets res,
ssize_type  expectedLength = -1 
)
noexcept

BT Core Spec v5.2: Vol 3, Part G GATT: 4.8.1 Read Characteristic Value.

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.

Definition at line 1229 of file BTGattHandler.cpp.

Here is the caller graph for this function:

◆ readDescriptorValue()

bool BTGattHandler::readDescriptorValue ( BTGattDesc cd,
ssize_type  expectedLength = -1 
)
noexcept

BT Core Spec v5.2: Vol 3, Part G GATT: 4.12.1 Read Characteristic Descriptor.

BT Core Spec v5.2: Vol 3, Part G GATT: 4.12.2 Read Long Characteristic Descriptor

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.

Definition at line 1219 of file BTGattHandler.cpp.

◆ writeValue()

bool BTGattHandler::writeValue ( const uint16_t  handle,
const jau::TROOctets value,
const bool  withResponse 
)
noexcept

Generic write GATT value and long value.

Definition at line 1345 of file BTGattHandler.cpp.

◆ writeDescriptorValue()

bool BTGattHandler::writeDescriptorValue ( const BTGattDesc cd)
noexcept

BT Core Spec v5.2: Vol 3, Part G GATT: 4.12.3 Write Characteristic Descriptors.

BT Core Spec v5.2: Vol 3, Part G GATT: 3.3.3 Characteristic Descriptor

BT Core Spec v5.2: Vol 3, Part G GATT: 3.3.3.3 Client Characteristic Configuration

Definition at line 1315 of file BTGattHandler.cpp.

◆ writeCharacteristicValue()

bool BTGattHandler::writeCharacteristicValue ( const BTGattChar c,
const jau::TROOctets value 
)
noexcept

BT Core Spec v5.2: Vol 3, Part G GATT: 4.9.3 Write Characteristic Value.

Definition at line 1329 of file BTGattHandler.cpp.

◆ writeCharacteristicValueNoResp()

bool BTGattHandler::writeCharacteristicValueNoResp ( const BTGattChar c,
const jau::TROOctets value 
)
noexcept

BT Core Spec v5.2: Vol 3, Part G GATT: 4.9.1 Write Characteristic Value Without Response.

Definition at line 1339 of file BTGattHandler.cpp.

◆ configNotificationIndication()

bool BTGattHandler::configNotificationIndication ( BTGattDesc cd,
const bool  enableNotification,
const bool  enableIndication 
)
noexcept

BT Core Spec v5.2: Vol 3, Part G GATT: 3.3.3.3 Client Characteristic Configuration.

Method enables notification and/or indication for the corresponding characteristic at BLE level.

It is recommended to utilize notification over indication, as its link-layer handshake and higher potential bandwidth may deliver material higher performance.

Throws an IllegalArgumentException if the given BTGattDesc is not a ClientCharacteristicConfiguration.

Definition at line 1397 of file BTGattHandler.cpp.

◆ sendNotification()

bool BTGattHandler::sendNotification ( const uint16_t  char_value_handle,
const jau::TROOctets value 
)
noexcept

Send a notification event consisting out of the given value representing the given characteristic value handle to the connected BTRole::Master.

This command is only valid if this BTGattHandler is in role GATTRole::Server.

Implementation is not receiving any reply after sending out the indication and returns immediately.

Parameters
char_value_handlevalid characteristic value handle, must be sourced from referenced DBGattServer
Returns
true if successful, otherwise false

Definition at line 835 of file BTGattHandler.cpp.

◆ sendIndication()

bool BTGattHandler::sendIndication ( const uint16_t  char_value_handle,
const jau::TROOctets value 
)
noexcept

Send an indication event consisting out of the given value representing the given characteristic value handle to the connected BTRole::Master.

This command is only valid if this BTGattHandler is in role GATTRole::Server.

Implementation awaits the indication reply after sending out the indication.

Parameters
char_value_handlevalid characteristic value handle, must be sourced from referenced DBGattServer
Returns
true if successful, otherwise false

Definition at line 856 of file BTGattHandler.cpp.

◆ addCharListener() [1/3]

bool BTGattHandler::addCharListener ( const BTGattCharListenerRef l)
noexcept

Add the given listener to the list if not already present.

Returns true if the given listener is not element of the list and has been newly added, otherwise false.

Definition at line 108 of file BTGattHandler.cpp.

◆ addCharListener() [2/3]

bool BTGattHandler::addCharListener ( const BTGattCharListenerRef l,
const BTGattCharRef d 
)
noexcept

Please use BTGattChar::addCharListener() for clarity, merely existing here to allow JNI access.

Definition at line 117 of file BTGattHandler.cpp.

◆ removeCharListener() [1/3]

bool BTGattHandler::removeCharListener ( const BTGattCharListenerRef l)
noexcept

Remove the given listener from the list.

Returns true if the given listener is an element of the list and has been removed, otherwise false.

Definition at line 130 of file BTGattHandler.cpp.

◆ removeCharListener() [2/3]

bool BTGattHandler::removeCharListener ( const BTGattCharListener l)
noexcept

Remove the given listener from the list.

Returns true if the given listener is an element of the list and has been removed, otherwise false.

Definition at line 141 of file BTGattHandler.cpp.

◆ removeAllAssociatedCharListener() [1/2]

BTGattHandler::size_type BTGattHandler::removeAllAssociatedCharListener ( const BTGattCharRef associatedChar)
noexcept

Remove all BTGattCharListener from the list, which are associated to the given BTGattChar when added via BTGattChar::addCharListener().

Parameters
associatedCharacteristicthe match criteria to remove any BTGattCharListener from the list
Returns
number of removed listener.

Definition at line 196 of file BTGattHandler.cpp.

◆ removeAllAssociatedCharListener() [2/2]

BTGattHandler::size_type BTGattHandler::removeAllAssociatedCharListener ( const BTGattChar associatedChar)
noexcept

Definition at line 204 of file BTGattHandler.cpp.

◆ addCharListener() [3/3]

bool BTGattHandler::addCharListener ( const NativeGattCharListenerRef l)
noexcept

Add the given listener to the list if not already present.

Returns true if the given listener is not element of the list and has been newly added, otherwise false.

Definition at line 160 of file BTGattHandler.cpp.

◆ removeCharListener() [3/3]

bool BTGattHandler::removeCharListener ( const NativeGattCharListenerRef l)
noexcept

Remove the given listener from the list.

Returns true if the given listener is an element of the list and has been removed, otherwise false.

Definition at line 168 of file BTGattHandler.cpp.

◆ removeAllCharListener()

BTGattHandler::size_type BTGattHandler::removeAllCharListener ( )
noexcept

Remove all event listener from the list.

Returns the number of removed event listener.

Definition at line 225 of file BTGattHandler.cpp.

◆ getCharListenerCount()

jau::nsize_t direct_bt::BTGattHandler::getCharListenerCount ( ) const
inlinenoexcept

Return event listener count.

Definition at line 904 of file BTGattHandler.hpp.

◆ printCharListener()

void BTGattHandler::printCharListener ( )
noexcept

Print a list of all BTGattCharListener and NativeGattCharListener.

This is merely a facility for debug and analysis.

Definition at line 177 of file BTGattHandler.cpp.

◆ notifyNativeRequestSent()

void BTGattHandler::notifyNativeRequestSent ( const AttPDUMsg pduRequest,
const BTDeviceRef clientSource 
)
noexcept

Notify all NativeGattCharListener about a low-level AttPDUMsg request being sent to this GATTRole::Server.

This functionality has an informal character only.

Parameters
pduRequestthe request
clientSourcethe GATTRole::Client source device, only known and not nullptr for DBGattServer::Mode:FWD GattServerHandler

Definition at line 233 of file BTGattHandler.cpp.

◆ notifyNativeReplyReceived()

void BTGattHandler::notifyNativeReplyReceived ( const AttPDUMsg pduReply,
const BTDeviceRef clientDest 
)
noexcept

Notify all NativeGattCharListener about a low-level AttPDUMsg reply being received from this GATTRole::Server.

Parameters
pduReplythe response
clientDestthe GATTRole::Client receiver device, only known and not nullptr for DBGattServer::Mode:FWD GattServerHandler

Definition at line 250 of file BTGattHandler.cpp.

◆ notifyNativeMTUResponse()

void BTGattHandler::notifyNativeMTUResponse ( const uint16_t  clientMTU,
const AttPDUMsg pduReply,
const AttErrorRsp::ErrorCode  error_reply,
const uint16_t  serverMTU,
const uint16_t  usedMTU,
const BTDeviceRef clientRequester 
)
noexcept

Notify all NativeGattCharListener about a completed MTU exchange request and response to and from this GATTRole::Server.

This functionality has an informal character only.

Parameters
clientMTUthe client MTU request
pduReplythe response
error_replyin case of an AttErrorRsp reply, the AttErrorRsp::ErrorCode is passed for convenience, otherwise AttErrorRsp::ErrorCode::NO_ERROR.
serverMTUthe replied server MTU, passed for convenience
usedMTUthe MTU minimum of client and server to be used, passed for convenience
clientRequesterthe GATTRole::Client requester device, only known and not nullptr for DBGattServer::Mode:FWD GattServerHandler

Definition at line 267 of file BTGattHandler.cpp.

◆ notifyNativeWriteRequest()

void BTGattHandler::notifyNativeWriteRequest ( const uint16_t  handle,
const jau::TROOctets data,
const NativeGattCharSections_t sections,
const bool  with_response,
const BTDeviceRef clientSource 
)
noexcept

Notify all NativeGattCharListener about a completed write request sent to this GATTRole::Server.

This functionality has an informal character only.

Parameters
handlethe GATT characteristic or descriptor handle, requested to be written
datathe data requested to be written
sectionslist of NativeGattCharListener::Section within given data, requested to be written. Overlapping consecutive sections have already been merged.
with_responsetrue if the write requests expects a response, i.e. via AttPDUMsg::Opcode::WRITE_REQ or AttPDUMsg::Opcode::EXECUTE_WRITE_REQ
clientSourcethe GATTRole::Client source device, only known and not nullptr for DBGattServer::Mode:FWD GattServerHandler

Definition at line 288 of file BTGattHandler.cpp.

◆ notifyNativeWriteResponse()

void BTGattHandler::notifyNativeWriteResponse ( const AttPDUMsg pduReply,
const AttErrorRsp::ErrorCode  error_code,
const BTDeviceRef clientDest 
)
noexcept

Notify all NativeGattCharListener about a write response received from this GATTRole::Server.

This functionality has an informal character only.

Parameters
pduReplythe response
error_codein case of an AttErrorRsp reply, the AttErrorRsp::ErrorCode is passed for convenience, otherwise AttErrorRsp::ErrorCode::NO_ERROR.
clientDestthe GATTRole::Client receiver device, only known and not nullptr for DBGattServer::Mode:FWD GattServerHandler

Definition at line 307 of file BTGattHandler.cpp.

◆ notifyNativeReadResponse()

void BTGattHandler::notifyNativeReadResponse ( const uint16_t  handle,
const uint16_t  value_offset,
const AttPDUMsg pduReply,
const AttErrorRsp::ErrorCode  error_reply,
const jau::TROOctets data_reply,
const BTDeviceRef clientRequester 
)
noexcept

Notify all NativeGattCharListener about a completed read request and response to and from this GATTRole::Server.

This functionality has an informal character only.

Parameters
handlethe GATT characteristic or descriptor handle, requested to be written
value_offsetthe value offset of the data to be read
pduReplythe response
error_replyin case of an AttErrorRsp reply, the AttErrorRsp::ErrorCode is passed for convenience, otherwise AttErrorRsp::ErrorCode::NO_ERROR.
data_replythe replied read data at given value_offset, passed for convenience
clientRequesterthe GATTRole::Client requester device, only known and not nullptr for DBGattServer::Mode:FWD GattServerHandler

Definition at line 324 of file BTGattHandler.cpp.

◆ setSendIndicationConfirmation()

void BTGattHandler::setSendIndicationConfirmation ( const bool  v)
noexcept

Enable or disable sending an immediate confirmation for received indication events from the device.

Default value is true.

This setting is per BTGattHandler and hence per BTDevice.

Definition at line 343 of file BTGattHandler.cpp.

◆ getSendIndicationConfirmation()

bool BTGattHandler::getSendIndicationConfirmation ( )
noexcept

Returns whether sending an immediate confirmation for received indication events from the device is enabled.

Default value is true.

This setting is per BTGattHandler and hence per BTDevice.

Definition at line 347 of file BTGattHandler.cpp.

◆ getGenericAccess() [2/3]

std::shared_ptr< GattGenericAccessSvc > direct_bt::BTGattHandler::getGenericAccess ( GattServiceList_t primServices)
noexcept

Higher level semantic functionality.

◆ getGenericAccess() [3/3]

std::shared_ptr< GattGenericAccessSvc > BTGattHandler::getGenericAccess ( jau::darray< BTGattCharRef > &  genericAccessCharDeclList)
noexcept

Definition at line 1431 of file BTGattHandler.cpp.

◆ getDeviceInformation() [1/2]

std::shared_ptr< GattDeviceInformationSvc > direct_bt::BTGattHandler::getDeviceInformation ( GattServiceList_t primServices)
noexcept

◆ getDeviceInformation() [2/2]

std::shared_ptr< GattDeviceInformationSvc > BTGattHandler::getDeviceInformation ( jau::darray< BTGattCharRef > &  deviceInfoCharDeclList)
noexcept

Definition at line 1508 of file BTGattHandler.cpp.

◆ ping()

bool BTGattHandler::ping ( )
noexcept

Issues a ping to the device, validating whether it is still reachable.

This method could be periodically utilized to shorten the underlying OS disconnect period after turning the device off, which lies within 7-13s.

In case the device is no more reachable, disconnect will be initiated due to the occurring IO error.

Returns
true if successful, otherwise false in case no GATT services exists etc.

Definition at line 1476 of file BTGattHandler.cpp.

◆ toString()

std::string BTGattHandler::toString ( ) const
noexcept

Definition at line 1588 of file BTGattHandler.cpp.

Here is the caller graph for this function:

Member Data Documentation

◆ supervision_timeout

const int32_t direct_bt::BTGattHandler::supervision_timeout

Supervison timeout of the connection.

Definition at line 186 of file BTGattHandler.hpp.

◆ env

const BTGattEnv& direct_bt::BTGattHandler::env

Environment runtime configuration, usually used internally only.

Definition at line 188 of file BTGattHandler.hpp.

◆ read_cmd_reply_timeout

const jau::fraction_i64 direct_bt::BTGattHandler::read_cmd_reply_timeout

Derived environment runtime configuration, usually used internally only.

Definition at line 190 of file BTGattHandler.hpp.

◆ write_cmd_reply_timeout

const jau::fraction_i64 direct_bt::BTGattHandler::write_cmd_reply_timeout

Derived environment runtime configuration, usually used internally only.

Definition at line 192 of file BTGattHandler.hpp.


The documentation for this class was generated from the following files: