2 //=============================================================================
6 * Exercises drivers for a bounded packet relay, based on threaded timer queues.
8 * @author Chris Gill <cdgill@cs.wustl.edu>
9 * @author Douglas C. Schmidt <d.schmidt@vanderbilt.edu>
11 * Based on the Timer Queue Test example written by Carlos O'Ryan <coryan@cs.wustl.edu>
12 * and Douglas C. Schmidt <d.schmidt@vanderbilt.edu> and Sergio Flores-Gaitan <sergio@cs.wustl.edu>
14 //=============================================================================
16 #include "Thread_Bounded_Packet_Relay.h"
19 typedef Bounded_Packet_Relay_Driver
<Thread_Timer_Queue
>
20 THREAD_BOUNDED_PACKET_RELAY_DRIVER
;
22 typedef ACE_Command_Callback
<Bounded_Packet_Relay
,Bounded_Packet_Relay::ACTION
>
25 // A snippet from Andrew Marvell (Oliver Cromwell's poet laureate)
26 static const char input_text
[] =
27 "But ever at my back I hear\n"
28 " Time's winged chariot hurrying near.";
31 ACE_TMAIN (int, ACE_TCHAR
*[])
33 // Construct a new thread manager for the input device task. Auto
34 // ptr ensures memory is freed when we exit this scope.
35 ACE_Thread_Manager
*input_task_mgr
;
36 ACE_NEW_RETURN (input_task_mgr
,
39 std::unique_ptr
<ACE_Thread_Manager
> mgr (input_task_mgr
);
41 // Construct a new input device wrapper. Auto ptr ensures memory is
42 // freed when we exit this scope.
43 Text_Input_Device_Wrapper
*input_device
;
44 ACE_NEW_RETURN (input_device
,
45 Text_Input_Device_Wrapper (input_task_mgr
,
49 std::unique_ptr
<Text_Input_Device_Wrapper
> input (input_device
);
51 // Construct a new output device wrapper. Auto ptr ensures memory
52 // is freed when we exit this scope.
53 Text_Output_Device_Wrapper
*output_device
= 0;
54 ACE_NEW_RETURN (output_device
,
55 Text_Output_Device_Wrapper
,
57 std::unique_ptr
<Text_Output_Device_Wrapper
> output (output_device
);
59 // Construct a new bounded packet relay. Auto ptr ensures memory is
60 // freed when we exit this scope.
61 Bounded_Packet_Relay
*packet_relay
= 0;
62 ACE_NEW_RETURN (packet_relay
,
63 Bounded_Packet_Relay (input_task_mgr
,
67 std::unique_ptr
<Bounded_Packet_Relay
> relay (packet_relay
);
69 // Construct a receive input callback command for the relay, and register
70 // it with the input device. Auto ptr ensures memory is freed when we exit
72 INPUT_CALLBACK
*input_callback
= 0;
73 ACE_NEW_RETURN (input_callback
,
74 INPUT_CALLBACK (*packet_relay
,
75 &Bounded_Packet_Relay::receive_input
),
77 std::unique_ptr
<INPUT_CALLBACK
> callback (input_callback
);
78 if (input_device
->set_send_input_msg_cmd (input_callback
) < 0)
80 ACE_ERROR_RETURN ((LM_ERROR
,
81 "failed to register input callback"),
85 // Construct a new bounded packet relay driver. Auto ptr ensures
86 // memory is freed when we exit this scope.
87 THREAD_BOUNDED_PACKET_RELAY_DRIVER
*tbprd
= 0;
89 ACE_NEW_RETURN (tbprd
,
90 Thread_Bounded_Packet_Relay_Driver (packet_relay
),
93 std::unique_ptr
<THREAD_BOUNDED_PACKET_RELAY_DRIVER
> driver (tbprd
);
95 return driver
->run ();
96 // All dynamically allocated memory is released when main() returns.