Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

RMCast_UDP_Proxy.cpp

Go to the documentation of this file.
00001 // $Id: RMCast_UDP_Proxy.cpp,v 1.1.1.1 2001/12/04 14:33:17 chad Exp $
00002 
00003 #include "RMCast_UDP_Proxy.h"
00004 #include "RMCast_Module.h"
00005 #include "RMCast_IO_UDP.h"
00006 #include "ace/Message_Block.h"
00007 
00008 #if !defined (__ACE_INLINE__)
00009 # include "RMCast_UDP_Proxy.i"
00010 #endif /* ! __ACE_INLINE__ */
00011 
00012 ACE_RCSID(ace, RMCast_UDP_Proxy, "$Id: RMCast_UDP_Proxy.cpp,v 1.1.1.1 2001/12/04 14:33:17 chad Exp $")
00013 
00014 ACE_RMCast_UDP_Proxy::ACE_RMCast_UDP_Proxy (ACE_RMCast_IO_UDP *io_udp,
00015                                             const ACE_INET_Addr &addr)
00016   : io_udp_ (io_udp)
00017   , peer_addr_ (addr)
00018 {
00019 }
00020 
00021 ACE_RMCast_UDP_Proxy::~ACE_RMCast_UDP_Proxy (void)
00022 {
00023 }
00024 
00025 int
00026 ACE_RMCast_UDP_Proxy::receive_message (char *buffer, size_t size)
00027 {
00028   int type = buffer[0];
00029 
00030   // @@ What should we do with invalid messages like this?
00031   //
00032   if (type < 0 || type >= ACE_RMCast::MT_LAST)
00033     return 0;
00034 
00035   if (type == ACE_RMCast::MT_POLL)
00036     {
00037       ACE_RMCast::Poll poll;
00038       poll.source = this;
00039       return this->poll (poll);
00040     }
00041 
00042   else if (type == ACE_RMCast::MT_ACK_JOIN)
00043     {
00044       ACE_RMCast::Ack_Join ack_join;
00045       ack_join.source = this;
00046 
00047       const size_t header_size = 1 + sizeof(ACE_UINT32);
00048       if (size < header_size)
00049         {
00050           // The message is too small
00051           return 0;
00052         }
00053 
00054       ACE_UINT32 tmp;
00055 
00056       ACE_OS::memcpy (&tmp, buffer + 1,
00057                       sizeof(tmp));
00058       ack_join.next_sequence_number = ACE_NTOHL (tmp);
00059       return this->ack_join (ack_join);
00060     }
00061 
00062   else if (type == ACE_RMCast::MT_ACK_LEAVE)
00063     {
00064       ACE_RMCast::Ack_Leave ack_leave;
00065       ack_leave.source = this;
00066       return this->ack_leave (ack_leave);
00067     }
00068 
00069   else if (type == ACE_RMCast::MT_DATA)
00070     {
00071       ACE_RMCast::Data data;
00072       data.source = this;
00073       const size_t header_size = 1 + 3 * sizeof(ACE_UINT32);
00074       if (size < header_size)
00075         {
00076           // The message is too small
00077           return 0;
00078         }
00079 
00080       ACE_UINT32 tmp;
00081 
00082       ACE_OS::memcpy (&tmp, buffer + 1,
00083                       sizeof(tmp));
00084       data.sequence_number = ACE_NTOHL (tmp);
00085 
00086       ACE_OS::memcpy (&tmp, buffer + 1 + sizeof(tmp),
00087                       sizeof(tmp));
00088       data.total_size = ACE_NTOHL (tmp);
00089 
00090       ACE_OS::memcpy (&tmp, buffer + 1 + 2 * sizeof(tmp),
00091                       sizeof(tmp));
00092       data.fragment_offset = ACE_NTOHL (tmp);
00093 
00094       // Pass it up the module...
00095       ACE_Message_Block *mb;
00096       ACE_NEW_RETURN (mb, ACE_Message_Block, -1);
00097       mb->size (size - header_size);
00098       mb->copy (buffer + header_size, size - header_size);
00099 
00100       data.payload = mb;
00101       return this->data (data);
00102     }
00103 
00104   else if (type == ACE_RMCast::MT_JOIN)
00105     {
00106       ACE_RMCast::Join join;
00107       join.source = this;
00108       return this->join (join);
00109     }
00110 
00111   else if (type == ACE_RMCast::MT_LEAVE)
00112     {
00113       ACE_RMCast::Leave leave;
00114       leave.source = this;
00115       return this->leave (leave);
00116     }
00117 
00118   else if (type == ACE_RMCast::MT_ACK)
00119     {
00120       ACE_RMCast::Ack ack;
00121       ack.source = this;
00122 
00123       const size_t header_size = 1 + sizeof(ACE_UINT32);
00124       if (size < header_size)
00125         {
00126           // The message is too small
00127           return 0;
00128         }
00129 
00130       ACE_UINT32 tmp;
00131 
00132       ACE_OS::memcpy (&tmp, buffer + 1,
00133                       sizeof(tmp));
00134       ack.next_expected = ACE_NTOHL (tmp);
00135       ACE_OS::memcpy (&tmp, buffer + 1 + sizeof(ACE_UINT32),
00136                       sizeof(tmp));
00137       ack.highest_received = ACE_NTOHL (tmp);
00138 
00139       return this->ack (ack);
00140     }
00141 
00142   return 0;
00143 }
00144 
00145 int
00146 ACE_RMCast_UDP_Proxy::reply_data (ACE_RMCast::Data &data)
00147 {
00148   return this->io_udp_->send_data (data, this->peer_addr_);
00149 }
00150 
00151 int
00152 ACE_RMCast_UDP_Proxy::reply_poll (ACE_RMCast::Poll &poll)
00153 {
00154   return this->io_udp_->send_poll (poll, this->peer_addr_);
00155 }
00156 
00157 int
00158 ACE_RMCast_UDP_Proxy::reply_ack_join (ACE_RMCast::Ack_Join &ack_join)
00159 {
00160   (void) this->ACE_RMCast_Proxy::reply_ack_join (ack_join);
00161   return this->io_udp_->send_ack_join (ack_join, this->peer_addr_);
00162 }
00163 
00164 int
00165 ACE_RMCast_UDP_Proxy::reply_ack_leave (ACE_RMCast::Ack_Leave &ack_leave)
00166 {
00167   return this->io_udp_->send_ack_leave (ack_leave, this->peer_addr_);
00168 }
00169 
00170 int
00171 ACE_RMCast_UDP_Proxy::reply_ack (ACE_RMCast::Ack &ack)
00172 {
00173   return this->io_udp_->send_ack (ack, this->peer_addr_);
00174 }
00175 
00176 int
00177 ACE_RMCast_UDP_Proxy::reply_join (ACE_RMCast::Join &join)
00178 {
00179   return this->io_udp_->send_join (join, this->peer_addr_);
00180 }
00181 
00182 int
00183 ACE_RMCast_UDP_Proxy::reply_leave (ACE_RMCast::Leave &leave)
00184 {
00185   return this->io_udp_->send_leave (leave, this->peer_addr_);
00186 }

Generated on Mon Jun 16 13:12:38 2003 for ACE_RMCast by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002