Just Intonation  Version 1.3.0 (18)
Explore scale-independent dynamically adapting tuning in just intonation
ThreadBase Class Reference

Universal base class for threaded modules. More...

#include <threadbase.h>

Inheritance diagram for ThreadBase:
Inheritance graph
Collaboration diagram for ThreadBase:
Collaboration graph

Public Member Functions

 ThreadBase ()
 Constructor. More...
 
 ~ThreadBase ()
 Destructor, stops the thread if it is still running. More...
 
virtual bool init ()
 Virtual initialization function (no functionality here) More...
 
virtual bool exit ()
 Virtual exit function (no functionality here) More...
 
virtual bool start ()
 Start the thread. More...
 
virtual bool stop ()
 Stop the thread. More...
 
virtual void suspend ()
 Mark the thread as suspended. More...
 
virtual void resume ()
 Resume from the suspend mode. More...
 
bool isActive () const
 Return true if thread is running and not suspended. More...
 
void setVerbosity (int verbosity)
 Set verbosity level of messages. More...
 
int getVerbosity ()
 Get verbosity level. More...
 
QString getThreadName () const
 Get thread name. More...
 

Protected Member Functions

virtual void initiallyCalledWorker ()
 Virtual worker function called when the thread is starting. More...
 
virtual void finallyCalledWorker ()
 Virtual worker function called when the thread stops. More...
 
virtual void periodicallyCalledWorker ()
 Virtual worker function called periodically from the timer. More...
 
void setPriority (const QThread::Priority p)
 Set thread priority. More...
 
void setTimerInterval (const int msec, const int firstMsec=0)
 Set timer interval for the periodically called worker. More...
 
void setThreadName (const QString name)
 Set thread name (Linux only) More...
 
bool isInterruptionRequested () const
 Return true if the thread was requested to interrupt or terminate. More...
 

Private Slots

virtual void timeout ()
 Private timeout slot called by the worker. More...
 

Private Attributes

ThreadWorker mThreadWorker
 Instance of the worker. More...
 
bool mSuspended
 Flag indicating suspended state. More...
 

Friends

class ThreadWorker
 Allow ThreadWorker to access the private elements of this class. More...
 

Detailed Description

Universal base class for threaded modules.

This wrapper class provides an easy way to run derived classes in an independent thread in an exec loop. It ensures that slots are automatically executed in the new thread.

Usage:

  • Optionally implemement init()/exit() functions (empty here)
  • Optionally extend the start()/stop() and suspend/resume functions
  • Implement signals and slots as usual There are three different worker functions which may be overloaded (empty here):
  • initiallyCalledWorker() called on start() in the new thread
  • finallyCalledWorker() called on stop() in the new thread
  • periodicallyCalledWorker() called on timeout in the new thread The latter requires that the timer is started by calling setTimerInterval(msec). You can also set the priority and the thread name.

Logic:

  • init/exit is like installing a component and establishing all its connections
  • start/stop is like on/off, starting the thread and stopping it
  • suspend/resume is like mute, the thread remains active
See also
ThreadWorker

Definition at line 60 of file threadbase.h.

Constructor & Destructor Documentation

ThreadBase::ThreadBase ( )

Constructor.

Definition at line 35 of file threadbase.cpp.

ThreadBase::~ThreadBase ( )

Destructor, stops the thread if it is still running.

Definition at line 49 of file threadbase.cpp.

Here is the call graph for this function:

Member Function Documentation

virtual bool ThreadBase::exit ( )
inlinevirtual

Virtual exit function (no functionality here)

Reimplemented in AudioOutput.

Definition at line 71 of file threadbase.h.

Here is the call graph for this function:

virtual void ThreadBase::finallyCalledWorker ( )
inlineprotectedvirtual

Virtual worker function called when the thread stops.

Reimplemented in Tuner, and AudioOutput.

Definition at line 87 of file threadbase.h.

QString ThreadBase::getThreadName ( ) const

Get thread name.

Definition at line 132 of file threadbase.cpp.

Here is the call graph for this function:

int ThreadBase::getVerbosity ( )
inline

Get verbosity level.

Definition at line 80 of file threadbase.h.

Here is the call graph for this function:

virtual bool ThreadBase::init ( )
inlinevirtual

Virtual initialization function (no functionality here)

Reimplemented in Tuner, AudioOutput, and SoundGenerator.

Definition at line 70 of file threadbase.h.

virtual void ThreadBase::initiallyCalledWorker ( )
inlineprotectedvirtual

Virtual worker function called when the thread is starting.

Reimplemented in Tuner, and AudioOutput.

Definition at line 85 of file threadbase.h.

bool ThreadBase::isActive ( ) const

Return true if thread is running and not suspended.

Definition at line 136 of file threadbase.cpp.

bool ThreadBase::isInterruptionRequested ( ) const
protected

Return true if the thread was requested to interrupt or terminate.

Definition at line 128 of file threadbase.cpp.

virtual void ThreadBase::periodicallyCalledWorker ( )
inlineprotectedvirtual

Virtual worker function called periodically from the timer.

Reimplemented in Tuner, and AudioDeviceGuard.

Definition at line 89 of file threadbase.h.

Here is the call graph for this function:

void ThreadBase::resume ( )
virtual

Resume from the suspend mode.

Restart the timer and clear the mSuspended flag

Reimplemented in MidiPlayer.

Definition at line 99 of file threadbase.cpp.

void ThreadBase::setPriority ( const QThread::Priority  p)
protected

Set thread priority.

Definition at line 109 of file threadbase.cpp.

Here is the call graph for this function:

void ThreadBase::setThreadName ( const QString  name)
protected

Set thread name (Linux only)

Definition at line 121 of file threadbase.cpp.

Here is the call graph for this function:

void ThreadBase::setTimerInterval ( const int  msec,
const int  firstMsec = 0 
)
protected

Set timer interval for the periodically called worker.

Definition at line 117 of file threadbase.cpp.

Here is the call graph for this function:

void ThreadBase::setVerbosity ( int  verbosity)

Set verbosity level of messages.

Definition at line 113 of file threadbase.cpp.

Here is the call graph for this function:

bool ThreadBase::start ( )
virtual

Start the thread.

Starts the thread. If the thread is suspended it will resume. If the thread is already started the function does nothing.

Returns
True on succes

Reimplemented in Tuner, and AudioOutput.

Definition at line 64 of file threadbase.cpp.

Here is the call graph for this function:

bool ThreadBase::stop ( )
virtual

Stop the thread.

Send a termination request to the execution loop. Wait for the thread to terminate. The active components of the thread should call isInterruptionRequested() and quit immediately if this function is true.

Returns
If the thread terminates regularly return true. If the thread does not terminate after a timeout of 2 secs return false.

Reimplemented in MidiPlayer, AudioOutput, and Instrument.

Definition at line 152 of file threadbase.cpp.

Here is the call graph for this function:

void ThreadBase::suspend ( )
virtual

Mark the thread as suspended.

Calling this function tells the thread that it has to wait in some sort of standby. Note that the thread itself is not terminated and that the event loop is still active. Calling this function stops the timer so that the periodicallyCalledWorker() is not active any more. In addition the mSuspended flag is set.

Reimplemented in MidiPlayer, and SoundGenerator.

Definition at line 84 of file threadbase.cpp.

void ThreadBase::timeout ( )
privatevirtualslot

Private timeout slot called by the worker.

This slot is called periodically by the timer of the worker. If the thread is not suspended it calles the user-defined virtual function periodicallyCalledWorker();

Definition at line 169 of file threadbase.cpp.

Here is the call graph for this function:

Friends And Related Function Documentation

friend class ThreadWorker
friend

Allow ThreadWorker to access the private elements of this class.

Definition at line 65 of file threadbase.h.

Member Data Documentation

bool ThreadBase::mSuspended
private

Flag indicating suspended state.

Definition at line 100 of file threadbase.h.

ThreadWorker ThreadBase::mThreadWorker
private

Instance of the worker.

Definition at line 99 of file threadbase.h.


The documentation for this class was generated from the following files: