diff options
Diffstat (limited to 'examples/Timer_Queue')
-rw-r--r-- | examples/Timer_Queue/.cvsignore | 3 | ||||
-rw-r--r-- | examples/Timer_Queue/Async_Timer_Queue_Test.cpp | 309 | ||||
-rw-r--r-- | examples/Timer_Queue/Async_Timer_Queue_Test.h | 119 | ||||
-rw-r--r-- | examples/Timer_Queue/Driver.cpp | 164 | ||||
-rw-r--r-- | examples/Timer_Queue/Driver.h | 137 | ||||
-rw-r--r-- | examples/Timer_Queue/Makefile.am | 94 | ||||
-rw-r--r-- | examples/Timer_Queue/README | 26 | ||||
-rw-r--r-- | examples/Timer_Queue/Reactor_Timer_Queue_Test.cpp | 231 | ||||
-rw-r--r-- | examples/Timer_Queue/Reactor_Timer_Queue_Test.h | 153 | ||||
-rw-r--r-- | examples/Timer_Queue/Thread_Timer_Queue_Test.cpp | 307 | ||||
-rw-r--r-- | examples/Timer_Queue/Thread_Timer_Queue_Test.h | 157 | ||||
-rw-r--r-- | examples/Timer_Queue/Timer_Queue.mpc | 40 | ||||
-rw-r--r-- | examples/Timer_Queue/main_async.cpp | 66 | ||||
-rw-r--r-- | examples/Timer_Queue/main_reactor.cpp | 70 | ||||
-rw-r--r-- | examples/Timer_Queue/main_thread.cpp | 65 |
15 files changed, 0 insertions, 1941 deletions
diff --git a/examples/Timer_Queue/.cvsignore b/examples/Timer_Queue/.cvsignore deleted file mode 100644 index 6f1917f64c8..00000000000 --- a/examples/Timer_Queue/.cvsignore +++ /dev/null @@ -1,3 +0,0 @@ -Asynch_Timer_Queue_Test -Reactor_Timer_Queue_Test -Thread_Timer_Queue_Test diff --git a/examples/Timer_Queue/Async_Timer_Queue_Test.cpp b/examples/Timer_Queue/Async_Timer_Queue_Test.cpp deleted file mode 100644 index 49d7973676a..00000000000 --- a/examples/Timer_Queue/Async_Timer_Queue_Test.cpp +++ /dev/null @@ -1,309 +0,0 @@ -// $Id$ - -// ============================================================================ -// -// = LIBRARY -// examples -// -// = FILENAME -// Async_Timer_Queue_Test.cpp -// -// = DESCRIPTION -// This test exercises the <ACE_Asynch_Timer_Queue_Adapter> -// using an <ACE_Timer_Heap>. -// -// = AUTHORS -// Douglas C. Schmidt <schmidt@cs.wustl.edu> and -// Sergio Flores-Gaitan <sergio@cs.wustl.edu> -// -// ============================================================================ - -#include "ace/OS_NS_sys_time.h" -#include "ace/Signal.h" -#include "ace/Timer_Heap.h" -#include "ace/Timer_Queue_Adapters.h" - -#include "Async_Timer_Queue_Test.h" - -#if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION) -template class ACE_Async_Timer_Queue_Adapter<ACE_Timer_Heap>; -template class Command<Async_Timer_Queue, Async_Timer_Queue::ACTION>; -template class Timer_Queue_Test_Driver<Async_Timer_Queue *, Async_Timer_Queue, Async_Timer_Queue::ACTION>; -#elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA) -#pragma instantiate ACE_Async_Timer_Queue_Adapter<ACE_Timer_Heap> -#pragma instantiate Command<Async_Timer_Queue, Async_Timer_Queue::ACTION> -#pragma instantiate Timer_Queue_Test_Driver<Async_Timer_Queue *, Async_Timer_Queue, Async_Timer_Queue::ACTION> -#endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */ - -ACE_RCSID(Timer_Queue, Async_Timer_Queue_Test, "$Id$") - -// Hook method that is called to handle the expiration of a timer. -int -Async_Timer_Handler::handle_timeout (const ACE_Time_Value &tv, - const void *arg) -{ - // Print some information here (note that this is not strictly - // signal-safe since the ACE logging mechanism uses functions that - // aren't guaranteed to work in all signal handlers). - ACE_DEBUG ((LM_DEBUG, - "handle_timeout() = (%d, %d) %d\n", - tv.sec (), - tv.usec (), - arg)); - - // Commit suicide! - delete this; - return 0; -} - -// Initialize the Singleton pointer. -Async_Timer_Queue *Async_Timer_Queue::instance_ = 0; - -// Implement the Singleton logic. -Async_Timer_Queue * -Async_Timer_Queue::instance (void) -{ - if (Async_Timer_Queue::instance_ == 0) - { - // Initialize with all signals enabled. - ACE_Sig_Set ss (1); - - // But, don't block out SIGQUIT since we always want that - // signal to interrupt the program. - ss.sig_del (SIGQUIT); - - ACE_NEW_RETURN (Async_Timer_Queue::instance_, - Async_Timer_Queue (&ss), - 0); - } - return Async_Timer_Queue::instance_; -} - -// Sets the signal set to mask, for the timer queue. - -Async_Timer_Queue::Async_Timer_Queue (ACE_Sig_Set *ss) - : tq_ (ss) -{ -} - -// Dump the contents of the queue when we receive ^C. - -void -Async_Timer_Queue::dump (void) -{ - ACE_DEBUG ((LM_DEBUG, "begin dumping timer queue\n")); - - // This iterator is implicitly protected since SIGINT and SIGALRM - // signals cannot occur while it is running. - - for (ACE_Timer_Heap_Iterator iter (this->tq_.timer_queue ()); - iter.item () != 0; - iter.next ()) - iter.item ()->dump (); - - ACE_DEBUG ((LM_DEBUG, - "end dumping timer queue\n")); -} - -// Schedule a timer. - -void -Async_Timer_Queue::schedule (u_int microsecs) -{ - ACE_Time_Value tv (0, microsecs); - - // Create a new Event_Handler for our timer. - - ACE_Event_Handler *eh; - ACE_NEW (eh, - Async_Timer_Handler); - - // Schedule the timer to run in the future. - long tid = this->tq_.schedule - (eh, - 0, // Note that our "magic cookie" ACT is always NULL. - ACE_OS::gettimeofday () + tv); - - if (tid == -1) - ACE_ERROR ((LM_ERROR, - "%p\n", - "schedule_timer")); -} - -// Cancel a timer. - -void -Async_Timer_Queue::cancel (long timer_id) -{ - ACE_DEBUG ((LM_DEBUG, - "canceling %d\n", - timer_id)); - - const void *act = 0; - - if (this->tq_.cancel (timer_id, &act) == -1) - ACE_ERROR ((LM_ERROR, - "%p\n", - "cancel_timer")); - - // In this case, the act will be 0, but it could be a real pointer - // in other cases. - delete (ACE_Event_Handler *) act; -} - -// Schedule timer hook method. This method is called from the driver. - -int -Async_Timer_Queue::schedule_timer (void *argument) -{ - u_long useconds = *(int *)argument; - - // Schedule a timer. - Async_Timer_Queue::instance ()->schedule (useconds); - - return 0; -} - -// Cancel timer hook method. Is called from the driver class. - -int -Async_Timer_Queue::cancel_timer (void *argument) -{ - u_long id = *(int *)argument; - - // Cancel a timer. - Async_Timer_Queue::instance ()->cancel (id); - - return 0; -} - -// Dummy list timer hook method. The listing of timers is done from a -// signal handler using SIGINT, not from the driver. - -int -Async_Timer_Queue::list_timer (void *) -{ - // Display an error message. - ACE_ERROR_RETURN ((LM_ERROR, - "invalid input\n"), 0); -} - -// Dummy shutdown timer hook method. The shutdown of the timer queue -// is done with a signal handler using SIGQUIT, not from the driver. - -int -Async_Timer_Queue::shutdown_timer (void *) -{ - // Display an error message. - ACE_ERROR_RETURN ((LM_ERROR, - "invalid input\n"), - 0); -} - -// Handler for the SIGINT and SIGQUIT signals. - -static void -signal_handler (int signum) -{ - ACE_DEBUG ((LM_DEBUG, - "handling signal %S\n", - signum)); - - switch (signum) - { - case SIGINT: - Async_Timer_Queue::instance ()->dump (); - break; - /* NOTREACHED */ - - case SIGQUIT: - ACE_ERROR ((LM_ERROR, - "shutting down on SIGQUIT%a\n", - 1)); - /* NOTREACHED */ - break; - } -} - -// Register the signal handlers for SIGQUIT and SIGINT. We must -// ensure that the SIGINT handler isn't interrupted by SIGALRM. -// However, SIGQUIT is never blocked... - -static void -register_signal_handlers (void) -{ - // Register SIGQUIT (never blocked). - ACE_Sig_Action sigquit ((ACE_SignalHandler) signal_handler, - SIGQUIT); - ACE_UNUSED_ARG (sigquit); - - // Don't let the SIGALRM interrupt the SIGINT handler! - ACE_Sig_Set ss; - ss.sig_add (SIGALRM); - - // Register SIGINT (note that system calls will be restarted - // automatically). - ACE_Sig_Action sigint ((ACE_SignalHandler) signal_handler, - SIGINT, - ss, - SA_RESTART); - ACE_UNUSED_ARG (sigint); -} - -// constructor - -Async_Timer_Queue_Test_Driver::Async_Timer_Queue_Test_Driver (void) -{ -} - -// displays the menu of options. - -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; -} - -// Initializes the test driver. - -int -Async_Timer_Queue_Test_Driver::init (void) -{ - typedef Command<Async_Timer_Queue, Async_Timer_Queue::ACTION> CMD; - - // Initialize <Command> objects with their corresponding <Input_Task> methods. - ACE_NEW_RETURN (schedule_cmd_, - CMD (*Async_Timer_Queue::instance (), - &Async_Timer_Queue::schedule_timer), - -1); - - ACE_NEW_RETURN (cancel_cmd_, - CMD (*Async_Timer_Queue::instance (), - &Async_Timer_Queue::cancel_timer), - -1); - - ACE_NEW_RETURN (list_cmd_, - CMD (*Async_Timer_Queue::instance (), - &Async_Timer_Queue::list_timer), - -1); - - ACE_NEW_RETURN (shutdown_cmd_, - CMD (*Async_Timer_Queue::instance (), - &Async_Timer_Queue::shutdown_timer), - -1); - - register_signal_handlers (); - - return 0; -} diff --git a/examples/Timer_Queue/Async_Timer_Queue_Test.h b/examples/Timer_Queue/Async_Timer_Queue_Test.h deleted file mode 100644 index 6b166f894c3..00000000000 --- a/examples/Timer_Queue/Async_Timer_Queue_Test.h +++ /dev/null @@ -1,119 +0,0 @@ -/* -*- C++ -*- */ - -// $Id$ - -// ============================================================================ -// -// = LIBRARY -// examples -// -// = FILENAME -// Async_Timer_Queue_Test.h -// -// = DESCRIPTION -// This test exercises the <ACE_Asynch_Timer_Queue_Adapter> -// using an <ACE_Timer_Heap>. -// -// = AUTHORS -// Douglas C. Schmidt and -// Sergio Flores-Gaitan -// ============================================================================ - -#ifndef _ASYNC_TIMER_QUEUE_TEST_H_ -#define _ASYNC_TIMER_QUEUE_TEST_H_ - -#include "ace/Signal.h" -#include "ace/svc_export.h" - -#if !defined (ACE_LACKS_PRAGMA_ONCE) -# pragma once -#endif /* ACE_LACKS_PRAGMA_ONCE */ - -#include "ace/Timer_Heap.h" -#include "ace/Timer_Queue_Adapters.h" - -#include "Driver.h" - -class Async_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: - typedef int (Async_Timer_Queue::*ACTION) (void *); - - 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); - // hook method to schedule a timer. Called from - // <Timer_Queue_Test_Driver> - - int cancel_timer (void *argument); - // hook method to cancel a timer. Called from - // <Timer_Queue_Test_Driver> - - int list_timer (void *argument); - // hook method to list timers. Called from - // <Timer_Queue_Test_Driver> - - int shutdown_timer (void *argument); - // hook method to exit the timer queue. Called from - // <Timer_Queue_Test_Driver> - -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 ACE_Svc_Export Async_Timer_Queue_Test_Driver : public Timer_Queue_Test_Driver <Async_Timer_Queue *, Async_Timer_Queue, Async_Timer_Queue::ACTION> -{ - // = TITLE - // Async_Timer_Queue_Test_Driver - // - // = DESCRIPTION - // This class implements a test driver for the - // <Async_Timer_Queue>. Implements a display_menu() method that - // prints the options for a user. and init() which initializes - // the driver. The rest of the common functionality is in the - // parent class <Timer_Queue_Test_Driver>. -public: - Async_Timer_Queue_Test_Driver (void); - - virtual int display_menu (void); - // Print menu of options. - - virtual int init (void); - // Initializes the driver's internal variables inherited from the parent -}; - -#endif /* _ASYNC_TIMER_QUEUE_TEST_H_ */ diff --git a/examples/Timer_Queue/Driver.cpp b/examples/Timer_Queue/Driver.cpp deleted file mode 100644 index ca549b1f952..00000000000 --- a/examples/Timer_Queue/Driver.cpp +++ /dev/null @@ -1,164 +0,0 @@ -// $Id$ - -// ============================================================================ -// = 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> -// -// ============================================================================ - -#if !defined (_DRIVER_CPP_) -#define _DRIVER_CPP_ - -#include "ace/OS_NS_stdio.h" -#include "ace/OS_NS_string.h" -#include "ace/OS_NS_unistd.h" -#include "ace/Auto_Ptr.h" -#include "Driver.h" - -ACE_RCSID(Timer_Queue, Driver, "$Id$") - -// constructor - -template <class RECEIVER, class ACTION> -Command<RECEIVER, ACTION>::Command (RECEIVER &recvr, - ACTION action) - : receiver_ (recvr), - action_ (action) -{ -} - -// destructor -template <class RECEIVER, class ACTION> -Command<RECEIVER, ACTION>::~Command (void) -{ -} - -// invokes an operation. - -template <class RECEIVER, class ACTION> int -Command<RECEIVER, ACTION>::execute (void *arg) -{ - return (receiver_.*action_) (arg); -} - -// gets the next request from the user input. - -template <class TQ, class RECEIVER, class ACTION> -Timer_Queue_Test_Driver<TQ, RECEIVER, ACTION>::~Timer_Queue_Test_Driver (void) -{ -} - -template <class TQ, class RECEIVER, class ACTION> int -Timer_Queue_Test_Driver<TQ, RECEIVER, ACTION>::get_next_request (void) -{ - char buf[BUFSIZ]; - - this->display_menu (); - - ACE_OS::printf ("please enter your choice: "); - ACE_OS::fflush (stdout); - - // reads input from the user - if (this->read_input (buf, sizeof buf) <= 0) - return -1; - - // Parse and run the command. - return this->parse_commands (buf); -} - -// Runs the test. - -template <class TQ, class RECEIVER, class ACTION> int -Timer_Queue_Test_Driver<TQ, RECEIVER, ACTION>::run_test (void) -{ - this->init (); - - for (;;) - if (this->get_next_request () == -1) - return -1; - - ACE_NOTREACHED (return 0); -} - -// Reads input from the user from ACE_STDIN into the buffer specified. - -template <class TQ, class RECEIVER, class ACTION> ssize_t -Timer_Queue_Test_Driver<TQ, RECEIVER, ACTION>::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); -} - -// Parse the input and executes the corresponding operation - -template <class TQ, class RECEIVER, class ACTION> int -Timer_Queue_Test_Driver<TQ, RECEIVER, ACTION>::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); - ACE_NOTREACHED (break); - /* NOTREACHED */ - } - return 0; -} - -#endif /* _DRIVER_CPP_ */ diff --git a/examples/Timer_Queue/Driver.h b/examples/Timer_Queue/Driver.h deleted file mode 100644 index 4677b904982..00000000000 --- a/examples/Timer_Queue/Driver.h +++ /dev/null @@ -1,137 +0,0 @@ -/* -*- C++ -*- */ - -// $Id$ - -// ============================================================================ -// -// = LIBRARY -// examples -// -// = FILENAME -// Driver.h -// -// = DESCRIPTION -// This code builds an abstraction to factor out common code for -// the different implementations of the Timer_Queue. -// -// = AUTHORS -// Sergio Flores-Gaitan <sergio@cs.wustl.edu> -// -// ============================================================================ - -#ifndef _DRIVER_H_ -#define _DRIVER_H_ - -#include "ace/Task.h" - -#if !defined (ACE_LACKS_PRAGMA_ONCE) -# pragma once -#endif /* ACE_LACKS_PRAGMA_ONCE */ - -#include "ace/Timer_Heap_T.h" -#include "ace/Timer_Queue_Adapters.h" - -template <class RECEIVER, class ACTION> -class Command -{ - // = TITLE - // Defines an abstract class that allows us to invoke commands - // without knowing anything about the implementation. This class - // is used in the <Timer_Queue_Test_Driver> to invoke operations - // of the driver. - // - // = DESCRIPTION - // This class declares an interface to execute operations, - // binding a RECEIVER object with an ACTION. The RECEIVER knows - // how to implement the operation. A class can invoke operations - // without knowing anything about it, or how it was implemented. -public: - Command (RECEIVER &recvr, ACTION action); - // Sets the <receiver_> of the Command to recvr, and the - // <action_> of the Command to <action>. - - virtual ~Command (void); - - virtual int execute (void *arg); - // Invokes the method <action_> from the object <receiver_>. - -private: - RECEIVER &receiver_; - // object where the method resides. - - ACTION action_; - // method that is going to be invoked. -}; - -template <class TQ, class RECEIVER, class ACTION> -class Timer_Queue_Test_Driver -{ - // = TITLE - // Defines a class that provides a simmple implementation for - // a test driver for timer queues. - // - // = DESCRIPTION - // This is the place where the common code to test the different - // implementations of the timer queue resides. This class has - // the logic for the parse_commands() method, the run_test(), - // read_input() and the get_next_request(). Subclasses can - // override these methods if there is some logic that is specific - // to that implementation. -public: - virtual ~Timer_Queue_Test_Driver (void); - // Default destructor - - virtual int parse_commands (const char *buf); - // Breaks up the input string buffer into pieces and executes - // the appropriate method to handle that operation. - - virtual int run_test (void); - // This is the main entry point to the test driver. The user - // of the class should normally invoke this method. - // Returns 0 when successful, or 0 otherwise. - - virtual int get_next_request (void); - // This internal method gets the next request from the user. - // Returns -1 when user wants to exit. Returns 0 otherwise. - - virtual ssize_t read_input (char *buf, size_t bufsiz); - // Reads input from the user into the buffer <buf> with a maximum - // of <bufsiz> bytes. Returns the amount of bytes actually read - // Otherwise, a -1 is returned and errno is set to indicate the error. - - // = Template Methods. - - virtual int display_menu (void)=0; - // Prints the user interface for the driver to STDOUT. - - virtual int init (void)=0; - // Initializes values and operations for the driver. - -protected: - TQ timer_queue_; - // timer queue - - // = Set of <Command>s to be executed. - - Command<RECEIVER, ACTION> *schedule_cmd_; - // schedule timer command - - Command<RECEIVER, ACTION> *cancel_cmd_; - // cancel timer command. - - Command<RECEIVER, ACTION> *list_cmd_; - // list timers command. - - Command<RECEIVER, ACTION> *shutdown_cmd_; - // shutdown the driver. -}; - -#if defined (ACE_TEMPLATES_REQUIRE_SOURCE) -#include "Driver.cpp" -#endif /* ACE_TEMPLATES_REQUIRE_SOURCE */ - -#if defined (ACE_TEMPLATES_REQUIRE_PRAGMA) -#pragma implementation ("Driver.cpp") -#endif /* ACE_TEMPLATES_REQUIRE_PRAGMA */ - -#endif /* _DRIVER_H_ */ diff --git a/examples/Timer_Queue/Makefile.am b/examples/Timer_Queue/Makefile.am deleted file mode 100644 index 278a98acf59..00000000000 --- a/examples/Timer_Queue/Makefile.am +++ /dev/null @@ -1,94 +0,0 @@ -## Process this file with automake to create Makefile.in -## -## $Id$ -## -## This file was generated by MPC. Any changes made directly to -## this file will be lost the next time it is generated. -## -## MPC Command: -## /acebuilds/ACE_wrappers-repository/bin/mwc.pl -include /acebuilds/MPC/config -include /acebuilds/MPC/templates -feature_file /acebuilds/ACE_wrappers-repository/local.features -noreldefs -type automake -exclude build,Kokyu - -ACE_BUILDDIR = $(top_builddir) -ACE_ROOT = $(top_srcdir) - -## Makefile.Timer_Queue_Library.am -noinst_LTLIBRARIES = libtqtd.la - -libtqtd_la_CPPFLAGS = \ - -I$(ACE_ROOT) \ - -I$(ACE_BUILDDIR) \ - -DACE_BUILD_SVC_DLL - -libtqtd_la_SOURCES = \ - Async_Timer_Queue_Test.cpp \ - Driver.cpp \ - Reactor_Timer_Queue_Test.cpp \ - Thread_Timer_Queue_Test.cpp - -libtqtd_la_LIBADD = \ - $(top_builddir)/ace/libACE.la - -noinst_HEADERS = \ - Async_Timer_Queue_Test.h \ - Driver.h \ - Reactor_Timer_Queue_Test.h \ - Thread_Timer_Queue_Test.h - -## Makefile.Timer_Queue_Async.am -noinst_PROGRAMS = Asynch_Timer_Queue_Test - -Asynch_Timer_Queue_Test_CPPFLAGS = \ - -I$(ACE_ROOT) \ - -I$(ACE_BUILDDIR) - -Asynch_Timer_Queue_Test_SOURCES = \ - main_async.cpp \ - Async_Timer_Queue_Test.h \ - Driver.h \ - Reactor_Timer_Queue_Test.h \ - Thread_Timer_Queue_Test.h - -Asynch_Timer_Queue_Test_LDADD = \ - libtqtd.la $(top_builddir)/ace/libACE.la - -## Makefile.Timer_Queue_Reactor.am -noinst_PROGRAMS += Reactor_Timer_Queue_Test - -Reactor_Timer_Queue_Test_CPPFLAGS = \ - -I$(ACE_ROOT) \ - -I$(ACE_BUILDDIR) - -Reactor_Timer_Queue_Test_SOURCES = \ - main_reactor.cpp \ - Async_Timer_Queue_Test.h \ - Driver.h \ - Reactor_Timer_Queue_Test.h \ - Thread_Timer_Queue_Test.h - -Reactor_Timer_Queue_Test_LDADD = \ - libtqtd.la $(top_builddir)/ace/libACE.la - -## Makefile.Timer_Queue_Thread.am -noinst_PROGRAMS += Thread_Timer_Queue_Test - -Thread_Timer_Queue_Test_CPPFLAGS = \ - -I$(ACE_ROOT) \ - -I$(ACE_BUILDDIR) - -Thread_Timer_Queue_Test_SOURCES = \ - main_thread.cpp \ - Async_Timer_Queue_Test.h \ - Driver.h \ - Reactor_Timer_Queue_Test.h \ - Thread_Timer_Queue_Test.h - -Thread_Timer_Queue_Test_LDADD = \ - libtqtd.la $(top_builddir)/ace/libACE.la - -## Clean up template repositories, etc. -clean-local: - -rm -f *~ *.bak *.rpo *.sym lib*.*_pure_* core core.* - -rm -f gcctemp.c gcctemp so_locations *.ics - -rm -rf cxx_repository ptrepository ti_files - -rm -rf templateregistry ir.out - -rm -rf ptrepository SunWS_cache Templates.DB diff --git a/examples/Timer_Queue/README b/examples/Timer_Queue/README deleted file mode 100644 index 3cf6ec1b75b..00000000000 --- a/examples/Timer_Queue/README +++ /dev/null @@ -1,26 +0,0 @@ -This directory contains several examples that illustrate how to use -various concurrency mechanisms to schedule and handle timer-based -events. All programs are interactive and utilize a common timer queue -test framework. You can schedule or cancel time events and list all -the timers that are waiting to be triggered. - -The tests include: - -Reactor_Timer_Queue_Test: -------------------------- - -This example shows how to use ACE_Reactor as the timer queue -management mechanism. - -Thread_Timer_Queue_Test: ------------------------- - -This example shows how to use threads as the mechanism to generate -timer queue events. - -Async_Timer_Queue_Test: ------------------------ - -This example shows how to use singals as the mechanism to generate -timer queue events. It doesn't work on NT because of NT's limited -signal mechanism, i.e., no support for SIGALRM. diff --git a/examples/Timer_Queue/Reactor_Timer_Queue_Test.cpp b/examples/Timer_Queue/Reactor_Timer_Queue_Test.cpp deleted file mode 100644 index d48694dc72b..00000000000 --- a/examples/Timer_Queue/Reactor_Timer_Queue_Test.cpp +++ /dev/null @@ -1,231 +0,0 @@ -// $Id$ - -// ============================================================================ -// = LIBRARY -// examples -// -// = FILENAME -// Reactor_Timer_Queue_Test -// -// = DESCRIPTION -// This example tests the timer queue mechanism of ACE_Reactor. -// -// = AUTHOR -// Nanbor Wang <nw1@cs.wustl.edu> and -// Sergio Flores-Gaitan <sergio@cs.wustl.edu> -// -// ============================================================================ - -#include "ace/OS_NS_sys_time.h" -#include "ace/Thread_Manager.h" -#include "ace/Select_Reactor.h" -#include "ace/Reactor.h" -#include "ace/Timer_Heap.h" - -#include "Driver.h" -#include "Reactor_Timer_Queue_Test.h" - -#if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION) -template class Timer_Queue_Test_Driver <ACE_Timer_Heap, Input_Handler, Input_Handler::ACTION>; -template class Command<Input_Handler, Input_Handler::ACTION>; -#elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA) -#pragma instantiate Timer_Queue_Test_Driver <ACE_Timer_Heap, Input_Handler, Input_Handler::ACTION> -#pragma instantiate Command<Input_Handler, Input_Handler::ACTION> -#endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */ - -ACE_RCSID(Timer_Queue, Reactor_Timer_Queue_Test, "$Id$") - -void -Reactor_Timer_Handler::set_timer_id (long tid) -{ - this->tid_ = tid; -} - -int -Reactor_Timer_Handler::handle_timeout (const ACE_Time_Value &tv, - const void *) -{ - // Macro to avoid "warning: unused parameter" type warning. - ACE_UNUSED_ARG (tv); - - 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) -{ - this->tq_ = tq; -} - -int -Input_Handler::done (void) -{ - return this->done_; -} - -int -Input_Handler::schedule_timer (void *argument) -{ - int delay = *(int *) argument; - Reactor_Timer_Handler *th; - long tid; - - th = new Reactor_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); -} - -int -Input_Handler::shutdown_timer (void *argument) -{ - // Macro to avoid "warning: unused parameter" type warning. - ACE_UNUSED_ARG (argument); - - this->done_ = 1; - ACE_DEBUG ((LM_DEBUG, - "Shutting down event loop\n")); - return -1; -} - -int -Input_Handler::list_timer (void *argument) -{ - // Macro to avoid "warning: unused parameter" type warning. - ACE_UNUSED_ARG (argument); - - 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 ())); - } - return 0; -} - -int -Input_Handler::handle_input (ACE_HANDLE) -{ - return driver_.get_next_request (); -} - -Reactor_Timer_Queue_Test_Driver::Reactor_Timer_Queue_Test_Driver (void) - : thandler_ (&timer_queue_, *this) -{ -} - -Reactor_Timer_Queue_Test_Driver::~Reactor_Timer_Queue_Test_Driver (void) -{ -} - -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)); - return 0; -} - -int -Reactor_Timer_Queue_Test_Driver::init (void) -{ - typedef Command<Input_Handler, Input_Handler::ACTION> CMD; - - // initialize <Command>s with their corresponding <Input_Handler> methods. - ACE_NEW_RETURN (schedule_cmd_, - CMD (thandler_, &Input_Handler::schedule_timer), - -1); - - ACE_NEW_RETURN (cancel_cmd_, - CMD (thandler_, &Input_Handler::cancel_timer), - -1); - - ACE_NEW_RETURN (list_cmd_, - CMD (thandler_, &Input_Handler::list_timer), - -1); - - ACE_NEW_RETURN (shutdown_cmd_, - CMD (thandler_, &Input_Handler::shutdown_timer), - -1); - - ACE_Reactor::instance ()->timer_queue (&timer_queue_); - - ACE_Event_Handler::register_stdin_handler (&thandler_, - ACE_Reactor::instance (), - ACE_Thread_Manager::instance ()); - - // print the menu of options. - this->display_menu (); - - return 0; -} - -// run test was overrun due to the reactive way of handling input. - -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) - ACE_Reactor::instance ()->handle_events (); - - ACE_DEBUG ((LM_DEBUG, - "TIMER TEST ENDED\n")); - return 0; -} diff --git a/examples/Timer_Queue/Reactor_Timer_Queue_Test.h b/examples/Timer_Queue/Reactor_Timer_Queue_Test.h deleted file mode 100644 index 3db20728814..00000000000 --- a/examples/Timer_Queue/Reactor_Timer_Queue_Test.h +++ /dev/null @@ -1,153 +0,0 @@ -/* -*- C++ -*- */ - -// $Id$ - -// ============================================================================ -// -// = LIBRARY -// examples -// -// = FILENAME -// Reactor_Timer_Queue_Test.h -// -// = DESCRIPTION -// This code is an implementation of a test driver for a reactor based -// timer queue. -// -// = AUTHORS -// Nanbor Wang <nw1@cs.wustl.edu> and -// Sergio Flores-Gaitan <sergio@cs.wustl.edu> -// -// ============================================================================ - -#ifndef _REACTOR_TIMER_QUEUE_TEST_H_ -#define _REACTOR_TIMER_QUEUE_TEST_H_ - -#include "Driver.h" - -#if !defined (ACE_LACKS_PRAGMA_ONCE) -# pragma once -#endif /* ACE_LACKS_PRAGMA_ONCE */ - -/// @@todo: Not sure why this needs to be included. But am sure that, -/// there is some circular dependency setup. Needs to be -/// fixed. Atleast on g++ -#include "ace/Timer_Queue.h" -#include "ace/Timer_Heap.h" -#include "ace/svc_export.h" - -class Reactor_Timer_Queue_Test_Driver; - -class Input_Handler : public ACE_Event_Handler -{ - // = TITLE - // Implements the handler to be called for input events. Also has - // the logic to handle the different timer queue operations (i.e., - // schedule, cancel, list, shutdown). - // - // = DESCRIPTION - // This class handles the reading of user input from stdin. Also - // has the logic to handle the commands that are to be invoked in - // response to the user input. -public: - typedef int (Input_Handler::*ACTION) (void *); - - Input_Handler (ACE_Timer_Queue *tq, - Reactor_Timer_Queue_Test_Driver &timer_queue_driver); - // Sets <done_> flag to 0, <driver_> to <timer_queue_driver> and - // timer queue <tq_> to <tq> - - int handle_input (ACE_HANDLE); - // Hook method for the <ACE_Reactor> to call whenever there is input - // ready to be read. - - int done (void); - // returns the value for <done_> that indicates whether we are - // exiting the program.A value of 0 indicates that we are NOT done, - // 1 otherwise. - - // = Hook methods to be called from <Reactor_Timer_Queue_Test_Driver> - - int schedule_timer (void *argument); - // Schedule a timer. The (void *) will be mapped to the delay - // parameter for the timer queue schedule method. - - int cancel_timer (void *argument); - // Cancel a timer. The (void *) will be mapped to the ID of the - // timer being cancelled. - - int list_timer (void *argument); - // Dump the timers in the queue. The argument is ignored. - - int shutdown_timer (void *argument); - // Processes the request to exit the timer queue application. - // argument is ignored. - -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_; - // Test driver. Used to call hook methods that are common code for - // all drivers. -}; - -class ACE_Svc_Export Reactor_Timer_Queue_Test_Driver : public Timer_Queue_Test_Driver <ACE_Timer_Heap, Input_Handler, Input_Handler::ACTION> -{ - // = TITLE - // Implements a test driver for a reactive timer queue using - // <ACE_Reactor>. - // - // = DESCRIPTION - // This class implements the logic to test the reactor - // implementation of timer queue, using an <ACE_Timer_Heap>. -public: - Reactor_Timer_Queue_Test_Driver (void); - // Sets the input handler <thandler_> with <timer_queue_> from the - // <Timer_Queue_Test_Driver> class and a reference to "this", so the - // input handler can call hook methods from the driver. Such - // methods are the common factored out code from other - // implementations of timer queues. - - virtual ~Reactor_Timer_Queue_Test_Driver (void); - // Default destructor - - virtual int display_menu (void); - // Prints the menu of options. - - virtual int init (void); - // Sets the timer queue that the REACTOR will use; registers the - // stdin input handler with the REACTOR and sets the <Command>s that - // the <Timer_Queue_Test_Driver> will execute(). - - virtual int run_test (void); - // Main entry point to the test driver implementation. - -private: - Input_Handler thandler_; - // This is the stdin handler. -}; - -class Reactor_Timer_Handler : public ACE_Event_Handler -{ - // = TITLE - // Target of the reactive timeout operation. -public: - virtual int handle_timeout (const ACE_Time_Value &tv, - const void *); - // Hook method that is called by the reactor when a timer expires. - // It prints the timer ID and the time it expired. - - void set_timer_id (long tid); - // Sets the timer id for this handler <tid_> to <tid> - -private: - long tid_; - // timer ID. -}; - -#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 deleted file mode 100644 index ceafaef5fe9..00000000000 --- a/examples/Timer_Queue/Thread_Timer_Queue_Test.cpp +++ /dev/null @@ -1,307 +0,0 @@ -// $Id$ - -// ============================================================================ -// -// = LIBRARY -// examples -// -// = FILENAME -// Thread_Timer_Queue_Test.cpp -// -// = DESCRIPTION -// This test exercises the <ACE_Thread_Timer_Queue_Adapter> -// using an <ACE_Timer_Heap>. -// -// = AUTHORS -// Carlos O'Ryan <coryan@cs.wustl.edu> and -// Douglas C. Schmidt <schmidt@cs.wustl.edu> -// -// ============================================================================ - -#include "ace/OS_NS_stdio.h" -#include "ace/OS_NS_sys_time.h" -#include "ace/Task.h" -#include "ace/Timer_Heap_T.h" -#include "ace/Timer_Queue_Adapters.h" - -#include "Thread_Timer_Queue_Test.h" - -#include "ace/Condition_T.h" -#include "ace/Thread_Mutex.h" - -#if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION) -template class ACE_Thread_Timer_Queue_Adapter<Timer_Heap>; -template class Timer_Queue_Test_Driver<Thread_Timer_Queue, - Input_Task, - Input_Task::ACTION>; -template class Command<Input_Task, Input_Task::ACTION>; -#elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA) -#pragma instantiate ACE_Thread_Timer_Queue_Adapter<Timer_Heap> -#pragma instantiate Timer_Queue_Test_Driver<Thread_Timer_Queue, \ - Input_Task, \ - Input_Task::ACTION> -#pragma instantiate Command<Input_Task, Input_Task::ACTION> -#endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */ - -#if defined (ACE_MT_SAFE) && (ACE_MT_SAFE != 0) -// These templates will specialized in libACE.* if the platforms does -// not define ACE_MT_SAFE. - -#if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION) -template class ACE_Thread_Condition<ACE_Thread_Mutex>; -template class ACE_Condition<ACE_Thread_Mutex>; -template class ACE_Event_Handler_Handle_Timeout_Upcall<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_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_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_Thread_Condition<ACE_Thread_Mutex> -#pragma instantiate ACE_Condition<ACE_Thread_Mutex> -#pragma instantiate ACE_Event_Handler_Handle_Timeout_Upcall<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_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_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 */ - -ACE_RCSID(Timer_Queue, Thread_Timer_Queue_Test, "$Id$") - -// Administrivia methods... -Handler::Handler(const ACE_Time_Value &expiration_time) - : expires_ (expiration_time), - id_ (0) -{ -} - -Handler::~Handler (void) -{ -} - -void -Handler::set_id (int id) -{ - this->id_ = id; -} - -// This is the method invoked when the Timer expires. - -int -Handler::handle_timeout (const ACE_Time_Value ¤t_time, - 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 %lu.%7.7lu secs\n" - "\tthere was a %lu.%7.7lu secs delay\n", - this->id_, - current_time.sec (), - current_time.usec (), - delay.sec (), - delay.usec ()); - // Notice this delete is protected. - delete this; - return 0; -} - -Input_Task::Input_Task (Thread_Timer_Queue *queue, - Thread_Timer_Queue_Test_Driver &timer_queue_driver) - : ACE_Task_Base (ACE_Thread_Manager::instance ()), - queue_ (queue), - usecs_ (ACE_ONE_SECOND_IN_USECS), - driver_ (timer_queue_driver) -{ -} - -// Svc method is called from the thread library to read input from the -// user. - -int -Input_Task::svc (void) -{ - for (;;) - // call back to the driver's implementation on how to read and - // parse input. - if (this->driver_.get_next_request () == -1) - break; - - // we are done. - this->queue_->deactivate (); - ACE_DEBUG ((LM_DEBUG, - "terminating input thread\n")); - return 0; -} - -// schedule a new timer. This method will be called from inside the -// <Timer_Queue_Test_Driver> class. (see Command pattern) - -int -Input_Task::add_timer (void *argument) -{ - u_long useconds = *reinterpret_cast<int *> (argument); - ACE_Time_Value interval (useconds / usecs_, - useconds % usecs_); - ACE_Time_Value expire_at = ACE_OS::gettimeofday () + interval; - - Handler *h; - - 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); - - // We store the id into the handler, this is only used to produce - // nicer messages. - h->set_id (id); - - ACE_OS::printf ("scheduling timer %d\n", - id); - return 0; -} - -// Cancel a timer. This method will be called from inside the -// <Timer_Queue_Test_Driver> class. (see Command pattern) - -int -Input_Task::cancel_timer (void *argument) -{ - return this->queue_->cancel (*reinterpret_cast<int *> (argument)); -} - -// Lists the timers in the queue. Ignores the argument. This method -// will be called from inside the <Timer_Queue_Test_Driver> class. -// (see Command pattern) - -int -Input_Task::list_timer (void *argument) -{ - // Macro to avoid "warning: unused parameter" type warning. - ACE_UNUSED_ARG (argument); - - // Dump the timer queue contents. - this->dump (); - - return 0; -} - -// Shutdown the timer queue. Return -1 indicates to the -// <Timer_Queue_Test_Driver> class that we are done. - -int -Input_Task::shutdown_timer (void *argument) -{ - // Macro to avoid "warning: unused parameter" type warning. - ACE_UNUSED_ARG (argument); - -#if defined (ACE_LACKS_PTHREAD_CANCEL) - // Cancel the thread timer queue task "voluntarily." - this->queue_->deactivate (); -#else - // Cancel the thread timer queue task "preemptively." - if (ACE_Thread::cancel (this->queue_->thr_id ()) == -1) - ACE_ERROR ((LM_ERROR, - "%p\n", - "cancel")); -#endif /* ACE_LACKS_PTHREAD_CANCEL */ - - // -1 indicates we are shutting down the application. - return -1; -} - -void -Input_Task::dump (void) -{ - ACE_GUARD (ACE_SYNCH_RECURSIVE_MUTEX, ace_mon, this->queue_->mutex ()); - - ACE_DEBUG ((LM_DEBUG, - "begin dumping timer queue\n")); - - for (Timer_Heap_Iterator i (*this->queue_->timer_queue ()); - i.item () != 0; - i.next ()) - i.item ()->dump (); - - ACE_DEBUG ((LM_DEBUG, - "end dumping timer queue\n")); -} - -// constructor - -Thread_Timer_Queue_Test_Driver::Thread_Timer_Queue_Test_Driver (void) - : input_task_ (&timer_queue_, *this) -{ -} - -Thread_Timer_Queue_Test_Driver::~Thread_Timer_Queue_Test_Driver (void) -{ -} - -int -Thread_Timer_Queue_Test_Driver::run_test (void) -{ - this->init (); - 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 -Thread_Timer_Queue_Test_Driver::init (void) -{ - typedef Command<Input_Task, Input_Task::ACTION> CMD; - - // initialize the <Command> objects with their corresponding - // methods from <Input_Task> - ACE_NEW_RETURN (schedule_cmd_, - CMD (input_task_, &Input_Task::add_timer), - -1); - - ACE_NEW_RETURN (cancel_cmd_, - CMD (input_task_, &Input_Task::cancel_timer), - -1); - - ACE_NEW_RETURN (list_cmd_, - CMD (input_task_, &Input_Task::list_timer), - -1); - - ACE_NEW_RETURN (shutdown_cmd_, - CMD (input_task_, &Input_Task::shutdown_timer), - -1); - - if (this->input_task_.activate () == -1) - ACE_ERROR_RETURN ((LM_ERROR, - "cannot activate input task"), - -1); - else if (this->timer_queue_.activate () == -1) - ACE_ERROR_RETURN ((LM_ERROR, - "cannot activate timer queue"), - -1); - else if (ACE_Thread_Manager::instance ()->wait () == -1) - ACE_ERROR_RETURN ((LM_ERROR, - "wait on Thread_Manager failed"), - -1); - return 0; -} diff --git a/examples/Timer_Queue/Thread_Timer_Queue_Test.h b/examples/Timer_Queue/Thread_Timer_Queue_Test.h deleted file mode 100644 index 573df6121f8..00000000000 --- a/examples/Timer_Queue/Thread_Timer_Queue_Test.h +++ /dev/null @@ -1,157 +0,0 @@ -/* -*- C++ -*- */ - -// $Id$ - -// ============================================================================ -// -// = LIBRARY -// examples -// -// = FILENAME -// Thread_Timer_Queue_Test.h -// -// = DESCRIPTION -// This code exercises the <ACE_Thread_Timer_Queue_Adapter> using -// an <ACE_Timer_Heap_T>. -// -// = AUTHORS -// Carlos O'Ryan <coryan@cs.wustl.edu> and -// Sergio Flores-Gaitan <sergio@cs.wustl.edu> -// -// ============================================================================ - -#ifndef _THREAD_TIMER_QUEUE_TEST_H_ -#define _THREAD_TIMER_QUEUE_TEST_H_ - -#include "ace/Task.h" - -#if !defined (ACE_LACKS_PRAGMA_ONCE) -# pragma once -#endif /* ACE_LACKS_PRAGMA_ONCE */ - -#include "ace/Null_Mutex.h" -#include "ace/Timer_Heap_T.h" -#include "ace/Timer_Queue_Adapters.h" -#include "ace/svc_export.h" -#include "ace/Condition_Recursive_Thread_Mutex.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 *, - Upcall, - ACE_Null_Mutex> - Timer_Heap; -typedef ACE_Timer_Heap_Iterator_T<ACE_Event_Handler *, - Upcall, - ACE_Null_Mutex> - Timer_Heap_Iterator; -typedef ACE_Thread_Timer_Queue_Adapter<Timer_Heap> - Thread_Timer_Queue; - -// Forward declaration. -class Thread_Timer_Queue_Test_Driver; - -class Input_Task : public ACE_Task_Base -{ - // = 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: - typedef int (Input_Task::*ACTION) (void *); - - Input_Task (Thread_Timer_Queue *queue, - Thread_Timer_Queue_Test_Driver &timer_queue_driver); - - virtual int svc (void); - // This method runs the event loop in 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. - - Thread_Timer_Queue_Test_Driver &driver_; - // The thread timer queue test driver. -}; - -class ACE_Svc_Export Thread_Timer_Queue_Test_Driver : public Timer_Queue_Test_Driver <Thread_Timer_Queue, Input_Task, Input_Task::ACTION> -{ - // = TITLE - // Implements an example application that exercises - // <Thread_Timer_Queue> timer queue. - // - // = DESCRIPTION - // This class implements a simple test driver for the - // <Thread_Timer_Queue>. The <display_menu> hook method is - // called from the base class to print a menu specific to the - // thread implementation of the timer queue. -public: - Thread_Timer_Queue_Test_Driver (void); - ~Thread_Timer_Queue_Test_Driver (void); - - virtual int display_menu (void); - virtual int init (void); - virtual int run_test (void); - -private: - Input_Task input_task_; - // Subclassed from ACE_Task. -}; - -class Handler : public ACE_Event_Handler -{ - // = TITLE - // Event handler for the timer queue timeout events. - // - // = DESCRIPTION - // The <handle_timeout> hook method prints out the current time, - // prints the time when this timer expired and deletes "this". -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. - -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. -}; - -#endif /* _THREAD_TIMER_QUEUE_TEST_H_ */ diff --git a/examples/Timer_Queue/Timer_Queue.mpc b/examples/Timer_Queue/Timer_Queue.mpc deleted file mode 100644 index 04026c0babd..00000000000 --- a/examples/Timer_Queue/Timer_Queue.mpc +++ /dev/null @@ -1,40 +0,0 @@ -// -*- MPC -*- -// $Id$ - -project(*Library) : acelib { - sharedname = tqtd - dynamicflags += ACE_BUILD_SVC_DLL - Source_Files { - Async_Timer_Queue_Test.cpp - Driver.cpp - Reactor_Timer_Queue_Test.cpp - Thread_Timer_Queue_Test.cpp - } -} - -project(*Async) : aceexe { - exename = Asynch_Timer_Queue_Test - after += Timer_Queue_Library - libs += tqtd - Source_Files { - main_async.cpp - } -} - -project(*Reactor) : aceexe { - exename = Reactor_Timer_Queue_Test - after += Timer_Queue_Library - libs += tqtd - Source_Files { - main_reactor.cpp - } -} - -project(*Thread) : aceexe { - exename = Thread_Timer_Queue_Test - after += Timer_Queue_Library - libs += tqtd - Source_Files { - main_thread.cpp - } -} diff --git a/examples/Timer_Queue/main_async.cpp b/examples/Timer_Queue/main_async.cpp deleted file mode 100644 index 7cb90111fde..00000000000 --- a/examples/Timer_Queue/main_async.cpp +++ /dev/null @@ -1,66 +0,0 @@ -// $Id$ - -// ============================================================================ -// -// = 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> -// -// ============================================================================ - -// The following #pragma is needed to disable a warning that occurs -// in MSVC 6 due to the overly long debugging symbols generated for -// the std::auto_ptr<Timer_Queue_Test_Driver<...> > template -// instance used by some of the methods in this file. -#ifdef _MSC_VER -# pragma warning(disable: 4786) /* identifier was truncated to '255' - characters in the browser - information */ -#endif /* _MSC_VER */ - -#include "ace/OS_main.h" -#include "ace/Auto_Ptr.h" -#include "Driver.h" -#include "Async_Timer_Queue_Test.h" - -ACE_RCSID (Timer_Queue, - main_async, - "$Id$") - -typedef Timer_Queue_Test_Driver<Async_Timer_Queue *, - Async_Timer_Queue, - Async_Timer_Queue::ACTION> - ASYNC_TIMER_QUEUE_TEST_DRIVER; - -int -ACE_TMAIN (int, ACE_TCHAR *[]) -{ - ASYNC_TIMER_QUEUE_TEST_DRIVER *tqtd; - ACE_NEW_RETURN (tqtd, Async_Timer_Queue_Test_Driver, -1); - // Auto ptr ensures that the driver memory is released - // automatically. - auto_ptr <ASYNC_TIMER_QUEUE_TEST_DRIVER> driver (tqtd); - - return driver->run_test (); -} - -#if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION) -template class auto_ptr <ASYNC_TIMER_QUEUE_TEST_DRIVER>; -template class ACE_Auto_Basic_Ptr <ASYNC_TIMER_QUEUE_TEST_DRIVER>; -#elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA) -#pragma instantiate auto_ptr <ASYNC_TIMER_QUEUE_TEST_DRIVER> -#pragma instantiate ACE_Auto_Basic_Ptr <ASYNC_TIMER_QUEUE_TEST_DRIVER> -#endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */ - - diff --git a/examples/Timer_Queue/main_reactor.cpp b/examples/Timer_Queue/main_reactor.cpp deleted file mode 100644 index 76088bc5287..00000000000 --- a/examples/Timer_Queue/main_reactor.cpp +++ /dev/null @@ -1,70 +0,0 @@ -// $Id$ - -// ============================================================================ -// -// = 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> -// -// ============================================================================ - -// The following #pragma is needed to disable a warning that occurs -// in MSVC 6 due to the overly long debugging symbols generated for -// the std::auto_ptr<Timer_Queue_Test_Driver<...> > template -// instance used by some of the methods in this file. -#ifdef _MSC_VER -# pragma warning(disable: 4786) /* identifier was truncated to '255' - characters in the browser - information */ -#endif /* _MSC_VER */ - -#include "ace/OS_main.h" -#include "ace/Auto_Ptr.h" -#include "Reactor_Timer_Queue_Test.h" -#include "Driver.h" - -ACE_RCSID (Timer_Queue, - main_reactor, - "$Id$") - -typedef Timer_Queue_Test_Driver <ACE_Timer_Heap, - Input_Handler, - Input_Handler::ACTION> - REACTOR_TIMER_QUEUE_TEST_DRIVER; - -int -ACE_TMAIN (int, ACE_TCHAR *[]) -{ - REACTOR_TIMER_QUEUE_TEST_DRIVER *tqtd; - ACE_NEW_RETURN (tqtd, Reactor_Timer_Queue_Test_Driver, -1); - // Auto ptr ensures that the driver memory is released - // automatically. - auto_ptr <REACTOR_TIMER_QUEUE_TEST_DRIVER> driver (tqtd); - - return driver->run_test (); -} - -#if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION) -template class auto_ptr <REACTOR_TIMER_QUEUE_TEST_DRIVER>; -template class ACE_Auto_Basic_Ptr <REACTOR_TIMER_QUEUE_TEST_DRIVER>; -template class Timer_Queue_Test_Driver<ACE_Timer_Heap *, - Input_Handler, - Input_Handler::ACTION>; -#elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA) -#pragma instantiate auto_ptr <REACTOR_TIMER_QUEUE_TEST_DRIVER> -#pragma instantiate ACE_Auto_Basic_Ptr <REACTOR_TIMER_QUEUE_TEST_DRIVER> -#pragma instantiate Timer_Queue_Test_Driver<ACE_Timer_Heap *, \ - Input_Handler, \ - Input_Handler::ACTION> -#endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */ diff --git a/examples/Timer_Queue/main_thread.cpp b/examples/Timer_Queue/main_thread.cpp deleted file mode 100644 index 3f8aba5866e..00000000000 --- a/examples/Timer_Queue/main_thread.cpp +++ /dev/null @@ -1,65 +0,0 @@ -// $Id$ - -// ============================================================================ -// -// = 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> -// -// ============================================================================ - -// The following #pragma is needed to disable a warning that occurs -// in MSVC 6 due to the overly long debugging symbols generated for -// the std::auto_ptr<Timer_Queue_Test_Driver<...> > template -// instance used by some of the methods in this file. -#ifdef _MSC_VER -# pragma warning(disable: 4786) /* identifier was truncated to '255' - characters in the browser - information */ -#endif /* _MSC_VER */ - -#include "ace/OS_main.h" -#include "ace/Auto_Ptr.h" -#include "Driver.h" -#include "Thread_Timer_Queue_Test.h" - -ACE_RCSID (Timer_Queue, - main_thread, - "$Id$") - -typedef Timer_Queue_Test_Driver<Thread_Timer_Queue, - Input_Task, - Input_Task::ACTION> - THREAD_TIMER_QUEUE_TEST_DRIVER; - -int -ACE_TMAIN (int, ACE_TCHAR *[]) -{ - // Auto ptr ensures that the driver memory is released - // automatically. - THREAD_TIMER_QUEUE_TEST_DRIVER *tqtd; - ACE_NEW_RETURN (tqtd, Thread_Timer_Queue_Test_Driver, -1); - - auto_ptr <THREAD_TIMER_QUEUE_TEST_DRIVER> driver (tqtd); - - return driver->run_test (); -} - -#if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION) -template class auto_ptr <THREAD_TIMER_QUEUE_TEST_DRIVER>; -template class ACE_Auto_Basic_Ptr <THREAD_TIMER_QUEUE_TEST_DRIVER>; -#elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA) -#pragma instantiate auto_ptr <THREAD_TIMER_QUEUE_TEST_DRIVER> -#pragma instantiate ACE_Auto_Basic_Ptr <THREAD_TIMER_QUEUE_TEST_DRIVER> -#endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */ |