From 02d0f40c6dd27672d10ca6bc7778503a309d3746 Mon Sep 17 00:00:00 2001 From: Mat Sutcliffe Date: Tue, 28 Sep 2021 18:34:52 +0100 Subject: [PATCH] Issue #11 Use CEventLoop in CAirspaceMonitor --- src/blackcore/airspacemonitor.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/blackcore/airspacemonitor.cpp b/src/blackcore/airspacemonitor.cpp index f9035c28e..3a64dbd1d 100644 --- a/src/blackcore/airspacemonitor.cpp +++ b/src/blackcore/airspacemonitor.cpp @@ -33,6 +33,7 @@ #include "blackmisc/sequence.h" #include "blackmisc/statusmessagelist.h" #include "blackmisc/threadutils.h" +#include "blackmisc/eventloop.h" #include "blackmisc/variant.h" #include "blackmisc/verify.h" #include "blackmisc/worker.h" @@ -181,17 +182,14 @@ namespace BlackCore // with this little trick we try to make an asynchronous signal / slot based approach // a synchronous return value - const QTime waitForFlightPlan = QTime::currentTime().addMSecs(1500); - while (sApp && !sApp->isShuttingDown() && QTime::currentTime() < waitForFlightPlan) + CEventLoop eventLoop; + eventLoop.stopWhen(m_fsdClient, &CFSDClient::flightPlanReceived, [ = ](const auto &cs, const auto &) { return cs == callsign; }); + if (eventLoop.exec(1500)) { - // process some other events and hope network answer is received already - // CEventLoop::processEventsUntil cannot be used, as a received flight plan might be for another callsign - sApp->processEventsFor(100); if (!myself || !sApp || sApp->isShuttingDown()) { return CFlightPlan(); } if (m_flightPlanCache.contains(callsign)) { plan = m_flightPlanCache[callsign]; - break; } } }