Alex Bikfalvi
SimStream Documentation
HostServerPushSelect.cpp
00001 #include "Headers.h" 00002 #include "HostServerPushSelect.h" 00003 00004 CHostServerPushSelect::CHostServerPushSelect( 00005 __uint32 id, 00006 CSimHandler* sim, 00007 CAddress address, 00008 CInfoPushSelect* info, 00009 CData* data 00010 ) : CHostServer(id, sim, address, info, data) 00011 { 00012 // Global 00013 this->info = info; 00014 00015 // Delegates 00016 this->delegateRecv = new Delegate4<CHostServerPushSelect, void, __uint32, CPacketIp*, CPacketUdp*, CPacket*>(this, &CHostServerPushSelect::Recv); 00017 this->delegateSendStream = new Delegate2<CHostServerPushSelect, void, CAddress, CPacketStream*>(this, &CHostServerPushSelect::SendStream); 00018 this->delegateSendMessage = new Delegate2<CHostServerPushSelect, void, CAddress, CStreamMessage*>(this, &CHostServerPushSelect::SendMessage); 00019 00020 // Create stream servers for unicast channels 00021 this->streamServers = new CStreamServerPushSelect*[this->info->NumChannels()]; 00022 00023 for(__uint32 index = 0; index < this->info->NumChannels(); index++) 00024 { 00025 this->streamServers[index] = new CStreamServerPushSelect( 00026 this->sim, 00027 this->info, 00028 this->info->StreamSource(index), 00029 this->delegateSendStream, 00030 this->delegateSendMessage 00031 ); 00032 } 00033 00034 // Create layer connections 00035 // Layer UDP -> this 00036 (*this->layerUdp->EventRecv()) += this->delegateRecv; 00037 } 00038 00039 CHostServerPushSelect::~CHostServerPushSelect() 00040 { 00041 // Delete stream servers 00042 for(__uint32 index = 0; index < this->info->NumChannels(); index++) 00043 delete this->streamServers[index]; 00044 delete[] this->streamServers; 00045 00046 // Delegates 00047 delete this->delegateRecv; 00048 delete this->delegateSendStream; 00049 delete this->delegateSendMessage; 00050 } 00051 00052 void CHostServerPushSelect::Start() 00053 { 00054 // Start the unicast channel servers 00055 for(__uint32 index = 0; index < this->info->NumChannels(); index++) 00056 this->streamServers[index]->Start(); 00057 } 00058 00059 void CHostServerPushSelect::Stop() 00060 { 00061 // Start the unicast channel servers 00062 for(__uint32 index = 0; index < this->info->NumChannels(); index++) 00063 this->streamServers[index]->Stop(); 00064 } 00065 00066 void CHostServerPushSelect::Finalize() 00067 { 00068 // Call base class finalizer 00069 CHostServer::Finalize(); 00070 00071 // Call stream servers finalizer 00072 for(__uint32 index = 0; index < this->info->NumChannels(); index++) 00073 this->streamServers[index]->Finalize(); 00074 } 00075 00076 void CHostServerPushSelect::Recv(__uint32 entry, CPacketIp* ip, CPacketUdp* udp, CPacket* packet) 00077 { 00078 // Receive UDP packets : process only control messages for unicast servers 00079 00080 if(NULL == packet) return; 00081 if(udp->Dst() != this->info->PortControl()) return; 00082 if(packet->Type() != PACKET_TYPE_MESSAGE) return; 00083 00084 // Convert the packet to a message 00085 CStreamMessage* message = type_cast<CStreamMessage*>(packet); 00086 00087 // Send the message to the upper layer : the server for the specified stream 00088 this->streamServers[message->Stream()]->Recv(ip->Src(), message); 00089 } 00090 00091 void CHostServerPushSelect::SendStream(CAddress dst, CPacketStream* packet) 00092 { 00093 // Send stream packet to the lower layer (TTL = 128) 00094 (*this->layerUdp->DelegateSend())(this->info->PortStream(), this->info->PortStream(), dst, 128, packet); 00095 } 00096 00097 void CHostServerPushSelect::SendMessage(CAddress dst, CStreamMessage* message) 00098 { 00099 // Send message packet to the lower layer (TTL = 128) 00100 (*this->layerUdp->DelegateSend())(this->info->PortControl(), this->info->PortControl(), dst, 128, message); 00101 }
Last updated: February 8, 2011