Alex Bikfalvi
SimStream Documentation
HostClientPush.cpp
00001 #include "Headers.h" 00002 #include "HostClientPush.h" 00003 #include "Debug.h" 00004 00005 CHostClientPush::CHostClientPush( 00006 __uint32 id, 00007 CSimHandler* sim, 00008 CAddress address, 00009 CInfoPush* info, 00010 CData* data, 00011 __bitrate bw 00012 ) : CHostClient(id, sim, address, info, data, bw) 00013 { 00014 // Global 00015 this->info = info; 00016 00017 // Delegates 00018 this->delegateRecv = new Delegate4<CHostClientPush, void, __uint32, CPacketIp*, CPacketUdp*, CPacket*>(this, &CHostClientPush::Recv); 00019 this->delegateSendStream = new Delegate2<CHostClientPush, void, CAddress, CPacketStream*>(this, &CHostClientPush::SendStream); 00020 this->delegateSendMessage = new Delegate2<CHostClientPush, void, CAddress, CStreamMessage*>(this, &CHostClientPush::SendMessage); 00021 this->delegateLink = new Delegate0<CHostClientPush, CLink*>(this, &CHostClientPush::Link); 00022 00023 // Stream client push 00024 this->streamClient = new CStreamClientPush( 00025 this->sim, 00026 this->info, 00027 this->address, 00028 this->delegateSendStream, 00029 this->delegateSendMessage, 00030 this->layerIgmp->DelegateJoin(), 00031 this->layerIgmp->DelegateLeave(), 00032 this->delegateLink, 00033 0, 00034 bw); 00035 00036 // Create layer connections 00037 // Layer UDP -> this 00038 (*this->layerUdp->EventRecv()) += this->delegateRecv; 00039 } 00040 00041 CHostClientPush::~CHostClientPush() 00042 { 00043 // Client 00044 delete this->streamClient; 00045 00046 // Delegates 00047 delete this->delegateRecv; 00048 delete this->delegateSendStream; 00049 delete this->delegateSendMessage; 00050 delete this->delegateLink; 00051 } 00052 00053 void CHostClientPush::ChannelConnectMcast(CChannel* channel) 00054 { 00055 // Start the client 00056 this->streamClient->Start(channel); 00057 00058 #ifdef MULTICAST 00059 // Multicast statistics 00060 this->info->MulticastJoin(this->id, channel->Id()); 00061 #endif 00062 } 00063 00064 void CHostClientPush::ChannelDisconnectMcast() 00065 { 00066 // Stop the client 00067 this->streamClient->Stop(); 00068 00069 #ifdef MULTICAST 00070 // Multicast statistics 00071 this->info->MulticastLeave(this->id, channel->Id()); 00072 #endif 00073 } 00074 00075 void CHostClientPush::ChannelConnectUcast(CChannel* channel) 00076 { 00077 // Start the client 00078 this->streamClient->Start(channel); 00079 } 00080 00081 void CHostClientPush::ChannelDisconnectUcast() 00082 { 00083 // Stop the client 00084 this->streamClient->Stop(); 00085 } 00086 00087 void CHostClientPush::Recv(__uint32 entry, CPacketIp* ip, CPacketUdp* udp, CPacket* packet) 00088 { 00089 // Process the received packets with the client 00090 this->streamClient->Recv(ip->Src(), ip->Dst(), udp->Src(), udp->Dst(), packet); 00091 } 00092 00093 00094 void CHostClientPush::SendStream(CAddress dst, CPacketStream* packet) 00095 { 00096 // Send the stream packet to the UDP layer (TTL = 128) 00097 (*this->layerUdp->DelegateSend())(this->info->PortStream(), this->info->PortStream(), dst, 128, packet); 00098 } 00099 00100 void CHostClientPush::SendMessage(CAddress dst, CStreamMessage* message) 00101 { 00102 // Send the message packet to the UDP layer (TTL = 128) 00103 (*this->layerUdp->DelegateSend())(this->info->PortControl(), this->info->PortControl(), dst, 128, message); 00104 } 00105 00106 void CHostClientPush::Finalize() 00107 { 00108 // Call base class finalizer 00109 CHostClient::Finalize(); 00110 00111 // Call client finalizer 00112 this->streamClient->Finalize(); 00113 }
Last updated: February 8, 2011