An activity which executes asynchronous (defered) handlers of Events. More...
#include <rtt/CompletionProcessor.hpp>
Public Types | |
typedef CompletionProcessor * | CompletionProcessorPtr |
enum | AsynStorageType { OnlyFirst, OnlyLast } |
For Asynchronous callbacks, this enum defines how the arguments are stored in case of an overrun, ie, when the event is fired multiple times, before the asynchronous callback can be called. More... | |
typedef boost::shared_ptr < ActivityInterface > | shared_ptr |
Public Member Functions | |
bool | initialize () |
The method that will be called before the first periodical execution of step() ( or non periodical execution of loop() ), when the thread is started. | |
void | step () |
The method that will be periodically executed when this class RTT_API is run in a periodic thread. | |
void | finalize () |
The method that will be called after the last periodical execution of step() ( or non periodical execution of loop() ), when the RunnableInterface is stopped. | |
bool | breakLoop () |
Force the loop() method to return. | |
bool | hasWork () |
This method is for 'intelligent' activity implementations that wish to see if it is required to call step() (again). | |
template<class SignalType > | |
Handle | connect (const typename SignalType::SlotFunction &f, SignalType &sig, AsynStorageType t) |
Connect a function to an Event and process upon each event the function in this event processor. | |
template<class SignalType > | |
Handle | setup (const typename SignalType::SlotFunction &f, SignalType &sig, AsynStorageType t) |
Setup the processing of an asynchronous event. | |
ActivityInterface * | getActivity () const |
Query for the task this interface is run in. | |
virtual void | setActivity (ActivityInterface *task) |
Set the task this interface is run in. | |
virtual OS::ThreadInterface * | getThread () const |
Get the thread this object is run in. | |
virtual void | loop () |
The method that will be executed once when this class RTT_API is run in a non periodic thread. | |
virtual void | setThread (ThreadInterface *t) |
Set the thread this object will be run in. | |
bool | run (int) |
Run another (or self in case of null) task. | |
virtual bool | run (RunnableInterface *r) |
Run exclusively this RunnableInterface. | |
virtual Seconds | getPeriod () const |
Get the periodicity of this activity in Seconds. | |
virtual ThreadInterface * | thread () |
Returns a pointer to the thread which will run this activity. | |
virtual bool | initialize () |
virtual void | loop () |
virtual bool | breakLoop () |
virtual void | finalize () |
virtual bool | isPeriodic () const |
Inspect if this activity is periodic. | |
virtual bool | start () |
Start the activity. | |
virtual bool | execute () |
Execute this activity such that it executes a step or loop of the RunnableInterface. | |
virtual bool | trigger () |
Trigger that work has to be done. | |
virtual bool | stop () |
Stop the activity This will stop the activity by removing it from the 'run-queue' of a thread or call RunnableInterface::breakLoop(). | |
virtual bool | isRunning () const |
Query if the activity is initialized and executing. | |
virtual bool | isActive () const |
Query if the activity is started. | |
Static Public Member Functions | |
static CompletionProcessorPtr | Instance () |
Returns the unique (singleton) CompletionProcessor. | |
static bool | Release () |
Releases the CompletionProcessor. | |
Protected Types | |
typedef List < detail::EventCatcher * > | ECList |
The EC is released when the connection it is used in is deleted *and* it is removed from this vector. | |
Protected Member Functions | |
CompletionProcessor () | |
Constructor. | |
void | destroyed (detail::EventCatcher *ec) |
void | disableRun (RunnableInterface *caller) |
This method is only meant for RunnableInterface (ie runner) in order to inform the ActivityInterface it should no longer be used. | |
Protected Attributes | |
ECList | catchers |
OS::AtomicInt | has_work |
RunnableInterface * | runner |
Friends | |
struct | EventCatcher |
struct | detail::EventCatcher |
class | RunnableInterface |
An activity which executes asynchronous (defered) handlers of Events.
This is an utility class which can be used to execute Event callback functions in a thread. It's purpose is to allow a way to process not real-time event callback functions, without disturbing the emitor of the event. If the user requires a not real-time, complex or lengthy callback execution, it can be done in this activity.
Definition at line 44 of file CompletionProcessor.hpp.
enum RTT::EventProcessor::AsynStorageType [inherited] |
For Asynchronous callbacks, this enum defines how the arguments are stored in case of an overrun, ie, when the event is fired multiple times, before the asynchronous callback can be called.
OnlyLast |
< Only call the callback once with the first fire() call's arguments < Only call the callback once with the last fire() call's arguments |
Definition at line 533 of file EventProcessor.hpp.
Handle RTT::EventProcessor::connect | ( | const typename SignalType::SlotFunction & | f, | |
SignalType & | sig, | |||
AsynStorageType | t | |||
) | [inline, inherited] |
Connect a function to an Event and process upon each event the function in this event processor.
The returned handle holds the connection between f and sig.
f | will be called within this EventProcessor when sig is emitted. | |
sig | The Event to which f will react. | |
t | specifies the policy in case of over-runs. That is, when sig is emitted multiple times before f could be called. |
Definition at line 569 of file EventProcessor.hpp.
References RTT::Handle::connect().
Referenced by RTT::Event< void() >::connect().
void RTT::ActivityInterface::disableRun | ( | RunnableInterface * | caller | ) | [inline, protected, inherited] |
This method is only meant for RunnableInterface (ie runner) in order to inform the ActivityInterface it should no longer be used.
run(0) can not be used in this case because it would recurse.
Definition at line 73 of file ActivityInterface.hpp.
virtual bool RTT::NonPeriodicActivity::execute | ( | ) | [virtual, inherited] |
Execute this activity such that it executes a step or loop of the RunnableInterface.
When you invoke execute() you intend to call the step() or loop() methods. Some activity implementations allow a user controlled execute, others ignore it, in which case execute() returns false.
Semantics: If execute() returns true, the activity has been executed exactly once during execute().
true | When this->isActive() and the implementation allows external executes. | |
false | When !this->isActive() or the implementation does not allow external updating. |
Implements RTT::ActivityInterface.
ActivityInterface * RTT::RunnableInterface::getActivity | ( | ) | const [inline, inherited] |
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 106 of file RunnableInterface.hpp.
virtual Seconds RTT::NonPeriodicActivity::getPeriod | ( | ) | const [virtual, inherited] |
Get the periodicity of this activity in Seconds.
Implements RTT::ActivityInterface.
virtual OS::ThreadInterface* RTT::RunnableInterface::getThread | ( | ) | const [virtual, inherited] |
Get the thread this object is run in.
Reimplemented from RTT::OS::RunnableInterface.
bool RTT::EventProcessor::hasWork | ( | ) | [virtual, inherited] |
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 from RTT::RunnableInterface.
virtual bool RTT::NonPeriodicActivity::isActive | ( | ) | const [virtual, inherited] |
Query if the activity is started.
This is less strict than isRunning(), it is true during initialize(), step() or loop() and finalize(). Use this method to check if an activity was start()ed.
Implements RTT::ActivityInterface.
virtual bool RTT::NonPeriodicActivity::isPeriodic | ( | ) | const [virtual, inherited] |
Inspect if this activity is periodic.
If so, it will call RunnableInterface::step(). If the activity is not periodic, it will call RunnableInterface::loop().
Implements RTT::ActivityInterface.
virtual bool RTT::NonPeriodicActivity::isRunning | ( | ) | const [virtual, inherited] |
Query if the activity is initialized and executing.
This is more strict than isActive(), it is only true after initialize() is executed and before finalize() is executed. More-over, an Activity may decide to be temporarily not running (not executing code), waiting for a signal to proceed. If this->isActive() and !this->isRunning() then the Activity is in a waiting state.
Implements RTT::ActivityInterface.
virtual void RTT::OS::RunnableInterface::loop | ( | ) | [virtual, inherited] |
The method that will be executed once when this class RTT_API is run in a non periodic thread.
The default implementation calls step() once.
Reimplemented in RTT::Timer.
static bool RTT::CompletionProcessor::Release | ( | ) | [static] |
Releases the CompletionProcessor.
virtual bool RTT::ActivityInterface::run | ( | RunnableInterface * | r | ) | [virtual, inherited] |
Run exclusively this RunnableInterface.
r | The RunnableInterface to run exclusively. |
Referenced by RTT::NonPeriodicActivity::run().
bool RTT::NonPeriodicActivity::run | ( | int | ) | [inline, inherited] |
Run another (or self in case of null) task.
This overload is needed to redirect the call of run( 0 ) to the correct function.
Definition at line 105 of file NonPeriodicActivity.hpp.
References RTT::ActivityInterface::run().
virtual void RTT::RunnableInterface::setActivity | ( | ActivityInterface * | task | ) | [virtual, inherited] |
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.
Handle RTT::EventProcessor::setup | ( | const typename SignalType::SlotFunction & | f, | |
SignalType & | sig, | |||
AsynStorageType | t | |||
) | [inline, inherited] |
Setup the processing of an asynchronous event.
The returned handle does not yet connect f and sig. Use Handle::connect().
f | will be called within this EventProcessor when sig is emitted. | |
sig | The Event to which f will react. | |
t | specifies the policy in case of over-runs. That is, when sig is emitted multiple times before f could be called. |
Definition at line 587 of file EventProcessor.hpp.
Referenced by RTT::Event< void() >::setup().
virtual bool RTT::NonPeriodicActivity::start | ( | ) | [virtual, inherited] |
Start the activity.
This will call RunnableInterface::initialize() and upon success, effectively start the activity, by running the RunnableInterface::step() or RunnableInterface::loop() in a thread.
Implements RTT::ActivityInterface.
Reimplemented in RTT::EventDrivenActivity.
virtual bool RTT::NonPeriodicActivity::stop | ( | ) | [virtual, inherited] |
Stop the activity This will stop the activity by removing it from the 'run-queue' of a thread or call RunnableInterface::breakLoop().
If no errors occured, RunnableInterface::finalize() is called.
Implements RTT::ActivityInterface.
Reimplemented in RTT::EventDrivenActivity.
virtual ThreadInterface* RTT::NonPeriodicActivity::thread | ( | ) | [virtual, inherited] |
Returns a pointer to the thread which will run this activity.
Will not be null.
Implements RTT::ActivityInterface.
virtual bool RTT::NonPeriodicActivity::trigger | ( | ) | [virtual, inherited] |
Trigger that work has to be done.
When you invoke trigger(), you intend to notify the mechanism that calls execute(), that execute() should be called. This allows a separation between actually executing code (execute()) and notifying that code must be executed (trigger()). A trigger may be ignored by the implementation, in which case trigger returns false.
Semantics: If trigger() returns true, the activity will be executed at least once from the moment trigger() is called.
true | When this->isActive() and the implementation allows external triggers. | |
false | When !this->isActive() or the implementation does not allow external triggering. |
Implements RTT::ActivityInterface.