Developer Documentation
OpenFlipperThread Class Reference

Thread handling class for OpenFlipper. More...

#include <OpenFlipper/threads/OpenFlipperThread.hh>

Inheritance diagram for OpenFlipperThread:
DecimateThread LoadFromPluginThread


void startProcessingInternal ()
 start processing of a function More...

Public Member Functions

 OpenFlipperThread (QString _jobId)

Private Slots

void slotJobFinished ()
 job has finished More...

Private Attributes

 Internal job wrapper. More...
QString jobId_
 Id of the current job. More...
QSemaphore startup_
 Semaphore to control order of thread startup calls. More...

Advanced job processing

void run ()
 Main processing. More...
virtual void cancel ()
 Cancel the job. More...
QString jobId ()
 get JobId get the Id of the current Job
void slotCancel (QString _jobId)
 Cancel this job. More...
void state (QString _jobId, int _state)
 Tell core about job state. More...

Simple job processing

void startProcessing ()
 start processing More...
void function (const QString _jobId="")
 job function More...
void finished (QString _jobId)
 job done More...

Detailed Description

Thread handling class for OpenFlipper.

Instantiate this class in order to provide a thread to a plugin. Unless you don't need a specialized run() or cancel() function, it won't be necessary to reimplement this class. Just connect the signals for the thread to work properly.

Note: Updating GUI elements of the main window from within a thread which is not the main thread can cause unexpected crashes to OpenFlipper. This introduces some major limitations to the usage of threads in plugins. These include avoiding the creation of new objects and generally every function that produces logging messages.

The class should be used along with Process Interface

It is not necessary to derive from this class for most operations, but you can.

Definition at line 83 of file OpenFlipperThread.hh.

Member Function Documentation

void OpenFlipperThread::cancel ( )

Cancel the job.

Reimplement this function to correctly terminate your job. If your job is able to terminate correctly then you can reimplement this function and stop your process.

Reimplemented in DecimateThread.

Definition at line 101 of file

void OpenFlipperThread::finished ( QString  _jobId)

job done

This signal is emitted if your job has finished and should be used to tell the core that your job has finished.

void OpenFlipperThread::function ( const QString  _jobId = "")

job function

If you do not specialize the OpenFlipperThread, The function connected to this signal will be used as the processing function for your thread. When you call


You have connect one of your slot using

connect( OpenFlipperThread ,SIGNAL(function()),YourPlugin,SLOT(YourSlot(),Qt::DirectConnection) );

The default implementation will call your slot inside the new thread and the core will still respond.

The optional parameter contains the job's id. In some cases the function that is to be called needs the job's id for further processing (status updates, etc.)

void OpenFlipperThread::run ( void  )

Main processing.

Do not reimplement this function. Connect the function() signal with your running function. Use signal state() in order to inform the core about the job's current state.

Definition at line 68 of file

void OpenFlipperThread::slotCancel ( QString  _jobId)

Cancel this job.

Call this slot with the correct job id to abort processing This directly calls cancel() This is only useful when you derived from this class, as other jobs might not react on this slot

Definition at line 105 of file

void OpenFlipperThread::slotJobFinished ( )

job has finished

Called by the job wrapper, when the job is done.

Definition at line 111 of file

void OpenFlipperThread::startProcessing ( )

start processing

This function will start the actual processing of a job.

Definition at line 118 of file

void OpenFlipperThread::startProcessingInternal ( )

start processing of a function

This signal is used to start the process execution through the wrapper

void OpenFlipperThread::state ( QString  _jobId,
int  _state 

Tell core about job state.

Use this signal to inform core about the job's state if and only if the thread class inherits from OpenFlipperThread and the virtual run() function is overridden. In all other cases this signal won't be used and does not have to be connected to from within the plugins.

Member Data Documentation

OpenFlipperJob* OpenFlipperThread::job_

Internal job wrapper.

This wrapper is used to start slots inside the event queue of the current thread. All slots defined in the QThread object live in the callers thread(The main thread). All slots inside the wrapper live in the thread created by QThread. and therefore do not lock the main event loop

Definition at line 211 of file OpenFlipperThread.hh.

QString OpenFlipperThread::jobId_

Id of the current job.

This holds the id of the current job. Most functions only react if the correct id is passed to the function.

Definition at line 218 of file OpenFlipperThread.hh.

QSemaphore OpenFlipperThread::startup_

Semaphore to control order of thread startup calls.

This variable is used to control the order of thread startup calls. The Thread itself is started, and when it is up and running, the resource will be created. The core thread waits for this resource and afterwards starts execution of the threads processing function. Without this sync, the processing call of the main thread might get lost as the thread is not online and listening for the signal.

Definition at line 228 of file OpenFlipperThread.hh.

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