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