4 //=============================================================================
6 * @file Reactor_Timer_Queue_Test.h
8 * This code is an implementation of a test driver for a reactor based
11 * @author Nanbor Wang <nw1@cs.wustl.edu> and Sergio Flores-Gaitan <sergio@cs.wustl.edu>
13 //=============================================================================
16 #ifndef _REACTOR_TIMER_QUEUE_TEST_H_
17 #define _REACTOR_TIMER_QUEUE_TEST_H_
21 #if !defined (ACE_LACKS_PRAGMA_ONCE)
23 #endif /* ACE_LACKS_PRAGMA_ONCE */
25 /// @@todo: Not sure why this needs to be included. But am sure that,
26 /// there is some circular dependency setup. Needs to be
27 /// fixed. Atleast on g++
28 #include "ace/Timer_Queue.h"
29 #include "ace/Timer_Heap.h"
30 #include "ace/svc_export.h"
32 class Reactor_Timer_Queue_Test_Driver
;
35 * @class Input_Handler
37 * @brief Implements the handler to be called for input events. Also has
38 * the logic to handle the different timer queue operations (i.e.,
39 * schedule, cancel, list, shutdown).
41 * This class handles the reading of user input from stdin. Also
42 * has the logic to handle the commands that are to be invoked in
43 * response to the user input.
45 class Input_Handler
: public ACE_Event_Handler
48 typedef int (Input_Handler::*ACTION
) (void *);
50 /// Sets <done_> flag to 0, <driver_> to <timer_queue_driver> and
51 /// timer queue <tq_> to <tq>
52 Input_Handler (ACE_Timer_Queue
*tq
,
53 Reactor_Timer_Queue_Test_Driver
&timer_queue_driver
);
55 /// Hook method for the <ACE_Reactor> to call whenever there is input
57 int handle_input (ACE_HANDLE
);
60 * returns the value for <done_> that indicates whether we are
61 * exiting the program.A value of 0 indicates that we are NOT done,
66 // = Hook methods to be called from <Reactor_Timer_Queue_Test_Driver>
68 /// Schedule a timer. The (void *) will be mapped to the delay
69 /// parameter for the timer queue schedule method.
70 int schedule_timer (void *argument
);
72 /// Cancel a timer. The (void *) will be mapped to the ID of the
73 /// timer being cancelled.
74 int cancel_timer (void *argument
);
76 /// Dump the timers in the queue. The argument is ignored.
77 int list_timer (void *argument
);
79 /// Processes the request to exit the timer queue application.
80 /// argument is ignored.
81 int shutdown_timer (void *argument
);
84 /// Keep a pointer to the timer queue we are using so we can traverse
88 /// Flag used to close down program.
91 /// Test driver. Used to call hook methods that are common code for
93 Reactor_Timer_Queue_Test_Driver
&driver_
;
97 * @class Reactor_Timer_Queue_Test_Driver
99 * @brief Implements a test driver for a reactive timer queue using
102 * This class implements the logic to test the reactor
103 * implementation of timer queue, using an <ACE_Timer_Heap>.
105 class ACE_Svc_Export Reactor_Timer_Queue_Test_Driver
: public Timer_Queue_Test_Driver
<ACE_Timer_Heap
, Input_Handler
, Input_Handler::ACTION
>
109 * Sets the input handler <thandler_> with <timer_queue_> from the
110 * <Timer_Queue_Test_Driver> class and a reference to "this", so the
111 * input handler can call hook methods from the driver. Such
112 * methods are the common factored out code from other
113 * implementations of timer queues.
115 Reactor_Timer_Queue_Test_Driver ();
117 /// Default destructor
118 virtual ~Reactor_Timer_Queue_Test_Driver ();
120 /// Prints the menu of options.
121 virtual int display_menu ();
124 * Sets the timer queue that the REACTOR will use; registers the
125 * stdin input handler with the REACTOR and sets the <Command>s that
126 * the <Timer_Queue_Test_Driver> will execute().
130 /// Main entry point to the test driver implementation.
131 virtual int run_test ();
134 /// This is the stdin handler.
135 Input_Handler thandler_
;
139 * @class Reactor_Timer_Handler
141 * @brief Target of the reactive timeout operation.
143 class Reactor_Timer_Handler
: public ACE_Event_Handler
146 /// Hook method that is called by the reactor when a timer expires.
147 /// It prints the timer ID and the time it expired.
148 virtual int handle_timeout (const ACE_Time_Value
&tv
,
151 /// Sets the timer id for this handler <tid_> to <tid>
152 void set_timer_id (long tid
);
159 #endif /* _REACTOR_TIMER_QUEUE_TEST_H_ */