swift
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 
6 namespace swift::core
7 {
8  CThreadedReaderPeriodic::CThreadedReaderPeriodic(QObject *owner, const QString &name)
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->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()) { return; }
30  this->doWorkImpl();
31  using namespace std::chrono_literals;
32  Q_ASSERT(m_periodicTime.load() > 0ms);
33 
34  m_updateTimer.startTimer(m_periodicTime); // restart
35  }
36 
37 } // namespace swift::core
Support for threaded based reading and parsing tasks such as data files via http, or file system and ...
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.
bool hasStarted() const
True if the worker has started.
Definition: worker.h:182
Backend services of the swift project, like dealing with the network or the simulators.
Definition: actionbind.cpp:7
auto singleShot(int msec, QObject *target, F &&task)
Starts a single-shot timer which will call a task in the thread of the given object when it times out...
Definition: threadutils.h:30