MIRA
RemoteConnectionPool.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) by
3  * MetraLabs GmbH (MLAB), GERMANY
4  * All rights reserved.
5  *
6  * Redistribution and modification of this code is strictly prohibited.
7  *
8  * IN NO EVENT SHALL "MLAB" BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
9  * SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE
10  * OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF "MLABS" HS BEEN
11  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
12  *
13  * "MLAB" SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT
14  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
15  * A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN
16  * "AS IS" BASIS, AND "MLAB" HAS NO OBLIGATION TO PROVIDE MAINTENANCE,
17  * SUPPORT, UPDATES, ENHANCEMENTS OR MODIFICATIONS.
18  */
19 
29 #ifndef _MIRA_FRAMEWORK_INCLUDE_FW_REMOTE_INTERNAL_REMOTECONNECTIONPOOL_H_
30 #define _MIRA_FRAMEWORK_INCLUDE_FW_REMOTE_INTERNAL_REMOTECONNECTIONPOOL_H_
31 
32 #include <unordered_map>
33 
35 #include <fw/RemoteConnection.h>
36 
37 namespace mira {
38 
40 
41 // forward declarations
42 class RemoteOutgoingConnectionBase;
43 class RemoteIncomingConnection;
44 class RemoteConnection;
45 struct KnownFramework;
46 
47 class RemoteConnectionPool;
48 
53 class RemoteConnectionProxy : boost::noncopyable
54 {
55  friend class RemoteConnectionPool;
56 public:
57  RemoteConnectionProxy() : mRemoteConnectionPool(nullptr), mRemoteConnection(nullptr) {};
59  RemoteConnectionProxy& operator= (RemoteConnectionProxy&&) noexcept;
60 
66 
68 
69  template<typename Reflector>
70  void reflect(Reflector& r)
71  {
72  r.delegate(mRemoteConnection);
73  }
74 
75  const RemoteConnection* operator->() const { return mRemoteConnection; }
76  RemoteConnection* operator->() { return mRemoteConnection; }
77 
78  const RemoteConnection& operator*() const { return *mRemoteConnection; }
79  RemoteConnection& operator*() { return *mRemoteConnection; }
80 
81  const RemoteConnection* get() const { return mRemoteConnection; }
82  RemoteConnection* get() { return mRemoteConnection; }
83 
88  bool valid() const;
89 
90  bool operator== (const RemoteConnection* other) const { return mRemoteConnection == other; }
91 
92 private:
93  // only the RemoteConnectionPool has access and can create a valid instance
95 
96 private:
97  RemoteConnectionPool* mRemoteConnectionPool;
98  RemoteConnection* mRemoteConnection;
99 };
100 
101 template <typename SerializerTag>
102 class IsTransparentSerializable<RemoteConnectionProxy, SerializerTag> : public std::true_type {};
103 
105 
116 {
117  friend RemoteConnectionProxy;
118 public:
126 
133 
138 
139 protected:
143  mutable boost::recursive_mutex mConnectionsMutex;
144 
150  void stopConnection(RemoteConnection* connection);
151 
155  std::set<RemoteConnection*> mRemoteConnections;
156 
160  std::vector<std::unique_ptr<RemoteConnection>> mStoppedConnections;
161 };
162 
163 
165 
166 } // namespace
167 
168 #endif
RemoteConnectionProxy()
Definition: RemoteConnectionPool.h:57
Information and settings for a known remote framework.
Definition: RemoteConnection.h:80
void reflect(Reflector &r)
Definition: RemoteConnectionPool.h:70
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:78
specialize cv::DataType for our ImgPixel and inherit from cv::DataType<Vec>
Definition: IOService.h:67
RemoteConnection * operator->()
Definition: RemoteConnectionPool.h:76
Provides type trait that indicates whether a type should be serialized "transparently".
A proxy object that represents a connection.
Definition: RemoteConnectionPool.h:53
RemoteConnection & operator*()
Definition: RemoteConnectionPool.h:79
bool operator==(const RemoteConnection *other) const
Definition: RemoteConnectionPool.h:90
std::vector< std::unique_ptr< RemoteConnection > > mStoppedConnections
Connections for which no RemoteConnectionProxy exists anymore (awaiting deletion).
Definition: RemoteConnectionPool.h:160
RemoteConnectionProxy createRemoteIncomingConnection()
Function that constructs a RemoteIncomingConnection, stores that connection in mRemoteConnections and...
const RemoteConnection * operator->() const
Definition: RemoteConnectionPool.h:75
Base class of connections between frameworks.
Definition: RemoteConnection.h:276
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:143
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:155
Owner of every RemoteConnection.
Definition: RemoteConnectionPool.h:115