diff options
author | sergio <sergio@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 1997-10-19 01:00:12 +0000 |
---|---|---|
committer | sergio <sergio@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 1997-10-19 01:00:12 +0000 |
commit | 70edff0bbb1faaefc7154efb7ce02cf13807b4c5 (patch) | |
tree | 226d09f921c3e747bf3933ddbc1d823a9f5c3ba4 /examples/Timer_Queue | |
parent | 8441bdfcc4c132eb3ffb0abb4a71303516f0cb96 (diff) | |
download | ATCD-70edff0bbb1faaefc7154efb7ce02cf13807b4c5.tar.gz |
*** empty log message ***
Diffstat (limited to 'examples/Timer_Queue')
-rw-r--r-- | examples/Timer_Queue/Async_Timer_Queue_Test.cpp | 164 | ||||
-rw-r--r-- | examples/Timer_Queue/Async_Timer_Queue_Test.h | 70 | ||||
-rw-r--r-- | examples/Timer_Queue/Driver.cpp | 115 | ||||
-rw-r--r-- | examples/Timer_Queue/Driver.h | 69 | ||||
-rw-r--r-- | examples/Timer_Queue/Makefile | 23 | ||||
-rw-r--r-- | examples/Timer_Queue/Reactor_Timer_Queue_Test.cpp | 272 | ||||
-rw-r--r-- | examples/Timer_Queue/Reactor_Timer_Queue_Test.h | 68 | ||||
-rw-r--r-- | examples/Timer_Queue/Thread_Timer_Queue_Test.cpp | 336 | ||||
-rw-r--r-- | examples/Timer_Queue/Thread_Timer_Queue_Test.h | 146 | ||||
-rw-r--r-- | examples/Timer_Queue/main_async.cpp | 42 | ||||
-rw-r--r-- | examples/Timer_Queue/main_reactor.cpp | 39 | ||||
-rw-r--r-- | examples/Timer_Queue/main_thread.cpp | 38 |
12 files changed, 930 insertions, 452 deletions
diff --git a/examples/Timer_Queue/Async_Timer_Queue_Test.cpp b/examples/Timer_Queue/Async_Timer_Queue_Test.cpp index c49978ba698..af1deaf0c90 100644 --- a/examples/Timer_Queue/Async_Timer_Queue_Test.cpp +++ b/examples/Timer_Queue/Async_Timer_Queue_Test.cpp @@ -21,15 +21,7 @@ #include "ace/Timer_Heap.h" #include "ace/Timer_Queue_Adapters.h" -class Timer_Handler : public ACE_Event_Handler - // = TITLE - // Target of the asynchronous timeout operation. -{ -public: - virtual int handle_timeout (const ACE_Time_Value &tv, - const void *arg); - // Callback hook invoked by the <Timer_Queue>. -}; +#include "Async_Timer_Queue_Test.h" int Timer_Handler::handle_timeout (const ACE_Time_Value &tv, @@ -49,39 +41,6 @@ Timer_Handler::handle_timeout (const ACE_Time_Value &tv, return 0; } -class Async_Timer_Queue - // = TITLE - // Asynchronous Timer Queue Singleton. - // - // = DESCRIPTION - // We use this class to avoid global variables and to - // consolidate all the Timer Queue processing in one central - // place. -{ -public: - static Async_Timer_Queue *instance (void); - // Singleton access point. - - void schedule (u_int microsecs); - // Schedule a timer to expire <microsecs> in the future. - - void cancel (long timer_id); - // Cancel a timer with <timer_id>. - - void dump (void); - // Dump the contents of the queue. - -private: - Async_Timer_Queue (ACE_Sig_Set *); - // Private constructor enforces the Singleton. - - static Async_Timer_Queue *instance_; - // Pointer to the timer queue. - - ACE_Async_Timer_Queue_Adapter<ACE_Timer_Heap> tq_; - // The adapter is instantiated by an <ACE_Timer_Heap>. -}; - // Initialize the Singleton pointer. Async_Timer_Queue *Async_Timer_Queue::instance_ = 0; @@ -167,34 +126,40 @@ Async_Timer_Queue::cancel (long timer_id) delete (ACE_Event_Handler *) act; } -// Command-line API. - -static int -parse_commands (const char *buf) +int +Async_Timer_Queue::schedule_timer (void *argument) { - u_int choice; - long value; + u_long useconds = *(int *)argument; - // @@ Should make sure to use signal-safe logic here... + // Schedule a timer. + Async_Timer_Queue::instance ()->schedule (useconds); - if (sscanf (buf, "%u %ld", &choice, &value) != 2) - ACE_ERROR_RETURN ((LM_ERROR, "invalid input %s", buf), -1); + return 0; +} - switch (choice) - { - case 1: // Schedule a timer. - Async_Timer_Queue::instance ()->schedule (value); +int +Async_Timer_Queue::cancel_timer (void *argument) +{ + u_long id = *(int *)argument; + + // Cancel a timer. + Async_Timer_Queue::instance ()->cancel (id); - break; - /* NOTREACHED */ + return 0; +} - case 2: // Cancel a timer. - Async_Timer_Queue::instance ()->cancel (value); - break; - /* NOTREACHED */ - } +int +Async_Timer_Queue::list_timer (void *argument) +{ + // Display an error message. + ACE_ERROR_RETURN ((LM_ERROR, "invalid input\n"), 0); +} - return 0; +int +Async_Timer_Queue::shutdown_timer (void *argument) +{ + // Display an error message. + ACE_ERROR_RETURN ((LM_ERROR, "invalid input\n"), 0); } // Handler for the SIGINT and SIGQUIT signals. @@ -243,41 +208,56 @@ register_signal_handlers (void) ACE_UNUSED_ARG (sigint); } -// The menu of options provided to the user. - -static char menu[] = -"****\n" -"1) schedule timer <usecs> \n" -"2) cancel timer <timer_id>\n" -"^C list timers\n" -"^\\ exit program\n" -"please enter your choice: "; - -int -main (int, char *[]) -{ - register_signal_handlers (); - - // Run until the user types ^\. - - for (;;) +Async_Timer_Queue_Test_Driver::Async_Timer_Queue_Test_Driver (void) { - ACE_DEBUG ((LM_DEBUG, "%s", menu)); + timer_queue_ = Async_Timer_Queue::instance (); + } - char buf[BUFSIZ]; +int +Async_Timer_Queue_Test_Driver::display_menu (void) +{ + // The menu of options provided to the user. + static char menu[] = + "****\n" + "1) schedule timer <usecs> \n" + "2) cancel timer <timer_id>\n" + "^C list timers\n" + "^\\ exit program\n"; + + ACE_DEBUG ((LM_DEBUG, "%s", menu)); + + return 0; +} - // Wait for user to type commands. This call is automatically - // restarted when SIGINT or SIGALRM signals occur. - if (ACE_OS::read (ACE_STDIN, buf, sizeof buf) <= 0) - break; +int +Async_Timer_Queue_Test_Driver::init (void) +{ + // initialize commands with their corresponding input_task methods. + ACE_NEW_RETURN (schedule_cmd_, + Command<Async_Timer_Queue> (*Async_Timer_Queue::instance (), + Async_Timer_Queue::instance ()->schedule_timer), + -1); + + ACE_NEW_RETURN (cancel_cmd_, + Command<Async_Timer_Queue> (*Async_Timer_Queue::instance (), + Async_Timer_Queue::instance ()->cancel_timer), + -1); + + ACE_NEW_RETURN (list_cmd_, + Command<Async_Timer_Queue> (*Async_Timer_Queue::instance (), + Async_Timer_Queue::instance ()->list_timer), + -1); + + ACE_NEW_RETURN (shutdown_cmd_, + Command<Async_Timer_Queue> (*Async_Timer_Queue::instance (), + Async_Timer_Queue::instance ()->shutdown_timer), + -1); - // Run the command. - parse_commands (buf); - } + register_signal_handlers (); return 0; -} - +} + #if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION) template class ACE_Async_Timer_Queue_Adapter<ACE_Timer_Heap>; #elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA) diff --git a/examples/Timer_Queue/Async_Timer_Queue_Test.h b/examples/Timer_Queue/Async_Timer_Queue_Test.h new file mode 100644 index 00000000000..b4805403b0e --- /dev/null +++ b/examples/Timer_Queue/Async_Timer_Queue_Test.h @@ -0,0 +1,70 @@ +#if !defined (_ASYNC_TIMER_QUEUE_TEST_H_) +#define _ASYNC_TIMER_QUEUE_TEST_H_ + +#include "ace/Signal.h" +#include "ace/Timer_Heap.h" +#include "ace/Timer_Queue_Adapters.h" + +#include "Driver.h" + +class Timer_Handler : public ACE_Event_Handler + // = TITLE + // Target of the asynchronous timeout operation. +{ +public: + virtual int handle_timeout (const ACE_Time_Value &tv, + const void *arg); + // Callback hook invoked by the <Timer_Queue>. +}; + +class Async_Timer_Queue + // = TITLE + // Asynchronous Timer Queue Singleton. + // + // = DESCRIPTION + // We use this class to avoid global variables and to + // consolidate all the Timer Queue processing in one central + // place. +{ +public: + static Async_Timer_Queue *instance (void); + // Singleton access point. + + void schedule (u_int microsecs); + // Schedule a timer to expire <microsecs> in the future. + + void cancel (long timer_id); + // Cancel a timer with <timer_id>. + + void dump (void); + // Dump the contents of the queue. + + int schedule_timer (void *argument); + int cancel_timer (void *argument); + int list_timer (void *argument); + int shutdown_timer (void *argument); + +private: + Async_Timer_Queue (ACE_Sig_Set *); + // Private constructor enforces the Singleton. + + static Async_Timer_Queue *instance_; + // Pointer to the timer queue. + + ACE_Async_Timer_Queue_Adapter<ACE_Timer_Heap> tq_; + // The adapter is instantiated by an <ACE_Timer_Heap>. +}; + +class Async_Timer_Queue_Test_Driver : public Timer_Queue_Test_Driver <Async_Timer_Queue *, Async_Timer_Queue> +// = TITLE +// +// = DESCRIPTION +{ +public: + Async_Timer_Queue_Test_Driver (void); + + virtual int display_menu (void); + virtual int init (void); +}; + +#endif /* _ASYNC_TIMER_QUEUE_TEST_H_ */ diff --git a/examples/Timer_Queue/Driver.cpp b/examples/Timer_Queue/Driver.cpp new file mode 100644 index 00000000000..2d828caf579 --- /dev/null +++ b/examples/Timer_Queue/Driver.cpp @@ -0,0 +1,115 @@ +// ============================================================================ +// = LIBRARY +// examples +// +// = FILENAME +// Driver.cpp +// +// = DESCRIPTION +// This code builds an abstraction to factor out common code for +// the different implementations of the Timer_Queue. +// +// = AUTHOR +// Douglas Schmidt <schmidt@cs.wustl.edu> && +// Sergio Flores-Gaitan <sergio@cs.wustl.edu> +// +// ============================================================================ + +#include "ace/Auto_Ptr.h" +#include "Driver.h" + +template <class TQ, class Receiver> int +Timer_Queue_Test_Driver<TQ, Receiver>::get_next_request (void) +{ + this->display_menu (); + + char buf[BUFSIZ]; + + ACE_OS::printf ("please enter your choice: "); + ACE_OS::fflush (stdout); + + if (this->read_input (buf, sizeof buf) <= 0) + return -1; + + // Run the command. + return this->parse_commands (buf); +} + +template <class TQ, class Receiver> int +Timer_Queue_Test_Driver<TQ, Receiver>::run_test (void) +{ + this->init (); + + for (;;) + if (this->get_next_request () == -1) + return -1; + + return 0; +} + +template <class TQ, class Receiver> ssize_t +Timer_Queue_Test_Driver<TQ, Receiver>::read_input (char *buf, size_t bufsiz) +{ + ACE_OS::memset (buf, 0, bufsiz); + + // Wait for user to type commands. This call is automatically + // restarted when SIGINT or SIGALRM signals occur. + return ACE_OS::read (ACE_STDIN, buf, bufsiz); +} + +template <class TQ, class Receiver> int +Timer_Queue_Test_Driver<TQ, Receiver>::parse_commands (const char *buf) +{ + int option; + + if (::sscanf (buf, "%d", &option) <= 0) + // If there was an error reading the option simply try on the next line. + return 0; + + switch (option) + { + case 1: // Schedule a new timer. + { + u_long useconds; + // We just reread the option, this simplies parsing (since + // sscanf can do it for us.) + if (::sscanf (buf, "%d %lu", &option, &useconds) < 2) + return 0; + + if (schedule_cmd_->execute ((void *) &useconds) == -1) + ACE_ERROR_RETURN ((LM_ERROR, "%t %p\n", "new timer failed"), -1); + } + break; // Cancel an existing timer. + /* NOTREACHED */ + case 2: + { + u_long id; + // We just reread the option, this simplies parsing (since + // sscanf can do it for us.) + if (::sscanf (buf, "%d %lu", &option, &id) < 2) + return 0; + + if (cancel_cmd_->execute ((void *) &id) == -1) + ACE_DEBUG ((LM_DEBUG, "Timer #%d is not valid\n", id)); + + } + break; + /* NOTREACHED */ + + case 3: // Dump the existing timers. + return list_cmd_->execute (NULL); + /* NOTREACHED */ + + case 4: // Exit the program. + return shutdown_cmd_->execute (NULL); + /* NOTREACHED */ + + default: + // Display an error message. + ACE_ERROR_RETURN ((LM_ERROR, "invalid input %s\n", buf), 0); + break; + /* NOTREACHED */ + } + return 0; +} + diff --git a/examples/Timer_Queue/Driver.h b/examples/Timer_Queue/Driver.h new file mode 100644 index 00000000000..f06c038149d --- /dev/null +++ b/examples/Timer_Queue/Driver.h @@ -0,0 +1,69 @@ +#if !defined (_DRIVER_H_) +#define _DRIVER_H_ + +#include "ace/Task.h" +#include "ace/Timer_Heap_T.h" +#include "ace/Timer_Queue_Adapters.h" + +typedef ACE_Event_Handler_Handle_Timeout_Upcall<ACE_Null_Mutex> + Upcall; +typedef ACE_Timer_Heap_T<ACE_Event_Handler *, + ACE_Event_Handler_Handle_Timeout_Upcall<ACE_Null_Mutex>, + ACE_Null_Mutex> + Timer_Heap; +typedef ACE_Timer_Heap_Iterator_T<ACE_Event_Handler *, + ACE_Event_Handler_Handle_Timeout_Upcall<ACE_Null_Mutex>, + ACE_Null_Mutex> + Timer_Heap_Iterator; +typedef ACE_Thread_Timer_Queue_Adapter<Timer_Heap> + Thread_Timer_Queue; + +template <class Receiver> +class Command +{ +public: + typedef int (Receiver::*Action) (void *); + + Command (Receiver &recvr, Action action) + : receiver_(recvr), + action_(action) + {} + + virtual int execute (void *arg) + { + return (receiver_.*action_) (arg); + } +private: + Receiver &receiver_; + Action action_; +}; + +template <class TQ, class Receiver> +class Timer_Queue_Test_Driver +{ +public: + virtual int parse_commands (const char *buf); + + virtual int run_test (void); + + // = Template Methods. + + virtual int display_menu (void)=0; + + virtual int init (void)=0; + + virtual int get_next_request (void); + + virtual ssize_t read_input (char *buf, size_t bufsiz); + +protected: + TQ timer_queue_; + + Command<Receiver> *schedule_cmd_; + Command<Receiver> *cancel_cmd_; + Command<Receiver> *list_cmd_; + Command<Receiver> *shutdown_cmd_; + +}; + +#endif diff --git a/examples/Timer_Queue/Makefile b/examples/Timer_Queue/Makefile index 11255f0752c..58c6b5fc69f 100644 --- a/examples/Timer_Queue/Makefile +++ b/examples/Timer_Queue/Makefile @@ -8,13 +8,22 @@ INFO = README -BIN = Async_Timer_Queue_Test \ - Reactor_Timer_Queue_Test \ - Thread_Timer_Queue_Test - -SRC = $(addsuffix .cpp,$(BIN)) -OBJ = $(SRC:%.cpp=$(VDIR)%.o) - +BIN = main_async +FILES = Async_Timer_Queue_Test +LSRC = $(addsuffix .cpp,$(FILES)) +LOBJ = $(addsuffix .o,$(FILES)) +BUILD = $(VBIN) + +BIN = main_reactor +FILES = Reactor_Timer_Queue_Test +LSRC = $(addsuffix .cpp,$(FILES)) +LOBJ = $(addsuffix .o,$(FILES)) +BUILD = $(VBIN) + +BIN = main_thread +FILES = Thread_Timer_Queue_Test +LSRC = $(addsuffix .cpp,$(FILES)) +LOBJ = $(addsuffix .o,$(FILES)) BUILD = $(VBIN) #---------------------------------------------------------------------------- diff --git a/examples/Timer_Queue/Reactor_Timer_Queue_Test.cpp b/examples/Timer_Queue/Reactor_Timer_Queue_Test.cpp index 64a6180fed4..02895f9944c 100644 --- a/examples/Timer_Queue/Reactor_Timer_Queue_Test.cpp +++ b/examples/Timer_Queue/Reactor_Timer_Queue_Test.cpp @@ -20,149 +20,177 @@ #include "ace/Reactor.h" #include "ace/Timer_Heap.h" +#include "Driver.h" +#include "Reactor_Timer_Queue_Test.h" + static const int NO_OF_IO_HANDLERS = 5; #define REACTOR ACE_Reactor::instance () -static void usage_prompt (void) +Timer_Handler::Timer_Handler (void) +{} + +void +Timer_Handler::set_timer_id (long tid) +{ + this->tid_ = tid; +} + +int +Timer_Handler::handle_timeout (const ACE_Time_Value &tv, + const void *) +{ + ACE_Time_Value txv = ACE_OS::gettimeofday (); + ACE_DEBUG ((LM_DEBUG, "\nTimer #%d fired at %d.%06d (%T)!\n", + this->tid_, txv.sec (), txv.usec ())); + delete this; + + return 0; +} + +Input_Handler::Input_Handler (ACE_Timer_Queue *tq, Reactor_Timer_Queue_Test_Driver &timer_queue_driver) + : done_ (0), + driver_ (timer_queue_driver) { - ACE_DEBUG ((LM_DEBUG, "\n*****\n" - "1) Schedule timer <usec>\n" - "2) Cancel timer <id>\n" - "3) List all timers\n" - "4) Shutdown program\n" - "Enter selection:")); + this->tq_ = tq; } -class Timer_Handler : public ACE_Event_Handler +int +Input_Handler::done (void) { -public: - virtual int handle_timeout (const ACE_Time_Value &, - const void *) - { - ACE_Time_Value txv = ACE_OS::gettimeofday (); - ACE_DEBUG ((LM_DEBUG, "\nTimer #%d fired at %d.%06d (%T)!\n", - this->tid_, txv.sec (), txv.usec ())); - delete this; - ::usage_prompt (); - return 0; - } - - void set_timer_id (long tid) - { - this->tid_ = tid; - } + return this->done_; +} -private: - long tid_; -}; +int +Input_Handler::schedule_timer (void *argument) +{ + int delay = *(int *) argument; + Timer_Handler *th; + long tid; + + th = new Timer_Handler; + if (th != 0) + { + tid = this->reactor ()->schedule_timer (th, + 0, + ACE_Time_Value (0, delay)); + if (tid == -1) + ACE_DEBUG ((LM_DEBUG, "Unable to schedule timer\n")); + else + { + ACE_DEBUG ((LM_DEBUG, + "Timer #%d schedule to fire after %d usec from now.\n", + tid, + delay)); + th->set_timer_id (tid); + } + } + else + ACE_ERROR_RETURN ((LM_ERROR, "not enough memory?\n"), -1); + + return tid; +} + +int +Input_Handler::cancel_timer (void *argument) +{ + int id = *(int *) argument; + return this->reactor ()->cancel_timer (id); +} -class Input_Handler : public ACE_Event_Handler +int +Input_Handler::shutdown_timer (void *argument) +{ + this->done_ = 1; + ACE_DEBUG ((LM_DEBUG, "Shutting down event loop\n")); + return -1; +} + +int +Input_Handler::list_timer (void *argument) { -public: - Input_Handler (ACE_Timer_Queue *tq) - : done_ (0) - { - this->tq_ = tq; - } - - int done (void) - { - return this->done_; - } - - virtual int handle_input (ACE_HANDLE) - { - char buffer [MAXPATHLEN]; - int c = 0; - long tv = 0; - Timer_Handler *th; - - ssize_t n = ACE_OS::read (ACE_STDIN, buffer, sizeof buffer); - if (n == -1) - ACE_ERROR_RETURN ((LM_ERROR, "Huh?\n"), -1); - - sscanf (buffer, "%d %ld", &c, &tv); - switch (c) - { - case 1: // Schedule timer. - th = new Timer_Handler; - if (th != 0) - { - long tid = this->reactor ()->schedule_timer - (th, 0, ACE_Time_Value (0, tv)); - if (tid == -1) - ACE_DEBUG ((LM_DEBUG, "Unable to schedule timer\n")); - else - { - ACE_DEBUG ((LM_DEBUG, - "Timer #%d schedule to fire after %d usec from now.\n", - tid, tv)); - th->set_timer_id (tid); - } - } - else - ACE_ERROR_RETURN ((LM_ERROR, "not enought memeory?\n"), -1); - break; - case 2: // Cancel timer <id> - if (this->reactor ()->cancel_timer (tv) == 0) - ACE_DEBUG ((LM_DEBUG, "Timer #%d is not valid\n", tv)); - break; - case 3: // Dump all timer in queue. - { - ACE_Timer_Queue_Iterator &iter = this->tq_->iter (); - ACE_DEBUG ((LM_DEBUG, "\n\nTimers in queue:\n")); + ACE_Timer_Queue_Iterator &iter = this->tq_->iter (); + ACE_DEBUG ((LM_DEBUG, "\n\nTimers in queue:\n")); - for (; ! iter.isdone (); iter.next ()) - { - ACE_Timer_Node *tn = iter.item (); - ACE_DEBUG ((LM_DEBUG, "Timer #%d: %d.%06d\n", - tn->get_timer_id (), - tn->get_timer_value ().sec (), - tn->get_timer_value ().usec ())); - } - } - break; - case 4: // Shutdown - this->done_ = 1; - ACE_DEBUG ((LM_DEBUG, "Shutting down event loop\n")); - return -1; - default: // Huh? - ACE_DEBUG ((LM_DEBUG, "Got string (%d): %s\n", n, buffer)); - break; - } - ::usage_prompt (); - return 0; - } -private: - ACE_Timer_Queue *tq_; - // Keep a pointer to the timer queue we are using so we can - // traverse the queue. - - int done_; - // Flag used to close down program. -}; + for (; ! iter.isdone (); iter.next ()) + { + ACE_Timer_Node *tn = iter.item (); + ACE_DEBUG ((LM_DEBUG, "Timer #%d: %d.%06d\n", + tn->get_timer_id (), + tn->get_timer_value ().sec (), + tn->get_timer_value ().usec ())); + } -int -main (int, char *[]) + return 0; +} + +int +Input_Handler::handle_input (ACE_HANDLE) { - ACE_DEBUG ((LM_DEBUG, "TIMER TEST STARTED\n")); + return driver_.get_next_request (); +} - // pick a timer queue implementation - // which happens to be the one that ACE is using. - ACE_Timer_Heap private_queue; +Reactor_Timer_Queue_Test_Driver::Reactor_Timer_Queue_Test_Driver (void) + : thandler (&timer_queue_, *this) + { + } + +int +Reactor_Timer_Queue_Test_Driver::display_menu (void) +{ + static char menu[] = + "\n*****\n" + "1) Schedule timer <usec>\n" + "2) Cancel timer <id>\n" + "3) List all timers\n" + "4) Shutdown program\n" + "Enter selection:"; + + ACE_DEBUG ((LM_DEBUG, "%s", menu)); - REACTOR->set_timer_queue (&private_queue); + return 0; +} - // This is the stdin handler. - Input_Handler *thandler = new Input_Handler (&private_queue); +int +Reactor_Timer_Queue_Test_Driver::init (void) +{ + // initialize commands with their corresponding input_task methods. + ACE_NEW_RETURN (schedule_cmd_, + Command<Input_Handler> (thandler, + thandler.schedule_timer), + -1); + + ACE_NEW_RETURN (cancel_cmd_, + Command<Input_Handler> (thandler, + thandler.cancel_timer), + -1); + + ACE_NEW_RETURN (list_cmd_, + Command<Input_Handler> (thandler, + thandler.list_timer), + -1); + + ACE_NEW_RETURN (shutdown_cmd_, + Command<Input_Handler> (thandler, + thandler.shutdown_timer), + -1); + + REACTOR->set_timer_queue (&timer_queue_); - ACE::register_stdin_handler (thandler, REACTOR, + ACE::register_stdin_handler (&thandler, REACTOR, ACE_Thread_Manager::instance ()); - ::usage_prompt (); + this->display_menu (); +} + +int +Reactor_Timer_Queue_Test_Driver::run_test (void) +{ + ACE_DEBUG ((LM_DEBUG, "TIMER TEST STARTED\n")); + + this->init (); // Run until we say stop. - while (thandler->done () == 0) + while (thandler.done () == 0) REACTOR->handle_events (); ACE_DEBUG ((LM_DEBUG, "TIMER TEST ENDED\n")); diff --git a/examples/Timer_Queue/Reactor_Timer_Queue_Test.h b/examples/Timer_Queue/Reactor_Timer_Queue_Test.h new file mode 100644 index 00000000000..d3c3a8d828c --- /dev/null +++ b/examples/Timer_Queue/Reactor_Timer_Queue_Test.h @@ -0,0 +1,68 @@ +#if !defined (_REACTOR_TIMER_QUEUE_TEST_H_) +#define _REACTOR_TIMER_QUEUE_TEST_H_ + +#include "ace/Timer_Heap.h" +#include "Driver.h" + +class Reactor_Timer_Queue_Test_Driver; + +class Input_Handler : public ACE_Event_Handler +// @@ Please add comments. +{ +public: + Input_Handler (ACE_Timer_Queue *tq, Reactor_Timer_Queue_Test_Driver &timer_queue_driver); + int handle_input (ACE_HANDLE); + + int done (void); + int schedule_timer (void *argument); + int cancel_timer (void *argument); + int list_timer (void *argument); + int shutdown_timer (void *argument); + +private: + ACE_Timer_Queue *tq_; + // Keep a pointer to the timer queue we are using so we can + // traverse the queue. + + int done_; + // Flag used to close down program. + + Reactor_Timer_Queue_Test_Driver &driver_; +}; + +class Reactor_Timer_Queue_Test_Driver : public Timer_Queue_Test_Driver <ACE_Timer_Heap, Input_Handler> +// @@ Please add comments. +{ +public: + Reactor_Timer_Queue_Test_Driver (void); + + virtual int display_menu (void); + virtual int init (void); + virtual int run_test (void); + +private: + // pick a timer queue implementation + // which happens to be the one that ACE is using. + // ACE_Timer_Heap private_queue; + + // This is the stdin handler. + Input_Handler thandler; +}; + +class Timer_Handler : public ACE_Event_Handler +// @@ Please add comments. +{ +public: + // Timer_Handler (Reactor_Queue_Test_Driver &driver); + Timer_Handler (void); + + virtual int handle_timeout (const ACE_Time_Value &tv, + const void *); + + void set_timer_id (long tid); + +private: + long tid_; +}; + +#endif /* _REACTOR_TIMER_QUEUE_TEST_H_ */ diff --git a/examples/Timer_Queue/Thread_Timer_Queue_Test.cpp b/examples/Timer_Queue/Thread_Timer_Queue_Test.cpp index a0441dce602..149ae7ad1a3 100644 --- a/examples/Timer_Queue/Thread_Timer_Queue_Test.cpp +++ b/examples/Timer_Queue/Thread_Timer_Queue_Test.cpp @@ -4,110 +4,24 @@ // // = LIBRARY // examples -// +// // = FILENAME // Thread_Timer_Queue_Test.cpp // // = DESCRIPTION -// This test exercises the <ACE_Thread_Timer_Queue_Adapter> +// This test exercises the <ACE_Thread_Timer_Queue_Adapter> // using an <ACE_Timer_Heap>. // // = AUTHORS // Carlos O'Ryan and Douglas C. Schmidt -// +// // ============================================================================ #include "ace/Task.h" #include "ace/Timer_Heap_T.h" #include "ace/Timer_Queue_Adapters.h" -// These typedefs ensure that we use the minimal amount of locking -// necessary. -typedef ACE_Event_Handler_Handle_Timeout_Upcall<ACE_Null_Mutex> - Upcall; -typedef ACE_Timer_Heap_T<ACE_Event_Handler *, - ACE_Event_Handler_Handle_Timeout_Upcall<ACE_Null_Mutex>, - ACE_Null_Mutex> - Timer_Heap; -typedef ACE_Timer_Heap_Iterator_T<ACE_Event_Handler *, - ACE_Event_Handler_Handle_Timeout_Upcall<ACE_Null_Mutex>, - ACE_Null_Mutex> - Timer_Heap_Iterator; -typedef ACE_Thread_Timer_Queue_Adapter<Timer_Heap> - Thread_Timer_Queue; - -class Handler : public ACE_Event_Handler - // = TITLE - // This class implements a simple Event_Handler, - // - // = DESCRIPTION - // The <handle_timeout> hook method justs printouts the current - // time, delete this and prints the delay on the twhen it is - // expired. -{ -public: - Handler (const ACE_Time_Value &expiration_time); - ~Handler (void); - - void set_id (int id); - // Store an "id" for the Handler, which is only use to print better - // messages. - - virtual int handle_timeout (const ACE_Time_Value ¤t_time, - const void *arg); - // Call back hook. - virtual int cancelled (void); - -private: - ACE_Time_Value expires_; - // Store the expected time of expiration, it is used to print a nice - // message saying how much delay was at the actual expiration time. - - int id_; - // Store an "id" for the Handler, which is only use to print better - // messages. -}; - -class Input_Task : public ACE_Task<ACE_SYNCH> - // = TITLE - // Read user actions on the Timer_Queue from stdin. - // - // = DESCRIPTION - // This class reads user input from stdin; those commands permit the - // control of a Timer_Queue, which is dispatched by another thread. -{ -public: - Input_Task (Thread_Timer_Queue* queue); - - virtual int svc (void); - // The method run on the new thread. - -private: - // = Some helper methods. - - void usage (void) const; - // Print a "Usage" message to the user. - - int add_timer (u_long seconds); - // Add a new timer to expire in <seconds> more. - - void cancel_timer (int id); - // Cancel timer <id>. - - int parse_commands (const char *buffer); - // Parse the commands in <buffer>, it is expected to be a line of - // input from the user. - - void dump (void); - // Dump the state of the timer queue. - -private: - Thread_Timer_Queue *queue_; - // The timer queue implementation. - - const int usecs_; - // How many micro seconds are in a second. -}; +#include "Thread_Timer_Queue_Test.h" // Administrivia methods... Handler::Handler(const ACE_Time_Value &expiration_time) @@ -120,7 +34,7 @@ Handler::~Handler (void) { } -void +void Handler::set_id (int id) { this->id_ = id; @@ -128,20 +42,20 @@ Handler::set_id (int id) // This is the method invoked when the Timer expires. -int +int Handler::handle_timeout (const ACE_Time_Value ¤t_time, - const void *) + const void *) { ACE_Time_Value delay = current_time - this->expires_; // No need to protect this printf is always called from a Async safe // point. ACE_OS::printf ("\nexpiring timer %d at %u.%07.7u secs\n" - "\tthere was a %u.%07.7u secs delay\n", - this->id_, - current_time.sec (), - current_time.usec (), - delay.sec (), delay.usec ()); + "\tthere was a %u.%07.7u secs delay\n", + this->id_, + current_time.sec (), + current_time.usec (), + delay.sec (), delay.usec ()); // Notice this delete is protected. delete this; @@ -150,36 +64,26 @@ Handler::handle_timeout (const ACE_Time_Value ¤t_time, // The handler was cancelled, so we must delete this. -int +int Handler::cancelled (void) { delete this; return 0; } -Input_Task::Input_Task (Thread_Timer_Queue *queue) +Input_Task::Input_Task (Thread_Timer_Queue *queue, Thread_Timer_Queue_Test_Driver &timer_queue_driver) : queue_ (queue), - usecs_ (1000000) // @@ Make this an ACE #define constant? + usecs_ (1000000), // @@ Make this an ACE #define constant? + driver_ (timer_queue_driver) { } -int +int Input_Task::svc (void) { for (;;) - { - char buf[BUFSIZ]; - - this->usage (); - ACE_OS::printf ("please enter your choice: "); - ACE_OS::fflush (stdout); - - if (ACE_OS::read (ACE_STDIN, buf, sizeof buf) <= 0) - break; - - if (parse_commands (buf) < 0) - break; - } + if (this->driver_.get_next_request () == -1) + break; this->queue_->deactivate (); ACE_DEBUG ((LM_DEBUG, "terminating input thread\n")); @@ -187,8 +91,9 @@ Input_Task::svc (void) } int -Input_Task::add_timer (u_long useconds) +Input_Task::add_timer (void *argument) { + u_long useconds = *(int *)argument; ACE_Time_Value interval (useconds / usecs_, useconds % usecs_); ACE_Time_Value expire_at = ACE_OS::gettimeofday () + interval; @@ -197,7 +102,7 @@ Input_Task::add_timer (u_long useconds) ACE_NEW_RETURN (h, Handler (expire_at), -1); int id = queue_->schedule (h, 0, expire_at); - + if (id == -1) ACE_ERROR_RETURN ((LM_ERROR, "schedule failed"), -1); @@ -210,13 +115,26 @@ Input_Task::add_timer (u_long useconds) return 0; } -void -Input_Task::cancel_timer (int id) +int +Input_Task::cancel_timer (void *argument) { - this->queue_->cancel (id); + return this->queue_->cancel (*(int *)argument); } -void +int +Input_Task::list_timer (void *argument) +{ + this->dump (); + return 0; +} + +int +Input_Task::shutdown_timer (void *argument) +{ + return -1; +} + +void Input_Task::dump (void) { ACE_GUARD (ACE_SYNCH_MUTEX, ace_mon, this->queue_->lock ()); @@ -231,133 +149,89 @@ Input_Task::dump (void) ACE_DEBUG ((LM_DEBUG, "end dumping timer queue\n")); } -void -Input_Task::usage (void) const +int +Thread_Timer_Queue_Test_Driver::run_test (void) { - ACE_OS::printf ("Usage:\n" - "1 <microseconds>: setups a new timer\n" - "2 <timerid>: removes a timer\n" - "3 : prints timer queue\n" - "4 : exit\n"); + this->init (); + return 0; } -int -Input_Task::parse_commands (const char *buf) -{ - int option; - - if (::sscanf (buf, "%d", &option) <= 0) - { - // If there was an error reading the option simply print thge - // usage and try on the next line. - this->usage (); - return 0; - } - - switch (option) - { - case 1: // Install a new timer. - { - u_long useconds; - // We just reread the option, this simplies parsing (since - // sscanf can do it for us.) - if (::sscanf (buf, "%d %lu", &option, &useconds) < 2) - { - this->usage (); - return 0; - } - if (this->add_timer (useconds) == -1) - ACE_ERROR_RETURN ((LM_ERROR, "%t %p\n", "new timer failed"), -1); - } - break; // Cancel an existing timer. - case 2: - { - u_long id; - // We just reread the option, this simplies parsing (since - // sscanf can do it for us.) - if (::sscanf (buf, "%d %lu", &option, &id) < 2) - { - this->usage (); - return 0; - } - this->cancel_timer (id); - } - break; - - case 3: // Dump the existing timers. - this->dump (); - break; - - case 4: // Exit the program. - return -1; - ACE_NOTREACHED(break); - - default: - this->usage (); - break; - } - return 0; +int +Thread_Timer_Queue_Test_Driver::display_menu (void) +{ + static char menu[] = + "Usage:\n" + "1 <microseconds>: setups a new timer\n" + "2 <timerid>: removes a timer\n" + "3 : prints timer queue\n" + "4 : exit\n"; + + ACE_DEBUG ((LM_DEBUG, "%s", menu)); + + return 0; } -int -main (int, char *[]) +int +Thread_Timer_Queue_Test_Driver::init (void) { - Thread_Timer_Queue tq; - Input_Task input_task (&tq); + // initialize commands with their corresponding input_task methods. + ACE_NEW_RETURN (schedule_cmd_, + Command<Input_Task> (input_task, + input_task.add_timer), + -1); + + ACE_NEW_RETURN (cancel_cmd_, + Command<Input_Task> (input_task, + input_task.cancel_timer), + -1); + + ACE_NEW_RETURN (list_cmd_, + Command<Input_Task> (input_task, + input_task.list_timer), + -1); + + ACE_NEW_RETURN (shutdown_cmd_, + Command<Input_Task> (input_task, + input_task.shutdown_timer), + -1); if (input_task.activate () == -1) ACE_ERROR_RETURN ((LM_ERROR, "cannot activate input task"), -1); - - if (tq.activate () == -1) + + if (timer_queue_.activate () == -1) ACE_ERROR_RETURN ((LM_ERROR, "cannot activate timer queue"), -1); - + if (ACE_Thread_Manager::instance ()->wait () == -1) ACE_ERROR_RETURN ((LM_ERROR, "wait on Thread_Manager failed"),-1); - return 0; -} + return 0; +} + + #if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION) - template class ACE_Event_Handler_Handle_Timeout_Upcall<ACE_Null_Mutex>; - template class ACE_Timer_Heap_T<ACE_Event_Handler *, - ACE_Event_Handler_Handle_Timeout_Upcall<ACE_Null_Mutex>, - ACE_Null_Mutex>; - template class ACE_Timer_Heap_Iterator_T<ACE_Event_Handler *, - ACE_Event_Handler_Handle_Timeout_Upcall<ACE_Null_Mutex>, - ACE_Null_Mutex>; - template class ACE_Timer_Queue_T<ACE_Event_Handler *, ACE_Event_Handler_Handle_Timeout_Upcall<ACE_Null_Mutex>, ACE_Null_Mutex>; - template class ACE_Timer_Queue_Iterator_T<ACE_Event_Handler *, ACE_Event_Handler_Handle_Timeout_Upcall<ACE_Null_Mutex>, ACE_Null_Mutex>; - template class ACE_Thread_Timer_Queue_Adapter<Timer_Heap>; +template class ACE_Thread_Timer_Queue_Adapter<Timer_Heap>; #elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA) -# pragma instantiate ACE_Event_Handler_Handle_Timeout_Upcall<ACE_Null_Mutex> -# pragma instantiate ACE_Timer_Heap_T<ACE_Event_Handler *, ACE_Event_Handler_Handle_Timeout_Upcall<ACE_Null_Mutex>, ACE_Null_Mutex> -# pragma instantiate ACE_Timer_Heap_Iterator_T<ACE_Event_Handler *, ACE_Event_Handler_Handle_Timeout_Upcall<ACE_Null_Mutex>, ACE_Null_Mutex> -# pragma instantiate ACE_Timer_Queue_T<ACE_Event_Handler *, ACE_Event_Handler_Handle_Timeout_Upcall<ACE_Null_Mutex>, ACE_Null_Mutex> -# pragma instantiate ACE_Timer_Queue_Iterator_T<ACE_Event_Handler *, ACE_Event_Handler_Handle_Timeout_Upcall<ACE_Null_Mutex>, ACE_Null_Mutex> -# pragma instantiate ACE_Thread_Timer_Queue_Adapter<Timer_Heap> +#pragma instantiate ACE_Thread_Timer_Queue_Adapter<Timer_Heap> #endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */ -#if defined (ACE_MT_SAFE) -# if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION) - template class ACE_Condition<ACE_Thread_Mutex>; - template class ACE_Thread_Condition<ACE_Thread_Mutex>; -# elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA) -# pragma instantiate ACE_Condition<ACE_Thread_Mutex> -# pragma instantiate ACE_Thread_Condition<ACE_Thread_Mutex> -# endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */ -#else /* ! ACE_MT_SAFE */ - - // These templates will specialized in liACE.* if the platforms does - // not define ACE_MT_SAFE. - -# if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION) - template class ACE_Event_Handler_Handle_Timeout_Upcall<ACE_Null_Mutex>; - template class ACE_Timer_Heap_T<ACE_Event_Handler *, ACE_Event_Handler_Handle_Timeout_Upcall<ACE_Null_Mutex>, ACE_Null_Mutex>; - template class ACE_Timer_Heap_Iterator_T<ACE_Event_Handler *, ACE_Event_Handler_Handle_Timeout_Upcall<ACE_Null_Mutex>, ACE_Null_Mutex>; -# elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA) -# pragma instantiate ACE_Event_Handler_Handle_Timeout_Upcall<ACE_Null_Mutex> -# pragma instantiate ACE_Timer_Heap_T<ACE_Event_Handler *, ACE_Event_Handler_Handle_Timeout_Upcall<ACE_Null_Mutex>, ACE_Null_Mutex> -# pragma instantiate ACE_Timer_Heap_Iterator_T<ACE_Event_Handler *, ACE_Event_Handler_Handle_Timeout_Upcall<ACE_Null_Mutex>, ACE_Null_Mutex> +#if !defined(ACE_MT_SAFE) + +// These templates will specialized in liACE.* if the platforms does +// not define ACE_MT_SAFE. + +#if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION) + +template class ACE_Event_Handler_Handle_Timeout_Upcall<ACE_Null_Mutex>; +template class ACE_Timer_Heap_T<ACE_Event_Handler *, ACE_Event_Handler_Handle_Timeout_Upcall<ACE_Null_Mutex>, ACE_Null_Mutex>; +template class ACE_Timer_Heap_Iterator_T<ACE_Event_Handler *, ACE_Event_Handler_Handle_Timeout_Upcall<ACE_Null_Mutex>, ACE_Null_Mutex>; + +#elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA) + +#pragma instantiate ACE_Event_Handler_Handle_Timeout_Upcall<ACE_Null_Mutex> +#pragma instantiate ACE_Timer_Heap_T<ACE_Event_Handler *, ACE_Event_Handler_Handle_Timeout_Upcall<ACE_Null_Mutex>, ACE_Null_Mutex> +#pragma instantiate ACE_Timer_Heap_Iterator_T<ACE_Event_Handler *, ACE_Event_Handler_Handle_Timeout_Upcall<ACE_Null_Mutex>, ACE_Null_Mutex> + #endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */ -#endif /* ! ACE_MT_SAFE */ +#endif /* ACE_MT_SAFE */ diff --git a/examples/Timer_Queue/Thread_Timer_Queue_Test.h b/examples/Timer_Queue/Thread_Timer_Queue_Test.h new file mode 100644 index 00000000000..521940891ec --- /dev/null +++ b/examples/Timer_Queue/Thread_Timer_Queue_Test.h @@ -0,0 +1,146 @@ +#if !defined (_THREAD_TIMER_QUEUE_TEST_H_) +#define _THREAD_TIMER_QUEUE_TEST_H_ + +#include "ace/Task.h" +#include "ace/Timer_Heap_T.h" +#include "ace/Timer_Queue_Adapters.h" + +#include "Driver.h" + +// These typedefs ensure that we use the minimal amount of locking +// necessary. +typedef ACE_Event_Handler_Handle_Timeout_Upcall<ACE_Null_Mutex> + Upcall; +typedef ACE_Timer_Heap_T<ACE_Event_Handler *, + ACE_Event_Handler_Handle_Timeout_Upcall<ACE_Null_Mutex>, + ACE_Null_Mutex> + Timer_Heap; +typedef ACE_Timer_Heap_Iterator_T<ACE_Event_Handler *, + ACE_Event_Handler_Handle_Timeout_Upcall<ACE_Null_Mutex>, + ACE_Null_Mutex> + Timer_Heap_Iterator; +typedef ACE_Thread_Timer_Queue_Adapter<Timer_Heap> + Thread_Timer_Queue; + +class Thread_Timer_Queue_Test_Driver; + +class Input_Task : public ACE_Task<ACE_SYNCH> + // = TITLE + // Read user actions on the Timer_Queue from stdin. + // + // = DESCRIPTION + // This class reads user input from stdin; those commands permit the + // control of a Timer_Queue, which is dispatched by another thread. +{ +public: + Input_Task (Thread_Timer_Queue *queue, + Thread_Timer_Queue_Test_Driver &timer_queue_driver); + + virtual int svc (void); + // The method run on the new thread. + + // = Some helper methods. + + int add_timer (void *); + // Add a new timer to expire in <seconds> more. + + int cancel_timer (void *); + // Cancel timer <id>. + + int list_timer (void *); + // List the current scheduled timers. + + int shutdown_timer (void *); + // Shutdown task. + + void dump (void); + // Dump the state of the timer queue. + +private: + Thread_Timer_Queue *queue_; + // The timer queue implementation. + + const int usecs_; + // How many micro seconds are in a second. + + Timer_Queue_Test_Driver<Thread_Timer_Queue, Input_Task> &driver_; +}; + +class Thread_Timer_Queue_Test_Driver : public Timer_Queue_Test_Driver <Thread_Timer_Queue, Input_Task> +// = TITLE +// +// = DESCRIPTION +{ +public: + // @@ Please don't put the definitions of methods in their declarations. + Thread_Timer_Queue_Test_Driver (void) + : input_task (&timer_queue_, *this) + {} + + virtual int display_menu (void); + virtual int init (void); + virtual int run_test (void); + +private: + Input_Task input_task; +}; + +class Handler : public ACE_Event_Handler + // = TITLE + // This class implements a simple Event_Handler, + // + // = DESCRIPTION + // The <handle_timeout> hook method justs printouts the current + // time, delete this and prints the delay on the twhen it is + // expired. +{ +public: + Handler (const ACE_Time_Value &expiration_time); + ~Handler (void); + + void set_id (int id); + // Store an "id" for the Handler, which is only use to print better + // messages. + + virtual int handle_timeout (const ACE_Time_Value ¤t_time, + const void *arg); + // Call back hook. + virtual int cancelled (void); + +private: + ACE_Time_Value expires_; + // Store the expected time of expiration, it is used to print a nice + // message saying how much delay was at the actual expiration time. + + int id_; + // Store an "id" for the Handler, which is only use to print better + // messages. +}; + +#if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION) +template class ACE_Thread_Timer_Queue_Adapter<Timer_Heap>; +#elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA) +#pragma instantiate ACE_Thread_Timer_Queue_Adapter<Timer_Heap> +#endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */ + +#if !defined(ACE_MT_SAFE) + +// These templates will specialized in liACE.* if the platforms does +// not define ACE_MT_SAFE. + +#if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION) + +template class ACE_Event_Handler_Handle_Timeout_Upcall<ACE_Null_Mutex>; +template class ACE_Timer_Heap_T<ACE_Event_Handler *, ACE_Event_Handler_Handle_Timeout_Upcall<ACE_Null_Mutex>, ACE_Null_Mutex>; +template class ACE_Timer_Heap_Iterator_T<ACE_Event_Handler *, ACE_Event_Handler_Handle_Timeout_Upcall<ACE_Null_Mutex>, ACE_Null_Mutex>; + +#elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA) + +#pragma instantiate ACE_Event_Handler_Handle_Timeout_Upcall<ACE_Null_Mutex> +#pragma instantiate ACE_Timer_Heap_T<ACE_Event_Handler *, ACE_Event_Handler_Handle_Timeout_Upcall<ACE_Null_Mutex>, ACE_Null_Mutex> +#pragma instantiate ACE_Timer_Heap_Iterator_T<ACE_Event_Handler *, ACE_Event_Handler_Handle_Timeout_Upcall<ACE_Null_Mutex>, ACE_Null_Mutex> + +#endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */ +#endif /* ACE_MT_SAFE */ + +#endif /* _THREAD_TIMER_QUEUE_TEST_H_ */ diff --git a/examples/Timer_Queue/main_async.cpp b/examples/Timer_Queue/main_async.cpp new file mode 100644 index 00000000000..28af96ba0ee --- /dev/null +++ b/examples/Timer_Queue/main_async.cpp @@ -0,0 +1,42 @@ +// ============================================================================ +// +// = LIBRARY +// examples +// +// = FILENAME +// main_async.cpp +// +// = DESCRIPTION +// Implements an asynchronous timer queue. +// This code exercises the Timer_Queue_Test_Driver class using +// signals as an asynchronous mechanism to dispatch events. +// +// = AUTHORS +// Douglas Schmidt <schmidt@cs.wustl.edu> && +// Sergio Flores-Gaitan <sergio@cs.wustl.edu> +// +// ============================================================================ +#include <ace/Auto_Ptr.h> + +#include "Driver.h" +#include "Async_Timer_Queue_Test.h" + +typedef Timer_Queue_Test_Driver<Async_Timer_Queue*, Async_Timer_Queue> + ASYNC_TIMER_QUEUE_TEST_DRIVER; + +int +main (int, char *[]) +{ + // Auto ptr ensures that the driver memory is released automatically. + auto_ptr <ASYNC_TIMER_QUEUE_TEST_DRIVER> driver; + ASYNC_TIMER_QUEUE_TEST_DRIVER *tqtd; + + ACE_NEW_RETURN (tqtd, Async_Timer_Queue_Test_Driver, -1); + driver = tqtd; + + driver->run_test () ; + return 0 ; +} + + + diff --git a/examples/Timer_Queue/main_reactor.cpp b/examples/Timer_Queue/main_reactor.cpp new file mode 100644 index 00000000000..65c680cf4aa --- /dev/null +++ b/examples/Timer_Queue/main_reactor.cpp @@ -0,0 +1,39 @@ +// ============================================================================ +// +// = LIBRARY +// examples +// +// = FILENAME +// main_reactor.cpp +// +// = DESCRIPTION +// Implements an reactive timer queue. +// This code exercises the Timer_Queue_Test_Driver class using +// a reactor. +// +// = AUTHORS +// Douglas Schmidt <schmidt@cs.wustl.edu> && +// Sergio Flores-Gaitan <sergio@cs.wustl.edu> +// +// ============================================================================ +#include <ace/Auto_Ptr.h> + +#include "Driver.h" +#include "Reactor_Timer_Queue_Test.h" + + +typedef Timer_Queue_Test_Driver <ACE_Timer_Heap, Input_Handler> + REACTOR_TIMER_QUEUE_TEST_DRIVER; + +int +main (int, char *[]) +{ + // Auto ptr ensures that the driver memory is released automatically. + auto_ptr <REACTOR_TIMER_QUEUE_TEST_DRIVER> driver; + REACTOR_TIMER_QUEUE_TEST_DRIVER *tqtd; + + ACE_NEW_RETURN (tqtd, Reactor_Timer_Queue_Test_Driver, -1); + driver = tqtd; + + return driver->run_test (); +} diff --git a/examples/Timer_Queue/main_thread.cpp b/examples/Timer_Queue/main_thread.cpp new file mode 100644 index 00000000000..98ccdac06dc --- /dev/null +++ b/examples/Timer_Queue/main_thread.cpp @@ -0,0 +1,38 @@ +// ============================================================================ +// +// = LIBRARY +// examples +// +// = FILENAME +// main_thread.cpp +// +// = DESCRIPTION +// Implements an threaded timer queue. +// This code exercises the Timer_Queue_Test_Driver class using +// threads. +// +// = AUTHORS +// Douglas Schmidt <schmidt@cs.wustl.edu> && +// Sergio Flores-Gaitan <sergio@cs.wustl.edu> +// +// ============================================================================ +#include <ace/Auto_Ptr.h> + +#include "Driver.h" +#include "Thread_Timer_Queue_Test.h" + +typedef Timer_Queue_Test_Driver<Thread_Timer_Queue, Input_Task> + THREAD_TIMER_QUEUE_TEST_DRIVER; + +int +main (int, char *[]) +{ + // Auto ptr ensures that the driver memory is released automatically. + auto_ptr <THREAD_TIMER_QUEUE_TEST_DRIVER> driver; + THREAD_TIMER_QUEUE_TEST_DRIVER *tqtd; + + ACE_NEW_RETURN (tqtd, Thread_Timer_Queue_Test_Driver, -1); + driver = tqtd; + + return driver->run_test (); +} |