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 76995 2007-02-11 12:51:42Z 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 if (policy_list[i]->policy_type () ==
00057 RTCORBA::PRIORITY_MODEL_POLICY_TYPE)
00058 this->exposed_priority_model (policy_list[i]);
00059
00060 else if (policy_list[i]->policy_type () ==
00061 RTCORBA::PRIORITY_BANDED_CONNECTION_POLICY_TYPE)
00062 this->exposed_priority_banded_connection (policy_list[i]);
00063
00064 else if (policy_list[i]->policy_type () ==
00065 RTCORBA::CLIENT_PROTOCOL_POLICY_TYPE)
00066 this->exposed_client_protocol (policy_list[i]);
00067 }
00068
00069 this->are_policies_parsed_ = true;
00070 }
00071
00072 CORBA::Policy *
00073 TAO_RT_Stub::exposed_priority_model (void)
00074 {
00075 if (!this->are_policies_parsed_)
00076 {
00077 this->parse_policies ();
00078 }
00079
00080 return CORBA::Policy::_duplicate (this->priority_model_policy_.in ());
00081 }
00082
00083 void
00084 TAO_RT_Stub::exposed_priority_model (CORBA::Policy_ptr policy)
00085 {
00086 this->priority_model_policy_ = CORBA::Policy::_duplicate (policy);
00087 }
00088
00089 CORBA::Policy *
00090 TAO_RT_Stub::exposed_priority_banded_connection (void)
00091 {
00092 if (!this->are_policies_parsed_)
00093 {
00094 this->parse_policies ();
00095 }
00096
00097 return CORBA::Policy::_duplicate (this->priority_banded_connection_policy_.in ());
00098 }
00099
00100 void
00101 TAO_RT_Stub::exposed_priority_banded_connection (CORBA::Policy_ptr policy)
00102 {
00103 this->priority_banded_connection_policy_ = CORBA::Policy::_duplicate (policy);
00104 }
00105
00106 CORBA::Policy *
00107 TAO_RT_Stub::exposed_client_protocol (void)
00108 {
00109 if (!this->are_policies_parsed_)
00110 {
00111 this->parse_policies ();
00112 }
00113
00114 return CORBA::Policy::_duplicate (this->client_protocol_policy_.in ());
00115 }
00116
00117 void
00118 TAO_RT_Stub::exposed_client_protocol (CORBA::Policy_ptr policy)
00119 {
00120 this->client_protocol_policy_ = CORBA::Policy::_duplicate (policy);
00121 }
00122
00123 #if (TAO_HAS_CORBA_MESSAGING == 1)
00124
00125 CORBA::Policy_ptr
00126 TAO_RT_Stub::get_policy (CORBA::PolicyType type)
00127 {
00128
00129
00130 if (type == RTCORBA::PRIORITY_MODEL_POLICY_TYPE)
00131 return this->exposed_priority_model ();
00132
00133 if (type == RTCORBA::PRIORITY_BANDED_CONNECTION_POLICY_TYPE)
00134 return this->effective_priority_banded_connection ();
00135
00136 if (type == RTCORBA::CLIENT_PROTOCOL_POLICY_TYPE)
00137 return this->effective_client_protocol ();
00138
00139 return this->TAO_Stub::get_policy (type);
00140 }
00141
00142 CORBA::Policy_ptr
00143 TAO_RT_Stub::get_cached_policy (TAO_Cached_Policy_Type type)
00144 {
00145
00146
00147 if (type == TAO_CACHED_POLICY_PRIORITY_MODEL)
00148 return this->exposed_priority_model ();
00149
00150 if (type == TAO_CACHED_POLICY_RT_PRIORITY_BANDED_CONNECTION)
00151 return this->effective_priority_banded_connection ();
00152
00153 if (type == TAO_CACHED_POLICY_RT_CLIENT_PROTOCOL)
00154 return this->effective_client_protocol ();
00155
00156 return this->TAO_Stub::get_cached_policy (type);
00157 }
00158
00159
00160 TAO_Stub *
00161 TAO_RT_Stub::set_policy_overrides (const CORBA::PolicyList & policies,
00162 CORBA::SetOverrideType set_add)
00163 {
00164
00165
00166 for (CORBA::ULong i = 0; i < policies.length (); ++i)
00167 {
00168 CORBA::Policy_ptr policy = policies[i];
00169 if (!CORBA::is_nil (policy))
00170 {
00171 CORBA::PolicyType const type = policy->policy_type ();
00172
00173 if (type == RTCORBA::PRIORITY_MODEL_POLICY_TYPE ||
00174 type == RTCORBA::THREADPOOL_POLICY_TYPE ||
00175 type == RTCORBA::SERVER_PROTOCOL_POLICY_TYPE)
00176 throw ::CORBA::NO_PERMISSION ();
00177 }
00178 }
00179
00180
00181
00182 return this->TAO_Stub::set_policy_overrides(policies, set_add);
00183 }
00184
00185 #endif
00186
00187 CORBA::Policy *
00188 TAO_RT_Stub::effective_priority_banded_connection (void)
00189 {
00190
00191 CORBA::Policy_var override =
00192 this->TAO_Stub::get_cached_policy (
00193 TAO_CACHED_POLICY_RT_PRIORITY_BANDED_CONNECTION);
00194
00195
00196 CORBA::Policy_var exposed = this->exposed_priority_banded_connection ();
00197
00198
00199 if (CORBA::is_nil (exposed.in ()))
00200 return override._retn ();
00201
00202 if (CORBA::is_nil (override.in ()))
00203 return exposed._retn ();
00204
00205 RTCORBA::PriorityBandedConnectionPolicy_var override_policy_var =
00206 RTCORBA::PriorityBandedConnectionPolicy::_narrow (override.in ());
00207
00208 TAO_PriorityBandedConnectionPolicy *override_policy =
00209 static_cast<TAO_PriorityBandedConnectionPolicy *> (override_policy_var.in ());
00210
00211 RTCORBA::PriorityBandedConnectionPolicy_var exposed_policy_var =
00212 RTCORBA::PriorityBandedConnectionPolicy::_narrow (exposed.in ());
00213
00214 TAO_PriorityBandedConnectionPolicy *exposed_policy =
00215 static_cast<TAO_PriorityBandedConnectionPolicy *> (exposed_policy_var.in ());
00216
00217
00218
00219 if (exposed_policy->priority_bands_rep ().length () == 0)
00220 return override._retn ();
00221
00222 if (override_policy->priority_bands_rep ().length () == 0)
00223 return exposed._retn ();
00224
00225
00226
00227 throw ::CORBA::INV_POLICY ();
00228 }
00229
00230 CORBA::Policy *
00231 TAO_RT_Stub::effective_client_protocol (void)
00232 {
00233
00234 CORBA::Policy_var override =
00235 this->TAO_Stub::get_cached_policy (TAO_CACHED_POLICY_RT_CLIENT_PROTOCOL);
00236
00237
00238 CORBA::Policy_var exposed =
00239 this->exposed_client_protocol ();
00240
00241
00242 if (CORBA::is_nil (exposed.in ()))
00243 return override._retn ();
00244
00245 if (CORBA::is_nil (override.in ()))
00246 return exposed._retn ();
00247
00248 RTCORBA::ClientProtocolPolicy_var override_policy_var =
00249 RTCORBA::ClientProtocolPolicy::_narrow (override.in ());
00250
00251 TAO_ClientProtocolPolicy *override_policy =
00252 static_cast<TAO_ClientProtocolPolicy *> (override_policy_var.in ());
00253
00254 RTCORBA::ClientProtocolPolicy_var exposed_policy_var =
00255 RTCORBA::ClientProtocolPolicy::_narrow (exposed.in ());
00256
00257 TAO_ClientProtocolPolicy *exposed_policy =
00258 static_cast<TAO_ClientProtocolPolicy *> (exposed_policy_var.in ());
00259
00260
00261
00262 RTCORBA::ProtocolList &protocols_rep_var =
00263 exposed_policy->protocols_rep ();
00264
00265 if (protocols_rep_var.length () == 0)
00266 return override._retn ();
00267
00268 if (override_policy->protocols_rep ().length () == 0)
00269 return exposed._retn ();
00270
00271
00272
00273 throw ::CORBA::INV_POLICY ();
00274 }
00275
00276 TAO_END_VERSIONED_NAMESPACE_DECL
00277
00278 #endif