Merge pull request #2216 from jwillemsen/jwi-cxxversionchecks
[ACE_TAO.git] / ACE / examples / APG / Timers / Alarm.cpp
blob99e9d49094d495d6e54507b95ab95b4e05d5f345
1 #include "ace/OS_NS_unistd.h"
2 #include "ace/OS_NS_sys_time.h"
4 // Listing 1 code/ch20
5 #include "ace/Timer_Queue_Adapters.h"
6 #include "ace/Timer_Heap.h"
8 typedef ACE_Async_Timer_Queue_Adapter<ACE_Timer_Heap> Timer;
9 // Listing 1
11 class CB : public ACE_Event_Handler
13 public:
14 CB (int id) : id_(id) { }
16 virtual int handle_timeout (const ACE_Time_Value &,
17 const void *arg)
19 ACE_TRACE ("CB::handle_timeout");
21 const int *val = static_cast<const int*> (arg);
22 ACE_ASSERT ((*val) == id_);
24 ACE_UNUSED_ARG (val);
26 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Timer expired\n")));
27 return 0;
30 private:
31 int id_;
34 // Listing 2 code/ch20
35 int ACE_TMAIN (int, ACE_TCHAR *[])
37 // Create the timer such that it blocks all signals
38 // when it goes off.
39 Timer timer;
41 // Schedule a timer to go off 2 seconds later and then
42 // after every 4 seconds.
43 CB cb (1);
44 int arg = 1;
45 ACE_Time_Value initial (2);
46 ACE_Time_Value repeat (4);
47 initial += ACE_OS::gettimeofday ();
48 timer.schedule (&cb, &arg, initial, repeat);
50 while (1) // Don't let the main thread exit.
51 ACE_OS::sleep (2);
52 ACE_NOTREACHED (return 0); // Not reached.
54 // Listing 2