Merge pull request #2216 from jwillemsen/jwi-cxxversionchecks
[ACE_TAO.git] / ACE / examples / APG / Timers / TimerDispatcher.cpp
blob9ccc18a7b71bd0d07a245e0891c960cef580fc7d
1 #include "TimerDispatcher.h"
2 // Listing 1 code/ch20
3 void Timer_Dispatcher::wait_for_event ()
5 ACE_TRACE ("Timer_Dispatcher::wait_for_event");
7 while (1)
9 ACE_Time_Value max_tv = timer_queue_->gettimeofday ();
11 ACE_Time_Value *this_timeout =
12 this->timer_queue_->calculate_timeout (&max_tv);
14 if (*this_timeout == ACE_Time_Value::zero)
15 this->timer_queue_->expire ();
16 else
18 // Convert to absolute time.
19 ACE_Time_Value next_timeout =
20 timer_queue_->gettimeofday ();
21 next_timeout += *this_timeout;
22 if (this->timer_.wait (&next_timeout) == -1 )
23 this->timer_queue_->expire ();
27 // Listing 1
28 // Listing 2 code/ch20
29 long
30 Timer_Dispatcher::schedule (ACE_Event_Handler *cb,
31 void *arg,
32 const ACE_Time_Value &abs_time,
33 const ACE_Time_Value &interval)
35 ACE_TRACE ("Timer_Dispatcher::schedule_timer");
37 return this->timer_queue_->schedule
38 (cb, arg, abs_time, interval);
40 // Listing 2
41 // Listing 3 code/ch20
42 int
43 Timer_Dispatcher::cancel (ACE_Event_Handler *cb,
44 int dont_call_handle_close)
46 ACE_TRACE ("Timer_Dispatcher::cancel");
47 return timer_queue_->cancel (cb, dont_call_handle_close);
49 // Listing 3
50 // Listing 4 code/ch20
51 void Timer_Dispatcher::set (ACE_Timer_Queue *timer_queue)
53 ACE_TRACE ("Timer_Dispatcher::set");
55 timer_queue_ = timer_queue;
57 // Listing 4
59 int
60 Timer_Dispatcher::reset_interval (long timer_id,
61 const ACE_Time_Value &interval)
63 ACE_TRACE ("Timer_Dispatcher::reset_interval");
65 return timer_queue_->reset_interval(timer_id, interval);
67 ACE_SINGLETON_TEMPLATE_INSTANTIATE(ACE_Singleton, Timer_Dispatcher, ACE_Null_Mutex);