KDE PIM / Developers / API Docs / libkdepim

KPIM::ThreadWeaver::Job Class Reference

A Job is a simple abstraction of an action that is to be executed in a thread context. More...

#include <weaver.h>

Inherits QObject.

List of all members.

Signals

Public Member Functions

Protected Member Functions

Protected Attributes


Detailed Description

A Job is a simple abstraction of an action that is to be executed in a thread context.

It is essential for the ThreadWeaver library that as a kind of convention, the different creators of Job objects do not touch the protected data members of the Job until somehow notified by the Job. See the SPR signal for an example.

Jobs may emit process requests as signals. Consider process requests as a kind of synchronized call to the main thread. Process Requests are a generic means for Job derivate programmers to have the jobs interact with the creators (in the main thread) during processing time. To avoid race conditions and extensive locking and unlocking, the thread executing the job is suspended during the period needed to process the request.

There are two kinds of process requests (we introduce abbreviations, also in the signal names and the code, only to save typing). Both are emitted by signals in the main thread:

Note: When using an APR, you better make sure to receive the signal with some object, otherwise the calling thread will block forever!


Constructor & Destructor Documentation

KPIM::ThreadWeaver::Job::Job QObject *  parent = 0,
const char *  name = 0
 

Construct a Job object.

KPIM::ThreadWeaver::Job::~Job  )  [virtual]
 

Destructor.


Member Function Documentation

void KPIM::ThreadWeaver::Job::execute Thread  )  [virtual]
 

Perform the job.

The thread in which this job is executed is given as a parameter. Do not overload this method to create your own Job implementation, overload run().

bool KPIM::ThreadWeaver::Job::isFinished  )  const [virtual]
 

Returns true if the jobs's execute method finished.

void KPIM::ThreadWeaver::Job::wakeAPR  ) 
 

Wake the thread after an APR has been processed.

void KPIM::ThreadWeaver::Job::processEvent Event  )  [virtual]
 

Process events related to this job (created by the processing thread or the weaver or whoever).

void KPIM::ThreadWeaver::Job::started  )  [signal]
 

This signal is emitted when a thread starts to process a job.

void KPIM::ThreadWeaver::Job::done  )  [signal]
 

This signal is emitted when a job has been finished.

void KPIM::ThreadWeaver::Job::SPR  )  [signal]
 

This signal is emitted when the job needs some operation done by the main thread (usually the creator of the job).

It is important to understand that the emitting thread is suspended until the signal returns. When the operation requested has been performed and this signal is finished, the thread is automatically waked. What operation needs to be performed has to be negotiated between the two objects. Note: This signal is an attempt to provide job programmers with a generic way to interact while the job is executed. I am interested in feedback about it's use.

void KPIM::ThreadWeaver::Job::APR  )  [signal]
 

Perform an Asynchronous Process Request.

See SPR and the generic Job documentation for a comparison.

void KPIM::ThreadWeaver::Job::lock  )  [protected]
 

Lock this Job's mutex.

void KPIM::ThreadWeaver::Job::unlock  )  [protected]
 

Unlock this Job's mutex.

virtual void KPIM::ThreadWeaver::Job::run  )  [protected, pure virtual]
 

The method that actually performs the job.

It is called from execute(). This method is the one to overload it with the job's task.

Thread * KPIM::ThreadWeaver::Job::thread  )  [protected]
 

Return the thread that executes this job.

Returns zero of the job is not currently executed.

void KPIM::ThreadWeaver::Job::setFinished bool  status  )  [protected, virtual]
 

Call with status = true to mark this job as done.

void KPIM::ThreadWeaver::Job::triggerSPR  )  [protected]
 

Trigger a SPR.

This emits a signal in the main thread indicating the necessity of a synchronized operation.

void KPIM::ThreadWeaver::Job::triggerAPR  )  [protected]
 

Trigger an APR.

This emit a signal in the main thread indicating the necessity of an unsynchronized operation. The calling thread needs to ensure to wake the thread when the operation is done.


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