OpenFlipperThread Class Reference

#include <OpenFlipperThread.hh>

Collaboration diagram for OpenFlipperThread:
Collaboration graph
[legend]

List of all members.

Signals

void startProcessingInternal ()
 start processing of a function

Public Member Functions

 OpenFlipperThread (QString _jobId)

Private Slots

void slotJobFinished ()
 job has finished

Private Attributes

OpenFlipperJobjob_
 Internal job wrapper.
QString jobId_
 Id of the current job.
QMutex startup_

Advanced job processing



virtual void run ()
 Main processing.
virtual void cancel ()
 Cancel the job.
void slotCancel (QString _jobId)
void state (QString _jobId, int _state)
 Tell core about job state.

Simple job processing



void startProcessing ()
 start processing
void function ()
 job function
void finished (QString _jobId)
 job done

Detailed Description

Instanciate 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.

The following code fragment shows a simple example of how to use this class from within a plugin:

OpenFlipperThread* myThread = new OpenFlipperThread("MyPluginsThread");

// Connect the appropriate signals
connect(myThread, SIGNAL(state(QString, int)), this, SIGNAL(setJobState(QString, int)));
connect(myThread, SIGNAL(finished(QString)),   this, SIGNAL(finishJob(QString)));
connect(myThread, SIGNAL(function()),          this, SLOT(myPluginsThreadFunction()), Qt::DirectConnection);

// Tell core about my thread
emit startJob( "MyPluginsThread", "Thread Description" , 0 , 100 , true);

// Start internal QThread
myThread->start();

// Start actual processing of job
myThread->startProcessing();

Definition at line 74 of file OpenFlipperThread.hh.


Member Function Documentation

void OpenFlipperThread::cancel (  )  [virtual]

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.

Definition at line 86 of file OpenFlipperThread.cc.

Referenced by slotCancel().

void OpenFlipperThread::finished ( QString  _jobId  )  [signal]

job done

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

Referenced by run(), and slotJobFinished().

void OpenFlipperThread::function (  )  [signal]

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 OpenFlipper::startProcessing();

If you want to provide more feedback (% of runtime) or cancel the job, you have to derive from OpenFlipperThread and emit the right signals.

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 given thread and the core will still respond. However you should only use this function if you Dont know how long your job takes. Or when you just want to keep the core responding.
Otherwise you should reimplement the run(), and cancel() function of OpenFlipperThread and emit the state signal.

Referenced by run().

void OpenFlipperThread::run (  )  [virtual]

Main processing.

Either reimplement this function or connect the function() signal.

Definition at line 49 of file OpenFlipperThread.cc.

References finished(), function(), job_, slotJobFinished(), and startProcessingInternal().

void OpenFlipperThread::slotCancel ( QString  _jobId  )  [slot]

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

Definition at line 90 of file OpenFlipperThread.cc.

References cancel(), and jobId_.

void OpenFlipperThread::slotJobFinished (  )  [private, slot]

job has finished

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

Definition at line 96 of file OpenFlipperThread.cc.

References finished(), and jobId_.

Referenced by run().

void OpenFlipperThread::startProcessing (  )  [slot]

start processing

This function will start the actuall processing of a job.

Definition at line 104 of file OpenFlipperThread.cc.

References startProcessingInternal().

void OpenFlipperThread::startProcessingInternal (  )  [signal]

start processing of a function

(INTERNAL!)
This signal is used to start the process execution through the wrapper

Referenced by run(), and startProcessing().

void OpenFlipperThread::state ( QString  _jobId,
int  _state 
) [signal]

Tell core about job state.

Emit this signal to tell the core about your job status. You have to create a new run function for this. In simple mode, this signal is not emitted at all!


Member Data Documentation

Internal job wrapper.

(INTERNAL!)
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 188 of file OpenFlipperThread.hh.

Referenced by run().

QString OpenFlipperThread::jobId_ [private]

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 195 of file OpenFlipperThread.hh.

Referenced by slotCancel(), and slotJobFinished().


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

acg pic Project OpenFlipper, ©  Computer Graphics Group, RWTH Aachen. Documentation generated using doxygen .