summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2020-10-25 02:32:37 +0200
committerSven Gothel <[email protected]>2020-10-25 02:32:37 +0200
commit5d3d7df23b1f499e27f1956e885f1a40d7a0de3b (patch)
tree206c3ae864c40fb35f1fdea23e1d86469c85520a /src
parent27d0b2381fe32a3cee9ce19200e42d749cbe8a76 (diff)
MgmtEvent::Opcode::NEW_SETTINGS: Be fully functional w/o Adapter: DBTManager shall update AdapterInfo state
DBTAdapter hence requires to cache the old AdapterInfo state to realize the changed bits and for AdapterStatusListener forwarding.
Diffstat (limited to 'src')
-rw-r--r--src/direct_bt/DBTAdapter.cpp24
-rw-r--r--src/direct_bt/DBTManager.cpp21
2 files changed, 34 insertions, 11 deletions
diff --git a/src/direct_bt/DBTAdapter.cpp b/src/direct_bt/DBTAdapter.cpp
index 17204570..caf09a28 100644
--- a/src/direct_bt/DBTAdapter.cpp
+++ b/src/direct_bt/DBTAdapter.cpp
@@ -155,6 +155,7 @@ bool DBTAdapter::validateDevInfo() noexcept {
ERR_PRINT("DBTAdapter::validateDevInfo: Adapter[%d]: Not existent: %s", dev_id, adapterInfo->toString().c_str());
return false;
}
+ old_settings = adapterInfo->getCurrentSettingMask();
btMode = adapterInfo->getCurrentBTMode();
if( BTMode::NONE == btMode ) {
@@ -703,18 +704,18 @@ std::string DBTAdapter::toString(bool includeDiscoveredDevices) const noexcept {
// *************************************************
-void DBTAdapter::sendAdapterSettingsChanged(const AdapterSetting old_settings, const AdapterSetting current_settings,
+void DBTAdapter::sendAdapterSettingsChanged(const AdapterSetting old_settings_, const AdapterSetting current_settings,
const uint64_t timestampMS) noexcept
{
- AdapterSetting changes = getAdapterSettingMaskDiff(current_settings, old_settings);
+ AdapterSetting changes = getAdapterSettingMaskDiff(current_settings, old_settings_);
COND_PRINT(debug_event, "DBTAdapter::sendAdapterSettingsChanged: %s -> %s, changes %s: %s",
- getAdapterSettingMaskString(old_settings).c_str(),
+ getAdapterSettingMaskString(old_settings_).c_str(),
getAdapterSettingMaskString(current_settings).c_str(),
getAdapterSettingMaskString(changes).c_str(), toString(false).c_str() );
int i=0;
jau::for_each_cow(statusListenerList, [&](std::shared_ptr<AdapterStatusListener> &l) {
try {
- l->adapterSettingsChanged(*this, old_settings, current_settings, changes, timestampMS);
+ l->adapterSettingsChanged(*this, old_settings_, current_settings, changes, timestampMS);
} catch (std::exception &e) {
ERR_PRINT("DBTAdapter:CB:NewSettings-CBs %d/%zd: %s of %s: Caught exception %s",
i+1, statusListenerList.size(),
@@ -725,16 +726,16 @@ void DBTAdapter::sendAdapterSettingsChanged(const AdapterSetting old_settings, c
}
void DBTAdapter::sendAdapterSettingsChanged(AdapterStatusListener & asl,
- const AdapterSetting old_settings, const AdapterSetting current_settings,
+ const AdapterSetting old_settings_, const AdapterSetting current_settings,
const uint64_t timestampMS) noexcept
{
- AdapterSetting changes = getAdapterSettingMaskDiff(current_settings, old_settings);
+ AdapterSetting changes = getAdapterSettingMaskDiff(current_settings, old_settings_);
COND_PRINT(debug_event, "DBTAdapter::sendAdapterSettingsChanged: %s -> %s, changes %s: %s",
- getAdapterSettingMaskString(old_settings).c_str(),
+ getAdapterSettingMaskString(old_settings_).c_str(),
getAdapterSettingMaskString(current_settings).c_str(),
getAdapterSettingMaskString(changes).c_str(), toString(false).c_str() );
try {
- asl.adapterSettingsChanged(*this, old_settings, current_settings, changes, timestampMS);
+ asl.adapterSettingsChanged(*this, old_settings_, current_settings, changes, timestampMS);
} catch (std::exception &e) {
ERR_PRINT("DBTAdapter::sendAdapterSettingsChanged-CB: %s of %s: Caught exception %s",
asl.toString().c_str(), toString(false).c_str(), e.what());
@@ -836,8 +837,7 @@ bool DBTAdapter::mgmtEvDeviceDiscoveringAny(std::shared_ptr<MgmtEvent> e, const
bool DBTAdapter::mgmtEvNewSettingsMgmt(std::shared_ptr<MgmtEvent> e) noexcept {
COND_PRINT(debug_event, "DBTAdapter:mgmt:NewSettings: %s", e->toString().c_str());
const MgmtEvtNewSettings &event = *static_cast<const MgmtEvtNewSettings *>(e.get());
- const AdapterSetting old_settings = adapterInfo->getCurrentSettingMask();
- const AdapterSetting new_settings = adapterInfo->setCurrentSettingMask(event.getSettings());
+ const AdapterSetting new_settings = adapterInfo->setCurrentSettingMask(event.getSettings()); // probably done by mgmt callback already
{
const BTMode _btMode = getAdapterSettingsBTMode(new_settings);
if( BTMode::NONE != _btMode ) {
@@ -846,7 +846,9 @@ bool DBTAdapter::mgmtEvNewSettingsMgmt(std::shared_ptr<MgmtEvent> e) noexcept {
}
sendAdapterSettingsChanged(old_settings, new_settings, event.getTimestamp());
- if( !isPowered() ) {
+ old_settings = new_settings;
+
+ if( !isAdapterSettingBitSet(new_settings, AdapterSetting::POWERED) ) {
// Adapter has been powered off, close connections and cleanup off-thread.
std::thread bg(&DBTAdapter::poweredOff, this); // @suppress("Invalid arguments")
bg.detach();
diff --git a/src/direct_bt/DBTManager.cpp b/src/direct_bt/DBTManager.cpp
index 2a4137e3..c7a74572 100644
--- a/src/direct_bt/DBTManager.cpp
+++ b/src/direct_bt/DBTManager.cpp
@@ -435,6 +435,7 @@ next1:
// Not required: CTOR: adapterInfos.set_store(std::move(snapshot));
}
}
+ addMgmtEventCallback(-1, MgmtEvent::Opcode::NEW_SETTINGS, jau::bindMemberFunc(this, &DBTManager::mgmtEvNewSettingsCB));
if( ok ) {
if( env.DEBUG_EVENT ) {
@@ -870,6 +871,26 @@ bool DBTManager::mgmtEvAdapterRemovedCB(std::shared_ptr<MgmtEvent> e) noexcept {
jau::PLAIN_PRINT("DBTManager:mgmt:AdapterRemoved: End: Removed %s", (nullptr != ai ? ai->toString().c_str() : "none"));
return true;
}
+bool DBTManager::mgmtEvNewSettingsCB(std::shared_ptr<MgmtEvent> e) noexcept {
+ const MgmtEvtNewSettings &event = *static_cast<const MgmtEvtNewSettings *>(e.get());
+ std::shared_ptr<AdapterInfo> adapterInfo = getAdapterInfo(event.getDevID());
+ if( nullptr != adapterInfo ) {
+ const AdapterSetting old_settings = adapterInfo->getCurrentSettingMask();
+ const AdapterSetting new_settings = adapterInfo->setCurrentSettingMask(event.getSettings());
+ DBG_PRINT("DBTManager:mgmt:NewSettings: Adapter[%d] %s -> %s - %s",
+ event.getDevID(),
+ getAdapterSettingMaskString(old_settings).c_str(),
+ getAdapterSettingMaskString(new_settings).c_str(),
+ e->toString().c_str());
+ } else {
+ DBG_PRINT("DBTManager:mgmt:NewSettings: Adapter[%d] %s -> adapter not present - %s",
+ event.getDevID(),
+ getAdapterSettingMaskString(event.getSettings()).c_str(),
+ e->toString().c_str());
+ }
+ return true;
+}
+
bool DBTManager::mgmtEvClassOfDeviceChangedCB(std::shared_ptr<MgmtEvent> e) noexcept {
jau::PLAIN_PRINT("DBTManager:mgmt:ClassOfDeviceChanged: %s", e->toString().c_str());
(void)e;