Ref T28, background updater: consolidate DB and model data in background

* automatically reload DB data
* consolidate models with DB data
This commit is contained in:
Klaus Basan
2017-05-03 02:22:37 +02:00
committed by Mathew Sutcliffe
parent 6a96913974
commit f12b69bb87
3 changed files with 309 additions and 0 deletions

View File

@@ -0,0 +1,84 @@
/* Copyright (C) 2017
* swift project Community / Contributors
*
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
* including this file, may be copied, modified, propagated, or distributed except according to the terms
* contained in the LICENSE file.
*/
//! \file
#ifndef BLACKCORE_DB_BACKGROUNDDATAUPDATER_H
#define BLACKCORE_DB_BACKGROUNDDATAUPDATER_H
#include "blackcore/data/dbcaches.h"
#include "blackcore/blackcoreexport.h"
#include "blackmisc/simulation/data/modelcaches.h"
#include "blackmisc/network/entityflags.h"
#include "blackmisc/worker.h"
#include <QMap>
namespace BlackCore
{
namespace Db
{
/**
* Update and consolidation of DB data
*/
class BLACKCORE_EXPORT CBackgroundDataUpdater : public BlackMisc::CContinuousWorker
{
public:
//! Log categories
static const BlackMisc::CLogCategoryList &getLogCategories();
//! Constructor
CBackgroundDataUpdater(QObject *owner);
//! Destructor
virtual ~CBackgroundDataUpdater();
//! 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:
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
bool m_inWork = false; //!< indicates a running update
QTimer m_updateTimer { this };
BlackMisc::Simulation::Data::CModelCaches m_modelCaches { false, this }; //!< caches
BlackMisc::Simulation::Data::CModelSetCaches m_modelSetCaches { false, this }; //!< caches
QMap<QString, QDateTime> m_dbModelsLatestChange;
//! Do the udpate checks
void doWork();
//! Read of new DB data
void triggerInfoReads();
//! Sync the model cache
void syncModelOrModelSetCacheWithDbData(BlackMisc::Simulation::Data::IMultiSimulatorModelCaches &cache);
//! Sync DB entity
void syncDbEntity(BlackMisc::Network::CEntityFlags::Entity entity) const;
//! Still enabled etc.
bool entryCheck() const;
};
} // ns
} // ns
#endif // guard