[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 | |
---|
[9454] | 33 | bool hasTimedOut() const; |
---|
[8362] | 34 | |
---|
[9454] | 35 | void printStatis() const; |
---|
[9431] | 36 | float getIncomingUnzippedBandWidth() const { return incomingUnzippedBandWidth; } |
---|
| 37 | float getOutgoingUnzippedBandWidth() const { return outgoingUnzippedBandWidth; } |
---|
| 38 | float getIncomingZippedBandWidth() const { return incomingZippedBandWidth; } |
---|
| 39 | float getOutgoingZippedBandWidth() const { return outgoingZippedBandWidth; } |
---|
[8362] | 40 | |
---|
[5618] | 41 | private: |
---|
[8623] | 42 | float calculateBandWidth( std::map<int,int> & packetHistory, int tick ); |
---|
| 43 | void removeOldPackets( std::map<int,int> & packetHistory, int tick ); |
---|
[5523] | 44 | |
---|
[8362] | 45 | int userId; //!< user's id |
---|
| 46 | |
---|
[7954] | 47 | std::map<int,int> sentStateTicks; |
---|
[8362] | 48 | |
---|
[7954] | 49 | std::map<int,int> incomingUnzippedPacketHistory; |
---|
| 50 | std::map<int,int> outgoingUnzippedPacketHistory; |
---|
[8362] | 51 | |
---|
[7954] | 52 | std::map<int,int> incomingZippedPacketHistory; |
---|
| 53 | std::map<int,int> outgoingZippedPacketHistory; |
---|
[8362] | 54 | |
---|
[7954] | 55 | std::list<int> ackDelay; |
---|
| 56 | int ping; |
---|
[5581] | 57 | |
---|
[7954] | 58 | float incomingUnzippedBandWidth; |
---|
| 59 | float outgoingUnzippedBandWidth; |
---|
[8362] | 60 | |
---|
[7954] | 61 | float incomingZippedBandWidth; |
---|
| 62 | float outgoingZippedBandWidth; |
---|
[8362] | 63 | |
---|
[7954] | 64 | int nIncomingPackets; |
---|
| 65 | int nOutgoingPackets; |
---|
[8362] | 66 | |
---|
[7954] | 67 | int nZIncomingPackets; |
---|
| 68 | int nZOutgoingPackets; |
---|
[8362] | 69 | |
---|
[7954] | 70 | int lastPacketTick; |
---|
[8362] | 71 | |
---|
[7954] | 72 | int lastPrintTick; |
---|
[5618] | 73 | }; |
---|
[5550] | 74 | |
---|
| 75 | #endif |
---|