monitor/ScStwMonitorSrc/sources/scstwmonitorbackend.cpp
2020-05-22 19:32:57 +02:00

55 lines
1.7 KiB
C++

#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;
}