From 3083f30576b7beb7a702e76b9eb7214075863985 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Mon, 7 Mar 2016 23:28:09 +0100 Subject: [PATCH] refs #613, logging for model matching --- src/blackcore/airspacemonitor.cpp | 13 ++++++++++--- src/blackcore/airspacemonitor.h | 17 ++++++++++++----- src/blackmisc/logcategory.h | 8 ++++++++ 3 files changed, 30 insertions(+), 8 deletions(-) diff --git a/src/blackcore/airspacemonitor.cpp b/src/blackcore/airspacemonitor.cpp index 186cb986d..f7a5e7451 100644 --- a/src/blackcore/airspacemonitor.cpp +++ b/src/blackcore/airspacemonitor.cpp @@ -618,6 +618,7 @@ namespace BlackCore Q_ASSERT_X(!m_serverSupportsNameQuery || remoteAircraft.hasValidRealName(), Q_FUNC_INFO, "invalid model data"); Q_ASSERT_X(remoteAircraft.getCallsign() == remoteAircraft.getModel().getCallsign(), Q_FUNC_INFO, "wrong model callsign"); emit this->readyForModelMatching(remoteAircraft); + this->logMatching(QString("Ready for matching %1 for with model type %2").arg(callsign.toQString()).arg(remoteAircraft.getModel().getModelTypeAsString())); } void CAirspaceMonitor::ps_atcPositionUpdate(const CCallsign &callsign, const BlackMisc::PhysicalQuantities::CFrequency &frequency, const CCoordinateGeodetic &position, const BlackMisc::PhysicalQuantities::CLength &range) @@ -786,7 +787,6 @@ namespace BlackCore Q_ASSERT_X(CThreadUtils::isCurrentThreadObjectThread(this), Q_FUNC_INFO, "not in main thread"); BLACK_VERIFY_X(callsign.isValid(), Q_FUNC_INFO, "invalid callsign"); if (!callsign.isValid()) { return; } - if (!this->m_connected) { return; } if (aircraftIcaoDesignator.isEmpty() && airlineIcaoDesignator.isEmpty() && livery.isEmpty()) { return; } @@ -804,17 +804,17 @@ namespace BlackCore model = m_modelCache[callsign]; } - // already matched with DB? + // already matched with DB? Means we already have DB data in cache or existing model if (!model.canInitializeFromFsd()) { return; } // update model string if not yet existing - if (!model.hasModelString() && !modelString.isEmpty()) { model.setModelString(modelString); } if (model.getModelType() == CAircraftModel::TypeUnknown || model.getModelType() == CAircraftModel::TypeQueriedFromNetwork) { model.setModelType(type); // update type if no type yet } // we have no DB model yet, but do we have model string? + if (!model.hasModelString() && !modelString.isEmpty()) { model.setModelString(modelString); } if (model.hasModelString()) { // if we find the model here we have a fully defined DB model @@ -894,6 +894,13 @@ namespace BlackCore } // lock } + void CAirspaceMonitor::logMatching(const QString &text) const + { + if (text.isEmpty()) { return; } + if (!this->m_logMatchingProcess) { return; } + CLogMessage(this).info(text); + } + void CAirspaceMonitor::ps_aircraftUpdateReceived(const CAircraftSituation &situation, const CTransponder &transponder) { Q_ASSERT_X(CThreadUtils::isCurrentThreadObjectThread(this), Q_FUNC_INFO, "Called in different thread"); diff --git a/src/blackcore/airspacemonitor.h b/src/blackcore/airspacemonitor.h index d03dfe56d..a9d3cb226 100644 --- a/src/blackcore/airspacemonitor.h +++ b/src/blackcore/airspacemonitor.h @@ -130,6 +130,9 @@ namespace BlackCore //! Returns the closest ATC station operating on the given frequency, if any BlackMisc::Aviation::CAtcStation getAtcStationForComUnit(const BlackMisc::Aviation::CComSystem &comSystem); + //! Logging for matching process (see why a model is matched like it is) + void logMatchingProcess(bool log) { this->m_logMatchingProcess = log; } + //! Clear the contents void clear(); @@ -214,14 +217,15 @@ namespace BlackCore CPartsPerCallsign m_partsByCallsign; //!< parts, for performance reasons per callsign, thread safe access required BlackMisc::Aviation::CCallsignSet m_aircraftSupportingParts; //!< aircraft supporting parts, thread safe access required - QMap m_flightPlanCache; - QMap m_modelCache; //!< any model information recevived from network temporarily stored until it is "completed". Will be removed when aircraft is moved to aircraft in range + QMap m_flightPlanCache; //!< flight plan information retrieved any cached + QMap m_modelCache; //!< any model information recevived from network temporarily stored until it is "completed". Will be removed when aircraft is moved to aircraft in range INetwork *m_network = nullptr; CAirspaceAnalyzer *m_analyzer = nullptr; //!< owned analyzer bool m_serverSupportsNameQuery = false; //!< not all servers support name query bool m_connected = false; //!< retrieve data - bool m_sendInterimPositions = false; + bool m_sendInterimPositions = false; //!< send interim positions to other clients + bool m_logMatchingProcess = false; //!< shall we log. information about the matching process QTimer m_interimPositionUpdateTimer; // locks @@ -241,12 +245,15 @@ namespace BlackCore //! Remove data from caches void removeFromAircraftCaches(const BlackMisc::Aviation::CCallsign &callsign); - //! Schedule a ready for model matching + //! Schedule a "ready for model matching" void fireDelayedReadyForModelMatching(const BlackMisc::Aviation::CCallsign &callsign, int trial = 1, int delayMs = 2500); - //! FSD or icao query received + //! FSD or icao query received. Here we also replace the model with a model from DB if possible (reverse lookup) void icaoOrFsdDataReceived(const BlackMisc::Aviation::CCallsign &callsign, const QString &aircraftIcaoDesignator, const QString &airlineIcaoDesignator, const QString &livery, const QString &modelString, BlackMisc::Simulation::CAircraftModel::ModelType type); + //! Log.matching + void logMatching(const QString &text) const; + //! Store an aircraft situation //! \threadsafe void storeAircraftSituation(const BlackMisc::Aviation::CAircraftSituation &situation); diff --git a/src/blackmisc/logcategory.h b/src/blackmisc/logcategory.h index bebc03fbf..dfd2d4be1 100644 --- a/src/blackmisc/logcategory.h +++ b/src/blackmisc/logcategory.h @@ -99,6 +99,13 @@ namespace BlackMisc return cat; } + //! Matching + static const CLogCategory &matching() + { + static const CLogCategory cat { "swift.matching" }; + return cat; + } + //! Webservice with swift DB static const CLogCategory &swiftDbWebservice() { @@ -121,6 +128,7 @@ namespace BlackMisc download(), webservice(), mapping(), + matching(), swiftDbWebservice(), }; return cats;