Direct-BT v3.3.0-1-gc2d430c
Direct-BT - Direct Bluetooth Programming.
|
L2CAP read/write communication channel to remote device. More...
#include <L2CAPComm.hpp>
Public Types | |
enum class | Defaults : int { L2CAP_CONNECT_MAX_RETRY = 3 } |
enum class | RWExitCode : jau::snsize_t { SUCCESS = 0 , NOT_OPEN = -1 , INTERRUPTED = -2 , INVALID_SOCKET_DD = -3 , POLL_ERROR = -10 , POLL_TIMEOUT = -11 , READ_ERROR = -20 , READ_TIMEOUT = -21 , WRITE_ERROR = -30 } |
Exit code for read() and write() operations. More... | |
Public Types inherited from direct_bt::L2CAPComm | |
typedef jau::function< bool(int)> | get_boolean_callback_t |
Utilized to query for external interruption, whether device is still connected etc. More... | |
Public Member Functions | |
L2CAPClient (const uint16_t adev_id, BDAddressAndType adapterAddressAndType, const L2CAP_PSM psm, const L2CAP_CID cid) noexcept | |
Constructing a non connected L2CAP channel instance for the pre-defined PSM and CID. More... | |
L2CAPClient (const uint16_t adev_id, BDAddressAndType adapterAddressAndType, const L2CAP_PSM psm, const L2CAP_CID cid, BDAddressAndType remoteAddressAndType, int client_socket) noexcept | |
Constructing a connected L2CAP channel instance for the pre-defined PSM and CID. More... | |
~L2CAPClient () noexcept override | |
Destructor closing the L2CAP channel, see close() . More... | |
bool | close () noexcept override |
Closing the L2CAP channel, locking mutex_write() . More... | |
BTSecurityLevel | getBTSecurityLevel () noexcept |
Fetches the current BlueZ's L2CAP socket BT_SECURITY sec_level. More... | |
const BDAddressAndType & | getRemoteAddressAndType () const noexcept |
std::string | getStateString () const noexcept override |
bool | hasIOError () const noexcept |
std::recursive_mutex & | mutex_write () noexcept |
Return the recursive write mutex for multithreading access. More... | |
bool | open (const BTDevice &device, const BTSecurityLevel sec_level=BTSecurityLevel::NONE) noexcept |
Opens and connects the L2CAP channel, locking mutex_write() . More... | |
jau::snsize_t | read (uint8_t *buffer, const jau::nsize_t capacity) noexcept |
Generic read, w/o locking suitable for a unique ringbuffer sink. More... | |
bool | setBTSecurityLevel (const BTSecurityLevel sec_level) noexcept |
If sec_level > BTSecurityLevel::UNSET, sets the BlueZ's L2CAP socket BT_SECURITY sec_level, determining the SMP security mode per connection. More... | |
std::string | toString () const noexcept override |
jau::snsize_t | write (const uint8_t *buffer, const jau::nsize_t length) noexcept |
Generic write, locking mutex_write() . More... | |
Public Member Functions inherited from direct_bt::L2CAPComm | |
L2CAPComm (const L2CAPComm &)=delete | |
L2CAPComm (const uint16_t adev_id, BDAddressAndType localAddressAndType, const L2CAP_PSM psm, const L2CAP_CID cid) noexcept | |
virtual | ~L2CAPComm () noexcept=default |
Destructor specialization shall close the L2CAP socket, see close() . More... | |
virtual bool | close () noexcept=0 |
Closing the L2CAP socket, see specializations. More... | |
virtual std::string | getStateString () const noexcept=0 |
bool | interrupted () const noexcept |
Returns true if interrupted by internal or external cause, hence shall stop connecting and reading. More... | |
bool | is_open () const noexcept |
void | operator= (const L2CAPComm &)=delete |
void | set_interrupted_query (get_boolean_callback_t is_interrupted_cb) noexcept |
The external is interrupted callback is used until close(), thereafter it is removed. More... | |
int | socket () const noexcept |
Return this L2CAP socket descriptor. More... | |
virtual std::string | toString () const noexcept=0 |
Static Public Member Functions | |
static std::string | getRWExitCodeString (const jau::snsize_t ecn) noexcept |
static std::string | getRWExitCodeString (const RWExitCode ec) noexcept |
static constexpr int | number (const Defaults d) noexcept |
static constexpr jau::snsize_t | number (const RWExitCode rhs) noexcept |
static constexpr RWExitCode | toRWExitCode (const jau::snsize_t rhs) noexcept |
Static Public Member Functions inherited from direct_bt::L2CAPComm | |
static std::string | getStateString (bool isOpen, bool hasIOError) noexcept |
static std::string | getStateString (bool isOpen, bool irqed_int, bool irqed_ext, bool hasIOError) noexcept |
static std::string | getStateString (bool isOpen, bool isInterrupted, bool hasIOError) noexcept |
Additional Inherited Members | |
Public Attributes inherited from direct_bt::L2CAPComm | |
const uint16_t | adev_id |
Corresponding BTAdapter device id. More... | |
const L2CAP_CID | cid |
Corresponding L2CAP_CID for the channel. More... | |
const BDAddressAndType | localAddressAndType |
Corresponding BTAdapter local BTAddressAndType. More... | |
const L2CAP_PSM | psm |
Corresponding L2CAP_PSM for the channel. More... | |
Protected Member Functions inherited from direct_bt::L2CAPComm | |
BTSecurityLevel | getBTSecurityLevelImpl (const BDAddressAndType &remoteAddressAndType) noexcept |
bool | interrupted_ext () const noexcept |
Returns true if interrupted by external cause. More... | |
bool | interrupted_int () const noexcept |
Returns true if interrupted by internal cause. More... | |
bool | setBTSecurityLevelImpl (const BTSecurityLevel sec_level, const BDAddressAndType &remoteAddressAndType) noexcept |
Static Protected Member Functions inherited from direct_bt::L2CAPComm | |
static int | l2cap_close_dev (int dd) noexcept |
static int | l2cap_open_dev (const BDAddressAndType &adapterAddressAndType, const L2CAP_PSM psm, const L2CAP_CID cid) noexcept |
Protected Attributes inherited from direct_bt::L2CAPComm | |
const L2CAPEnv & | env |
jau::sc_atomic_bool | interrupted_intern |
get_boolean_callback_t | is_interrupted_extern |
jau::sc_atomic_bool | is_open_ |
std::recursive_mutex | mtx_open |
jau::relaxed_atomic_int | socket_ |
L2CAP read/write communication channel to remote device.
Definition at line 195 of file L2CAPComm.hpp.
|
strong |
Enumerator | |
---|---|
L2CAP_CONNECT_MAX_RETRY |
Definition at line 197 of file L2CAPComm.hpp.
|
strong |
Exit code for read() and write() operations.
Definition at line 205 of file L2CAPComm.hpp.
|
noexcept |
Constructing a non connected L2CAP channel instance for the pre-defined PSM and CID.
Definition at line 253 of file L2CAPComm.cpp.
|
noexcept |
Constructing a connected L2CAP channel instance for the pre-defined PSM and CID.
Definition at line 259 of file L2CAPComm.cpp.
|
inlineoverridenoexcept |
Destructor closing the L2CAP channel, see close()
.
Definition at line 249 of file L2CAPComm.hpp.
|
inlinestaticconstexprnoexcept |
|
inlinestaticconstexprnoexcept |
Definition at line 216 of file L2CAPComm.hpp.
|
inlinestaticconstexprnoexcept |
Definition at line 219 of file L2CAPComm.hpp.
|
staticnoexcept |
|
inlinestaticnoexcept |
Definition at line 223 of file L2CAPComm.hpp.
|
noexcept |
Opens and connects the L2CAP channel, locking mutex_write()
.
BT Core Spec v5.2: Vol 3, Part A: L2CAP_CONNECTION_REQ
device | the remote device to establish this L2CAP connection |
sec_level | sec_level < BTSecurityLevel::NONE will not set security level |
Definition at line 269 of file L2CAPComm.cpp.
|
inlinenoexcept |
Definition at line 265 of file L2CAPComm.hpp.
|
inlineoverridevirtualnoexcept |
Closing the L2CAP channel, locking mutex_write()
.
Implements direct_bt::L2CAPComm.
Definition at line 268 of file L2CAPComm.hpp.
|
inlinenoexcept |
Definition at line 270 of file L2CAPComm.hpp.
|
inlineoverridevirtualnoexcept |
Implements direct_bt::L2CAPComm.
Definition at line 271 of file L2CAPComm.hpp.
|
inlinenoexcept |
Return the recursive write mutex for multithreading access.
Definition at line 274 of file L2CAPComm.hpp.
|
noexcept |
If sec_level > BTSecurityLevel::UNSET, sets the BlueZ's L2CAP socket BT_SECURITY sec_level, determining the SMP security mode per connection.
To unset security, the L2CAP socket should be closed and opened again.
If setting the security level fails, close() will be called.
sec_level | sec_level == BTSecurityLevel::UNSET will not set security level and returns true. |
Definition at line 462 of file L2CAPComm.cpp.
|
noexcept |
Fetches the current BlueZ's L2CAP socket BT_SECURITY sec_level.
Definition at line 484 of file L2CAPComm.cpp.
|
noexcept |
Generic read, w/o locking suitable for a unique ringbuffer sink.
Using L2CAPEnv::L2CAP_READER_POLL_TIMEOUT.
buffer | |
capacity |
Definition at line 521 of file L2CAPComm.cpp.
|
noexcept |
Generic write, locking mutex_write()
.
buffer | |
length |
Definition at line 643 of file L2CAPComm.cpp.
|
overridevirtualnoexcept |
Implements direct_bt::L2CAPComm.
Definition at line 713 of file L2CAPComm.cpp.