From d78a7e639a8b370c7a8b508b787d79b470ddc406 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Tue, 7 Aug 2018 19:55:33 +0200 Subject: [PATCH] Improved default for matching messages based on model set size --- .../context/contextsimulatorimpl.cpp | 39 ++++++++++++------- src/blackcore/context/contextsimulatorimpl.h | 5 +-- 2 files changed, 28 insertions(+), 16 deletions(-) diff --git a/src/blackcore/context/contextsimulatorimpl.cpp b/src/blackcore/context/contextsimulatorimpl.cpp index 51623f53d..3e1bed1c4 100644 --- a/src/blackcore/context/contextsimulatorimpl.cpp +++ b/src/blackcore/context/contextsimulatorimpl.cpp @@ -66,7 +66,7 @@ namespace BlackCore CContextSimulator::registerHelp(); Q_ASSERT_X(sApp, Q_FUNC_INFO, "Need sApp"); - m_enableMatchingMessages = true; // there seems to be no big disadavantage in always enabling it + m_enableMatchingMessages = CBuildConfig::isLocalDeveloperDebugBuild(); // can be slow with huge model sets m_plugins->collectPlugins(); this->restoreSimulatorPlugins(); @@ -75,11 +75,15 @@ namespace BlackCore // deferred init of last model set, if no other data are set in meantime const QPointer myself(this); - QTimer::singleShot(1250, this, [ = ] + QTimer::singleShot(2500, this, [ = ] { if (!myself) { return; } this->initByLastUsedModelSet(); m_aircraftMatcher.setSetup(m_matchingSettings.get()); + if (m_aircraftMatcher.getModelSetCount() <= MatchingLogMaxModelSetSize) + { + this->enableMatchingMessages(true); + } }); } @@ -567,16 +571,11 @@ namespace BlackCore if (!status.testFlag(ISimulator::Connected)) { // we got disconnected, plugin no longer needed - unloadSimulatorPlugin(); - restoreSimulatorPlugins(); + this->unloadSimulatorPlugin(); + this->restoreSimulatorPlugins(); } - emit simulatorStatusChanged(status); - } - void CContextSimulator::onModelSetChanged(const CSimulatorInfo &simulator) - { - Q_UNUSED(simulator); - emit this->modelSetChanged(simulator); + emit this->simulatorStatusChanged(status); } void CContextSimulator::xCtxTextMessagesReceived(const Network::CTextMessageList &textMessages) @@ -853,13 +852,27 @@ namespace BlackCore void CContextSimulator::onSimulatorStarted(const CSimulatorPluginInfo &info) { - stopSimulatorListeners(); - loadSimulatorPlugin(info); + this->stopSimulatorListeners(); + this->loadSimulatorPlugin(info); + + // if we have enabled messages, we will disable if size getting too high + if (m_enableMatchingMessages) + { + const QPointer myself(this); + QTimer::singleShot(5000, this, [ = ] + { + if (!myself) { return; } + if (m_aircraftMatcher.getModelSetCount() > MatchingLogMaxModelSetSize) + { + this->enableMatchingMessages(false); + } + }); + } } void CContextSimulator::stopSimulatorListeners() { - for (const auto &info : getAvailableSimulatorPlugins()) + for (const CSimulatorPluginInfo &info : getAvailableSimulatorPlugins()) { ISimulatorListener *listener = m_plugins->getListener(info.getIdentifier()); if (listener) diff --git a/src/blackcore/context/contextsimulatorimpl.h b/src/blackcore/context/contextsimulatorimpl.h index 026afd38c..26d2eb230 100644 --- a/src/blackcore/context/contextsimulatorimpl.h +++ b/src/blackcore/context/contextsimulatorimpl.h @@ -159,6 +159,8 @@ namespace BlackCore CContextSimulator *registerWithDBus(BlackMisc::CDBusServer *server); private: + static constexpr int MatchingLogMaxModelSetSize = 125; //!< default value for switching matching log on + // ------------ slots connected with network or other contexts --------- //! \ingroup crosscontextfunction //! @{ @@ -195,9 +197,6 @@ namespace BlackCore //! Handle new connection status of simulator void onSimulatorStatusChanged(ISimulator::SimulatorStatus status); - //! Model set from model set loader changed - void onModelSetChanged(const BlackMisc::Simulation::CSimulatorInfo &simulator); - //! Listener reports the simulator has started void onSimulatorStarted(const BlackMisc::Simulation::CSimulatorPluginInfo &info);