Alex Bikfalvi
SimStream Documentation
Connection.h
00001 #pragma once 00002 00003 #include "SimHandler.h" 00004 #include "Address.h" 00005 #include "PacketConnectionFeedback.h" 00006 #include "PacketConnectionMessage.h" 00007 #include "PacketConnectionData.h" 00008 #include "Timer.h" 00009 #include "ConnectionTag.h" 00010 00011 class CConnection 00012 { 00013 public: 00014 enum EConnectionType 00015 { 00016 REQUESTER = 0, 00017 RESPONDER = 1 00018 }; 00019 00020 enum EState 00021 { 00022 CLOSED = 0, 00023 OPENING = 1, 00024 OPENED = 2, 00025 CLOSING = 3, 00026 CANCELING = 4, 00027 WAITING = 5 00028 }; 00029 00030 enum EOpenResult 00031 { 00032 OPEN_SUCCESS = 0, 00033 OPEN_CANCELED = 1, 00034 OPEN_FAIL_TIMEOUT = 2, 00035 OPEN_FAIL_REMOTE = 3 00036 }; 00037 00038 enum ECloseResult 00039 { 00040 CLOSE_CONFIRMED = 0, 00041 CLOSE_TIMEOUT = 1, 00042 CLOSE_COMPLETE = 2 00043 }; 00044 00045 private: 00046 static __uint32 idGlobal; 00047 static __uint32 flowGlobal; 00048 00049 // Timer timeout values 00050 static __time timerOpenTimeout; 00051 static __time timerCloseTimeout; 00052 static __time timerCancelTimeout; 00053 static __time timerRequesterWaitTimeout; 00054 static __time timerResponderWaitTimeout; 00055 static __time timerDefaultWaitTimeout; 00056 00057 // Functions 00058 void (CConnection::*functionOpen)(); 00059 void (CConnection::*functionClose)(); 00060 00061 void (CConnection::*functionRecvMessageOpen)(CPacketConnectionMessage*); 00062 void (CConnection::*functionRecvMessageOpenAck)(CPacketConnectionMessage*); 00063 void (CConnection::*functionRecvMessageClose)(CPacketConnectionMessage*); 00064 void (CConnection::*functionRecvMessageCloseAck)(CPacketConnectionMessage*); 00065 void (CConnection::*functionRecvMessageCloseAckAck)(CPacketConnectionMessage*); 00066 00067 // Tag 00068 CConnectionTag* tag; 00069 00070 protected: 00071 // Type 00072 EConnectionType type; 00073 00074 // State 00075 EState state; 00076 00077 // Simulator 00078 CSimHandler* sim; 00079 00080 // Flow 00081 __uint32 flow; 00082 00083 // Local connection 00084 __uint32 id; 00085 __uint32 idEntry; 00086 __uint16 port; 00087 00088 // Remote connection 00089 CAddress remoteAddress; 00090 __uint32 remoteId; 00091 __uint32 remoteIdEntry; 00092 __uint16 remotePort; 00093 00094 // Timers 00095 CTimer<CConnection>* 00096 timerControl; 00097 00098 // Delegates 00099 IDelegate5<void, __uint16, __uint16, CAddress, __byte, CPacket*>* 00100 delegateSend; 00101 00102 // Events 00103 Event2<void, CConnection*, EOpenResult>* 00104 eventOpen; 00105 Event2<void, CConnection*, ECloseResult>* 00106 eventClose; 00107 00108 // Calls 00109 Call1<CConnection*>* 00110 callDispose; 00111 00112 // String 00113 static char* strConnectionType[]; 00114 static char* strState[]; 00115 char str[256]; 00116 00117 public: 00118 CConnection( 00119 EConnectionType type, 00120 __uint32 idEntry, 00121 __uint16 port, 00122 CSimHandler* sim, 00123 IDelegate5<void, __uint16, __uint16, CAddress, __byte, CPacket*>* delegateSend, 00124 IDelegate1<void, CConnection*>* delegateDispose, 00125 CAddress remoteAddress, 00126 __uint16 remotePort 00127 ); 00128 virtual ~CConnection(); 00129 00130 inline EConnectionType Type() { return this->type; } 00131 inline EState State() { return this->state; } 00132 00133 inline __uint32 Id() { return this->id; } 00134 inline __uint32 IdEntry() { return this->idEntry; } 00135 inline __uint16 Port() { return this->port; } 00136 00137 inline __uint32 RemoteId() { return this->remoteId; } 00138 inline __uint32 RemoteIdEntry() { return this->remoteIdEntry; } 00139 inline CAddress RemoteAddress() { return this->remoteAddress; } 00140 inline __uint16 RemotePort() { return this->remotePort; } 00141 00142 // Events 00143 inline Event2<void, CConnection*, EOpenResult>* 00144 EventOpen() { return this->eventOpen; } 00145 inline Event2<void, CConnection*, ECloseResult>* 00146 EventClose() { return this->eventClose; } 00147 00148 // Calls 00149 inline Call1<CConnection*>* 00150 CallDispose() { return this->callDispose; } // Call when the object can be disposed 00151 00152 // Functions 00153 void Open(); 00154 void Close(); 00155 00156 // Receive 00157 void Recv(CAddress src, CPacketConnection* packet); 00158 00159 // Tag 00160 inline CConnectionTag* 00161 Tag() { return this->tag; } 00162 inline void Tag(CConnectionTag* tag) { this->tag = tag; } 00163 00164 char* ToString() const; 00165 00166 protected: 00167 // Send 00168 bool SendData(CPacketConnectionData* packet); 00169 00170 // Receive 00171 virtual void Recv(CPacketConnection* packet) = 0; 00172 virtual void RecvData(CPacketConnectionData* packet) = 0; 00173 virtual void RecvFeedback(CPacketConnectionFeedback* packet) = 0; 00174 void RecvMessage(CPacketConnectionMessage* packet); 00175 00176 void RecvMessageOpenRequester(CPacketConnectionMessage* packet); 00177 void RecvMessageOpenAckRequester(CPacketConnectionMessage* packet); 00178 void RecvMessageCloseRequester(CPacketConnectionMessage* packet); 00179 void RecvMessageCloseAckRequester(CPacketConnectionMessage* packet); 00180 void RecvMessageCloseAckAckRequester(CPacketConnectionMessage* packet); 00181 00182 void RecvMessageOpenResponder(CPacketConnectionMessage* packet); 00183 void RecvMessageOpenAckResponder(CPacketConnectionMessage* packet); 00184 void RecvMessageCloseResponder(CPacketConnectionMessage* packet); 00185 void RecvMessageCloseAckResponder(CPacketConnectionMessage* packet); 00186 void RecvMessageCloseAckAckResponder(CPacketConnectionMessage* packet); 00187 00188 // Functions 00189 void OpenRequester(); 00190 void OpenResponder(); 00191 00192 void CloseRequester(); 00193 void CloseResponder(); 00194 00195 // Timers 00196 void TimerOpen(CTimerInfo* info); 00197 void TimerClose(CTimerInfo* info); 00198 void TimerCancel(CTimerInfo* info); 00199 void TimerWait(CTimerInfo* info); 00200 };
Last updated: February 8, 2011