Revert "Use a variable on the stack to not have a temporary in the call"
[ACE_TAO.git] / TAO / tests / Bug_1495_Regression / Threaded_Client.cpp
blobe69d3dbf1a174e1ca44fbe52ac83e243595d3f5f
1 /**
2 * @file Threaded_Client.cpp
3 * @author Will Otte <wotte@dre.vanderbilt.edu>
5 * This program spawns two threads:
6 * 1.) A "server" thread using Server_Task that acts as a server meant to
7 * recieve forwarded requests.
8 * 2.) A "client" thread using Client_Task that acts as a client that sends
9 * a get_thread_id request that is forwarded by a remote server to
10 * the server in thread (1).
12 * The test passes if the thread id of the thread that services the get_thread_id
13 * request is the same as the thread that makes the request.
16 #include "Server_Task.h"
17 #include "Client_Task.h"
18 #include "ace/Get_Opt.h"
19 #include "ace/Argv_Type_Converter.h"
20 #include "ace/Manual_Event.h"
22 const ACE_TCHAR *ior_input_file = ACE_TEXT("test.ior");
23 const ACE_TCHAR *ior_output_file = ACE_TEXT("thr_server.ior");
25 int
26 parse_args (int argc, ACE_TCHAR *argv[])
28 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("i:o:"));
29 int c;
31 while ((c = get_opts ()) != -1)
32 switch (c)
34 case 'i':
35 ior_input_file = get_opts.opt_arg ();
36 break;
37 case 'o':
38 ior_output_file = get_opts.opt_arg ();
39 break;
40 case '?':
41 default:
42 ACE_ERROR_RETURN ((LM_ERROR,
43 "usage: %s "
44 "-i alternate_remote_ior "
45 "-o alternate_local_ior "
46 "\n",
47 argv [0]),
48 -1);
50 return 0;
54 int
55 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
57 try
59 ACE_Argv_Type_Converter main_args_s (argc, argv);
61 CORBA::ORB_var sorb =
62 CORBA::ORB_init (main_args_s.get_argc (),
63 main_args_s.get_TCHAR_argv (),
64 "Server_ORB");
65 // Parse command line
66 if (parse_args (argc, argv) == -1)
68 return -1;
71 ACE_Manual_Event me;
73 Server_Task server_task (ior_output_file,
74 sorb.in (),
75 me,
76 ACE_Thread_Manager::instance ());
78 if (server_task.activate (THR_JOINABLE, 1, 1) == -1)
80 ACE_ERROR ((LM_ERROR, "Error activating the server task."));
81 return -1;
84 // Wait for the server task to activate.
85 me.wait ();
87 ACE_Argv_Type_Converter main_args_c (argc, argv);
89 CORBA::ORB_var corb =
90 CORBA::ORB_init (main_args_c.get_argc (),
91 main_args_c.get_TCHAR_argv (),
92 "Client_ORB");
95 Client_Task client_task (ior_input_file,
96 corb.in (),
97 ACE_Thread_Manager::instance ());
99 if (client_task.activate (THR_JOINABLE, 1, 1) == -1)
101 ACE_ERROR ((LM_ERROR, "Error activating client thread.\n"));
102 return -1;
105 ACE_Thread_Manager::instance ()->wait ();
108 corb->destroy ();
110 catch (const CORBA::Exception&)
112 // ignore exceptions
115 ACE_DEBUG ((LM_DEBUG, "Threaded client ready.\n"));
117 return 0;