Alex Bikfalvi
SimStream Documentation
ConnectionLayer.h
00001 #pragma once 00002 00003 #include "SimHandler.h" 00004 #include "ConnectionEntry.h" 00005 #include "ConnectionSender.h" 00006 #include "ConnectionReceiver.h" 00007 #include "Address.h" 00008 #include "PacketConnection.h" 00009 00010 class CConnectionLayer 00011 { 00012 public: 00013 enum EResult 00014 { 00015 SUCCESS = 0, // Packet received and processed successfully 00016 FAIL_INCORRECT_PORT = 1, // Packet arrived on the incorrect port 00017 FAIL_INVALID_DESTINATION_PACKET = 2, // Packet with invalid destination is not a message packet 00018 FAIL_INVALID_DESTINATION_MESSAGE = 3, // Message packet with invalid destination is not an OPEN message 00019 FAIL_CONNECTION_NOT_EXIST = 4, // Packet destination is valid, but the connection does not exist, 00020 FAIL_NOT_ACCEPTED = 5, // The upper layer did not accept the connection request 00021 FAIL_MAX_CONNECTIONS_REACHED = 6 // The number of maximum opened or half-opened connections has been reached 00022 }; 00023 private: 00024 // Simulator 00025 CSimHandler* sim; 00026 00027 // Connections 00028 CConnectionEntry* connections; 00029 CConnectionEntry* connectionsFree; 00030 CConnectionEntry* connectionsAlloc; 00031 00032 __uint32 connectionsMax; 00033 __uint32 connectionsNum; 00034 00035 // Port 00036 __uint16 port; 00037 00038 // Delegates 00039 IDelegate5<void, __uint16, __uint16, CAddress, __byte, CPacket*>* 00040 delegateSend; 00041 IDelegate2<void, CConnectionReceiver*, CPacket*>* 00042 delegateRecv; 00043 IDelegate2<bool, CAddress, CPacket*>* 00044 delegateAccept; 00045 IDelegate1<void, CConnectionSender*>* 00046 delegateAccepted; 00047 00048 Delegate1<CConnectionLayer, void, CConnection*>* 00049 delegateDispose; 00050 00051 // Sender 00052 __uint32 senderSegmentSize; 00053 00054 public: 00055 CConnectionLayer( 00056 CSimHandler* sim, 00057 __uint16 port, 00058 __uint32 connectionsMax, 00059 IDelegate5<void, __uint16, __uint16, CAddress, __byte, CPacket*>* delegateSend, 00060 IDelegate2<void, CConnectionReceiver*, CPacket*>* delegateRecv, 00061 IDelegate2<bool, CAddress, CPacket*>* delegateAccept, 00062 IDelegate1<void, CConnectionSender*>* delegateAccepted, 00063 __uint32 senderSegmentSize 00064 ); 00065 virtual ~CConnectionLayer(); 00066 00067 inline __uint32 ConnectionsMax() { return this->connectionsMax; } 00068 inline __uint32 ConnectionsNum() { return this->connectionsNum; } 00069 00070 EResult Recv(CAddress srcAddress, __uint16 srcPort, __uint16 dstPort, CPacketConnection* packet); 00071 EResult Create(CAddress dstAddress, __uint16 dstPort, CConnectionReceiver** receiver); 00072 00073 CConnection* Get(__uint32 id, __uint32 idEntry); 00074 00075 private: 00076 __uint32 Alloc(); 00077 void Assign(CConnection* connection); 00078 void Free(__uint32 entry); 00079 bool IsAvailable(); 00080 00081 void Dispose(CConnection* connection); 00082 };
Last updated: February 8, 2011