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

RMCast_Membership.cpp

Go to the documentation of this file.
00001 //
00002 // $Id: RMCast_Membership.cpp,v 1.1.1.1 2001/12/04 14:33:17 chad Exp $
00003 //
00004 
00005 #include "RMCast_Membership.h"
00006 #include "RMCast_Proxy.h"
00007 
00008 #if !defined (__ACE_INLINE__)
00009 # include "RMCast_Membership.i"
00010 #endif /* ! __ACE_INLINE__ */
00011 
00012 ACE_RCSID(ace, RMCast_Membership, "$Id: RMCast_Membership.cpp,v 1.1.1.1 2001/12/04 14:33:17 chad Exp $")
00013 
00014 ACE_RMCast_Membership::~ACE_RMCast_Membership (void)
00015 {
00016 }
00017 
00018 int
00019 ACE_RMCast_Membership::has_members (void)
00020 {
00021   ACE_GUARD_RETURN (ACE_SYNCH_MUTEX, ace_mon, this->mutex_, -1);
00022 
00023   Proxy_Iterator end = this->proxies_.end ();
00024   Proxy_Iterator i = this->proxies_.begin ();
00025   return (i != end);
00026 }
00027 
00028 int
00029 ACE_RMCast_Membership::ack (ACE_RMCast::Ack &ack)
00030 {
00031   //ACE_DEBUG ((LM_DEBUG, "ACE_RMCast_Membership::ack (%d:%d)\n",
00032   //            ack.next_expected, ack.highest_received));
00033 
00034   ACE_RMCast::Ack next_ack;
00035   {
00036     ACE_GUARD_RETURN (ACE_SYNCH_MUTEX, ace_mon, this->mutex_, -1);
00037     if (ack.next_expected < this->next_expected_)
00038       {
00039         // @@ This violates an invariant of the class, shouldn't
00040         // happen...
00041         //ACE_DEBUG ((LM_DEBUG, "ACE_RMCast_Membership::ack[2]\n"));
00042         return 0;
00043       }
00044     else if (ack.next_expected == this->next_expected_)
00045       {
00046         // Nothing new, just continue....
00047         //ACE_DEBUG ((LM_DEBUG, "ACE_RMCast_Membership::ack[3]\n"));
00048         return 0;
00049       }
00050 
00051     int r = this->compute_ack_i (ack.source, next_ack);
00052     if (r < 0)
00053       return r;
00054     if (r == 1)
00055       return 0;
00056   }
00057 
00058   //ACE_DEBUG ((LM_DEBUG, "ACE_RMCast_Membership::ack[4] (%d:%d)\n",
00059   //            next_ack.next_expected, next_ack.highest_received));
00060 
00061   return this->ACE_RMCast_Module::ack (next_ack);
00062 }
00063 
00064 int
00065 ACE_RMCast_Membership::join (ACE_RMCast::Join &join)
00066 {
00067   if (join.source == 0)
00068     return 0;
00069 
00070   {
00071     //  ACE_DEBUG ((LM_DEBUG,
00072     //            "RMCast_Membership::join - %d\n",
00073     //            long(join.source)));
00074 
00075     ACE_GUARD_RETURN (ACE_SYNCH_MUTEX, ace_mon, this->mutex_, -1);
00076     if (this->proxies_.insert (join.source) == -1)
00077       return -1;
00078   }
00079   (void) this->generate_ack (join.source);
00080 
00081   return this->ACE_RMCast_Module::join (join);
00082 }
00083 
00084 int
00085 ACE_RMCast_Membership::leave (ACE_RMCast::Leave &leave)
00086 {
00087   if (leave.source == 0)
00088     return 0;
00089 
00090   {
00091     ACE_GUARD_RETURN (ACE_SYNCH_MUTEX, ace_mon, this->mutex_, -1);
00092     (void) this->proxies_.remove (leave.source);
00093   }
00094   (void) this->generate_ack (leave.source);
00095 
00096   return this->ACE_RMCast_Module::leave (leave);
00097 }
00098 
00099 int
00100 ACE_RMCast_Membership::generate_ack (ACE_RMCast_Proxy *proxy)
00101 {
00102   ACE_RMCast::Ack next_ack;
00103   {
00104     ACE_GUARD_RETURN (ACE_SYNCH_MUTEX, ace_mon, this->mutex_, -1);
00105     int r = this->compute_ack_i (proxy, next_ack);
00106     if (r < 0)
00107       return r;
00108     if (r == 1)
00109       return 0;
00110   }
00111 
00112   //ACE_DEBUG ((LM_DEBUG, "ACE_RMCast_Membership::ack[6] (%d:%d)\n",
00113   //            next_ack.next_expected, next_ack.highest_received));
00114 
00115   return this->ACE_RMCast_Module::ack (next_ack);
00116 }
00117 
00118 int
00119 ACE_RMCast_Membership::compute_ack_i (ACE_RMCast_Proxy *source,
00120                                       ACE_RMCast::Ack &next_ack)
00121 {
00122   Proxy_Iterator end = this->proxies_.end ();
00123   Proxy_Iterator i = this->proxies_.begin ();
00124   if (i == end)
00125     return 1;
00126 
00127   //ACE_DEBUG ((LM_DEBUG,
00128   //            "RMCast_Membership::generate_ack[1] - %d -> (%d:%d)\n",
00129   //            long(*i),
00130   //            (*i)->next_expected (),
00131   //            (*i)->highest_received ()));
00132 
00133   ACE_UINT32 next_expected = (*i)->next_expected ();
00134   ACE_UINT32 highest_received = (*i)->highest_received ();
00135   ++i;
00136 
00137   for (; i != end; ++i)
00138     {
00139       //    ACE_DEBUG ((LM_DEBUG,
00140       //            "RMCast_Membership::generate_ack[2] - %d -> (%d:%d)\n",
00141       //            long(*i),
00142       //            (*i)->next_expected (),
00143       //            (*i)->highest_received ()));
00144 
00145       ACE_UINT32 s = (*i)->next_expected ();
00146       if (s < next_expected)
00147         next_expected = s;
00148       ACE_UINT32 r = (*i)->highest_received ();
00149       if (r > highest_received)
00150         highest_received = r;
00151     }
00152 #if 0
00153   // @@TODO: this is an important feature, disabled until it is
00154   // fully debugged
00155   if (this->next_expected_ >= next_expected
00156       || this->highest_received_ >= highest_received)
00157     {
00158       // No change....
00159       ACE_DEBUG ((LM_DEBUG,
00160                   "RMCast_Membership::generate_ack[3]\n"));
00161       return 1;
00162     }
00163 #endif /* 0 */
00164   this->next_expected_ = next_expected;
00165   this->highest_received_ = highest_received;
00166   next_ack.source = source;
00167   next_ack.next_expected = this->next_expected_;
00168   next_ack.highest_received = this->highest_received_;
00169 
00170   //ACE_DEBUG ((LM_DEBUG,
00171   //            "RMCast_Membership::generate_ack[4] - (%d:%d)\n",
00172   //            next_ack.next_expected,
00173   //            next_ack.highest_received));
00174 
00175   return 0;
00176 }
00177 
00178 #if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION)
00179 
00180 template class ACE_Unbounded_Set<ACE_RMCast_Proxy*>;
00181 template class ACE_Unbounded_Set_Iterator<ACE_RMCast_Proxy*>;
00182 template class ACE_Node<ACE_RMCast_Proxy*>;
00183 
00184 #endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */

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