Merge pull request #2309 from mitza-oci/warnings
[ACE_TAO.git] / ACE / examples / Timer_Queue / Thread_Timer_Queue_Test.h
blobabdabe082a27cb06e2f7eb3d3afa7e63946f6e39
1 /* -*- C++ -*- */
4 //=============================================================================
5 /**
6 * @file Thread_Timer_Queue_Test.h
8 * This code exercises the <ACE_Thread_Timer_Queue_Adapter> using
9 * an <ACE_Timer_Heap_T>.
11 * @author Carlos O'Ryan <coryan@cs.wustl.edu> and Sergio Flores-Gaitan <sergio@cs.wustl.edu>
13 //=============================================================================
16 #ifndef _THREAD_TIMER_QUEUE_TEST_H_
17 #define _THREAD_TIMER_QUEUE_TEST_H_
19 #include "ace/Task.h"
21 #if !defined (ACE_LACKS_PRAGMA_ONCE)
22 # pragma once
23 #endif /* ACE_LACKS_PRAGMA_ONCE */
25 #include "ace/Null_Mutex.h"
26 #include "ace/Timer_Heap_T.h"
27 #include "ace/Timer_Queue_Adapters.h"
28 #include "ace/svc_export.h"
29 #include "ace/Condition_Recursive_Thread_Mutex.h"
30 #include "ace/Event_Handler_Handle_Timeout_Upcall.h"
31 #include "Driver.h"
33 // These typedefs ensure that we use the minimal amount of locking
34 // necessary.
35 typedef ACE_Event_Handler_Handle_Timeout_Upcall
36 Upcall;
37 typedef ACE_Timer_Heap_T<ACE_Event_Handler *,
38 Upcall,
39 ACE_Null_Mutex>
40 Timer_Heap;
41 typedef ACE_Timer_Heap_Iterator_T<ACE_Event_Handler *,
42 Upcall,
43 ACE_Null_Mutex>
44 Timer_Heap_Iterator;
45 typedef ACE_Thread_Timer_Queue_Adapter<Timer_Heap>
46 Thread_Timer_Queue;
48 // Forward declaration.
49 class Thread_Timer_Queue_Test_Driver;
51 /**
52 * @class Input_Task
54 * @brief Read user actions on the Timer_Queue from stdin.
56 * This class reads user input from stdin; those commands permit
57 * the control of a Timer_Queue, which is dispatched by another
58 * thread.
60 class Input_Task : public ACE_Task_Base
62 public:
63 typedef int (Input_Task::*ACTION) (void *);
65 Input_Task (Thread_Timer_Queue *queue,
66 Thread_Timer_Queue_Test_Driver &timer_queue_driver);
68 /// This method runs the event loop in the new thread.
69 virtual int svc ();
71 // = Some helper methods.
73 /// Add a new timer to expire in <seconds> more.
74 int add_timer (void *);
76 /// Cancel timer <id>.
77 int cancel_timer (void *);
79 /// List the current scheduled timers.
80 int list_timer (void *);
82 /// Shutdown task.
83 int shutdown_timer (void *);
85 /// Dump the state of the timer queue.
86 void dump ();
88 private:
89 /// The timer queue implementation.
90 Thread_Timer_Queue *queue_;
92 /// How many micro seconds are in a second.
93 const int usecs_;
95 /// The thread timer queue test driver.
96 Thread_Timer_Queue_Test_Driver &driver_;
99 /**
100 * @class Thread_Timer_Queue_Test_Driver
102 * @brief Implements an example application that exercises
103 * <Thread_Timer_Queue> timer queue.
105 * This class implements a simple test driver for the
106 * <Thread_Timer_Queue>. The <display_menu> hook method is
107 * called from the base class to print a menu specific to the
108 * thread implementation of the timer queue.
110 class ACE_Svc_Export Thread_Timer_Queue_Test_Driver : public Timer_Queue_Test_Driver <Thread_Timer_Queue, Input_Task, Input_Task::ACTION>
112 public:
113 Thread_Timer_Queue_Test_Driver ();
114 ~Thread_Timer_Queue_Test_Driver ();
116 virtual int display_menu ();
117 virtual int init ();
118 virtual int run_test ();
120 private:
121 /// Subclassed from ACE_Task.
122 Input_Task input_task_;
126 * @class Handler
128 * @brief Event handler for the timer queue timeout events.
130 * The <handle_timeout> hook method prints out the current time,
131 * prints the time when this timer expired and deletes "this".
133 class Handler : public ACE_Event_Handler
135 public:
136 Handler (const ACE_Time_Value &expiration_time);
137 ~Handler ();
139 /// Store an "id" for the Handler, which is only use to print better
140 /// messages.
141 void set_id (int id);
143 /// Call back hook.
144 virtual int handle_timeout (const ACE_Time_Value &current_time,
145 const void *arg);
147 private:
148 /// Store the expected time of expiration, it is used to print a nice
149 /// message saying how much delay was at the actual expiration time.
150 ACE_Time_Value expires_;
152 /// Store an "id" for the Handler, which is only use to print better
153 /// messages.
154 int id_;
157 #endif /* _THREAD_TIMER_QUEUE_TEST_H_ */