Merge pull request #2216 from jwillemsen/jwi-cxxversionchecks
[ACE_TAO.git] / TAO / tao / Messaging / Connection_Timeout_Policy_i.cpp
blobd8ebe3a5c3dbc0147ea15f41d2a8561c26b3e181
1 // -*- C++ -*-
2 #include "tao/Messaging/Connection_Timeout_Policy_i.h"
3 #include "tao/ORB_Core.h"
4 #include "tao/Stub.h"
5 #include "tao/debug.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)
16 : ::CORBA::Object ()
17 , ::CORBA::Policy ()
18 , TAO::ConnectionTimeoutPolicy ()
19 , ::CORBA::LocalObject ()
20 , relative_expiry_ (relative_expiry)
24 TAO_ConnectionTimeoutPolicy::TAO_ConnectionTimeoutPolicy (
25 const TAO_ConnectionTimeoutPolicy &rhs)
26 : ::CORBA::Object ()
27 , ::CORBA::Policy ()
28 , TAO::ConnectionTimeoutPolicy ()
29 , ::CORBA::LocalObject ()
30 , relative_expiry_ (rhs.relative_expiry_)
34 TimeBase::TimeT
35 TAO_ConnectionTimeoutPolicy::relative_expiry ()
37 return this->relative_expiry_;
40 CORBA::PolicyType
41 TAO_ConnectionTimeoutPolicy::policy_type ()
43 return TAO::CONNECTION_TIMEOUT_POLICY_TYPE;
46 void
47 TAO_ConnectionTimeoutPolicy::hook (TAO_ORB_Core *orb_core,
48 TAO_Stub *stub,
49 bool &has_timeout,
50 ACE_Time_Value &time_value)
52 try
54 CORBA::Policy_var policy = CORBA::Policy::_nil ();
56 if (stub == 0)
58 policy =
59 orb_core->get_cached_policy_including_current (
60 TAO_CACHED_POLICY_CONNECTION_TIMEOUT);
62 else
64 policy =
65 stub->get_cached_policy (TAO_CACHED_POLICY_CONNECTION_TIMEOUT);
68 if (CORBA::is_nil (policy.in ()))
70 has_timeout = false;
71 return;
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
84 has_timeout = true;
86 if (TAO_debug_level > 0)
88 ACE_UINT64 msecs;
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"),
93 msecs));
96 catch (const ::CORBA::Exception&)
98 // Ignore all exceptions...
102 CORBA::Policy_ptr
103 TAO_ConnectionTimeoutPolicy::create (const CORBA::Any& val)
105 // Future policy implementors: notice how the following code is
106 // exception safe!
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));
118 return tmp;
121 TAO_ConnectionTimeoutPolicy *
122 TAO_ConnectionTimeoutPolicy::clone () const
124 TAO_ConnectionTimeoutPolicy *copy = 0;
125 ACE_NEW_RETURN (copy,
126 TAO_ConnectionTimeoutPolicy (*this),
128 return copy;
131 CORBA::Policy_ptr
132 TAO_ConnectionTimeoutPolicy::copy ()
134 // Future policy implementors: notice how the following code is
135 // exception safe!
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));
142 return tmp;
145 void
146 TAO_ConnectionTimeoutPolicy::destroy ()
150 TAO_Cached_Policy_Type
151 TAO_ConnectionTimeoutPolicy::_tao_cached_type () const
153 return TAO_CACHED_POLICY_CONNECTION_TIMEOUT;
156 void
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)
167 ACE_UINT64 msecs;
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"),
172 msecs));
176 TAO_END_VERSIONED_NAMESPACE_DECL
178 #endif /* TAO_HAS_RELATIVE_ROUNDTRIP_TIMEOUT_POLICY == 1 */