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

A class encapsulating a software loop. More...

#include <QDaqJob.h>

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

Public Slots

bool arm ()
 Arm the loop. More...
 
void disarm ()
 Disarm the loop.
 
QString stat ()
 Print loop statistics.
 
void createLoopEngine ()
 Create a dedicated QDaqScriptEngine. More...
 
- 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

void abort ()
 This is emitted if the loop aborts due to an error.
 
- Signals inherited from QDaqObject
void propertiesChanged ()
 Fired when object properties have changed.
 
void updateWidgets ()
 Fired when widgets need update.
 

Public Member Functions

bool isTop () const
 Return true if this is a top level loop.
 
QDaqLoopparentLoop () const
 Return the parent loop of this loop.
 
- Public Member Functions inherited from QDaqJob
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 exec ()
 Called when a loop is executed. More...
 
virtual bool arm_ ()
 Performs internal initialization for the job. More...
 
virtual void disarm_ ()
 Performs internal de-initialization. More...
 
- Protected Member Functions inherited from QDaqJob
bool setArmed (bool on)
 Arms or disarms a job. 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

uint count
 Number of executed loop cycles (read-only). More...
 
uint limit
 Total number of cycles to be executed. More...
 
uint delay
 Number of parent loop cycles before this loop is called. More...
 
uint preload
 Preload the internal counter. More...
 
uint period
 The repetition period in ms. More...
 
- Properties inherited from QDaqJob
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

- 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

A class encapsulating a software loop.

QDaqLoop is used to execute a number of child-jobs and/or child-loops.

By setting the class properties we can arrange for a number of different execution scenarios: repetitive with given period repeat for ever or for a given number of cycles skip execution every delay cycles single shot

A QDaqLoop that has no QDaqLoop ancestor is considered a "top level loop" (isTop() returns true). Otherwise the loop is a child-loop.

When arm() is called on a top level loop, a new QTimerThread is spawned that calls exec() at each timer repetition.

If arm() is called on a child loop, then it simply arms all child jobs. The exec() function of a child loop is called from the top level loop thread.

To use QDaqLoop, create the object and build underneath it a tree of child-jobs and child-loops that perform the required tasks in the correct order. Then attach the loop to the QDaq tree either as a child of the root object ("qdaq") or under another object that does not have a QDaqLoop anchestor. Thus the loop becomes top level.

Definition at line 285 of file QDaqJob.h.

Member Function Documentation

bool QDaqLoop::arm ( )
inlineslot

Arm the loop.

If this is a top level loop then this function starts the timer thread after succesfully arming all child jobs.

If it is a child loop then only the arming is done.

Returns
true if the loop is succesfully armed.

Definition at line 409 of file QDaqJob.h.

bool QDaqLoop::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 from QDaqJob.

Definition at line 288 of file QDaqJob.cpp.

void QDaqLoop::createLoopEngine ( )
slot

Create a dedicated QDaqScriptEngine.

The created script engine will be used for running script code of child jobs.

The created script engine lives executes code within the loop timer thread.

All child jobs can obtain a pointer to this engine with loopEngine().

Definition at line 378 of file QDaqJob.cpp.

void QDaqLoop::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 from QDaqJob.

Definition at line 306 of file QDaqJob.cpp.

bool QDaqLoop::exec ( )
protectedvirtual

Called when a loop is executed.

In a top level loop this function is called at each repetition of the timer thread.

In a child-loop exec() is called from the parent loop according to the order of the child-loop in the tree structure.

This function first locks the mutexes of all child jobs to prevent access from other threads. Then it calls QDaqJob::exec() which runs all child jobs. Finally it unlocks the mutexes in the reverse order as they were locked.

The signals updateWidgets() and propertiesChanged() are emitted at each valid repetition.

Returns

Reimplemented from QDaqJob.

Definition at line 242 of file QDaqJob.cpp.

Property Documentation

uint QDaqLoop::count
read

Number of executed loop cycles (read-only).

It is reset to 0 when the loop is armed.

Definition at line 292 of file QDaqJob.h.

uint QDaqLoop::delay
readwrite

Number of parent loop cycles before this loop is called.

The loop is executed every delay repetitions of the parent loop.

If delay is 0 or 1 then the loop is executed at each repetition.

Definition at line 305 of file QDaqJob.h.

uint QDaqLoop::limit
readwrite

Total number of cycles to be executed.

If limit is equal to 0 (default) then the loop runs indefinately.

Definition at line 297 of file QDaqJob.h.

uint QDaqLoop::period
readwrite

The repetition period in ms.

This is meaningful only for the top level loop.

Definition at line 317 of file QDaqJob.h.

uint QDaqLoop::preload
readwrite

Preload the internal counter.

Can be used in combination with delay to run loops out of phase.

Definition at line 312 of file QDaqJob.h.


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