[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 | { |
---|
[9869] | 21 | ObjectListDeclaration(ConnectionMonitor); |
---|
[5618] | 22 | public: |
---|
[7954] | 23 | ConnectionMonitor( int userId ); |
---|
[6981] | 24 | virtual ~ConnectionMonitor(); |
---|
[5523] | 25 | |
---|
[8068] | 26 | void processUnzippedOutgoingPacket( int tick, byte * data, int length, int stateId ); |
---|
| 27 | void processUnzippedIncomingPacket( int tick, byte * data, int length, int stateId, int ackedState ); |
---|
[8362] | 28 | |
---|
[8068] | 29 | void processZippedOutgoingPacket( int tick, byte * data, int length, int stateId ); |
---|
| 30 | void processZippedIncomingPacket( int tick, byte * data, int length ); |
---|
[8362] | 31 | |
---|
[7954] | 32 | void calculatePing(); |
---|
[8362] | 33 | |
---|
[9494] | 34 | bool hasTimedOut() const; |
---|
[8362] | 35 | |
---|
[9494] | 36 | void printStatis() const; |
---|
| 37 | float getIncomingUnzippedBandWidth() const { return incomingUnzippedBandWidth; } |
---|
| 38 | float getOutgoingUnzippedBandWidth() const { return outgoingUnzippedBandWidth; } |
---|
| 39 | float getIncomingZippedBandWidth() const { return incomingZippedBandWidth; } |
---|
| 40 | float getOutgoingZippedBandWidth() const { return outgoingZippedBandWidth; } |
---|
[8362] | 41 | |
---|
[5618] | 42 | private: |
---|
[8623] | 43 | float calculateBandWidth( std::map<int,int> & packetHistory, int tick ); |
---|
| 44 | void removeOldPackets( std::map<int,int> & packetHistory, int tick ); |
---|
[5523] | 45 | |
---|
[8362] | 46 | int userId; //!< user's id |
---|
| 47 | |
---|
[7954] | 48 | std::map<int,int> sentStateTicks; |
---|
[8362] | 49 | |
---|
[7954] | 50 | std::map<int,int> incomingUnzippedPacketHistory; |
---|
| 51 | std::map<int,int> outgoingUnzippedPacketHistory; |
---|
[8362] | 52 | |
---|
[7954] | 53 | std::map<int,int> incomingZippedPacketHistory; |
---|
| 54 | std::map<int,int> outgoingZippedPacketHistory; |
---|
[8362] | 55 | |
---|
[7954] | 56 | std::list<int> ackDelay; |
---|
| 57 | int ping; |
---|
[5581] | 58 | |
---|
[7954] | 59 | float incomingUnzippedBandWidth; |
---|
| 60 | float outgoingUnzippedBandWidth; |
---|
[8362] | 61 | |
---|
[7954] | 62 | float incomingZippedBandWidth; |
---|
| 63 | float outgoingZippedBandWidth; |
---|
[8362] | 64 | |
---|
[7954] | 65 | int nIncomingPackets; |
---|
| 66 | int nOutgoingPackets; |
---|
[8362] | 67 | |
---|
[7954] | 68 | int nZIncomingPackets; |
---|
| 69 | int nZOutgoingPackets; |
---|
[8362] | 70 | |
---|
[7954] | 71 | int lastPacketTick; |
---|
[8362] | 72 | |
---|
[7954] | 73 | int lastPrintTick; |
---|
[5618] | 74 | }; |
---|
[5550] | 75 | |
---|
| 76 | #endif |
---|