![]() |
ducttape-engine
0.2.0
A universal game engine
|
Class for managing all Connections. More...
#include "ConnectionsManager.hpp"
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 ConnectionsManager * | get () |
| 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< Timer > | mPingTimer |
| The timer for when to send out pings. | |
Class for managing all Connections.
Definition at line 28 of file ConnectionsManager.hpp.
| 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.
| dt::ConnectionsManager::ConnectionsManager | ( | ID_t | max_connections = 0 | ) |
Advanced Constructor.
| max_connections | The maximum number of Connections allowed. |
| void dt::ConnectionsManager::_checkTimeouts | ( | ) | [private] |
Private method.
Checks all connections for timeouts.
| ID_t dt::ConnectionsManager::_getNewID | ( | ) | [private] |
| void dt::ConnectionsManager::_handlePing | ( | std::shared_ptr< PingEvent > | ping_event | ) | [private] |
Private method.
Handles an incoming ping event.
| ping_event | The 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.
| connection | The ID of the connection that timed out. |
| ID_t dt::ConnectionsManager::addConnection | ( | Connection::ConnectionSP | c | ) |
Adds a Connection to this manager.
| c | The Connection to add. |
| static ConnectionsManager* dt::ConnectionsManager::get | ( | ) | [static] |
| std::vector<Connection::ConnectionSP> dt::ConnectionsManager::getAllConnections | ( | ) |
Returns a list of all Connections.
| Connection::ConnectionSP dt::ConnectionsManager::getConnection | ( | ID_t | id | ) |
Returns a pointer to the Connection with the ID.
| id | The ID to search for. |
| uint16_t dt::ConnectionsManager::getConnectionCount | ( | ) |
Returns the number of active connections.
Returns the ID of a Connection.
| c | The Connection to search for. |
Returns the maximum number of connections allowed.
| double dt::ConnectionsManager::getPing | ( | ID_t | connection | ) |
Returns the ping of a connection.
| connection | The ID of the connection. |
| double dt::ConnectionsManager::getPingInterval | ( | ) |
Returns the interval between two pings.
| double dt::ConnectionsManager::getTimeout | ( | ) |
Returns the time until a connection times out.
Checks whether a connection is known by this manager.
| c | A Connection object to search for. |
| void dt::ConnectionsManager::removeConnection | ( | ID_t | id | ) |
Removes a Connection from the manager.
| id | The ID of the Connection to remove. |
Removes a Connection from the manager.
| c | The Connection to remove. |
| void dt::ConnectionsManager::setMaxConnections | ( | ID_t | max | ) |
Setter for maximum number of connections allowed.
Existing connections will not be removed if this value is lowered.
| max | The 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.
| ping_interval | The 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.
| timeout | The time until a connection times out, in seconds. |
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.
ID_t dt::ConnectionsManager::mMaxConnections [private] |
The maximum number of Connections allowed.
Definition at line 186 of file ConnectionsManager.hpp.
double dt::ConnectionsManager::mPingInterval [private] |
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.
double dt::ConnectionsManager::mTimeout [private] |
The time to wait before a connection times out.
In milliseconds.
Definition at line 191 of file ConnectionsManager.hpp.
1.8.0