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

RMCast_Reassembly.cpp

Go to the documentation of this file.
00001 // $Id: RMCast_Reassembly.cpp,v 1.1.1.2.2.1 2003/05/05 16:04:55 chad Exp $
00002 
00003 #include "RMCast_Reassembly.h"
00004 #include "RMCast_Partial_Message.h"
00005 #include "ace/Message_Block.h"
00006 
00007 #if !defined (ACE_LACKS_PRAGMA_ONCE)
00008 # pragma once
00009 #endif /* ACE_LACKS_PRAGMA_ONCE */
00010 
00011 #if !defined (__ACE_INLINE__)
00012 #include "RMCast_Reassembly.i"
00013 #endif /* __ACE_INLINE__ */
00014 
00015 ACE_RCSID(ace, RMCast_Reassembly, "$Id: RMCast_Reassembly.cpp,v 1.1.1.2.2.1 2003/05/05 16:04:55 chad Exp $")
00016 
00017 
00018 ACE_RMCast_Reassembly::ACE_RMCast_Reassembly (void)
00019   :  ACE_RMCast_Module ()
00020 {
00021 }
00022 
00023 ACE_RMCast_Reassembly::~ACE_RMCast_Reassembly (void)
00024 {
00025   (void) this->close_i ();
00026 }
00027 
00028 /**
00029  *
00030  * We cleanup the resources in the destructor
00031  */
00032 int
00033 ACE_RMCast_Reassembly::close ()
00034 {
00035   this->close_i ();
00036   return this->ACE_RMCast_Module::close ();
00037 }
00038 
00039 int
00040 ACE_RMCast_Reassembly::data (ACE_RMCast::Data &data)
00041 {
00042   if (this->next () == 0)
00043     return 0;
00044 
00045   // ACE_DEBUG ((LM_DEBUG,
00046   //             "Reassembly::data - %d,%d,%d\n",
00047   //             data.sequence_number,
00048   //             data.total_size,
00049   //             data.fragment_offset));
00050 
00051   if (data.payload->length () + data.fragment_offset > data.total_size)
00052     {
00053       ACE_ERROR ((LM_ERROR,
00054                   "RMCast_Reassembly::data - invalid size\n"));
00055       return -1; // Corrupt message?
00056     }
00057 
00058   ACE_RMCast_Partial_Message *message;
00059 
00060   {
00061     ACE_GUARD_RETURN (ACE_SYNCH_MUTEX, ace_mon, this->mutex_, -1);
00062     if (this->messages_.find (data.sequence_number, message) == -1)
00063       {
00064         ACE_NEW_RETURN (message,
00065                         ACE_RMCast_Partial_Message (data.total_size),
00066                         -1);
00067 
00068         // ACE_DEBUG ((LM_DEBUG,
00069         //             "Reassembly::data - new message\n"));
00070         if (this->messages_.bind (data.sequence_number,
00071                                   message) == -1)
00072           return -1; // Internal error?
00073       }
00074 
00075     if (message->fragment_received (data.total_size,
00076                                     data.fragment_offset,
00077                                     data.payload) == -1)
00078       {
00079         // ACE_DEBUG ((LM_DEBUG,
00080         //             "Error in fragment_received\n"));
00081         return -1;
00082       }
00083 
00084     if (!message->is_complete ())
00085       {
00086         // ACE_DEBUG ((LM_DEBUG,
00087         //             "Reassembly::data - message still incomplete\n"));
00088         return 0;
00089       }
00090 
00091     if (this->messages_.unbind (data.sequence_number) == -1)
00092       {
00093         // ACE_DEBUG ((LM_DEBUG,
00094         //            "Reassembly::data - message now complete\n"));
00095         return -1;
00096       }
00097   }
00098 
00099   // Push the message...
00100   ACE_RMCast::Data downstream_data;
00101   downstream_data.source = data.source;
00102   downstream_data.sequence_number = data.sequence_number;
00103   downstream_data.total_size = ACE_static_cast(
00104                                     ACE_UINT32,
00105                                     message->message_body ()->length ());
00106   downstream_data.fragment_offset = 0;
00107   downstream_data.payload = message->message_body ();
00108 
00109   int r = this->next ()->data (downstream_data);
00110 
00111   delete message;
00112 
00113   return r;
00114 }
00115 
00116 void
00117 ACE_RMCast_Reassembly::close_i (void)
00118 {
00119   for (Message_Map_Iterator i = this->messages_.begin ();
00120        i != this->messages_.end ();
00121        ++i)
00122     {
00123       ACE_RMCast_Partial_Message *message = (*i).int_id_;
00124       if (message != 0)
00125         delete message;
00126     }
00127   this->messages_.unbind_all ();
00128 }
00129 
00130 #if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION)
00131 
00132 template class ACE_Hash_Map_Manager<ACE_UINT32,ACE_RMCast_Partial_Message*,ACE_Null_Mutex>;
00133 template class ACE_Hash_Map_Manager_Ex<ACE_UINT32,ACE_RMCast_Partial_Message*,ACE_Hash<ACE_UINT32>,ACE_Equal_To<ACE_UINT32>,ACE_Null_Mutex>;
00134 template class ACE_Hash_Map_Iterator<ACE_UINT32,ACE_RMCast_Partial_Message*,ACE_Null_Mutex>;
00135 template class ACE_Hash_Map_Iterator_Ex<ACE_UINT32,ACE_RMCast_Partial_Message*,ACE_Hash<ACE_UINT32>,ACE_Equal_To<ACE_UINT32>,ACE_Null_Mutex >;
00136 template class ACE_Hash_Map_Reverse_Iterator_Ex<ACE_UINT32,ACE_RMCast_Partial_Message*,ACE_Hash<ACE_UINT32>,ACE_Equal_To<ACE_UINT32>,ACE_Null_Mutex >;
00137 template class ACE_Hash_Map_Iterator_Base_Ex<ACE_UINT32,ACE_RMCast_Partial_Message*,ACE_Hash<ACE_UINT32>,ACE_Equal_To<ACE_UINT32>,ACE_Null_Mutex >;
00138 template class ACE_Hash_Map_Entry<ACE_UINT32,ACE_RMCast_Partial_Message*>;
00139 
00140 template class ACE_Less_Than<ACE_UINT32>;
00141 
00142 #endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */

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