00001 // @(#) $Id: EndpointPolicy_Factory.cpp 84718 2009-03-05 10:23:08Z johnnyw $ 00002 #include "tao/EndpointPolicy/EndpointPolicy_Factory.h" 00003 00004 ACE_RCSID (EndpointPolicy, 00005 EndpointPolicy_Factory, 00006 "$Id: EndpointPolicy_Factory.cpp 84718 2009-03-05 10:23:08Z johnnyw $") 00007 00008 #include "tao/EndpointPolicy/EndpointPolicy_i.h" 00009 #include "tao/EndpointPolicy/EndpointPolicyA.h" 00010 #include "tao/EndpointPolicy/Endpoint_Value_Impl.h" 00011 00012 #include "tao/PolicyC.h" 00013 #include "tao/ORB_Constants.h" 00014 #include "tao/ORB_Core.h" 00015 #include "tao/Acceptor_Registry.h" 00016 #include "tao/AnyTypeCode/TAOA.h" 00017 #include "tao/AnyTypeCode/Any.h" 00018 #include "tao/Thread_Lane_Resources.h" 00019 #include "tao/Transport_Acceptor.h" 00020 00021 TAO_BEGIN_VERSIONED_NAMESPACE_DECL 00022 00023 00024 TAO_EndpointPolicy_Factory::TAO_EndpointPolicy_Factory (TAO_ORB_Core * orb_core) 00025 : orb_core_ (orb_core) 00026 { 00027 } 00028 00029 00030 CORBA::Policy_ptr 00031 TAO_EndpointPolicy_Factory::create_policy ( 00032 CORBA::PolicyType type, 00033 const CORBA::Any &value) 00034 { 00035 if (type == EndpointPolicy::ENDPOINT_POLICY_TYPE) 00036 { 00037 const EndpointPolicy::EndpointList* endpoint_list = 0; 00038 if (!(value >>= endpoint_list)) 00039 throw ::CORBA::PolicyError (CORBA::BAD_POLICY_VALUE); 00040 00041 TAO_Acceptor_Registry & registry = 00042 this->orb_core_->lane_resources ().acceptor_registry (); 00043 00044 TAO_Acceptor ** const acceptors_begin = registry.begin (); 00045 TAO_Acceptor ** const acceptors_end = registry.end (); 00046 CORBA::ULong const num_eps = endpoint_list->length (); 00047 00048 // need to count the protocol types offered by the acceptors 00049 // partially defaulted endpoint values are only acceptable if 00050 // there are more than one protocol available to the ORB. 00051 00052 CORBA::ULong last_known_prot = 0xFFFFFFFF; // tag = 0 is IIOP 00053 int prot_count = 0; 00054 for (TAO_Acceptor** acceptor = acceptors_begin; 00055 acceptor != acceptors_end; 00056 ++acceptor) 00057 { 00058 if ((*acceptor)->tag () != last_known_prot) 00059 { 00060 last_known_prot = (*acceptor)->tag (); 00061 ++prot_count; 00062 } 00063 } 00064 00065 00066 // The endpoint list in the value is validated to ensure that 00067 // at least one endpoint in the list matches an endpoint the 00068 // ORB is listening on. 00069 00070 bool found_one = false; 00071 for (CORBA::ULong idx = 0; !found_one && idx < num_eps; ++idx) 00072 { 00073 CORBA::ULong prot_tag = (*endpoint_list)[idx]->protocol_tag(); 00074 00075 TAO_Endpoint_Value_Impl const * const evi = 00076 dynamic_cast <TAO_Endpoint_Value_Impl const *> ( 00077 (*endpoint_list)[idx].in ()); 00078 00079 if (!evi) 00080 continue; 00081 00082 for (TAO_Acceptor** acceptor = acceptors_begin; 00083 !found_one && acceptor != acceptors_end; 00084 ++acceptor) 00085 { 00086 if ((*acceptor)->tag () == prot_tag) 00087 found_one = evi->validate_acceptor (*acceptor, prot_count > 1); 00088 } 00089 } 00090 00091 // There is no endpoint policy value matches an endpoint the ORB 00092 // is listening on. A CORBA::PolicyError exception with a 00093 // PolicyErrorCode of UNSUPPORTED_POLICY_VALUE is raised. 00094 if (!found_one) 00095 throw ::CORBA::PolicyError (CORBA::UNSUPPORTED_POLICY_VALUE); 00096 00097 TAO_EndpointPolicy_i *tmp = 0; 00098 ACE_NEW_THROW_EX (tmp, 00099 TAO_EndpointPolicy_i (*endpoint_list), 00100 CORBA::NO_MEMORY (TAO::VMCID, 00101 CORBA::COMPLETED_NO)); 00102 00103 return tmp; 00104 } 00105 else 00106 throw ::CORBA::PolicyError (CORBA::BAD_POLICY_TYPE); 00107 } 00108 00109 00110 TAO_END_VERSIONED_NAMESPACE_DECL