This repository has been archived on 2024-06-03. You can view files and clone it, but cannot push or open issues or pull requests.
monitor/ScStwMonitorSrc/sources/scstwmonitorbackend.cpp

55 lines
1.7 KiB
C++
Raw Normal View History

#include "../headers/scstwmonitorbackend.h"
ScStwMonitorBackend::ScStwMonitorBackend(QObject *parent) : QObject(parent)
{
this->scStwClient = new ScStwClient();
this->remoteRace = new ScStwRemoteMonitorRace(this->scStwClient, this);
// init refresh timers
this->autoConnectRetryTimer = new QTimer(this);
this->autoConnectRetryTimer->setInterval(1000);
this->autoConnectRetryTimer->setSingleShot(true);
connect(this->autoConnectRetryTimer, &QTimer::timeout, this, &ScStwMonitorBackend::doConnectionAttempt);
this->autoConnectRetryTimer->start();
this->timerTextRefreshTimer = new QTimer(this);
this->timerTextRefreshTimer->setInterval(1);
this->timerTextRefreshTimer->setSingleShot(true);
this->timerTextRefreshTimer->connect(this->timerTextRefreshTimer, &QTimer::timeout, this, &ScStwMonitorBackend::refreshTimerText);
this->refreshTimerText();
}
void ScStwMonitorBackend::refreshTimerText() {
// --- refresh timer text ---
if(this->getRace()->getState() == ScStwRace::RUNNING) {
emit this->getRace()->timersChanged();
}
// --- refresh next start action delay progress ---
if(this->getRace()->getState() == ScStwRace::STARTING) {
emit this->getRace()->nextStartActionDetailsChanged();
}
this->timerTextRefreshTimer->start();
}
void ScStwMonitorBackend::doConnectionAttempt()
{
if(this->scStwClient->getState() == ScStwClient::DISCONNECTED) {
qDebug() << "+--- trying to connect";
this->scStwClient->connectToHost();
}
this->autoConnectRetryTimer->start();
}
ScStwRace* ScStwMonitorBackend::getRace() {
return this->remoteRace;
}
ScStwClient* ScStwMonitorBackend::getScStwClient() {
return this->scStwClient;
}