00001
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
00013 ACE_RCSID (PortableGroup,
00014 PortableGroup_Acceptor_Registry,
00015 "PortableGroup_Acceptor_Registry.cpp,v 1.13 2006/03/14 06:14:34 jtc Exp")
00016
00017 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00018
00019 TAO_PortableGroup_Acceptor_Registry::TAO_PortableGroup_Acceptor_Registry (void)
00020 {
00021 }
00022
00023 TAO_PortableGroup_Acceptor_Registry::~TAO_PortableGroup_Acceptor_Registry (void)
00024 {
00025
00026 Entry *entry;
00027 Acceptor_Registry_Iterator iter (this->registry_);
00028
00029 while (iter.next (entry))
00030 {
00031 delete entry->endpoint;
00032 delete entry->acceptor;
00033 iter.advance ();
00034 }
00035 }
00036
00037
00038 void
00039 TAO_PortableGroup_Acceptor_Registry::open (const TAO_Profile* profile,
00040 TAO_ORB_Core &orb_core
00041 ACE_ENV_ARG_DECL)
00042 {
00043 Entry *entry;
00044
00045 if (this->find (profile, entry) == 1)
00046 {
00047
00048 ++entry->cnt;
00049 }
00050 else
00051 {
00052
00053
00054
00055 TAO_ProtocolFactorySetItor end =
00056 orb_core.protocol_factories ()->end ();
00057
00058
00059
00060
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 ACE_ENV_ARG_PARAMETER);
00073 ACE_CHECK;
00074
00075
00076 }
00077 else
00078 continue;
00079 }
00080 }
00081 }
00082
00083 #define MAX_ADDR_LENGTH (32)
00084
00085 void
00086 TAO_PortableGroup_Acceptor_Registry::open_i (const TAO_Profile* profile,
00087 TAO_ORB_Core &orb_core,
00088 TAO_ProtocolFactorySetItor &factory
00089 ACE_ENV_ARG_DECL)
00090 {
00091 TAO_Acceptor *acceptor = (*factory)->factory ()->make_acceptor ();
00092
00093 if (acceptor != 0)
00094 {
00095
00096
00097 const TAO_GIOP_Message_Version &version = profile->version ();
00098 char buffer [MAX_ADDR_LENGTH];
00099
00100
00101
00102 TAO_Profile* nc_profile = const_cast<TAO_Profile *> (profile);
00103 nc_profile->endpoint ()->addr_to_string (buffer, MAX_ADDR_LENGTH);
00104
00105 if (acceptor->open (&orb_core,
00106 orb_core.lane_resources ().leader_follower ().reactor(),
00107 version.major,
00108 version.minor,
00109 buffer,
00110 0) == -1)
00111 {
00112 delete acceptor;
00113
00114 if (TAO_debug_level > 0)
00115 ACE_ERROR ((LM_ERROR,
00116 ACE_TEXT ("TAO (%P|%t) ")
00117 ACE_TEXT ("unable to open acceptor ")
00118 ACE_TEXT ("for <%s>%p\n"),
00119 buffer,
00120 ""));
00121
00122 ACE_THROW (CORBA::BAD_PARAM (
00123 CORBA::SystemException::_tao_minor_code (
00124 TAO_ACCEPTOR_REGISTRY_OPEN_LOCATION_CODE,
00125 EINVAL),
00126 CORBA::COMPLETED_NO));
00127 }
00128
00129
00130 Entry tmp_entry;
00131 tmp_entry.acceptor = acceptor;
00132 tmp_entry.endpoint = nc_profile->endpoint ()->duplicate ();
00133 tmp_entry.cnt = 1;
00134
00135 if (this->registry_.enqueue_tail (tmp_entry) == -1)
00136 {
00137 delete acceptor;
00138
00139 if (TAO_debug_level > 0)
00140 ACE_ERROR ((LM_ERROR,
00141 ACE_TEXT ("TAO (%P|%t) ")
00142 ACE_TEXT ("unable to add acceptor to registry")
00143 ACE_TEXT ("for <%s>%p\n"),
00144 buffer,
00145 ""));
00146
00147 ACE_THROW (CORBA::BAD_PARAM (
00148 CORBA::SystemException::_tao_minor_code (
00149 TAO_ACCEPTOR_REGISTRY_OPEN_LOCATION_CODE,
00150 EINVAL),
00151 CORBA::COMPLETED_NO));
00152 }
00153 }
00154 else
00155 {
00156 if (TAO_debug_level > 0)
00157 ACE_ERROR ((LM_ERROR,
00158 ACE_TEXT ("TAO (%P|%t) ")
00159 ACE_TEXT ("unable to create acceptor ")
00160 ));
00161
00162 ACE_THROW (CORBA::BAD_PARAM (
00163 CORBA::SystemException::_tao_minor_code (
00164 TAO_ACCEPTOR_REGISTRY_OPEN_LOCATION_CODE,
00165 EINVAL),
00166 CORBA::COMPLETED_NO));
00167 }
00168 }
00169
00170 int
00171 TAO_PortableGroup_Acceptor_Registry::find (const TAO_Profile* profile,
00172 Entry *&entry)
00173 {
00174 Acceptor_Registry_Iterator iter (this->registry_);
00175
00176 while (iter.next (entry))
00177 {
00178
00179
00180
00181 TAO_Profile *nc_profile = const_cast<TAO_Profile *> (profile);
00182 if (entry->endpoint->is_equivalent (nc_profile->endpoint ()))
00183 return 1;
00184
00185 iter.advance ();
00186 }
00187
00188 return 0;
00189 }
00190
00191 TAO_END_VERSIONED_NAMESPACE_DECL