Merge pull request #2218 from jwillemsen/jwi-pthreadsigmask
[ACE_TAO.git] / TAO / tao / Messaging / Messaging_Policy_i.cpp
blob6bb83e9eee655fda604a3be55de6f3bc2b2d5d98
1 #include "tao/Messaging/Messaging_Policy_i.h"
2 #include "tao/Stub.h"
3 #include "tao/ORB_Core.h"
4 #include "tao/debug.h"
5 #include "tao/AnyTypeCode/Any.h"
6 #include "ace/Truncate.h"
8 #if ! defined (__ACE_INLINE__)
9 #include "tao/Messaging/Messaging_Policy_i.inl"
10 #endif /* __ACE_INLINE__ */
12 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
14 #if (TAO_HAS_RELATIVE_ROUNDTRIP_TIMEOUT_POLICY == 1)
16 TAO_RelativeRoundtripTimeoutPolicy::TAO_RelativeRoundtripTimeoutPolicy (
17 const TimeBase::TimeT& relative_expiry)
18 : ::CORBA::Object ()
19 , ::CORBA::Policy ()
20 , Messaging::RelativeRoundtripTimeoutPolicy ()
21 , ::CORBA::LocalObject ()
22 , relative_expiry_ (relative_expiry)
26 TAO_RelativeRoundtripTimeoutPolicy::TAO_RelativeRoundtripTimeoutPolicy (
27 const TAO_RelativeRoundtripTimeoutPolicy &rhs)
28 : ::CORBA::Object ()
29 , ::CORBA::Policy ()
30 , Messaging::RelativeRoundtripTimeoutPolicy ()
31 , ::CORBA::LocalObject ()
32 , relative_expiry_ (rhs.relative_expiry_)
36 TimeBase::TimeT
37 TAO_RelativeRoundtripTimeoutPolicy::relative_expiry ()
39 return this->relative_expiry_;
42 CORBA::PolicyType
43 TAO_RelativeRoundtripTimeoutPolicy::policy_type ()
45 return Messaging::RELATIVE_RT_TIMEOUT_POLICY_TYPE;
48 void
49 TAO_RelativeRoundtripTimeoutPolicy::hook (TAO_ORB_Core *orb_core,
50 TAO_Stub *stub,
51 bool &has_timeout,
52 ACE_Time_Value &time_value)
54 try
56 CORBA::Policy_var policy = CORBA::Policy::_nil ();
58 if (stub == 0)
60 policy =
61 orb_core->get_cached_policy_including_current (
62 TAO_CACHED_POLICY_RELATIVE_ROUNDTRIP_TIMEOUT);
64 else
66 policy =
67 stub->get_cached_policy (
68 TAO_CACHED_POLICY_RELATIVE_ROUNDTRIP_TIMEOUT);
71 if (CORBA::is_nil (policy.in ()))
73 has_timeout = false;
74 return;
77 Messaging::RelativeRoundtripTimeoutPolicy_var p =
78 Messaging::RelativeRoundtripTimeoutPolicy::_narrow (policy.in ());
80 TimeBase::TimeT const t = p->relative_expiry ();
81 TimeBase::TimeT const seconds = t / 10000000u;
82 TimeBase::TimeT const microseconds = (t % 10000000u) / 10;
83 time_value.set (ACE_Utils::truncate_cast<time_t> (seconds),
84 ACE_Utils::truncate_cast<suseconds_t> (microseconds));
86 // Set the flag once all operations complete successfully
87 has_timeout = true;
89 if (TAO_debug_level > 0)
91 ACE_UINT64 msecs;
92 const_cast<ACE_Time_Value const &> (time_value).msec (msecs);
93 TAOLIB_DEBUG ((LM_DEBUG,
94 ACE_TEXT ("TAO (%P|%t) - Request timeout is ")
95 ACE_TEXT ("%Q milliseconds\n"),
96 msecs));
99 catch (const ::CORBA::Exception&)
101 // Ignore all exceptions...
105 CORBA::Policy_ptr
106 TAO_RelativeRoundtripTimeoutPolicy::create (const CORBA::Any& val)
108 // Future policy implementors: notice how the following code is
109 // exception safe!
110 TimeBase::TimeT value;
111 if ((val >>= value) == 0)
112 throw ::CORBA::PolicyError (CORBA::BAD_POLICY_VALUE);
114 TAO_RelativeRoundtripTimeoutPolicy *tmp = 0;
115 ACE_NEW_THROW_EX (tmp,
116 TAO_RelativeRoundtripTimeoutPolicy (value),
117 CORBA::NO_MEMORY (TAO::VMCID,
118 CORBA::COMPLETED_NO));
120 return tmp;
123 TAO_RelativeRoundtripTimeoutPolicy *
124 TAO_RelativeRoundtripTimeoutPolicy::clone () const
126 TAO_RelativeRoundtripTimeoutPolicy *copy = 0;
127 ACE_NEW_RETURN (copy,
128 TAO_RelativeRoundtripTimeoutPolicy (*this),
130 return copy;
133 CORBA::Policy_ptr
134 TAO_RelativeRoundtripTimeoutPolicy::copy ()
136 // Future policy implementors: notice how the following code is
137 // exception safe!
139 TAO_RelativeRoundtripTimeoutPolicy* tmp = 0;
140 ACE_NEW_THROW_EX (tmp, TAO_RelativeRoundtripTimeoutPolicy (*this),
141 CORBA::NO_MEMORY (TAO::VMCID,
142 CORBA::COMPLETED_NO));
144 return tmp;
147 void
148 TAO_RelativeRoundtripTimeoutPolicy::destroy ()
152 TAO_Cached_Policy_Type
153 TAO_RelativeRoundtripTimeoutPolicy::_tao_cached_type () const
155 return TAO_CACHED_POLICY_RELATIVE_ROUNDTRIP_TIMEOUT;
158 void
159 TAO_RelativeRoundtripTimeoutPolicy::set_time_value (ACE_Time_Value &time_value)
161 TimeBase::TimeT const t = this->relative_expiry_;
162 TimeBase::TimeT const seconds = t / 10000000u;
163 TimeBase::TimeT const microseconds = (t % 10000000u) / 10;
164 time_value.set (ACE_Utils::truncate_cast<time_t> (seconds),
165 ACE_Utils::truncate_cast<suseconds_t> (microseconds));
167 if (TAO_debug_level > 0)
169 ACE_UINT64 msecs;
170 const_cast<ACE_Time_Value const &> (time_value).msec (msecs);
171 TAOLIB_DEBUG ((LM_DEBUG,
172 ACE_TEXT ("TAO (%P|%t) - Request timeout is ")
173 ACE_TEXT ("%Q milliseconds\n"),
174 msecs));
178 #endif /* TAO_HAS_RELATIVE_ROUNDTRIP_TIMEOUT_POLICY == 1 */
180 // ****************************************************************
182 #if (TAO_HAS_SYNC_SCOPE_POLICY == 1)
184 TAO_Sync_Scope_Policy::TAO_Sync_Scope_Policy (Messaging::SyncScope synchronization)
185 : ::CORBA::Object ()
186 , ::CORBA::Policy ()
187 , Messaging::SyncScopePolicy ()
188 , ::CORBA::LocalObject ()
189 , synchronization_ (synchronization)
193 TAO_Sync_Scope_Policy::TAO_Sync_Scope_Policy (const TAO_Sync_Scope_Policy &rhs)
194 : ::CORBA::Object ()
195 , ::CORBA::Policy ()
196 , Messaging::SyncScopePolicy ()
197 , ::CORBA::LocalObject ()
198 , synchronization_ (rhs.synchronization_)
202 CORBA::PolicyType
203 TAO_Sync_Scope_Policy::policy_type ()
205 return Messaging::SYNC_SCOPE_POLICY_TYPE;
208 void
209 TAO_Sync_Scope_Policy::hook (TAO_ORB_Core *orb_core,
210 TAO_Stub *stub,
211 bool &has_synchronization,
212 Messaging::SyncScope &scope)
216 CORBA::Policy_var policy = CORBA::Policy::_nil ();
218 if (stub == 0)
220 policy =
221 orb_core->get_cached_policy_including_current (
222 TAO_CACHED_POLICY_SYNC_SCOPE);
224 else
226 policy =
227 stub->get_cached_policy (TAO_CACHED_POLICY_SYNC_SCOPE);
230 if (CORBA::is_nil (policy.in ()))
232 has_synchronization = true;
233 scope = orb_core->default_sync_scope ();
234 return;
236 Messaging::SyncScopePolicy_var p =
237 Messaging::SyncScopePolicy::_narrow (policy.in ());
239 if (CORBA::is_nil (p.in ()))
240 throw ::CORBA::INTERNAL (
241 CORBA::SystemException::_tao_minor_code (
242 TAO_POLICY_NARROW_CODE,
244 CORBA::COMPLETED_NO);
246 has_synchronization = true;
247 scope = p->synchronization ();
249 catch (const ::CORBA::Exception&)
251 // Ignore all exceptions...
255 CORBA::Policy_ptr
256 TAO_Sync_Scope_Policy::create (const CORBA::Any& val)
258 Messaging::SyncScope synchronization;
259 if ((val >>= synchronization) == 0)
260 throw ::CORBA::PolicyError (CORBA::BAD_POLICY_VALUE);
262 TAO_Sync_Scope_Policy *servant = 0;
263 ACE_NEW_THROW_EX (servant,
264 TAO_Sync_Scope_Policy (synchronization),
265 CORBA::NO_MEMORY ());
267 return servant;
270 TAO_Sync_Scope_Policy *
271 TAO_Sync_Scope_Policy::clone () const
273 TAO_Sync_Scope_Policy *copy = 0;
274 ACE_NEW_RETURN (copy,
275 TAO_Sync_Scope_Policy (*this),
277 return copy;
280 Messaging::SyncScope
281 TAO_Sync_Scope_Policy::synchronization ()
283 return this->synchronization_;
286 CORBA::Policy_ptr
287 TAO_Sync_Scope_Policy::copy ()
289 TAO_Sync_Scope_Policy *servant = 0;
290 ACE_NEW_THROW_EX (servant,
291 TAO_Sync_Scope_Policy (*this),
292 CORBA::NO_MEMORY ());
294 return servant;
297 void
298 TAO_Sync_Scope_Policy::destroy ()
301 TAO_Cached_Policy_Type
302 TAO_Sync_Scope_Policy::_tao_cached_type () const
304 return TAO_CACHED_POLICY_SYNC_SCOPE;
307 #endif /* TAO_HAS_SYNC_SCOPE_POLICY == 1 */
309 TAO_END_VERSIONED_NAMESPACE_DECL