aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2020-06-24 23:13:25 +0200
committerSven Gothel <[email protected]>2020-06-24 23:13:25 +0200
commitbb5e23e940be93b10f983a97c6b3ffb04ea6d729 (patch)
tree98d64282b27b4c926570cf6409f1fce5c4c188b2
parentcb17c522a3d0e2c268b7f283c8f032a9c4a6f446 (diff)
DBTAdapter:: removeDiscoveredDevice(..) after mgmtEvDeviceDisconnectedCB processed, allowing deviceFound event after disconnect.v2.1.6
The remaining device within adapter's discoveredDevicesList caused the 'mgmtEvDeviceFoundCB' to not expose the disconnected device via AdapterStatusListener callbacks. Only a stop- and startDiscovery would have resolved such 'timing' issue. Therefor, we shall assume a disconnected device not to be discovered yet and hence enable it to be found again.
-rw-r--r--api/direct_bt/DBTAdapter.hpp1
-rw-r--r--src/direct_bt/DBTAdapter.cpp17
2 files changed, 18 insertions, 0 deletions
diff --git a/api/direct_bt/DBTAdapter.hpp b/api/direct_bt/DBTAdapter.hpp
index fbb1fab4..7e4fb9e2 100644
--- a/api/direct_bt/DBTAdapter.hpp
+++ b/api/direct_bt/DBTAdapter.hpp
@@ -189,6 +189,7 @@ namespace direct_bt {
std::shared_ptr<DBTDevice> findConnectedDevice (EUI48 const & mac) const;
bool addDiscoveredDevice(std::shared_ptr<DBTDevice> const &device);
+ bool removeDiscoveredDevice(const DBTDevice & device);
bool addSharedDevice(std::shared_ptr<DBTDevice> const &device);
std::shared_ptr<DBTDevice> getSharedDevice(const DBTDevice & device);
diff --git a/src/direct_bt/DBTAdapter.cpp b/src/direct_bt/DBTAdapter.cpp
index a54ae3f1..543947a0 100644
--- a/src/direct_bt/DBTAdapter.cpp
+++ b/src/direct_bt/DBTAdapter.cpp
@@ -375,6 +375,22 @@ bool DBTAdapter::addDiscoveredDevice(std::shared_ptr<DBTDevice> const &device) {
return true;
}
+bool DBTAdapter::removeDiscoveredDevice(const DBTDevice & device) {
+ const std::lock_guard<std::recursive_mutex> lock(mtx_discoveredDevices); // RAII-style acquire and relinquish via destructor
+ for (auto it = discoveredDevices.begin(); it != discoveredDevices.end(); ) {
+ if ( &device == (*it).get() ) { // compare actual device address
+ it = discoveredDevices.erase(it);
+ DBG_PRINT("DBTAdapter::removeDiscoveredDevice: Device discovered: %s", device.toString().c_str());
+ return true;
+ } else {
+ ++it;
+ }
+ }
+ DBG_PRINT("DBTAdapter::removeDiscoveredDevice: Device not discovered: %s", device.toString().c_str());
+ return false;
+}
+
+
int DBTAdapter::removeDiscoveredDevices() {
const std::lock_guard<std::recursive_mutex> lock(mtx_discoveredDevices); // RAII-style acquire and relinquish via destructor
int res = discoveredDevices.size();
@@ -627,6 +643,7 @@ bool DBTAdapter::mgmtEvDeviceDisconnectedCB(std::shared_ptr<MgmtEvent> e) {
}
i++;
});
+ removeDiscoveredDevice(*device); // ensure device will cause a deviceFound event after disconnect
} else {
DBG_PRINT("DBTAdapter::EventCB:DeviceDisconnected(dev_id %d): %s\n -> Device not tracked",
dev_id, event.toString().c_str());