Orocos Real-Time Toolkit
2.8.3
|
A class for running a certain piece of code in a thread. More...
#include <rtt/base/RunnableInterface.hpp>
Public Member Functions | |
RunnableInterface () | |
Create a runnable object. More... | |
virtual | ~RunnableInterface () |
Checks if this is still in a task and if so, issues a critical warning. More... | |
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. More... | |
virtual void | step ()=0 |
The method that will be periodically executed when this class is run in a periodic thread. More... | |
virtual void | loop () |
The method that will be executed once when this class is run in a non periodic thread. More... | |
virtual bool | breakLoop () |
This method is called by the framework to break out of the loop() method. More... | |
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. More... | |
virtual os::ThreadInterface * | getThread () const |
Get the thread this object is run in. More... | |
virtual bool | hasWork () |
This method is for 'intelligent' activity implementations that wish to see if it is required to call step() (again). More... | |
ActivityInterface * | getActivity () const |
Query for the task this interface is run in. More... | |
virtual void | setActivity (ActivityInterface *task) |
Set the task this interface is run in. More... | |
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() ).
Definition at line 69 of file RunnableInterface.hpp.
RTT::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.
t | The thread this object must attach to. |
Definition at line 58 of file CoreRunnableInterface.cpp.
|
virtual |
Checks if this is still in a task and if so, issues a critical warning.
Definition at line 47 of file CoreRunnableInterface.cpp.
References RTT::Critical, RTT::base::ActivityInterface::disableRun(), and RTT::base::ActivityInterface::isRunning().
|
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.
Reimplemented in RTT::ExecutionEngine, and RTT::os::Timer.
Definition at line 62 of file CoreRunnableInterface.cpp.
Referenced by RTT::Activity::breakLoop(), and RTT::extras::SlaveActivity::stop().
|
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 RTT::ExecutionEngine, and RTT::os::Timer.
Referenced by RTT::Activity::finalize(), RTT::extras::PeriodicActivity::finalize(), RTT::extras::SequentialActivity::stop(), and RTT::extras::SlaveActivity::stop().
|
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.
Definition at line 167 of file RunnableInterface.hpp.
Referenced by RTT::base::TaskCore::activate(), RTT::scripting::StateMachine::createEventTransition(), RTT::base::TaskCore::fatal(), RTT::TaskContext::getActivity(), RTT::base::TaskCore::getCpuAffinity(), RTT::base::TaskCore::getPeriod(), RTT::base::TaskCore::isActive(), RTT::ExecutionEngine::process(), RTT::ExecutionEngine::processChildren(), RTT::ExecutionEngine::removeFunction(), RTT::ExecutionEngine::runFunction(), RTT::base::TaskCore::setCpuAffinity(), RTT::base::TaskCore::setPeriod(), RTT::ExecutionEngine::stopTask(), RTT::base::TaskCore::trigger(), RTT::base::TaskCore::update(), RTT::ExecutionEngine::waitForFunctions(), and RTT::ExecutionEngine::waitForMessages().
|
virtual |
Get the thread this object is run in.
Definition at line 78 of file CoreRunnableInterface.cpp.
References RTT::base::ActivityInterface::thread().
|
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.
Reimplemented in RTT::ExecutionEngine.
Definition at line 65 of file CoreRunnableInterface.cpp.
Referenced by RTT::extras::SequentialActivity::trigger().
|
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 RTT::ExecutionEngine, and RTT::os::Timer.
Referenced by RTT::Activity::initialize(), RTT::extras::PeriodicActivity::initialize(), RTT::extras::SequentialActivity::start(), and RTT::extras::SlaveActivity::start().
|
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 RTT::os::Timer.
Definition at line 60 of file CoreRunnableInterface.cpp.
References step().
Referenced by RTT::extras::SlaveActivity::execute(), and RTT::Activity::loop().
|
virtual |
Set the task this interface is run in.
A Zero means no task is running it.
task | The ActivityInterface running this interface. |
Reimplemented in RTT::ExecutionEngine.
Definition at line 69 of file CoreRunnableInterface.cpp.
References RTT::base::ActivityInterface::disableRun().
Referenced by RTT::base::ActivityInterface::ActivityInterface(), RTT::base::ActivityInterface::run(), RTT::ExecutionEngine::setActivity(), and RTT::base::ActivityInterface::~ActivityInterface().
|
pure virtual |
The method that will be periodically executed when this class is run in a periodic thread.
Implemented in RTT::ExecutionEngine, and RTT::os::Timer.
Referenced by RTT::extras::SlaveActivity::execute(), loop(), RTT::extras::IRQActivity::start(), RTT::Activity::step(), RTT::extras::PeriodicActivity::step(), RTT::extras::FileDescriptorActivity::step(), and RTT::extras::SequentialActivity::trigger().