Just Intonation  Version 1.3.0 (18)
Explore scale-independent dynamically adapting tuning in just intonation
threadbase.cpp
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 #include "threadbase.h"
25 
26 #include <QDebug>
27 
28 //-----------------------------------------------------------------------------
29 // Constructor
30 //-----------------------------------------------------------------------------
34 
36  : mThreadWorker(this)
37  , mSuspended(false)
38 {
39 }
40 
41 
42 //-----------------------------------------------------------------------------
43 // Destructor
44 //-----------------------------------------------------------------------------
48 
50 { stop(); }
51 
52 
53 //-----------------------------------------------------------------------------
54 // Start thread
55 //-----------------------------------------------------------------------------
63 
65 {
67  return mThreadWorker.start();
68 }
69 
70 
71 //-----------------------------------------------------------------------------
72 // Suspend
73 //-----------------------------------------------------------------------------
83 
85 {
86  emit mThreadWorker.stopTimer();
87  mSuspended = true;
88 }
89 
90 
91 //-----------------------------------------------------------------------------
92 // Resume
93 //-----------------------------------------------------------------------------
98 
100 {
101  emit mThreadWorker.startTimer();
102  mSuspended = false;
103 }
104 
105 
106 //----------------------------- Setter functions ------------------------------
107 
109 void ThreadBase::setPriority(const QThread::Priority p)
111 
113 void ThreadBase::setVerbosity(int verbosity)
114 { Log::setVerbosity(verbosity); mThreadWorker.setVerbosity(verbosity); }
115 
117 void ThreadBase::setTimerInterval(const int msec, const int firstMsec)
118 { mThreadWorker.setTimerInterval(msec,firstMsec); }
119 
121 void ThreadBase::setThreadName(const QString name)
122 { mThreadWorker.setThreadName(name); }
123 
124 
125 //------------------------------- Getter functions ----------------------------
126 
129 { return mThreadWorker.isInterruptionRequested(); }
130 
133 { return mThreadWorker.getThreadName(); }
134 
137 { return mThreadWorker.isRunning() and not mSuspended; }
138 
139 
140 //-----------------------------------------------------------------------------
141 // Stop thread
142 //-----------------------------------------------------------------------------
151 
153 {
154  mSuspended = false;
155  return mThreadWorker.stop();
156 }
157 
158 
159 //-----------------------------------------------------------------------------
160 // Private slot: timeout
161 //-----------------------------------------------------------------------------
168 
170 {
172 }
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
QString getThreadName() const
Helper function for debugging: Get the current thread id and time.
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
void setPriority(const QThread::Priority p)
Set thread priority.
Definition: threadbase.cpp:109
bool start()
Start thread and move base class to the new thread.
void setTimerInterval(const int msec, const int firstMsec)
Set timer interval in milliseconds.
ThreadWorker mThreadWorker
Instance of the worker.
Definition: threadbase.h:99
void setVerbosity(int verbosity)
Set verbosity level of messages.
Definition: threadbase.cpp:113
void setPriority(const QThread::Priority p)
Specify the priority of the thread.
virtual void resume()
Resume from the suspend mode.
Definition: threadbase.cpp:99
void setVerbosity(int verbosity)
Set the verbosity level of the class-specific messages.
Definition: log.cpp:107
virtual void timeout()
Private timeout slot called by the worker.
Definition: threadbase.cpp:169
ThreadBase()
Constructor.
Definition: threadbase.cpp:35
void setThreadName(const QString name)
Set thread name.
bool stop()
Send a request to the thread for termination.
~ThreadBase()
Destructor, stops the thread if it is still running.
Definition: threadbase.cpp:49
void stopTimer()
Helper signal for stopping the temporarily existing timer.
virtual bool start()
Start the thread.
Definition: threadbase.cpp:64
bool isInterruptionRequested() const
Return true if the thread was requested to interrupt or terminate.
Definition: threadbase.cpp:128
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
void startTimer()
Helper signal for starting the temporarily existing timer.