TaskContext.hpp
Go to the documentation of this file.
1 /***************************************************************************
2  tag: Peter Soetens Tue Dec 21 22:43:08 CET 2004 TaskContext.hpp
3 
4  TaskContext.hpp - description
5  -------------------
6  begin : Tue December 21 2004
7  copyright : (C) 2004 Peter Soetens
8  email : peter.soetens@mech.kuleuven.ac.be
9 
10  ***************************************************************************
11  * This library is free software; you can redistribute it and/or *
12  * modify it under the terms of the GNU General Public *
13  * License as published by the Free Software Foundation; *
14  * version 2 of the License. *
15  * *
16  * As a special exception, you may use this file as part of a free *
17  * software library without restriction. Specifically, if other files *
18  * instantiate templates or use macros or inline functions from this *
19  * file, or you compile this file and link it with other files to *
20  * produce an executable, this file does not by itself cause the *
21  * resulting executable to be covered by the GNU General Public *
22  * License. This exception does not however invalidate any other *
23  * reasons why the executable file might be covered by the GNU General *
24  * Public License. *
25  * *
26  * This library is distributed in the hope that it will be useful, *
27  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
28  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
29  * Lesser General Public License for more details. *
30  * *
31  * You should have received a copy of the GNU General Public *
32  * License along with this library; if not, write to the Free Software *
33  * Foundation, Inc., 59 Temple Place, *
34  * Suite 330, Boston, MA 02111-1307 USA *
35  * *
36  ***************************************************************************/
37 
38 
39 #ifndef ORO_TASK_CONTEXT_HPP
40 #define ORO_TASK_CONTEXT_HPP
41 
42 
43 #include "rtt-config.h"
44 #include "Service.hpp"
45 #include "ServiceRequester.hpp"
46 #include "DataFlowInterface.hpp"
47 #include "ExecutionEngine.hpp"
48 #include "base/TaskCore.hpp"
49 #include <boost/make_shared.hpp>
50 
51 #include <string>
52 #include <map>
53 
54 namespace RTT
55 {
93  class RTT_API TaskContext
94  : public base::TaskCore
95  {
96  public:
100  typedef std::vector< std::string > PeerList;
101 
110  TaskContext( const std::string& name, TaskState initial_state = Stopped );
111 
112  virtual ~TaskContext();
113 
117  virtual const std::string& getName() const { return tcservice->getName(); }
118 
134  bool setActivity( base::ActivityInterface* new_act );
135 
141  base::ActivityInterface* getActivity();
142 
162  template<typename T>
163  T* getActivity() { return dynamic_cast<T*>(getActivity()); }
164 
170  virtual void clear();
171 
180  virtual bool ready();
181 
182  virtual bool start();
183  virtual bool stop();
184 
199  virtual bool addPeer( TaskContext* peer, std::string alias = "" );
200 
204  virtual void removePeer( const std::string& name );
205 
209  virtual void removePeer( TaskContext* peer );
210 
214  virtual bool connectPeers( TaskContext* peer );
215 
221  virtual void disconnect();
222 
226  virtual void disconnectPeers( const std::string& name );
227 
232  virtual PeerList getPeerList() const;
233 
237  virtual bool hasPeer( const std::string& peer_name ) const;
238 
243  virtual TaskContext* getPeer(const std::string& peer_name ) const;
258  Service::shared_ptr provides() { return tcservice; }
259 
265  Service::shared_ptr provides(const std::string& service_name) { return tcservice->provides(service_name); }
266 
271  ServiceRequester::shared_ptr requires() { return tcrequests; }
272 
277  ServiceRequester::shared_ptr requires(const std::string& service_name) {
278  return tcrequests->requires(service_name);
279  }
280 
284  virtual bool connectServices( TaskContext* peer);
285 
298  template<class ServiceType>
299  boost::shared_ptr<ServiceType> getProvider(const std::string& name) {
300  if (!prepareProvide(name)) return boost::shared_ptr<ServiceType>();
301  LocalServices::iterator it = localservs.find(name);
302  if ( it != localservs.end() ) {
303  return boost::dynamic_pointer_cast<ServiceType>(it->second);
304  }
305  boost::shared_ptr<ServiceType> st = boost::make_shared<ServiceType>(this);
306  st->connectTo( provides(name) );
307  localservs[name] = st;
308  return st;
309  }
310 
316  bool loadService(const std::string& service_name);
317 
336  template<class Signature>
338  {
339  return tcservice->addOperation(op);
340  }
341 
346  template<class Func, class Service>
348  addOperation( const std::string name, Func func, Service* serv, ExecutionThread et = ClientThread )
349  {
350  return tcservice->addOperation(name,func, serv, et);
351  }
352 
357  template<class Signature>
359  addOperation( const std::string name, Signature* func, ExecutionThread et = ClientThread )
360  {
361  return tcservice->addOperation(name, func, et);
362  }
363 
374  {
375  return tcservice->getOperation(name);
376  }
377 
381  OperationInterface* operations() { return this->provides().get(); }
382 
400  template<class T>
401  bool addAttribute( const std::string& name, T& attr) {
402  return tcservice->addAttribute(name, attr);
403  }
404 
413  template<class T>
414  bool addConstant( const std::string& name, const T& attr) {
415  return tcservice->addConstant(name, attr);
416  }
417 
428  {
429  return tcservice->addAttribute(a);
430  }
431 
440  base::AttributeBase* getAttribute( const std::string& name ) const
441  {
442  return tcservice->getAttribute(name);
443  }
444 
448  ConfigurationInterface* attributes() { return this->provides().get(); }
449 
468  template<class T>
469  Property<T>& addProperty( const std::string& name, T& attr) {
470  return tcservice->addProperty(name, attr);
471  }
472 
478  return tcservice->addProperty(pb);
479  }
480 
488  base::PropertyBase* getProperty(const std::string& name) const
489  {
490  return tcservice->getProperty(name);
491  }
492 
496  PropertyBag* properties() { return this->provides()->properties(); }
497 
513  base::PortInterface& addPort(const std::string& name, base::PortInterface& port) {
514  port.setName(name);
515  return ports()->addPort(port);
516  }
517 
524  return ports()->addPort(port);
525  }
526 
527  typedef boost::function<void(base::PortInterface*)> SlotFunction;
537  base::InputPortInterface& addEventPort(const std::string& name, base::InputPortInterface& port, SlotFunction callback = SlotFunction() ) {
538  port.setName(name);
539  return ports()->addEventPort(port,callback);
540  }
541 
550  base::InputPortInterface& addEventPort(base::InputPortInterface& port, SlotFunction callback = SlotFunction() ) {
551  return ports()->addEventPort(port,callback);
552  }
553 
559  base::PortInterface* getPort(const std::string& name) const {
560  return ports()->getPort(name);
561  }
562 
563 
568  return tcservice.get();
569  }
570 
574  const DataFlowInterface* ports() const {
575  return tcservice.get();
576  }
577 
581  virtual bool connectPorts( TaskContext* peer );
584  protected:
592  void forceActivity( base::ActivityInterface* new_act);
593 
607  virtual bool dataOnPortHook( base::PortInterface* port );
608 
620  virtual void dataOnPortCallback( base::PortInterface* port );
621 
622  // Required to invoke dataOnPortCallback() from the ExecutionEngine.
623  friend class ExecutionEngine;
624 
625  private:
626 
627  typedef std::map< std::string, TaskContext* > PeerMap;
628  typedef std::vector< TaskContext* > Users;
630  PeerMap _task_map;
632  Users musers;
633 
638  void addUser(TaskContext* user);
639 
644  void removeUser(TaskContext* user);
645 
649  void setup();
650 
651  friend class DataFlowInterface;
652  typedef std::map<base::PortInterface*, SlotFunction > UserCallbacks;
653  UserCallbacks user_callbacks;
654 
659  void dataOnPort(base::PortInterface* port);
660 
664  void setDataOnPortCallback(base::InputPortInterface* port, SlotFunction callback);
665 
669  void removeDataOnPortCallback(base::PortInterface* port);
670 
678  bool prepareProvide(const std::string& name);
679 
680  typedef std::map<std::string, boost::shared_ptr<ServiceRequester> > LocalServices;
681  LocalServices localservs;
682 
686 
687  // non copyable
689 
695  };
696 
702  RTT_API bool connectPorts(TaskContext* A, TaskContext* B);
703 
710  RTT_API bool connectPeers(TaskContext* A, TaskContext* B);
711 }
712 
713 #endif
PeerMap _task_map
map of the tasks we are using
Property< T > & addProperty(const std::string &name, T &attr)
std::map< std::string, TaskContext * > PeerMap
std::vector< TaskContext * > Users
UserCallbacks user_callbacks
const DataFlowInterface * ports() const
base::PortInterface * getPort(const std::string &name) const
Service::shared_ptr provides()
ConfigurationInterface * attributes()
base::InputPortInterface & addEventPort(const std::string &name, base::InputPortInterface &port, SlotFunction callback=SlotFunction())
Users musers
map of the tasks that are using us.
Operation< Signature > & addOperation(const std::string name, Signature *func, ExecutionThread et=ClientThread)
bool addProperty(base::PropertyBase &pb)
OperationInterface * operations()
bool addConstant(const std::string &name, const T &attr)
boost::shared_ptr< ServiceRequester > shared_ptr
Operation< typename internal::GetSignature< Func >::Signature > & addOperation(const std::string name, Func func, Service *serv, ExecutionThread et=ClientThread)
A container for holding references to properties.
Definition: PropertyBag.hpp:96
bool addAttribute(base::AttributeBase &a)
base::InputPortInterface & addEventPort(base::InputPortInterface &port, SlotFunction callback=SlotFunction())
boost::shared_ptr< Service > shared_ptr
Definition: Service.hpp:101
ServiceRequester::shared_ptr requires()
LocalServices localservs
boost::function< void(base::PortInterface *)> SlotFunction
os::Mutex mportlock
DataFlowInterface * ports()
boost::shared_ptr< ActivityInterface > shared_ptr
Service::shared_ptr provides(const std::string &service_name)
Interface to start/stop and query a Activity.
Service::shared_ptr tcservice
base::PortInterface & addPort(const std::string &name, base::PortInterface &port)
A property represents a named value of any type with a description.
Definition: Property.hpp:76
ServiceRequester::shared_ptr tcrequests
base::AttributeBase * getAttribute(const std::string &name) const
std::vector< std::string > PeerList
std::map< base::PortInterface *, SlotFunction > UserCallbacks
bool setName(const std::string &name)
A class for keeping track of Attribute, Constant and Property objects of a TaskContext. It allows plugins and remote components to browse the attributes and properties of a TaskContext.
bool addAttribute(const std::string &name, T &attr)
PropertyBag * properties()
OperationInterfacePart * getOperation(std::string name)
base::PropertyBase * getProperty(const std::string &name) const
base::ActivityInterface::shared_ptr our_act
std::map< std::string, boost::shared_ptr< ServiceRequester > > LocalServices
An object oriented wrapper around a non recursive mutex.
Definition: Mutex.hpp:92
bool connectPorts(TaskContext *A, TaskContext *B)
Contains TaskContext, Activity, OperationCaller, Operation, Property, InputPort, OutputPort, Attribute.
Definition: Activity.cpp:53
Operation< Signature > & addOperation(Operation< Signature > &op)
def attr(e, n)
Definition: svn2log.py:70
Holds all exported operations of a component and is able to produce callers for these operations...
base::PortInterface & addPort(base::PortInterface &port)
bool connectPeers(TaskContext *A, TaskContext *B)
virtual const std::string & getName() const
ExecutionThread
ServiceRequester::shared_ptr requires(const std::string &service_name)
boost::shared_ptr< ServiceType > getProvider(const std::string &name)


rtt
Author(s): RTT Developers
autogenerated on Tue Jun 25 2019 19:33:37