summaryrefslogtreecommitdiff
path: root/ACE/examples
diff options
context:
space:
mode:
authorJohnny Willemsen <jwillemsen@remedy.nl>2010-05-06 12:02:19 +0000
committerJohnny Willemsen <jwillemsen@remedy.nl>2010-05-06 12:02:19 +0000
commitbf1acc9439e756967791344c0e68ae1f51e8403d (patch)
treea4cbf42377f9f59aa7b58df8f77f63b6318be02c /ACE/examples
parent8c01d14216040bebd1a338dab9044f282e84d28a (diff)
downloadATCD-bf1acc9439e756967791344c0e68ae1f51e8403d.tar.gz
Thu May 6 12:01:16 UTC 2010 Johnny Willemsen <jwillemsen@remedy.nl>
* examples/Timer_Queue/Async_Timer_Queue_Test.h: * examples/Timer_Queue/Async_Timer_Queue_Test.cpp: * examples/Timer_Queue/Custom_Handler.h: * examples/Timer_Queue/Custom_Handler.cpp: * examples/Timer_Queue/Driver.h: * examples/Timer_Queue/Driver.cpp: * examples/Timer_Queue/Reactor_Timer_Queue_Test.h: * examples/Timer_Queue/Reactor_Timer_Queue_Test.cpp: * examples/Timer_Queue/Thread_Timer_Queue_Custom_Handler_Test.h: * examples/Timer_Queue/Thread_Timer_Queue_Custom_Handler_Test.cpp: * examples/Timer_Queue/Thread_Timer_Queue_Test.h: * examples/Timer_Queue/Thread_Timer_Queue_Test.cpp: * examples/Timer_Queue/Timer_Queue.mpc: * examples/Timer_Queue/main_async.cpp: * examples/Timer_Queue/main_reactor.cpp: * examples/Timer_Queue/main_thread.cpp: * examples/Timer_Queue/main_thread_custom_handler.cpp: Converted to doxygen style and added a seperate example that uses a thread timer queue with customer event handler.
Diffstat (limited to 'ACE/examples')
-rw-r--r--ACE/examples/Timer_Queue/Async_Timer_Queue_Test.cpp34
-rw-r--r--ACE/examples/Timer_Queue/Async_Timer_Queue_Test.h112
-rw-r--r--ACE/examples/Timer_Queue/Custom_Handler.cpp115
-rw-r--r--ACE/examples/Timer_Queue/Custom_Handler.h141
-rw-r--r--ACE/examples/Timer_Queue/Driver.cpp33
-rw-r--r--ACE/examples/Timer_Queue/Driver.h131
-rw-r--r--ACE/examples/Timer_Queue/Reactor_Timer_Queue_Test.cpp31
-rw-r--r--ACE/examples/Timer_Queue/Reactor_Timer_Queue_Test.h153
-rw-r--r--ACE/examples/Timer_Queue/Thread_Timer_Queue_Custom_Handler_Test.cpp230
-rw-r--r--ACE/examples/Timer_Queue/Thread_Timer_Queue_Custom_Handler_Test.h127
-rw-r--r--ACE/examples/Timer_Queue/Thread_Timer_Queue_Test.cpp34
-rw-r--r--ACE/examples/Timer_Queue/Thread_Timer_Queue_Test.h118
-rw-r--r--ACE/examples/Timer_Queue/Timer_Queue.mpc10
-rw-r--r--ACE/examples/Timer_Queue/main_async.cpp46
-rw-r--r--ACE/examples/Timer_Queue/main_reactor.cpp46
-rw-r--r--ACE/examples/Timer_Queue/main_thread.cpp46
-rw-r--r--ACE/examples/Timer_Queue/main_thread_custom_handler.cpp45
17 files changed, 1042 insertions, 410 deletions
diff --git a/ACE/examples/Timer_Queue/Async_Timer_Queue_Test.cpp b/ACE/examples/Timer_Queue/Async_Timer_Queue_Test.cpp
index d139bca0c87..5e4058feae6 100644
--- a/ACE/examples/Timer_Queue/Async_Timer_Queue_Test.cpp
+++ b/ACE/examples/Timer_Queue/Async_Timer_Queue_Test.cpp
@@ -1,22 +1,18 @@
-// $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>
-//
-// ============================================================================
+
+//=============================================================================
+/**
+ * @file Async_Timer_Queue_Test.cpp
+ *
+ * $Id$
+ *
+ * This test exercises the <ACE_Asynch_Timer_Queue_Adapter>
+ * using an <ACE_Timer_Heap>.
+ *
+ *
+ * @author 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"
diff --git a/ACE/examples/Timer_Queue/Async_Timer_Queue_Test.h b/ACE/examples/Timer_Queue/Async_Timer_Queue_Test.h
index 6b166f894c3..e9d7aef22b1 100644
--- a/ACE/examples/Timer_Queue/Async_Timer_Queue_Test.h
+++ b/ACE/examples/Timer_Queue/Async_Timer_Queue_Test.h
@@ -1,23 +1,20 @@
/* -*- 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
-// ============================================================================
+
+//=============================================================================
+/**
+ * @file Async_Timer_Queue_Test.h
+ *
+ * $Id$
+ *
+ * This test exercises the <ACE_Asynch_Timer_Queue_Adapter>
+ * using an <ACE_Timer_Heap>.
+ *
+ *
+ * @author Douglas C. Schmidt and Sergio Flores-Gaitan
+ */
+//=============================================================================
+
#ifndef _ASYNC_TIMER_QUEUE_TEST_H_
#define _ASYNC_TIMER_QUEUE_TEST_H_
@@ -34,86 +31,93 @@
#include "Driver.h"
+/**
+ * @class Async_Timer_Handler
+ *
+ * @brief Target of the asynchronous timeout operation.
+ */
class Async_Timer_Handler : public ACE_Event_Handler
{
- // = TITLE
- // Target of the asynchronous timeout operation.
public:
+ /// Callback hook invoked by the <Timer_Queue>.
virtual int handle_timeout (const ACE_Time_Value &tv,
const void *arg);
- // Callback hook invoked by the <Timer_Queue>.
};
+/**
+ * @class Async_Timer_Queue
+ *
+ * @brief Asynchronous Timer Queue Singleton.
+ *
+ * We use this class to avoid global variables and to
+ * consolidate all the Timer Queue processing in one central
+ * place.
+ */
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 *);
+ /// Singleton access point.
static Async_Timer_Queue *instance (void);
- // Singleton access point.
+ /// Schedule a timer to expire <microsecs> in the future.
void schedule (u_int microsecs);
- // Schedule a timer to expire <microsecs> in the future.
+ /// Cancel a timer with <timer_id>.
void cancel (long timer_id);
- // Cancel a timer with <timer_id>.
+ /// Dump the contents of the queue.
void dump (void);
- // Dump the contents of the queue.
+ /// hook method to schedule a timer. Called from
+ /// <Timer_Queue_Test_Driver>
int schedule_timer (void *argument);
- // hook method to schedule a timer. Called from
- // <Timer_Queue_Test_Driver>
+ /// hook method to cancel 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>
+ /// hook method to list timers. Called from
+ /// <Timer_Queue_Test_Driver>
int list_timer (void *argument);
- // hook method to list timers. Called from
- // <Timer_Queue_Test_Driver>
+ /// hook method to exit the timer queue. 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:
+ /// Private constructor enforces the Singleton.
Async_Timer_Queue (ACE_Sig_Set *);
- // Private constructor enforces the Singleton.
+ /// Pointer to the timer queue.
static Async_Timer_Queue *instance_;
- // Pointer to the timer queue.
+ /// The adapter is instantiated by an <ACE_Timer_Heap>.
ACE_Async_Timer_Queue_Adapter<ACE_Timer_Heap> tq_;
- // The adapter is instantiated by an <ACE_Timer_Heap>.
};
+/**
+ * @class Async_Timer_Queue_Test_Driver
+ *
+ * @brief Async_Timer_Queue_Test_Driver
+ *
+ * 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>.
+ */
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);
+ /// Print menu of options.
virtual int display_menu (void);
- // Print menu of options.
+ /// Initializes the driver's internal variables inherited from the parent
virtual int init (void);
- // Initializes the driver's internal variables inherited from the parent
};
#endif /* _ASYNC_TIMER_QUEUE_TEST_H_ */
diff --git a/ACE/examples/Timer_Queue/Custom_Handler.cpp b/ACE/examples/Timer_Queue/Custom_Handler.cpp
new file mode 100644
index 00000000000..003c38ccb61
--- /dev/null
+++ b/ACE/examples/Timer_Queue/Custom_Handler.cpp
@@ -0,0 +1,115 @@
+// $Id$
+// ============================================================================
+// = LIBRARY
+// examples
+//
+// = FILENAME
+// Custom_Handler.cpp
+//
+// = DESCRIPTION
+// This is a custom event handler to be used with the thread timer queue
+// adapter, and its appropriate upcall.
+//
+// = AUTHOR
+// Alon Diamant <diamant.alon@gmail.com
+//
+// ============================================================================
+
+#if !defined (_CUSTOM_HANDLER_CPP_)
+#define _CUSTOM_HANDLER_CPP_
+
+#include "Custom_Handler.h"
+#include "ace/OS_NS_stdio.h"
+
+Custom_Handler::Custom_Handler(const ACE_Time_Value &expiration_time)
+ : expires_ (expiration_time),
+ id_ (0)
+{
+}
+
+Custom_Handler::~Custom_Handler (void)
+{
+}
+
+void
+Custom_Handler::set_id (int id)
+{
+ this->id_ = id;
+}
+
+// This is the method invoked when the Timer expires.
+int
+Custom_Handler::on_timeout (const ACE_Time_Value &current_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;
+}
+
+int Custom_Handler_Upcall::registration(TTimerQueue& timer_queue, Custom_Handler* handler, const void* arg)
+{
+ ACE_TRACE(ACE_TEXT ("registration"));
+
+ return 0;
+}
+
+int Custom_Handler_Upcall::preinvoke(TTimerQueue& timer_queue, Custom_Handler* handler, const void* arg, int recurring_timer, const ACE_Time_Value& cur_time, const void*& upcall_act)
+{
+ ACE_TRACE(ACE_TEXT ("preinvoke"));
+
+ return 0;
+}
+
+int Custom_Handler_Upcall::timeout(TTimerQueue& timer_queue, Custom_Handler* handler, const void* arg, int recurring_timer, const ACE_Time_Value& cur_time)
+{
+ ACE_TRACE(ACE_TEXT ("timeout"));
+
+ // Do the actual timer call
+ handler->on_timeout(cur_time, arg);
+
+ return 0;
+}
+
+int Custom_Handler_Upcall::postinvoke(TTimerQueue& timer_queue, Custom_Handler* handler, const void* arg, int recurring_timer, const ACE_Time_Value& cur_time, const void* upcall_act)
+{
+ ACE_TRACE(ACE_TEXT ("postinvoke"));
+
+ return 0;
+}
+
+int Custom_Handler_Upcall::cancel_type(TTimerQueue& timer_queue, Custom_Handler* handler, int dont_call, int& requires_reference_counting)
+{
+ ACE_TRACE(ACE_TEXT ("cancel_type"));
+
+ return 0;
+}
+
+int Custom_Handler_Upcall::cancel_timer(TTimerQueue& timer_queue, Custom_Handler* handler, int dont_call, int requires_reference_counting)
+{
+ ACE_TRACE(ACE_TEXT ("cancel_timer"));
+ delete handler;
+ return 0;
+}
+
+int Custom_Handler_Upcall::deletion(TTimerQueue& timer_queue, Custom_Handler* handler, const void* arg)
+{
+ ACE_TRACE(ACE_TEXT ("deletion"));
+ delete handler;
+ return 0;
+}
+#endif /* _CUSTOM_HANDLER_CPP_ */
+
diff --git a/ACE/examples/Timer_Queue/Custom_Handler.h b/ACE/examples/Timer_Queue/Custom_Handler.h
new file mode 100644
index 00000000000..07948f09419
--- /dev/null
+++ b/ACE/examples/Timer_Queue/Custom_Handler.h
@@ -0,0 +1,141 @@
+/* -*- C++ -*- */
+
+// $Id$
+// ============================================================================
+//
+// = LIBRARY
+// examples
+//
+// = FILENAME
+// Custom_Handler.h
+//
+// = DESCRIPTION
+// This is a custom event handler to be used with the thread timer queue
+// adapter, and its appropriate upcall.
+//
+// = AUTHORS
+// Alon Diamant <diamant.alon@gmail.com>
+//
+// ============================================================================
+
+#ifndef _CUSTOM_HANDLER_H_
+#define _CUSTOM_HANDLER_H_
+
+#if !defined (ACE_LACKS_PRAGMA_ONCE)
+# pragma once
+#endif /* ACE_LACKS_PRAGMA_ONCE */
+
+#include "ace/Timer_Queue.h"
+
+class Custom_Handler
+{
+ // = TITLE
+ // Custom event handler for the timer queue timeout events.
+ //
+ // = DESCRIPTION
+ // The <on_timeout> hook method prints out the current time,
+ // prints the time when this timer expired and deletes "this".
+
+ public:
+
+ Custom_Handler (const ACE_Time_Value &expiration_time);
+
+ ~Custom_Handler (void);
+
+ // Set the custom handler's id
+ void set_id (int id);
+
+ // Call back hook.
+ virtual int on_timeout(const ACE_Time_Value &current_time,
+ const void *arg);
+
+ private:
+
+ // Store the expected time of expiration, it is used to print a nice
+ // message saying how much delay was at the actual expiration time.
+ ACE_Time_Value expires_;
+
+ // Store an "id" for the Handler, which is only use to print better
+ // messages.
+ int id_;
+};
+
+
+/// CWorkItemAndParamTupleUpcall
+///
+/// Implements the Upcall interface used by the ACE_Timer_Queue, specifically for the
+/// IWorkItem interface.
+class Custom_Handler_Upcall
+{
+ public:
+
+ typedef ACE_Timer_Queue_T<Custom_Handler*,
+ Custom_Handler_Upcall,
+ ACE_Null_Mutex> TTimerQueue;
+
+ // Default constructor
+ Custom_Handler_Upcall()
+ {
+ }
+
+ // Destructor.
+ ~Custom_Handler_Upcall()
+ {
+ }
+
+ // This method is called when a timer is registered.
+ int registration(TTimerQueue& timer_queue,
+ Custom_Handler* handler,
+ const void* arg);
+
+ // This method is called before the timer expires.
+ int preinvoke(TTimerQueue& timer_queue,
+ Custom_Handler* handler,
+ const void* arg,
+ int recurring_timer,
+ const ACE_Time_Value& cur_time,
+ const void*& upcall_act);
+
+ // This method is called when the timer expires.
+ int timeout (TTimerQueue& timer_queue,
+ Custom_Handler* handler,
+ const void* arg,
+ int recurring_timer,
+ const ACE_Time_Value& cur_time);
+
+ // This method is called after the timer expires.
+ int postinvoke(TTimerQueue& timer_queue,
+ Custom_Handler* handler,
+ const void* arg,
+ int recurring_timer,
+ const ACE_Time_Value& cur_time,
+ const void* upcall_act);
+
+ // This method is called when a handler is canceled
+ int cancel_type(TTimerQueue& timer_queue,
+ Custom_Handler* handler,
+ int dont_call,
+ int& requires_reference_counting);
+
+ // This method is called when a timer is canceled
+ int cancel_timer(TTimerQueue& timer_queue,
+ Custom_Handler* handler,
+ int dont_call,
+ int requires_reference_counting);
+
+ // This method is called when the timer queue is destroyed and
+ // the timer is still contained in it
+ int deletion(TTimerQueue& timer_queue,
+ Custom_Handler* handler,
+ const void* arg);
+};
+
+#if defined (ACE_TEMPLATES_REQUIRE_SOURCE)
+#include "Custom_Handler.cpp"
+#endif /* ACE_TEMPLATES_REQUIRE_SOURCE */
+
+#if defined (ACE_TEMPLATES_REQUIRE_PRAGMA)
+#pragma implementation ("Custom_Handler.cpp")
+#endif /* ACE_TEMPLATES_REQUIRE_PRAGMA */
+
+#endif
diff --git a/ACE/examples/Timer_Queue/Driver.cpp b/ACE/examples/Timer_Queue/Driver.cpp
index 20327d76dc1..f290b17b053 100644
--- a/ACE/examples/Timer_Queue/Driver.cpp
+++ b/ACE/examples/Timer_Queue/Driver.cpp
@@ -1,21 +1,18 @@
-// $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>
-//
-// ============================================================================
+
+//=============================================================================
+/**
+ * @file Driver.cpp
+ *
+ * $Id$
+ *
+ * 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_
diff --git a/ACE/examples/Timer_Queue/Driver.h b/ACE/examples/Timer_Queue/Driver.h
index 4677b904982..d927e2f60a0 100644
--- a/ACE/examples/Timer_Queue/Driver.h
+++ b/ACE/examples/Timer_Queue/Driver.h
@@ -1,23 +1,20 @@
/* -*- 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>
-//
-// ============================================================================
+
+//=============================================================================
+/**
+ * @file Driver.h
+ *
+ * $Id$
+ *
+ * This code builds an abstraction to factor out common code for
+ * the different implementations of the Timer_Queue.
+ *
+ *
+ * @author Sergio Flores-Gaitan <sergio@cs.wustl.edu>
+ */
+//=============================================================================
+
#ifndef _DRIVER_H_
#define _DRIVER_H_
@@ -31,99 +28,107 @@
#include "ace/Timer_Heap_T.h"
#include "ace/Timer_Queue_Adapters.h"
+/**
+ * @class Command
+ *
+ * @brief 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.
+ *
+ * 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.
+ */
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:
+ /// Sets the <receiver_> of the Command to recvr, and the
+ /// <action_> of the Command to <action>.
Command (RECEIVER &recvr, ACTION action);
- // Sets the <receiver_> of the Command to recvr, and the
- // <action_> of the Command to <action>.
virtual ~Command (void);
+ /// Invokes the method <action_> from the object <receiver_>.
virtual int execute (void *arg);
- // Invokes the method <action_> from the object <receiver_>.
private:
+ /// object where the method resides.
RECEIVER &receiver_;
- // object where the method resides.
+ /// method that is going to be invoked.
ACTION action_;
- // method that is going to be invoked.
};
+/**
+ * @class Timer_Queue_Test_Driver
+ *
+ * @brief Defines a class that provides a simmple implementation for
+ * a test driver for timer queues.
+ *
+ * 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.
+ */
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:
+ /// Default destructor
virtual ~Timer_Queue_Test_Driver (void);
- // Default destructor
+ /// Breaks up the input string buffer into pieces and executes
+ /// the appropriate method to handle that operation.
virtual int parse_commands (const char *buf);
- // Breaks up the input string buffer into pieces and executes
- // the appropriate method to handle that operation.
+ /**
+ * 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 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.
+ /// This internal method gets the next request from the user.
+ /// Returns -1 when user wants to exit. Returns 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.
+ /**
+ * 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.
+ */
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.
+ /// Prints the user interface for the driver to STDOUT.
virtual int display_menu (void)=0;
- // Prints the user interface for the driver to STDOUT.
+ /// Initializes values and operations for the driver.
virtual int init (void)=0;
- // Initializes values and operations for the driver.
protected:
+ /// timer queue
TQ timer_queue_;
- // timer queue
// = Set of <Command>s to be executed.
+ /// schedule timer command
Command<RECEIVER, ACTION> *schedule_cmd_;
- // schedule timer command
+ /// cancel timer command.
Command<RECEIVER, ACTION> *cancel_cmd_;
- // cancel timer command.
+ /// list timers command.
Command<RECEIVER, ACTION> *list_cmd_;
- // list timers command.
+ /// shutdown the driver.
Command<RECEIVER, ACTION> *shutdown_cmd_;
- // shutdown the driver.
};
#if defined (ACE_TEMPLATES_REQUIRE_SOURCE)
diff --git a/ACE/examples/Timer_Queue/Reactor_Timer_Queue_Test.cpp b/ACE/examples/Timer_Queue/Reactor_Timer_Queue_Test.cpp
index 714abed08e7..0b651ae4584 100644
--- a/ACE/examples/Timer_Queue/Reactor_Timer_Queue_Test.cpp
+++ b/ACE/examples/Timer_Queue/Reactor_Timer_Queue_Test.cpp
@@ -1,20 +1,17 @@
-// $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>
-//
-// ============================================================================
+
+//=============================================================================
+/**
+ * @file Reactor_Timer_Queue_Test
+ *
+ * $Id$
+ *
+ * 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"
diff --git a/ACE/examples/Timer_Queue/Reactor_Timer_Queue_Test.h b/ACE/examples/Timer_Queue/Reactor_Timer_Queue_Test.h
index 3db20728814..536732b52b8 100644
--- a/ACE/examples/Timer_Queue/Reactor_Timer_Queue_Test.h
+++ b/ACE/examples/Timer_Queue/Reactor_Timer_Queue_Test.h
@@ -1,24 +1,20 @@
/* -*- 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>
-//
-// ============================================================================
+
+//=============================================================================
+/**
+ * @file Reactor_Timer_Queue_Test.h
+ *
+ * $Id$
+ *
+ * This code is an implementation of a test driver for a reactor based
+ * timer queue.
+ *
+ *
+ * @author 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_
@@ -38,116 +34,129 @@
class Reactor_Timer_Queue_Test_Driver;
+/**
+ * @class Input_Handler
+ *
+ * @brief 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).
+ *
+ * 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.
+ */
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 *);
+ /// Sets <done_> flag to 0, <driver_> to <timer_queue_driver> and
+ /// timer queue <tq_> to <tq>
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>
+ /// Hook method for the <ACE_Reactor> to call whenever there is input
+ /// ready to be read.
int handle_input (ACE_HANDLE);
- // Hook method for the <ACE_Reactor> to call whenever there is input
- // ready to be read.
+ /**
+ * 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.
+ */
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>
+ /// Schedule a timer. The (void *) will be mapped to the delay
+ /// parameter for the timer queue schedule method.
int schedule_timer (void *argument);
- // Schedule a timer. The (void *) will be mapped to the delay
- // parameter for the timer queue schedule method.
+ /// Cancel a timer. The (void *) will be mapped to the ID of the
+ /// timer being cancelled.
int cancel_timer (void *argument);
- // Cancel a timer. The (void *) will be mapped to the ID of the
- // timer being cancelled.
+ /// Dump the timers in the queue. The argument is ignored.
int list_timer (void *argument);
- // Dump the timers in the queue. The argument is ignored.
+ /// Processes the request to exit the timer queue application.
+ /// argument is ignored.
int shutdown_timer (void *argument);
- // Processes the request to exit the timer queue application.
- // argument is ignored.
private:
+ /// Keep a pointer to the timer queue we are using so we can traverse
+ /// the queue.
ACE_Timer_Queue *tq_;
- // Keep a pointer to the timer queue we are using so we can traverse
- // the queue.
+ /// Flag used to close down program.
int done_;
- // Flag used to close down program.
+ /// Test driver. Used to call hook methods that are common code for
+ /// all drivers.
Reactor_Timer_Queue_Test_Driver &driver_;
- // Test driver. Used to call hook methods that are common code for
- // all drivers.
};
+/**
+ * @class Reactor_Timer_Queue_Test_Driver
+ *
+ * @brief Implements a test driver for a reactive timer queue using
+ * <ACE_Reactor>.
+ *
+ * This class implements the logic to test the reactor
+ * implementation of timer queue, using an <ACE_Timer_Heap>.
+ */
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:
+ /**
+ * 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.
+ */
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.
+ /// Default destructor
virtual ~Reactor_Timer_Queue_Test_Driver (void);
- // Default destructor
+ /// Prints the menu of options.
virtual int display_menu (void);
- // Prints the menu of options.
+ /**
+ * 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 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().
+ /// Main entry point to the test driver implementation.
virtual int run_test (void);
- // Main entry point to the test driver implementation.
private:
+ /// This is the stdin handler.
Input_Handler thandler_;
- // This is the stdin handler.
};
+/**
+ * @class Reactor_Timer_Handler
+ *
+ * @brief Target of the reactive timeout operation.
+ */
class Reactor_Timer_Handler : public ACE_Event_Handler
{
- // = TITLE
- // Target of the reactive timeout operation.
public:
+ /// Hook method that is called by the reactor when a timer expires.
+ /// It prints the timer ID and the time it expired.
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.
+ /// Sets the timer id for this handler <tid_> to <tid>
void set_timer_id (long tid);
- // Sets the timer id for this handler <tid_> to <tid>
private:
+ /// timer ID.
long tid_;
- // timer ID.
};
#endif /* _REACTOR_TIMER_QUEUE_TEST_H_ */
diff --git a/ACE/examples/Timer_Queue/Thread_Timer_Queue_Custom_Handler_Test.cpp b/ACE/examples/Timer_Queue/Thread_Timer_Queue_Custom_Handler_Test.cpp
new file mode 100644
index 00000000000..59b7b822e3b
--- /dev/null
+++ b/ACE/examples/Timer_Queue/Thread_Timer_Queue_Custom_Handler_Test.cpp
@@ -0,0 +1,230 @@
+// $Id$
+// ============================================================================
+//
+// = LIBRARY
+// examples
+//
+// = FILENAME
+// Thread_Timer_Queue_Custom_Handler_Test.cpp
+//
+// = DESCRIPTION
+// This test exercises the <ACE_Thread_Timer_Queue_Adapter>
+// using an <ACE_Timer_Heap>. It also demonstrates using a custom handler for
+// timer events.
+//
+// = AUTHORS
+// Carlos O'Ryan <coryan@cs.wustl.edu> and
+// Douglas C. Schmidt <schmidt@cs.wustl.edu> and
+// Alon Diamant <diamant.alon@gmail.com>
+//
+// ============================================================================
+
+#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_Custom_Handler_Test.h"
+
+#include "ace/Condition_T.h"
+#include "ace/Thread_Mutex.h"
+
+Custom_Handler_Input_Task::Custom_Handler_Input_Task (Thread_Timer_Queue *queue,
+ Thread_Timer_Queue_Custom_Handler_Test &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
+Custom_Handler_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
+Custom_Handler_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;
+
+ Custom_Handler *h;
+
+ ACE_NEW_RETURN (h,
+ Custom_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
+Custom_Handler_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
+Custom_Handler_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
+Custom_Handler_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
+Custom_Handler_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_Custom_Handler_Test::Thread_Timer_Queue_Custom_Handler_Test (void)
+ : input_task_ (&timer_queue_, *this)
+{
+}
+
+Thread_Timer_Queue_Custom_Handler_Test::~Thread_Timer_Queue_Custom_Handler_Test (void)
+{
+}
+
+int
+Thread_Timer_Queue_Custom_Handler_Test::run_test (void)
+{
+ this->init ();
+ return 0;
+}
+
+int
+Thread_Timer_Queue_Custom_Handler_Test::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_Custom_Handler_Test::init (void)
+{
+ typedef Command<Custom_Handler_Input_Task, Custom_Handler_Input_Task::ACTION> CMD;
+
+ // initialize the <Command> objects with their corresponding
+ // methods from <Custom_Handler_Input_Task>
+ ACE_NEW_RETURN (schedule_cmd_,
+ CMD (input_task_, &Custom_Handler_Input_Task::add_timer),
+ -1);
+
+ ACE_NEW_RETURN (cancel_cmd_,
+ CMD (input_task_, &Custom_Handler_Input_Task::cancel_timer),
+ -1);
+
+ ACE_NEW_RETURN (list_cmd_,
+ CMD (input_task_, &Custom_Handler_Input_Task::list_timer),
+ -1);
+
+ ACE_NEW_RETURN (shutdown_cmd_,
+ CMD (input_task_, &Custom_Handler_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/ACE/examples/Timer_Queue/Thread_Timer_Queue_Custom_Handler_Test.h b/ACE/examples/Timer_Queue/Thread_Timer_Queue_Custom_Handler_Test.h
new file mode 100644
index 00000000000..33e7c180a7b
--- /dev/null
+++ b/ACE/examples/Timer_Queue/Thread_Timer_Queue_Custom_Handler_Test.h
@@ -0,0 +1,127 @@
+/* -*- C++ -*- */
+
+// $Id$
+// ============================================================================
+//
+// = LIBRARY
+// examples
+//
+// = FILENAME
+// Thread_Timer_Queue_Custom_Handler_Test.h
+//
+// = DESCRIPTION
+// This code exercises the <ACE_Thread_Timer_Queue_Adapter> using
+// an <ACE_Timer_Heap_T>. It also demonstrates using a custom handler for
+// timer events.
+//
+// = AUTHORS
+// Carlos O'Ryan <coryan@cs.wustl.edu> and
+// Sergio Flores-Gaitan <sergio@cs.wustl.edu> and
+// Alon Diamant <diamant.alon@gmail.com>
+//
+// ============================================================================
+
+#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"
+#include "Custom_Handler.h"
+
+// These typedefs ensure that we use the minimal amount of locking
+// necessary.
+typedef ACE_Timer_Heap_T<Custom_Handler*,
+ Custom_Handler_Upcall,
+ ACE_Null_Mutex>
+ Timer_Heap;
+typedef ACE_Timer_Heap_Iterator_T<Custom_Handler*,
+ Custom_Handler_Upcall,
+ ACE_Null_Mutex>
+ Timer_Heap_Iterator;
+typedef ACE_Thread_Timer_Queue_Adapter<Timer_Heap, Custom_Handler*>
+ Thread_Timer_Queue;
+
+// Forward declaration.
+class Thread_Timer_Queue_Custom_Handler_Test;
+
+class Custom_Handler_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 (Custom_Handler_Input_Task::*ACTION) (void *);
+
+ Custom_Handler_Input_Task (Thread_Timer_Queue *queue,
+ Thread_Timer_Queue_Custom_Handler_Test &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_Custom_Handler_Test &driver_;
+ // The thread timer queue test driver.
+};
+
+class ACE_Svc_Export Thread_Timer_Queue_Custom_Handler_Test : public Timer_Queue_Test_Driver <Thread_Timer_Queue, Custom_Handler_Input_Task, Custom_Handler_Input_Task::ACTION>
+{
+ // = 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_Custom_Handler_Test (void);
+ ~Thread_Timer_Queue_Custom_Handler_Test (void);
+
+ virtual int display_menu (void);
+ virtual int init (void);
+ virtual int run_test (void);
+
+private:
+ Custom_Handler_Input_Task input_task_;
+ // Subclassed from ACE_Task.
+};
+
+#endif /* _THREAD_TIMER_QUEUE_TEST_H_ */
diff --git a/ACE/examples/Timer_Queue/Thread_Timer_Queue_Test.cpp b/ACE/examples/Timer_Queue/Thread_Timer_Queue_Test.cpp
index d9cf88ff5ee..d96b548164a 100644
--- a/ACE/examples/Timer_Queue/Thread_Timer_Queue_Test.cpp
+++ b/ACE/examples/Timer_Queue/Thread_Timer_Queue_Test.cpp
@@ -1,22 +1,18 @@
-// $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>
-//
-// ============================================================================
+
+//=============================================================================
+/**
+ * @file Thread_Timer_Queue_Test.cpp
+ *
+ * $Id$
+ *
+ * This test exercises the <ACE_Thread_Timer_Queue_Adapter>
+ * using an <ACE_Timer_Heap>.
+ *
+ *
+ * @author 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"
diff --git a/ACE/examples/Timer_Queue/Thread_Timer_Queue_Test.h b/ACE/examples/Timer_Queue/Thread_Timer_Queue_Test.h
index 573df6121f8..f5e9f07d4f6 100644
--- a/ACE/examples/Timer_Queue/Thread_Timer_Queue_Test.h
+++ b/ACE/examples/Timer_Queue/Thread_Timer_Queue_Test.h
@@ -1,24 +1,20 @@
/* -*- 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>
-//
-// ============================================================================
+
+//=============================================================================
+/**
+ * @file Thread_Timer_Queue_Test.h
+ *
+ * $Id$
+ *
+ * This code exercises the <ACE_Thread_Timer_Queue_Adapter> using
+ * an <ACE_Timer_Heap_T>.
+ *
+ *
+ * @author 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_
@@ -54,63 +50,67 @@ typedef ACE_Thread_Timer_Queue_Adapter<Timer_Heap>
// Forward declaration.
class Thread_Timer_Queue_Test_Driver;
+/**
+ * @class Input_Task
+ *
+ * @brief Read user actions on the Timer_Queue from stdin.
+ *
+ * This class reads user input from stdin; those commands permit
+ * the control of a Timer_Queue, which is dispatched by another
+ * thread.
+ */
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);
+ /// This method runs the event loop in the new thread.
virtual int svc (void);
- // This method runs the event loop in the new thread.
// = Some helper methods.
+ /// Add a new timer to expire in <seconds> more.
int add_timer (void *);
- // Add a new timer to expire in <seconds> more.
+ /// Cancel timer <id>.
int cancel_timer (void *);
- // Cancel timer <id>.
+ /// List the current scheduled timers.
int list_timer (void *);
- // List the current scheduled timers.
+ /// Shutdown task.
int shutdown_timer (void *);
- // Shutdown task.
+ /// Dump the state of the timer queue.
void dump (void);
- // Dump the state of the timer queue.
private:
+ /// The timer queue implementation.
Thread_Timer_Queue *queue_;
- // The timer queue implementation.
+ /// How many micro seconds are in a second.
const int usecs_;
- // How many micro seconds are in a second.
+ /// The thread timer queue test driver.
Thread_Timer_Queue_Test_Driver &driver_;
- // The thread timer queue test driver.
};
+/**
+ * @class Thread_Timer_Queue_Test_Driver
+ *
+ * @brief Implements an example application that exercises
+ * <Thread_Timer_Queue> timer queue.
+ *
+ * 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.
+ */
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);
@@ -120,38 +120,40 @@ public:
virtual int run_test (void);
private:
+ /// Subclassed from ACE_Task.
Input_Task input_task_;
- // Subclassed from ACE_Task.
};
+/**
+ * @class Handler
+ *
+ * @brief Event handler for the timer queue timeout events.
+ *
+ * The <handle_timeout> hook method prints out the current time,
+ * prints the time when this timer expired and deletes "this".
+ */
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);
+ /// Store an "id" for the Handler, which is only use to print better
+ /// messages.
void set_id (int id);
- // Store an "id" for the Handler, which is only use to print better
- // messages.
+ /// Call back hook.
virtual int handle_timeout (const ACE_Time_Value &current_time,
const void *arg);
- // Call back hook.
private:
+ /// Store the expected time of expiration, it is used to print a nice
+ /// message saying how much delay was at the actual expiration time.
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.
+ /// Store an "id" for the Handler, which is only use to print better
+ /// messages.
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/ACE/examples/Timer_Queue/Timer_Queue.mpc b/ACE/examples/Timer_Queue/Timer_Queue.mpc
index 04026c0babd..3ca7930c3ce 100644
--- a/ACE/examples/Timer_Queue/Timer_Queue.mpc
+++ b/ACE/examples/Timer_Queue/Timer_Queue.mpc
@@ -9,6 +9,7 @@ project(*Library) : acelib {
Driver.cpp
Reactor_Timer_Queue_Test.cpp
Thread_Timer_Queue_Test.cpp
+ Thread_Timer_Queue_Custom_Handler_Test.cpp
}
}
@@ -38,3 +39,12 @@ project(*Thread) : aceexe {
main_thread.cpp
}
}
+
+project(*Thread_Custom_Handlers) : aceexe {
+ exename = Thread_Custom_Handlers_Timer_Queue_Test
+ after += Timer_Queue_Library
+ libs += tqtd
+ Source_Files {
+ main_thread_custom_handler.cpp
+ }
+}
diff --git a/ACE/examples/Timer_Queue/main_async.cpp b/ACE/examples/Timer_Queue/main_async.cpp
index 8c21c4fcdd2..87a184f583b 100644
--- a/ACE/examples/Timer_Queue/main_async.cpp
+++ b/ACE/examples/Timer_Queue/main_async.cpp
@@ -1,33 +1,19 @@
-// $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 */
+
+//=============================================================================
+/**
+ * @file main_async.cpp
+ *
+ * $Id$
+ *
+ * Implements an asynchronous timer queue.
+ * This code exercises the Timer_Queue_Test_Driver class using
+ * signals as an asynchronous mechanism to dispatch events.
+ *
+ *
+ * @author Douglas Schmidt <schmidt@cs.wustl.edu> && Sergio Flores-Gaitan <sergio@cs.wustl.edu>
+ */
+//=============================================================================
+
#include "ace/OS_main.h"
#include "ace/Auto_Ptr.h"
diff --git a/ACE/examples/Timer_Queue/main_reactor.cpp b/ACE/examples/Timer_Queue/main_reactor.cpp
index 9ce80093bd9..33bc8166134 100644
--- a/ACE/examples/Timer_Queue/main_reactor.cpp
+++ b/ACE/examples/Timer_Queue/main_reactor.cpp
@@ -1,33 +1,19 @@
-// $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 */
+
+//=============================================================================
+/**
+ * @file main_reactor.cpp
+ *
+ * $Id$
+ *
+ * Implements an reactive timer queue.
+ * This code exercises the Timer_Queue_Test_Driver class using
+ * a reactor.
+ *
+ *
+ * @author Douglas Schmidt <schmidt@cs.wustl.edu> && Sergio Flores-Gaitan <sergio@cs.wustl.edu>
+ */
+//=============================================================================
+
#include "ace/OS_main.h"
#include "ace/Auto_Ptr.h"
diff --git a/ACE/examples/Timer_Queue/main_thread.cpp b/ACE/examples/Timer_Queue/main_thread.cpp
index fe3c53a9fd9..3dc1e9b9bc9 100644
--- a/ACE/examples/Timer_Queue/main_thread.cpp
+++ b/ACE/examples/Timer_Queue/main_thread.cpp
@@ -1,33 +1,19 @@
-// $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 */
+
+//=============================================================================
+/**
+ * @file main_thread.cpp
+ *
+ * $Id$
+ *
+ * Implements an threaded timer queue.
+ * This code exercises the Timer_Queue_Test_Driver class using
+ * threads.
+ *
+ *
+ * @author Douglas Schmidt <schmidt@cs.wustl.edu> && Sergio Flores-Gaitan <sergio@cs.wustl.edu>
+ */
+//=============================================================================
+
#include "ace/OS_main.h"
#include "ace/Auto_Ptr.h"
diff --git a/ACE/examples/Timer_Queue/main_thread_custom_handler.cpp b/ACE/examples/Timer_Queue/main_thread_custom_handler.cpp
new file mode 100644
index 00000000000..afb8978cf81
--- /dev/null
+++ b/ACE/examples/Timer_Queue/main_thread_custom_handler.cpp
@@ -0,0 +1,45 @@
+// $Id$
+// ============================================================================
+//
+// = LIBRARY
+// examples
+//
+// = FILENAME
+// main_thread_custom_handler.cpp
+//
+// = DESCRIPTION
+// Implements a threaded timer queue.
+// This code exercises the Timer_Queue_Test_Driver class using
+// threads.
+// It also uses custom event handlers for timer events.
+//
+// = AUTHORS
+// Douglas Schmidt <schmidt@cs.wustl.edu> &&
+// Sergio Flores-Gaitan <sergio@cs.wustl.edu> &&
+// Alon Diamant <diamant.alon@gmail.com>
+//
+// ============================================================================
+
+#include "ace/OS_main.h"
+#include "ace/Auto_Ptr.h"
+#include "Driver.h"
+#include "Thread_Timer_Queue_Custom_Handler_Test.h"
+
+typedef Timer_Queue_Test_Driver<Thread_Timer_Queue,
+ Custom_Handler_Input_Task,
+ Custom_Handler_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_Custom_Handler_Test, -1);
+
+ auto_ptr <THREAD_TIMER_QUEUE_TEST_DRIVER> driver (tqtd);
+
+ return driver->run_test ();
+}
+