14 using namespace swift::misc::network;
15 using namespace swift::misc::simulation::data;
17 namespace swift::misc::simulation
19 const QStringList &CBackgroundValidation::getLogCategories()
25 CBackgroundValidation::CBackgroundValidation(QObject *owner) :
CContinuousWorker(owner,
"Background validation")
27 connect(&
m_updateTimer, &QTimer::timeout,
this, &CBackgroundValidation::doWork);
32 const QStringList &modelDirList)
34 QWriteLocker l(&m_lock);
35 m_simulator = simulator;
36 m_simDirectory = simDirectory;
37 m_modelDirList = modelDirList;
42 QReadLocker l(&m_lock);
43 return m_checkedSimulatorMsgs.contains(simulator);
48 QWriteLocker l(&m_lock);
49 m_checkedSimulatorMsgs.remove(simulator);
54 QReadLocker l(&m_lock);
60 const QPointer<CBackgroundValidation> myself(
this);
64 QWriteLocker l(&m_lock);
65 if (m_inWork) {
return false; }
66 m_simulator = simulator;
67 m_simDirectory = simDirectory;
68 m_checkedSimulatorMsgs.remove(simulator);
71 if (!myself) {
return; }
84 bool wasStopped =
false;
86 QReadLocker l(&m_lock);
87 simulator = m_lastResultSimulator;
88 valid = m_lastResultValid;
89 invalid = m_lastResultInvalid;
90 msgs = m_lastResultMsgs;
91 wasStopped = m_lastResultWasStopped;
94 emit this->
validated(simulator, valid, invalid, wasStopped, msgs);
104 void CBackgroundValidation::doWork()
106 if (m_inWork) {
return; }
110 const bool isTimerBased = (QObject::sender() == &
m_updateTimer);
111 CAircraftModelList valid;
112 CAircraftModelList invalid;
115 bool onlyErrorsAndWarnings =
false;
117 const qint64 started = QDateTime::currentMSecsSinceEpoch();
118 m_wasStopped =
false;
121 if (!simulator.isSingleSimulator()) {
break; }
124 const CAircraftMatcherSetup setup = m_matchingSettings.get();
125 if (!setup.doVerificationAtStartup()) {
break; }
127 onlyErrorsAndWarnings = setup.onlyShowVerificationWarningsAndErrors();
128 const CAircraftModelList models = m_modelSets.
getCachedModels(simulator);
129 const qint64 now = QDateTime::currentMSecsSinceEpoch();
132 if (models.isEmpty())
136 QStringLiteral(
"No models in set for '%1'").arg(simulator.toQString(
true))));
141 m_wasStopped, m_simDirectory);
144 const qint64 deltaTimeMs = now - started;
146 QStringLiteral(
"Validated in %1ms").arg(deltaTimeMs)));
150 QWriteLocker l(&m_lock);
151 m_lastResultValid = valid;
152 m_lastResultInvalid = invalid;
153 m_lastResultWasStopped = m_wasStopped;
154 m_lastResultSimulator = simulator;
155 m_lastResultMsgs = msgs;
156 m_checkedSimulatorMsgs.insert(simulator, msgs);
173 if (e || !isTimerBased) { emit this->
validated(simulator, valid, invalid, m_wasStopped, msgs); }
Base class for a long-lived worker object which lives in its own thread.
QTimer m_updateTimer
timer which can be used by implementing classes
void stopUpdateTimer()
Safely stop update time.
static const QString & worker()
Background task.
static const QString & modelSetCache()
Model set cache.
void push_back(const T &value)
Appends an element at the end of the sequence.
constexpr static auto SeverityInfo
Status severities.
constexpr static auto SeverityWarning
Status severities.
Status messages, e.g. from Core -> GUI.
bool hasWarningOrErrorMessages() const
Warning or error messages.
void sortBySeverityHighestFirst()
Sort by severity, highest first.
void freezeOrder()
Current order of list will be new order values.
Value object encapsulating a list of aircraft models.
static CStatusMessageList validateModelFiles(const CSimulatorInfo &simulator, const CAircraftModelList &models, CAircraftModelList &validModels, CAircraftModelList &invalidModels, bool ignoreEmpty, int stopAtFailedFiles, std::atomic_bool &wasStopped, const QString &simulatorDir)
Validate aircraft.cfg entries.
bool wasAlreadyChecked(const CSimulatorInfo &simulator) const
Was already checked for simulator?
swift::misc::simulation::CSimulatorInfo getCurrentSimulator() const
Corresponding simulator.
void validating(bool running)
Validating.
bool requestLastValidationResults()
Request last results (again), if there are any.
void setCurrentSimulator(const CSimulatorInfo &simulator, const QString &simDirectory, const QStringList &modelDirList)
Corresponding simulator.
virtual void beforeQuit() noexcept
Called before quit is called.
void resetAlreadyChecked(const CSimulatorInfo &simulator)
Reset checked for simulator.
bool triggerValidation(const CSimulatorInfo &simulator, const QString &simDirectory)
Trigger a validation, returns false if "work 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.
bool isNoSimulator() const
No simulator?
bool isUnspecified() const
Unspecified simulator.
CAircraftModelList getCachedModels(const CSimulatorInfo &simulator) const
Models for simulator.
auto singleShot(int msec, QObject *target, F &&task)
Starts a single-shot timer which will call a task in the thread of the given object when it times out...