From ac22e1d17d3defa9dbcb0b3b5b6cae0a50b04cc2 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Tue, 16 Jul 2019 18:12:13 +0200 Subject: [PATCH] Ref T554, check function for auto publishing --- src/blackcore/db/databaseutils.cpp | 18 ++++++++++++++++++ src/blackcore/db/databaseutils.h | 12 +++++++++++- src/blackmisc/simulation/autopublishdata.h | 16 ++++++++++++++++ 3 files changed, 45 insertions(+), 1 deletion(-) diff --git a/src/blackcore/db/databaseutils.cpp b/src/blackcore/db/databaseutils.cpp index 322be0c94..0b8de9978 100644 --- a/src/blackcore/db/databaseutils.cpp +++ b/src/blackcore/db/databaseutils.cpp @@ -513,5 +513,23 @@ namespace BlackCore textPartDebug.setBody(QString("ECLIPSE_DBGP").toUtf8()); return textPartDebug; } + + ChangedAutoPublishData CDatabaseUtils::autoPublishDataChanged(const QString &modelString, const PhysicalQuantities::CLength &cg, const CSimulatorInfo &simulator) + { + ChangedAutoPublishData changed; + if (!sApp || sApp->isShuttingDown() || !sApp->getWebDataServices()) { return changed; } + const CAircraftModel model = sApp->getWebDataServices()->getModelForModelString(modelString); + return CDatabaseUtils::autoPublishDataChanged(model, cg, simulator); + } + + ChangedAutoPublishData CDatabaseUtils::autoPublishDataChanged(const CAircraftModel &model, const PhysicalQuantities::CLength &cg, const CSimulatorInfo &simulator) + { + ChangedAutoPublishData changed; + changed.modelKnown = model.hasValidDbKey(); + if (!changed.modelKnown) { return changed; } + changed.changedCG = !(cg == model.getCG()); + changed.changedSim = !(model.getSimulator().matchesAll(simulator)); + return changed; + } } // ns } // ns diff --git a/src/blackcore/db/databaseutils.h b/src/blackcore/db/databaseutils.h index 1553da076..adbac9ad7 100644 --- a/src/blackcore/db/databaseutils.h +++ b/src/blackcore/db/databaseutils.h @@ -11,9 +11,11 @@ #ifndef BLACKCORE_DB_DATABASEUTILS_H #define BLACKCORE_DB_DATABASEUTILS_H -#include "blackcore/blackcoreexport.h" #include "blackcore/progress.h" +#include "blackcore/blackcoreexport.h" #include "blackmisc/simulation/aircraftmodel.h" +#include "blackmisc/simulation/autopublishdata.h" + #include #include #include @@ -108,6 +110,14 @@ namespace BlackCore //! Multipart with DEBUG FLAG for server static QHttpPart getMultipartWithDebugFlag(); + + //! Which auto-publish data did change? + //! \sa CAutoPublishData::analyzeAgainstDBData + static BlackMisc::Simulation::ChangedAutoPublishData autoPublishDataChanged(const QString &modelString, const BlackMisc::PhysicalQuantities::CLength &cg, const BlackMisc::Simulation::CSimulatorInfo &simulator); + + //! Which auto-publish data did change? + //! \sa CAutoPublishData::analyzeAgainstDBData + static BlackMisc::Simulation::ChangedAutoPublishData autoPublishDataChanged(const BlackMisc::Simulation::CAircraftModel &model, const BlackMisc::PhysicalQuantities::CLength &cg, const BlackMisc::Simulation::CSimulatorInfo &simulator); }; } // ns } // ns diff --git a/src/blackmisc/simulation/autopublishdata.h b/src/blackmisc/simulation/autopublishdata.h index eda966553..77d74b8b8 100644 --- a/src/blackmisc/simulation/autopublishdata.h +++ b/src/blackmisc/simulation/autopublishdata.h @@ -42,6 +42,22 @@ namespace BlackMisc }; } + //! Which data have changed + struct ChangedAutoPublishData + { + bool modelKnown = false; //!< model known in DB + bool changedCG = false; //!< CG changed + bool changedSim = false; //!< simulator changed + + //! Set all to true; + void setAllTrue() + { + modelKnown = true; + changedCG = true; + changedSim = true; + } + }; + //! Objects that can be use for auto-publishing. //! Auto publishing means we sent those data to the DB. class BLACKMISC_EXPORT CAutoPublishData