Public Types | Public Member Functions | Protected Member Functions | Private Types | Private Member Functions | Private Attributes | Friends
RTT::TaskContext Class Reference

#include <TaskContext.hpp>

Inheritance diagram for RTT::TaskContext:
Inheritance graph
[legend]

List of all members.

Public Types

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

Public Member Functions

virtual void clear ()
base::ActivityInterfacegetActivity ()
template<typename T >
T * getActivity ()
virtual const std::string & getName () const
virtual bool ready ()
bool setActivity (base::ActivityInterface *new_act)
virtual bool start ()
virtual bool stop ()
 TaskContext (const std::string &name, TaskState initial_state=Stopped)
 TaskContext (const std::string &name, ExecutionEngine *parent, TaskState initial_state=Stopped)
virtual ~TaskContext ()
Peer-to-Peer functions

These functions are used to setup and manage peer-to-peer networks of TaskContext objects.

virtual bool addPeer (TaskContext *peer, std::string alias="")
virtual void removePeer (const std::string &name)
virtual void removePeer (TaskContext *peer)
virtual bool connectPeers (TaskContext *peer)
virtual void disconnect ()
virtual void disconnectPeers (const std::string &name)
virtual PeerList getPeerList () const
virtual bool hasPeer (const std::string &peer_name) const
virtual TaskContextgetPeer (const std::string &peer_name) const
Services

These functions are used to create and manage services. Use provides() or requires() to access the Service or ServiceRequester objects that contain all service related functions.

Service::shared_ptr provides ()
Service::shared_ptr provides (const std::string &service_name)
ServiceRequester::shared_ptr requires ()
ServiceRequester::shared_ptr requires (const std::string &service_name)
virtual bool connectServices (TaskContext *peer)
template<class ServiceType >
boost::shared_ptr< ServiceType > getProvider (const std::string &name)
bool loadService (const std::string &service_name)
Operations

Adding and getting operations from the TaskContext interface. These functions all forward to the Service representing this TaskContext. Use provides() to access the complete Service interface of this TaskContext.

template<class Signature >
Operation< Signature > & addOperation (Operation< Signature > &op)
template<class Func , class Service >
Operation< typename
internal::GetSignature< Func >
::Signature > & 
addOperation (const std::string name, Func func, Service *serv, ExecutionThread et=ClientThread)
template<class Signature >
Operation< Signature > & addOperation (const std::string name, Signature *func, ExecutionThread et=ClientThread)
OperationInterfacePartgetOperation (std::string name)
OperationInterfaceoperations ()
Attributes

Adding and getting attributes from the TaskContext interface. These functions all forward to the Service representing this TaskContext. Use attributes() to access the complete ConfigurationInterface interface of this TaskContext.

template<class T >
bool addAttribute (const std::string &name, T &attr)
template<class T >
bool addConstant (const std::string &name, const T &attr)
bool addAttribute (base::AttributeBase &a)
base::AttributeBasegetAttribute (const std::string &name) const
ConfigurationInterfaceattributes ()
Properties

Adding and getting properties from the TaskContext interface. These functions all forward to the Service representing this TaskContext. Use properties() to access the complete PropertyBag interface of this TaskContext.

template<class T >
Property< T > & addProperty (const std::string &name, T &attr)
bool addProperty (base::PropertyBase &pb)
base::PropertyBasegetProperty (const std::string &name) const
PropertyBagproperties ()

Protected Member Functions

void forceActivity (base::ActivityInterface *new_act)

Private Types

typedef std::map< std::string,
boost::shared_ptr
< ServiceRequester > > 
LocalServices
typedef std::map< std::string,
TaskContext * > 
PeerMap
typedef std::map
< base::PortInterface
*, SlotFunction
UserCallbacks
typedef std::vector
< TaskContext * > 
Users

Private Member Functions

void addUser (TaskContext *user)
void dataOnPort (base::PortInterface *port)
void dataOnPortCallback (base::InputPortInterface *port, SlotFunction callback)
void dataOnPortRemoved (base::PortInterface *port)
bool dataOnPortSize (unsigned int max)
bool prepareProvide (const std::string &name)
void prepareUpdateHook ()
void removeUser (TaskContext *user)
void setup ()
 TaskContext (TaskContext &)

Private Attributes

PeerMap _task_map
 map of the tasks we are using
LocalServices localservs
os::Mutex mportlock
Users musers
 map of the tasks that are using us.
base::ActivityInterface::shared_ptr our_act
internal::MWSRQueue
< base::PortInterface * > * 
portqueue
ServiceRequester::shared_ptr tcrequests
Service::shared_ptr tcservice
UserCallbacks user_callbacks

Friends

class DataFlowInterface

Ports

These functions serve to manage ports and data flow connections. Use ports() to access the complete DataFlowInterface functionality of this TaskContext.

typedef boost::function< void(base::PortInterface *) SlotFunction )
base::PortInterfaceaddPort (const std::string &name, base::PortInterface &port)
base::PortInterfaceaddPort (base::PortInterface &port)
base::InputPortInterfaceaddEventPort (const std::string &name, base::InputPortInterface &port, SlotFunction callback=SlotFunction())
base::InputPortInterfaceaddEventPort (base::InputPortInterface &port, SlotFunction callback=SlotFunction())
base::PortInterfacegetPort (const std::string &name) const
DataFlowInterfaceports ()
const DataFlowInterfaceports () const
virtual bool connectPorts (TaskContext *peer)

Detailed Description

The TaskContext is the C++ representation of an Orocos component. It defines which services it provides and requires and which ports are inputs and outputs. It can be configured through the means of properties.

TaskContext interface
You can define the interface of a TaskContext by adding interface primitives. These are (data flow) ports, (configuration) properties and operations (functions). Setting up the interface is explained at length in the Orocos Component Builder's Manual.
TaskContext state behaviour
When a TaskContext is created it defaults to the 'Stopped' state or the 'PreOperational' state. If it is 'Stopped', it can be start()'ed. If it is 'PreOperational', it must first be configure()'d before it can be started. You can choose between both using the constructor.
See also:
TaskState (in base::TaskCore) for a detailed explanation.
Executing a TaskContext
In order to run the ExecutionEngine, the ExecutionEngine must be run by an base::ActivityInterface implementation. As long as there is no activity or the activity is not started, this TaskContext will not accept any asynchronous invocations, nor execute programs or state machines.
Connecting TaskContexts
TaskContexts are connected using the unidirectional addPeer() or bidirectional RTT::connectPeers() methods. These methods only allow 'peer' TaskContexts to use each other's interface. Use RTT::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.

In day-to-day use, TaskContexts are connected using the OCL::DeploymentComponent and an XML file or script.

Definition at line 93 of file TaskContext.hpp.


Member Typedef Documentation

typedef std::map<std::string, boost::shared_ptr<ServiceRequester> > RTT::TaskContext::LocalServices [private]

Definition at line 669 of file TaskContext.hpp.

typedef std::vector< std::string > RTT::TaskContext::PeerList

A list of Peer TaskContext names.

Definition at line 100 of file TaskContext.hpp.

typedef std::map< std::string, TaskContext* > RTT::TaskContext::PeerMap [private]

Definition at line 605 of file TaskContext.hpp.

typedef boost::function<void(base::PortInterface*) RTT::TaskContext::SlotFunction)

Definition at line 537 of file TaskContext.hpp.

Definition at line 631 of file TaskContext.hpp.

typedef std::vector< TaskContext* > RTT::TaskContext::Users [private]

Definition at line 606 of file TaskContext.hpp.


Constructor & Destructor Documentation

RTT::TaskContext::TaskContext ( const std::string &  name,
TaskState  initial_state = Stopped 
)

Create a TaskContext. It's ExecutionEngine will be newly constructed with private processing of commands, events, programs and state machines.

Parameters:
nameThe name of this component.
initial_stateProvide the PreOperational parameter flag here to force users in calling configure(), before they call start().

Definition at line 70 of file TaskContext.cpp.

RTT::TaskContext::TaskContext ( const std::string &  name,
ExecutionEngine parent,
TaskState  initial_state = Stopped 
)

Create a TaskContext. 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).

Parameters:
nameThe name of this component.
initial_stateProvide the PreOperational parameter flag here to force users in calling configure(), before they call start().

Definition at line 83 of file TaskContext.cpp.

Definition at line 126 of file TaskContext.cpp.


Member Function Documentation

template<class T >
bool RTT::TaskContext::addAttribute ( const std::string &  name,
T &  attr 
) [inline]

Adds a variable of any type as read/write attribute to the attribute interface. An Alias is created which causes contents of the attr variable always to be in sync with the contents of the attribute object in the interface.

Parameters:
nameThe name of this attribute
attrThe variable that will be aliased.

Definition at line 411 of file TaskContext.hpp.

Add an base::AttributeBase which remains owned by the user. This is a low-level function that can be used if you already created an Attribute object that does not belong yet to a service.

Parameters:
aremains owned by the user, and becomes served by the repository.

Definition at line 437 of file TaskContext.hpp.

template<class T >
bool RTT::TaskContext::addConstant ( const std::string &  name,
const T &  attr 
) [inline]

Adds a variable of any type as read-only attribute to the attribute interface. An Alias is created which causes contents of the attribute always to be in sync with the contents of attr, but it can only be read through the interface.

Parameters:
nameThe name of this attribute
attrThe variable that will be aliased.

Definition at line 424 of file TaskContext.hpp.

base::InputPortInterface& RTT::TaskContext::addEventPort ( const std::string &  name,
base::InputPortInterface port,
SlotFunction  callback = SlotFunction() 
) [inline]

Name and add an Event triggering Port to the interface of this task and add a Service with the same name of the port.

Parameters:
nameThe name to give to the port.
portThe port to add.
callback(Optional) provide a function which will be called asynchronously when new data arrives on this port. You can add more functions by using the port directly using base::PortInterface::getNewDataOnPort().

Definition at line 547 of file TaskContext.hpp.

Add an Event triggering Port to the interface of this task and add a Service with the same name of the port.

Parameters:
portThe port to add.
callback(Optional) provide a function which will be called asynchronously when new data arrives on this port. You can add more functions by using the port directly using base::PortInterface::getNewDataOnPort().

Definition at line 560 of file TaskContext.hpp.

template<class Signature >
Operation<Signature>& RTT::TaskContext::addOperation ( Operation< Signature > &  op) [inline]

Add an operation object to the interface. This version of addOperation exports an Operation object to the public interface of this component.

Parameters:
opThe operation object to add.
Returns:
true if it could be added.

Definition at line 347 of file TaskContext.hpp.

template<class Func , class Service >
Operation< typename internal::GetSignature<Func>::Signature >& RTT::TaskContext::addOperation ( const std::string  name,
Func  func,
Service serv,
ExecutionThread  et = ClientThread 
) [inline]

Adds a C++ function as an operation.

See also:
Service::addOperation

Definition at line 358 of file TaskContext.hpp.

template<class Signature >
Operation< Signature >& RTT::TaskContext::addOperation ( const std::string  name,
Signature *  func,
ExecutionThread  et = ClientThread 
) [inline]

Adds a C function as an operation.

See also:
Service::addOperation

Definition at line 369 of file TaskContext.hpp.

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

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

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

Reimplemented in RTT::corba::TaskContextProxy.

Definition at line 252 of file TaskContext.cpp.

base::PortInterface& RTT::TaskContext::addPort ( const std::string &  name,
base::PortInterface port 
) [inline]

Name and add a Port to the interface of this task and add a Service with the same name of the port.

Parameters:
nameThe name to give to the port.
portThe port to add.

Definition at line 523 of file TaskContext.hpp.

Add a Port to the interface of this task and add a Service with the same name of the port.

Parameters:
portThe port to add.

Definition at line 533 of file TaskContext.hpp.

template<class T >
Property<T>& RTT::TaskContext::addProperty ( const std::string &  name,
T &  attr 
) [inline]

Adds a variable of any type as a property to the attribute interface. A Property is created which causes contents of the property always to be in sync with the contents of attr.

Parameters:
nameThe name of this property
attrThe variable that will be aliased.
Returns:
the Property object by reference, which you can further query or document.

Definition at line 479 of file TaskContext.hpp.

Add an base::PropertyBase as a property.

Returns:
false if a property with the same name already exists.

Definition at line 487 of file TaskContext.hpp.

void RTT::TaskContext::addUser ( TaskContext user) [private]

Inform this TaskContext that user is using our services.

Definition at line 239 of file TaskContext.cpp.

Returns the attributes of this TaskContext as an ConfigurationInterface.

Definition at line 458 of file TaskContext.hpp.

void RTT::TaskContext::clear ( ) [virtual]

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.

Definition at line 380 of file TaskContext.cpp.

bool RTT::TaskContext::connectPeers ( TaskContext peer) [virtual]

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

Reimplemented in RTT::corba::TaskContextProxy.

Definition at line 282 of file TaskContext.cpp.

bool RTT::TaskContext::connectPorts ( TaskContext peer) [virtual]

Add a data flow connection from this task's ports to a peer's ports.

Reimplemented in RTT::corba::TaskContextProxy.

Definition at line 154 of file TaskContext.cpp.

bool RTT::TaskContext::connectServices ( TaskContext peer) [virtual]

Connects all requires/provides services of this component to these of a peer.

Reimplemented in RTT::corba::TaskContextProxy.

Definition at line 191 of file TaskContext.cpp.

This callback is called each time data arrived on an event port.

Definition at line 421 of file TaskContext.cpp.

Function to call in the thread of this component if data on the given port arrives.

Definition at line 427 of file TaskContext.cpp.

Inform that a given port will no longer raise dataOnPort() events.

Definition at line 433 of file TaskContext.cpp.

bool RTT::TaskContext::dataOnPortSize ( unsigned int  max) [private]

Called to inform us of the number of possible ports that will trigger a dataOnPort event.

Returns:
false if this->isRunning().
void RTT::TaskContext::disconnect ( ) [virtual]

Disconnect this TaskContext from it's peers and ports. All its Data Flow Ports are disconnected as well. This method invokes removePeer() as well on the peers listed in this->getPeerList().

Definition at line 292 of file TaskContext.cpp.

void RTT::TaskContext::disconnectPeers ( const std::string &  name) [virtual]

Remove a two-way connection from this task to a peer task.

Reimplemented in RTT::corba::TaskContextProxy.

Definition at line 313 of file TaskContext.cpp.

Forces the current activity to become new_act, even if this TaskContext is still running.

This can be used to bypass the isRunning() check regular setActivity() does.

Definition at line 362 of file TaskContext.cpp.

Get a pointer to the activity running this component.

Returns:
Our activity.

Definition at line 373 of file TaskContext.cpp.

template<typename T >
T* RTT::TaskContext::getActivity ( ) [inline]

Get a pointer to the activity running this component.

Unlike the non-template version, it converts it to the activity type provided.

Example usage in a startHook(): RTT::extras::FileDescriptorActivity* fd_activity = getActivity<RTT::extras::FileDescriptorActivity>(); if (fd_activity) { // do specific setup for FDActivity }

Returns:
Our activity if it is of type T, NULL otherwise.

Definition at line 173 of file TaskContext.hpp.

base::AttributeBase* RTT::TaskContext::getAttribute ( const std::string &  name) const [inline]

Definition at line 450 of file TaskContext.hpp.

virtual const std::string& RTT::TaskContext::getName ( ) const [inline, virtual]

Returns the name of this TaskContext.

Definition at line 128 of file TaskContext.hpp.

OperationInterfacePart* RTT::TaskContext::getOperation ( std::string  name) [inline]

Get a previously added operation for use in a C++ OperationCaller object. Store the result of this function in a OperationCaller<Signature> object.

Parameters:
nameThe name of the operation to retrieve.
Returns:
true if it could be found, false otherwise.

Definition at line 383 of file TaskContext.hpp.

TaskContext * RTT::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 RTT::corba::TaskContextProxy.

Definition at line 336 of file TaskContext.cpp.

std::vector< std::string > RTT::TaskContext::getPeerList ( ) const [virtual]

Return a standard container which contains all the Peer names of this TaskContext.

Reimplemented in RTT::corba::TaskContextProxy.

Definition at line 322 of file TaskContext.cpp.

base::PortInterface* RTT::TaskContext::getPort ( const std::string &  name) const [inline]

Get a port of this Component.

Parameters:
nameThe port name
Returns:
a pointer to a port or null if it does not exist.

Definition at line 569 of file TaskContext.hpp.

base::PropertyBase* RTT::TaskContext::getProperty ( const std::string &  name) const [inline]

Get a Property with name name.

Parameters:
nameThe name of the property to search for.
Returns:
The Property with this name, zero if it does not exist

Definition at line 498 of file TaskContext.hpp.

template<class ServiceType >
boost::shared_ptr<ServiceType> RTT::TaskContext::getProvider ( const std::string &  name) [inline]

Use this method to be able to make OperationCaller calls to services provided by this component. In case the service does not exist in this component, it tries to load the service using the plugin::PluginLoader class. If all fails, a null pointer is returned.

For example: getProvider<Scripting>("scripting")->loadPrograms("file.ops");

Parameters:
nameThe name of the service to get, must have been added with addService.
ServiceTypethe ServiceRequester type to use. Must have a constructor that takes TaskContext* as argument.
Returns:
a shared ServiceRequester object which allows to call the operations provided by service name.

Definition at line 309 of file TaskContext.hpp.

bool RTT::TaskContext::hasPeer ( const std::string &  peer_name) const [virtual]

Return true if it knows a peer by that name.

Reimplemented in RTT::corba::TaskContextProxy.

Definition at line 331 of file TaskContext.cpp.

bool RTT::TaskContext::loadService ( const std::string &  service_name)

Use this method to load a service known to RTT into this component.

Parameters:
service_nameThe name with which the service is registered by in the PluginLoader.
Returns:
true if the service was present already or could be loaded.

Definition at line 233 of file TaskContext.cpp.

Returns the operations of this TaskContext as an OperationInterface.

Definition at line 391 of file TaskContext.hpp.

Get the Data flow ports of this task.

Definition at line 577 of file TaskContext.hpp.

const DataFlowInterface* RTT::TaskContext::ports ( ) const [inline]

Get the Data flow ports of this task.

Definition at line 584 of file TaskContext.hpp.

bool RTT::TaskContext::prepareProvide ( const std::string &  name) [private]

Check if this component could provide a given service, either by already providing it (hasService(name)==true), or by loading its service. If this function returns true, getProvider() will return a non-null object given the correct ServiceType.

Definition at line 229 of file TaskContext.cpp.

void RTT::TaskContext::prepareUpdateHook ( ) [private, virtual]

Function that is called before updateHook, where the TC implementation can do bookkeeping with regard to event ports.

Reimplemented from RTT::base::TaskCore.

Definition at line 441 of file TaskContext.cpp.

Returns the properties of this TaskContext as a PropertyBag.

Definition at line 506 of file TaskContext.hpp.

Returns this Service.

Returns:
a shared pointer from this.

Definition at line 268 of file TaskContext.hpp.

Service::shared_ptr RTT::TaskContext::provides ( const std::string &  service_name) [inline]

Returns a sub-Service which resorts under this Service.

Parameters:
service_nameThe name of the sub-service.

Definition at line 275 of file TaskContext.hpp.

bool RTT::TaskContext::ready ( ) [virtual]

Checks the validity of this TaskContext. When this method returns false, the TaskContext should not be used and various methods may throw exceptions. Use this in case the TaskContext could be a remote object. Will always return true when this TaskContext is local.

Reimplemented in RTT::corba::TaskContextProxy.

Definition at line 385 of file TaskContext.cpp.

void RTT::TaskContext::removePeer ( const std::string &  name) [virtual]

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

Reimplemented in RTT::corba::TaskContextProxy.

Definition at line 263 of file TaskContext.cpp.

void RTT::TaskContext::removePeer ( TaskContext peer) [virtual]

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

Reimplemented in RTT::corba::TaskContextProxy.

Definition at line 272 of file TaskContext.cpp.

void RTT::TaskContext::removeUser ( TaskContext user) [private]

Inform this TaskContext that user is no longer using our services.

Definition at line 245 of file TaskContext.cpp.

Returns the object that manages which methods this Task requires to be implemented by another task.

Definition at line 281 of file TaskContext.hpp.

ServiceRequester::shared_ptr RTT::TaskContext::requires ( const std::string &  service_name) [inline]

Returns the object that manages which methods this Task requires to be implemented by another service.

Definition at line 287 of file TaskContext.hpp.

Sets the activity of this TaskContext. The activity is owned by the TaskContext and you should not hold a pointer to it after this call. Use getActivity() lateron to retrieve a safe pointer to it.

Parameters:
new_actThe new activity for this TaskContext, which becomes owned by this TaskContext, in case this method returns true.
Returns:
false if this->isRunning(). You can not change the activity of a TaskContext once it is running. In that case, new_act is not destroyed.
Note:
This function may not be called from the current ExecutionEngine thread (OwnThread), another thread (ClientThread) must call this function.

Definition at line 343 of file TaskContext.cpp.

void RTT::TaskContext::setup ( ) [private]

Internal function to setup the 'this' service and activity.

Definition at line 96 of file TaskContext.cpp.

bool RTT::TaskContext::start ( ) [virtual]

This method starts the execution of the updateHook() with each trigger or period. This function calls the user function startHook(), which must return true in order to allow this component to run.

Return values:
false
  • if startHook() returned false
  • if the component was not Stopped
trueif the Running state was entered.

Reimplemented from RTT::base::TaskCore.

Reimplemented in RTT::corba::TaskContextProxy.

Definition at line 398 of file TaskContext.cpp.

bool RTT::TaskContext::stop ( ) [virtual]

This method stops the execution of updateHook() of this component. You can override this method to do something else or in addition. This function calls stopHook() as well.

Returns:
false if the component was not Running or not Active.

Reimplemented from RTT::base::TaskCore.

Reimplemented in RTT::corba::TaskContextProxy.

Definition at line 408 of file TaskContext.cpp.


Friends And Related Function Documentation

friend class DataFlowInterface [friend]

Definition at line 629 of file TaskContext.hpp.


Member Data Documentation

map of the tasks we are using

Definition at line 608 of file TaskContext.hpp.

Definition at line 670 of file TaskContext.hpp.

Definition at line 674 of file TaskContext.hpp.

map of the tasks that are using us.

Definition at line 610 of file TaskContext.hpp.

This pointer tracks our activity which is set by setActivity. By default, a extras::SequentialActivity is assigned.

Definition at line 683 of file TaskContext.hpp.

Definition at line 630 of file TaskContext.hpp.

Definition at line 673 of file TaskContext.hpp.

Definition at line 672 of file TaskContext.hpp.

Definition at line 632 of file TaskContext.hpp.


The documentation for this class was generated from the following files:


rtt
Author(s): RTT Developers
autogenerated on Wed Aug 26 2015 16:16:23