1 #include "tao/RTCORBA/RT_Stub.h"
3 #if defined (TAO_HAS_CORBA_MESSAGING) && TAO_HAS_CORBA_MESSAGING != 0
5 #include "tao/RTCORBA/RT_Policy_i.h"
6 #include "tao/ORB_Core.h"
7 #include "tao/Policy_Set.h"
8 #include "tao/Policy_Manager.h"
9 #include "tao/SystemException.h"
11 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
13 TAO_RT_Stub::TAO_RT_Stub (const char *repository_id
,
14 const TAO_MProfile
&profiles
,
15 TAO_ORB_Core
*orb_core
)
16 : TAO_Stub (repository_id
,
19 priority_model_policy_ (0),
20 priority_banded_connection_policy_ (0),
21 client_protocol_policy_ (0),
22 are_policies_parsed_ (false)
26 TAO_RT_Stub::~TAO_RT_Stub ()
28 if (this->priority_model_policy_
.in ())
29 this->priority_model_policy_
->destroy ();
31 if (this->priority_banded_connection_policy_
.in ())
32 this->priority_banded_connection_policy_
->destroy ();
34 if (this->client_protocol_policy_
.in ())
35 this->client_protocol_policy_
->destroy ();
39 TAO_RT_Stub::parse_policies ()
41 CORBA::PolicyList_var policy_list
42 = this->base_profiles_
.policy_list ();
44 CORBA::ULong
const length
= policy_list
->length ();
46 // Cache away the policies that we'll need later.
47 for (CORBA::ULong i
= 0; i
< length
; ++i
)
49 switch (policy_list
[i
]->policy_type ())
51 case RTCORBA::PRIORITY_MODEL_POLICY_TYPE
:
53 this->exposed_priority_model (policy_list
[i
]);
56 case RTCORBA::PRIORITY_BANDED_CONNECTION_POLICY_TYPE
:
58 this->exposed_priority_banded_connection (policy_list
[i
]);
61 case RTCORBA::CLIENT_PROTOCOL_POLICY_TYPE
:
63 this->exposed_client_protocol (policy_list
[i
]);
69 this->are_policies_parsed_
= true;
73 TAO_RT_Stub::exposed_priority_model ()
75 if (!this->are_policies_parsed_
)
77 this->parse_policies ();
80 return CORBA::Policy::_duplicate (this->priority_model_policy_
.in ());
84 TAO_RT_Stub::exposed_priority_model (CORBA::Policy_ptr policy
)
86 this->priority_model_policy_
= CORBA::Policy::_duplicate (policy
);
90 TAO_RT_Stub::exposed_priority_banded_connection ()
92 if (!this->are_policies_parsed_
)
94 this->parse_policies ();
97 return CORBA::Policy::_duplicate (this->priority_banded_connection_policy_
.in ());
101 TAO_RT_Stub::exposed_priority_banded_connection (CORBA::Policy_ptr policy
)
103 this->priority_banded_connection_policy_
= CORBA::Policy::_duplicate (policy
);
107 TAO_RT_Stub::exposed_client_protocol ()
109 if (!this->are_policies_parsed_
)
111 this->parse_policies ();
114 return CORBA::Policy::_duplicate (this->client_protocol_policy_
.in ());
118 TAO_RT_Stub::exposed_client_protocol (CORBA::Policy_ptr policy
)
120 this->client_protocol_policy_
= CORBA::Policy::_duplicate (policy
);
124 TAO_RT_Stub::get_policy (CORBA::PolicyType type
)
126 // If we are dealing with a client exposed policy, check if any
127 // value came in the IOR/reconcile IOR value and overrides.
130 case RTCORBA::PRIORITY_MODEL_POLICY_TYPE
:
132 return this->exposed_priority_model ();
134 case RTCORBA::PRIORITY_BANDED_CONNECTION_POLICY_TYPE
:
136 return this->effective_priority_banded_connection ();
138 case RTCORBA::CLIENT_PROTOCOL_POLICY_TYPE
:
140 return this->effective_client_protocol ();
144 return this->TAO_Stub::get_policy (type
);
148 TAO_RT_Stub::get_cached_policy (TAO_Cached_Policy_Type type
)
150 // If we are dealing with a client exposed policy, check if any
151 // value came in the IOR/reconcile IOR value and overrides.
154 case TAO_CACHED_POLICY_PRIORITY_MODEL
:
156 return this->exposed_priority_model ();
158 case TAO_CACHED_POLICY_RT_PRIORITY_BANDED_CONNECTION
:
160 return this->effective_priority_banded_connection ();
162 case TAO_CACHED_POLICY_RT_CLIENT_PROTOCOL
:
164 return this->effective_client_protocol ();
170 return this->TAO_Stub::get_cached_policy (type
);
175 TAO_RT_Stub::set_policy_overrides (const CORBA::PolicyList
& policies
,
176 CORBA::SetOverrideType set_add
)
178 // Validity check. Make sure requested policies are allowed to be
179 // set at this scope.
180 for (CORBA::ULong i
= 0; i
< policies
.length (); ++i
)
182 CORBA::Policy_ptr policy
= policies
[i
];
183 if (!CORBA::is_nil (policy
))
185 CORBA::PolicyType
const type
= policy
->policy_type ();
187 if (type
== RTCORBA::PRIORITY_MODEL_POLICY_TYPE
||
188 type
== RTCORBA::THREADPOOL_POLICY_TYPE
||
189 type
== RTCORBA::SERVER_PROTOCOL_POLICY_TYPE
)
190 throw ::CORBA::NO_PERMISSION ();
194 // We are not required to check for consistency of <policies> with
195 // overrides at other levels or with policies exported in the IOR.
196 return this->TAO_Stub::set_policy_overrides(policies
, set_add
);
200 TAO_RT_Stub::effective_priority_banded_connection ()
202 // Get effective override.
203 CORBA::Policy_var override
=
204 this->TAO_Stub::get_cached_policy (
205 TAO_CACHED_POLICY_RT_PRIORITY_BANDED_CONNECTION
);
207 // Get the value from the ior.
208 CORBA::Policy_var exposed
= this->exposed_priority_banded_connection ();
210 // Reconcile client-exposed and locally set values.
211 if (CORBA::is_nil (exposed
.in ()))
212 return override
._retn ();
214 if (CORBA::is_nil (override
.in ()))
215 return exposed
._retn ();
217 RTCORBA::PriorityBandedConnectionPolicy_var override_policy_var
=
218 RTCORBA::PriorityBandedConnectionPolicy::_narrow (override
.in ());
220 TAO_PriorityBandedConnectionPolicy
*override_policy
=
221 dynamic_cast<TAO_PriorityBandedConnectionPolicy
*> (override_policy_var
.in ());
223 RTCORBA::PriorityBandedConnectionPolicy_var exposed_policy_var
=
224 RTCORBA::PriorityBandedConnectionPolicy::_narrow (exposed
.in ());
226 TAO_PriorityBandedConnectionPolicy
*exposed_policy
=
227 dynamic_cast<TAO_PriorityBandedConnectionPolicy
*> (exposed_policy_var
.in ());
229 if (!override_policy
|| !exposed_policy
)
231 throw ::CORBA::INV_POLICY ();
234 // Both override and exposed have been set.
235 // See if either of them has empty priority bands.
236 if (exposed_policy
->priority_bands_rep ().length () == 0)
237 return override
._retn ();
239 if (override_policy
->priority_bands_rep ().length () == 0)
240 return exposed
._retn ();
242 // Both override and exposed have been set and neither has empty
243 // priority bands. This is illegal (ptc/99-05-03, sec. 4.12.1).
244 throw ::CORBA::INV_POLICY ();
248 TAO_RT_Stub::effective_client_protocol ()
250 // Get effective override.
251 CORBA::Policy_var override
=
252 this->TAO_Stub::get_cached_policy (TAO_CACHED_POLICY_RT_CLIENT_PROTOCOL
);
254 // Get the value from the ior.
255 CORBA::Policy_var exposed
=
256 this->exposed_client_protocol ();
258 // Reconcile client-exposed and locally set values.
259 if (CORBA::is_nil (exposed
.in ()))
260 return override
._retn ();
262 if (CORBA::is_nil (override
.in ()))
263 return exposed
._retn ();
265 RTCORBA::ClientProtocolPolicy_var override_policy_var
=
266 RTCORBA::ClientProtocolPolicy::_narrow (override
.in ());
268 TAO_ClientProtocolPolicy
*override_policy
=
269 dynamic_cast<TAO_ClientProtocolPolicy
*> (override_policy_var
.in ());
271 RTCORBA::ClientProtocolPolicy_var exposed_policy_var
=
272 RTCORBA::ClientProtocolPolicy::_narrow (exposed
.in ());
274 TAO_ClientProtocolPolicy
*exposed_policy
=
275 dynamic_cast<TAO_ClientProtocolPolicy
*> (exposed_policy_var
.in ());
277 if (!override_policy
|| !exposed_policy
)
279 throw ::CORBA::INV_POLICY ();
282 // Both override and exposed have been set.
283 // See if either of them has empty priority bands.
284 RTCORBA::ProtocolList
&protocols_rep_var
=
285 exposed_policy
->protocols_rep ();
287 if (protocols_rep_var
.length () == 0)
288 return override
._retn ();
290 if (override_policy
->protocols_rep ().length () == 0)
291 return exposed
._retn ();
293 // Both override and exposed have been set and neither has empty
294 // protocols. This is illegal (ptc/99-05-03, sec. 4.15.4).
295 throw ::CORBA::INV_POLICY ();
298 TAO_END_VERSIONED_NAMESPACE_DECL
300 #endif /* TAO_HAS_CORBA_MESSAGING && TAO_HAS_CORBA_MESSAGING != 0 */