Robot Devastation
Public Member Functions | Static Public Member Functions | Static Protected Member Functions | Protected Attributes | Static Private Attributes | List of all members
rd::NetworkManager Class Referenceabstract

Manages the communications between the user and the RobotDevastation network. More...

#include <NetworkManager.hpp>

Inheritance diagram for rd::NetworkManager:
rd::MentalMapEventListener rd::MockNetworkManager rd::YarpNetworkManager rd::test::YarpNetworkManagerNoKeepAlive

Public Member Functions

virtual bool start ()=0
 Start the network manager. More...
 
virtual bool stop ()=0
 Stop the network manager.
 
virtual bool isStopped () const =0
 Returns true if manager is stopped (obviously)
 
bool addNetworkEventListener (NetworkEventListener *listener)
 Adds a NetworkEventListener to the list of observers to be notified of events.
 
bool removeNetworkEventListeners ()
 Unregisters all the NetworkEventListener stored.
 
virtual bool configure (const std::string &parameter, const Player &value)
 Configures a parameter with a value.
 
virtual bool sendPlayerHit (const Player &player, int damage)=0
 Communicate to the network that a player has been hit by the user.
 
virtual bool login ()=0
 Log the user into the network.
 
virtual bool logout ()=0
 Log the user out of the network.
 
virtual bool keepAlive ()=0
 Keeps the user connected to the server (requires to be called periodically)
 
bool onTargetHit (const Target &target, const Player &player, const Weapon &weapon)
 Implementation of MentalMapEventListener interface.
 
bool onRespawn (const Player &player)
 Implementation of MentalMapEventListener interface.
 

Static Public Member Functions

static NetworkManagergetNetworkManager ()
 Get a reference to the NetworkManager. More...
 
static NetworkManagergetNetworkManager (const std::string &id)
 Get a reference to the NetworkManager. More...
 
static bool destroyNetworkManager ()
 Deallocate all the registered NetworkManager.
 

Static Protected Member Functions

static bool Register (NetworkManager *manager, const std::string &id)
 This function allows subclasses to install their unique instances in the singleton register to be selected later by the user.
 

Protected Attributes

std::vector< NetworkEventListener * > listeners
 Observers registered to be notified of network events.
 

Static Private Attributes

static NetworkManagernetworkManagerInstance = NULL
 Stores the unique instance of the NetworkManager.
 
static std::string currentId = ""
 Stores the id of the current unique instance used.
 
static std::map< std::string, NetworkManager * > networkManagerRegistry = std::map<std::string, rd::NetworkManager *>()
 Stores all the NetworkManager that have been registered.
 

Detailed Description

NetworkManager is a singleton text (only one instance of this object can exist, that is is shared by all the users). To use this class, we first get the reference to the NetworkManager with getNetworkManager() and then we access the manager with that reference.

When the program finishes, the NetworkManager can be deallocated using destroyNetworkManager().

Network events are broadcasted to the registered listeners, along with the data relevant to the event triggered (i.e. data that just arrived).

Member Function Documentation

◆ getNetworkManager() [1/2]

rd::NetworkManager * rd::NetworkManager::getNetworkManager ( )
static
Returns
By default, if no id is specified, this will return a reference to the first NetworkManager that it can find in the registry, or NULL if no NetworkManager was registered.

◆ getNetworkManager() [2/2]

rd::NetworkManager * rd::NetworkManager::getNetworkManager ( const std::string &  id)
static
Returns
The NetworkManager registered with the given id, NULL if the id is not found in the registry.

◆ start()

virtual bool rd::NetworkManager::start ( )
pure virtual

This function is supposed to be called after NetworkManager configuration.

Implemented in rd::YarpNetworkManager, and rd::MockNetworkManager.


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