Direct-BT
2.3.1
Direct-BT - Direct Bluetooth Programming.
|
A thread safe singleton handler of the Linux Kernel's BlueZ manager control channel. More...
#include <BTManager.hpp>
Public Types | |
enum | Defaults : int32_t { ClientMaxMTU = 512 } |
Public Member Functions | |
~BTManager () noexcept | |
void | close () noexcept |
std::string | get_java_class () const noexcept override |
BTMode | getDefaultBTMode () noexcept |
Returns the default BTMode, adapters are tried to be initialized. More... | |
bool | isOpen () const noexcept |
Returns true if this mgmt instance is open and hence valid, otherwise false. More... | |
std::string | toString () const noexcept override |
int | getAdapterCount () const noexcept |
retrieve information gathered at startup More... | |
jau::darray< std::shared_ptr< BTAdapter > > | getAdapters () |
Returns a list of currently added DBTAdapter. More... | |
std::shared_ptr< BTAdapter > | getAdapter (const uint16_t dev_id) const noexcept |
Returns the DBTAdapter with the given dev_id, or nullptr if not found. More... | |
std::shared_ptr< BTAdapter > | getDefaultAdapter () const noexcept |
Returns the default AdapterInfo. More... | |
bool | setIOCapability (const uint16_t dev_id, const SMPIOCapability io_cap, SMPIOCapability &pre_io_cap) noexcept |
SMPIOCapability | getIOCapability (const uint16_t dev_id) const noexcept |
bool | setMode (const uint16_t dev_id, const MgmtCommand::Opcode opc, const uint8_t mode, AdapterSetting ¤t_settings) noexcept |
MgmtStatus | setDiscoverable (const uint16_t dev_id, const uint8_t state, const uint16_t timeout, AdapterSetting ¤t_settings) noexcept |
ScanType | startDiscovery (const uint16_t dev_id, const BTMode btMode) noexcept |
Start discovery on given adapter dev_id with a ScanType matching the given BTMode. More... | |
ScanType | startDiscovery (const uint16_t dev_id, const ScanType type) noexcept |
Start discovery on given adapter dev_id with given ScanType. More... | |
bool | stopDiscovery (const uint16_t dev_id, const ScanType type) noexcept |
Stop discovery on given adapter dev_id. More... | |
bool | uploadConnParam (const uint16_t dev_id, const BDAddressAndType &addressAndType, const uint16_t conn_interval_min=12, const uint16_t conn_interval_max=12, const uint16_t conn_latency=0, const uint16_t supervision_timeout=getHCIConnSupervisorTimeout(0, 15)) noexcept |
Uploads given connection parameter for given device to the kernel. More... | |
bool | isDeviceWhitelisted (const uint16_t dev_id, const BDAddressAndType &addressAndType) noexcept |
Returns true, if the adapter's device is already whitelisted. More... | |
bool | addDeviceToWhitelist (const uint16_t dev_id, const BDAddressAndType &addressAndType, const HCIWhitelistConnectType ctype) noexcept |
Add the given device to the adapter's autoconnect whitelist. More... | |
bool | removeDeviceFromWhitelist (const uint16_t dev_id, const BDAddressAndType &addressAndType) noexcept |
Remove the given device from the adapter's autoconnect whitelist. More... | |
int | removeAllDevicesFromWhitelist () noexcept |
Remove all previously added devices from the autoconnect whitelist. More... | |
bool | disconnect (const bool ioErrorCause, const uint16_t dev_id, const BDAddressAndType &addressAndType, const HCIStatusCode reason=HCIStatusCode::REMOTE_USER_TERMINATED_CONNECTION) noexcept |
std::shared_ptr< ConnectionInfo > | getConnectionInfo (const uint16_t dev_id, const BDAddressAndType &addressAndType) noexcept |
std::shared_ptr< NameAndShortName > | setLocalName (const uint16_t dev_id, const std::string &name, const std::string &short_name) noexcept |
MgmtStatus | uploadLinkKey (const uint16_t dev_id, const bool debug_keys, const MgmtLinkKeyInfo &key) noexcept |
Security commands. More... | |
HCIStatusCode | uploadLongTermKey (const uint16_t dev_id, const MgmtLongTermKeyInfo &key) noexcept |
HCIStatusCode | uploadLongTermKeyInfo (const uint16_t dev_id, const BDAddressAndType &addressAndType, const SMPLongTermKeyInfo <k) noexcept |
MgmtStatus | userPasskeyReply (const uint16_t dev_id, const BDAddressAndType &addressAndType, const uint32_t passkey) noexcept |
MgmtStatus | userPasskeyNegativeReply (const uint16_t dev_id, const BDAddressAndType &addressAndType) noexcept |
MgmtStatus | userConfirmReply (const uint16_t dev_id, const BDAddressAndType &addressAndType, const bool positive) noexcept |
bool | pairDevice (const uint16_t dev_id, const BDAddressAndType &addressAndType, const SMPIOCapability iocap) noexcept |
MgmtStatus | unpairDevice (const uint16_t dev_id, const BDAddressAndType &addressAndType, const bool disconnect) noexcept |
bool | addMgmtEventCallback (const int dev_id, const MgmtEvent::Opcode opc, const MgmtEventCallback &cb) noexcept |
MgmtEventCallback handling More... | |
int | removeMgmtEventCallback (const MgmtEvent::Opcode opc, const MgmtEventCallback &cb) noexcept |
Returns count of removed given MgmtEventCallback from the named MgmtEvent::Opcode list. More... | |
int | removeMgmtEventCallback (const int dev_id) noexcept |
Returns count of removed MgmtEventCallback from the named MgmtEvent::Opcode list matching the given adapter dev_id . More... | |
void | clearMgmtEventCallbacks (const MgmtEvent::Opcode opc) noexcept |
Removes all MgmtEventCallbacks from the to the named MgmtEvent::Opcode list. More... | |
void | clearAllCallbacks () noexcept |
Removes all MgmtEventCallbacks from all MgmtEvent::Opcode lists. More... | |
void | sendMgmtEvent (const MgmtEvent &event) noexcept |
Manually send a MgmtEvent to all of its listeners. More... | |
void | addChangedAdapterSetCallback (const ChangedAdapterSetCallback &l) |
ChangedAdapterSetCallback handling. More... | |
int | removeChangedAdapterSetCallback (const ChangedAdapterSetCallback &l) |
Remove the given ChangedAdapterSetCallback from this manager. More... | |
void | addChangedAdapterSetCallback (ChangedAdapterSetFunc f) |
Adds the given ChangedAdapterSetFunc to this manager. More... | |
int | removeChangedAdapterSetCallback (ChangedAdapterSetFunc f) |
Remove the given ChangedAdapterSetFunc from this manager. More... | |
Public Member Functions inherited from jau::JavaUplink | |
std::string | javaObjectToString () const noexcept |
std::shared_ptr< JavaAnon > | getJavaObject () noexcept |
void | setJavaObject (std::shared_ptr< JavaAnon > objRef) noexcept |
Assigns a new shared JavaAnon reference, replaced item might be deleted via JNI from dtor. More... | |
void | setJavaObject () noexcept |
Resets the shared JavaAnon reference, the replaced item might be deleted via JNI from dtor. More... | |
void | clearJavaObject () noexcept |
Clears the java reference, i.e. More... | |
virtual void | checkValid () const |
Throws an IllegalStateException if isValid() == false. More... | |
virtual | ~JavaUplink () noexcept |
Static Public Member Functions | |
static BTManager & | get (const BTMode defaultBTMode=BTMode::NONE) |
Retrieves the singleton instance. More... | |
static std::string | java_class () noexcept |
Static Public Attributes | |
static const pid_t | pidSelf = getpid() |
A thread safe singleton handler of the Linux Kernel's BlueZ manager control channel.
Implementation utilizes a lock free ringbuffer receiving data within its separate thread.
Controlling Environment variables, see MgmtEnv.
Definition at line 201 of file BTManager.hpp.
enum direct_bt::BTManager::Defaults : int32_t |
Enumerator | |
---|---|
ClientMaxMTU |
Definition at line 203 of file BTManager.hpp.
|
inlinenoexcept |
void BTManager::addChangedAdapterSetCallback | ( | ChangedAdapterSetFunc | f | ) |
Adds the given ChangedAdapterSetFunc to this manager.
When a new callback is added, all available adapter's will be reported as added, this allows a fully event driven workflow.
The callback is performed on a dedicated thread, allowing the user to perform complex operations.
Definition at line 1242 of file BTManager.cpp.
void BTManager::addChangedAdapterSetCallback | ( | const ChangedAdapterSetCallback & | l | ) |
ChangedAdapterSetCallback handling.
Adds the given ChangedAdapterSetCallback to this manager.
When a new callback is added, all available adapter's will be reported as added, this allows a fully event driven workflow.
The callback is performed on a dedicated thread, allowing the user to perform complex operations.
Definition at line 1230 of file BTManager.cpp.
|
noexcept |
Add the given device to the adapter's autoconnect whitelist.
Make sure uploadConnParam(..) is invoked first, otherwise performance will lack.
Method will reject duplicate devices, in which case it should be removed first.
Definition at line 973 of file BTManager.cpp.
|
noexcept |
MgmtEventCallback handling
Appends the given MgmtEventCallback for the given adapter dev_id to the named MgmtEvent::Opcode list, if it is not present already (dev_id + opcode + callback).
The adapter dev_id allows filtering the events only directed to the given adapter. Use dev_id -1
to receive the event for all adapter.
dev_id | the associated adapter dev_id |
opc | opcode index for callback list, the callback shall be added to |
cb | the to be added callback |
Definition at line 1117 of file BTManager.cpp.
|
noexcept |
Removes all MgmtEventCallbacks from all MgmtEvent::Opcode lists.
Definition at line 1155 of file BTManager.cpp.
|
noexcept |
Removes all MgmtEventCallbacks from the to the named MgmtEvent::Opcode list.
Definition at line 1148 of file BTManager.cpp.
|
noexcept |
Definition at line 538 of file BTManager.cpp.
|
noexcept |
|
inlinestatic |
Retrieves the singleton instance.
First call will open and initialize the bluetooth kernel.
btMode | default BTMode when initializing new adapter. If BTMode::NONE given (default), MgmtEnv::DEFAULT_BTMODE is being used. |
Definition at line 320 of file BTManager.hpp.
|
inlineoverridevirtualnoexcept |
Implements jau::JavaUplink.
Definition at line 338 of file BTManager.hpp.
|
noexcept |
Returns the DBTAdapter with the given dev_id, or nullptr if not found.
Definition at line 624 of file BTManager.cpp.
|
inlinenoexcept |
retrieve information gathered at startup
Returns AdapterInfo count in list
Definition at line 362 of file BTManager.hpp.
|
inline |
Returns a list of currently added DBTAdapter.
Definition at line 367 of file BTManager.hpp.
|
noexcept |
Definition at line 1072 of file BTManager.cpp.
|
noexcept |
Returns the default AdapterInfo.
The default adapter is either the first AdapterSetting::POWERED adapter, or function returns nullptr if none is AdapterSetting::POWERED.
Definition at line 614 of file BTManager.cpp.
|
inlinenoexcept |
Returns the default BTMode, adapters are tried to be initialized.
Definition at line 346 of file BTManager.hpp.
|
noexcept |
|
noexcept |
Returns true, if the adapter's device is already whitelisted.
Definition at line 962 of file BTManager.cpp.
|
inlinenoexcept |
Returns true if this mgmt instance is open and hence valid, otherwise false.
Definition at line 349 of file BTManager.hpp.
|
inlinestaticnoexcept |
|
noexcept |
|
noexcept |
Remove all previously added devices from the autoconnect whitelist.
Returns number of removed devices.
Definition at line 992 of file BTManager.cpp.
int BTManager::removeChangedAdapterSetCallback | ( | ChangedAdapterSetFunc | f | ) |
Remove the given ChangedAdapterSetFunc from this manager.
l | the to be removed element |
Definition at line 1248 of file BTManager.cpp.
int BTManager::removeChangedAdapterSetCallback | ( | const ChangedAdapterSetCallback & | l | ) |
Remove the given ChangedAdapterSetCallback from this manager.
l | the to be removed element |
Definition at line 1238 of file BTManager.cpp.
|
noexcept |
Remove the given device from the adapter's autoconnect whitelist.
Definition at line 1019 of file BTManager.cpp.
|
noexcept |
Returns count of removed MgmtEventCallback from the named MgmtEvent::Opcode list matching the given adapter dev_id .
Definition at line 1135 of file BTManager.cpp.
|
noexcept |
Returns count of removed given MgmtEventCallback from the named MgmtEvent::Opcode list.
Definition at line 1126 of file BTManager.cpp.
|
noexcept |
Manually send a MgmtEvent to all of its listeners.
Definition at line 154 of file BTManager.cpp.
|
noexcept |
|
noexcept |
|
noexcept |
|
noexcept |
Start discovery on given adapter dev_id with a ScanType matching the given BTMode.
Returns set ScanType.
Definition at line 775 of file BTManager.cpp.
Start discovery on given adapter dev_id with given ScanType.
Returns set ScanType.
Definition at line 779 of file BTManager.cpp.
|
noexcept |
Stop discovery on given adapter dev_id.
Definition at line 796 of file BTManager.cpp.
|
inlineoverridevirtualnoexcept |
Reimplemented from jau::JavaUplink.
Definition at line 353 of file BTManager.hpp.
|
noexcept |
Definition at line 946 of file BTManager.cpp.
|
noexcept |
Uploads given connection parameter for given device to the kernel.
dev_id | |
address | |
address_type | |
conn_interval_min | in units of 1.25ms, default value 12 for 15ms; Value range [6 .. 3200] for [7.5ms .. 4000ms] |
conn_interval_max | in units of 1.25ms, default value 12 for 15ms; Value range [6 .. 3200] for [7.5ms .. 4000ms] |
conn_latency | slave latency in units of connection events, default value 0; Value range [0 .. 0x01F3]. |
supervision_timeout | in units of 10ms, default value >= 10 x conn_interval_max, we use HCIConstInt::LE_CONN_MIN_TIMEOUT_MS minimum; Value range [0xA-0x0C80] for [100ms - 32s]. |
Definition at line 806 of file BTManager.cpp.
|
noexcept |
Security commands.
Definition at line 819 of file BTManager.cpp.
|
noexcept |
|
noexcept |
Definition at line 858 of file BTManager.cpp.
|
noexcept |
Definition at line 916 of file BTManager.cpp.
|
noexcept |
Definition at line 901 of file BTManager.cpp.
|
noexcept |
Definition at line 886 of file BTManager.cpp.
|
static |
Definition at line 208 of file BTManager.hpp.