Improved default for matching messages based on model set size

This commit is contained in:
Klaus Basan
2018-08-07 19:55:33 +02:00
parent 8b6bdf2276
commit d78a7e639a
2 changed files with 28 additions and 16 deletions

View File

@@ -66,7 +66,7 @@ namespace BlackCore
CContextSimulator::registerHelp(); CContextSimulator::registerHelp();
Q_ASSERT_X(sApp, Q_FUNC_INFO, "Need sApp"); 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(); m_plugins->collectPlugins();
this->restoreSimulatorPlugins(); this->restoreSimulatorPlugins();
@@ -75,11 +75,15 @@ namespace BlackCore
// deferred init of last model set, if no other data are set in meantime // deferred init of last model set, if no other data are set in meantime
const QPointer<CContextSimulator> myself(this); const QPointer<CContextSimulator> myself(this);
QTimer::singleShot(1250, this, [ = ] QTimer::singleShot(2500, this, [ = ]
{ {
if (!myself) { return; } if (!myself) { return; }
this->initByLastUsedModelSet(); this->initByLastUsedModelSet();
m_aircraftMatcher.setSetup(m_matchingSettings.get()); 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)) if (!status.testFlag(ISimulator::Connected))
{ {
// we got disconnected, plugin no longer needed // we got disconnected, plugin no longer needed
unloadSimulatorPlugin(); this->unloadSimulatorPlugin();
restoreSimulatorPlugins(); this->restoreSimulatorPlugins();
} }
emit simulatorStatusChanged(status);
}
void CContextSimulator::onModelSetChanged(const CSimulatorInfo &simulator) emit this->simulatorStatusChanged(status);
{
Q_UNUSED(simulator);
emit this->modelSetChanged(simulator);
} }
void CContextSimulator::xCtxTextMessagesReceived(const Network::CTextMessageList &textMessages) void CContextSimulator::xCtxTextMessagesReceived(const Network::CTextMessageList &textMessages)
@@ -853,13 +852,27 @@ namespace BlackCore
void CContextSimulator::onSimulatorStarted(const CSimulatorPluginInfo &info) void CContextSimulator::onSimulatorStarted(const CSimulatorPluginInfo &info)
{ {
stopSimulatorListeners(); this->stopSimulatorListeners();
loadSimulatorPlugin(info); this->loadSimulatorPlugin(info);
// if we have enabled messages, we will disable if size getting too high
if (m_enableMatchingMessages)
{
const QPointer<CContextSimulator> myself(this);
QTimer::singleShot(5000, this, [ = ]
{
if (!myself) { return; }
if (m_aircraftMatcher.getModelSetCount() > MatchingLogMaxModelSetSize)
{
this->enableMatchingMessages(false);
}
});
}
} }
void CContextSimulator::stopSimulatorListeners() void CContextSimulator::stopSimulatorListeners()
{ {
for (const auto &info : getAvailableSimulatorPlugins()) for (const CSimulatorPluginInfo &info : getAvailableSimulatorPlugins())
{ {
ISimulatorListener *listener = m_plugins->getListener(info.getIdentifier()); ISimulatorListener *listener = m_plugins->getListener(info.getIdentifier());
if (listener) if (listener)

View File

@@ -159,6 +159,8 @@ namespace BlackCore
CContextSimulator *registerWithDBus(BlackMisc::CDBusServer *server); CContextSimulator *registerWithDBus(BlackMisc::CDBusServer *server);
private: private:
static constexpr int MatchingLogMaxModelSetSize = 125; //!< default value for switching matching log on
// ------------ slots connected with network or other contexts --------- // ------------ slots connected with network or other contexts ---------
//! \ingroup crosscontextfunction //! \ingroup crosscontextfunction
//! @{ //! @{
@@ -195,9 +197,6 @@ namespace BlackCore
//! Handle new connection status of simulator //! Handle new connection status of simulator
void onSimulatorStatusChanged(ISimulator::SimulatorStatus status); 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 //! Listener reports the simulator has started
void onSimulatorStarted(const BlackMisc::Simulation::CSimulatorPluginInfo &info); void onSimulatorStarted(const BlackMisc::Simulation::CSimulatorPluginInfo &info);