UIPMC_Mcast_Connection_Handler.cpp

Go to the documentation of this file.
00001 // This may look like C, but it's really -*- C++ -*-
00002 //
00003 // $Id: UIPMC_Mcast_Connection_Handler.cpp 79015 2007-07-24 15:03:04Z vridosh $
00004 
00005 
00006 #include "orbsvcs/PortableGroup/UIPMC_Mcast_Connection_Handler.h"
00007 #include "orbsvcs/PortableGroup/UIPMC_Endpoint.h"
00008 
00009 #include "tao/Timeprobe.h"
00010 #include "tao/debug.h"
00011 #include "tao/ORB_Core.h"
00012 #include "tao/ORB.h"
00013 #include "tao/CDR.h"
00014 #include "tao/Server_Strategy_Factory.h"
00015 #include "tao/Transport_Cache_Manager.h"
00016 #include "tao/Thread_Lane_Resources.h"
00017 #include "tao/Base_Transport_Property.h"
00018 #include "tao/Resume_Handle.h"
00019 #include "tao/Protocols_Hooks.h"
00020 
00021 
00022 ACE_RCSID(PortableGroup,
00023           UIPMC_Mcast_Connection_Handler,
00024           "$Id: UIPMC_Mcast_Connection_Handler.cpp 79015 2007-07-24 15:03:04Z vridosh $")
00025 
00026 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00027 
00028 TAO_UIPMC_Mcast_Connection_Handler::TAO_UIPMC_Mcast_Connection_Handler (
00029   ACE_Thread_Manager *t)
00030   : TAO_UIPMC_MCAST_SVC_HANDLER (t, 0 , 0),
00031     TAO_Connection_Handler (0)
00032 {
00033   // This constructor should *never* get called, it is just here to
00034   // make the compiler happy: the default implementation of the
00035   // Creation_Strategy requires a constructor with that signature, we
00036   // don't use that implementation, but some (most?) compilers
00037   // instantiate it anyway.
00038   ACE_ASSERT (0);
00039 }
00040 
00041 TAO_UIPMC_Mcast_Connection_Handler::TAO_UIPMC_Mcast_Connection_Handler (
00042   TAO_ORB_Core *orb_core)
00043   : TAO_UIPMC_MCAST_SVC_HANDLER (orb_core->thr_mgr (), 0, 0),
00044     TAO_Connection_Handler (orb_core)
00045 {
00046   UIPMC_MULTICAST_TRANSPORT* specific_transport = 0;
00047   ACE_NEW(specific_transport,
00048           UIPMC_MULTICAST_TRANSPORT (this, orb_core));
00049 
00050   // store this pointer (indirectly increment ref count)
00051   this->transport (specific_transport);
00052 }
00053 
00054 TAO_UIPMC_Mcast_Connection_Handler::~TAO_UIPMC_Mcast_Connection_Handler (void)
00055 {
00056   delete this->transport ();
00057   int const result =
00058     this->release_os_resources ();
00059 
00060   if (result == -1 && TAO_debug_level)
00061     {
00062       ACE_ERROR ((LM_ERROR,
00063                   ACE_TEXT("TAO (%P|%t) - UIPMC_Mcast_Connection_Handler::")
00064                   ACE_TEXT("~UIPMC_Mcast_Connection_Handler, ")
00065                   ACE_TEXT("release_os_resources() failed %m\n")));
00066     }
00067 }
00068 
00069 const ACE_INET_Addr &
00070 TAO_UIPMC_Mcast_Connection_Handler::addr (void)
00071 {
00072   return this->addr_;
00073 }
00074 
00075 void
00076 TAO_UIPMC_Mcast_Connection_Handler::addr (const ACE_INET_Addr &addr)
00077 {
00078   this->addr_ = addr;
00079 }
00080 
00081 const ACE_INET_Addr &
00082 TAO_UIPMC_Mcast_Connection_Handler::local_addr (void)
00083 {
00084   return local_addr_;
00085 }
00086 
00087 void
00088 TAO_UIPMC_Mcast_Connection_Handler::local_addr (const ACE_INET_Addr &addr)
00089 {
00090   local_addr_ = addr;
00091 }
00092 
00093 ssize_t
00094 TAO_UIPMC_Mcast_Connection_Handler::send (const iovec [],
00095                                           int,
00096                                           const ACE_Addr &,
00097                                           int) const
00098 {
00099   ACE_ASSERT (0);
00100   return -1;
00101 }
00102 
00103 int
00104 TAO_UIPMC_Mcast_Connection_Handler::open_handler (void *v)
00105 {
00106   return this->open (v);
00107 }
00108 
00109 int
00110 TAO_UIPMC_Mcast_Connection_Handler::open (void*)
00111 {
00112   this->peer ().join (this->local_addr_);
00113 
00114   if (TAO_debug_level > 5)
00115   {
00116      ACE_DEBUG ((LM_DEBUG,
00117                  ACE_TEXT("TAO (%P|%t) - UIPMC_Mcast_Connection_Handler::open_server, ")
00118                  ACE_TEXT("subcribed to multicast group at %s:%d\n"),
00119                  this->local_addr_.get_host_addr (),
00120                  this->local_addr_.get_port_number ()
00121                ));
00122   }
00123 
00124   this->transport ()->id ((size_t) this->peer ().get_handle ());
00125 
00126   return 0;
00127 }
00128 
00129 int
00130 TAO_UIPMC_Mcast_Connection_Handler::resume_handler (void)
00131 {
00132   return ACE_Event_Handler::ACE_APPLICATION_RESUMES_HANDLER;
00133 }
00134 
00135 int
00136 TAO_UIPMC_Mcast_Connection_Handler::close_connection (void)
00137 {
00138   return this->close_connection_eh (this);
00139 }
00140 
00141 int
00142 TAO_UIPMC_Mcast_Connection_Handler::handle_input (ACE_HANDLE h)
00143 {
00144   return this->handle_input_eh (h, this);
00145 }
00146 
00147 int
00148 TAO_UIPMC_Mcast_Connection_Handler::handle_output (ACE_HANDLE handle)
00149 {
00150   int result =
00151     this->handle_output_eh (handle, this);
00152 
00153   if (result == -1)
00154     {
00155       this->close_connection ();
00156       return 0;
00157     }
00158 
00159   return result;
00160 }
00161 
00162 int
00163 TAO_UIPMC_Mcast_Connection_Handler::handle_timeout (const ACE_Time_Value &,
00164                                                         const void *)
00165 {
00166   // Using this to ensure this instance will be deleted (if necessary)
00167   // only after reset_state(). Without this, when this refcount==1 -
00168   // the call to close() will cause a call to remove_reference() which
00169   // will delete this. At that point this->reset_state() is in no
00170   // man's territory and that causes SEGV on some platforms (Windows!)
00171 
00172   TAO_Auto_Reference<TAO_UIPMC_Mcast_Connection_Handler> safeguard (*this);
00173 
00174   // NOTE: Perhaps not the best solution, as it feels like the upper
00175   // layers should be responsible for this?
00176 
00177   // We don't use this upcall for I/O.  This is only used by the
00178   // Connector to indicate that the connection timedout.  Therefore,
00179   // we should call close().
00180   int ret = this->close ();
00181   this->reset_state (TAO_LF_Event::LFS_TIMEOUT);
00182   return ret;
00183 }
00184 
00185 int
00186 TAO_UIPMC_Mcast_Connection_Handler::handle_close (ACE_HANDLE,
00187                                                       ACE_Reactor_Mask)
00188 {
00189   // No asserts here since the handler is registered with the Reactor
00190   // and the handler ownership is given to the Reactor.  When the
00191   // Reactor closes, it will call handle_close() on the handler.  It
00192   // is however important to overwrite handle_close() to do nothing
00193   // since the base class does too much.
00194   return 0;
00195 }
00196 
00197 int
00198 TAO_UIPMC_Mcast_Connection_Handler::close (u_long)
00199 {
00200   return this->close_handler ();
00201 }
00202 
00203 int
00204 TAO_UIPMC_Mcast_Connection_Handler::release_os_resources (void)
00205 {
00206   return this->peer ().close ();
00207 }
00208 
00209 int
00210 TAO_UIPMC_Mcast_Connection_Handler::add_transport_to_cache (void)
00211 {
00212   ACE_INET_Addr addr;
00213 
00214   // This function is called by the acceptor to add this
00215   // transport to the transport cache.  This is really
00216   // important for proper shutdown.  The address used
00217   // is irrelevent, since UIPMC is connectionless.
00218 
00219   // Construct a UIPMC_Endpoint object.
00220   TAO_UIPMC_Endpoint endpoint (addr);
00221 
00222   // Construct a property object
00223   TAO_Base_Transport_Property prop (&endpoint);
00224 
00225   // Add the handler to Cache
00226   return this->orb_core ()->lane_resources ()
00227           .transport_cache ().cache_transport (&prop,
00228                                                this->transport ());
00229 }
00230 
00231 TAO_END_VERSIONED_NAMESPACE_DECL

Generated on Tue Feb 2 17:49:50 2010 for TAO_PortableGroup by  doxygen 1.4.7