Files
pilotclient/src/blackcore/db/backgrounddataupdater.h
Klaus Basan 106ef6709e Ref T285, Ref T292 improved background updater
* use atomic members (precaution)
* refactoring
2018-07-27 23:31:29 +02:00

92 lines
3.4 KiB
C++

/* 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/network/entityflags.h"
#include "blackmisc/simulation/data/modelcaches.h"
#include "blackmisc/statusmessagelist.h"
#include "blackmisc/worker.h"
#include <QMap>
#include <QReadWriteLock>
#include <atomic>
namespace BlackCore
{
namespace Db
{
//! Update and consolidation of DB data
class BLACKCORE_EXPORT CBackgroundDataUpdater : public BlackMisc::CContinuousWorker
{
Q_OBJECT
public:
//! Log categories
static const BlackMisc::CLogCategoryList &getLogCategories();
//! Constructor
CBackgroundDataUpdater(QObject *owner);
//! The message history
//! \threadsafe
BlackMisc::CStatusMessageList getMessageHistory() const;
signals:
//! Consolidation
void consolidating(bool running);
private:
mutable QReadWriteLock m_lockMsg; //!< lock snapshot
std::atomic_int m_cycle { 0 }; //!< cycle
std::atomic_bool m_inWork { false }; //!< indicates a running update
std::atomic_bool m_updatePublishedModels { true }; //!< update when models have been updated
QMap<QString, QDateTime> m_syncedModelsLatestChange; //! timestamp per cache when last synced
BlackMisc::CStatusMessageList m_messageHistory;
// set/caches as member as we are in own thread, central instance will not work
BlackMisc::Simulation::Data::CModelCaches m_modelCaches { false, this };
BlackMisc::Simulation::Data::CModelSetCaches m_modelSets { false, this };
//! Do the update checks
void doWork();
//! Read of new DB data
void triggerInfoReads();
//! Sync the model cache, normally model set or simulator models cache
//! \param modelSetFlag true means model set, false means model cach
//! \param dbModelsConsidered if no DB models are passed all DB models are used
void syncModelOrModelSetCacheWithDbData(bool modelSetFlag, const BlackMisc::Simulation::CAircraftModelList &dbModelsConsidered = {});
//! Sync DB entity
void syncDbEntity(BlackMisc::Network::CEntityFlags::Entity entity);
//! Still enabled etc.
bool doWorkCheck() const;
//! Models have been published
void onModelsPublished(const BlackMisc::Simulation::CAircraftModelList &modelsPublished, bool directWrite);
//! Model or model set instance
BlackMisc::Simulation::Data::IMultiSimulatorModelCaches &modelCaches(bool modelSetFlag);
//! Add history message
//! \threadsafe
void addHistory(const BlackMisc::CStatusMessage &msg);
};
} // ns
} // ns
#endif // guard