2 #include "tao/EndpointPolicy/EndpointPolicy_Factory.h"
4 #include "tao/EndpointPolicy/EndpointPolicy_i.h"
5 #include "tao/EndpointPolicy/EndpointPolicyA.h"
6 #include "tao/EndpointPolicy/Endpoint_Value_Impl.h"
8 #include "tao/PolicyC.h"
9 #include "tao/ORB_Constants.h"
10 #include "tao/ORB_Core.h"
11 #include "tao/Acceptor_Registry.h"
12 #include "tao/AnyTypeCode/TAOA.h"
13 #include "tao/AnyTypeCode/Any.h"
14 #include "tao/Thread_Lane_Resources.h"
15 #include "tao/Transport_Acceptor.h"
17 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
19 TAO_EndpointPolicy_Factory::TAO_EndpointPolicy_Factory (TAO_ORB_Core
* orb_core
)
20 : orb_core_ (orb_core
)
26 TAO_EndpointPolicy_Factory::create_policy (
27 CORBA::PolicyType type
,
28 const CORBA::Any
&value
)
30 if (type
== EndpointPolicy::ENDPOINT_POLICY_TYPE
)
32 const EndpointPolicy::EndpointList
* endpoint_list
= 0;
33 if (!(value
>>= endpoint_list
))
34 throw ::CORBA::PolicyError (CORBA::BAD_POLICY_VALUE
);
36 TAO_Acceptor_Registry
& registry
=
37 this->orb_core_
->lane_resources ().acceptor_registry ();
39 TAO_Acceptor
** const acceptors_begin
= registry
.begin ();
40 TAO_Acceptor
** const acceptors_end
= registry
.end ();
41 CORBA::ULong
const num_eps
= endpoint_list
->length ();
43 // need to count the protocol types offered by the acceptors
44 // partially defaulted endpoint values are only acceptable if
45 // there are more than one protocol available to the ORB.
47 CORBA::ULong last_known_prot
= 0xFFFFFFFF; // tag = 0 is IIOP
49 for (TAO_Acceptor
** acceptor
= acceptors_begin
;
50 acceptor
!= acceptors_end
;
53 if ((*acceptor
)->tag () != last_known_prot
)
55 last_known_prot
= (*acceptor
)->tag ();
61 // The endpoint list in the value is validated to ensure that
62 // at least one endpoint in the list matches an endpoint the
63 // ORB is listening on.
65 bool found_one
= false;
66 for (CORBA::ULong idx
= 0; !found_one
&& idx
< num_eps
; ++idx
)
68 CORBA::ULong prot_tag
= (*endpoint_list
)[idx
]->protocol_tag();
70 TAO_Endpoint_Value_Impl
const * const evi
=
71 dynamic_cast <TAO_Endpoint_Value_Impl
const *> (
72 (*endpoint_list
)[idx
].in ());
77 for (TAO_Acceptor
** acceptor
= acceptors_begin
;
78 !found_one
&& acceptor
!= acceptors_end
;
81 if ((*acceptor
)->tag () == prot_tag
)
82 found_one
= evi
->validate_acceptor (*acceptor
, prot_count
> 1);
86 // There is no endpoint policy value matches an endpoint the ORB
87 // is listening on. A CORBA::PolicyError exception with a
88 // PolicyErrorCode of UNSUPPORTED_POLICY_VALUE is raised.
90 throw ::CORBA::PolicyError (CORBA::UNSUPPORTED_POLICY_VALUE
);
92 TAO_EndpointPolicy_i
*tmp
= 0;
93 ACE_NEW_THROW_EX (tmp
,
94 TAO_EndpointPolicy_i (*endpoint_list
),
95 CORBA::NO_MEMORY (TAO::VMCID
,
96 CORBA::COMPLETED_NO
));
101 throw ::CORBA::PolicyError (CORBA::BAD_POLICY_TYPE
);
105 TAO_END_VERSIONED_NAMESPACE_DECL