summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2020-10-14 18:48:16 +0200
committerSven Gothel <[email protected]>2020-10-14 18:48:16 +0200
commit4b7dea80e1a56b72dd3fc11d18178a26d70b66bc (patch)
tree58ade2d3007e103b6128806e681c94684de82a43 /src
parent6ee66ac954a7e2c9f909e1f27debd02cf9954a4e (diff)
DBTManager::getDefaultAdapter*(): Define the first POWERED adapter as default adapter; Add convenient getCurrentBTMode(dev_id)
Diffstat (limited to 'src')
-rw-r--r--src/direct_bt/DBTManager.cpp27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/direct_bt/DBTManager.cpp b/src/direct_bt/DBTManager.cpp
index 48ba4e1b..e0aaaa43 100644
--- a/src/direct_bt/DBTManager.cpp
+++ b/src/direct_bt/DBTManager.cpp
@@ -560,6 +560,33 @@ std::shared_ptr<AdapterInfo> DBTManager::getAdapterInfo(const int idx) const {
return adapter;
}
+BTMode DBTManager::getCurrentBTMode(int dev_id) const noexcept {
+ if( 0 > dev_id || dev_id >= static_cast<int>(adapterInfos.size()) ) {
+ ERR_PRINT("dev_id %d out of bounds [0..%d[", dev_id, static_cast<int>(adapterInfos.size()));
+ return BTMode::NONE;
+ }
+ return adapterInfos.at(dev_id)->getCurrentBTMode();
+}
+
+std::shared_ptr<AdapterInfo> DBTManager::getDefaultAdapterInfo() const noexcept {
+ auto begin = adapterInfos.begin();
+ auto it = std::find_if(begin, adapterInfos.end(), [&](std::shared_ptr<AdapterInfo> const& p) {
+ return p->isCurrentSettingBitSet(AdapterSetting::POWERED);
+ });
+ if ( it != std::end(adapterInfos) ) {
+ return *it; // the 1st POWERED adapter
+ }
+ return adapterInfos.size() > 0 ? getAdapterInfo(0) : nullptr; // first adapter or nullptr, if none.
+}
+
+int DBTManager::getDefaultAdapterIdx() const noexcept {
+ std::shared_ptr<AdapterInfo> ai = getDefaultAdapterInfo();
+ if( nullptr == ai ) {
+ return -1;
+ }
+ return ai->dev_id;
+}
+
bool DBTManager::setMode(const int dev_id, const MgmtOpcode opc, const uint8_t mode) noexcept {
MgmtUint8Cmd req(opc, dev_id, mode);
std::shared_ptr<MgmtEvent> res = sendWithReply(req);