26#ifndef L2CAP_COMM_HPP_
27#define L2CAP_COMM_HPP_
125 static std::string
getStateString(
bool isOpen,
bool hasIOError)
noexcept;
126 static std::string
getStateString(
bool isOpen,
bool isInterrupted,
bool hasIOError)
noexcept;
127 static std::string
getStateString(
bool isOpen,
bool irqed_int,
bool irqed_ext,
bool hasIOError)
noexcept;
198 L2CAP_CONNECT_MAX_RETRY = 3
200 static constexpr int number(
const Defaults d)
noexcept {
return static_cast<int>(d); }
209 INVALID_SOCKET_DD = -3,
220 return rhs >= 0 ? RWExitCode::SUCCESS :
static_cast<RWExitCode>(rhs);
222 static std::string getRWExitCodeString(
const RWExitCode ec)
noexcept;
224 return getRWExitCodeString( toRWExitCode( ecn ) );
228 std::recursive_mutex mtx_write;
230 std::atomic<bool> has_ioerror;
231 std::atomic<::pthread_t> tid_connect;
232 std::atomic<::pthread_t> tid_read;
234 bool close_impl() noexcept;
268 bool close() noexcept
override {
return close_impl(); }
274 std::recursive_mutex &
mutex_write() noexcept {
return mtx_write; }
319 std::atomic<::pthread_t> tid_accept;
321 bool close_impl()
noexcept;
331 bool open() noexcept;
333 bool close() noexcept
override {
return close_impl(); }
335 std::unique_ptr<L2CAPClient> accept() noexcept;
339 std::string
toString() const noexcept override;
Unique Bluetooth EUI48 address and BDAddressType tuple.
BTDevice represents one remote Bluetooth device.
L2CAP read/write communication channel to remote device.
bool close() noexcept override
Closing the L2CAP channel, locking mutex_write().
std::string getStateString() const noexcept override
static std::string getRWExitCodeString(const jau::snsize_t ecn) noexcept
std::recursive_mutex & mutex_write() noexcept
Return the recursive write mutex for multithreading access.
static constexpr int number(const Defaults d) noexcept
static constexpr RWExitCode toRWExitCode(const jau::snsize_t rhs) noexcept
bool hasIOError() const noexcept
RWExitCode
Exit code for read() and write() operations.
static constexpr jau::snsize_t number(const RWExitCode rhs) noexcept
const BDAddressAndType & getRemoteAddressAndType() const noexcept
L2CAP client/server socket abstract base class to listen for connecting remote devices.
jau::sc_atomic_bool interrupted_intern
L2CAPComm(const uint16_t adev_id, BDAddressAndType localAddressAndType, const L2CAP_PSM psm, const L2CAP_CID cid) noexcept
BTSecurityLevel getBTSecurityLevelImpl(const BDAddressAndType &remoteAddressAndType) noexcept
const BDAddressAndType localAddressAndType
Corresponding BTAdapter local BTAddressAndType.
int socket() const noexcept
Return this L2CAP socket descriptor.
virtual ~L2CAPComm() noexcept=default
Destructor specialization shall close the L2CAP socket, see close().
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.
bool interrupted_ext() const noexcept
Returns true if interrupted by external cause.
const L2CAP_CID cid
Corresponding L2CAP_CID for the channel.
bool interrupted_int() const noexcept
Returns true if interrupted by internal cause.
jau::relaxed_atomic_int socket_
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
virtual bool close() noexcept=0
Closing the L2CAP socket, see specializations.
virtual std::string getStateString() const noexcept=0
bool is_open() const noexcept
get_boolean_callback_t is_interrupted_extern
jau::sc_atomic_bool is_open_
std::recursive_mutex mtx_open
jau::function< bool(int)> get_boolean_callback_t
Utilized to query for external interruption, whether device is still connected etc.
bool interrupted() const noexcept
Returns true if interrupted by internal or external cause, hence shall stop connecting and reading.
const L2CAP_PSM psm
Corresponding L2CAP_PSM for the channel.
const uint16_t adev_id
Corresponding BTAdapter device id.
bool setBTSecurityLevelImpl(const BTSecurityLevel sec_level, const BDAddressAndType &remoteAddressAndType) noexcept
static std::string getStateString(bool isOpen, bool isInterrupted, bool hasIOError) noexcept
virtual std::string toString() const noexcept=0
L2CAP Singleton runtime environment properties.
const int32_t L2CAP_READER_POLL_TIMEOUT
L2CAP poll timeout for reading, defaults to 10s.
const bool DEBUG_DATA
Debug all GATT Data communication.
const int32_t L2CAP_RESTART_COUNT_ON_ERROR
Debugging facility: L2CAP restart count on transmission errors, defaults to 5 attempts.
static L2CAPEnv & get() noexcept
L2CAP server socket to listen for connecting remote devices.
~L2CAPServer() noexcept override
Destructor closing the L2CAP channel, see close().
Class template jau::function is a general-purpose static-polymorphic function wrapper.
Base jau environment class, merely to tag all environment settings by inheritance and hence documenta...
L2CAP_PSM
Protocol Service Multiplexers (PSM) Assigned numbers https://www.bluetooth.com/specifications/assigne...
BTSecurityLevel
Bluetooth Security Level.
@ NONE
No encryption and no authentication.
uint_fast32_t nsize_t
Natural 'size_t' alternative using uint_fast32_t as its natural sized type.
int_fast32_t snsize_t
Natural 'ssize_t' alternative using int_fast32_t as its natural sized type.
__pack(...): Produces MSVC, clang and gcc compatible lead-in and -out macros.