/*! * @file connection_monitor.h \brief provides information about the quality of a connection. */ #ifndef _CONNECTION_MONITOR_H #define _CONNECTION_MONITOR_H #include "base_object.h" #include "netdefs.h" #include #include #define N_PACKETS_FOR_PING 20 #define MSECS_TO_CALC_BWIDTH 1000 #define SECS_TO_TIMEOUT 30 class ConnectionMonitor : virtual public BaseObject { ObjectListDeclaration(ConnectionMonitor); public: ConnectionMonitor( int userId ); virtual ~ConnectionMonitor(); void processUnzippedOutgoingPacket( int tick, byte * data, int length, int stateId ); void processUnzippedIncomingPacket( int tick, byte * data, int length, int stateId, int ackedState ); void processZippedOutgoingPacket( int tick, byte * data, int length, int stateId ); void processZippedIncomingPacket( int tick, byte * data, int length ); void calculatePing(); bool hasTimedOut() const; void printStatis() const; float getIncomingUnzippedBandWidth() const { return incomingUnzippedBandWidth; } float getOutgoingUnzippedBandWidth() const { return outgoingUnzippedBandWidth; } float getIncomingZippedBandWidth() const { return incomingZippedBandWidth; } float getOutgoingZippedBandWidth() const { return outgoingZippedBandWidth; } private: float calculateBandWidth( std::map & packetHistory, int tick ); void removeOldPackets( std::map & packetHistory, int tick ); int userId; //!< user's id std::map sentStateTicks; std::map incomingUnzippedPacketHistory; std::map outgoingUnzippedPacketHistory; std::map incomingZippedPacketHistory; std::map outgoingZippedPacketHistory; std::list ackDelay; int ping; float incomingUnzippedBandWidth; float outgoingUnzippedBandWidth; float incomingZippedBandWidth; float outgoingZippedBandWidth; int nIncomingPackets; int nOutgoingPackets; int nZIncomingPackets; int nZOutgoingPackets; int lastPacketTick; int lastPrintTick; }; #endif