PortableGroup_Acceptor_Registry.cpp

Go to the documentation of this file.
00001 // $Id: PortableGroup_Acceptor_Registry.cpp 77001 2007-02-12 07:54:49Z johnnyw $
00002 
00003 #include "orbsvcs/PortableGroup/PortableGroup_Acceptor_Registry.h"
00004 #include "tao/ORB_Core.h"
00005 #include "tao/Profile.h"
00006 #include "tao/Protocol_Factory.h"
00007 #include "tao/GIOP_Message_State.h"
00008 #include "tao/debug.h"
00009 #include "tao/Endpoint.h"
00010 #include "tao/Thread_Lane_Resources.h"
00011 #include "tao/Leader_Follower.h"
00012 #include "tao/SystemException.h"
00013 
00014 ACE_RCSID (PortableGroup,
00015            PortableGroup_Acceptor_Registry,
00016            "$Id: PortableGroup_Acceptor_Registry.cpp 77001 2007-02-12 07:54:49Z johnnyw $")
00017 
00018 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00019 
00020 TAO_PortableGroup_Acceptor_Registry::TAO_PortableGroup_Acceptor_Registry (void)
00021 {
00022 }
00023 
00024 TAO_PortableGroup_Acceptor_Registry::~TAO_PortableGroup_Acceptor_Registry (void)
00025 {
00026   // Free the memory for the endpoints.
00027   Entry *entry;
00028   Acceptor_Registry_Iterator iter (this->registry_);
00029 
00030   while (iter.next (entry))
00031     {
00032       delete entry->endpoint;
00033       delete entry->acceptor;
00034       iter.advance ();
00035     }
00036 }
00037 
00038 
00039 void
00040 TAO_PortableGroup_Acceptor_Registry::open (const TAO_Profile* profile,
00041                                            TAO_ORB_Core &orb_core)
00042 {
00043   Entry *entry;
00044 
00045   if (this->find (profile, entry) == 1)
00046     {
00047       // Found it.  Increment the reference count.
00048       ++entry->cnt;
00049     }
00050   else
00051     {
00052       // Not found.  Open a new acceptor.
00053 
00054       // Now get the list of available protocol factories.
00055       TAO_ProtocolFactorySetItor end =
00056         orb_core.protocol_factories ()->end ();
00057 
00058       // int found = 0;
00059       // If usable protocol (factory) is found then this will be
00060       // set equal to 1.
00061 
00062       for (TAO_ProtocolFactorySetItor factory =
00063              orb_core.protocol_factories ()->begin ();
00064            factory != end;
00065            ++factory)
00066         {
00067           if ((*factory)->factory ()->tag () == profile->tag ())
00068             {
00069               this->open_i (profile,
00070                             orb_core,
00071                             factory);
00072 
00073               // found = 1;  // A usable protocol was found.
00074             }
00075           else
00076             continue;
00077         }
00078     }
00079 }
00080 
00081 #define MAX_ADDR_LENGTH   (32)
00082 
00083 void
00084 TAO_PortableGroup_Acceptor_Registry::open_i (const TAO_Profile* profile,
00085                                              TAO_ORB_Core &orb_core,
00086                                              TAO_ProtocolFactorySetItor &factory)
00087 {
00088   TAO_Acceptor *acceptor = (*factory)->factory ()->make_acceptor ();
00089 
00090   if (acceptor != 0)
00091     {
00092       // Extract the desired endpoint/protocol version if one
00093       // exists.
00094       const TAO_GIOP_Message_Version &version = profile->version ();
00095       char buffer [MAX_ADDR_LENGTH];
00096 
00097       // Removed the constness of profile.  We're not changing
00098       // anything, but need to call a nonconst function.
00099       TAO_Profile* nc_profile = const_cast<TAO_Profile *> (profile);
00100       nc_profile->endpoint ()->addr_to_string (buffer, MAX_ADDR_LENGTH);
00101 
00102       if (acceptor->open (&orb_core,
00103                           orb_core.lane_resources ().leader_follower ().reactor(),
00104                           version.major,
00105                           version.minor,
00106                           buffer,
00107                           0) == -1)
00108         {
00109           delete acceptor;
00110 
00111           if (TAO_debug_level > 0)
00112             ACE_ERROR ((LM_ERROR,
00113                         ACE_TEXT ("TAO (%P|%t) ")
00114                         ACE_TEXT ("unable to open acceptor ")
00115                         ACE_TEXT ("for <%s>%p\n"),
00116                         buffer,
00117                         ""));
00118 
00119           throw CORBA::BAD_PARAM (
00120             CORBA::SystemException::_tao_minor_code (
00121               TAO_ACCEPTOR_REGISTRY_OPEN_LOCATION_CODE,
00122               EINVAL),
00123             CORBA::COMPLETED_NO);
00124         }
00125 
00126       // Add acceptor to list.
00127       Entry tmp_entry;
00128       tmp_entry.acceptor = acceptor;
00129       tmp_entry.endpoint = nc_profile->endpoint ()->duplicate ();
00130       tmp_entry.cnt = 1;
00131 
00132       if (this->registry_.enqueue_tail (tmp_entry) == -1)
00133         {
00134           delete acceptor;
00135 
00136           if (TAO_debug_level > 0)
00137             ACE_ERROR ((LM_ERROR,
00138                         ACE_TEXT ("TAO (%P|%t) ")
00139                         ACE_TEXT ("unable to add acceptor to registry")
00140                         ACE_TEXT ("for <%s>%p\n"),
00141                         buffer,
00142                         ""));
00143 
00144           throw CORBA::BAD_PARAM (
00145             CORBA::SystemException::_tao_minor_code (
00146               TAO_ACCEPTOR_REGISTRY_OPEN_LOCATION_CODE,
00147               EINVAL),
00148             CORBA::COMPLETED_NO);
00149         }
00150     }
00151   else
00152     {
00153       if (TAO_debug_level > 0)
00154         ACE_ERROR ((LM_ERROR,
00155                     ACE_TEXT ("TAO (%P|%t) ")
00156                     ACE_TEXT ("unable to create acceptor ")
00157                     ));
00158 
00159       throw CORBA::BAD_PARAM (
00160         CORBA::SystemException::_tao_minor_code (
00161           TAO_ACCEPTOR_REGISTRY_OPEN_LOCATION_CODE,
00162           EINVAL),
00163         CORBA::COMPLETED_NO);
00164     }
00165 }
00166 
00167 int
00168 TAO_PortableGroup_Acceptor_Registry::find (const TAO_Profile* profile,
00169                                            Entry *&entry)
00170 {
00171   Acceptor_Registry_Iterator iter (this->registry_);
00172 
00173   while (iter.next (entry))
00174     {
00175       // Since the endpoint routine is nonconst, need to
00176       // cast away the constness even though we're not
00177       // changing anything.
00178       TAO_Profile *nc_profile = const_cast<TAO_Profile *> (profile);
00179       if (entry->endpoint->is_equivalent (nc_profile->endpoint ()))
00180         return 1;
00181 
00182       iter.advance ();
00183    }
00184 
00185    return 0;
00186 }
00187 
00188 TAO_END_VERSIONED_NAMESPACE_DECL

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