/*! * @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 #define N_PACKETS_FOR_PING 20 #define MSECS_TO_CALC_BWIDTH 1000 #define SECS_TO_TIMEOUT 10 class ConnectionMonitor : virtual public BaseObject { public: ConnectionMonitor( int userId ); virtual ~ConnectionMonitor(); void processUnzippedOutgoingPacket( byte * data, int length, int stateId ); void processUnzippedIncomingPacket( byte * data, int length, int stateId, int ackedState ); void calculatePing(); //TODO bool hasTimedOut(){ return false; return ( lastPacketTick + SECS_TO_TIMEOUT*1000 < SDL_GetTicks() ) && nIncomingPackets > 0; } int getMaxPacketSize(); private: float calculateBandWidth( 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 lastPacketTick; }; #endif