Orocos Real-Time Toolkit  2.8.3
DataFlowInterface.hpp
Go to the documentation of this file.
1 /***************************************************************************
2  tag: Peter Soetens Thu Mar 2 08:30:18 CET 2006 DataFlowInterface.hpp
3 
4  DataFlowInterface.hpp - description
5  -------------------
6  begin : Thu March 02 2006
7  copyright : (C) 2006 Peter Soetens
8  email : peter.soetens@fmtc.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_EXECUTION_DATA_FLOW_INTERFACE_HPP
40 #define ORO_EXECUTION_DATA_FLOW_INTERFACE_HPP
41 
42 #include <vector>
43 #include <map>
44 #include <string>
47 #include "rtt-fwd.hpp"
48 #include <boost/function.hpp>
49 
50 namespace RTT
51 {
52 
60  {
61  public:
65  typedef std::vector<base::PortInterface*> Ports;
66 
70  typedef std::vector<std::string> PortNames;
71 
72  typedef boost::function<void(base::PortInterface*)> SlotFunction;
73 
79  DataFlowInterface(Service* parent = 0 );
80 
82 
89  base::PortInterface& addPort(const std::string& name, base::PortInterface& port) {
90  if ( !chkPtr("addPort", name, &port) ) return port;
91  port.setName(name);
92  return addPort(port);
93  }
94 
104 
114  base::InputPortInterface& addEventPort(const std::string& name, base::InputPortInterface& port, SlotFunction callback = SlotFunction() ) {
115  if ( !chkPtr("addEventPort", name, &port) ) return port;
116  port.setName(name);
117  return addEventPort(port,callback);
118  }
119 
132  base::InputPortInterface& addEventPort(base::InputPortInterface& port, SlotFunction callback = SlotFunction() );
133 
145  void removePort(const std::string& name);
146 
151  Ports getPorts() const;
152 
158  PortNames getPortNames() const;
159 
165  base::PortInterface* getPort(const std::string& name) const;
166 
174  std::string getPortDescription(const std::string& name) const;
175 
186  bool setPortDescription(const std::string& name, const std::string description);
187 
191  TaskContext* getOwner() const;
192 
198  Service* getService() const { return mservice; }
199 
206  base::PortInterface& addLocalPort(base::PortInterface& port);
207 
220  base::InputPortInterface& addLocalEventPort(base::InputPortInterface& port,
221  SlotFunction callback = SlotFunction() );
222 
232  void removeLocalPort(const std::string& name);
233 
234 
238  template< class Type>
239  Type* getPortType(const std::string& name) {
240  return dynamic_cast<Type*>( this->getPort(name) );
241  }
242 
247  void clear();
248 
249 #ifdef ORO_SIGNALLING_PORTS
250 
253  void setupHandles();
257  void cleanupHandles();
258 #else
259 
262  void dataOnPort(base::PortInterface* port);
263 #endif
264  protected:
269  Service* createPortObject(const std::string& name);
270 
271  bool chkPtr(const std::string &where, const std::string& name, const void* ptr);
275  Ports mports;
280 #ifdef ORO_SIGNALLING_PORTS
281 
285  typedef std::vector< Handle > Handles;
286  Handles handles;
287 #endif
288 
289  };
290 
291 }
292 
293 #endif
The base class of the InputPort.
base::PortInterface & addPort(const std::string &name, base::PortInterface &port)
Name and add a Port to the interface of this task and add a Service with the same name of the port...
The Interface of a TaskContext which exposes its data-flow ports.
Type * getPortType(const std::string &name)
Get a port of a specific type.
#define RTT_API
Definition: rtt-config.h:97
base::InputPortInterface & addEventPort(const std::string &name, base::InputPortInterface &port, SlotFunction callback=SlotFunction())
Name and add an Event triggering Port to the interface of this task and add a Service with the same n...
Ports mports
All our ports.
This class allows storage and retrieval of operations, ports, attributes and properties provided by a...
Definition: Service.hpp:93
Service * getService() const
Returns the service this interface belongs to.
boost::function< void(base::PortInterface *)> SlotFunction
bool setName(const std::string &name)
Change the name of this unconnected Port.
std::vector< base::PortInterface * > Ports
A sequence of pointers to ports.
std::vector< std::string > PortNames
A sequence of names of ports.
The TaskContext is the C++ representation of an Orocos component.
Definition: TaskContext.hpp:93
Service * mservice
The parent Service.
Contains TaskContext, Activity, OperationCaller, Operation, Property, InputPort, OutputPort, Attribute.
Definition: Activity.cpp:51
The base class of every data flow port.