summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorcdgill <cdgill@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>1998-09-21 05:38:04 +0000
committercdgill <cdgill@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>1998-09-21 05:38:04 +0000
commit082f2168672cd3c833ff0736bda1c6ff0a66b097 (patch)
treeefdc13f5b78f237bafed1624699c65e2ec677596 /examples
parente323d42863c2c75e030aaad2fc12fdeb08d6d1e3 (diff)
downloadATCD-082f2168672cd3c833ff0736bda1c6ff0a66b097.tar.gz
moved device construction to main executable
Diffstat (limited to 'examples')
-rw-r--r--examples/Bounded_Packet_Relay/BPR_Drivers.cpp296
-rw-r--r--examples/Bounded_Packet_Relay/BPR_Drivers.h2
-rw-r--r--examples/Bounded_Packet_Relay/README72
-rw-r--r--examples/Bounded_Packet_Relay/Thread_Bounded_Packet_Relay.cpp78
-rw-r--r--examples/Bounded_Packet_Relay/Thread_Bounded_Packet_Relay.h9
-rw-r--r--examples/Bounded_Packet_Relay/bpr_thread.cpp52
6 files changed, 258 insertions, 251 deletions
diff --git a/examples/Bounded_Packet_Relay/BPR_Drivers.cpp b/examples/Bounded_Packet_Relay/BPR_Drivers.cpp
index d97b7c6fa89..3d2d34d32f6 100644
--- a/examples/Bounded_Packet_Relay/BPR_Drivers.cpp
+++ b/examples/Bounded_Packet_Relay/BPR_Drivers.cpp
@@ -35,164 +35,18 @@ ACE_RCSID(Bounded_Packet_Relay, BPR_Driver, "$Id$")
// Constructor.
-Input_Device_Wrapper_Base::Input_Device_Wrapper_Base (ACE_Thread_Manager *input_task_mgr)
- : ACE_Task_Base (input_task_mgr),
- send_input_msg_cmd_ (0),
- input_period_ (ACE_ONE_SECOND_IN_USECS),
- is_active_ (0)
-{
-}
-
-// Destructor.
-
-Input_Device_Wrapper_Base::~Input_Device_Wrapper_Base (void)
-{
- delete send_input_msg_cmd_;
-}
-
-// Sets send input message command in the input device driver object.
-
-int
-Input_Device_Wrapper_Base::set_send_input_msg_cmd (Command_Base *send_input_msg_cmd)
-{
- // Delete the old command (if any), then set the new command.
- delete send_input_msg_cmd_;
- send_input_msg_cmd_ = send_input_msg_cmd;
- return 0;
-}
-
-// Sets period between when input messages are produced.
-
-int
-Input_Device_Wrapper_Base::set_input_period (u_long input_period)
-{
- input_period_ = input_period;
- return 0;
-}
-
-// Sets count of messages to send.
-
-int
-Input_Device_Wrapper_Base::set_send_count (long count)
-{
- send_count_ = count;
- return 0;
-}
-
-// Request that the input device stop sending messages
-// and terminate its thread. Should return 1 if it will do so, 0
-// if it has already done so, or -1 if there is a problem doing so.
-
-int
-Input_Device_Wrapper_Base::request_stop (void)
-{
- if (is_active_)
- {
- is_active_ = 0;
- return 1;
- }
-
- return 0;
-}
-
-// This method runs the input device loop in the new thread.
-
-int
-Input_Device_Wrapper_Base::svc (void)
-{
- long count;
- ACE_Time_Value timeout;
- ACE_Message_Block *message;
-
- // Set a flag to indicate we're active.
- is_active_ = 1;
-
- // Start with the total count of messages to send.
- for (count = send_count_;
- // While we're still marked active, and there are packets to send.
- is_active_ && count != 0;
- )
- {
- // make sure there is a send command object
- if (send_input_msg_cmd_ == 0)
- {
- is_active_ = 0;
- ACE_ERROR_RETURN ((LM_ERROR, "%t %p\n",
- "send message command object not instantiated"),
- -1);
- }
-
- // create an input message to send
- message = create_input_message ();
- if (message == 0)
- {
- is_active_ = 0;
- ACE_ERROR_RETURN ((LM_ERROR, "%t %p\n",
- "Failed to create input message object"),
- -1);
- }
-
- // send the input message
- if (send_input_msg_cmd_->execute ((void *) message) < 0)
- {
- is_active_ = 0;
- delete message;
- ACE_ERROR_RETURN ((LM_ERROR, "%t %p\n",
- "Failed executing send message command object"),
- -1);
- }
-
- // If all went well, decrement count of messages to send,
- // and run the reactor event loop unti we get a timeout
- // or something happens in a registered upcall.
- if (count > 0)
- --count;
-
- timeout = ACE_Time_Value (0, input_period_);
- reactor_.run_event_loop (timeout);
- }
-
- is_active_ = 0;
-
- return 0;
-}
-
-// Sends a newly created message block, carrying data
-// read from the underlying input device, by passing a
-// pointer to the message block to its command execution.
-
-int
-Input_Device_Wrapper_Base::send_input_message (ACE_Message_Block *amb)
-{
- if (send_input_msg_cmd_)
- return send_input_msg_cmd_->execute ((void *) amb);
- else
- {
- ACE_ERROR_RETURN ((LM_ERROR, "%t %p\n",
- "Input_Device_Wrapper_Base::send_input_message: "
- "command object not instantiated"),
- -1);
- }
-}
-
-// Constructor.
-
template <ACE_SYNCH_DECL>
Bounded_Packet_Relay<ACE_SYNCH_USE>::Bounded_Packet_Relay (ACE_Thread_Manager *input_task_mgr,
Input_Device_Wrapper_Base *input_wrapper,
Output_Device_Wrapper_Base *output_wrapper)
: input_task_mgr_ (input_task_mgr),
input_wrapper_ (input_wrapper),
- input_thread_handle_ (0),
output_wrapper_ (output_wrapper),
- queue_,
- is_active_ (0),
- transmission_lock_,
- queue_lock_,
transmission_number_ (0),
packets_sent_ (0),
status_ (Bounded_Packet_Relay_Base::UN_INITIALIZED),
- elapsed_duration_ (0)
+ transmission_start_ (0, 0),
+ transmission_end_ (0, 0)
{
if (input_task_mgr_ == 0)
input_task_mgr_ = ACE_Thread_Manager::instance ();
@@ -203,8 +57,6 @@ Bounded_Packet_Relay<ACE_SYNCH_USE>::Bounded_Packet_Relay (ACE_Thread_Manager *i
template <ACE_SYNCH_DECL>
Bounded_Packet_Relay<ACE_SYNCH_USE>::~Bounded_Packet_Relay (void)
{
- delete input_wrapper_;
- delete output_wrapper_;
}
// Requests output be sent to output device.
@@ -401,6 +253,150 @@ Bounded_Packet_Relay<ACE_SYNCH_USE>::receive_input (void * arg)
return 0;
}
+
+// Constructor.
+
+Input_Device_Wrapper_Base::Input_Device_Wrapper_Base (ACE_Thread_Manager *input_task_mgr)
+ : ACE_Task_Base (input_task_mgr),
+ send_input_msg_cmd_ (0),
+ input_period_ (ACE_ONE_SECOND_IN_USECS),
+ is_active_ (0)
+{
+}
+
+// Destructor.
+
+Input_Device_Wrapper_Base::~Input_Device_Wrapper_Base (void)
+{
+ delete send_input_msg_cmd_;
+}
+
+// Sets send input message command in the input device driver object.
+
+int
+Input_Device_Wrapper_Base::set_send_input_msg_cmd (Command_Base *send_input_msg_cmd)
+{
+ // Delete the old command (if any), then set the new command.
+ delete send_input_msg_cmd_;
+ send_input_msg_cmd_ = send_input_msg_cmd;
+ return 0;
+}
+
+// Sets period between when input messages are produced.
+
+int
+Input_Device_Wrapper_Base::set_input_period (u_long input_period)
+{
+ input_period_ = input_period;
+ return 0;
+}
+
+// Sets count of messages to send.
+
+int
+Input_Device_Wrapper_Base::set_send_count (long count)
+{
+ send_count_ = count;
+ return 0;
+}
+
+// Request that the input device stop sending messages
+// and terminate its thread. Should return 1 if it will do so, 0
+// if it has already done so, or -1 if there is a problem doing so.
+
+int
+Input_Device_Wrapper_Base::request_stop (void)
+{
+ if (is_active_)
+ {
+ is_active_ = 0;
+ return 1;
+ }
+
+ return 0;
+}
+
+// This method runs the input device loop in the new thread.
+
+int
+Input_Device_Wrapper_Base::svc (void)
+{
+ long count;
+ ACE_Time_Value timeout;
+ ACE_Message_Block *message;
+
+ // Set a flag to indicate we're active.
+ is_active_ = 1;
+
+ // Start with the total count of messages to send.
+ for (count = send_count_;
+ // While we're still marked active, and there are packets to send.
+ is_active_ && count != 0;
+ )
+ {
+ // make sure there is a send command object
+ if (send_input_msg_cmd_ == 0)
+ {
+ is_active_ = 0;
+ ACE_ERROR_RETURN ((LM_ERROR, "%t %p\n",
+ "send message command object not instantiated"),
+ -1);
+ }
+
+ // create an input message to send
+ message = create_input_message ();
+ if (message == 0)
+ {
+ is_active_ = 0;
+ ACE_ERROR_RETURN ((LM_ERROR, "%t %p\n",
+ "Failed to create input message object"),
+ -1);
+ }
+
+ // send the input message
+ if (send_input_msg_cmd_->execute ((void *) message) < 0)
+ {
+ is_active_ = 0;
+ delete message;
+ ACE_ERROR_RETURN ((LM_ERROR, "%t %p\n",
+ "Failed executing send message command object"),
+ -1);
+ }
+
+ // If all went well, decrement count of messages to send,
+ // and run the reactor event loop unti we get a timeout
+ // or something happens in a registered upcall.
+ if (count > 0)
+ --count;
+
+ timeout = ACE_Time_Value (0, input_period_);
+ reactor_.run_event_loop (timeout);
+ }
+
+ is_active_ = 0;
+
+ return 0;
+}
+
+// Sends a newly created message block, carrying data
+// read from the underlying input device, by passing a
+// pointer to the message block to its command execution.
+
+int
+Input_Device_Wrapper_Base::send_input_message (ACE_Message_Block *amb)
+{
+ if (send_input_msg_cmd_)
+ return send_input_msg_cmd_->execute ((void *) amb);
+ else
+ {
+ ACE_ERROR_RETURN ((LM_ERROR, "%t %p\n",
+ "Input_Device_Wrapper_Base::send_input_message: "
+ "command object not instantiated"),
+ -1);
+ }
+}
+
+
// Parse the input and execute the corresponding command.
template <class TQ> int
diff --git a/examples/Bounded_Packet_Relay/BPR_Drivers.h b/examples/Bounded_Packet_Relay/BPR_Drivers.h
index 136e5ce689c..f558d5061a2 100644
--- a/examples/Bounded_Packet_Relay/BPR_Drivers.h
+++ b/examples/Bounded_Packet_Relay/BPR_Drivers.h
@@ -294,7 +294,7 @@ public:
// Otherwise, a -1 is returned and errno is set to indicate the
// error.
- virtual int display_menu (void);
+ virtual int display_menu (void)=0;
// Prints the user interface for the driver to STDERR.
virtual int init (void)=0;
diff --git a/examples/Bounded_Packet_Relay/README b/examples/Bounded_Packet_Relay/README
index 46fdbde6af2..d6db77cebf3 100644
--- a/examples/Bounded_Packet_Relay/README
+++ b/examples/Bounded_Packet_Relay/README
@@ -5,28 +5,23 @@ threaded and reactive concurrency mechanisms in ACE. The example
application schedules and processes heterogenerous user input and
timer-based events in the context of a bounded packet relay mechanism.
-This example is based on the notion of a time-bounded packet relay.
-In this example, a transmission begins, packets arrive from an input
-device object, and are transferred to an output device object by a
-relay object at a specified pace. The transfer continues until all
-packets have been relayed or a duration limit expires, at which point
-the transmission ends.
+In this example, a transmission begins, packets arrive from an input device
+object, and are transferred to an output device object by a relay object at
+a specified pace. The transfer continues until all packets have been
+relayed, a duration limit expires, or the transmission is cancelled.
User input is handled concurrently with a running transmission. You
can run a transmission, cancel a transmission, change transmission
parameters, view statistics from the most recent transmission, or exit
the program, using selections from an interactive text-based menu.
-
In addition, the example program can be run in batch mode, with the
-appropriate commands piped to the program in place of its standard
-input stream.
+appropriate commands piped to the program's standard input stream.
-Transmission parameters are intialized to default values.
-Transmission parameter values persist until/unless they are
-subsequently modified by an appropriate command. If an invalid value
-for a command is given, or a run or report command is issued while a
-transmission is in progress, the offending command has no effect, and
-an error message is generated.
+Transmission parameters are intialized to default values. Transmission
+parameter values persist until/unless they are subsequently modified by an
+appropriate command. If an invalid value for a command is given, or a run
+or report command is issued while a transmission is in progress, the
+offending command has no effect, and an error message is generated.
2. USER INTERFACE
@@ -78,16 +73,15 @@ The design of this example application consists of four main
components: the driver object, the relay object, the input device
object, and the output device object.
-The driver object is responsible for receiving user input and overall
-handling of user input commands. The driver object is active, with
-separate threads for receiving user input and managing its
-transmission timer queue. This allows the user to issue commands
-while a transmission is in progress. The driver object uses an
-ACE_Thread_Timer_Queue_Adapter, which is derived from ACE_Task_Base.
-The driver object runs inside another active object, called
-User_Input_Task, which is also derived from ACE_Task_Base. This
-allows both the timer queue and the user input object to be made
-active, running in their own threads of control.
+The driver object is responsible for receiving user input and overall handling
+of user input commands. The driver object is active, with separate threads
+for receiving user input and managing its transmission timer queue. This
+allows the user to issue commands while a transmission is in progress. The
+driver object uses an ACE_Thread_Timer_Queue_Adapter, which is derived from
+ACE_Task_Base. The driver object starts another active object, called
+User_Input_Task, which is also derived from ACE_Task_Base. This allows both
+the timer queue and the user input object to be made active, running in their
+own threads of control.
The relay object is passive, managing a message queue and necessary
locks to allow safe access from multiple threads. It provides methods
@@ -115,11 +109,10 @@ delete on the passed pointer.
3.2. RUN-TIME CHARACTERSITICS
-When the user initiates a transmission, the appropriate settings are
-passed by the driver to the relay object's start transmission method.
-The relay object tries to acquire a lock for a new transmission. If
-it fails to do so, another transmission is in progress, and the
-methods returns an error. Otherwise, the relay object's start
+When the user initiates a transmission, the appropriate settings are passed
+by the driver to the relay object's start transmission method. The relay
+object tries to start a new transmission. If another transmission is in
+progress, the method returns an error. Otherwise, the relay object's start
transmission method initializes itself and the input and output device
objects, activates the input device object, and stores the handle for
the new input device thread.
@@ -128,7 +121,7 @@ The driver then constructs a timeout handler with a count of the
number of messages to relay and a send timeout value, and pushes a
timer with this handler onto the timer queue. If there is a limit on
the duration of the transmission, the driver constructs a different
-handler for end-of- transmission, and pushes a timer for the end of
+handler for end-of-transmission, and pushes a timer for the end of
the transmission with this handler onto the timer queue as well. When
the user issues a cancel transmission command, the driver calls the
relay's end transmission method.
@@ -136,15 +129,14 @@ relay's end transmission method.
When a send timeout expires, the handler (running in the timer queue
thread) calls the send method of the relay. If there are any enqueued
messages from the input device object in its queue, the relay object's
-send method will dequeue the message, pass it to the output device
+send method will dequeue a message, pass it to the output device
object, and return success. If there are no messages in the queue,
the relay object's send method will return failure. If the send was
successful, the handler will decrement its count of remaining
messages. If the count is greater than zero, the handler will
register a new send timer for itself and exit. If the count is zero,
then the handler will call the relay's end transmission method, clear
-the timer queue, and release the transmission-in-progress semaphore
-before exiting.
+the timer queue, and mark itself inactive before exiting.
Similarly, if the end-of-transmission timer expires before all packets
have been sent, that handler will call the relay's end transmission
@@ -153,14 +145,14 @@ method, clear the timer queue, release the semaphore, and then exit.
When the relay's end transmission method is called, it marks the relay
itself inactive, and calls the input device's deactivate method, which
sets the input device's activity flag to inactive (see below). The
-relay's end transmission method then waits on the stored input thread
-handle until that thread exits, before returning.
+relay's end transmission method then waits until the input device thread
+exits, before returning.
While it is still active, the input device thread blocks on a reactor
timeout for the duration it was given by the relay. When the timeout
expires, the input device checks a flag to see if it is still active.
If the flag says the input device is inactive, the thread simply
-exits. Tis allows cancellation of the input device when a
+exits. This allows cancellation of the input device when a
transmission has ended. If the flag says it is still active, the
thread builds a new character buffer, and wraps this with a new
ACE_Message_Block. The input device passes this message block to the
@@ -176,12 +168,10 @@ its thread simply exits.
The files for this example are located in
$ACE_ROOT/examples/Bounded_Packet_Relay in the latest release of ACE,
-which will be located at
+which is located at
http://www.cs.wustl.edu/~schmidt/ACE_wrappers/ACE.tar.gz
-when the example application is complete.
-
Source Files: Thread_Bounded_Packet_Relay.h
Thread_Bounded_Packet_Relay.cpp
BPR_Driver.h
@@ -193,5 +183,3 @@ Make file: Makefile
Doc file: README (this file)
Executable: bpr_thread
-
-
diff --git a/examples/Bounded_Packet_Relay/Thread_Bounded_Packet_Relay.cpp b/examples/Bounded_Packet_Relay/Thread_Bounded_Packet_Relay.cpp
index dc5c9660860..7098159e584 100644
--- a/examples/Bounded_Packet_Relay/Thread_Bounded_Packet_Relay.cpp
+++ b/examples/Bounded_Packet_Relay/Thread_Bounded_Packet_Relay.cpp
@@ -106,7 +106,7 @@ Text_Input_Device_Wrapper::create_input_message (void)
// Constructor.
-Text_Output_Driver_Wrapper::Text_Output_Driver_Wrapper (int logging)
+Text_Output_Device_Wrapper::Text_Output_Device_Wrapper (int logging)
: logging_ (logging)
{
}
@@ -114,7 +114,7 @@ Text_Output_Driver_Wrapper::Text_Output_Driver_Wrapper (int logging)
// Consume and possibly print out the passed message.
int
-Text_Output_Driver_Wrapper::write_output_message (void *message)
+Text_Output_Device_Wrapper::write_output_message (void *message)
{
if (message)
{
@@ -128,7 +128,7 @@ Text_Output_Driver_Wrapper::write_output_message (void *message)
}
ACE_ERROR_RETURN ((LM_ERROR,
- "Text_Output_Driver_Wrapper::"
+ "Text_Output_Device_Wrapper::"
"write_output_message: null argument"), -1);
return 0;
}
@@ -138,7 +138,7 @@ Text_Output_Driver_Wrapper::write_output_message (void *message)
// nothing if the pointer is null.
int
-Text_Output_Driver_Wrapper::modify_device_settings (void *logging)
+Text_Output_Device_Wrapper::modify_device_settings (void *logging)
{
if (logging)
logging_ = *ACE_static_cast (int *, logging);
@@ -150,9 +150,11 @@ Text_Output_Driver_Wrapper::modify_device_settings (void *logging)
// Constructor.
-User_Input_Task::User_Input_Task (Thread_Timer_Queue *queue,
+User_Input_Task::User_Input_Task (Bounded_Packet_Relay<ACE_MT_SYNCH> *relay,
+ Thread_Timer_Queue *queue,
Thread_Bounded_Packet_Relay_Driver &tbprd)
: ACE_Task_Base (ACE_Thread_Manager::instance ()),
+ relay_ (relay),
queue_ (queue),
usecs_ (ACE_ONE_SECOND_IN_USECS),
driver_ (tbprd)
@@ -260,11 +262,8 @@ User_Input_Task::set_logging_level (void *argument)
// Runs the next transmission (if one is not in progress).
int
-User_Input_Task::run_transmission (void *argument)
+User_Input_Task::run_transmission (void *)
{
- // Macro to avoid "warning: unused parameter" type warning.
- ACE_UNUSED_ARG (argument);
-
if (relay_)
{
switch (relay_->start_transmission (packet_count_,
@@ -339,38 +338,25 @@ User_Input_Task::end_transmission (void *)
{
if (relay_)
{
- Bounded_Packet_Relay_Base::Transmission_Status *status;
-
- status =
- ACE_static_cast (Bounded_Packet_Relay_Base::Transmission_Status *,
- argument);
-
- if (status)
+ switch (relay_->end_transmission (Bounded_Packet_Relay_Base::CANCELLED))
{
- switch (relay_->end_transmission (*status))
- {
- case 1:
- ACE_DEBUG ((LM_DEBUG,
- "\nEnd transmission: "
- "no transmission in progress\n"));
- return 0;
- /* NOTREACHED */
-
- case 0:
- // Cancel any remaining timers.
- this->clear_all_timers ();
- return 0;
- /* NOTREACHED */
+ case 1:
+ ACE_DEBUG ((LM_DEBUG,
+ "\nEnd transmission: "
+ "no transmission in progress\n"));
+ return 0;
+ /* NOTREACHED */
+
+ case 0:
+ // Cancel any remaining timers.
+ this->clear_all_timers ();
+ return 0;
+ /* NOTREACHED */
- default:
- return -1;
- /* NOTREACHED */
- }
- }
- ACE_ERROR_RETURN ((LM_ERROR,
- "User_Input_Task::end_transmission: "
- "null argument"),
- -1);
+ default:
+ return -1;
+ /* NOTREACHED */
+ }
}
ACE_ERROR_RETURN ((LM_ERROR,
"User_Input_Task::end_transmission: "
@@ -382,11 +368,8 @@ User_Input_Task::end_transmission (void *)
// (if one is not in progress).
int
-User_Input_Task::report_stats (void *argument)
+User_Input_Task::report_stats (void *)
{
- // Macro to avoid "warning: unused parameter" type warning.
- ACE_UNUSED_ARG (argument);
-
if (relay_)
{
switch (relay_->report_statistics ())
@@ -415,11 +398,8 @@ User_Input_Task::report_stats (void *argument)
// Shut down the task.
int
-User_Input_Task::shutdown (void *argument)
+User_Input_Task::shutdown (void *)
{
- // Macro to avoid "warning: unused parameter" type warning.
- ACE_UNUSED_ARG (argument);
-
#if !defined (ACE_LACKS_PTHREAD_CANCEL)
// Cancel the thread timer queue task "preemptively."
ACE_Thread::cancel (this->queue_->thr_id ());
@@ -584,8 +564,8 @@ Termination_Handler::cancelled (void)
// Constructor.
-Thread_Bounded_Packet_Relay_Driver::Thread_Bounded_Packet_Relay_Driver (void)
- : input_task_ (&timer_queue_, *this)
+Thread_Bounded_Packet_Relay_Driver::Thread_Bounded_Packet_Relay_Driver (Bounded_Packet_Relay<ACE_MT_SYNCH> *relay)
+ : input_task_ (relay, &timer_queue_, *this)
{
}
diff --git a/examples/Bounded_Packet_Relay/Thread_Bounded_Packet_Relay.h b/examples/Bounded_Packet_Relay/Thread_Bounded_Packet_Relay.h
index f5e00c299b2..1347b44c96e 100644
--- a/examples/Bounded_Packet_Relay/Thread_Bounded_Packet_Relay.h
+++ b/examples/Bounded_Packet_Relay/Thread_Bounded_Packet_Relay.h
@@ -125,7 +125,7 @@ private:
// Index into the string.
};
-class Text_Output_Driver_Wrapper : public Output_Device_Wrapper_Base
+class Text_Output_Device_Wrapper : public Output_Device_Wrapper_Base
{
// = TITLE
// Implements a simple wrapper for a output pseudo-device.
@@ -135,7 +135,7 @@ class Text_Output_Driver_Wrapper : public Output_Device_Wrapper_Base
// output stream, if logging is turned on.
public:
- Text_Output_Driver_Wrapper (int logging = 0);
+ Text_Output_Device_Wrapper (int logging = 0);
// Default constructor.
// = Command Accessible Entry Points
@@ -166,7 +166,8 @@ public:
typedef int (User_Input_Task::*ACTION) (void *);
// Trait for command accessible entry points.
- User_Input_Task (Thread_Timer_Queue *queue,
+ User_Input_Task (Bounded_Packet_Relay<ACE_MT_SYNCH> *relay,
+ Thread_Timer_Queue *queue,
Thread_Bounded_Packet_Relay_Driver &timer_queue_driver);
// Constructor.
@@ -349,7 +350,7 @@ public:
typedef Command<User_Input_Task, User_Input_Task::ACTION> COMMAND;
// = Initialization and termination methods.
- Thread_Bounded_Packet_Relay_Driver (void);
+ Thread_Bounded_Packet_Relay_Driver (Bounded_Packet_Relay<ACE_MT_SYNCH> *relay);
// Constructor.
~Thread_Bounded_Packet_Relay_Driver (void);
diff --git a/examples/Bounded_Packet_Relay/bpr_thread.cpp b/examples/Bounded_Packet_Relay/bpr_thread.cpp
index 3b5205ed4a2..8b62f4d829a 100644
--- a/examples/Bounded_Packet_Relay/bpr_thread.cpp
+++ b/examples/Bounded_Packet_Relay/bpr_thread.cpp
@@ -31,17 +31,59 @@ ACE_RCSID(Bounded_Packet_Relay, bpr_thread, "$Id$")
typedef Bounded_Packet_Relay_Driver<Thread_Timer_Queue>
THREAD_BOUNDED_PACKET_RELAY_DRIVER;
+typedef Bounded_Packet_Relay<ACE_MT_SYNCH>
+ BOUNDED_PACKET_RELAY;
+
+// A snippet from Andrew Marvell (Oliver Cromwell's poet laureate)
+const char input_text [] = "But ever at my back I hear\n"
+ "Time's winged chariot hurrying near.\n";
+
int
main (int, char *[])
{
- // Auto ptr ensures that the driver memory is released
- // automatically.
- THREAD_BOUNDED_PACKET_RELAY_DRIVER *tbprd;
+ // 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);
- ACE_NEW_RETURN (tbprd,
- Thread_Bounded_Packet_Relay_Driver,
+ // 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 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 ();