mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-22 06:45:37 +08:00
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
38 lines
1.3 KiB
C++
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(owner, 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
|