Revert "Use a variable on the stack to not have a temporary in the call"
[ACE_TAO.git] / TAO / tests / Bug_2084_Regression / Collocated_Test.cpp
blob0752ac2b4715c6f7109bed2dc4df40092b4f9315
1 #include "Server_Task.h"
2 #include "Client_Task.h"
3 #include "ace/Get_Opt.h"
4 #include "ace/Argv_Type_Converter.h"
5 #include "ace/SString.h"
6 #include "ace/Manual_Event.h"
7 #include <ace/ARGV.h>
8 #include <iostream>
10 const ACE_TCHAR *output = ACE_TEXT("test.ior");
11 const ACE_TCHAR *input = ACE_TEXT("file://test.ior");
12 // static int named_orbs = 0;
13 ACE_CString server_orb;
14 ACE_CString client_orb;
15 int
16 parse_args (int argc, ACE_TCHAR *argv[])
18 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("k:o:n"));
19 int c;
21 while ((c = get_opts ()) != -1)
22 switch (c)
24 case 'o':
25 output = get_opts.opt_arg ();
26 break;
27 case 'k':
28 input = get_opts.opt_arg ();
29 break;
30 case 'n':
31 // named_orbs = 1;
32 server_orb.set ("server_orb");
33 client_orb.set ("client_orb");
34 break;
35 case '?':
36 default:
37 // This is a hack but that is okay!
38 return 0;
40 // Indicates successful parsing of the command line
41 return 0;
44 int
45 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
47 if (parse_args (argc,
48 argv) == -1)
49 return -1;
51 try
53 // Keep a copy of the ORB options args
54 ACE_ARGV orb_args;
55 for (int i = 1; i < argc; ++i)
57 if (orb_args.add (argv[i]) == -1)
58 return -1;
61 ACE_Argv_Type_Converter satc (argc, argv);
62 // This eats all orb-specific options!
63 CORBA::ORB_var sorb =
64 CORBA::ORB_init (satc.get_argc (),
65 satc.get_TCHAR_argv (),
66 server_orb.c_str ());
68 ACE_Manual_Event me;
69 Server_Task server_task (output,
70 sorb.in (),
71 me,
72 ACE_Thread_Manager::instance ());
74 if (server_task.activate (THR_NEW_LWP | THR_JOINABLE,
76 1) == -1)
78 ACE_ERROR ((LM_ERROR, "Error activating server task\n"));
81 // Wait for the server thread to do some processing
82 me.wait ();
84 // Restore the orb-specific options.
85 argc = orb_args.argc ();
86 for (int i = 1; i < argc; ++i)
88 argv[i] = const_cast<ACE_TCHAR*> (orb_args[i]);
90 ACE_Argv_Type_Converter catc (argc, argv);
91 CORBA::ORB_var corb =
92 CORBA::ORB_init (catc.get_argc(),
93 catc.get_TCHAR_argv(),
94 client_orb.c_str ());
96 Client_Task client_task (input,
97 corb.in (),
98 ACE_Thread_Manager::instance ());
100 if (client_task.activate (THR_NEW_LWP | THR_JOINABLE,
102 1) == -1)
104 ACE_ERROR ((LM_ERROR, "Error activating client task\n"));
107 // Wait for the client and server to finish
108 ACE_Thread_Manager::instance ()->wait ();
110 // Now that all threads have completed we can destroy the ORB
111 sorb->destroy ();
112 if (server_orb != client_orb)
114 corb->destroy ();
117 catch (const CORBA::Exception&)
119 // Ignore exceptions..
121 return 0;