swift
backgroundvalidation.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (C) 2019 swift Project Community / Contributors
2 // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3 
5 
6 #ifndef SWIFT_MISC_SIMULATION_BACKGROUNDVALIDATION_H
7 #define SWIFT_MISC_SIMULATION_BACKGROUNDVALIDATION_H
8 
9 #include <atomic>
10 
11 #include <QMap>
12 #include <QReadWriteLock>
13 
15 #include "misc/settingscache.h"
18 #include "misc/statusmessagelist.h"
19 #include "misc/swiftmiscexport.h"
20 #include "misc/threadedtimer.h"
21 #include "misc/worker.h"
22 
23 namespace swift::misc::simulation
24 {
27  {
28  Q_OBJECT
29 
30  public:
32  static const QStringList &getLogCategories();
33 
35  CBackgroundValidation(QObject *owner);
36 
39  void setCurrentSimulator(const CSimulatorInfo &simulator, const QString &simDirectory,
40  const QStringList &modelDirList);
41 
44  bool wasAlreadyChecked(const CSimulatorInfo &simulator) const;
45 
48  bool isValidating() const { return m_inWork; }
49 
52  void resetAlreadyChecked(const CSimulatorInfo &simulator);
53 
56  swift::misc::simulation::CSimulatorInfo getCurrentSimulator() const;
57 
60  bool triggerValidation(const CSimulatorInfo &simulator, const QString &simDirectory);
61 
65  bool requestLastValidationResults();
66 
69  void startUpdating(std::chrono::milliseconds ms);
70 
71  signals:
73  void validating(bool running);
74 
76  void validated(const CSimulatorInfo &simulator, const CAircraftModelList &validModels,
77  const CAircraftModelList &invalidModels, bool stopped, const CStatusMessageList &msgs);
78 
79  protected:
81  virtual void beforeQuit() noexcept override;
82 
83  private:
84  mutable QReadWriteLock m_lock;
85  std::atomic_bool m_inWork { false };
86  std::atomic_bool m_wasStopped { false };
87  CSimulatorInfo m_simulator;
88  QString m_simDirectory;
89  QStringList m_modelDirList;
90  // last result values, mostly needed when running in the distributed swift system and we want to get the values
91  CAircraftModelList m_lastResultValid;
92  CAircraftModelList m_lastResultInvalid;
93  CSimulatorInfo m_lastResultSimulator;
94  CStatusMessageList m_lastResultMsgs;
95  bool m_lastResultWasStopped = false;
96  std::atomic_int m_timerBasedRuns { 0 };
97 
98  QMap<CSimulatorInfo, CStatusMessageList> m_checkedSimulatorMsgs;
99  CSetting<settings::TModelMatching> m_matchingSettings { this };
100 
101  // Set/caches as member as we are in own thread, central instance will not work
102  data::CModelSetCaches m_modelSets { false, this };
103 
104  CThreadedTimer m_updateTimer;
105 
107  void doWork();
108  };
109 } // namespace swift::misc::simulation
110 #endif // SWIFT_MISC_SIMULATION_BACKGROUNDVALIDATION_H
Base class for a long-lived worker object which lives in its own thread.
Definition: worker.h:299
Status messages, e.g. from Core -> GUI.
Value object encapsulating a list of aircraft models.
Validate model files from the sets and check if the model still exists.
void validating(bool running)
Validating.
bool isValidating() const
Validation in progress.
void validated(const CSimulatorInfo &simulator, const CAircraftModelList &validModels, const CAircraftModelList &invalidModels, bool stopped, const CStatusMessageList &msgs)
Validated for simulator.
Simple hardcoded info about the corresponding simulator.
Definition: simulatorinfo.h:41
#define SWIFT_MISC_EXPORT
Export a class or function from the library.