#include <TaskContext.hpp>
Public Types | |
typedef std::vector< std::string > | PeerList |
Public Member Functions | |
virtual void | clear () |
base::ActivityInterface * | getActivity () |
template<typename T > | |
T * | getActivity () |
virtual const std::string & | getName () |
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 TaskContext * | getPeer (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 * | requires () |
ServiceRequester * | 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) |
OperationInterfacePart * | getOperation (std::string name) |
OperationInterface * | operations () |
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::AttributeBase * | getAttribute (const std::string &name) const |
ConfigurationInterface * | attributes () |
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::PropertyBase * | getProperty (const std::string &name) const |
PropertyBag * | properties () |
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 * | 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::PortInterface & | addPort (const std::string &name, base::PortInterface &port) |
base::PortInterface & | addPort (base::PortInterface &port) |
base::InputPortInterface & | addEventPort (const std::string &name, base::InputPortInterface &port, SlotFunction callback=SlotFunction()) |
base::InputPortInterface & | addEventPort (base::InputPortInterface &port, SlotFunction callback=SlotFunction()) |
base::PortInterface * | getPort (const std::string &name) const |
DataFlowInterface * | ports () |
const DataFlowInterface * | ports () const |
virtual bool | connectPorts (TaskContext *peer) |
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.
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.
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.
typedef std::map<base::PortInterface*, SlotFunction > RTT::TaskContext::UserCallbacks [private] |
Definition at line 631 of file TaskContext.hpp.
typedef std::vector< TaskContext* > RTT::TaskContext::Users [private] |
Definition at line 606 of file TaskContext.hpp.
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.
name | The name of this component. |
initial_state | Provide 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).
name | The name of this component. |
initial_state | Provide the PreOperational parameter flag here to force users in calling configure(), before they call start(). |
Definition at line 83 of file TaskContext.cpp.
RTT::TaskContext::~TaskContext | ( | ) | [virtual] |
Definition at line 126 of file TaskContext.cpp.
RTT::TaskContext::TaskContext | ( | TaskContext & | ) | [private] |
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.
name | The name of this attribute |
attr | The variable that will be aliased. |
Definition at line 411 of file TaskContext.hpp.
bool RTT::TaskContext::addAttribute | ( | base::AttributeBase & | a | ) | [inline] |
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.
a | remains owned by the user, and becomes served by the repository. |
Definition at line 437 of file TaskContext.hpp.
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.
name | The name of this attribute |
attr | The 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.
name | The name to give to the port. |
port | The 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.
base::InputPortInterface& RTT::TaskContext::addEventPort | ( | base::InputPortInterface & | port, |
SlotFunction | callback = SlotFunction() |
||
) | [inline] |
Add an Event triggering Port to the interface of this task and add a Service with the same name of the port.
port | The 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.
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.
op | The operation object to add. |
Definition at line 347 of file TaskContext.hpp.
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.
Definition at line 358 of file TaskContext.hpp.
Operation< Signature >& RTT::TaskContext::addOperation | ( | const std::string | name, |
Signature * | func, | ||
ExecutionThread | et = ClientThread |
||
) | [inline] |
Adds a C function as an operation.
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.
peer | The peer to add. |
alias | An 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.
name | The name to give to the port. |
port | The port to add. |
Definition at line 523 of file TaskContext.hpp.
base::PortInterface& RTT::TaskContext::addPort | ( | base::PortInterface & | port | ) | [inline] |
Add a Port to the interface of this task and add a Service with the same name of the port.
port | The port to add. |
Definition at line 533 of file TaskContext.hpp.
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.
name | The name of this property |
attr | The variable that will be aliased. |
Definition at line 479 of file TaskContext.hpp.
bool RTT::TaskContext::addProperty | ( | base::PropertyBase & | pb | ) | [inline] |
Add an base::PropertyBase as a property.
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.
ConfigurationInterface* RTT::TaskContext::attributes | ( | ) | [inline] |
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.
void RTT::TaskContext::dataOnPort | ( | base::PortInterface * | port | ) | [private] |
This callback is called each time data arrived on an event port.
Definition at line 421 of file TaskContext.cpp.
void RTT::TaskContext::dataOnPortCallback | ( | base::InputPortInterface * | port, |
TaskContext::SlotFunction | callback | ||
) | [private] |
Function to call in the thread of this component if data on the given port arrives.
Definition at line 427 of file TaskContext.cpp.
void RTT::TaskContext::dataOnPortRemoved | ( | base::PortInterface * | port | ) | [private] |
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.
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.
void RTT::TaskContext::forceActivity | ( | base::ActivityInterface * | new_act | ) | [protected] |
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.
Definition at line 373 of file TaskContext.cpp.
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 }
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 | ( | ) | [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.
name | The name of the operation to retrieve. |
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.
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.
name | The port name |
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.
name | The name of the property to search for. |
Definition at line 498 of file TaskContext.hpp.
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");
name | The name of the service to get, must have been added with addService. |
ServiceType | the ServiceRequester type to use. Must have a constructor that takes TaskContext* as argument. |
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.
service_name | The name with which the service is registered by in the PluginLoader. |
Definition at line 233 of file TaskContext.cpp.
OperationInterface* RTT::TaskContext::operations | ( | ) | [inline] |
Returns the operations of this TaskContext as an OperationInterface.
Definition at line 391 of file TaskContext.hpp.
DataFlowInterface* RTT::TaskContext::ports | ( | ) | [inline] |
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.
PropertyBag* RTT::TaskContext::properties | ( | ) | [inline] |
Returns the properties of this TaskContext as a PropertyBag.
Definition at line 506 of file TaskContext.hpp.
Service::shared_ptr RTT::TaskContext::provides | ( | ) | [inline] |
Returns this Service.
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.
service_name | The 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.
ServiceRequester* RTT::TaskContext::requires | ( | ) | [inline] |
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* 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.
bool RTT::TaskContext::setActivity | ( | base::ActivityInterface * | new_act | ) |
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.
new_act | The new activity for this TaskContext, which becomes owned by this TaskContext, in case this method returns true. |
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 | ( | void | ) | [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.
false |
|
true | if 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 | ( | void | ) | [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.
Reimplemented from RTT::base::TaskCore.
Reimplemented in RTT::corba::TaskContextProxy.
Definition at line 408 of file TaskContext.cpp.
friend class DataFlowInterface [friend] |
Definition at line 629 of file TaskContext.hpp.
PeerMap RTT::TaskContext::_task_map [private] |
map of the tasks we are using
Definition at line 608 of file TaskContext.hpp.
LocalServices RTT::TaskContext::localservs [private] |
Definition at line 670 of file TaskContext.hpp.
os::Mutex RTT::TaskContext::mportlock [private] |
Definition at line 674 of file TaskContext.hpp.
Users RTT::TaskContext::musers [private] |
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.
ServiceRequester* RTT::TaskContext::tcrequests [private] |
Definition at line 673 of file TaskContext.hpp.
Definition at line 672 of file TaskContext.hpp.
Definition at line 632 of file TaskContext.hpp.