Merge pull request #2301 from sonndinh/remove-dup-reactor-functions
[ACE_TAO.git] / TAO / tests / Collocated_ThruP_Sp / Collocated_Test.cpp
blobc39aa8eafefae2d63f7d0a210e5384c9d2e08151
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"
8 const ACE_TCHAR *output = ACE_TEXT("test.ior");
9 const ACE_TCHAR *input = ACE_TEXT("file://test.ior");
10 // static int named_orbs = 0;
11 ACE_CString server_orb;
12 ACE_CString client_orb;
13 int
14 parse_args (int argc, ACE_TCHAR *argv[])
16 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("k:o:n"));
17 int c;
19 while ((c = get_opts ()) != -1)
20 switch (c)
22 case 'o':
23 output = get_opts.opt_arg ();
24 break;
25 case 'k':
26 input = get_opts.opt_arg ();
27 break;
28 case 'n':
29 // named_orbs = 1;
30 server_orb.set ("server_orb");
31 client_orb.set ("client_orb");
32 break;
33 case '?':
34 default:
35 // This is a hack but that is okay!
36 return 0;
38 // Indicates successful parsing of the command line
39 return 0;
42 int
43 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
45 if (parse_args (argc, argv) == -1)
46 return -1;
48 try
50 ACE_Argv_Type_Converter satc (argc, argv);
51 CORBA::ORB_var sorb =
52 CORBA::ORB_init (satc.get_argc (),
53 satc.get_TCHAR_argv (),
54 server_orb.c_str ());
56 ACE_Manual_Event me;
57 Server_Task server_task (output,
58 sorb.in (),
59 me,
60 ACE_Thread_Manager::instance ());
62 if (server_task.activate (THR_NEW_LWP | THR_JOINABLE,
64 1) == -1)
66 ACE_ERROR ((LM_ERROR, "Error activating server task\n"));
69 // Wait for the server thread to do some processing
70 me.wait ();
72 ACE_Argv_Type_Converter catc (argc, argv);
73 CORBA::ORB_var corb =
74 CORBA::ORB_init (catc.get_argc (),
75 catc.get_TCHAR_argv (),
76 client_orb.c_str ());
78 Client_Task client_task (input,
79 corb.in (),
80 ACE_Thread_Manager::instance ());
82 if (client_task.activate (THR_NEW_LWP | THR_JOINABLE,
84 1) == -1)
86 ACE_ERROR ((LM_ERROR, "Error activating client task\n"));
89 // Wait for the client and server to finish
90 ACE_Thread_Manager::instance ()->wait ();
92 // Now that all threads have completed we can destroy the ORB
93 sorb->destroy ();
94 if (server_orb != client_orb)
96 corb->destroy ();
99 catch (const CORBA::Exception&)
101 // Ignore exceptions..
103 return 0;