MIRA
RemoteConnectionPool.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) by
3  * MetraLabs GmbH (MLAB), GERMANY
4  * and
5  * Neuroinformatics and Cognitive Robotics Labs (NICR) at TU Ilmenau, GERMANY
6  * All rights reserved.
7  *
8  * Contact: info@mira-project.org
9  *
10  * Commercial Usage:
11  * Licensees holding valid commercial licenses may use this file in
12  * accordance with the commercial license agreement provided with the
13  * software or, alternatively, in accordance with the terms contained in
14  * a written agreement between you and MLAB or NICR.
15  *
16  * GNU General Public License Usage:
17  * Alternatively, this file may be used under the terms of the GNU
18  * General Public License version 3.0 as published by the Free Software
19  * Foundation and appearing in the file LICENSE.GPL3 included in the
20  * packaging of this file. Please review the following information to
21  * ensure the GNU General Public License version 3.0 requirements will be
22  * met: http://www.gnu.org/copyleft/gpl.html.
23  * Alternatively you may (at your option) use any later version of the GNU
24  * General Public License if such license has been publicly approved by
25  * MLAB and NICR (or its successors, if any).
26  *
27  * IN NO EVENT SHALL "MLAB" OR "NICR" BE LIABLE TO ANY PARTY FOR DIRECT,
28  * INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF
29  * THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF "MLAB" OR
30  * "NICR" HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  *
32  * "MLAB" AND "NICR" SPECIFICALLY DISCLAIM ANY WARRANTIES, INCLUDING,
33  * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
34  * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
35  * ON AN "AS IS" BASIS, AND "MLAB" AND "NICR" HAVE NO OBLIGATION TO
36  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS OR MODIFICATIONS.
37  */
38 
48 #ifndef _MIRA_FRAMEWORK_INCLUDE_FW_REMOTE_INTERNAL_REMOTECONNECTIONPOOL_H_
49 #define _MIRA_FRAMEWORK_INCLUDE_FW_REMOTE_INTERNAL_REMOTECONNECTIONPOOL_H_
50 
51 #include <unordered_map>
52 
54 #include <fw/RemoteConnection.h>
55 
56 namespace mira {
57 
59 
60 // forward declarations
61 class RemoteOutgoingConnectionBase;
62 class RemoteIncomingConnection;
63 class RemoteConnection;
64 struct KnownFramework;
65 
66 class RemoteConnectionPool;
67 
72 class RemoteConnectionProxy : boost::noncopyable
73 {
74  friend class RemoteConnectionPool;
75 public:
76  RemoteConnectionProxy() : mRemoteConnectionPool(nullptr), mRemoteConnection(nullptr) {};
78  RemoteConnectionProxy& operator= (RemoteConnectionProxy&&) noexcept;
79 
85 
87 
88  template<typename Reflector>
89  void reflect(Reflector& r)
90  {
91  r.delegate(mRemoteConnection);
92  }
93 
94  const RemoteConnection* operator->() const { return mRemoteConnection; }
95  RemoteConnection* operator->() { return mRemoteConnection; }
96 
97  const RemoteConnection& operator*() const { return *mRemoteConnection; }
98  RemoteConnection& operator*() { return *mRemoteConnection; }
99 
100  const RemoteConnection* get() const { return mRemoteConnection; }
101  RemoteConnection* get() { return mRemoteConnection; }
102 
107  bool valid() const;
108 
109  bool operator== (const RemoteConnection* other) const { return mRemoteConnection == other; }
110 
111 private:
112  // only the RemoteConnectionPool has access and can create a valid instance
114 
115 private:
116  RemoteConnectionPool* mRemoteConnectionPool;
117  RemoteConnection* mRemoteConnection;
118 };
119 
120 template <typename SerializerTag>
121 class IsTransparentSerializable<RemoteConnectionProxy, SerializerTag> : public std::true_type {};
122 
124 
135 {
136  friend RemoteConnectionProxy;
137 public:
145 
152 
157 
158 protected:
162  mutable boost::recursive_mutex mConnectionsMutex;
163 
169  void stopConnection(RemoteConnection* connection);
170 
174  std::set<RemoteConnection*> mRemoteConnections;
175 
179  std::vector<std::unique_ptr<RemoteConnection>> mStoppedConnections;
180 };
181 
182 
184 
185 } // namespace
186 
187 #endif
RemoteConnectionProxy()
Definition: RemoteConnectionPool.h:76
Information and settings for a known remote framework.
Definition: RemoteConnection.h:80
void reflect(Reflector &r)
Definition: RemoteConnectionPool.h:89
Connection classes representing connections between frameworks.
Type trait that indicates whether a type should be serialized "transparently", i.e.
Definition: IsTransparentSerializable.h:81
void releaseStoppedConnections()
Clears mStoppedConnections to destroy the RemoteConnection objects.
const RemoteConnection & operator*() const
Definition: RemoteConnectionPool.h:97
specialize cv::DataType for our ImgPixel and inherit from cv::DataType<Vec>
Definition: IOService.h:67
RemoteConnection * operator->()
Definition: RemoteConnectionPool.h:95
Provides type trait that indicates whether a type should be serialized "transparently".
A proxy object that represents a connection.
Definition: RemoteConnectionPool.h:72
RemoteConnection & operator*()
Definition: RemoteConnectionPool.h:98
bool operator==(const RemoteConnection *other) const
Definition: RemoteConnectionPool.h:109
std::vector< std::unique_ptr< RemoteConnection > > mStoppedConnections
Connections for which no RemoteConnectionProxy exists anymore (awaiting deletion).
Definition: RemoteConnectionPool.h:179
RemoteConnectionProxy createRemoteIncomingConnection()
Function that constructs a RemoteIncomingConnection, stores that connection in mRemoteConnections and...
const RemoteConnection * operator->() const
Definition: RemoteConnectionPool.h:94
Base class of connections between frameworks.
Definition: RemoteConnection.h:277
bool valid() const
RemoteConnectionProxy is valid if its RemoteConnectionPool and RemoteConnection pointers are valid an...
boost::recursive_mutex mConnectionsMutex
Mutex for access to mRemoteConnections and mStoppedConnections.
Definition: RemoteConnectionPool.h:162
friend void swap(RemoteConnectionProxy &a, RemoteConnectionProxy &b)
void stopConnection(RemoteConnection *connection)
Moves the ownership for a connection from mRemoteConnections to mStoppedConnections.
RemoteConnectionProxy createRemoteOutgoingConnection(const KnownFramework &address)
Function that constructs a RemoteOutgoingConnection, stores that connection in mRemoteConnections and...
std::set< RemoteConnection * > mRemoteConnections
Connections for which a RemoteConnectionProxy exists.
Definition: RemoteConnectionPool.h:174
Owner of every RemoteConnection.
Definition: RemoteConnectionPool.h:134