4 //=============================================================================
8 * This code builds an abstraction to factor out common code for
9 * the different implementations of the Timer_Queue.
11 * @author Sergio Flores-Gaitan <sergio@cs.wustl.edu>
13 //=============================================================================
21 #if !defined (ACE_LACKS_PRAGMA_ONCE)
23 #endif /* ACE_LACKS_PRAGMA_ONCE */
25 #include "ace/Timer_Heap_T.h"
26 #include "ace/Timer_Queue_Adapters.h"
31 * @brief Defines an abstract class that allows us to invoke commands
32 * without knowing anything about the implementation. This class
33 * is used in the <Timer_Queue_Test_Driver> to invoke operations
36 * This class declares an interface to execute operations,
37 * binding a RECEIVER object with an ACTION. The RECEIVER knows
38 * how to implement the operation. A class can invoke operations
39 * without knowing anything about it, or how it was implemented.
41 template <class RECEIVER
, class ACTION
>
45 /// Sets the <receiver_> of the Command to recvr, and the
46 /// <action_> of the Command to <action>.
47 Command (RECEIVER
&recvr
, ACTION action
);
51 /// Invokes the method <action_> from the object <receiver_>.
52 virtual int execute (void *arg
);
55 /// object where the method resides.
58 /// method that is going to be invoked.
63 * @class Timer_Queue_Test_Driver
65 * @brief Defines a class that provides a simmple implementation for
66 * a test driver for timer queues.
68 * This is the place where the common code to test the different
69 * implementations of the timer queue resides. This class has
70 * the logic for the parse_commands() method, the run_test(),
71 * read_input() and the get_next_request(). Subclasses can
72 * override these methods if there is some logic that is specific
73 * to that implementation.
75 template <class TQ
, class RECEIVER
, class ACTION
>
76 class Timer_Queue_Test_Driver
79 /// Default destructor
80 virtual ~Timer_Queue_Test_Driver ();
82 /// Breaks up the input string buffer into pieces and executes
83 /// the appropriate method to handle that operation.
84 virtual int parse_commands (const char *buf
);
87 * This is the main entry point to the test driver. The user
88 * of the class should normally invoke this method.
89 * Returns 0 when successful, or 0 otherwise.
91 virtual int run_test ();
93 /// This internal method gets the next request from the user.
94 /// Returns -1 when user wants to exit. Returns 0 otherwise.
95 virtual int get_next_request ();
98 * Reads input from the user into the buffer <buf> with a maximum
99 * of <bufsiz> bytes. Returns the amount of bytes actually read
100 * Otherwise, a -1 is returned and errno is set to indicate the error.
102 virtual ssize_t
read_input (char *buf
, size_t bufsiz
);
104 // = Template Methods.
106 /// Prints the user interface for the driver to STDOUT.
107 virtual int display_menu () = 0;
109 /// Initializes values and operations for the driver.
110 virtual int init () = 0;
116 // = Set of <Command>s to be executed.
118 /// schedule timer command
119 Command
<RECEIVER
, ACTION
> *schedule_cmd_
;
121 /// cancel timer command.
122 Command
<RECEIVER
, ACTION
> *cancel_cmd_
;
124 /// list timers command.
125 Command
<RECEIVER
, ACTION
> *list_cmd_
;
127 /// shutdown the driver.
128 Command
<RECEIVER
, ACTION
> *shutdown_cmd_
;
131 #include "Driver.cpp"
133 #endif /* _DRIVER_H_ */