mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-29 20:55:42 +08:00
Ref T118, background updater subscribes simplified published models signal
* direct consolidation after models have been published * renamed some syncModelOrModelSetCacheWithDbData variables
This commit is contained in:
@@ -9,6 +9,7 @@
|
|||||||
|
|
||||||
#include "backgrounddataupdater.h"
|
#include "backgrounddataupdater.h"
|
||||||
#include "blackcore/db/databaseutils.h"
|
#include "blackcore/db/databaseutils.h"
|
||||||
|
#include "blackcore/db/databasewriter.h"
|
||||||
#include "blackcore/application.h"
|
#include "blackcore/application.h"
|
||||||
#include "blackcore/webdataservices.h"
|
#include "blackcore/webdataservices.h"
|
||||||
#include "blackmisc/simulation/aircraftmodellist.h"
|
#include "blackmisc/simulation/aircraftmodellist.h"
|
||||||
@@ -38,6 +39,10 @@ namespace BlackCore
|
|||||||
{
|
{
|
||||||
connect(&m_updateTimer, &QTimer::timeout, this, &CBackgroundDataUpdater::doWork);
|
connect(&m_updateTimer, &QTimer::timeout, this, &CBackgroundDataUpdater::doWork);
|
||||||
m_updateTimer.setInterval(60 * 1000);
|
m_updateTimer.setInterval(60 * 1000);
|
||||||
|
if (sApp && sApp->hasWebDataServices())
|
||||||
|
{
|
||||||
|
connect(sApp->getWebDataServices()->getDatabaseWriter(), &CDatabaseWriter::publishedModelsSimplified, this, &CBackgroundDataUpdater::onModelsPublished);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CBackgroundDataUpdater::doWork()
|
void CBackgroundDataUpdater::doWork()
|
||||||
@@ -83,20 +88,24 @@ namespace BlackCore
|
|||||||
sApp->getWebDataServices()->triggerReadOfSharedInfoObjects();
|
sApp->getWebDataServices()->triggerReadOfSharedInfoObjects();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CBackgroundDataUpdater::syncModelOrModelSetCacheWithDbData(Simulation::Data::IMultiSimulatorModelCaches &cache)
|
void CBackgroundDataUpdater::syncModelOrModelSetCacheWithDbData(IMultiSimulatorModelCaches &cache, const CAircraftModelList &dbModelsConsidered)
|
||||||
{
|
{
|
||||||
if (!this->doWorkCheck()) { return; }
|
if (!this->doWorkCheck()) { return; }
|
||||||
const QDateTime cacheTs = sApp->getWebDataServices()->getCacheTimestamp(CEntityFlags::ModelEntity);
|
const QDateTime latestDbModelsTs = dbModelsConsidered.isEmpty() ?
|
||||||
if (!cacheTs.isValid()) { return; }
|
sApp->getWebDataServices()->getCacheTimestamp(CEntityFlags::ModelEntity) :
|
||||||
|
dbModelsConsidered.latestTimestamp();
|
||||||
|
if (!latestDbModelsTs.isValid()) { return; }
|
||||||
|
|
||||||
QDateTime dbModelsLatestChange = m_dbModelsLatestChange.value(cache.getDescription());
|
const QDateTime dbModelsLatestSync = m_syncedModelsLatestChange.value(cache.getDescription());
|
||||||
if (dbModelsLatestChange.isValid() && dbModelsLatestChange <= cacheTs) { return; }
|
if (dbModelsLatestSync.isValid() && latestDbModelsTs <= dbModelsLatestSync) { return; }
|
||||||
|
|
||||||
m_dbModelsLatestChange[cache.getDescription()] = cacheTs;
|
m_syncedModelsLatestChange[cache.getDescription()] = latestDbModelsTs;
|
||||||
const CSimulatorInfo sims = cache.simulatorsWithInitializedCache(); // sims ever used
|
const CSimulatorInfo sims = cache.simulatorsWithInitializedCache(); // sims ever used
|
||||||
if (sims.isNoSimulator()) { return; }
|
if (sims.isNoSimulator()) { return; }
|
||||||
|
|
||||||
const CAircraftModelList dbModels = sApp->getWebDataServices()->getModels();
|
const CAircraftModelList dbModels = dbModelsConsidered.isEmpty() ?
|
||||||
|
sApp->getWebDataServices()->getModels() :
|
||||||
|
dbModelsConsidered;
|
||||||
if (dbModels.isEmpty()) { return; }
|
if (dbModels.isEmpty()) { return; }
|
||||||
const QSet<CSimulatorInfo> simSet = sims.asSingleSimulatorSet();
|
const QSet<CSimulatorInfo> simSet = sims.asSingleSimulatorSet();
|
||||||
for (const CSimulatorInfo &singleInfo : simSet)
|
for (const CSimulatorInfo &singleInfo : simSet)
|
||||||
@@ -117,9 +126,9 @@ namespace BlackCore
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
CLogMessage(this).info("Syncronize, no changes for '%1'") << singleInfo.convertToQString();
|
CLogMessage(this).info("Synchronized, no changes for '%1'") << singleInfo.convertToQString();
|
||||||
}
|
}
|
||||||
if (simSet.size() > 1) { CEventLoop::processEventsFor(5000); } // just give the system some time to relax, consolidate is time consuming
|
if (simSet.size() > 1) { CEventLoop::processEventsFor(5000); } // just give the system some time to relax, consolidation is time consuming
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -146,5 +155,17 @@ namespace BlackCore
|
|||||||
if (!isEnabled()) { return false; }
|
if (!isEnabled()) { return false; }
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CBackgroundDataUpdater::onModelsPublished(const CAircraftModelList &modelsPublished)
|
||||||
|
{
|
||||||
|
if (!this->doWorkCheck()) { return; }
|
||||||
|
if (modelsPublished.isEmpty()) { return; }
|
||||||
|
if (!m_updatePublishedModels) { return; }
|
||||||
|
|
||||||
|
emit this->consolidating(true);
|
||||||
|
this->syncModelOrModelSetCacheWithDbData(m_modelCaches, modelsPublished);
|
||||||
|
this->syncModelOrModelSetCacheWithDbData(m_modelSetCaches, modelsPublished);
|
||||||
|
emit this->consolidating(false);
|
||||||
|
}
|
||||||
} // ns
|
} // ns
|
||||||
} // ns
|
} // ns
|
||||||
|
|||||||
@@ -39,15 +39,16 @@ namespace BlackCore
|
|||||||
|
|
||||||
signals:
|
signals:
|
||||||
//! Consolidation
|
//! Consolidation
|
||||||
void consolidating(bool started);
|
void consolidating(bool running);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int m_cycle = 0; //!< cycle
|
int m_cycle = 0; //!< cycle
|
||||||
bool m_inWork = false; //!< indicates a running update
|
bool m_inWork = false; //!< indicates a running update
|
||||||
|
bool m_updatePublishedModels = true; //!< update when models have been updated
|
||||||
|
|
||||||
BlackMisc::Simulation::Data::CModelCaches m_modelCaches { false, this }; //!< caches
|
BlackMisc::Simulation::Data::CModelCaches m_modelCaches { false, this }; //!< caches
|
||||||
BlackMisc::Simulation::Data::CModelSetCaches m_modelSetCaches { false, this }; //!< caches
|
BlackMisc::Simulation::Data::CModelSetCaches m_modelSetCaches { false, this }; //!< caches
|
||||||
QMap<QString, QDateTime> m_dbModelsLatestChange;
|
QMap<QString, QDateTime> m_syncedModelsLatestChange; //! timestamp per cache
|
||||||
|
|
||||||
//! Do the update checks
|
//! Do the update checks
|
||||||
void doWork();
|
void doWork();
|
||||||
@@ -55,14 +56,18 @@ namespace BlackCore
|
|||||||
//! Read of new DB data
|
//! Read of new DB data
|
||||||
void triggerInfoReads();
|
void triggerInfoReads();
|
||||||
|
|
||||||
//! Sync the model cache
|
//! Sync the model cache, normally model set or simulator models cache
|
||||||
void syncModelOrModelSetCacheWithDbData(BlackMisc::Simulation::Data::IMultiSimulatorModelCaches &cache);
|
void syncModelOrModelSetCacheWithDbData(BlackMisc::Simulation::Data::IMultiSimulatorModelCaches &cache,
|
||||||
|
const BlackMisc::Simulation::CAircraftModelList &dbModelsConsidered = {});
|
||||||
|
|
||||||
//! Sync DB entity
|
//! Sync DB entity
|
||||||
void syncDbEntity(BlackMisc::Network::CEntityFlags::Entity entity) const;
|
void syncDbEntity(BlackMisc::Network::CEntityFlags::Entity entity) const;
|
||||||
|
|
||||||
//! Still enabled etc.
|
//! Still enabled etc.
|
||||||
bool doWorkCheck() const;
|
bool doWorkCheck() const;
|
||||||
|
|
||||||
|
//! Models have been published
|
||||||
|
void onModelsPublished(const BlackMisc::Simulation::CAircraftModelList &modelsPublished);
|
||||||
};
|
};
|
||||||
} // ns
|
} // ns
|
||||||
} // ns
|
} // ns
|
||||||
|
|||||||
Reference in New Issue
Block a user