Orocos Real-Time Toolkit  2.9.0
ConnectionManager.hpp
Go to the documentation of this file.
1 /***************************************************************************
2  tag: Peter Soetens Thu Oct 22 11:59:08 CEST 2009 ConnectionManager.hpp
3 
4  ConnectionManager.hpp - description
5  -------------------
6  begin : Thu October 22 2009
7  copyright : (C) 2009 Peter Soetens
8  email : peter@thesourcworks.com
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 /*
40  * ConnectionManager.hpp
41  *
42  * Created on: Oct 9, 2009
43  * Author: kaltan
44  */
45 
46 #ifndef CONNECTIONMANAGER_HPP_
47 #define CONNECTIONMANAGER_HPP_
48 
49 
50 #include "ConnID.hpp"
51 #include "List.hpp"
52 #include "SharedConnection.hpp"
53 #include "../ConnPolicy.hpp"
54 #include "../os/Mutex.hpp"
55 #include "../base/rtt-base-fwd.hpp"
56 #include "../base/ChannelElementBase.hpp"
57 #include <boost/tuple/tuple.hpp>
58 #include <boost/function.hpp>
59 #include <boost/bind.hpp>
60 #include <boost/shared_ptr.hpp>
61 
62 #include <rtt/os/Mutex.hpp>
63 #include <rtt/os/MutexLock.hpp>
64 #include <list>
65 
66 
67 namespace RTT
68 {
69 
70  namespace internal
71  {
79  {
80  public:
87  typedef boost::tuple<boost::shared_ptr<ConnID>, base::ChannelElementBase::shared_ptr, ConnPolicy> ChannelDescriptor;
88 
89  typedef std::list<ChannelDescriptor> Connections;
90 
98 
104  bool addConnection(ConnID* port_id, base::ChannelElementBase::shared_ptr channel, ConnPolicy policy);
105 
106  bool removeConnection(ConnID* port_id, bool disconnect = true);
107  bool removeConnection(base::ChannelElementBase* channel, bool disconnect = true);
108 
112  void disconnect();
113 
117  bool connected() const;
118 
121  bool connectedTo(base::PortInterface* port);
122 
123 
125  bool disconnect(base::PortInterface* port);
126 
131  bool isSingleConnection() const { return connections.size() == 1; }
132 
136  Connections getConnections() const {
137  return connections;
138  }
139 
144  return shared_connection;
145  }
146 
150  void lock() const {
151  connection_lock.lock();
152  };
153 
157  void unlock() const {
158  connection_lock.unlock();
159  }
160  protected:
161 
166  Connections::iterator eraseConnection(const Connections::iterator& descriptor, bool disconnect);
167 
172 
177  std::list< ChannelDescriptor > connections;
178 
183 
189  };
190 
191  }
192 
193 }
194 
195 #endif /* CONNECTIONMANAGER_HPP_ */
We can&#39;t use typedefs since C++ doesn&#39;t allow it for templated classes without specifying all the tem...
boost::intrusive_ptr< SharedConnectionBase > shared_ptr
internal::SharedConnectionBase::shared_ptr shared_connection
A pointer to the shared connection this port may be connected to.
Manages connections between ports.
#define RTT_API
Definition: rtt-config.h:97
A connection policy object describes how a given connection should behave.
Definition: ConnPolicy.hpp:107
void unlock() const
Unlocks the mutex protecting the channel element list.
void lock() const
Locks the mutex protecting the channel element list.
std::list< ChannelDescriptor > Connections
base::PortInterface * mport
The port for which we manage connections.
boost::tuple< boost::shared_ptr< ConnID >, base::ChannelElementBase::shared_ptr, ConnPolicy > ChannelDescriptor
A connection is described by an opaque ConnID object, the first element of the connection and the pol...
boost::intrusive_ptr< ChannelElementBase > shared_ptr
RTT::os::Mutex connection_lock
Lock that should be taken before the list of connections is accessed or modified. ...
Connections getConnections() const
Returns a list of all connections managed by this object.
bool isSingleConnection() const
Returns true if this manager manages only one connection.
This class is used in places where a permanent representation of a reference to a connection is neede...
Definition: ConnID.hpp:58
An object oriented wrapper around a non recursive mutex.
Definition: Mutex.hpp:92
Contains TaskContext, Activity, OperationCaller, Operation, Property, InputPort, OutputPort, Attribute.
Definition: Activity.cpp:52
std::list< ChannelDescriptor > connections
A list of all our connections.
In the data flow implementation, a channel is created by chaining ChannelElementBase objects...
The base class of every data flow port.
internal::SharedConnectionBase::shared_ptr getSharedConnection() const
Returns a pointer to the shared connection element this port may be connected to. ...