/tmp/ws/src/rtt/rtt/TaskContext.hpp

Retrieve a Attribute by name. Returns zero if no Attribute by that name exists.

Attribute<double> d_attr = getAttribute("Xval");

See also
addAttribute to add an Attribute.
/***************************************************************************
tag: Peter Soetens Tue Dec 21 22:43:08 CET 2004 TaskContext.hpp
TaskContext.hpp - description
-------------------
begin : Tue December 21 2004
copyright : (C) 2004 Peter Soetens
email : peter.soetens@mech.kuleuven.ac.be
***************************************************************************
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public *
* License as published by the Free Software Foundation; *
* version 2 of the License. *
* *
* As a special exception, you may use this file as part of a free *
* software library without restriction. Specifically, if other files *
* instantiate templates or use macros or inline functions from this *
* file, or you compile this file and link it with other files to *
* produce an executable, this file does not by itself cause the *
* resulting executable to be covered by the GNU General Public *
* License. This exception does not however invalidate any other *
* reasons why the executable file might be covered by the GNU General *
* Public License. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU General Public *
* License along with this library; if not, write to the Free Software *
* Foundation, Inc., 59 Temple Place, *
* Suite 330, Boston, MA 02111-1307 USA *
* *
***************************************************************************/
#ifndef ORO_TASK_CONTEXT_HPP
#define ORO_TASK_CONTEXT_HPP
#include "rtt-config.h"
#include "Service.hpp"
#include <boost/make_shared.hpp>
#include <string>
#include <map>
namespace RTT
{
class RTT_API TaskContext
: public base::TaskCore
{
public:
typedef std::vector< std::string > PeerList;
TaskContext( const std::string& name, TaskState initial_state = Stopped );
virtual ~TaskContext();
virtual const std::string& getName() const { return tcservice->getName(); }
bool setActivity( base::ActivityInterface* new_act );
base::ActivityInterface* getActivity();
template<typename T>
T* getActivity() { return dynamic_cast<T*>(getActivity()); }
virtual void clear();
virtual bool ready();
virtual bool start();
virtual bool stop();
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;
Service::shared_ptr provides() { return tcservice; }
Service::shared_ptr provides(const std::string& service_name) { return tcservice->provides(service_name); }
ServiceRequester::shared_ptr requires() { return tcrequests; }
ServiceRequester::shared_ptr requires(const std::string& service_name) {
return tcrequests->requires(service_name);
}
virtual bool connectServices( TaskContext* peer);
template<class ServiceType>
boost::shared_ptr<ServiceType> getProvider(const std::string& name) {
if (!prepareProvide(name)) return boost::shared_ptr<ServiceType>();
LocalServices::iterator it = localservs.find(name);
if ( it != localservs.end() ) {
return boost::dynamic_pointer_cast<ServiceType>(it->second);
}
boost::shared_ptr<ServiceType> st = boost::make_shared<ServiceType>(this);
st->connectTo( provides(name) );
localservs[name] = st;
return st;
}
bool loadService(const std::string& service_name);
template<class Signature>
Operation<Signature>& addOperation( Operation<Signature>& op )
{
return tcservice->addOperation(op);
}
template<class Func, class Service>
Operation< typename internal::GetSignature<Func>::Signature >&
addOperation( const std::string name, Func func, Service* serv, ExecutionThread et = ClientThread )
{
return tcservice->addOperation(name,func, serv, et);
}
template<class Signature>
Operation< Signature >&
addOperation( const std::string name, Signature* func, ExecutionThread et = ClientThread )
{
return tcservice->addOperation(name, func, et);
}
OperationInterfacePart* getOperation( std::string name )
{
return tcservice->getOperation(name);
}
OperationInterface* operations() { return this->provides().get(); }
template<class T>
bool addAttribute( const std::string& name, T& attr) {
return tcservice->addAttribute(name, attr);
}
template<class T>
bool addConstant( const std::string& name, const T& attr) {
return tcservice->addConstant(name, attr);
}
bool addAttribute( base::AttributeBase& a )
{
return tcservice->addAttribute(a);
}
base::AttributeBase* getAttribute( const std::string& name ) const
{
return tcservice->getAttribute(name);
}
ConfigurationInterface* attributes() { return this->provides().get(); }
template<class T>
Property<T>& addProperty( const std::string& name, T& attr) {
return tcservice->addProperty(name, attr);
}
bool addProperty( base::PropertyBase& pb ) {
return tcservice->addProperty(pb);
}
base::PropertyBase* getProperty(const std::string& name) const
{
return tcservice->getProperty(name);
}
PropertyBag* properties() { return this->provides()->properties(); }
base::PortInterface& addPort(const std::string& name, base::PortInterface& port) {
port.setName(name);
return ports()->addPort(port);
}
base::PortInterface& addPort(base::PortInterface& port) {
return ports()->addPort(port);
}
typedef boost::function<void(base::PortInterface*)> SlotFunction;
base::InputPortInterface& addEventPort(const std::string& name, base::InputPortInterface& port, SlotFunction callback = SlotFunction() ) {
port.setName(name);
return ports()->addEventPort(port,callback);
}
base::InputPortInterface& addEventPort(base::InputPortInterface& port, SlotFunction callback = SlotFunction() ) {
return ports()->addEventPort(port,callback);
}
base::PortInterface* getPort(const std::string& name) const {
return ports()->getPort(name);
}
DataFlowInterface* ports() {
return tcservice.get();
}
const DataFlowInterface* ports() const {
return tcservice.get();
}
virtual bool connectPorts( TaskContext* peer );
protected:
void forceActivity( base::ActivityInterface* new_act);
virtual bool dataOnPortHook( base::PortInterface* port );
virtual void dataOnPortCallback( base::PortInterface* port );
// Required to invoke dataOnPortCallback() from the ExecutionEngine.
friend class ExecutionEngine;
private:
typedef std::map< std::string, TaskContext* > PeerMap;
typedef std::vector< TaskContext* > Users;
PeerMap _task_map;
Users musers;
void addUser(TaskContext* user);
void removeUser(TaskContext* user);
void setup();
friend class DataFlowInterface;
typedef std::map<base::PortInterface*, SlotFunction > UserCallbacks;
UserCallbacks user_callbacks;
void dataOnPort(base::PortInterface* port);
void setDataOnPortCallback(base::InputPortInterface* port, SlotFunction callback);
void removeDataOnPortCallback(base::PortInterface* port);
bool prepareProvide(const std::string& name);
typedef std::map<std::string, boost::shared_ptr<ServiceRequester> > LocalServices;
LocalServices localservs;
os::Mutex mportlock;
// non copyable
TaskContext( TaskContext& );
};
RTT_API bool connectPorts(TaskContext* A, TaskContext* B);
RTT_API bool connectPeers(TaskContext* A, TaskContext* B);
}
#endif


rtt
Author(s): RTT Developers
autogenerated on Fri Oct 25 2019 03:59:30