summaryrefslogtreecommitdiff
path: root/ACE/examples/Bounded_Packet_Relay/bpr_thread.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'ACE/examples/Bounded_Packet_Relay/bpr_thread.cpp')
-rw-r--r--ACE/examples/Bounded_Packet_Relay/bpr_thread.cpp122
1 files changed, 122 insertions, 0 deletions
diff --git a/ACE/examples/Bounded_Packet_Relay/bpr_thread.cpp b/ACE/examples/Bounded_Packet_Relay/bpr_thread.cpp
new file mode 100644
index 00000000000..0a564ecd2a5
--- /dev/null
+++ b/ACE/examples/Bounded_Packet_Relay/bpr_thread.cpp
@@ -0,0 +1,122 @@
+// $Id$
+
+// ============================================================================
+//
+// = LIBRARY
+// examples
+//
+// = FILENAME
+// bpr_thread.cpp
+//
+// = DESCRIPTION
+// Exercises drivers for a bounded packet relay, based on threaded timer queues.
+//
+// = AUTHORS
+// Chris Gill <cdgill@cs.wustl.edu> and
+// Douglas C. Schmidt <schmidt@cs.wustl.edu>
+//
+// Based on the Timer Queue Test example written by
+//
+// Carlos O'Ryan <coryan@cs.wustl.edu> and
+// Douglas C. Schmidt <schmidt@cs.wustl.edu> and
+// 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/Auto_Ptr.h"
+#include "Thread_Bounded_Packet_Relay.h"
+
+ACE_RCSID (Bounded_Packet_Relay,
+ bpr_thread,
+ "$Id$")
+
+typedef Bounded_Packet_Relay_Driver<Thread_Timer_Queue>
+ THREAD_BOUNDED_PACKET_RELAY_DRIVER;
+
+typedef ACE_Command_Callback<Bounded_Packet_Relay,Bounded_Packet_Relay::ACTION>
+ INPUT_CALLBACK;
+
+// A snippet from Andrew Marvell (Oliver Cromwell's poet laureate)
+static const char input_text [] =
+"But ever at my back I hear\n"
+" Time's winged chariot hurrying near.";
+
+int
+ACE_TMAIN (int, ACE_TCHAR *[])
+{
+ // Construct a new thread manager for the input device task. Auto
+ // ptr ensures memory is freed when we exit this scope.
+ ACE_Thread_Manager *input_task_mgr;
+ ACE_NEW_RETURN (input_task_mgr,
+ ACE_Thread_Manager,
+ -1);
+ auto_ptr <ACE_Thread_Manager> mgr (input_task_mgr);
+
+ // Construct a new input device wrapper. Auto ptr ensures memory is
+ // freed when we exit this scope.
+ Text_Input_Device_Wrapper *input_device;
+ ACE_NEW_RETURN (input_device,
+ Text_Input_Device_Wrapper (input_task_mgr,
+ sizeof (input_text),
+ input_text),
+ -1);
+ auto_ptr <Text_Input_Device_Wrapper> input (input_device);
+
+ // Construct a new output device wrapper. Auto ptr ensures memory
+ // is freed when we exit this scope.
+ Text_Output_Device_Wrapper *output_device;
+ ACE_NEW_RETURN (output_device,
+ Text_Output_Device_Wrapper,
+ -1);
+ auto_ptr <Text_Output_Device_Wrapper> output (output_device);
+
+ // Construct a new bounded packet relay. Auto ptr ensures memory is
+ // freed when we exit this scope.
+ Bounded_Packet_Relay *packet_relay;
+ ACE_NEW_RETURN (packet_relay,
+ Bounded_Packet_Relay (input_task_mgr,
+ input_device,
+ output_device),
+ -1);
+ auto_ptr <Bounded_Packet_Relay> relay (packet_relay);
+
+ // Construct a receive input callback command for the relay, and register
+ // it with the input device. Auto ptr ensures memory is freed when we exit
+ // this scope.
+ INPUT_CALLBACK *input_callback;
+ ACE_NEW_RETURN (input_callback,
+ INPUT_CALLBACK (*packet_relay,
+ &Bounded_Packet_Relay::receive_input),
+ -1);
+ auto_ptr <INPUT_CALLBACK> callback (input_callback);
+ if (input_device->set_send_input_msg_cmd (input_callback) < 0)
+ {
+ ACE_ERROR_RETURN ((LM_ERROR,
+ "failed to register input callback"),
+ -1);
+ }
+
+ // Construct a new bounded packet relay driver. Auto ptr ensures
+ // memory is freed when we exit this scope.
+ THREAD_BOUNDED_PACKET_RELAY_DRIVER *tbprd;
+
+ ACE_NEW_RETURN (tbprd,
+ Thread_Bounded_Packet_Relay_Driver (packet_relay),
+ -1);
+
+ auto_ptr <THREAD_BOUNDED_PACKET_RELAY_DRIVER> driver (tbprd);
+
+ return driver->run ();
+ // All dynamically allocated memory is released when main() returns.
+}
+