#include <TaskContext.hpp>
Public Types | |
typedef std::vector< std::string > | PeerList |
Public Types inherited from RTT::base::TaskCore | |
enum | TaskState { Init, PreOperational, FatalError, Exception, Stopped, Running, RunTimeError } |
Public Member Functions | |
virtual void | clear () |
base::ActivityInterface * | getActivity () |
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) | |
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::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) |
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 () |
Public Member Functions inherited from RTT::base::TaskCore | |
const ExecutionEngine * | engine () const |
ExecutionEngine * | engine () |
unsigned int | getCycleCounter () const |
unsigned int | getIOCounter () const |
virtual TaskState | getTargetState () const |
virtual TaskState | getTaskState () const |
unsigned int | getTimeOutCounter () const |
unsigned int | getTriggerCounter () const |
TaskCore (TaskState initial_state=Stopped, const std::string &name=std::string()) | |
virtual | ~TaskCore () |
virtual bool | configure () |
virtual bool | activate () |
virtual bool | cleanup () |
virtual bool | isConfigured () const |
virtual bool | isActive () const |
virtual bool | isRunning () const |
virtual Seconds | getPeriod () const |
virtual bool | setPeriod (Seconds s) |
virtual unsigned | getCpuAffinity () const |
virtual bool | setCpuAffinity (unsigned cpu) |
virtual bool | inFatalError () const |
virtual bool | inException () const |
virtual bool | inRunTimeError () const |
virtual bool | update () |
virtual bool | trigger () |
virtual void | error () |
virtual bool | recover () |
Protected Member Functions | |
virtual void | dataOnPortCallback (base::PortInterface *port) |
virtual bool | dataOnPortHook (base::PortInterface *port) |
void | forceActivity (base::ActivityInterface *new_act) |
Protected Member Functions inherited from RTT::base::TaskCore | |
virtual bool | breakUpdateHook () |
virtual void | cleanupHook () |
virtual bool | configureHook () |
virtual void | errorHook () |
virtual void | exception () |
virtual void | exceptionHook () |
virtual void | fatal () |
virtual bool | startHook () |
virtual void | stopHook () |
virtual void | updateHook () |
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) |
bool | prepareProvide (const std::string &name) |
void | removeDataOnPortCallback (base::PortInterface *port) |
void | removeUser (TaskContext *user) |
void | setDataOnPortCallback (base::InputPortInterface *port, SlotFunction callback) |
void | setup () |
TaskContext (TaskContext &) | |
Private Attributes | |
PeerMap | _task_map |
map of the tasks we are using More... | |
LocalServices | localservs |
os::Mutex | mportlock |
Users | musers |
map of the tasks that are using us. More... | |
base::ActivityInterface::shared_ptr | our_act |
ServiceRequester::shared_ptr | tcrequests |
Service::shared_ptr | tcservice |
UserCallbacks | user_callbacks |
Friends | |
class | DataFlowInterface |
class | ExecutionEngine |
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) |
Additional Inherited Members | |
Protected Attributes inherited from RTT::base::TaskCore | |
ExecutionEngine * | ee |
unsigned int | mCycleCounter |
unsigned int | mIOCounter |
std::string | mName |
TaskState | mTaskState |
unsigned int | mTimeOutCounter |
unsigned int | mTriggerCounter |
bool | mTriggerOnStart |
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.
|
private |
Definition at line 680 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.
|
private |
Definition at line 627 of file TaskContext.hpp.
typedef boost::function<void(base::PortInterface*)> RTT::TaskContext::SlotFunction |
Definition at line 527 of file TaskContext.hpp.
|
private |
Definition at line 652 of file TaskContext.hpp.
|
private |
Definition at line 628 of file TaskContext.hpp.
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.
|
virtual |
Definition at line 119 of file TaskContext.cpp.
|
private |
|
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 401 of file TaskContext.hpp.
|
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 427 of file TaskContext.hpp.
|
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 414 of file TaskContext.hpp.
|
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 537 of file TaskContext.hpp.
|
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 550 of file TaskContext.hpp.
|
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 337 of file TaskContext.hpp.
|
inline |
Adds a C++ function as an operation.
Definition at line 348 of file TaskContext.hpp.
|
inline |
Adds a C function as an operation.
Definition at line 359 of file TaskContext.hpp.
|
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 249 of file TaskContext.cpp.
|
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 513 of file TaskContext.hpp.
|
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 523 of file TaskContext.hpp.
|
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 469 of file TaskContext.hpp.
|
inline |
Add an base::PropertyBase as a property.
Definition at line 477 of file TaskContext.hpp.
|
private |
Inform this TaskContext that user is using our services.
Definition at line 236 of file TaskContext.cpp.
|
inline |
Returns the attributes of this TaskContext as an ConfigurationInterface.
Definition at line 448 of file TaskContext.hpp.
|
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 397 of file TaskContext.cpp.
|
virtual |
Add a two-way connection from this task to a peer task.
Reimplemented in RTT::corba::TaskContextProxy.
Definition at line 279 of file TaskContext.cpp.
|
virtual |
Add a data flow connection from this task's ports to a peer's ports.
Reimplemented in RTT::corba::TaskContextProxy.
Definition at line 151 of file TaskContext.cpp.
|
virtual |
Connects all requires/provides services of this component to these of a peer.
Reimplemented in RTT::corba::TaskContextProxy.
Definition at line 188 of file TaskContext.cpp.
|
private |
This callback is called each time data arrived on an event port.
Definition at line 439 of file TaskContext.cpp.
|
protectedvirtual |
This method implements port callbacks. It will be called once per sample received on the port and is executed in the component's thread.
The default implementation invokes the user callback if one was given in the addEventPort() call. It can be overwritten in a subclass to react on incoming data for all event ports. This is equivalent to adding this function as a user callback on each of the ports individually.
Definition at line 450 of file TaskContext.cpp.
|
protectedvirtual |
Reimplement this method to influence how writing to event ports is handled by the component. This method will be executed in the writer's thread.
The default implementation returns true if and only if the component is running.
true | to indicate that the user callback should be invoked and trigger the component |
false | to ignore the new data and not trigger the component or invoke a user callback |
Definition at line 446 of file TaskContext.cpp.
|
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 289 of file TaskContext.cpp.
|
virtual |
Remove a two-way connection from this task to a peer task.
Reimplemented in RTT::corba::TaskContextProxy.
Definition at line 310 of file TaskContext.cpp.
|
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 377 of file TaskContext.cpp.
ActivityInterface * RTT::TaskContext::getActivity | ( | ) |
Get a pointer to the activity running this component.
Definition at line 390 of file TaskContext.cpp.
|
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 163 of file TaskContext.hpp.
|
inline |
Definition at line 440 of file TaskContext.hpp.
|
inlinevirtual |
Returns the name of this TaskContext.
Definition at line 117 of file TaskContext.hpp.
|
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 373 of file TaskContext.hpp.
|
virtual |
Get a pointer to a peer of this task.
Reimplemented in RTT::corba::TaskContextProxy.
Definition at line 333 of file TaskContext.cpp.
|
virtual |
Return a standard container which contains all the Peer names of this TaskContext.
Reimplemented in RTT::corba::TaskContextProxy.
Definition at line 319 of file TaskContext.cpp.
|
inline |
Get a port of this Component.
name | The port name |
Definition at line 559 of file TaskContext.hpp.
|
inline |
Get a Property with name name.
name | The name of the property to search for. |
Definition at line 488 of file TaskContext.hpp.
|
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 299 of file TaskContext.hpp.
|
virtual |
Return true if it knows a peer by that name.
Reimplemented in RTT::corba::TaskContextProxy.
Definition at line 328 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 230 of file TaskContext.cpp.
|
inline |
Returns the operations of this TaskContext as an OperationInterface.
Definition at line 381 of file TaskContext.hpp.
|
inline |
Get the Data flow ports of this task.
Definition at line 567 of file TaskContext.hpp.
|
inline |
Get the Data flow ports of this task.
Definition at line 574 of file TaskContext.hpp.
|
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 226 of file TaskContext.cpp.
|
inline |
Returns the properties of this TaskContext as a PropertyBag.
Definition at line 496 of file TaskContext.hpp.
|
inline |
Returns this Service.
Definition at line 258 of file TaskContext.hpp.
|
inline |
Returns a sub-Service which resorts under this Service.
service_name | The name of the sub-service. |
Definition at line 265 of file TaskContext.hpp.
|
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, and OperationCallerComponent.
Definition at line 403 of file TaskContext.cpp.
|
private |
Inform that a given port will no longer raise dataOnPort() events.
Definition at line 462 of file TaskContext.cpp.
|
virtual |
Remove a one-way connection from this task to a peer task.
Reimplemented in RTT::corba::TaskContextProxy.
Definition at line 260 of file TaskContext.cpp.
|
virtual |
Remove a one-way connection from this task to a peer task.
Reimplemented in RTT::corba::TaskContextProxy.
Definition at line 269 of file TaskContext.cpp.
|
private |
Inform this TaskContext that user is no longer using our services.
Definition at line 242 of file TaskContext.cpp.
|
inline |
Returns the object that manages which methods this Task requires to be implemented by another task.
Definition at line 271 of file TaskContext.hpp.
|
inline |
Returns the object that manages which methods this Task requires to be implemented by another service.
Definition at line 277 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 340 of file TaskContext.cpp.
|
private |
Function to call in the thread of this component if data on the given port arrives.
Definition at line 456 of file TaskContext.cpp.
|
private |
Internal function to setup the 'this' service and activity.
Definition at line 82 of file TaskContext.cpp.
|
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 416 of file TaskContext.cpp.
|
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 426 of file TaskContext.cpp.
|
friend |
Definition at line 651 of file TaskContext.hpp.
|
friend |
Definition at line 623 of file TaskContext.hpp.
|
private |
map of the tasks we are using
Definition at line 630 of file TaskContext.hpp.
|
private |
Definition at line 681 of file TaskContext.hpp.
|
private |
Definition at line 685 of file TaskContext.hpp.
|
private |
map of the tasks that are using us.
Definition at line 632 of file TaskContext.hpp.
|
private |
This pointer tracks our activity which is set by setActivity. By default, a extras::SequentialActivity is assigned.
Definition at line 694 of file TaskContext.hpp.
|
private |
Definition at line 684 of file TaskContext.hpp.
|
private |
Definition at line 683 of file TaskContext.hpp.
|
private |
Definition at line 653 of file TaskContext.hpp.