Orocos Real-Time Toolkit  2.9.0
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 
117  base::InputPortInterface& addEventPort(const std::string& name, base::InputPortInterface& port, SlotFunction callback = SlotFunction() ) {
118  if ( !chkPtr("addEventPort", name, &port) ) return port;
119  port.setName(name);
120  return addEventPort(port,callback);
121  }
122 
137  base::InputPortInterface& addEventPort(base::InputPortInterface& port, SlotFunction callback = SlotFunction() );
138 
150  void removePort(const std::string& name);
151 
156  Ports getPorts() const;
157 
163  PortNames getPortNames() const;
164 
170  base::PortInterface* getPort(const std::string& name) const;
171 
179  std::string getPortDescription(const std::string& name) const;
180 
191  bool setPortDescription(const std::string& name, const std::string description);
192 
196  TaskContext* getOwner() const;
197 
203  Service* getService() const { return mservice; }
204 
211  base::PortInterface& addLocalPort(base::PortInterface& port);
212 
225  base::InputPortInterface& addLocalEventPort(base::InputPortInterface& port,
226  SlotFunction callback = SlotFunction() );
227 
237  void removeLocalPort(const std::string& name);
238 
239 
243  template< class Type>
244  Type* getPortType(const std::string& name) {
245  return dynamic_cast<Type*>( this->getPort(name) );
246  }
247 
252  void clear();
253 
254 #ifdef ORO_SIGNALLING_PORTS
255 
258  void setupHandles();
262  void cleanupHandles();
263 #else
264 
267  void dataOnPort(base::PortInterface* port);
268 #endif
269  protected:
274  Service* createPortObject(const std::string& name);
275 
276  bool chkPtr(const std::string &where, const std::string& name, const void* ptr);
280  Ports mports;
285 #ifdef ORO_SIGNALLING_PORTS
286 
290  typedef std::vector< Handle > Handles;
291  Handles handles;
292 #endif
293 
294  };
295 
296 }
297 
298 #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:52
The base class of every data flow port.