File indexing completed on 2024-04-21 14:50:37

0001 // SPDX-License-Identifier: LGPL-2.1-or-later
0002 //
0003 // SPDX-FileCopyrightText: 2009 Bastian Holst <bastianholst@gmx.de>
0004 //
0005 
0006 #ifndef MARBLE_ABSTRACTWORKERTHREAD_H
0007 #define MARBLE_ABSTRACTWORKERTHREAD_H
0008 
0009 // Marble
0010 #include "marble_export.h"
0011 
0012 // Qt
0013 #include <QThread>
0014 
0015 namespace Marble
0016 {
0017 
0018 class AbstractWorkerThreadPrivate;
0019 
0020 /**
0021  * The AbstractWorkerThread is a class written for small tasks that have to run
0022  * multiple times on different data asynchronously.
0023  * You should be able to use this class for many different tasks, but you'll have to
0024  * think about Multi-Threading additionally.
0025  * The AbstractWorkerThread runs the function work() as long as workAvailable()
0026  * returns true. If there is no work available for a longer time, the thread will
0027  * switch itself off. As a result you have to call ensureRunning() every time you
0028  * want something to be worked on. You'll probably want to call this in your
0029  * addSchedule() function.
0030  */
0031 class MARBLE_EXPORT AbstractWorkerThread : public QThread
0032 {
0033     Q_OBJECT
0034 
0035  public:
0036     explicit AbstractWorkerThread( QObject *parent = nullptr );
0037     ~AbstractWorkerThread() override;
0038 
0039     void ensureRunning();
0040 
0041  protected:
0042     virtual bool workAvailable() = 0;
0043     virtual void work() = 0;
0044 
0045     void run() override;
0046 
0047  private:
0048     AbstractWorkerThreadPrivate * const d;
0049 };
0050 
0051 }
0052 
0053 #endif