diff options
author | Sven Gothel <[email protected]> | 2020-07-22 02:27:35 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2020-07-22 02:27:35 +0200 |
commit | 60e72dd2776dfd3649a791ad5f8dbab20c77cc1e (patch) | |
tree | 4107c27cf60385c7dacdf440000a1e8a24d58c32 /src | |
parent | dd6c802b593f2d6f88c6bd85dafe451ad8121fb1 (diff) |
DBTAdapter: startDiscovery(..) also might need to change 'keepDiscoveringAlive' even if still in discovery
Hence adding locking mtx_discovery in mgmtEvDeviceDiscoveringMgmt due to multiple state changes
and updating keepDiscoveringAlive even if not initiating discovery (still running).
Further all calls to startDiscovery(..) (C++ and Java) shall clear the list of discovered devices
to end up in the same state, regardless of an alread running discovery or not.
Note: We might have to observe this behavior in more detail, but as we usually utilize the
status listener model, this list is of less interest.
The Java implementation simply always calls down to native code,
ensuring same 'keepAlive' behavior.
It hence also always clears the list of discovered devices.
Diffstat (limited to 'src')
-rw-r--r-- | src/direct_bt/DBTAdapter.cpp | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/src/direct_bt/DBTAdapter.cpp b/src/direct_bt/DBTAdapter.cpp index e972f277..8707a1f7 100644 --- a/src/direct_bt/DBTAdapter.cpp +++ b/src/direct_bt/DBTAdapter.cpp @@ -342,14 +342,21 @@ bool DBTAdapter::startDiscovery(const bool keepAlive, const HCILEOwnAddressType checkValid(); const std::lock_guard<std::recursive_mutex> lock(mtx_discovery); // RAII-style acquire and relinquish via destructor if( ScanType::SCAN_TYPE_NONE != currentScanType ) { + removeDiscoveredDevices(); + if( keepDiscoveringAlive == keepAlive ) { + DBG_PRINT("DBTAdapter::startDiscovery: Already discovering, unchanged keepAlive %d -> %d ...", keepDiscoveringAlive.load(), keepAlive); + } else { + DBG_PRINT("DBTAdapter::startDiscovery: Already discovering, changed keepAlive %d -> %d ...", keepDiscoveringAlive.load(), keepAlive); + keepDiscoveringAlive = keepAlive; + } return true; } (void)own_mac_type; (void)le_scan_interval; (void)le_scan_window; - DBG_PRINT("DBTAdapter::startDiscovery: keepAlive %d ...", keepAlive); removeDiscoveredDevices(); + DBG_PRINT("DBTAdapter::startDiscovery: Initiating discovery, keepAlive %d -> %d ...", keepDiscoveringAlive.load(), keepAlive); keepDiscoveringAlive = keepAlive; currentScanType = mgmt.startDiscovery(dev_id); return ScanType::SCAN_TYPE_NONE != currentScanType; @@ -465,6 +472,7 @@ std::string DBTAdapter::toString() const { // ************************************************* bool DBTAdapter::mgmtEvDeviceDiscoveringMgmt(std::shared_ptr<MgmtEvent> e) { + const std::lock_guard<std::recursive_mutex> lock(mtx_discovery); // RAII-style acquire and relinquish via destructor DBG_PRINT("DBTAdapter::EventCB:DeviceDiscovering(dev_id %d, keepDiscoveringAlive %d): %s", dev_id, keepDiscoveringAlive.load(), e->toString().c_str()); const MgmtEvtDiscovering &event = *static_cast<const MgmtEvtDiscovering *>(e.get()); |