14 using namespace swift::misc::network;
15 using namespace swift::misc::simulation::data;
17 namespace swift::misc::simulation
25 CBackgroundValidation::CBackgroundValidation(
QObject *owner)
26 :
CContinuousWorker(owner,
"Background validation"), m_updateTimer(this,
"Background validation")
35 m_simulator = simulator;
36 m_simDirectory = simDirectory;
37 m_modelDirList = modelDirList;
43 return m_checkedSimulatorMsgs.contains(simulator);
49 m_checkedSimulatorMsgs.remove(simulator);
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;
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);
100 Q_ASSERT_X(this->
hasStarted(), Q_FUNC_INFO,
"Worker not started yet");
110 void CBackgroundValidation::doWork()
112 if (m_inWork) {
return; }
117 CAircraftModelList valid;
118 CAircraftModelList invalid;
121 bool onlyErrorsAndWarnings =
false;
124 m_wasStopped =
false;
127 if (!simulator.isSingleSimulator()) {
break; }
130 const CAircraftMatcherSetup setup = m_matchingSettings.get();
131 if (!setup.doVerificationAtStartup()) {
break; }
133 onlyErrorsAndWarnings = setup.onlyShowVerificationWarningsAndErrors();
134 const CAircraftModelList models = m_modelSets.
getCachedModels(simulator);
138 if (models.isEmpty())
142 QStringLiteral(
"No models in set for '%1'").arg(simulator.toQString(
true))));
147 m_wasStopped, m_simDirectory);
150 const qint64 deltaTimeMs = now - started;
152 QStringLiteral(
"Validated in %1ms").arg(deltaTimeMs)));
157 m_lastResultValid = valid;
158 m_lastResultInvalid = invalid;
159 m_lastResultWasStopped = m_wasStopped;
160 m_lastResultSimulator = simulator;
161 m_lastResultMsgs = msgs;
162 m_checkedSimulatorMsgs.insert(simulator, msgs);
172 if (m_timerBasedRuns > 3) { m_updateTimer.
stopTimer(); }
179 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.
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 stopTimer()
Safely stop update time.
void startTimer(std::chrono::milliseconds ms)
Start updating (start timer)
void timeout()
Timer timed out.
bool hasStarted() const
True if the worker has started.
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 startUpdating(std::chrono::milliseconds ms)
Start the updating timer.
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.
qint64 currentMSecsSinceEpoch()
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
QObject * sender() const const