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/worker.h"
21 
22 namespace swift::misc::simulation
23 {
26  {
27  Q_OBJECT
28 
29  public:
31  static const QStringList &getLogCategories();
32 
34  CBackgroundValidation(QObject *owner);
35 
38  void setCurrentSimulator(const CSimulatorInfo &simulator, const QString &simDirectory,
39  const QStringList &modelDirList);
40 
43  bool wasAlreadyChecked(const CSimulatorInfo &simulator) const;
44 
47  bool isValidating() const { return m_inWork; }
48 
51  void resetAlreadyChecked(const CSimulatorInfo &simulator);
52 
55  swift::misc::simulation::CSimulatorInfo getCurrentSimulator() const;
56 
59  bool triggerValidation(const CSimulatorInfo &simulator, const QString &simDirectory);
60 
64  bool requestLastValidationResults();
65 
66  signals:
68  void validating(bool running);
69 
71  void validated(const CSimulatorInfo &simulator, const CAircraftModelList &validModels,
72  const CAircraftModelList &invalidModels, bool stopped, const CStatusMessageList &msgs);
73 
74  protected:
76  virtual void beforeQuit() noexcept override;
77 
78  private:
79  mutable QReadWriteLock m_lock;
80  std::atomic_bool m_inWork { false };
81  std::atomic_bool m_wasStopped { false };
82  CSimulatorInfo m_simulator;
83  QString m_simDirectory;
84  QStringList m_modelDirList;
85  // last result values, mostly needed when running in the distributed swift system and we want to get the values
86  CAircraftModelList m_lastResultValid;
87  CAircraftModelList m_lastResultInvalid;
88  CSimulatorInfo m_lastResultSimulator;
89  CStatusMessageList m_lastResultMsgs;
90  bool m_lastResultWasStopped = false;
91  std::atomic_int m_timerBasedRuns { 0 };
92 
93  QMap<CSimulatorInfo, CStatusMessageList> m_checkedSimulatorMsgs;
94  CSetting<settings::TModelMatching> m_matchingSettings { this };
95 
96  // Set/caches as member as we are in own thread, central instance will not work
97  data::CModelSetCaches m_modelSets { false, this };
98 
100  void doWork();
101  };
102 } // namespace swift::misc::simulation
103 #endif // SWIFT_MISC_SIMULATION_BACKGROUNDVALIDATION_H
Base class for a long-lived worker object which lives in its own thread.
Definition: worker.h:275
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.