From 2497e689af16fa92247c263e2c40d1f208c06ff7 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Tue, 21 Apr 2020 19:52:15 +0200 Subject: [PATCH] [FSX/P3D] self adjusting timer for listener P3D with remote connections caan be SLOW before running in a timeout --- .../simulator/fsxcommon/simulatorfsxcommon.cpp | 18 +++++++++++++++--- .../simulator/fsxcommon/simulatorfsxcommon.h | 2 ++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/plugins/simulator/fsxcommon/simulatorfsxcommon.cpp b/src/plugins/simulator/fsxcommon/simulatorfsxcommon.cpp index 289120d15..57737ef55 100644 --- a/src/plugins/simulator/fsxcommon/simulatorfsxcommon.cpp +++ b/src/plugins/simulator/fsxcommon/simulatorfsxcommon.cpp @@ -2798,8 +2798,7 @@ namespace BlackSimPlugin CSimulatorFsxCommonListener::CSimulatorFsxCommonListener(const CSimulatorPluginInfo &info) : ISimulatorListener(info) { - constexpr int QueryInterval = 5 * 1000; // 5 seconds - m_timer.setInterval(QueryInterval); + m_timer.setInterval(MinQueryIntervalMs); m_timer.setObjectName(this->objectName().append(":m_timer")); connect(&m_timer, &QTimer::timeout, this, &CSimulatorFsxCommonListener::checkConnection); } @@ -2876,7 +2875,20 @@ namespace BlackSimPlugin emit this->simulatorStarted(this->getPluginInfo()); } - CLogMessage(this).debug(u"Checked sim connection in %1ms") << t.elapsed(); + const qint64 elapsed = t.elapsed(); + const QString sim = this->getPluginInfo().getSimulatorInfo().toQString(true); + CLogMessage(this).debug(u"Checked sim.'%1' connection in %1ms") << elapsed; + + if (elapsed > qRound(1.25 * MinQueryIntervalMs)) + { + const int newIntervalMs = qRound(1.5 * elapsed); + CLogMessage(this).debug(u"Check for simulator sim.'%1' connection in %2ms, too slow. Setting %3ms") << sim << elapsed << newIntervalMs; + if (m_timer.interval() != newIntervalMs) { m_timer.setInterval(newIntervalMs); } + } + else + { + if (m_timer.interval() != MinQueryIntervalMs) { m_timer.setInterval(MinQueryIntervalMs); } + } } bool CSimulatorFsxCommonListener::checkVersionAndSimulator() const diff --git a/src/plugins/simulator/fsxcommon/simulatorfsxcommon.h b/src/plugins/simulator/fsxcommon/simulatorfsxcommon.h index ba05620b3..2ff1d9ee5 100644 --- a/src/plugins/simulator/fsxcommon/simulatorfsxcommon.h +++ b/src/plugins/simulator/fsxcommon/simulatorfsxcommon.h @@ -667,6 +667,8 @@ namespace BlackSimPlugin bool checkSimConnectDll() const; private: + static constexpr int MinQueryIntervalMs = 5 * 1000; // 5 seconds + QTimer m_timer { this }; //!< timer, "this" is needed otherwise I get warnings when move to new thread QString m_simulatorVersion; QString m_simConnectVersion;