swift
Loading...
Searching...
No Matches
threadedreaderperiodic.cpp
1// SPDX-FileCopyrightText: Copyright (C) 2025 swift Project Community / Contributors
2// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3
5
6namespace swift::core
7{
9 : CThreadedReader(owner, name), m_updateTimer(this, name, true)
10 {
11 connect(&m_updateTimer, &misc::CThreadedTimer::timeout, this, &CThreadedReaderPeriodic::doWork);
12 }
13
15 {
16 Q_ASSERT_X(hasStarted(), Q_FUNC_INFO, "Thread was not started yet!");
17 QTimer::singleShot(m_initialTime.load(), this, [=, this] { this->doWork(); });
18 }
19
20 void CThreadedReaderPeriodic::setInitialAndPeriodicTime(std::chrono::milliseconds initialTime,
21 std::chrono::milliseconds periodicTime)
22 {
23 m_initialTime = initialTime;
24 m_periodicTime = periodicTime;
25 }
26
27 void CThreadedReaderPeriodic::doWork()
28 {
29 if (!doWorkCheck())
30 {
31 return;
32 }
33 this->doWorkImpl();
34 using namespace std::chrono_literals;
35 Q_ASSERT(m_periodicTime.load() > 0ms);
36
37 m_updateTimer.startTimer(m_periodicTime); // restart
38 }
39
40} // namespace swift::core
CThreadedReader(const CThreadedReader &)=delete
Copy constructor.
bool doWorkCheck() const
Still enabled etc.?
CThreadedReaderPeriodic(QObject *owner, const QString &name)
Constructor.
virtual void doWorkImpl()=0
This method does the actual work in the derived class.
void setInitialAndPeriodicTime(std::chrono::milliseconds initialTime, std::chrono::milliseconds periodicTime)
Set initial and periodic times Changes only apply after the next time the timer restarts.
const QObject * owner() const
Owner of the worker.
Definition worker.h:352
void startTimer(std::chrono::milliseconds ms)
Start updating (start timer).
void timeout()
Timer timed out.
bool hasStarted() const
True if the worker has started.
Definition worker.h:200
Backend services of the swift project, like dealing with the network or the simulators.
Definition actionbind.cpp:7
QObject(QObject *parent)
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)