swift
backgrounddataupdater.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (C) 2017 swift Project Community / Contributors
2 // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3 
5 
6 #ifndef SWIFT_CORE_DB_BACKGROUNDDATAUPDATER_H
7 #define SWIFT_CORE_DB_BACKGROUNDDATAUPDATER_H
8 
9 #include <atomic>
10 
11 #include <QMap>
12 #include <QReadWriteLock>
13 
14 #include "core/data/dbcaches.h"
15 #include "core/swiftcoreexport.h"
18 #include "misc/statusmessagelist.h"
19 #include "misc/threadedtimer.h"
20 #include "misc/worker.h"
21 
22 namespace swift::core::db
23 {
26  {
27  Q_OBJECT
28 
29  public:
31  static const QStringList &getLogCategories();
32 
34  CBackgroundDataUpdater(QObject *owner);
35 
38  swift::misc::CStatusMessageList getMessageHistory() const;
39 
42  void startUpdating(std::chrono::milliseconds ms);
43 
44  signals:
46  void consolidating(bool running);
47 
48  private:
49  mutable QReadWriteLock m_lockMsg;
50  std::atomic_int m_cycle { 0 };
51  std::atomic_bool m_inWork { false };
52  std::atomic_bool m_updatePublishedModels { true };
53  QMap<QString, QDateTime> m_syncedModelsLatestChange;
54  swift::misc::CStatusMessageList m_messageHistory;
55  misc::CThreadedTimer m_updateTimer;
56 
57  // set/caches as member as we are in own thread, central instance will not work
58  swift::misc::simulation::data::CModelCaches m_modelCaches { false, this };
59  swift::misc::simulation::data::CModelSetCaches m_modelSets { false, this };
60 
62  void doWork();
63 
65  void triggerInfoReads();
66 
70  void
71  syncModelOrModelSetCacheWithDbData(bool modelSetFlag,
72  const swift::misc::simulation::CAircraftModelList &dbModelsConsidered = {});
73 
75  void syncDbEntity(swift::misc::network::CEntityFlags::Entity entity);
76 
78  bool doWorkCheck() const;
79 
81  void onModelsPublished(const swift::misc::simulation::CAircraftModelList &modelsPublished, bool directWrite);
82 
84  swift::misc::simulation::data::IMultiSimulatorModelCaches &modelCaches(bool modelSetFlag);
85 
88  void addHistory(const swift::misc::CStatusMessage &msg);
89  };
90 } // namespace swift::core::db
91 #endif // SWIFT_CORE_DB_BACKGROUNDDATAUPDATER_H
Update and consolidation of DB data.
void consolidating(bool running)
Consolidation.
Base class for a long-lived worker object which lives in its own thread.
Definition: worker.h:299
Streamable status message, e.g.
Status messages, e.g. from Core -> GUI.
Thread-safe timer class.
Definition: threadedtimer.h:18
Value object encapsulating a list of aircraft models.
Bundle of caches for all simulators.
Definition: modelcaches.h:339
Bundle of caches for model sets of all simulators.
Definition: modelcaches.h:382
Cache for multiple simulators specified by CSimulatorInfo.
Definition: modelcaches.h:189
Classes interacting with the swift database (aka "datastore").
#define SWIFT_CORE_EXPORT
Export a class or function from the library.