diff --git a/src/blackcore/aircraftmatcher.cpp b/src/blackcore/aircraftmatcher.cpp index c9f8f3fcd..340718104 100644 --- a/src/blackcore/aircraftmatcher.cpp +++ b/src/blackcore/aircraftmatcher.cpp @@ -34,43 +34,6 @@ using namespace BlackMisc::Simulation; namespace BlackCore { - const QString &CAircraftMatcher::matchingLogFlagToString(CAircraftMatcher::MatchingLogFlag logFlag) - { - static const QString logNothing("nothing"); - static const QString logModelstring("model string"); - static const QString logStepwiseReduce("step wise reduce"); - static const QString logScoring("scoring"); - static const QString logCombinedDefaultType("combined default type"); - static const QString logMinimal("minimal"); - static const QString logAll("all"); - - switch (logFlag) - { - case LogCombinedDefaultType: return logCombinedDefaultType; - case LogNothing: return logNothing; - case LogModelstring: return logModelstring; - case LogStepwiseReduce: return logStepwiseReduce; - case LogScoring: return logScoring; - case LogMinimal: return logMinimal; - case LogAll: return logAll; - default: break; - } - - static const QString unknown("unknown"); - return unknown; - } - - const QString CAircraftMatcher::matchingLogToString(MatchingLog log) - { - if (log == LogNothing) { return matchingLogFlagToString(LogNothing); } - QStringList l; - if (log.testFlag(LogCombinedDefaultType)) { l << matchingLogFlagToString(LogCombinedDefaultType); } - if (log.testFlag(LogModelstring)) { l << matchingLogFlagToString(LogModelstring); } - if (log.testFlag(LogStepwiseReduce)) { l << matchingLogFlagToString(LogStepwiseReduce); } - if (log.testFlag(LogScoring)) { l << matchingLogFlagToString(LogScoring); } - return l.join(", "); - } - const CLogCategoryList &CAircraftMatcher::getLogCategories() { static const CLogCategoryList cats { CLogCategory::matching() }; @@ -162,7 +125,7 @@ namespace BlackCore "-----------------------------------------\n"); const QDateTime startTime = QDateTime::currentDateTimeUtc(); - if (whatToLog == LogNothing) { log = nullptr; } + if (whatToLog == MatchingLogNothing) { log = nullptr; } if (log) { log->clear(); } CMatchingUtils::addLogDetailsToList(log, remoteAircraft, m1.arg(startTime.toString(format))); @@ -894,7 +857,7 @@ namespace BlackCore Q_UNUSED(whatToLog); const CAircraftMatcherSetup::MatchingMode mode = setup.getMatchingMode(); - CStatusMessageList *reduceLog = log && whatToLog.testFlag(LogStepwiseReduce) ? log : nullptr; + CStatusMessageList *reduceLog = log && whatToLog.testFlag(MatchingLogStepwiseReduce) ? log : nullptr; bool reduced = false; do { @@ -990,15 +953,15 @@ namespace BlackCore CAircraftMatcherSetup::MatchingMode mode = setup.getMatchingMode(); const bool noZeroScores = mode.testFlag(CAircraftMatcherSetup::ScoreIgnoreZeros); const bool preferColorLiveries = mode.testFlag(CAircraftMatcherSetup::ScorePreferColorLiveries); + CStatusMessageList *scoreLog = log && whatToLog.testFlag(MatchingLogScoring) ? log : nullptr; // VTOL ScoredModels map; - map = modelSet.scoreFull(remoteAircraft.getModel(), preferColorLiveries, noZeroScores, whatToLog.testFlag(LogScoring) ? log : nullptr); + map = modelSet.scoreFull(remoteAircraft.getModel(), preferColorLiveries, noZeroScores, scoreLog); CAircraftModel matchedModel; if (map.isEmpty()) { return CAircraftModelList(); } - CStatusMessageList *scoreLog = log && whatToLog.testFlag(LogScoring) ? log : nullptr; maxScore = map.lastKey(); const CAircraftModelList maxScoreAircraft(map.values(maxScore)); CMatchingUtils::addLogDetailsToList(scoreLog, remoteAircraft, QStringLiteral("Scores: %1").arg(scoresToString(map)), getLogCategories()); @@ -1009,7 +972,7 @@ namespace BlackCore CAircraftModel CAircraftMatcher::getCombinedTypeDefaultModel(const CAircraftModelList &modelSet, const CSimulatedAircraft &remoteAircraft, const CAircraftModel &defaultModel, MatchingLog whatToLog, CStatusMessageList *log) { const QString combinedType = remoteAircraft.getAircraftIcaoCombinedType(); - CStatusMessageList *combinedLog = log && whatToLog.testFlag(LogCombinedDefaultType) ? log : nullptr; + CStatusMessageList *combinedLog = log && whatToLog.testFlag(MatchingLogCombinedDefaultType) ? log : nullptr; if (combinedType.isEmpty()) { @@ -1045,7 +1008,7 @@ namespace BlackCore CAircraftModel CAircraftMatcher::matchByExactModelString(const CSimulatedAircraft &remoteAircraft, const CAircraftModelList &models, MatchingLog whatToLog, CStatusMessageList *log) { - CStatusMessageList *msLog = log && whatToLog.testFlag(LogModelstring) ? log : nullptr; + CStatusMessageList *msLog = log && whatToLog.testFlag(MatchingLogModelstring) ? log : nullptr; if (remoteAircraft.getModelString().isEmpty()) { if (msLog) { CMatchingUtils::addLogDetailsToList(log, remoteAircraft, QStringLiteral("No model string, no exact match possible")); } diff --git a/src/blackcore/aircraftmatcher.h b/src/blackcore/aircraftmatcher.h index 534789d00..742c62e5f 100644 --- a/src/blackcore/aircraftmatcher.h +++ b/src/blackcore/aircraftmatcher.h @@ -14,6 +14,7 @@ #include "blackcore/blackcoreexport.h" #include "blackmisc/simulation/aircraftmatchersetup.h" #include "blackmisc/simulation/aircraftmodellist.h" +#include "blackmisc/simulation/matchinglog.h" #include "blackmisc/simulation/matchingstatistics.h" #include "blackmisc/simulation/categorymatcher.h" #include "blackmisc/statusmessage.h" @@ -44,25 +45,6 @@ namespace BlackCore Q_OBJECT public: - //! What to log - enum MatchingLogFlag - { - LogNothing = 0, - LogModelstring = 1 << 0, - LogStepwiseReduce = 1 << 1, - LogScoring = 1 << 2, - LogCombinedDefaultType = 1 << 3, - LogMinimal = 1 << 10, - LogAll = LogModelstring | LogStepwiseReduce | LogScoring | LogCombinedDefaultType - }; - Q_DECLARE_FLAGS(MatchingLog, MatchingLogFlag) - - //! Log flag to string - static const QString &matchingLogFlagToString(MatchingLogFlag logFlag); - - //! Log flag to string - static const QString matchingLogToString(MatchingLog log); - //! Log categories static const BlackMisc::CLogCategoryList &getLogCategories(); @@ -88,7 +70,7 @@ namespace BlackCore //! \threadsafe BlackMisc::Simulation::CAircraftModel getClosestMatch( const BlackMisc::Simulation::CSimulatedAircraft &remoteAircraft, - MatchingLog whatToLog, + BlackMisc::Simulation::MatchingLog whatToLog, BlackMisc::CStatusMessageList *log = nullptr) const; //! Return an valid airline ICAO code @@ -249,19 +231,19 @@ namespace BlackCore static BlackMisc::Simulation::CAircraftModelList getClosestMatchStepwiseReduceImplementation( const BlackMisc::Simulation::CAircraftModelList &modelSet, const BlackMisc::Simulation::CAircraftMatcherSetup &setup, const BlackMisc::Simulation::CCategoryMatcher &categoryMatcher, const BlackMisc::Simulation::CSimulatedAircraft &remoteAircraft, - MatchingLog whatToLog, BlackMisc::CStatusMessageList *log = nullptr); + BlackMisc::Simulation::MatchingLog whatToLog, BlackMisc::CStatusMessageList *log = nullptr); //! The score based implementation - static BlackMisc::Simulation::CAircraftModelList getClosestMatchScoreImplementation(const BlackMisc::Simulation::CAircraftModelList &modelSet, const BlackMisc::Simulation::CAircraftMatcherSetup &setup, const BlackMisc::Simulation::CSimulatedAircraft &remoteAircraft, int &maxScore, BlackCore::CAircraftMatcher::MatchingLog whatToLog, BlackMisc::CStatusMessageList *log = nullptr); + static BlackMisc::Simulation::CAircraftModelList getClosestMatchScoreImplementation(const BlackMisc::Simulation::CAircraftModelList &modelSet, const BlackMisc::Simulation::CAircraftMatcherSetup &setup, const BlackMisc::Simulation::CSimulatedAircraft &remoteAircraft, int &maxScore, BlackMisc::Simulation::MatchingLog whatToLog, BlackMisc::CStatusMessageList *log = nullptr); //! Get combined type default model, i.e. get a default model under consideration of the combined code such as "L2J" //! \see BlackMisc::Simulation::CSimulatedAircraft::getAircraftIcaoCombinedType //! \remark in any case a (default) model is returned - static BlackMisc::Simulation::CAircraftModel getCombinedTypeDefaultModel(const BlackMisc::Simulation::CAircraftModelList &modelSet, const BlackMisc::Simulation::CSimulatedAircraft &remoteAircraft, const BlackMisc::Simulation::CAircraftModel &defaultModel, MatchingLog whatToLog, BlackMisc::CStatusMessageList *log = nullptr); + static BlackMisc::Simulation::CAircraftModel getCombinedTypeDefaultModel(const BlackMisc::Simulation::CAircraftModelList &modelSet, const BlackMisc::Simulation::CSimulatedAircraft &remoteAircraft, const BlackMisc::Simulation::CAircraftModel &defaultModel, BlackMisc::Simulation::MatchingLog whatToLog, BlackMisc::CStatusMessageList *log = nullptr); //! Search in models by key (aka model string) //! \threadsafe - static BlackMisc::Simulation::CAircraftModel matchByExactModelString(const BlackMisc::Simulation::CSimulatedAircraft &remoteAircraft, const BlackMisc::Simulation::CAircraftModelList &models, MatchingLog whatToLog, BlackMisc::CStatusMessageList *log); + static BlackMisc::Simulation::CAircraftModel matchByExactModelString(const BlackMisc::Simulation::CSimulatedAircraft &remoteAircraft, const BlackMisc::Simulation::CAircraftModelList &models, BlackMisc::Simulation::MatchingLog whatToLog, BlackMisc::CStatusMessageList *log); //! Installed models by ICAO data //! \threadsafe @@ -338,7 +320,4 @@ namespace BlackCore }; } // namespace -Q_DECLARE_METATYPE(BlackCore::CAircraftMatcher::MatchingLogFlag) -Q_DECLARE_METATYPE(BlackCore::CAircraftMatcher::MatchingLog) - #endif // guard diff --git a/src/blackcore/context/contextsimulator.h b/src/blackcore/context/contextsimulator.h index cb2790d03..5395f70f3 100644 --- a/src/blackcore/context/contextsimulator.h +++ b/src/blackcore/context/contextsimulator.h @@ -11,16 +11,16 @@ #ifndef BLACKCORE_CONTEXTSIMULATOR_H #define BLACKCORE_CONTEXTSIMULATOR_H -#include "blackconfig/buildconfig.h" -#include "blackcore/blackcoreexport.h" #include "blackcore/context/context.h" #include "blackcore/corefacade.h" #include "blackcore/corefacadeconfig.h" #include "blackcore/simulator.h" +#include "blackcore/blackcoreexport.h" #include "blackmisc/weather/weathergrid.h" #include "blackmisc/simulation/aircraftmodellist.h" #include "blackmisc/simulation/aircraftmatchersetup.h" #include "blackmisc/simulation/matchingstatistics.h" +#include "blackmisc/simulation/matchinglog.h" #include "blackmisc/simulation/simulatorplugininfo.h" #include "blackmisc/simulation/simulatorplugininfolist.h" #include "blackmisc/simulation/simulatorinternals.h" @@ -31,6 +31,7 @@ #include "blackmisc/pq/time.h" #include "blackmisc/identifier.h" #include "blackmisc/pixmap.h" +#include "blackconfig/buildconfig.h" #include #include @@ -261,10 +262,10 @@ namespace BlackCore virtual BlackMisc::CStatusMessageList getMatchingMessages(const BlackMisc::Aviation::CCallsign &callsign) const = 0; //! Enabled mapping logging? - virtual bool isMatchingMessagesEnabled() const = 0; + virtual BlackMisc::Simulation::MatchingLog isMatchingMessagesEnabled() const = 0; //! Enable mapping logging - virtual void enableMatchingMessages(bool enabled) = 0; + virtual void enableMatchingMessages(BlackMisc::Simulation::MatchingLog enabled) = 0; //! Highlight aircraft in simulator virtual void highlightAircraft(const BlackMisc::Simulation::CSimulatedAircraft &aircraftToHighlight, bool enableHighlight, const BlackMisc::PhysicalQuantities::CTime &displayTime) = 0; diff --git a/src/blackcore/context/contextsimulatorempty.h b/src/blackcore/context/contextsimulatorempty.h index 14553b4aa..572108476 100644 --- a/src/blackcore/context/contextsimulatorempty.h +++ b/src/blackcore/context/contextsimulatorempty.h @@ -349,17 +349,17 @@ namespace BlackCore } //! \copydoc IContextSimulator::enableMatchingMessages - virtual void enableMatchingMessages(bool enable) override + virtual void enableMatchingMessages(BlackMisc::Simulation::MatchingLog enable) override { Q_UNUSED(enable); logEmptyContextWarning(Q_FUNC_INFO); } //! \copydoc IContextSimulator::isMatchingMessagesEnabled - virtual bool isMatchingMessagesEnabled() const override + virtual BlackMisc::Simulation::MatchingLog isMatchingMessagesEnabled() const override { logEmptyContextWarning(Q_FUNC_INFO); - return false; + return BlackMisc::Simulation::MatchingLogNothing; } //! \copydoc IContextSimulator::parseCommandLine diff --git a/src/blackcore/context/contextsimulatorimpl.cpp b/src/blackcore/context/contextsimulatorimpl.cpp index c221f00a6..59f26f7c2 100644 --- a/src/blackcore/context/contextsimulatorimpl.cpp +++ b/src/blackcore/context/contextsimulatorimpl.cpp @@ -70,7 +70,8 @@ namespace BlackCore CContextSimulator::registerHelp(); Q_ASSERT_X(sApp, Q_FUNC_INFO, "Need sApp"); - m_enableMatchingMessages = CBuildConfig::isLocalDeveloperDebugBuild(); // can be slow with huge model sets + MatchingLog logMatchingMessages = CBuildConfig::isLocalDeveloperDebugBuild() ? MatchingLogAll : MatchingLogSimplified; + m_logMatchingMessages = logMatchingMessages; m_plugins->collectPlugins(); this->restoreSimulatorPlugins(); @@ -87,7 +88,7 @@ namespace BlackCore m_aircraftMatcher.setSetup(m_matchingSettings.get()); if (m_aircraftMatcher.getModelSetCount() <= MatchingLogMaxModelSetSize) { - this->enableMatchingMessages(true); + this->enableMatchingMessages(logMatchingMessages); } }); @@ -586,9 +587,9 @@ namespace BlackCore // here we find the best simulator model for a resolved model // in the first step we already tried to find accurate ICAO codes etc. // coming from CAirspaceMonitor::sendReadyForModelMatching - CAircraftMatcher::MatchingLog whatToLog = CAircraftMatcher::LogAll; + MatchingLog whatToLog = m_logMatchingMessages; CStatusMessageList matchingMessages; - CStatusMessageList *pMatchingMessages = m_enableMatchingMessages ? &matchingMessages : nullptr; + CStatusMessageList *pMatchingMessages = m_logMatchingMessages > 0 ? &matchingMessages : nullptr; CAircraftModel aircraftModel = m_aircraftMatcher.getClosestMatch(remoteAircraft, whatToLog, pMatchingMessages); Q_ASSERT_X(remoteAircraft.getCallsign() == aircraftModel.getCallsign(), Q_FUNC_INFO, "Mismatching callsigns"); const CLength cg = m_simulatorPlugin.second->getCGPerModelString(aircraftModel.getModelString()); @@ -837,17 +838,17 @@ namespace BlackCore return m_matchingMessages[callsign]; } - bool CContextSimulator::isMatchingMessagesEnabled() const + MatchingLog CContextSimulator::isMatchingMessagesEnabled() const { if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; } - return m_enableMatchingMessages; + return m_logMatchingMessages; } - void CContextSimulator::enableMatchingMessages(bool enabled) + void CContextSimulator::enableMatchingMessages(MatchingLog enabled) { - if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO << enabled; } - if (m_enableMatchingMessages == enabled) { return; } - m_enableMatchingMessages = enabled; + if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO << matchingLogToString(enabled); } + if (m_logMatchingMessages == enabled) { return; } + m_logMatchingMessages = enabled; emit CContext::changedLogOrDebugSettings(); } @@ -1045,7 +1046,7 @@ namespace BlackCore this->loadSimulatorPlugin(info); // if we have enabled messages, we will disable if size getting too high - if (m_enableMatchingMessages) + if (m_logMatchingMessages) { const QPointer myself(this); QTimer::singleShot(5000, this, [ = ] @@ -1087,7 +1088,7 @@ namespace BlackCore { if (callsign.isEmpty()) { return; } if (messages.isEmpty()) { return; } - if (!m_enableMatchingMessages) { return; } + if (!m_logMatchingMessages) { return; } if (m_matchingMessages.contains(callsign)) { CStatusMessageList &msgs = m_matchingMessages[callsign]; diff --git a/src/blackcore/context/contextsimulatorimpl.h b/src/blackcore/context/contextsimulatorimpl.h index 9f66e32b4..a06d38d4b 100644 --- a/src/blackcore/context/contextsimulatorimpl.h +++ b/src/blackcore/context/contextsimulatorimpl.h @@ -117,8 +117,8 @@ namespace BlackCore virtual int doMatchingsAgain() override; virtual bool doMatchingAgain(const BlackMisc::Aviation::CCallsign &callsign) override; virtual BlackMisc::CStatusMessageList getMatchingMessages(const BlackMisc::Aviation::CCallsign &callsign) const override; - virtual bool isMatchingMessagesEnabled() const override; - virtual void enableMatchingMessages(bool enabled) override; + virtual BlackMisc::Simulation::MatchingLog isMatchingMessagesEnabled() const override; + virtual void enableMatchingMessages(BlackMisc::Simulation::MatchingLog enabled) override; virtual BlackMisc::Simulation::CMatchingStatistics getCurrentMatchingStatistics(bool missingOnly) const override; virtual void setMatchingSetup(const BlackMisc::Simulation::CAircraftMatcherSetup &setup) override; virtual BlackMisc::Simulation::CAircraftMatcherSetup getMatchingSetup() const override; @@ -267,8 +267,8 @@ namespace BlackCore bool m_wasSimulating = false; bool m_initallyAddAircraft = false; - bool m_enableMatchingMessages = true; bool m_isWeatherActivated = false; // used to activate after plugin is loaded + BlackMisc::Simulation::MatchingLog m_logMatchingMessages = BlackMisc::Simulation::MatchingLogSimplified; QString m_networkSessionId; //!< Network session of CServer::getServerSessionId, if not connected empty (for statistics, ..) BlackMisc::Simulation::CBackgroundValidation *m_validator = nullptr; diff --git a/src/blackcore/context/contextsimulatorproxy.cpp b/src/blackcore/context/contextsimulatorproxy.cpp index 5f5739527..2b36aa992 100644 --- a/src/blackcore/context/contextsimulatorproxy.cpp +++ b/src/blackcore/context/contextsimulatorproxy.cpp @@ -307,12 +307,14 @@ namespace BlackCore return m_dBusInterface->callDBusRet(QLatin1String("getMatchingMessages"), callsign); } - bool CContextSimulatorProxy::isMatchingMessagesEnabled() const + MatchingLog CContextSimulatorProxy::isMatchingMessagesEnabled() const { - return m_dBusInterface->callDBusRet(QLatin1String("isMatchingMessagesEnabled")); + //! \fixme KB 2019-04 directly return MatchingLog causes issues with QDbusArgument + const int r = m_dBusInterface->callDBusRet(QLatin1String("isMatchingMessagesEnabled")); + return static_cast(r); } - void CContextSimulatorProxy::enableMatchingMessages(bool enabled) + void CContextSimulatorProxy::enableMatchingMessages(MatchingLog enabled) { m_dBusInterface->callDBus(QLatin1String("enableMatchingMessages"), enabled); } diff --git a/src/blackcore/context/contextsimulatorproxy.h b/src/blackcore/context/contextsimulatorproxy.h index 2630791f9..e330c7221 100644 --- a/src/blackcore/context/contextsimulatorproxy.h +++ b/src/blackcore/context/contextsimulatorproxy.h @@ -98,8 +98,8 @@ namespace BlackCore virtual void setWeatherActivated(bool activated) override; virtual void requestWeatherGrid(const BlackMisc::Weather::CWeatherGrid &weatherGrid, const BlackMisc::CIdentifier &identifier) override; virtual BlackMisc::CStatusMessageList getMatchingMessages(const BlackMisc::Aviation::CCallsign &callsign) const override; - virtual bool isMatchingMessagesEnabled() const override; - virtual void enableMatchingMessages(bool enabled) override; + virtual BlackMisc::Simulation::MatchingLog isMatchingMessagesEnabled() const override; + virtual void enableMatchingMessages(BlackMisc::Simulation::MatchingLog enabled) override; virtual bool parseCommandLine(const QString &commandLine, const BlackMisc::CIdentifier &originator) override; virtual int doMatchingsAgain() override; virtual bool doMatchingAgain(const BlackMisc::Aviation::CCallsign &callsign) override;