2 #include "tao/Messaging/Connection_Timeout_Policy_i.h"
3 #include "tao/ORB_Core.h"
6 #include "tao/SystemException.h"
7 #include "tao/AnyTypeCode/Any.h"
8 #include "ace/Truncate.h"
10 #if (TAO_HAS_CONNECTION_TIMEOUT_POLICY == 1)
12 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
14 TAO_ConnectionTimeoutPolicy::TAO_ConnectionTimeoutPolicy (
15 const TimeBase::TimeT
& relative_expiry
)
18 , TAO::ConnectionTimeoutPolicy ()
19 , ::CORBA::LocalObject ()
20 , relative_expiry_ (relative_expiry
)
24 TAO_ConnectionTimeoutPolicy::TAO_ConnectionTimeoutPolicy (
25 const TAO_ConnectionTimeoutPolicy
&rhs
)
28 , TAO::ConnectionTimeoutPolicy ()
29 , ::CORBA::LocalObject ()
30 , relative_expiry_ (rhs
.relative_expiry_
)
35 TAO_ConnectionTimeoutPolicy::relative_expiry ()
37 return this->relative_expiry_
;
41 TAO_ConnectionTimeoutPolicy::policy_type ()
43 return TAO::CONNECTION_TIMEOUT_POLICY_TYPE
;
47 TAO_ConnectionTimeoutPolicy::hook (TAO_ORB_Core
*orb_core
,
50 ACE_Time_Value
&time_value
)
54 CORBA::Policy_var policy
= CORBA::Policy::_nil ();
59 orb_core
->get_cached_policy_including_current (
60 TAO_CACHED_POLICY_CONNECTION_TIMEOUT
);
65 stub
->get_cached_policy (TAO_CACHED_POLICY_CONNECTION_TIMEOUT
);
68 if (CORBA::is_nil (policy
.in ()))
74 TAO::ConnectionTimeoutPolicy_var p
=
75 TAO::ConnectionTimeoutPolicy::_narrow (policy
.in ());
77 TimeBase::TimeT
const t
= p
->relative_expiry ();
78 TimeBase::TimeT
const seconds
= t
/ 10000000u;
79 TimeBase::TimeT
const microseconds
= (t
% 10000000u) / 10;
80 time_value
.set (ACE_Utils::truncate_cast
<time_t> (seconds
),
81 ACE_Utils::truncate_cast
<suseconds_t
> (microseconds
));
83 // Set the flag once all operations complete successfully
86 if (TAO_debug_level
> 0)
89 const_cast<ACE_Time_Value
const &> (time_value
).msec (msecs
);
90 TAOLIB_DEBUG ((LM_DEBUG
,
91 ACE_TEXT ("TAO (%P|%t) - Connect timeout is ")
92 ACE_TEXT ("%Q milliseconds\n"),
96 catch (const ::CORBA::Exception
&)
98 // Ignore all exceptions...
103 TAO_ConnectionTimeoutPolicy::create (const CORBA::Any
& val
)
105 // Future policy implementors: notice how the following code is
108 TimeBase::TimeT value
;
109 if ((val
>>= value
) == 0)
110 throw ::CORBA::PolicyError (CORBA::BAD_POLICY_VALUE
);
112 TAO_ConnectionTimeoutPolicy
*tmp
= 0;
113 ACE_NEW_THROW_EX (tmp
,
114 TAO_ConnectionTimeoutPolicy (value
),
115 CORBA::NO_MEMORY (TAO::VMCID
,
116 CORBA::COMPLETED_NO
));
121 TAO_ConnectionTimeoutPolicy
*
122 TAO_ConnectionTimeoutPolicy::clone () const
124 TAO_ConnectionTimeoutPolicy
*copy
= 0;
125 ACE_NEW_RETURN (copy
,
126 TAO_ConnectionTimeoutPolicy (*this),
132 TAO_ConnectionTimeoutPolicy::copy ()
134 // Future policy implementors: notice how the following code is
136 TAO_ConnectionTimeoutPolicy
* tmp
= 0;
137 ACE_NEW_THROW_EX (tmp
,
138 TAO_ConnectionTimeoutPolicy (*this),
139 CORBA::NO_MEMORY (TAO::VMCID
,
140 CORBA::COMPLETED_NO
));
146 TAO_ConnectionTimeoutPolicy::destroy ()
150 TAO_Cached_Policy_Type
151 TAO_ConnectionTimeoutPolicy::_tao_cached_type () const
153 return TAO_CACHED_POLICY_CONNECTION_TIMEOUT
;
157 TAO_ConnectionTimeoutPolicy::set_time_value (ACE_Time_Value
&time_value
)
159 TimeBase::TimeT
const t
= this->relative_expiry_
;
160 TimeBase::TimeT
const seconds
= t
/ 10000000u;
161 TimeBase::TimeT
const microseconds
= (t
% 10000000u) / 10;
162 time_value
.set (ACE_Utils::truncate_cast
<time_t> (seconds
),
163 ACE_Utils::truncate_cast
<suseconds_t
> (microseconds
));
165 if (TAO_debug_level
> 0)
168 const_cast<ACE_Time_Value
const &> (time_value
).msec (msecs
);
169 TAOLIB_DEBUG ((LM_DEBUG
,
170 ACE_TEXT ("TAO (%P|%t) - Connect timeout is ")
171 ACE_TEXT ("%Q milliseconds\n"),
176 TAO_END_VERSIONED_NAMESPACE_DECL
178 #endif /* TAO_HAS_RELATIVE_ROUNDTRIP_TIMEOUT_POLICY == 1 */