mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-21 12:55:31 +08:00
Ref T105, modified background updater
* removed gracefulShutdown * removed isShuttingDown
This commit is contained in:
committed by
Mathew Sutcliffe
parent
7f3643fb0e
commit
2fbd2c6382
@@ -37,6 +37,7 @@ namespace BlackCore
|
|||||||
CContinuousWorker(owner, "Background data updater")
|
CContinuousWorker(owner, "Background data updater")
|
||||||
{
|
{
|
||||||
connect(&m_updateTimer, &QTimer::timeout, this, &CBackgroundDataUpdater::doWork);
|
connect(&m_updateTimer, &QTimer::timeout, this, &CBackgroundDataUpdater::doWork);
|
||||||
|
m_updateTimer.setObjectName(getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
void CBackgroundDataUpdater::initialize()
|
void CBackgroundDataUpdater::initialize()
|
||||||
@@ -47,42 +48,6 @@ namespace BlackCore
|
|||||||
void CBackgroundDataUpdater::cleanup()
|
void CBackgroundDataUpdater::cleanup()
|
||||||
{
|
{
|
||||||
m_updateTimer.stop();
|
m_updateTimer.stop();
|
||||||
m_shutdown = true;
|
|
||||||
m_enabled = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
CBackgroundDataUpdater::~CBackgroundDataUpdater()
|
|
||||||
{
|
|
||||||
gracefulShutdown();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool CBackgroundDataUpdater::isShuttingDown() const
|
|
||||||
{
|
|
||||||
if (!sApp) { return true; } // sApp object is gone, whole system shutdown
|
|
||||||
if (this->m_shutdown) { return true; } // marked as shutdown
|
|
||||||
if (this->isAbandoned()) { return true; } // worker abandoned
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool CBackgroundDataUpdater::isEnabled() const
|
|
||||||
{
|
|
||||||
return m_enabled;
|
|
||||||
}
|
|
||||||
|
|
||||||
void CBackgroundDataUpdater::gracefulShutdown()
|
|
||||||
{
|
|
||||||
m_shutdown = true;
|
|
||||||
m_enabled = false;
|
|
||||||
if (!CThreadUtils::isCurrentThreadObjectThread(this))
|
|
||||||
{
|
|
||||||
std::promise<void> promise;
|
|
||||||
doIfFinishedElse([&promise] { promise.set_value(); }, [&promise, this]
|
|
||||||
{
|
|
||||||
this->then([&promise] { promise.set_value(); });
|
|
||||||
this->abandon();
|
|
||||||
});
|
|
||||||
promise.get_future().wait();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CBackgroundDataUpdater::startUpdating(int updateTimeSecs)
|
void CBackgroundDataUpdater::startUpdating(int updateTimeSecs)
|
||||||
@@ -94,22 +59,21 @@ namespace BlackCore
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_enabled = updateTimeSecs > 0;
|
|
||||||
if (updateTimeSecs < 0)
|
if (updateTimeSecs < 0)
|
||||||
{
|
{
|
||||||
m_enabled = false;
|
setEnabled(false);
|
||||||
QTimer::singleShot(0, &m_updateTimer, &QTimer::stop);
|
QTimer::singleShot(0, &m_updateTimer, &QTimer::stop);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
m_enabled = true;
|
setEnabled(true);
|
||||||
m_updateTimer.start(1000 * updateTimeSecs);
|
m_updateTimer.start(1000 * updateTimeSecs);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CBackgroundDataUpdater::doWork()
|
void CBackgroundDataUpdater::doWork()
|
||||||
{
|
{
|
||||||
if (!this->entryCheck()) { return; }
|
if (!this->doWorkCheck()) { return; }
|
||||||
m_inWork = true;
|
m_inWork = true;
|
||||||
|
|
||||||
const int cycle = m_cycle;
|
const int cycle = m_cycle;
|
||||||
@@ -143,14 +107,14 @@ namespace BlackCore
|
|||||||
|
|
||||||
void CBackgroundDataUpdater::triggerInfoReads()
|
void CBackgroundDataUpdater::triggerInfoReads()
|
||||||
{
|
{
|
||||||
if (!this->entryCheck()) { return; }
|
if (!this->doWorkCheck()) { return; }
|
||||||
sApp->getWebDataServices()->triggerReadOfDbInfoObjects();
|
sApp->getWebDataServices()->triggerReadOfDbInfoObjects();
|
||||||
sApp->getWebDataServices()->triggerReadOfSharedInfoObjects();
|
sApp->getWebDataServices()->triggerReadOfSharedInfoObjects();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CBackgroundDataUpdater::syncModelOrModelSetCacheWithDbData(Simulation::Data::IMultiSimulatorModelCaches &cache)
|
void CBackgroundDataUpdater::syncModelOrModelSetCacheWithDbData(Simulation::Data::IMultiSimulatorModelCaches &cache)
|
||||||
{
|
{
|
||||||
if (!this->entryCheck()) { return; }
|
if (!this->doWorkCheck()) { return; }
|
||||||
const QDateTime cacheTs = sApp->getWebDataServices()->getCacheTimestamp(CEntityFlags::ModelEntity);
|
const QDateTime cacheTs = sApp->getWebDataServices()->getCacheTimestamp(CEntityFlags::ModelEntity);
|
||||||
if (!cacheTs.isValid()) { return; }
|
if (!cacheTs.isValid()) { return; }
|
||||||
|
|
||||||
@@ -169,7 +133,7 @@ namespace BlackCore
|
|||||||
const QSet<CSimulatorInfo> simSet = sims.asSingleSimulatorSet();
|
const QSet<CSimulatorInfo> simSet = sims.asSingleSimulatorSet();
|
||||||
for (const CSimulatorInfo &singleInfo : simSet)
|
for (const CSimulatorInfo &singleInfo : simSet)
|
||||||
{
|
{
|
||||||
if (this->isShuttingDown()) { return; }
|
if (!this->doWorkCheck()) { return; }
|
||||||
CAircraftModelList simModels = cache.getSynchronizedCachedModels(singleInfo);
|
CAircraftModelList simModels = cache.getSynchronizedCachedModels(singleInfo);
|
||||||
if (simModels.isEmpty()) { continue; }
|
if (simModels.isEmpty()) { continue; }
|
||||||
const CAircraftModelList dbModelsForSim = dbModels.matchesSimulator(singleInfo);
|
const CAircraftModelList dbModelsForSim = dbModels.matchesSimulator(singleInfo);
|
||||||
@@ -193,7 +157,7 @@ namespace BlackCore
|
|||||||
|
|
||||||
void CBackgroundDataUpdater::syncDbEntity(CEntityFlags::Entity entity) const
|
void CBackgroundDataUpdater::syncDbEntity(CEntityFlags::Entity entity) const
|
||||||
{
|
{
|
||||||
if (!this->entryCheck()) { return; }
|
if (!this->doWorkCheck()) { return; }
|
||||||
const QDateTime latestCacheTs = sApp->getWebDataServices()->getCacheTimestamp(entity);
|
const QDateTime latestCacheTs = sApp->getWebDataServices()->getCacheTimestamp(entity);
|
||||||
if (!latestCacheTs.isValid()) { return; }
|
if (!latestCacheTs.isValid()) { return; }
|
||||||
const QDateTime latestDbTs = sApp->getWebDataServices()->getLatestDbEntityTimestamp(entity);
|
const QDateTime latestDbTs = sApp->getWebDataServices()->getLatestDbEntityTimestamp(entity);
|
||||||
@@ -208,11 +172,10 @@ namespace BlackCore
|
|||||||
sApp->getWebDataServices()->triggerLoadingDirectlyFromDb(CEntityFlags::ModelEntity, latestCacheTs);
|
sApp->getWebDataServices()->triggerLoadingDirectlyFromDb(CEntityFlags::ModelEntity, latestCacheTs);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CBackgroundDataUpdater::entryCheck() const
|
bool CBackgroundDataUpdater::doWorkCheck() const
|
||||||
{
|
{
|
||||||
if (!sApp || !sApp->hasWebDataServices()) { return false; }
|
if (!sApp || !sApp->hasWebDataServices()) { return false; }
|
||||||
if (isShuttingDown()) { return false; }
|
if (!isEnabled()) { return false; }
|
||||||
if (!m_enabled) { return false; }
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} // ns
|
} // ns
|
||||||
|
|||||||
@@ -35,33 +35,17 @@ namespace BlackCore
|
|||||||
//! Constructor
|
//! Constructor
|
||||||
CBackgroundDataUpdater(QObject *owner);
|
CBackgroundDataUpdater(QObject *owner);
|
||||||
|
|
||||||
//! Destructor
|
//! Enable updates
|
||||||
virtual ~CBackgroundDataUpdater();
|
void startUpdating(int updateTimeSecs);
|
||||||
|
|
||||||
|
protected:
|
||||||
//! \copydoc BlackMisc::CContinuousWorker::initialize
|
//! \copydoc BlackMisc::CContinuousWorker::initialize
|
||||||
virtual void initialize() override;
|
virtual void initialize() override;
|
||||||
|
|
||||||
//! \copydoc BlackMisc::CContinuousWorker::cleanup
|
//! \copydoc BlackMisc::CContinuousWorker::cleanup
|
||||||
virtual void cleanup() override;
|
virtual void cleanup() override;
|
||||||
|
|
||||||
//! Is shutting down?
|
|
||||||
//! \threadsafe
|
|
||||||
bool isShuttingDown() const;
|
|
||||||
|
|
||||||
//! Enabled (running)?
|
|
||||||
//! \threadsafe
|
|
||||||
bool isEnabled() const;
|
|
||||||
|
|
||||||
//! Graceful shutdown
|
|
||||||
//! \threadsafe
|
|
||||||
void gracefulShutdown();
|
|
||||||
|
|
||||||
//! Enable updates
|
|
||||||
void startUpdating(int updateTimeSecs);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::atomic<bool> m_shutdown { false }; //!< marker it is shutting down
|
|
||||||
std::atomic<bool> m_enabled { false }; //!< marker it is enabled
|
|
||||||
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
|
||||||
QTimer m_updateTimer { this };
|
QTimer m_updateTimer { this };
|
||||||
@@ -83,7 +67,7 @@ namespace BlackCore
|
|||||||
void syncDbEntity(BlackMisc::Network::CEntityFlags::Entity entity) const;
|
void syncDbEntity(BlackMisc::Network::CEntityFlags::Entity entity) const;
|
||||||
|
|
||||||
//! Still enabled etc.
|
//! Still enabled etc.
|
||||||
bool entryCheck() const;
|
bool doWorkCheck() const;
|
||||||
};
|
};
|
||||||
} // ns
|
} // ns
|
||||||
} // ns
|
} // ns
|
||||||
|
|||||||
@@ -149,7 +149,7 @@ void CSwiftData::performGracefulShutdown()
|
|||||||
{
|
{
|
||||||
if (this->m_updater)
|
if (this->m_updater)
|
||||||
{
|
{
|
||||||
this->m_updater->gracefulShutdown();
|
this->m_updater->abandonAndWait();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -161,7 +161,7 @@ void CSwiftData::consolidationSettingChanged()
|
|||||||
if (m_updater)
|
if (m_updater)
|
||||||
{
|
{
|
||||||
ui->comp_MainInfoArea->getDataSettingsComponent()->setBackgroundUpdater(nullptr);
|
ui->comp_MainInfoArea->getDataSettingsComponent()->setBackgroundUpdater(nullptr);
|
||||||
m_updater->gracefulShutdown();
|
m_updater->abandonAndWait();
|
||||||
m_updater = nullptr;
|
m_updater = nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user