QDaq  0.2.6
Qt-based Data Aqcuisition
 All Classes Functions Variables Typedefs Enumerations Enumerator Properties Groups Pages
Public Member Functions | Protected Member Functions | Properties | List of all members
QDaqJob Class Reference

Base class for objects that perform a specific task reqursively. More...

#include <QDaqJob.h>

Inheritance diagram for QDaqJob:
Inheritance graph
[legend]
Collaboration diagram for QDaqJob:
Collaboration graph
[legend]

Public Member Functions

Q_INVOKABLE QDaqJob (const QString &name)
 QDaqJob constructor. More...
 
virtual void attach ()
 Attach this QDaqObject to the QDaq tree. More...
 
virtual void detach ()
 Detach this QDaqObject from the QDaq tree. More...
 
QDaqLooptopLoop () const
 Returns the top level loop that this job belongs to.
 
QDaqLooploop () const
 Returns the loop that this job belongs to.
 
virtual QDaqScriptEngine * loopEngine () const
 Returns the QDaqScriptEngine of the top level loop.
 
- Public Member Functions inherited from QDaqObject
Q_INVOKABLE QDaqObject (const QString &name)
 Construct a QDaqObject with a name. More...
 
bool isAttached () const
 Returns true is this object is attached to the QDaq tree.
 

Protected Member Functions

virtual bool arm_ ()
 Performs internal initialization for the job. More...
 
virtual void disarm_ ()
 Performs internal de-initialization. More...
 
bool setArmed (bool on)
 Arms or disarms a job. More...
 
virtual bool exec ()
 Called when the job is executed. More...
 
virtual bool run ()
 This function performs the actual task of this QDaqJob. More...
 
- Protected Member Functions inherited from QDaqObject
void pushError (const QString &type, const QString &descr=QString()) const
 Push an error in the error queue.
 
void throwScriptError (const QString &msg) const
 Throw a script error with message msg.
 
bool checkName (const QString &name) const
 Check if name is a legal name for an QDaqObject. More...
 
virtual void writeh5 (H5::Group *g, QDaqH5File *f) const
 Write contents of the object to a H5 group. More...
 
virtual void readh5 (H5::Group *g, QDaqH5File *f)
 Read contents of the object from a H5 group. More...
 

Properties

bool armed
 True if job is armed. More...
 
QString runCode
 Script code executed by the job at each repetition. More...
 
QString armCode
 Script code executed by the job in the arming face. More...
 
QString disarmCode
 Script code executed by the job in the dis-arming face. More...
 

Additional Inherited Members

- Public Slots inherited from QDaqObject
QString errorBacktrace (int maxItems=10) const
 Print a backtrace of recent errors in this QDaqObject.
 
QString path () const
 Return the object's path in the QDaq tree. More...
 
QString objectTree () const
 Output in a string the object hierarchy beneath this object.
 
QString listProperties () const
 List the objects properties.
 
QString listFunctions () const
 List the objects scriptable functions.
 
QDaqObjectparent () const
 
QDaqObjectList children () const
 Return a list of children of this object.
 
bool hasChildren () const
 Returns true if the object has children.
 
QDaqObjectappendChild (QDaqObject *obj)
 Adds a new child QDaqObject, as the last child and returns a pointer to it.
 
QDaqObjectinsertBefore (QDaqObject *newobj, QDaqObject *existingobj)
 Adds a new child QDaqObject, before an existing child and returns a pointer to it.
 
QDaqObjectclone ()
 Clone a QDaqObject with its child objects.
 
QDaqObjectremoveChild (QDaqObject *obj)
 Remove a child and return a pointer to it.
 
QDaqObjectreplaceChild (QDaqObject *newobj, QDaqObject *oldobj)
 Replace a child and return a pointer to the old child.
 
QDaqObjectfindChild (const QString &name) const
 Find the first child QDaqObject with objectName equal to name.
 
- Signals inherited from QDaqObject
void propertiesChanged ()
 Fired when object properties have changed.
 
void updateWidgets ()
 Fired when widgets need update.
 
- Static Public Member Functions inherited from QDaqObject
static QDaqRootroot ()
 Obtain a pointer to the one-and-only QDaqRoot object.
 
static QDaqObjectfromPath (const QString &path)
 Return a pointer to an object given its full path in the QDaq tree. More...
 
- Public Attributes inherited from QDaqObject
QMutex comm_lock
 A recursive mutex for synching thread access to this object.
 

Detailed Description

Base class for objects that perform a specific task reqursively.

Jobs can be organized as children of a parent-job or children of the super-class QDaqLoop.

When a QDaqLoop runs all its child jobs are executed by calling their exec() function. The exec() function first calls run() to perform the actual processing of this job (if there is any) and then calls exec() of each child job.

To give an example of the order that jobs are executed, the following job tree:

job0
 |--job1
 |   |--job11
 |   |--job12
 |--job2
 |--job3

will be executed with the following order: job0-job1-job11-job12-job2-job3

Before the job can perform its task it must be "armed". Arming does all the necessary initialization and is implemented in the function setArmed().

Definition at line 46 of file QDaqJob.h.

Constructor & Destructor Documentation

QDaqJob::QDaqJob ( const QString &  name)
explicit

QDaqJob constructor.

Parameters
nameThe QDaqObject name.

Definition at line 5 of file QDaqJob.cpp.

Member Function Documentation

bool QDaqJob::arm_ ( )
protectedvirtual

Performs internal initialization for the job.

It is called by the setArmed() function.

This function can be reimplemented to perform specific initialization for a job. The parent class arm_() function should be called afterwards.

In the default implementation, if a loopEngine() exists the script code is checked against the script engine for errors.

If initialization is sucessfull it returns true, otherwise the function returns false.

Reimplemented in QDaqLoop, QDaqChannel, and QDaqDevice.

Definition at line 55 of file QDaqJob.cpp.

void QDaqJob::attach ( )
virtual

Attach this QDaqObject to the QDaq tree.

This function is called when the object becomes part of the QDaq tree.

In the base class implementation this function signals the root object that a new QDaqObject has been inserted in the tree and then calls attach() for each child QDaqObject.

Subclasses may reimplement this function to perform specific initialization.

Reimplemented from QDaqObject.

Definition at line 12 of file QDaqJob.cpp.

void QDaqJob::detach ( )
virtual

Detach this QDaqObject from the QDaq tree.

This function is called just before the object becomes detached from the QDaq tree.

In the base class implementation it first calls detach() for each child QDaqObject and then signal root that the object is removed from the qdaq tree.

Subclasses may reimplement this function to perform needed actions before detaching.

Reimplemented from QDaqObject.

Reimplemented in QDaqChannel, and QDaqDevice.

Definition at line 16 of file QDaqJob.cpp.

void QDaqJob::disarm_ ( )
protectedvirtual

Performs internal de-initialization.

It is called by the setArmed() function.

Can be reimplemented to define special behavior during dis-arming. The parent class disarm_() should be called.

Reimplemented in QDaqLoop.

Definition at line 91 of file QDaqJob.cpp.

bool QDaqJob::exec ( )
protectedvirtual

Called when the job is executed.

If armed is false, the function does nothing.

If armed is true, then this job's run() is called and then the exec() of all sub-jobs.

The function is called by the parent loop's QDaqLoop::exec() function.

Returns
false if run() return false or some child-job returns false; true otherwise.

Reimplemented in QDaqLoop.

Definition at line 26 of file QDaqJob.cpp.

bool QDaqJob::run ( )
protectedvirtual

This function performs the actual task of this QDaqJob.

It can be reimplemented in subclasses to define the specific job that must be performed.

In the base implementation, it executes the script code if available.

Returns
false if a serious error occured, true otherwise.

Reimplemented in QDaqChannel, and QDaqDataBuffer.

Definition at line 38 of file QDaqJob.cpp.

bool QDaqJob::setArmed ( bool  on)
protected

Arms or disarms a job.

If on is true then setArmed() is called for each child-QDaqJob (not QDaqLoop) and finally arm_() is called to initialize this job. If any of those calls return false the arming is aborted and false is returned.

If on is false then disarm_() is called first and then setArmed() with parameter false is called for each child job.

This funtion is protected so that it cannot be called directly. QDaqJob objects are armed by their parent QDaqLoop, when calling QDaqLoop::arm().

Parameters
onIf true the job is armed otherwise it is disarmed.
Returns
true if the operation was sucesfull.

Definition at line 129 of file QDaqJob.cpp.

Property Documentation

QString QDaqJob::armCode
readwrite

Script code executed by the job in the arming face.

If code is empty then nothing will be executed.

The script code is executed in the root engine, in the main application thread.

Definition at line 79 of file QDaqJob.h.

bool QDaqJob::armed
read

True if job is armed.

An armed job is ready to run. If the armed QDaqJob belongs to a loop it will execute its task.

This property is read-only.

Definition at line 58 of file QDaqJob.h.

QString QDaqJob::disarmCode
readwrite

Script code executed by the job in the dis-arming face.

If code is empty then nothing will be executed.

The script code is executed in the root engine, in the main application thread.

Definition at line 89 of file QDaqJob.h.

QString QDaqJob::runCode
readwrite

Script code executed by the job at each repetition.

If code is empty then nothing will be executed.

The script code is executed by the top loop script engine, which is obtained by loopEngine(). This script engine lives in the top-loop thread.

Definition at line 69 of file QDaqJob.h.


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