RunnableInterface Class Reference

#include <rtt/os/RunnableInterface.hpp>

Inheritance diagram for RunnableInterface:

CommandProcessor EventProcessor ExecutionEngine ProgramProcessor RunnableInterface StateMachineProcessor Timer BlockingEventProcessor CompletionProcessor

List of all members.


Detailed Description

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

It defines three methods for executing functionality. It allows to execute code in a PeriodicThreadInterface or SingleThreadInterface, which define the control methods as starting and stopping (periodic) threads.

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.

Definition at line 66 of file RunnableInterface.hpp.


Public Member Functions

 RunnableInterface (ThreadInterface *t=0)
 Create a runnable object.
virtual bool initialize ()=0
 The method that will be called before the first periodical execution of step() ( or non periodical execution of loop() ), when the thread is started.
virtual void step ()=0
 The method that will be periodically executed when this class is run in a periodic thread.
virtual void loop ()
 The method that will be executed once when this class is run in a non periodic thread.
virtual bool breakLoop ()
 This method is called by the framework to break out of the loop() method.
virtual void finalize ()=0
 The method that will be called after the last periodical execution of step() ( or non periodical execution of loop() ), when the RunnableInterface is stopped.
ThreadInterfacegetThread () const
 Get the thread this object is run in.
virtual void setThread (ThreadInterface *t)
 Set the thread this object will be run in.

Constructor & Destructor Documentation

Create a runnable object.

The optional constructor parameter allows the object to attach directly to a thread. Otherwise, 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:
t The thread this object must attach to.

Definition at line 46 of file RunnableInterface.cpp.

References ThreadInterface::run().


Member Function Documentation

void loop (  )  [virtual]

The method that will be executed once when this class is run in a non periodic thread.

The default implementation calls step() once.

Reimplemented in Timer.

Definition at line 60 of file RunnableInterface.cpp.

References RunnableInterface::step().

Referenced by SlaveActivity::execute().

bool 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 EventProcessor, ExecutionEngine, and Timer.

Definition at line 62 of file RunnableInterface.cpp.

Referenced by SlaveActivity::stop().

ThreadInterface * getThread (  )  const

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 69 of file RunnableInterface.cpp.

Referenced by Timer::initialize().


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

Generated on Mon Jan 19 16:54:00 2009 for OrocosReal-TimeToolkit by  doxygen 1.5.6