Public Types | Public Member Functions | Private Attributes | List of all members
RTT::base::RunnableInterface Class Referenceabstract

A class for running a certain piece of code in a thread. More...

#include <RunnableInterface.hpp>

Inheritance diagram for RTT::base::RunnableInterface:
Inheritance graph
[legend]

Public Types

enum  WorkReason { TimeOut = 0, Trigger, IOReady }
 

Public Member Functions

virtual bool breakLoop ()
 
virtual void finalize ()=0
 
ActivityInterfacegetActivity () const
 Query for the task this interface is run in. More...
 
virtual os::ThreadInterfacegetThread () const
 
virtual bool hasWork ()
 
virtual bool initialize ()=0
 
virtual void loop ()
 
 RunnableInterface ()
 
virtual void setActivity (ActivityInterface *task)
 Set the task this interface is run in. More...
 
virtual void step ()=0
 
virtual void work (WorkReason reason)
 
virtual ~RunnableInterface ()
 

Private Attributes

ActivityInterfaceowner_act
 

Detailed Description

A class for running a certain piece of code in a thread.

It defines three methods which can execute functionality.

In a start-run-stop cycle, before step() is called the first time, initialize() will be called in the thread that started this RunnableInterface. When step() is ran the last time in this cycle, finalize() will be called, after it finishes, in the threaad that stopped this RunnableInterface.

A non periodic thread will call loop(), which indicates that the RunnableInterface is allowed to block ( step() is not allowed to block ). By default, loop() calls step(), but a subclass may override the loop() method to put its own blocking functionality in. To break out of the loop() method, reimplement breakLoop() such that loop() returns when breakLoop() is called.

The getActivity() method is guaranteed to return a valid task pointer during initialize(), step() or loop() and finalize(). This allows the RunnableInterface to query the task's period(icity) and ThreadInterface. Consequently, initialize() knows whether step() or loop() will be called ( depending on ActivityInterface::isPeriodic() ).

See also
ActivityInterface

Definition at line 69 of file RunnableInterface.hpp.

Member Enumeration Documentation

Enumerator
TimeOut 
Trigger 
IOReady 

Definition at line 76 of file RunnableInterface.hpp.

Constructor & Destructor Documentation

RunnableInterface::RunnableInterface ( )

Create a runnable object. The optional constructor parameter allows the object to attach directly to a thread. Otherwise, os::ThreadInterface::run(RunnableInterface*) must be used to attach this object to a thread. A thread can only run one RunnableInterface object, use CoreLib tasks otherwise.

Parameters
tThe thread this object must attach to.

Definition at line 58 of file CoreRunnableInterface.cpp.

RunnableInterface::~RunnableInterface ( )
virtual

Checks if this is still in a task and if so, issues a critical warning.

Definition at line 47 of file CoreRunnableInterface.cpp.

Member Function Documentation

bool RunnableInterface::breakLoop ( )
virtual

This method is called by the framework to break out of the loop() method. Reimplement this method to signal loop() to return and return true on success. When this method is not reimplemented by you, it will always return false, denoting that the loop can not be broken. If breakLoop() returns true, the caller will wait until loop() returns.

Returns
true if the loop could be notified to return.

Reimplemented in BuffersMPoolTest::Worker< T >, RTT::ExecutionEngine, and RTT::os::Timer.

Definition at line 64 of file CoreRunnableInterface.cpp.

virtual void RTT::base::RunnableInterface::finalize ( )
pure virtual

The method that will be called after the last periodical execution of step() ( or non periodical execution of loop() ), when the RunnableInterface is stopped.

Implemented in BuffersMPoolTest::Worker< T >, RTT::ExecutionEngine, and RTT::os::Timer.

ActivityInterface * RunnableInterface::getActivity ( ) const
inline

Query for the task this interface is run in.

Zero denotes that no task is present to run it, and hence no detailed information is available.

Returns
The Activity which runs this RunnableInterface.

Definition at line 175 of file RunnableInterface.hpp.

os::ThreadInterface * RunnableInterface::getThread ( ) const
virtual

Get the thread this object is run in.

Returns
a pointer to the thread or 0 if not run by a thread.

Definition at line 82 of file CoreRunnableInterface.cpp.

bool RunnableInterface::hasWork ( )
virtual

This method is for 'intelligent' activity implementations that wish to see if it is required to call step() (again). By default, false is returned. You should only return true in case there is a temporary reason to (re-)run step.

Returns
true if this object should be run.
See also
extras::SequentialActivity implementation to see how this can be of use.

Reimplemented in RTT::ExecutionEngine.

Definition at line 67 of file CoreRunnableInterface.cpp.

virtual bool RTT::base::RunnableInterface::initialize ( )
pure virtual

The method that will be called before the first periodical execution of step() ( or non periodical execution of loop() ), when the thread is started.

Implemented in BuffersMPoolTest::Worker< T >, RTT::ExecutionEngine, and RTT::os::Timer.

void RunnableInterface::loop ( )
virtual

The method that will be executed once when this class is run in a non periodic Activity. The default implementation calls step() once.

Reimplemented in RTT::os::Timer.

Definition at line 60 of file CoreRunnableInterface.cpp.

void RunnableInterface::setActivity ( ActivityInterface task)
virtual

Set the task this interface is run in.

A Zero means no task is running it.

Parameters
taskThe ActivityInterface running this interface.

Definition at line 73 of file CoreRunnableInterface.cpp.

virtual void RTT::base::RunnableInterface::step ( )
pure virtual

The method that will be (periodically) executed when this object is run in an Activity.

Implemented in BuffersMPoolTest::Worker< T >, RTT::ExecutionEngine, and RTT::os::Timer.

void RunnableInterface::work ( WorkReason  reason)
virtual

Identical to step() but gives a reason why the function was called. Both step() and work() will be called an equal amount of times, so you need to use only one, but work gives you the reason why.

Reimplemented in RTT::ExecutionEngine.

Definition at line 71 of file CoreRunnableInterface.cpp.

Member Data Documentation

ActivityInterface* RTT::base::RunnableInterface::owner_act
private

The Activityobject which owns this RunnableInterface.

Definition at line 74 of file RunnableInterface.hpp.


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


rtt
Author(s): RTT Developers
autogenerated on Tue Jun 25 2019 19:33:42