aboutsummaryrefslogtreecommitdiffstats
path: root/api/direct_bt/DBTManager.hpp
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2020-06-04 04:11:12 +0200
committerSven Gothel <[email protected]>2020-06-04 04:11:12 +0200
commit73f5b4fc21d7a14aa174f2c48657ca3f2229dda1 (patch)
tree1b455d3e699600eb9f0c1ccc09d10ffd8052929b /api/direct_bt/DBTManager.hpp
parent1c449ba2a4cede1e942ff9df181bf96a408d2c67 (diff)
Introduce HCITypes + HCIHandler: Providing C++ basics for full HCI support; Misc..
Introduce HCITypes + HCIHandler: Providing C++ basics for full HCI support ============================================================================ - HCITypes defines the HCI command and event data structures, similar to MgmtTypes and ATTPDUTypes. For more coding efficiency we use template command and event classes, allowing to reuse the HCIIoctl struct types being wrapped in the C++ classes for flow and lifecycle control. HCITypes further includes all essential 'enum class' command opcodes, event types etc, ensuring type safety. - HCIHandler defines the command/event workflow similar to GATTHandler and DBTManager. One HCIHandler per DBTAdapter is being used, each HCIHandler using its event reader thread and ringbuffer. Socket event filtering and manual le-meta filtering ensures reduced workload (DoS safety). Similar to HCITypes, we use template function to utilize the template command and event classes, reuising the HCIIoctl struct types... HCIHandler can be extended for more functionality as well as used to implement our own DBTManager, i.e. Reducing HCIEvents to MgmtEvents with callback support. At least this is a viable option now, if so desired (non-linux, etc). - HCIComm: Contains the core I/O functionality only, dropped all semantic HCI code. The latter resides in HCIHandler now. - DBTAdapter now uses HCIHander instead of HCIComm, renamed field to simply 'hci' Misc.. ======= - reduced all ringbuffer capacity to 128 from 256 - Moved Mgmt*EventCallback from DBTManager to MgmtTypes, as we might want to reuse the MgmtTypes incl callbacks for alternative DBTManager implementations. - Added 'enum class' to underlying number type conversion pattern: <NumberType> number('enum class type') Avoiding the many static_cast<NumberType>(..) directives. - align all Type -> String method names: 'get<Type>String(Type)' - BasicTypes: Add safe uint32_t bitfield mask helper
Diffstat (limited to 'api/direct_bt/DBTManager.hpp')
-rw-r--r--api/direct_bt/DBTManager.hpp48
1 files changed, 6 insertions, 42 deletions
diff --git a/api/direct_bt/DBTManager.hpp b/api/direct_bt/DBTManager.hpp
index 15e46098..c2e1e7a4 100644
--- a/api/direct_bt/DBTManager.hpp
+++ b/api/direct_bt/DBTManager.hpp
@@ -42,47 +42,9 @@
#include "JavaUplink.hpp"
#include "MgmtTypes.hpp"
#include "LFRingbuffer.hpp"
-#include "FunctionDef.hpp"
namespace direct_bt {
- typedef FunctionDef<bool, std::shared_ptr<MgmtEvent>> MgmtEventCallback;
-
- class MgmtAdapterEventCallback {
- private:
- /** Unique adapter index filter or <code>-1</code> to listen for all adapter. */
- int dev_id;
- /** MgmtEventCallback instance */
- MgmtEventCallback callback;
-
- public:
- MgmtAdapterEventCallback(int _dev_id, const MgmtEventCallback & _callback)
- : dev_id(_dev_id), callback(_callback) {}
-
- MgmtAdapterEventCallback(const MgmtAdapterEventCallback &o) = default;
- MgmtAdapterEventCallback(MgmtAdapterEventCallback &&o) = default;
- MgmtAdapterEventCallback& operator=(const MgmtAdapterEventCallback &o) = default;
- MgmtAdapterEventCallback& operator=(MgmtAdapterEventCallback &&o) = default;
-
- /** Unique adapter index filter or <code>-1</code> to listen for all adapter. */
- int getDevID() const { return dev_id; }
-
- /** MgmtEventCallback reference */
- MgmtEventCallback& getCallback() { return callback; }
-
- bool operator==(const MgmtAdapterEventCallback& rhs) const
- { return dev_id == rhs.dev_id && callback == rhs.callback; }
-
- bool operator!=(const MgmtAdapterEventCallback& rhs) const
- { return !(*this == rhs); }
-
- std::string toString() const {
- return "MgmtAdapterEventCallback[dev_id "+std::to_string(dev_id)+", "+callback.toString()+"]";
- }
- };
-
- typedef std::vector<MgmtAdapterEventCallback> MgmtAdapterEventCallbackList;
-
/**
* A thread safe singleton handler of the Linux Kernel's BlueZ manager control channel.
* <p>
@@ -108,7 +70,7 @@ namespace direct_bt {
MGMT_READER_THREAD_POLL_TIMEOUT = 3000,
/** 1s timeout for mgmt command replies */
MGMT_COMMAND_REPLY_TIMEOUT = 1000,
- MGMTEVT_RING_CAPACITY = 256
+ MGMTEVT_RING_CAPACITY = 128
};
static const pid_t pidSelf;
@@ -200,7 +162,9 @@ namespace direct_bt {
return comm.isOpen();
}
- std::string toString() const override { return "MgmtHandler["+std::to_string(adapterInfos.size())+" adapter, "+javaObjectToString()+"]"; }
+ std::string toString() const override {
+ return "MgmtHandler["+BTModeString(btMode)+", "+std::to_string(adapterInfos.size())+" adapter, "+javaObjectToString()+"]";
+ }
/** retrieve information gathered at startup */
@@ -257,7 +221,7 @@ namespace direct_bt {
*/
bool uploadConnParam(const int dev_id, const EUI48 &address, const BDAddressType address_type,
const uint16_t conn_interval_min=0x000F, const uint16_t conn_interval_max=0x000F,
- const uint16_t conn_latency=0x0000, const uint16_t timeout=HCI_LE_CONN_TIMEOUT_MS/10);
+ const uint16_t conn_latency=0x0000, const uint16_t timeout=number(HCIConstInt::LE_CONN_TIMEOUT_MS)/10);
/**
* Returns true, if the adapter's device is already whitelisted.
@@ -287,7 +251,7 @@ namespace direct_bt {
const BDAddressType own_mac_type=BDADDR_LE_PUBLIC,
const uint16_t interval=0x0004, const uint16_t window=0x0004,
const uint16_t min_interval=0x000F, const uint16_t max_interval=0x000F,
- const uint16_t latency=0x0000, const uint16_t supervision_timeout=HCI_LE_CONN_TIMEOUT_MS/10);
+ const uint16_t latency=0x0000, const uint16_t supervision_timeout=number(HCIConstInt::LE_CONN_TIMEOUT_MS)/10);
bool disconnect(const bool ioErrorCause,
const int dev_id, const EUI48 &peer_bdaddr, const BDAddressType peer_mac_type,