summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2020-09-29 18:24:00 +0200
committerSven Gothel <[email protected]>2020-09-29 18:24:00 +0200
commitf03c57b88c9053d730e1f6767f6b305865a54049 (patch)
tree92d55a4a75748f472686a5dc16ef04b0bd91d76e /examples
parent9beadf76cac57c79fbf8d87865a244bc92bab71e (diff)
dbt_scanner10: Have counter MULTI_MEASUREMENTS atomic and issue decrement @ end of processing thread (for main thread exit); ..
Also issue DBTManager::close() to have a proper visibility @ program runtime via valgrind. Remove the nonsense 3s wait @ test end.
Diffstat (limited to 'examples')
-rw-r--r--examples/direct_bt_scanner10/dbt_scanner10.cpp25
1 files changed, 16 insertions, 9 deletions
diff --git a/examples/direct_bt_scanner10/dbt_scanner10.cpp b/examples/direct_bt_scanner10/dbt_scanner10.cpp
index e04294e1..54569039 100644
--- a/examples/direct_bt_scanner10/dbt_scanner10.cpp
+++ b/examples/direct_bt_scanner10/dbt_scanner10.cpp
@@ -52,7 +52,7 @@ using namespace direct_bt;
static int64_t timestamp_t0;
-static int MULTI_MEASUREMENTS = 8;
+static std::atomic<int> MULTI_MEASUREMENTS = 8;
static bool KEEP_CONNECTED = true;
static bool GATT_PING_ENABLED = false;
@@ -424,11 +424,6 @@ exit:
device->getAdapter().printSharedPtrListOfDevices();
}
- if( 0 < MULTI_MEASUREMENTS ) {
- MULTI_MEASUREMENTS--;
- fprintf(stderr, "****** Processing Device: MULTI_MEASUREMENTS left %d: %s\n", MULTI_MEASUREMENTS, device->getAddressString().c_str());
- }
-
fprintf(stderr, "****** Processing Device: End: Success %d on %s; devInProc %zd\n",
success, device->toString().c_str(), devicesInProcessing.size());
@@ -444,6 +439,11 @@ exit:
device->getAdapter().startDiscovery( true );
}
}
+
+ if( 0 < MULTI_MEASUREMENTS ) {
+ MULTI_MEASUREMENTS--;
+ fprintf(stderr, "****** Processing Device: MULTI_MEASUREMENTS left %d: %s\n", MULTI_MEASUREMENTS.load(), device->getAddressString().c_str());
+ }
}
static void removeDevice(std::shared_ptr<DBTDevice> device) {
@@ -501,7 +501,7 @@ void test(int dev_id) {
)
{
fprintf(stderr, "****** EOL Test MULTI_MEASUREMENTS left %d, processed %zd/%zd\n",
- MULTI_MEASUREMENTS, devicesProcessed.size(), waitForDevices.size());
+ MULTI_MEASUREMENTS.load(), devicesProcessed.size(), waitForDevices.size());
printList("****** WaitForDevice ", waitForDevices);
printList("****** DevicesProcessed ", devicesProcessed);
done = true;
@@ -581,7 +581,7 @@ int main(int argc, char *argv[])
"[-dbt_l2cap reader.timeout=10000,restart.count=0,...] "
"\n");
- fprintf(stderr, "MULTI_MEASUREMENTS %d\n", MULTI_MEASUREMENTS);
+ fprintf(stderr, "MULTI_MEASUREMENTS %d\n", MULTI_MEASUREMENTS.load());
fprintf(stderr, "KEEP_CONNECTED %d\n", KEEP_CONNECTED);
fprintf(stderr, "GATT_PING_ENABLED %d\n", GATT_PING_ENABLED);
fprintf(stderr, "REMOVE_DEVICE %d\n", REMOVE_DEVICE);
@@ -598,6 +598,13 @@ int main(int argc, char *argv[])
}
fprintf(stderr, "****** TEST start\n");
test(dev_id);
- std::this_thread::sleep_for(std::chrono::milliseconds(3000));
fprintf(stderr, "****** TEST end\n");
+ if( true ) {
+ // Just for testing purpose, i.e. triggering DBTManager::close() within the test controlled app,
+ // instead of program shutdown.
+ fprintf(stderr, "****** Manager close start\n");
+ DBTManager & mngr = DBTManager::get(BTMode::NONE); // already existing
+ mngr.close();
+ fprintf(stderr, "****** Manager close end\n");
+ }
}