FREEDM DGI
CConnectionManager.hpp
Go to the documentation of this file.
1 
25 #ifndef CONNECTIONMANAGER_HPP
26 #define CONNECTIONMANAGER_HPP
27 
28 #include "SRemoteHost.hpp"
29 
30 #include <map>
31 #include <set>
32 #include <string>
33 
34 #include <boost/bimap.hpp>
35 #include <boost/noncopyable.hpp>
36 #include <boost/shared_ptr.hpp>
37 #include <boost/thread/mutex.hpp>
38 #include <boost/asio.hpp>
39 
40 namespace freedm {
41 namespace broker {
42 
43 class CConnection;
44 
47  : private boost::noncopyable
48 {
49 public:
51  typedef boost::shared_ptr<CConnection> ConnectionPtr;
52 
54  typedef std::map<std::string, SRemoteHost> hostnamemap;
55 
57  typedef boost::bimap<std::string, ConnectionPtr> connectionmap;
58 
60  static CConnectionManager& Instance();
61 
63  void PutHost(std::string u, std::string host, std::string port);
64 
66  void PutHost(std::string u, SRemoteHost host);
67 
69  void PutConnection(std::string uuid, ConnectionPtr c);
70 
72  void Stop(ConnectionPtr c);
73 
75  void StopAll();
76 
78  void ChangePhase(bool newround);
79 
81  ConnectionPtr GetConnectionByUUID( std::string uuid );
82 
84  ConnectionPtr CreateConnection(std::string uuid, boost::asio::ip::udp::endpoint endpoint);
85 
87  bool HasConnection(std::string uuid);
88 
90  hostnamemap::iterator GetHostsBegin() { return m_hosts.begin(); };
91 
93  hostnamemap::iterator GetHostsEnd() { return m_hosts.end(); };
94 
96  hostnamemap::iterator GetHost(std::string uuid) { return m_hosts.find(uuid); };
97 
99  connectionmap::iterator GetConnectionsBegin() { return m_connections.begin(); };
100 
102  connectionmap::iterator GetConnectionsEnd() { return m_connections.end(); };
103 
104  // Transient Network Simulation
106  void LoadNetworkConfig();
107 
108 private:
112  hostnamemap m_hosts;
114  connectionmap m_connections;
116  boost::mutex m_Mutex;
117 };
118 
119 } // namespace broker
120 } // namespace freedm
121 
122 #endif // CONNECTIONMANAGER_HPP
boost::bimap< std::string, ConnectionPtr > connectionmap
Typedef for the map which handles uuid to connection.
Definition: CConnectionManager.hpp:57
void ChangePhase(bool newround)
Handle changing rounds.
Definition: CConnectionManager.cpp:289
connectionmap::iterator GetConnectionsBegin()
Iterator to the beginning of the connection map.
Definition: CConnectionManager.hpp:99
void Stop(ConnectionPtr c)
Stop the specified connection.
Definition: CConnectionManager.cpp:143
void StopAll()
Stop all connections.
Definition: CConnectionManager.cpp:161
void PutConnection(std::string uuid, ConnectionPtr c)
Register a connection with the manager once it has been built.
Definition: CConnectionManager.cpp:85
hostnamemap::iterator GetHostsBegin()
An iterator to the beginning of the hostname map.
Definition: CConnectionManager.hpp:90
CConnectionManager()
Private constructor for the singleton instance.
Definition: CConnectionManager.cpp:59
ConnectionPtr CreateConnection(std::string uuid, boost::asio::ip::udp::endpoint endpoint)
Creates a connection by binding it to an endpoint.
Definition: CConnectionManager.cpp:266
bool HasConnection(std::string uuid)
Returns true if this map is currently tracking a connection to this peer.
Definition: CConnectionManager.cpp:234
A container which lists the hostname and and port of a peer.
Definition: SRemoteHost.hpp:52
boost::mutex m_Mutex
Mutex for protecting the handler maps above.
Definition: CConnectionManager.hpp:116
connectionmap m_connections
Forward map (UUID->Connection)
Definition: CConnectionManager.hpp:114
hostnamemap::iterator GetHostsEnd()
An iterator to the end of the hostname map.
Definition: CConnectionManager.hpp:93
void PutHost(std::string u, std::string host, std::string port)
Place a host/port and uuid into the host / uuid map.
Definition: CConnectionManager.cpp:103
hostnamemap::iterator GetHost(std::string uuid)
An iterator to the specified hostname.
Definition: CConnectionManager.hpp:96
General FREEDM Namespace.
Definition: CBroker.cpp:53
connectionmap::iterator GetConnectionsEnd()
Iterator to the end of the connections map.
Definition: CConnectionManager.hpp:102
Manages open connections so that they may be cleanly stopped.
Definition: CConnectionManager.hpp:46
static CConnectionManager & Instance()
Access the singleton instance of the connection manager.
Definition: CConnectionManager.cpp:71
void LoadNetworkConfig()
Load a network configuration & apply it.
Definition: CConnectionManager.cpp:304
ConnectionPtr GetConnectionByUUID(std::string uuid)
Fetch a connection pointer via UUID.
Definition: CConnectionManager.cpp:185
boost::shared_ptr< CConnection > ConnectionPtr
ConnectionPtr Typedef.
Definition: CConnectionManager.hpp:51
hostnamemap m_hosts
Mapping from uuid to host.
Definition: CConnectionManager.hpp:112
std::map< std::string, SRemoteHost > hostnamemap
Typedef for the map which handles uuid to hostname.
Definition: CConnectionManager.hpp:54