1 #include "tao/Messaging/Messaging_Policy_i.h"
3 #include "tao/ORB_Core.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
)
20 , Messaging::RelativeRoundtripTimeoutPolicy ()
21 , ::CORBA::LocalObject ()
22 , relative_expiry_ (relative_expiry
)
26 TAO_RelativeRoundtripTimeoutPolicy::TAO_RelativeRoundtripTimeoutPolicy (
27 const TAO_RelativeRoundtripTimeoutPolicy
&rhs
)
30 , Messaging::RelativeRoundtripTimeoutPolicy ()
31 , ::CORBA::LocalObject ()
32 , relative_expiry_ (rhs
.relative_expiry_
)
37 TAO_RelativeRoundtripTimeoutPolicy::relative_expiry ()
39 return this->relative_expiry_
;
43 TAO_RelativeRoundtripTimeoutPolicy::policy_type ()
45 return Messaging::RELATIVE_RT_TIMEOUT_POLICY_TYPE
;
49 TAO_RelativeRoundtripTimeoutPolicy::hook (TAO_ORB_Core
*orb_core
,
52 ACE_Time_Value
&time_value
)
56 CORBA::Policy_var policy
= CORBA::Policy::_nil ();
61 orb_core
->get_cached_policy_including_current (
62 TAO_CACHED_POLICY_RELATIVE_ROUNDTRIP_TIMEOUT
);
67 stub
->get_cached_policy (
68 TAO_CACHED_POLICY_RELATIVE_ROUNDTRIP_TIMEOUT
);
71 if (CORBA::is_nil (policy
.in ()))
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
89 if (TAO_debug_level
> 0)
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"),
99 catch (const ::CORBA::Exception
&)
101 // Ignore all exceptions...
106 TAO_RelativeRoundtripTimeoutPolicy::create (const CORBA::Any
& val
)
108 // Future policy implementors: notice how the following code is
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
));
123 TAO_RelativeRoundtripTimeoutPolicy
*
124 TAO_RelativeRoundtripTimeoutPolicy::clone () const
126 TAO_RelativeRoundtripTimeoutPolicy
*copy
= 0;
127 ACE_NEW_RETURN (copy
,
128 TAO_RelativeRoundtripTimeoutPolicy (*this),
134 TAO_RelativeRoundtripTimeoutPolicy::copy ()
136 // Future policy implementors: notice how the following code is
139 TAO_RelativeRoundtripTimeoutPolicy
* tmp
= 0;
140 ACE_NEW_THROW_EX (tmp
, TAO_RelativeRoundtripTimeoutPolicy (*this),
141 CORBA::NO_MEMORY (TAO::VMCID
,
142 CORBA::COMPLETED_NO
));
148 TAO_RelativeRoundtripTimeoutPolicy::destroy ()
152 TAO_Cached_Policy_Type
153 TAO_RelativeRoundtripTimeoutPolicy::_tao_cached_type () const
155 return TAO_CACHED_POLICY_RELATIVE_ROUNDTRIP_TIMEOUT
;
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)
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"),
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
)
187 , Messaging::SyncScopePolicy ()
188 , ::CORBA::LocalObject ()
189 , synchronization_ (synchronization
)
193 TAO_Sync_Scope_Policy::TAO_Sync_Scope_Policy (const TAO_Sync_Scope_Policy
&rhs
)
196 , Messaging::SyncScopePolicy ()
197 , ::CORBA::LocalObject ()
198 , synchronization_ (rhs
.synchronization_
)
203 TAO_Sync_Scope_Policy::policy_type ()
205 return Messaging::SYNC_SCOPE_POLICY_TYPE
;
209 TAO_Sync_Scope_Policy::hook (TAO_ORB_Core
*orb_core
,
211 bool &has_synchronization
,
212 Messaging::SyncScope
&scope
)
216 CORBA::Policy_var policy
= CORBA::Policy::_nil ();
221 orb_core
->get_cached_policy_including_current (
222 TAO_CACHED_POLICY_SYNC_SCOPE
);
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 ();
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...
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 ());
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),
281 TAO_Sync_Scope_Policy::synchronization ()
283 return this->synchronization_
;
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 ());
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