4 //=============================================================================
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_
21 #if !defined (ACE_LACKS_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"
33 // These typedefs ensure that we use the minimal amount of locking
35 typedef ACE_Event_Handler_Handle_Timeout_Upcall
37 typedef ACE_Timer_Heap_T
<ACE_Event_Handler
*,
41 typedef ACE_Timer_Heap_Iterator_T
<ACE_Event_Handler
*,
45 typedef ACE_Thread_Timer_Queue_Adapter
<Timer_Heap
>
48 // Forward declaration.
49 class Thread_Timer_Queue_Test_Driver
;
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
60 class Input_Task
: public ACE_Task_Base
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.
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 *);
83 int shutdown_timer (void *);
85 /// Dump the state of the timer queue.
89 /// The timer queue implementation.
90 Thread_Timer_Queue
*queue_
;
92 /// How many micro seconds are in a second.
95 /// The thread timer queue test driver.
96 Thread_Timer_Queue_Test_Driver
&driver_
;
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
>
113 Thread_Timer_Queue_Test_Driver ();
114 ~Thread_Timer_Queue_Test_Driver ();
116 virtual int display_menu ();
118 virtual int run_test ();
121 /// Subclassed from ACE_Task.
122 Input_Task input_task_
;
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
136 Handler (const ACE_Time_Value
&expiration_time
);
139 /// Store an "id" for the Handler, which is only use to print better
141 void set_id (int id
);
144 virtual int handle_timeout (const ACE_Time_Value
¤t_time
,
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
157 #endif /* _THREAD_TIMER_QUEUE_TEST_H_ */