FREEDM DGI
Public Types | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | List of all members
freedm::broker::CConnectionManager Class Reference

Manages open connections so that they may be cleanly stopped.

#include <CConnectionManager.hpp>

Inheritance diagram for freedm::broker::CConnectionManager:

Public Types

typedef boost::bimap< std::string, ConnectionPtrconnectionmap
 Typedef for the map which handles uuid to connection. More...
 
typedef boost::shared_ptr< CConnectionConnectionPtr
 ConnectionPtr Typedef. More...
 
typedef std::map< std::string, SRemoteHosthostnamemap
 Typedef for the map which handles uuid to hostname. More...
 

Public Member Functions

void ChangePhase (bool newround)
 Handle changing rounds. More...
 
ConnectionPtr CreateConnection (std::string uuid, boost::asio::ip::udp::endpoint endpoint)
 Creates a connection by binding it to an endpoint. More...
 
ConnectionPtr GetConnectionByUUID (std::string uuid)
 Fetch a connection pointer via UUID. More...
 
connectionmap::iterator GetConnectionsBegin ()
 Iterator to the beginning of the connection map. More...
 
connectionmap::iterator GetConnectionsEnd ()
 Iterator to the end of the connections map. More...
 
hostnamemap::iterator GetHost (std::string uuid)
 An iterator to the specified hostname. More...
 
hostnamemap::iterator GetHostsBegin ()
 An iterator to the beginning of the hostname map. More...
 
hostnamemap::iterator GetHostsEnd ()
 An iterator to the end of the hostname map. More...
 
bool HasConnection (std::string uuid)
 Returns true if this map is currently tracking a connection to this peer. More...
 
void LoadNetworkConfig ()
 Load a network configuration & apply it. More...
 
void PutConnection (std::string uuid, ConnectionPtr c)
 Register a connection with the manager once it has been built. More...
 
void PutHost (std::string u, std::string host, std::string port)
 Place a host/port and uuid into the host / uuid map. More...
 
void PutHost (std::string u, SRemoteHost host)
 Place a host/port and uuid into the host / uuid map. More...
 
void Stop (ConnectionPtr c)
 Stop the specified connection. More...
 
void StopAll ()
 Stop all connections. More...
 

Static Public Member Functions

static CConnectionManagerInstance ()
 Access the singleton instance of the connection manager. More...
 

Private Member Functions

 CConnectionManager ()
 Private constructor for the singleton instance. More...
 

Private Attributes

connectionmap m_connections
 Forward map (UUID->Connection) More...
 
hostnamemap m_hosts
 Mapping from uuid to host. More...
 
boost::mutex m_Mutex
 Mutex for protecting the handler maps above. More...
 

Member Typedef Documentation

Constructor & Destructor Documentation

freedm::broker::CConnectionManager::CConnectionManager ( )
private

CConnectionManager::CConnectionManager

Description:
: Initializes the connection manager object
Precondition:
None
Postcondition:
Connection manager is ready for use

Member Function Documentation

void freedm::broker::CConnectionManager::ChangePhase ( bool  newround)

CConnectionManager::ChangePhase

Description:
called when the broker changes phases in the realtime scheduler
Precondition:
None
Postcondition:
Each Connection's Change phase events is called.
Parameters
newroundTrue if the phase change corresponds to a new round.
ConnectionPtr freedm::broker::CConnectionManager::CreateConnection ( std::string  uuid,
boost::asio::ip::udp::endpoint  endpoint 
)

CConnectionManager::CreateConnection

Description:
Creates the CConnection object and binds it to an endpoint & uuid.
Parameters
uuidThe uuid of the remote endpoint
endpointThe network destination for the messages sent to this peer.
Precondition:
endpoint is a valid endpoint
Postcondition:
A new CConnection is created and bound to and endpoint. The resulting CConnection is inserted into the connection manager's map.
ConnectionPtr freedm::broker::CConnectionManager::GetConnectionByUUID ( std::string  uuid)

CConnectionManager::GetConnectionByUUID

Description:
Constructs or retrieves a connection to a specific UUID.
Parameters
uuidThe uuid of the peer you wish to connect to.
Precondition:
None
Postcondition:
If a connection has been constructed it will be put in the connections table and be started. If the connection is not constructed there is no change to the connection table. Throws an exception of the connection couldn't be constructed.
Returns
A pointer to the connection
connectionmap::iterator freedm::broker::CConnectionManager::GetConnectionsBegin ( )
inline
connectionmap::iterator freedm::broker::CConnectionManager::GetConnectionsEnd ( )
inline
hostnamemap::iterator freedm::broker::CConnectionManager::GetHost ( std::string  uuid)
inline
hostnamemap::iterator freedm::broker::CConnectionManager::GetHostsBegin ( )
inline
hostnamemap::iterator freedm::broker::CConnectionManager::GetHostsEnd ( )
inline
bool freedm::broker::CConnectionManager::HasConnection ( std::string  uuid)

CConnectionManager::HasConnection

Description:
Checks to see if the connection manager has a connection to the specified peer.
Precondition:
None
Postcondition:
If the connection is no longer valid, the connection manager will stop it.
Parameters
uuidThe uuid of the peer.
Returns
Returns true if the connection exists and has not stopped.
CConnectionManager & freedm::broker::CConnectionManager::Instance ( )
static

CConnectionManager::Instance

Description:
Access the singleton instance of the connection manager
Precondition:
None
Postcondition:
None
Returns
A reference to the Connection Manager.
void freedm::broker::CConnectionManager::LoadNetworkConfig ( )

CConnectionManager::LoadNetworkConfig

Description:
Accesses the network.xml file and parses it, setting the network reliability for all specified interfaces.
Precondition:
Only enabled with the -DCUSTOMNETWORK compile option
Postcondition:
All connections in the file are modified to behave as specified.
void freedm::broker::CConnectionManager::PutConnection ( std::string  uuid,
ConnectionPtr  c 
)

CConnectionManager::PutConnection

Description:
Registers a connection with the connection manager.
Parameters
uuidThe uuid of the node the connection is to.
cThe connection object that manages the channel to uuid
Precondition:
The connection is initialized.
Postcondition:
The connection has been inserted into the connection map.
void freedm::broker::CConnectionManager::PutHost ( std::string  u,
std::string  host,
std::string  port 
)

CConnectionManager::PutHost

Description:
Registers a peer with the connection manager.
Precondition:
None
Postcondition:
The hostname is registered with the uuid to hostname map.
Parameters
uThe peer's UUID
hostThe peer's hostname.
portThe port the peer listens on.
void freedm::broker::CConnectionManager::PutHost ( std::string  u,
SRemoteHost  host 
)

CConnectionManager::PutHost

Description:
Registers a peer with the connection manager
Precondition:
None
Postcondition:
The hostname is registered with the uuid to hostname map.
Parameters
uthe uuid to enter into the map.
hostThe hostname and port to enter into the map.
void freedm::broker::CConnectionManager::Stop ( ConnectionPtr  c)

CConnectionManager::Stop

Description:
Stops a connection.
Precondition:
The connection is in the connections map.
Postcondition:
The connection is closed and removed from the connections map.
Parameters
cthe connection pointer to stop.
void freedm::broker::CConnectionManager::StopAll ( )

CConnectionManager::StopAll

Description:
Stops all the connections registered with the connection manager.
Precondition:
None
Postcondition:
The forward and reverse connection maps are empty, and all connections that were contained within them are stopped.

Member Data Documentation

connectionmap freedm::broker::CConnectionManager::m_connections
private
hostnamemap freedm::broker::CConnectionManager::m_hosts
private
boost::mutex freedm::broker::CConnectionManager::m_Mutex
private

The documentation for this class was generated from the following files: