Merge pull request #2309 from mitza-oci/warnings
[ACE_TAO.git] / ACE / examples / Bounded_Packet_Relay / bpr_thread.cpp
blobbc1d5c8c516fb6e7df332f8b2a5c516cc7f42fd1
2 //=============================================================================
3 /**
4 * @file bpr_thread.cpp
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"
17 #include <memory>
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>
23 INPUT_CALLBACK;
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.";
30 int
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,
37 ACE_Thread_Manager,
38 -1);
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,
46 sizeof (input_text),
47 input_text),
48 -1);
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,
56 -1);
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,
64 input_device,
65 output_device),
66 -1);
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
71 // this scope.
72 INPUT_CALLBACK *input_callback = 0;
73 ACE_NEW_RETURN (input_callback,
74 INPUT_CALLBACK (*packet_relay,
75 &Bounded_Packet_Relay::receive_input),
76 -1);
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"),
82 -1);
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),
91 -1);
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.