CommandProcessor Class Reference
[Execution Engine]

#include <rtt/CommandProcessor.hpp>

Inheritance diagram for CommandProcessor:

RunnableInterface

List of all members.


Detailed Description

This class implements an Orocos command processor. It executes external commands when running.

Changing the Command Processing Policy
The default policy of the CommandProcessor is to dequeue one command in each step() and execute it. If you want to change this policy, subclass the CommandProcessor and override the virtual functions, such as step() or process(). The current command queue is non blocking for push and pop operations. process() fails when the queue is full; step() does nothing when the queue is empty. A subclass may install a new command queue with for example blocking semantics.

Definition at line 77 of file CommandProcessor.hpp.


Public Member Functions

 CommandProcessor (int queue_size=ORONUM_EXECUTION_PROC_QUEUE_SIZE)
 Constructs a new CommandProcessor.
virtual ~CommandProcessor ()
virtual 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.
virtual void step ()
 The method that will be periodically executed when this class is run in a periodic thread.
virtual 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.
virtual int process (CommandInterface *c)
 Queue and execute (process) a given command.
virtual bool isProcessed (int id) const
 Check if a given command id has been processed.
void acceptCommands (bool true_false)
 Should the CommandProcessor accept or reject commands in process().
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.
ThreadInterfacegetThread () const
 Get the thread this object is run in.
virtual void setThread (ThreadInterface *t)
 Set the thread this object will be run in.

Protected Attributes

AtomicQueue
< CommandInterface *,
NonBlockingPolicy,
NonBlockingPolicy > * 
a_queue
int coms_processed
 Counting how much commands we processed.
bool accept

Constructor & Destructor Documentation

CommandProcessor ( int  queue_size = ORONUM_EXECUTION_PROC_QUEUE_SIZE  ) 

Constructs a new CommandProcessor.

Parameters:
queue_size The size of the command queue.

Definition at line 51 of file CommandProcessor.cpp.


Member Function Documentation

int process ( CommandInterface c  )  [virtual]

Queue and execute (process) a given command.

The command is executed in step() or loop() directly after all other queued CommandInterface objects. The constructor parameter queue_size limits how many commands can be queued in between step()s or loop().

Warning:
process() assumes that step() is executed once for each command, hence, it invokes ActivityInterface::trigger() each time. In case you override step() in a subclass, override process as well in order to reduce calling trigger().
Returns:
The command number. You can check if the given command was processed by calling CommandProcessor::isProcessed( command id ). The command number is reset to one each time the CommandProcessor is (re-)started.

0 when the CommandProcessor is not running or does not accept commands.

See also:
isProcessed, acceptCommands

Definition at line 90 of file CommandProcessor.cpp.

References CommandProcessor::a_queue, and CommandProcessor::accept.

Referenced by DataSourceArgsCommand::dispatch(), CommandDispatch::dispatch(), and LocalCommandImpl::invoke().

void acceptCommands ( bool  true_false  )  [inline]

Should the CommandProcessor accept or reject commands in process().

Parameters:
true_false true to accept, false to reject.

Definition at line 122 of file CommandProcessor.hpp.

References CommandProcessor::accept.

void loop (  )  [virtual, inherited]

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(), SingleThread::loop(), and NonPeriodicActivity::loop().

bool breakLoop (  )  [virtual, inherited]

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 SingleThread::breakLoop(), NonPeriodicActivity::breakLoop(), and SlaveActivity::stop().

ThreadInterface * getThread (  )  const [inherited]

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 Tue Mar 25 17:41:54 2008 for OrocosReal-TimeToolkit by  doxygen 1.5.3