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