Just Intonation  Version 1.3.1 (19)
Explore key-independent dynamically adapting tuning in just intonation
threadbase.h
Go to the documentation of this file.
1 /*****************************************************************************
2  * Copyright 2016-2017 Karolin Stange, Christoph Wick, and Haye Hinrichsen
3  *
4  * This file is part of JustIntonation.
5  *
6  * JustIntonation is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by the
8  * Free Software Foundation, either version 3 of the License, or (at your
9  * option) any later version.
10  *
11  * JustIntonation is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14  * for more details.
15  *
16  * You should have received a copy of the GNU General Public License along
17  * with JustIntonation. If not, see http://www.gnu.org/licenses/.
18  *****************************************************************************/
19 
20 //=============================================================================
21 // Thread base - a universal base class for threaded modules
22 //=============================================================================
23 
24 #ifndef THREADBASE_H
25 #define THREADBASE_H
26 
27 #include <QObject>
28 
29 #include "log.h"
30 #include "threadworker.h"
31 #include "shared.h"
32 
59 
60 class ThreadBase : public QObject, public Log
61 {
62  Q_OBJECT
63 public:
65  friend class ThreadWorker;
66 
67  ThreadBase();
68  ~ThreadBase();
69 
70  virtual bool init() { return true; }
71  virtual bool exit() { return true; }
72 
73  virtual bool start();
74  virtual bool stop();
75 
76  virtual void suspend();
77  virtual void resume();
78  bool isActive() const;
79  void setVerbosity (int verbosity);
81  QString getThreadName() const;
82 
83 protected:
85  virtual void initiallyCalledWorker() {}
87  virtual void finallyCalledWorker() {}
89  virtual void periodicallyCalledWorker() {}
90 
91  void setPriority (const QThread::Priority p);
92  void setTimerInterval (const int msec, const int firstMsec=0);
93  void setThreadName (const QString name);
94  bool isInterruptionRequested() const;
95 
96 private slots:
97  virtual void timeout();
98 private:
100  bool mSuspended;
101 };
102 
103 #endif // THREADBASE_H
void setTimerInterval(const int msec, const int firstMsec=0)
Set timer interval for the periodically called worker.
Definition: threadbase.cpp:117
bool isActive() const
Return true if thread is running and not suspended.
Definition: threadbase.cpp:136
QString getThreadName() const
Get thread name.
Definition: threadbase.cpp:132
Universal base class for threaded modules.
Definition: threadbase.h:60
virtual void periodicallyCalledWorker()
Virtual worker function called periodically from the timer.
Definition: threadbase.h:89
virtual void suspend()
Mark the thread as suspended.
Definition: threadbase.cpp:84
int getVerbosity()
Get the actual verbosity level.
Definition: log.cpp:118
void setPriority(const QThread::Priority p)
Set thread priority.
Definition: threadbase.cpp:109
virtual void finallyCalledWorker()
Virtual worker function called when the thread stops.
Definition: threadbase.h:87
virtual void initiallyCalledWorker()
Virtual worker function called when the thread is starting.
Definition: threadbase.h:85
int getVerbosity()
Get verbosity level.
Definition: threadbase.h:80
ThreadWorker mThreadWorker
Instance of the worker.
Definition: threadbase.h:99
void setVerbosity(int verbosity)
Set verbosity level of messages.
Definition: threadbase.cpp:113
virtual void resume()
Resume from the suspend mode.
Definition: threadbase.cpp:99
virtual bool init()
Virtual initialization function (no functionality here)
Definition: threadbase.h:70
virtual void timeout()
Private timeout slot called by the worker.
Definition: threadbase.cpp:169
ThreadBase()
Constructor.
Definition: threadbase.cpp:35
~ThreadBase()
Destructor, stops the thread if it is still running.
Definition: threadbase.cpp:49
virtual bool exit()
Virtual exit function (no functionality here)
Definition: threadbase.h:71
virtual bool start()
Start the thread.
Definition: threadbase.cpp:64
Helper class for ThreadBase.
Definition: threadworker.h:44
bool isInterruptionRequested() const
Return true if the thread was requested to interrupt or terminate.
Definition: threadbase.cpp:128
Base class for managing log messages.
Definition: log.h:83
void setThreadName(const QString name)
Set thread name (Linux only)
Definition: threadbase.cpp:121
virtual bool stop()
Stop the thread.
Definition: threadbase.cpp:152
bool mSuspended
Flag indicating suspended state.
Definition: threadbase.h:100