TaskContext Class Reference

#include <rtt/TaskContext.hpp>

Inheritance diagram for TaskContext:

Inheritance graph
[legend]
List of all members.

Detailed Description

A TaskContext exports the commands, methods, events, properties and ports a task has.

Furthermore, it allows to visit its peer tasks.

TaskContext interface
When a command is exported, one can access it using commands(). A similar mechanism is available for properties(), methods(), events() and ports(). The commands of this TaskContext are executed by its ExecutionEngine.
Executing a TaskContext
In order to run the ExecutionEngine, the ExecutionEngine must be invoked from an ActivityInterface implementation. As long as there is no activity or the activity is not started, this TaskContext will not accept any commands, nor process events, nor execute programs or state machines. In this way, the user of this class can determine himself at which point and at which moment commands and programs can be executed.
Connecting TaskContexts
TaskContexts are connected using the unidirectional addPeer() or bidirectional connectPeers() methods. These methods only allow 'peer' TaskContexts to use each other's interface. Use connectPorts() to setup the data connections between data ports. In order to disconnect this task from its peers, use disconnect(), which will disconnect all the Data Flow Ports and remove this object from its Peers.


Public Types

typedef std::vector< std::string > PeerList
typedef std::vector< std::string > ObjectList

Public Member Functions

 TaskContext (const std::string &name)
 Create a TaskContext visible with name.
 TaskContext (const std::string &name, ExecutionEngine *parent)
 Create a TaskContext visible with name.
virtual const std::string & getName () const
virtual const std::string & getDescription () const
virtual void setDescription (const std::string &descr)
void exportPorts ()
 Call this function to force a TaskContext to export its Data Flow ports as scripting objects.
virtual bool addPeer (TaskContext *peer, std::string alias="")
 Add a one-way connection from this task to a peer task.
virtual void removePeer (const std::string &name)
 Remove a one-way connection from this task to a peer task.
virtual void removePeer (TaskContext *peer)
 Remove a one-way connection from this task to a peer task.
virtual bool connectPeers (TaskContext *peer)
 Add a two-way connection from this task to a peer task.
virtual bool connectPorts (TaskContext *peer)
 Add a data flow connection from this task's ports to a peer's ports.
virtual void disconnect ()
 Disconnect this TaskContext from it's peers.
virtual void reconnect ()
 Reconnect the data ports of this task, without removing the peer relationship.
virtual void disconnectPeers (const std::string &name)
 Remove a two-way connection from this task to a peer task.
virtual PeerList getPeerList () const
 Return a standard container which contains all the Peer names of this TaskContext.
virtual bool hasPeer (const std::string &peer_name) const
 Return true if it knows a peer by that name.
virtual TaskContextgetPeer (const std::string &peer_name) const
 Get a pointer to a peer of this task.
virtual bool addObject (OperationInterface *obj)
 Add a new TaskObject to this TaskContext.
virtual OperationInterfacegetObject (const std::string &obj_name)
 Get a pointer to a previously added TaskObject.
virtual ObjectList getObjectList () const
 Get a list of all the object names of this TaskContext.
virtual bool removeObject (const std::string &obj_name)
 Remove and delete a previously added TaskObject.
void clear ()
 Clear the complete interface of this Component.
ScriptingAccessscripting ()
 Get access to high level controls for programs, state machines and scripting statements.
const ScriptingAccessscripting () const
 Get access to high level controls for programs, state machines and scripting statements.
ExecutionAccessexecution ()
 Get access to high level controls for controlling programs and state machines.
const ExecutionAccessexecution () const
 Get access to high level controls for controlling programs and state machines.
MarshallingAccessmarshalling ()
 Get access to high level controls for (de)serializing properties to/from an XML format.
const MarshallingAccessmarshalling () const
 Get access to high level controls for (de)serializing properties to/from an XML format.
CommandRepositorycommands ()
 The command interface of this task context.
const CommandRepositorycommands () const
 The command interface of this task context.
MethodRepositorymethods ()
 The method interface of this task context.
const MethodRepositorymethods () const
 The method interface of this task context.
AttributeRepositoryattributes ()
 The task-local values ( attributes and properties ) of this TaskContext.
const AttributeRepositoryattributes () const
 The task-local values ( attributes and properties ) of this TaskContext.
PropertyBagproperties ()
 The properties of this TaskContext.
const PropertyBagproperties () const
 The properties of this TaskContext.
EventServiceevents ()
 The task-local events ( 'signals' ) of this TaskContext.
const EventServiceevents () const
 The task-local events ( 'signals' ) of this TaskContext.
DataFlowInterfaceports ()
 Get the Data flow ports of this task.
const DataFlowInterfaceports () const
 Get the Data flow ports of this task.
virtual bool startup ()
 Function where the user must insert his 'startup' code.
virtual void update ()
 Function where the user must insert his 'application' code.
virtual void shutdown ()
 Function where the user must insert his 'shutdown' code.
void setName (const std::string &n)
 Change the name of this TaskCore.
void setExecutionEngine (ExecutionEngine *engine)
 Use this method to re-set the execution engine of this task core.
const ExecutionEngineengine () const
 Get a const pointer to the ExecutionEngine of this Task.
ExecutionEngineengine ()
 Get a pointer to the ExecutionEngine of this Task.
Script Methods
The standard script methods of a TaskContext are for starting and stopping its ExecutionEngine.

The methods map to the ActivityInterface which executes the ExecutionEngine.

virtual bool start ()
 Start is a method which starts the execution engine's task.
virtual bool stop ()
 Stop is a method which stops the execution engine's task.
virtual bool isRunning () const
 DataSource to inspect if this Task is running.
virtual bool doUpdate ()
 Invoke this method to execute the ExecutionEngine and the update() method.
virtual bool doTrigger ()
 Invoke this method to trigger the thread of this TaskContext to execute its ExecutionEngine and the update() method.

Protected Types

typedef std::map< std::string,
TaskContext * > 
PeerMap
typedef std::vector< TaskContext * > Users
typedef std::vector< OperationInterface * > Objects

Protected Member Functions

void addUser (TaskContext *user)
 Inform this TaskContext that user is using our services.
void removeUser (TaskContext *user)
 Inform this TaskContext that user is no longer using our services.
void setup ()

Protected Attributes

std::string mdescription
PeerMap _task_map
 map of the tasks we are using
Users musers
 map of the tasks that are using us.
Objects mobjects
 the TaskObjects.
ScriptingAccessmscriptAcc
ExecutionAccessmengAcc
MarshallingAccessmarshAcc
std::string mtask_name
ExecutionEngineee
 The execution engine which calls update() and processes our commands, events etc.


Constructor & Destructor Documentation

TaskContext ( const std::string &  name  ) 

Create a TaskContext visible with name.

It's ExecutionEngine will be newly constructed with private ExecutionEngine processing its commands, events, programs and state machines.

TaskContext ( const std::string &  name,
ExecutionEngine parent 
)

Create a TaskContext visible with name.

Its commands programs and state machines are processed by parent. Use this constructor to share execution engines among task contexts, such that the execution of their functionality is serialised (executed in the same thread).


Member Function Documentation

void exportPorts (  ) 

Call this function to force a TaskContext to export its Data Flow ports as scripting objects.

This is done by the component itself when a peer connection is made, but in case you want to access the Data Flow ports of a stand-alone component from the scripting interface, you need to call this function.

virtual bool start (  )  [virtual]

Start is a method which starts the execution engine's task.

It can not be a command because if the engine is not running, it does not accept commands. Also, RunnableInterface::initialize() is then called in the context of the caller. You can override this method to do something else or in addition to starting the Processor.

Returns:
false if the engine was not assigned to a ActivityInterface or if initialize() returned false or it was already started.

Reimplemented in ControlTaskProxy.

virtual bool stop (  )  [virtual]

Stop is a method which stops the execution engine's task.

RunnableInterface::finalize() is called in the context of the caller. You can override this method to do something else or in addition to stopping the engine.

Returns:
false if the engine was not assigned to a ActivityInterface or if it was not running.

Reimplemented in ControlTaskProxy.

virtual bool isRunning (  )  const [virtual]

DataSource to inspect if this Task is running.

Defaults to this->getProcessor()->getActivity() && this->getProcessor()->getActivity()->isRunning()

Reimplemented in ControlTaskProxy.

virtual bool doUpdate (  )  [virtual]

Invoke this method to execute the ExecutionEngine and the update() method.

This method maps to the 'update()' method in the scripting language.

Return values:
false if this->engine()->getActivity()->execute() == false
true otherwise.

virtual bool doTrigger (  )  [virtual]

Invoke this method to trigger the thread of this TaskContext to execute its ExecutionEngine and the update() method.

This method maps to the 'trigger()' method in the scripting language.

Return values:
false if this->engine()->getActivity()->trigger() == false
true otherwise.

virtual bool addPeer ( TaskContext peer,
std::string  alias = "" 
) [virtual]

Add a one-way connection from this task to a peer task.

Parameters:
peer The peer to add.
alias An optional alias (another name) for the peer. defaults to peer->getName()

Reimplemented in ControlTaskProxy.

virtual void disconnect (  )  [virtual]

Disconnect this TaskContext from it's peers.

All its Data Flow Ports are disconnected from the connections but the connections themselves may continue to exist to serve other TaskContexts. This method invokes removePeer() as well on the peers listed in this->getPeerList().

virtual void reconnect (  )  [virtual]

Reconnect the data ports of this task, without removing the peer relationship.

Use this if you changed a port name of an already connected task.

virtual TaskContext* getPeer ( const std::string &  peer_name  )  const [virtual]

Get a pointer to a peer of this task.

Returns:
null if no such peer.

Reimplemented in ControlTaskProxy.

virtual bool addObject ( OperationInterface obj  )  [virtual]

Add a new TaskObject to this TaskContext.

Parameters:
obj This object becomes owned by this TaskContext.
Returns:
true if it cuold be added, false if such object already exists.

virtual OperationInterface* getObject ( const std::string &  obj_name  )  [virtual]

Get a pointer to a previously added TaskObject.

Parameters:
obj_name The name of the TaskObject
Returns:
the pointer

virtual ObjectList getObjectList (  )  const [virtual]

Get a list of all the object names of this TaskContext.

Returns:
a list of string names.

virtual bool removeObject ( const std::string &  obj_name  )  [virtual]

Remove and delete a previously added TaskObject.

Parameters:
obj_name The name of the TaskObject
Returns:
true if found and removed, false otherwise.

void clear (  ) 

Clear the complete interface of this Component.

This method removes all objects and all methods, commands, events, properties and ports from the interface of this TaskContext.

ExecutionAccess* execution (  )  [inline]

Get access to high level controls for controlling programs and state machines.

It is the implementation of the 'engine' TaskObject.

const ExecutionAccess* execution (  )  const [inline]

Get access to high level controls for controlling programs and state machines.

It is the implementation of the 'engine' TaskObject.

virtual bool startup (  )  [virtual, inherited]

Function where the user must insert his 'startup' code.

This function is called by the ExecutionEngine before it starts its processors. If it returns false, the startup of the TaskCore is aborted. The default implementation is an empty function which returns true.

virtual void update (  )  [virtual, inherited]

Function where the user must insert his 'application' code.

When the ExecutionEngine's Activity is a PeriodicActivity, this function is called by the ExecutionEngine in each periodic step after all command, event,... processors. When it's Task is a NonPeriodicActivity, this function is called after an Event or Command is received and executed. It should not loop forever, since no commands or events are processed when this function executes. The default implementation is an empty function.

virtual void shutdown (  )  [virtual, inherited]

Function where the user must insert his 'shutdown' code.

This function is called by the ExecutionEngine after it stops its processors. The default implementation is an empty function.

void setExecutionEngine ( ExecutionEngine engine  )  [inherited]

Use this method to re-set the execution engine of this task core.

Parameters:
engine The new execution engine which will execute this TaskCore or null if a new execution engine must be created (the old is deleted in that case).
Postcondition:
The TaskCore is being run by engine or a new execution engine.


The documentation for this class was generated from the following file:
Generated on Fri May 11 11:19:46 2007 for Orocos by  doxygen 1.5.1