Merge pull request #2216 from jwillemsen/jwi-cxxversionchecks
[ACE_TAO.git] / ACE / examples / APG / Timers / Task.cpp
blob01325f5502a5e454e4367f5ba743becab6ee9215
1 #include "ace/OS_NS_sys_time.h"
3 // Listing 1 code/ch20
4 #include "ace/Timer_Queue_Adapters.h"
5 #include "ace/Timer_Heap.h"
7 typedef ACE_Thread_Timer_Queue_Adapter<ACE_Timer_Heap>
8 ActiveTimer;
10 // Listing 1
11 // Listing 2 code/ch20
12 class CB : public ACE_Event_Handler
14 public:
15 CB (int id) : id_(id) { }
17 virtual int handle_timeout (const ACE_Time_Value &,
18 const void *arg)
20 ACE_TRACE ("CB::handle_timeout");
22 const int *val = static_cast<const int*> (arg);
23 ACE_ASSERT((*val) == id_);
25 ACE_UNUSED_ARG (val);
27 ACE_DEBUG ((LM_DEBUG,
28 ACE_TEXT ("Expiry handled by thread %t\n")));
29 return 0;
32 private:
33 int id_;
35 // Listing 2
37 // Listing 3 code/ch20
38 int ACE_TMAIN (int, ACE_TCHAR *[])
40 ACE_DEBUG ((LM_DEBUG,
41 ACE_TEXT ("the main thread %t has started\n")));
43 // Create an "active" timer and start its thread.
44 ActiveTimer atimer;
45 atimer.activate ();
47 CB cb1 (1);
48 CB cb2 (2);
49 int arg1 = 1;
50 int arg2 = 2;
52 // Schedule timers to go off 3 & 4 seconds from now
53 // and then with an interval of 1.1 seconds.
54 const ACE_Time_Value curr_tv = ACE_OS::gettimeofday ();
55 ACE_Time_Value interval = ACE_Time_Value (1, 100000);
57 atimer.schedule (&cb1,
58 &arg1,
59 curr_tv + ACE_Time_Value (3L),
60 interval);
61 atimer.schedule (&cb2,
62 &arg2,
63 curr_tv + ACE_Time_Value (4L),
64 interval);
66 ACE_Thread_Manager::instance ()->wait (); // Wait forever.
68 return 0;
70 // Listing 3