00001
00002
00003 #include "tao/Messaging/Messaging_Policy_i.h"
00004 #include "tao/Stub.h"
00005 #include "tao/ORB_Core.h"
00006 #include "tao/debug.h"
00007 #include "tao/AnyTypeCode/Any.h"
00008 #include "ace/Truncate.h"
00009
00010 #if ! defined (__ACE_INLINE__)
00011 #include "tao/Messaging/Messaging_Policy_i.inl"
00012 #endif
00013
00014 ACE_RCSID (Messaging,
00015 Messaging_Policy_i,
00016 "$Id: Messaging_Policy_i.cpp 88011 2009-12-09 09:50:25Z vzykov $")
00017
00018 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00019
00020 #if (TAO_HAS_RELATIVE_ROUNDTRIP_TIMEOUT_POLICY == 1)
00021
00022 TAO_RelativeRoundtripTimeoutPolicy::TAO_RelativeRoundtripTimeoutPolicy (
00023 const TimeBase::TimeT& relative_expiry)
00024 : ::CORBA::Object ()
00025 , ::CORBA::Policy ()
00026 , Messaging::RelativeRoundtripTimeoutPolicy ()
00027 , ::CORBA::LocalObject ()
00028 , relative_expiry_ (relative_expiry)
00029 {
00030 }
00031
00032 TAO_RelativeRoundtripTimeoutPolicy::TAO_RelativeRoundtripTimeoutPolicy (
00033 const TAO_RelativeRoundtripTimeoutPolicy &rhs)
00034 : ::CORBA::Object ()
00035 , ::CORBA::Policy ()
00036 , Messaging::RelativeRoundtripTimeoutPolicy ()
00037 , ::CORBA::LocalObject ()
00038 , relative_expiry_ (rhs.relative_expiry_)
00039 {
00040 }
00041
00042 TimeBase::TimeT
00043 TAO_RelativeRoundtripTimeoutPolicy::relative_expiry (void)
00044 {
00045 return this->relative_expiry_;
00046 }
00047
00048 CORBA::PolicyType
00049 TAO_RelativeRoundtripTimeoutPolicy::policy_type (void)
00050 {
00051 return Messaging::RELATIVE_RT_TIMEOUT_POLICY_TYPE;
00052 }
00053
00054 void
00055 TAO_RelativeRoundtripTimeoutPolicy::hook (TAO_ORB_Core *orb_core,
00056 TAO_Stub *stub,
00057 bool &has_timeout,
00058 ACE_Time_Value &time_value)
00059 {
00060 try
00061 {
00062 CORBA::Policy_var policy = CORBA::Policy::_nil ();
00063
00064 if (stub == 0)
00065 {
00066 policy =
00067 orb_core->get_cached_policy_including_current (
00068 TAO_CACHED_POLICY_RELATIVE_ROUNDTRIP_TIMEOUT);
00069 }
00070 else
00071 {
00072 policy =
00073 stub->get_cached_policy (
00074 TAO_CACHED_POLICY_RELATIVE_ROUNDTRIP_TIMEOUT);
00075 }
00076
00077 if (CORBA::is_nil (policy.in ()))
00078 {
00079 has_timeout = false;
00080 return;
00081 }
00082
00083 Messaging::RelativeRoundtripTimeoutPolicy_var p =
00084 Messaging::RelativeRoundtripTimeoutPolicy::_narrow (policy.in ());
00085
00086 TimeBase::TimeT const t = p->relative_expiry ();
00087 TimeBase::TimeT const seconds = t / 10000000u;
00088 TimeBase::TimeT const microseconds = (t % 10000000u) / 10;
00089 time_value.set (ACE_Utils::truncate_cast<time_t> (seconds),
00090 ACE_Utils::truncate_cast<suseconds_t> (microseconds));
00091
00092
00093 has_timeout = true;
00094
00095 if (TAO_debug_level > 0)
00096 {
00097 ACE_UINT64 msecs;
00098 const_cast<ACE_Time_Value const &> (time_value).msec (msecs);
00099 ACE_DEBUG ((LM_DEBUG,
00100 ACE_TEXT ("TAO (%P|%t) - Request timeout is ")
00101 ACE_TEXT ("%Q milliseconds\n"),
00102 msecs));
00103 }
00104 }
00105 catch (const ::CORBA::Exception&)
00106 {
00107
00108 }
00109 }
00110
00111 CORBA::Policy_ptr
00112 TAO_RelativeRoundtripTimeoutPolicy::create (const CORBA::Any& val)
00113 {
00114
00115
00116 TimeBase::TimeT value;
00117 if ((val >>= value) == 0)
00118 throw ::CORBA::PolicyError (CORBA::BAD_POLICY_VALUE);
00119
00120 TAO_RelativeRoundtripTimeoutPolicy *tmp = 0;
00121 ACE_NEW_THROW_EX (tmp,
00122 TAO_RelativeRoundtripTimeoutPolicy (value),
00123 CORBA::NO_MEMORY (TAO::VMCID,
00124 CORBA::COMPLETED_NO));
00125
00126 return tmp;
00127 }
00128
00129 TAO_RelativeRoundtripTimeoutPolicy *
00130 TAO_RelativeRoundtripTimeoutPolicy::clone (void) const
00131 {
00132 TAO_RelativeRoundtripTimeoutPolicy *copy = 0;
00133 ACE_NEW_RETURN (copy,
00134 TAO_RelativeRoundtripTimeoutPolicy (*this),
00135 0);
00136 return copy;
00137 }
00138
00139 CORBA::Policy_ptr
00140 TAO_RelativeRoundtripTimeoutPolicy::copy (void)
00141 {
00142
00143
00144
00145 TAO_RelativeRoundtripTimeoutPolicy* tmp = 0;
00146 ACE_NEW_THROW_EX (tmp, TAO_RelativeRoundtripTimeoutPolicy (*this),
00147 CORBA::NO_MEMORY (TAO::VMCID,
00148 CORBA::COMPLETED_NO));
00149
00150 return tmp;
00151 }
00152
00153 void
00154 TAO_RelativeRoundtripTimeoutPolicy::destroy (void)
00155 {
00156 }
00157
00158 TAO_Cached_Policy_Type
00159 TAO_RelativeRoundtripTimeoutPolicy::_tao_cached_type (void) const
00160 {
00161 return TAO_CACHED_POLICY_RELATIVE_ROUNDTRIP_TIMEOUT;
00162 }
00163
00164 void
00165 TAO_RelativeRoundtripTimeoutPolicy::set_time_value (ACE_Time_Value &time_value)
00166 {
00167 TimeBase::TimeT const t = this->relative_expiry_;
00168 TimeBase::TimeT const seconds = t / 10000000u;
00169 TimeBase::TimeT const microseconds = (t % 10000000u) / 10;
00170 time_value.set (ACE_Utils::truncate_cast<time_t> (seconds),
00171 ACE_Utils::truncate_cast<suseconds_t> (microseconds));
00172
00173 if (TAO_debug_level > 0)
00174 {
00175 ACE_UINT64 msecs;
00176 const_cast<ACE_Time_Value const &> (time_value).msec (msecs);
00177 ACE_DEBUG ((LM_DEBUG,
00178 ACE_TEXT ("TAO (%P|%t) - Request timeout is ")
00179 ACE_TEXT ("%Q milliseconds\n"),
00180 msecs));
00181 }
00182 }
00183
00184 #endif
00185
00186
00187
00188 #if (TAO_HAS_SYNC_SCOPE_POLICY == 1)
00189
00190 TAO_Sync_Scope_Policy::TAO_Sync_Scope_Policy (Messaging::SyncScope synchronization)
00191 : ::CORBA::Object ()
00192 , ::CORBA::Policy ()
00193 , Messaging::SyncScopePolicy ()
00194 , ::CORBA::LocalObject ()
00195 , synchronization_ (synchronization)
00196 {
00197 }
00198
00199 TAO_Sync_Scope_Policy::TAO_Sync_Scope_Policy (const TAO_Sync_Scope_Policy &rhs)
00200 : ::CORBA::Object ()
00201 , ::CORBA::Policy ()
00202 , Messaging::SyncScopePolicy ()
00203 , ::CORBA::LocalObject ()
00204 , synchronization_ (rhs.synchronization_)
00205 {
00206 }
00207
00208 CORBA::PolicyType
00209 TAO_Sync_Scope_Policy::policy_type (void)
00210 {
00211 return Messaging::SYNC_SCOPE_POLICY_TYPE;
00212 }
00213
00214 void
00215 TAO_Sync_Scope_Policy::hook (TAO_ORB_Core *orb_core,
00216 TAO_Stub *stub,
00217 bool &has_synchronization,
00218 Messaging::SyncScope &scope)
00219 {
00220 try
00221 {
00222 CORBA::Policy_var policy = CORBA::Policy::_nil ();
00223
00224 if (stub == 0)
00225 {
00226 policy =
00227 orb_core->get_cached_policy_including_current (
00228 TAO_CACHED_POLICY_SYNC_SCOPE);
00229 }
00230 else
00231 {
00232 policy =
00233 stub->get_cached_policy (TAO_CACHED_POLICY_SYNC_SCOPE);
00234 }
00235
00236 if (CORBA::is_nil (policy.in ()))
00237 {
00238 has_synchronization = true;
00239 scope = Messaging::SYNC_WITH_TRANSPORT;
00240 return;
00241 }
00242 Messaging::SyncScopePolicy_var p =
00243 Messaging::SyncScopePolicy::_narrow (policy.in ());
00244
00245 if (CORBA::is_nil (p.in ()))
00246 throw ::CORBA::INTERNAL (
00247 CORBA::SystemException::_tao_minor_code (
00248 TAO_POLICY_NARROW_CODE,
00249 0),
00250 CORBA::COMPLETED_NO);
00251
00252 has_synchronization = true;
00253 scope = p->synchronization ();
00254 }
00255 catch (const ::CORBA::Exception&)
00256 {
00257
00258 }
00259 }
00260
00261 CORBA::Policy_ptr
00262 TAO_Sync_Scope_Policy::create (const CORBA::Any& val)
00263 {
00264 Messaging::SyncScope synchronization;
00265 if ((val >>= synchronization) == 0)
00266 throw ::CORBA::PolicyError (CORBA::BAD_POLICY_VALUE);
00267
00268 TAO_Sync_Scope_Policy *servant = 0;
00269 ACE_NEW_THROW_EX (servant,
00270 TAO_Sync_Scope_Policy (synchronization),
00271 CORBA::NO_MEMORY ());
00272
00273 return servant;
00274 }
00275
00276 TAO_Sync_Scope_Policy *
00277 TAO_Sync_Scope_Policy::clone (void) const
00278 {
00279 TAO_Sync_Scope_Policy *copy = 0;
00280 ACE_NEW_RETURN (copy,
00281 TAO_Sync_Scope_Policy (*this),
00282 0);
00283 return copy;
00284 }
00285
00286 Messaging::SyncScope
00287 TAO_Sync_Scope_Policy::synchronization (void)
00288 {
00289 return this->synchronization_;
00290 }
00291
00292 CORBA::Policy_ptr
00293 TAO_Sync_Scope_Policy::copy (void)
00294 {
00295 TAO_Sync_Scope_Policy *servant = 0;
00296 ACE_NEW_THROW_EX (servant,
00297 TAO_Sync_Scope_Policy (*this),
00298 CORBA::NO_MEMORY ());
00299
00300 return servant;
00301 }
00302
00303 void
00304 TAO_Sync_Scope_Policy::destroy (void)
00305 {
00306 }
00307 TAO_Cached_Policy_Type
00308 TAO_Sync_Scope_Policy::_tao_cached_type (void) const
00309 {
00310 return TAO_CACHED_POLICY_SYNC_SCOPE;
00311 }
00312
00313 #endif
00314
00315 TAO_END_VERSIONED_NAMESPACE_DECL