ducttape-engine  0.2.0
A universal game engine
 All Classes Functions Variables Typedefs Enumerations Enumerator
Public Types | Public Slots | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes
dt::ConnectionsManager Class Reference

Class for managing all Connections. More...

#include "ConnectionsManager.hpp"

Inheritance diagram for dt::ConnectionsManager:
[legend]
Collaboration diagram for dt::ConnectionsManager:
[legend]

List of all members.

Public Types

typedef uint16_t ID_t
 Type of Connection IDs.

Public Slots

void handleEvent (std::shared_ptr< dt::NetworkEvent > e)
void timerTick (QString message, double interval)

Public Member Functions

 ConnectionsManager (ID_t max_connections=0)
 Advanced Constructor.
 ~ConnectionsManager ()
 Destructor.
void initialize ()
 Called when the Manager is being initialized.
void deinitialize ()
 Called when the Manager is being deinitialized.
void setMaxConnections (ID_t max)
 Setter for maximum number of connections allowed.
ID_t getMaxConnections () const
 Returns the maximum number of connections allowed.
bool isKnownConnection (Connection c)
 Checks whether a connection is known by this manager.
ID_t addConnection (Connection::ConnectionSP c)
 Adds a Connection to this manager.
void removeConnection (ID_t id)
 Removes a Connection from the manager.
void removeConnection (Connection c)
 Removes a Connection from the manager.
ID_t getConnectionID (Connection c)
 Returns the ID of a Connection.
Connection::ConnectionSP getConnection (ID_t id)
 Returns a pointer to the Connection with the ID.
std::vector
< Connection::ConnectionSP > 
getAllConnections ()
 Returns a list of all Connections.
uint16_t getConnectionCount ()
 Returns the number of active connections.
void setPingInterval (double ping_interval)
 Sets the interval between two pings.
double getPingInterval ()
 Returns the interval between two pings.
void setTimeout (double timeout)
 Sets the time until a connection times out.
double getTimeout ()
 Returns the time until a connection times out.
double getPing (ID_t connection)
 Returns the ping of a connection.

Static Public Member Functions

static ConnectionsManagerget ()
 Returns a pointer to the Manager instance.

Private Member Functions

ID_t _getNewID ()
 Private method.
void _ping ()
 Private method.
void _handlePing (std::shared_ptr< PingEvent > ping_event)
 Private method.
void _checkTimeouts ()
 Private method.
void _timeoutConnection (ID_t connection)
 Private method.

Private Attributes

ID_t mMaxConnections
 The maximum number of Connections allowed.
std::map< ID_t,
Connection::ConnectionSP > 
mConnections
 The Connections known to this manager.
std::map< ID_t, double > mPings
 The pings for the different Connections.
std::map< ID_t, double > mLastActivity
 The time the connection sent the last packet.
double mTimeout
 The time to wait before a connection times out.
double mPingInterval
 The interval in milliseconds between two pings.
std::shared_ptr< TimermPingTimer
 The timer for when to send out pings.

Detailed Description

Class for managing all Connections.

See also:
Connection

Definition at line 28 of file ConnectionsManager.hpp.


Member Typedef Documentation

typedef uint16_t dt::ConnectionsManager::ID_t

Type of Connection IDs.

Limits the number of maximum connections.

Definition at line 34 of file ConnectionsManager.hpp.


Constructor & Destructor Documentation

Advanced Constructor.

Parameters:
max_connectionsThe maximum number of Connections allowed.

Member Function Documentation

Private method.

Checks all connections for timeouts.

Private method.

Finds an unused ID to assign to the next Connection.

Returns:
An unused ID.
void dt::ConnectionsManager::_handlePing ( std::shared_ptr< PingEvent ping_event) [private]

Private method.

Handles an incoming ping event.

Parameters:
ping_eventThe ping event.
void dt::ConnectionsManager::_ping ( ) [private]

Private method.

Sends out a PingEvent.

void dt::ConnectionsManager::_timeoutConnection ( ID_t  connection) [private]

Private method.

Called when a connection times out.

Parameters:
connectionThe ID of the connection that timed out.
ID_t dt::ConnectionsManager::addConnection ( Connection::ConnectionSP  c)

Adds a Connection to this manager.

Parameters:
cThe Connection to add.
Returns:
The ID assigned to the Connection.

Returns a pointer to the Manager instance.

Returns:
A pointer to the Manager instance.
std::vector<Connection::ConnectionSP> dt::ConnectionsManager::getAllConnections ( )

Returns a list of all Connections.

Returns:
A list of all Connections.
Connection::ConnectionSP dt::ConnectionsManager::getConnection ( ID_t  id)

Returns a pointer to the Connection with the ID.

Parameters:
idThe ID to search for.
Returns:
A pointer to the Connection or nullptr if it is not know.

Returns the number of active connections.

Returns:
An int of the number of active connections.

Returns the ID of a Connection.

Parameters:
cThe Connection to search for.
Returns:
The ID of the Connection or 0 if it is not known.

Returns the maximum number of connections allowed.

Returns:
The maximum number of connections allowed.
double dt::ConnectionsManager::getPing ( ID_t  connection)

Returns the ping of a connection.

Parameters:
connectionThe ID of the connection.
Returns:
The ping of the connection.

Returns the interval between two pings.

Returns:
The interval between two pings, in seconds.

Returns the time until a connection times out.

Returns:
The time until a connection times out, in seconds.

Checks whether a connection is known by this manager.

Parameters:
cA Connection object to search for.
Returns:
True if the connection is known, otherwise false.

Removes a Connection from the manager.

Parameters:
idThe ID of the Connection to remove.

Removes a Connection from the manager.

Parameters:
cThe Connection to remove.

Setter for maximum number of connections allowed.

Existing connections will not be removed if this value is lowered.

Parameters:
maxThe maximum number of connections allowed.
void dt::ConnectionsManager::setPingInterval ( double  ping_interval)

Sets the interval between two pings.

Set this to 0 to disable pings. Default: 1.0.

Parameters:
ping_intervalThe interval between two pings, in seconds.
void dt::ConnectionsManager::setTimeout ( double  timeout)

Sets the time until a connection times out.

Set this to 0 to disable timeouts. Default: 10.0.

Parameters:
timeoutThe time until a connection times out, in seconds.

Member Data Documentation

std::map<ID_t, Connection::ConnectionSP> dt::ConnectionsManager::mConnections [private]

The Connections known to this manager.

Definition at line 187 of file ConnectionsManager.hpp.

std::map<ID_t, double> dt::ConnectionsManager::mLastActivity [private]

The time the connection sent the last packet.

Definition at line 189 of file ConnectionsManager.hpp.

The maximum number of Connections allowed.

Definition at line 186 of file ConnectionsManager.hpp.

The interval in milliseconds between two pings.

Definition at line 192 of file ConnectionsManager.hpp.

std::map<ID_t, double> dt::ConnectionsManager::mPings [private]

The pings for the different Connections.

Definition at line 188 of file ConnectionsManager.hpp.

std::shared_ptr<Timer> dt::ConnectionsManager::mPingTimer [private]

The timer for when to send out pings.

Definition at line 193 of file ConnectionsManager.hpp.

The time to wait before a connection times out.

In milliseconds.

Definition at line 191 of file ConnectionsManager.hpp.


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