ProgramProcessor Class Reference
[Execution Engine]

#include <rtt/ProgramProcessor.hpp>

Inheritance diagram for ProgramProcessor:

RunnableInterface

List of all members.


Detailed Description

This class implements a real-time program processor.

It executes Realtime Programs when running.

Changing the Program Processing Policy
The default policy of the ProgramProcessor is to call ProgramInterface::execute() of all loaded programs in each step(). Within the same step(), after all programs are executed, any loaded function is executed. The functions are automatically unloaded when they are in error or finished.

If you want to change this policy, subclass the ProgramProcessor and override the virtual functions, such as step().

Definition at line 79 of file ProgramProcessor.hpp.


Public Types

typedef
ProgramInterface::Status 
Status

Public Member Functions

 ProgramProcessor (int f_queue_size=ORONUM_EXECUTION_PROC_QUEUE_SIZE)
 Constructs a new ProgramProcessor.
virtual ~ProgramProcessor ()
bool loadProgram (ProgramInterfacePtr pi)
 Load a new Program.
bool deleteProgram (const std::string &name)
 Completely discard a loaded Program.
bool unloadProgram (const std::string &name)
 Unload a program from this processor.
void clear ()
 Stop and unload all programs from the ProgramProcessor.
Status::ProgramStatus getProgramStatus (const std::string &name) const
 Return the status of a Program.
std::string getProgramStatusStr (const std::string &name) const
 Return the status of a Program as a human readable string.
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 bool runFunction (ProgramInterface *f)
 Run a given function in step() or loop().
virtual bool removeFunction (ProgramInterface *f)
 Remove a running function added with runFunction.
std::vector
< std::string > 
getProgramList () const
 Get a list of all loaded Programs.
const ProgramInterfacePtr getProgram (const std::string &name) const
 Get a pointer to a loaded Program.
ProgramInterfacePtr getProgram (const std::string &name)
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 Types

typedef ListLockFree
< ProgramInterfacePtr
ProgMap

Protected Attributes

ProgMapprograms
std::vector
< ProgramInterface * > 
funcs
AtomicQueue
< ProgramInterface *,
NonBlockingPolicy,
NonBlockingPolicy > * 
f_queue

Constructor & Destructor Documentation

ProgramProcessor ( int  f_queue_size = ORONUM_EXECUTION_PROC_QUEUE_SIZE  ) 

Constructs a new ProgramProcessor.

Parameters:
f_queue_size The maximum number of 'functions' this processor can execute

Definition at line 55 of file ProgramProcessor.cpp.


Member Function Documentation

bool loadProgram ( ProgramInterfacePtr  pi  ) 

Load a new Program.

The Processor takes full ownership and will delete it upon destruction.

Exceptions:
program_load_exception if a program with the same name already exists.

Definition at line 109 of file ProgramProcessor.cpp.

References ListLockFree::append(), ListLockFree::find_if(), ProgramInterface::getName(), ListLockFree::grow(), and ProgramProcessor::programs.

bool deleteProgram ( const std::string &  name  ) 

Completely discard a loaded Program.

Exceptions:
program_unload_exception if the program is not stopped or does not exist.
Deprecated:
by unloadProgram

Definition at line 121 of file ProgramProcessor.cpp.

References ProgramProcessor::unloadProgram().

bool unloadProgram ( const std::string &  name  ) 

Unload a program from this processor.

Exceptions:
program_unload_exception if the program is not stopped or does not exist.

Definition at line 126 of file ProgramProcessor.cpp.

References ListLockFree::erase(), ListLockFree::find_if(), ProgramInterface::getName(), ORO_THROW_OR_RETURN, ProgramProcessor::programs, and ListLockFree::shrink().

Referenced by ProgramProcessor::clear(), and ProgramProcessor::deleteProgram().

bool runFunction ( ProgramInterface f  )  [virtual]

Run a given function in step() or loop().

The function may only be destroyed after isFunctionFinished() returns true,the Processor is stopped or removeFunction() was invoked. The number of functions the Processor can run in parallel is set in its constructor argument queue_size. In addition to that number, a queue of the same size is allocated for pending functions to execute.

Returns:
false if the Processor is not running or the 'pending' queue is full.
See also:
isFunctionFinished, acceptCommands, removeFunction

Definition at line 196 of file ProgramProcessor.cpp.

References ProgramProcessor::f_queue, ProgramInterface::setProgramProcessor(), and ProgramInterface::start().

Referenced by CommandExecFunction::execute().

bool removeFunction ( ProgramInterface f  )  [virtual]

Remove a running function added with runFunction.

This method is only required if the function is to be destroyed and is still present in the ProgramProcessor.

Definition at line 212 of file ProgramProcessor.cpp.

References ProgramProcessor::funcs, and ProgramInterface::stop().

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:57 2008 for OrocosReal-TimeToolkit by  doxygen 1.5.3