Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / tests / AMI_Timeouts / timeout_i.cpp
blobe497ca6eaa3e9c830d34ff011e417f1b2c43822c
2 //=============================================================================
3 /**
4 * @file timeout_i.cpp
6 * Implements the timeout CORBA Object and its reply handler.
8 * @author Michael Kircher <Michael.Kircher@mchp.siemens.de>
9 */
10 //=============================================================================
13 #include "timeout_i.h"
14 #include "ace/OS_NS_unistd.h"
16 Timeout_i::Timeout_i (CORBA::ORB_ptr orb)
18 orb_ = CORBA::ORB::_duplicate (orb);
21 Timeout_i::~Timeout_i ()
25 void
26 Timeout_i::sendTimeToWait (CORBA::Long msec)
28 //ACE_DEBUG ((LM_DEBUG,
29 // "Timeout_i::sendTimeToWait: invoked with msec = %d\n\n",
30 // msec));
32 if (msec != 0)
34 // ACE_DEBUG ((LM_DEBUG,
35 // "Timeout_i::sendTimeToWait: sleeping\n\n"));
37 ACE_Time_Value tv (0, msec * 1000);
38 ACE_OS::sleep (tv);
42 void
43 Timeout_i::shutdown (void)
45 orb_->shutdown ();
46 //ACE_DEBUG ((LM_DEBUG,
47 // "Timeout_i::shutdown: shut down ORB\n\n"));
50 // Reply Handler implementation
52 TimeoutHandler_i::TimeoutHandler_i ()
53 : reply_counter_ (0)
54 , reply_excep_counter_ (0)
56 timer_.reset ();
57 timer_.start ();
58 timer_.stop ();
61 TimeoutHandler_i::~TimeoutHandler_i ()
65 void
66 TimeoutHandler_i::sendTimeToWait (void)
68 ACE_DEBUG ((LM_DEBUG,
69 "reply"));
70 ++reply_counter_;
71 timer_.stop ();
74 void
75 TimeoutHandler_i::sendTimeToWait_excep (::Messaging::ExceptionHolder *excep_holder)
77 timer_.stop ();
79 try
81 excep_holder->raise_exception ();
83 catch (const CORBA::TIMEOUT& )
85 ACE_DEBUG ((LM_DEBUG,
86 "timeout"));
87 ++reply_excep_counter_;
89 catch (...)
91 ACE_DEBUG ((LM_DEBUG,
92 "Error: Unexpected exception"));
96 void
97 TimeoutHandler_i::reset_reply_counter ()
99 reply_counter_ = 0;
102 void
103 TimeoutHandler_i::reset_reply_excep_counter ()
105 reply_excep_counter_ = 0;
108 unsigned short
109 TimeoutHandler_i::reply_counter ()
111 return reply_counter_;
114 unsigned short
115 TimeoutHandler_i::reply_excep_counter ()
117 return reply_excep_counter_;
120 void
121 TimeoutHandler_i::start ()
123 timer_.reset ();
124 timer_.start ();
127 ACE_Time_Value &
128 TimeoutHandler_i::elapsed_time ()
130 timer_.elapsed_time (elapsed_time_);
131 return elapsed_time_;