[5523] | 1 | /*! |
---|
| 2 | * @file connection_monitor.h |
---|
| 3 | \brief provides information about the quality of a connection. |
---|
[5550] | 4 | */ |
---|
[5523] | 5 | |
---|
[5550] | 6 | #ifndef _CONNECTION_MONITOR_H |
---|
| 7 | #define _CONNECTION_MONITOR_H |
---|
[5523] | 8 | |
---|
[5581] | 9 | #include "base_object.h" |
---|
[5550] | 10 | #include "netdefs.h" |
---|
[5547] | 11 | |
---|
[7954] | 12 | #include <map> |
---|
[8362] | 13 | #include <list> |
---|
[7954] | 14 | |
---|
| 15 | #define N_PACKETS_FOR_PING 20 |
---|
| 16 | #define MSECS_TO_CALC_BWIDTH 1000 |
---|
[8623] | 17 | #define SECS_TO_TIMEOUT 30 |
---|
[7954] | 18 | |
---|
[5581] | 19 | class ConnectionMonitor : virtual public BaseObject |
---|
[7954] | 20 | { |
---|
[5618] | 21 | public: |
---|
[7954] | 22 | ConnectionMonitor( int userId ); |
---|
[6981] | 23 | virtual ~ConnectionMonitor(); |
---|
[5523] | 24 | |
---|
[8068] | 25 | void processUnzippedOutgoingPacket( int tick, byte * data, int length, int stateId ); |
---|
| 26 | void processUnzippedIncomingPacket( int tick, byte * data, int length, int stateId, int ackedState ); |
---|
[8362] | 27 | |
---|
[8068] | 28 | void processZippedOutgoingPacket( int tick, byte * data, int length, int stateId ); |
---|
| 29 | void processZippedIncomingPacket( int tick, byte * data, int length ); |
---|
[8362] | 30 | |
---|
[7954] | 31 | void calculatePing(); |
---|
[8362] | 32 | |
---|
[7954] | 33 | bool hasTimedOut(); |
---|
[8362] | 34 | |
---|
[7954] | 35 | void printStatis(); |
---|
[8362] | 36 | |
---|
[5618] | 37 | private: |
---|
[8623] | 38 | float calculateBandWidth( std::map<int,int> & packetHistory, int tick ); |
---|
| 39 | void removeOldPackets( std::map<int,int> & packetHistory, int tick ); |
---|
[5523] | 40 | |
---|
[8362] | 41 | int userId; //!< user's id |
---|
| 42 | |
---|
[7954] | 43 | std::map<int,int> sentStateTicks; |
---|
[8362] | 44 | |
---|
[7954] | 45 | std::map<int,int> incomingUnzippedPacketHistory; |
---|
| 46 | std::map<int,int> outgoingUnzippedPacketHistory; |
---|
[8362] | 47 | |
---|
[7954] | 48 | std::map<int,int> incomingZippedPacketHistory; |
---|
| 49 | std::map<int,int> outgoingZippedPacketHistory; |
---|
[8362] | 50 | |
---|
[7954] | 51 | std::list<int> ackDelay; |
---|
| 52 | int ping; |
---|
[5581] | 53 | |
---|
[7954] | 54 | float incomingUnzippedBandWidth; |
---|
| 55 | float outgoingUnzippedBandWidth; |
---|
[8362] | 56 | |
---|
[7954] | 57 | float incomingZippedBandWidth; |
---|
| 58 | float outgoingZippedBandWidth; |
---|
[8362] | 59 | |
---|
[7954] | 60 | int nIncomingPackets; |
---|
| 61 | int nOutgoingPackets; |
---|
[8362] | 62 | |
---|
[7954] | 63 | int nZIncomingPackets; |
---|
| 64 | int nZOutgoingPackets; |
---|
[8362] | 65 | |
---|
[7954] | 66 | int lastPacketTick; |
---|
[8362] | 67 | |
---|
[7954] | 68 | int lastPrintTick; |
---|
[5618] | 69 | }; |
---|
[5550] | 70 | |
---|
| 71 | #endif |
---|