Alex Bikfalvi
SimStream Documentation
HostServerPush.cpp
00001 #include "Headers.h" 00002 #include "HostServerPush.h" 00003 00004 CHostServerPush::CHostServerPush( 00005 __uint32 id, 00006 CSimHandler* sim, 00007 CAddress address, 00008 CInfoPush* 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<CHostServerPush, void, __uint32, CPacketIp*, CPacketUdp*, CPacket*>(this, &CHostServerPush::Recv); 00017 this->delegateSendStream = new Delegate2<CHostServerPush, void, CAddress, CPacketStream*>(this, &CHostServerPush::SendStream); 00018 this->delegateSendMessage = new Delegate2<CHostServerPush, void, CAddress, CStreamMessage*>(this, &CHostServerPush::SendMessage); 00019 00020 // Create stream servers for multicast channels 00021 this->streamServersMcast = new CStreamServerPushMcast*[this->info->NumChannelsMulticast()]; 00022 00023 for(__uint32 index = 0; index < this->info->NumChannelsMulticast(); index++) 00024 { 00025 this->streamServersMcast[index] = new CStreamServerPushMcast( 00026 this->sim, 00027 this->info->StreamSource(this->info->IndexMulticastToGlobal(index)), 00028 this->delegateSendStream, 00029 this->layerIgmp->DelegateJoin(), 00030 this->layerIgmp->DelegateLeave(), 00031 0 00032 ); 00033 } 00034 00035 // Create stream servers for unicast channels 00036 this->streamServersUcast = new CStreamServerPushUcast*[this->info->NumChannelsUnicast()]; 00037 00038 for(__uint32 index = 0; index < this->info->NumChannelsUnicast(); index++) 00039 { 00040 this->streamServersUcast[index] = new CStreamServerPushUcast( 00041 this->sim, 00042 this->info->StreamSource(this->info->IndexUnicastToGlobal(index)), 00043 this->delegateSendStream, 00044 this->delegateSendMessage 00045 ); 00046 } 00047 00048 // Create layer connections 00049 // Layer UDP -> this 00050 (*this->layerUdp->EventRecv()) += this->delegateRecv; 00051 } 00052 00053 CHostServerPush::~CHostServerPush() 00054 { 00055 // Delete stream servers 00056 for(__uint32 index = 0; index < this->info->NumChannelsMulticast(); index++) 00057 delete this->streamServersMcast[index]; 00058 delete[] this->streamServersMcast; 00059 00060 for(__uint32 index = 0; index < this->info->NumChannelsUnicast(); index++) 00061 delete this->streamServersUcast[index]; 00062 delete[] this->streamServersUcast; 00063 00064 // Delegates 00065 delete this->delegateRecv; 00066 delete this->delegateSendStream; 00067 delete this->delegateSendMessage; 00068 } 00069 00070 void CHostServerPush::Start() 00071 { 00072 // Start the multicast channel servers 00073 for(__uint32 index = 0; index < this->info->NumChannelsMulticast(); index++) 00074 this->streamServersMcast[index]->Start(); 00075 00076 // Start the unicast channel servers 00077 for(__uint32 index = 0; index < this->info->NumChannelsUnicast(); index++) 00078 this->streamServersUcast[index]->Start(); 00079 } 00080 00081 void CHostServerPush::Stop() 00082 { 00083 // Start the multicast channel servers 00084 for(__uint32 index = 0; index < this->info->NumChannelsMulticast(); index++) 00085 this->streamServersMcast[index]->Stop(); 00086 00087 // Start the unicast channel servers 00088 for(__uint32 index = 0; index < this->info->NumChannelsUnicast(); index++) 00089 this->streamServersUcast[index]->Stop(); 00090 } 00091 00092 void CHostServerPush::Finalize() 00093 { 00094 // Call base class finalizer 00095 CHostServer::Finalize(); 00096 00097 // Call stream servers finalizer 00098 for(__uint32 index = 0; index < this->info->NumChannelsMulticast(); index++) 00099 this->streamServersMcast[index]->Finalize(); 00100 for(__uint32 index = 0; index < this->info->NumChannelsUnicast(); index++) 00101 this->streamServersUcast[index]->Finalize(); 00102 } 00103 00104 void CHostServerPush::Recv(__uint32 entry, CPacketIp* ip, CPacketUdp* udp, CPacket* packet) 00105 { 00106 // Receive UDP packets : process only control messages for unicast servers 00107 00108 if(NULL == packet) return; 00109 if(udp->Dst() != this->info->PortControl()) return; 00110 if(packet->Type() != PACKET_TYPE_MESSAGE) return; 00111 00112 // Convert the packet to a message 00113 CStreamMessage* message = type_cast<CStreamMessage*>(packet); 00114 00115 // Send the message to the upper layer : the server for the specified stream 00116 this->streamServersUcast[this->info->IndexGlobalToUnicast(message->Stream())]->Recv(ip->Src(), message); 00117 } 00118 00119 void CHostServerPush::SendStream(CAddress dst, CPacketStream* packet) 00120 { 00121 // Send stream packet to the lower layer (TTL = 128) 00122 (*this->layerUdp->DelegateSend())(this->info->PortStream(), this->info->PortStream(), dst, 128, packet); 00123 } 00124 00125 void CHostServerPush::SendMessage(CAddress dst, CStreamMessage* message) 00126 { 00127 // Send message packet to the lower layer (TTL = 128) 00128 (*this->layerUdp->DelegateSend())(this->info->PortControl(), this->info->PortControl(), dst, 128, message); 00129 }
Last updated: February 8, 2011