diff options
author | Sven Gothel <[email protected]> | 2020-07-29 23:04:03 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2020-07-29 23:04:03 +0200 |
commit | 536975dd325723593e38efecde061d8c7c95c707 (patch) | |
tree | 96aeb63d7d9fcfb2fdc025a02296e3d795644766 | |
parent | 8eb02d1afc5eee52c5e3c8bd21a1ec820b558934 (diff) |
Refine send DISCOVERY event (m true, n false) -> (m false, n false), fix state transition.v2.1.20
-rw-r--r-- | src/direct_bt/DBTAdapter.cpp | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/src/direct_bt/DBTAdapter.cpp b/src/direct_bt/DBTAdapter.cpp index 1a7d580c..3e51c153 100644 --- a/src/direct_bt/DBTAdapter.cpp +++ b/src/direct_bt/DBTAdapter.cpp @@ -409,6 +409,25 @@ void DBTAdapter::startDiscoveryBackground() { void DBTAdapter::stopDiscovery() { const std::lock_guard<std::recursive_mutex> lock(mtx_discovery); // RAII-style acquire and relinquish via destructor + /** + * Need to send mgmtEvDeviceDiscoveringMgmt(..) + * as manager/hci won't produce such event having temporarily disabled discovery. + * + --+-------+--------+-----------+----------------------------------------------------+ + * | # | meta | native | keepAlive | Note + * +---+-------+--------+-----------+----------------------------------------------------+ + * | 1 | true | true | false | - + * | 2 | false | false | false | - + * +---+-------+--------+-----------+----------------------------------------------------+ + * | 3 | true | true | true | - + * | 4 | true | false | true | temporarily disabled -> startDiscoveryBackground() + * | 5 | false | false | true | [4] -> [5] requires manual DISCOVERING event + * +---+-------+--------+-----------+----------------------------------------------------+ + * [4] current -> [5] post stopDiscovery == sendEvent + */ + const bool sendEvent = ScanType::NONE != currentMetaScanType && // true + ScanType::NONE == currentNativeScanType && // false + keepDiscoveringAlive; // true + keepDiscoveringAlive = false; if( ScanType::NONE == currentMetaScanType ) { DBG_PRINT("DBTAdapter::stopDiscovery: Already disabled, keepAlive %d, currentScanType[native %s, meta %s] ...", @@ -417,15 +436,13 @@ void DBTAdapter::stopDiscovery() { checkDiscoveryState(); return; } - // Need to send mgmtEvDeviceDiscoveringMgmt(..) - // as manager/hci won't produce such event having temporarily disabled discovery. - const bool sendEvent = ScanType::NONE == currentNativeScanType; bool r; if( ( r = mgmt.stopDiscovery(dev_id, currentMetaScanType) ) == true ) { currentNativeScanType = ScanType::NONE; - currentMetaScanType = currentNativeScanType.load(); } + currentMetaScanType = currentNativeScanType.load(); // always to have valid DiscoveryState triple + DBG_PRINT("DBTAdapter::stopDiscovery: Stopped (res %d), keepAlive %d, currentScanType[native %s, meta %s], sendEvent %d ...", r, keepDiscoveringAlive.load(), getScanTypeString(currentNativeScanType).c_str(), getScanTypeString(currentMetaScanType).c_str(), |