3 //=============================================================================
5 * @file Thread_Timer_Queue_Custom_Handler_Test.h
7 * This code exercises the <ACE_Thread_Timer_Queue_Adapter> using
8 * an <ACE_Timer_Heap_T>. It also demonstrates using a custom handler for
11 * @author Carlos O'Ryan <coryan@cs.wustl.edu> and Sergio Flores-Gaitan <sergio@cs.wustl.edu> and Alon Diamant <diamant.alon@gmail.com>
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"
31 #include "Custom_Handler.h"
33 // These typedefs ensure that we use the minimal amount of locking
35 typedef ACE_Timer_Heap_T
<Custom_Handler
*,
36 Custom_Handler_Upcall
,
39 typedef ACE_Timer_Heap_Iterator_T
<Custom_Handler
*,
40 Custom_Handler_Upcall
,
43 typedef ACE_Thread_Timer_Queue_Adapter
<Timer_Heap
, Custom_Handler
*>
46 // Forward declaration.
47 class Thread_Timer_Queue_Custom_Handler_Test
;
50 * @class Custom_Handler_Input_Task
52 * @brief Read user actions on the Timer_Queue from stdin.
54 * This class reads user input from stdin; those commands permit
55 * the control of a Timer_Queue, which is dispatched by another
58 class Custom_Handler_Input_Task
: public ACE_Task_Base
61 typedef int (Custom_Handler_Input_Task::*ACTION
) (void *);
63 Custom_Handler_Input_Task (Thread_Timer_Queue
*queue
,
64 Thread_Timer_Queue_Custom_Handler_Test
&timer_queue_driver
);
66 /// This method runs the event loop in the new thread.
69 // = Some helper methods.
71 /// Add a new timer to expire in <seconds> more.
72 int add_timer (void *);
74 /// Cancel timer <id>.
75 int cancel_timer (void *);
77 /// List the current scheduled timers.
78 int list_timer (void *);
81 int shutdown_timer (void *);
83 /// Dump the state of the timer queue.
87 /// The timer queue implementation.
88 Thread_Timer_Queue
*queue_
;
90 /// How many micro seconds are in a second.
93 /// The thread timer queue test driver.
94 Thread_Timer_Queue_Custom_Handler_Test
&driver_
;
98 * @class Thread_Timer_Queue_Custom_Handler_Test
100 * @brief Implements an example application that exercises
101 * <Thread_Timer_Queue> timer queue.
103 * This class implements a simple test driver for the
104 * <Thread_Timer_Queue>. The <display_menu> hook method is
105 * called from the base class to print a menu specific to the
106 * thread implementation of the timer queue.
108 class ACE_Svc_Export Thread_Timer_Queue_Custom_Handler_Test
: public Timer_Queue_Test_Driver
<Thread_Timer_Queue
, Custom_Handler_Input_Task
, Custom_Handler_Input_Task::ACTION
>
111 Thread_Timer_Queue_Custom_Handler_Test ();
112 ~Thread_Timer_Queue_Custom_Handler_Test ();
114 virtual int display_menu ();
116 virtual int run_test ();
119 /// Subclassed from ACE_Task.
120 Custom_Handler_Input_Task input_task_
;
123 #endif /* _THREAD_TIMER_QUEUE_TEST_H_ */