Files
pilotclient/src/core/threadedreaderperiodic.cpp
Lars Toenning 5004db1885 refactor: Use composition for update time
The timer is not required by all classes and the deep inheritance makes
it hard to see where it is actually used. Use composition instead.
2025-06-10 21:39:52 +02:00

38 lines
1.3 KiB
C++

// SPDX-FileCopyrightText: Copyright (C) 2025 swift Project Community / Contributors
// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
#include "core/threadedreaderperiodic.h"
namespace swift::core
{
CThreadedReaderPeriodic::CThreadedReaderPeriodic(QObject *owner, const QString &name)
: CThreadedReader(owner, name), m_updateTimer(this, name, true)
{
connect(&m_updateTimer, &misc::CThreadedTimer::timeout, this, &CThreadedReaderPeriodic::doWork);
}
void CThreadedReaderPeriodic::startReader()
{
Q_ASSERT_X(hasStarted(), Q_FUNC_INFO, "Thread was not started yet!");
QTimer::singleShot(m_initialTime.load(), this, [=] { this->doWork(); });
}
void CThreadedReaderPeriodic::setInitialAndPeriodicTime(std::chrono::milliseconds initialTime,
std::chrono::milliseconds periodicTime)
{
m_initialTime = initialTime;
m_periodicTime = periodicTime;
}
void CThreadedReaderPeriodic::doWork()
{
if (!doWorkCheck()) { return; }
this->doWorkImpl();
using namespace std::chrono_literals;
Q_ASSERT(m_periodicTime.load() > 0ms);
m_updateTimer.startTimer(m_periodicTime); // restart
}
} // namespace swift::core