Go to the documentation of this file.00001
00002
00003 #include "tao/RTCORBA/RT_Stub.h"
00004
00005 #if defined (TAO_HAS_CORBA_MESSAGING) && TAO_HAS_CORBA_MESSAGING != 0
00006
00007 #include "tao/RTCORBA/RT_Policy_i.h"
00008 #include "tao/ORB_Core.h"
00009 #include "tao/Policy_Set.h"
00010 #include "tao/Policy_Manager.h"
00011 #include "tao/SystemException.h"
00012
00013 ACE_RCSID (RTCORBA,
00014 RT_Stub,
00015 "$Id: RT_Stub.cpp 82394 2008-07-23 12:52:46Z johnnyw $")
00016
00017
00018 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00019
00020 TAO_RT_Stub::TAO_RT_Stub (const char *repository_id,
00021 const TAO_MProfile &profiles,
00022 TAO_ORB_Core *orb_core)
00023 : TAO_Stub (repository_id,
00024 profiles,
00025 orb_core),
00026 priority_model_policy_ (0),
00027 priority_banded_connection_policy_ (0),
00028 client_protocol_policy_ (0),
00029 are_policies_parsed_ (false)
00030 {
00031 }
00032
00033 TAO_RT_Stub::~TAO_RT_Stub (void)
00034 {
00035 if (this->priority_model_policy_.in ())
00036 this->priority_model_policy_->destroy ();
00037
00038 if (this->priority_banded_connection_policy_.in ())
00039 this->priority_banded_connection_policy_->destroy ();
00040
00041 if (this->client_protocol_policy_.in ())
00042 this->client_protocol_policy_->destroy ();
00043 }
00044
00045 void
00046 TAO_RT_Stub::parse_policies (void)
00047 {
00048 CORBA::PolicyList_var policy_list
00049 = this->base_profiles_.policy_list ();
00050
00051 CORBA::ULong const length = policy_list->length ();
00052
00053
00054 for (CORBA::ULong i = 0; i < length; ++i)
00055 {
00056 switch (policy_list[i]->policy_type ())
00057 {
00058 case RTCORBA::PRIORITY_MODEL_POLICY_TYPE:
00059 {
00060 this->exposed_priority_model (policy_list[i]); }
00061 break;
00062 case RTCORBA::PRIORITY_BANDED_CONNECTION_POLICY_TYPE :
00063 {
00064 this->exposed_priority_banded_connection (policy_list[i]);
00065 }
00066 break;
00067 case RTCORBA::CLIENT_PROTOCOL_POLICY_TYPE :
00068 {
00069 this->exposed_client_protocol (policy_list[i]);
00070 }
00071 break;
00072 }
00073 }
00074
00075 this->are_policies_parsed_ = true;
00076 }
00077
00078 CORBA::Policy *
00079 TAO_RT_Stub::exposed_priority_model (void)
00080 {
00081 if (!this->are_policies_parsed_)
00082 {
00083 this->parse_policies ();
00084 }
00085
00086 return CORBA::Policy::_duplicate (this->priority_model_policy_.in ());
00087 }
00088
00089 void
00090 TAO_RT_Stub::exposed_priority_model (CORBA::Policy_ptr policy)
00091 {
00092 this->priority_model_policy_ = CORBA::Policy::_duplicate (policy);
00093 }
00094
00095 CORBA::Policy *
00096 TAO_RT_Stub::exposed_priority_banded_connection (void)
00097 {
00098 if (!this->are_policies_parsed_)
00099 {
00100 this->parse_policies ();
00101 }
00102
00103 return CORBA::Policy::_duplicate (this->priority_banded_connection_policy_.in ());
00104 }
00105
00106 void
00107 TAO_RT_Stub::exposed_priority_banded_connection (CORBA::Policy_ptr policy)
00108 {
00109 this->priority_banded_connection_policy_ = CORBA::Policy::_duplicate (policy);
00110 }
00111
00112 CORBA::Policy *
00113 TAO_RT_Stub::exposed_client_protocol (void)
00114 {
00115 if (!this->are_policies_parsed_)
00116 {
00117 this->parse_policies ();
00118 }
00119
00120 return CORBA::Policy::_duplicate (this->client_protocol_policy_.in ());
00121 }
00122
00123 void
00124 TAO_RT_Stub::exposed_client_protocol (CORBA::Policy_ptr policy)
00125 {
00126 this->client_protocol_policy_ = CORBA::Policy::_duplicate (policy);
00127 }
00128
00129 CORBA::Policy_ptr
00130 TAO_RT_Stub::get_policy (CORBA::PolicyType type)
00131 {
00132
00133
00134 switch (type)
00135 {
00136 case RTCORBA::PRIORITY_MODEL_POLICY_TYPE:
00137 {
00138 return this->exposed_priority_model ();
00139 }
00140 case RTCORBA::PRIORITY_BANDED_CONNECTION_POLICY_TYPE :
00141 {
00142 return this->effective_priority_banded_connection ();
00143 }
00144 case RTCORBA::CLIENT_PROTOCOL_POLICY_TYPE :
00145 {
00146 return this->effective_client_protocol ();
00147 }
00148 }
00149
00150 return this->TAO_Stub::get_policy (type);
00151 }
00152
00153 CORBA::Policy_ptr
00154 TAO_RT_Stub::get_cached_policy (TAO_Cached_Policy_Type type)
00155 {
00156
00157
00158 switch (type)
00159 {
00160 case TAO_CACHED_POLICY_PRIORITY_MODEL:
00161 {
00162 return this->exposed_priority_model ();
00163 }
00164 case TAO_CACHED_POLICY_RT_PRIORITY_BANDED_CONNECTION :
00165 {
00166 return this->effective_priority_banded_connection ();
00167 }
00168 case TAO_CACHED_POLICY_RT_CLIENT_PROTOCOL :
00169 {
00170 return this->effective_client_protocol ();
00171 }
00172 default:
00173 break;
00174 }
00175
00176 return this->TAO_Stub::get_cached_policy (type);
00177 }
00178
00179
00180 TAO_Stub *
00181 TAO_RT_Stub::set_policy_overrides (const CORBA::PolicyList & policies,
00182 CORBA::SetOverrideType set_add)
00183 {
00184
00185
00186 for (CORBA::ULong i = 0; i < policies.length (); ++i)
00187 {
00188 CORBA::Policy_ptr policy = policies[i];
00189 if (!CORBA::is_nil (policy))
00190 {
00191 CORBA::PolicyType const type = policy->policy_type ();
00192
00193 if (type == RTCORBA::PRIORITY_MODEL_POLICY_TYPE ||
00194 type == RTCORBA::THREADPOOL_POLICY_TYPE ||
00195 type == RTCORBA::SERVER_PROTOCOL_POLICY_TYPE)
00196 throw ::CORBA::NO_PERMISSION ();
00197 }
00198 }
00199
00200
00201
00202 return this->TAO_Stub::set_policy_overrides(policies, set_add);
00203 }
00204
00205 CORBA::Policy_ptr
00206 TAO_RT_Stub::effective_priority_banded_connection (void)
00207 {
00208
00209 CORBA::Policy_var override =
00210 this->TAO_Stub::get_cached_policy (
00211 TAO_CACHED_POLICY_RT_PRIORITY_BANDED_CONNECTION);
00212
00213
00214 CORBA::Policy_var exposed = this->exposed_priority_banded_connection ();
00215
00216
00217 if (CORBA::is_nil (exposed.in ()))
00218 return override._retn ();
00219
00220 if (CORBA::is_nil (override.in ()))
00221 return exposed._retn ();
00222
00223 RTCORBA::PriorityBandedConnectionPolicy_var override_policy_var =
00224 RTCORBA::PriorityBandedConnectionPolicy::_narrow (override.in ());
00225
00226 TAO_PriorityBandedConnectionPolicy *override_policy =
00227 dynamic_cast<TAO_PriorityBandedConnectionPolicy *> (override_policy_var.in ());
00228
00229 RTCORBA::PriorityBandedConnectionPolicy_var exposed_policy_var =
00230 RTCORBA::PriorityBandedConnectionPolicy::_narrow (exposed.in ());
00231
00232 TAO_PriorityBandedConnectionPolicy *exposed_policy =
00233 dynamic_cast<TAO_PriorityBandedConnectionPolicy *> (exposed_policy_var.in ());
00234
00235 if (!override_policy || !exposed_policy)
00236 {
00237 throw ::CORBA::INV_POLICY ();
00238 }
00239
00240
00241
00242 if (exposed_policy->priority_bands_rep ().length () == 0)
00243 return override._retn ();
00244
00245 if (override_policy->priority_bands_rep ().length () == 0)
00246 return exposed._retn ();
00247
00248
00249
00250 throw ::CORBA::INV_POLICY ();
00251 }
00252
00253 CORBA::Policy_ptr
00254 TAO_RT_Stub::effective_client_protocol (void)
00255 {
00256
00257 CORBA::Policy_var override =
00258 this->TAO_Stub::get_cached_policy (TAO_CACHED_POLICY_RT_CLIENT_PROTOCOL);
00259
00260
00261 CORBA::Policy_var exposed =
00262 this->exposed_client_protocol ();
00263
00264
00265 if (CORBA::is_nil (exposed.in ()))
00266 return override._retn ();
00267
00268 if (CORBA::is_nil (override.in ()))
00269 return exposed._retn ();
00270
00271 RTCORBA::ClientProtocolPolicy_var override_policy_var =
00272 RTCORBA::ClientProtocolPolicy::_narrow (override.in ());
00273
00274 TAO_ClientProtocolPolicy *override_policy =
00275 dynamic_cast<TAO_ClientProtocolPolicy *> (override_policy_var.in ());
00276
00277 RTCORBA::ClientProtocolPolicy_var exposed_policy_var =
00278 RTCORBA::ClientProtocolPolicy::_narrow (exposed.in ());
00279
00280 TAO_ClientProtocolPolicy *exposed_policy =
00281 dynamic_cast<TAO_ClientProtocolPolicy *> (exposed_policy_var.in ());
00282
00283 if (!override_policy || !exposed_policy)
00284 {
00285 throw ::CORBA::INV_POLICY ();
00286 }
00287
00288
00289
00290 RTCORBA::ProtocolList &protocols_rep_var =
00291 exposed_policy->protocols_rep ();
00292
00293 if (protocols_rep_var.length () == 0)
00294 return override._retn ();
00295
00296 if (override_policy->protocols_rep ().length () == 0)
00297 return exposed._retn ();
00298
00299
00300
00301 throw ::CORBA::INV_POLICY ();
00302 }
00303
00304 TAO_END_VERSIONED_NAMESPACE_DECL
00305
00306 #endif