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