digiKam
dynamicthread.h
Go to the documentation of this file.
1 /* ============================================================
2  *
3  * This file is a part of digiKam project
4  * https://www.digikam.org
5  *
6  * Date : 2010-04-13
7  * Description : Dynamically active thread
8  *
9  * Copyright (C) 2010-2012 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de>
10  *
11  * This program is free software; you can redistribute it
12  * and/or modify it under the terms of the GNU General
13  * Public License as published by the Free Software Foundation;
14  * either version 2, or (at your option)
15  * any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU General Public License for more details.
21  *
22  * ============================================================ */
23 
24 #ifndef DIGIKAM_DYNAMIC_THREAD_H
25 #define DIGIKAM_DYNAMIC_THREAD_H
26 
27 // Qt includes
28 
29 #include <QObject>
30 #include <QThread>
31 #include <QRunnable>
32 #include <QMutex>
33 #include <QMutexLocker>
34 
35 // Local includes
36 
37 #include "digikam_export.h"
38 
39 namespace Digikam
40 {
41 
42 class DIGIKAM_EXPORT DynamicThread : public QObject
43 {
44  Q_OBJECT
45 
46 public:
47 
48  enum State
49  {
53  Deactivating
54  };
55 
56 public:
57 
62  explicit DynamicThread(QObject* const parent = nullptr);
63 
69  ~DynamicThread() override;
70 
74  virtual void run() = 0;
75 
76  State state() const;
77  bool isRunning() const;
78  bool isFinished() const;
79 
80  void setEmitSignals(bool emitThem);
81 
89  void setPriority(QThread::Priority priority);
90  QThread::Priority priority() const;
91 
92 public Q_SLOTS:
93 
94  void start();
95 
99  void stop();
100 
104  void wait();
105 
106 Q_SIGNALS:
107 
111  void starting();
112  void finished();
113 
114 protected:
115 
130  void shutDown();
131 
136  bool runningFlag() const volatile;
137 
145  QMutex* threadMutex() const;
146 
152 #if (QT_VERSION > QT_VERSION_CHECK(5, 99, 0))
153  void start(QMutexLocker<QMutex>& locker);
154  void stop(QMutexLocker<QMutex>& locker);
155  void wait(QMutexLocker<QMutex>& locker);
156 #else
157  void start(QMutexLocker& locker);
158  void stop(QMutexLocker& locker);
159  void wait(QMutexLocker& locker);
160 #endif
161 
162 private:
163 
164  // Disable
165  DynamicThread(const DynamicThread&) = delete;
166  DynamicThread& operator=(const DynamicThread&) = delete;
167 
168 private:
169 
170  friend class DynamicThreadPriv;
171 
172  class Private;
173  Private* const d;
174 };
175 
176 } // namespace Digikam
177 
178 #endif // DIGIKAM_DYNAMIC_THREAD_H
Definition: dynamicthread.h:43
virtual void run()=0
State
Definition: dynamicthread.h:49
@ Scheduled
Definition: dynamicthread.h:51
@ Running
Definition: dynamicthread.h:52
@ Inactive
Definition: dynamicthread.h:50
Definition: datefolderview.cpp:43