Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/proxy/src/lib/network/monitor/network_monitor.h @ 9584

Last change on this file since 9584 was 9584, checked in by patrick, 18 years ago

proxy control center now registers joining clients to the network monitor

File size: 4.3 KB
Line 
1/*!
2 * @file network_monitor.h
3 *  a class to monitor the network: throughput, network nodes
4 */
5
6#ifndef _NETWORK_MONITOR_H
7#define _NETWORK_MONITOR_H
8
9#include "base_object.h"
10#include "synchronizeable.h"
11#include "shared_network_data.h"
12#include "ip.h"
13
14#include "network_node.h"
15
16#include <list>
17
18class NetworkStream;
19class PeerInfo;
20
21
22namespace OrxGui { class GLGuiBox; };
23
24
25
26//!< a class that monitors the whole network. it tries to gather all informations its able to from the network
27class NetworkMonitor : public Synchronizeable
28{
29
30  public:
31    NetworkMonitor(NetworkStream* networkStream);
32    virtual ~NetworkMonitor();
33
34    /* client/masterserver/proxyserver addition/removal interface */
35    void addNetworkNode(NetworkNode* node);
36    void removeNetworkNode(NetworkNode* node);
37
38    void addNode(PeerInfo* pInfo);
39    void addNode(const IP& ip, int nodeType);
40    void addNode(NetworkNode* node) { this->nodeList.push_back(node); }
41    void addNode(NetworkNode* node, PeerInfo* pInfo);
42
43    /** adds to @param node a network node @param pInfo a new client */
44    inline void addClient(NetworkNode* node, PeerInfo* pInfo) { node->addClient(pInfo); }
45    /** adds to @param node a network node @param pInfo a new proxy server */
46    inline void addActiveProxyServer(NetworkNode* node, PeerInfo* pInfo) { node->addActiveProxyServer(pInfo); }
47    /** adds to @param node a network node @param pInfo a new proxy server */
48    inline void addPassiveProxyServer(NetworkNode* node, PeerInfo* pInfo) { node->addPassiveProxyServer(pInfo); }
49    /** adds to @param node a network node @param pInfo a new master server*/
50    inline void addMasterServer(NetworkNode* node, PeerInfo* pInfo) { node->addMasterServer(pInfo); }
51
52    inline void removeClient(NetworkNode* node, PeerInfo* pInfo) { node->removeClient(pInfo); }
53    inline void removeActiveProxyServer(NetworkNode* node, PeerInfo* pInfo) { node->removeActiveProxyServer(pInfo); }
54    inline void removePassiveProxyServer(NetworkNode* node, PeerInfo* pInfo) { node->removePassiveProxyServer(pInfo); }
55    inline void removeMasterServer(NetworkNode* node, PeerInfo* pInfo) { node->removeMasterServer(pInfo); }
56
57    PeerInfo* getFirstChoiceProxy() const;
58    PeerInfo* getSecondChoiceProxy() const;
59    /** @returns the local node */
60    inline NetworkNode* getLocalNode() const { return this->localNode; };
61
62    /** @returns the active proxy server list of the localnode */
63    inline std::list<PeerInfo*> getActiveProxyServer() const { return this->localNode->getActiveProxyServer(); }
64
65    /* slots admin and info interface */
66    /** @returns the total number of players in this game (including all proxy servers etc)*/
67    inline int getPlayerNumber() const { return this->playerNumber; }
68
69    /** @returns true if there are still free network slots available at the local node*/
70    inline bool gotFreeSlots() const { return (this->localNode->getPlayerNumber() < SharedNetworkData::getInstance()->getMaxPlayer()); }
71    /** @param node node to be checked for slots @returns true if there are still free network slots available at this node */
72    inline bool gotFreeSlots(NetworkNode* node) const { return (node->getPlayerNumber() < SharedNetworkData::getInstance()->getMaxPlayer()); }
73
74    /** @returns true if the next client should be reconnected to some other proxy server with more connections */
75    inline bool isReconnectNextClient() const { return (this->localNode->getPlayerNumber() >= SharedNetworkData::getInstance()->getMaxPlayer()); }
76
77    inline const std::list<NetworkNode*>& getNodeList() const { return this->nodeList; };
78    inline PeerInfo* getPeerByUserId( int userId) { return this->localNode->getPeerByUserId(userId); }
79
80    void toggleGUI();
81
82    void process();
83    void debug() const;
84
85
86  private:
87    NetworkStream*               networkStream;              //!< reference to the one networkstream of the network
88    NetworkNode*                 localNode;                  //!< reference to the local node
89    std::list<NetworkNode*>      nodeList;                   //!< list of all network nodes
90
91    OrxGui::GLGuiBox*            box;
92
93    int                          playerNumber;                 //!< total number of players in the game
94    int                          connectionNumber;             //!< total number of connections at this localhost
95};
96
97
98#endif
Note: See TracBrowser for help on using the repository browser.