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