00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef CLIENT_H
00024 #define CLIENT_H
00025
00026 #include <pinet.h>
00027 USING_PTYPES
00028
00029 #include "../common/averagetimecalculator.h"
00030 #include "../common/frameworkseqnolist.h"
00031
00032 class ServerPacket;
00033 class ServerFramework;
00034
00035
00036
00037
00038
00039
00040
00041 class Client
00042 {
00043 friend bool operator== (const Client &c1, const Client &c2);
00044
00045 private:
00046 static unsigned int next_uid;
00047
00048 private:
00049 ServerFramework * server_framework;
00050 unsigned int uid;
00051 ipaddress addr;
00052 int port;
00053 AverageTimeCalculator<8,50,1,1000> rtt_time;
00054
00055 FrameworkSeqNoList<ServerPacket,ipmsgserver> sequencenumbers;
00056 bool has_called_on_connect;
00057 bool has_called_on_disconnect;
00058 unsigned int last_packet_received;
00059
00060 public:
00061 enum ClientState
00062 {
00063 NEWCLIENT = 0,
00064 CONNECTED = 1,
00065 CONNECTION_ABORTED = 2,
00066 DICONNECTED = 3,
00067 };
00068 inline const ClientState getState() const { return state; };
00069 inline void setState(const ClientState & _s ) { state = _s; };
00070
00071 private:
00072 ClientState state;
00073
00074 public:
00075 Client(ServerFramework * fw, const ipaddress &addr, int port);
00076 ~Client();
00077
00078 public:
00079 const ipaddress &getAddress(){ return addr; };
00080 const int getPort() { return port; };
00081 const unsigned int getId() const { return uid; };
00082
00083 public:
00084 inline void registerRTT( unsigned int ms ){ rtt_time.registerValue(ms); };
00085 inline void registerLastPacketReceivedTime( unsigned int time ){ last_packet_received = time; };
00086 inline unsigned int getLastPacketReceivedTime() const { return last_packet_received; };
00087 inline unsigned int getRTT() const { return rtt_time.getAvg(); };
00088 inline unsigned int getNextOutgoingSeqNo( ServerPacket * packet ) { return sequencenumbers.getNextOutgoingSeqNo(packet); };
00089 inline bool hasCalledOnConnect() const { return has_called_on_connect; };
00090 inline void setCalledOnConnect(bool b){ has_called_on_connect = b; };
00091 inline bool hasCalledOnDisconnect() const { return has_called_on_disconnect; };
00092 inline void setCalledOnDisconnect(bool b){ has_called_on_disconnect = b; };
00093 bool isPacketReadyForDelivery(ServerPacket * packet);
00094 ServerPacket * incrementNextIngoingSeqNo( ServerPacket * packet );
00095 inline unsigned int bufferedPackets( ) const { return sequencenumbers.bufferePacketsTotal(); };
00096 unsigned int getNextOutgoingPacketSeqNumber(ServerPacket * packet);
00097 };
00098
00099
00100 bool operator== (const Client &c1, const Client &c2);
00101
00102 std::ostream & operator<<(std::ostream & o, Client & client);
00103
00104
00105 #endif