/**************************************************************************** ** ScStw Monitor ** Copyright (C) 2020 Itsblue development ** ** This program is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** ** This program is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. ** ** You should have received a copy of the GNU General Public License ** along with this program. If not, see . ****************************************************************************/ #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; }