Merge pull request #1551 from DOCGroup/plm_jira_333
[ACE_TAO.git] / TAO / orbsvcs / tests / Bug_2709_Regression / client.cpp
blob783d061e8fe44840758bb9d3820648db8dd0beb5
1 #include "TestC.h"
2 #include "TestImpl.h"
3 #include "Client_Task.h"
5 #include "ace/Get_Opt.h"
6 #include "ace/Argv_Type_Converter.h"
7 #include "tao/ORB_Core.h"
8 // Ensure that the PI library is linked in when building statically
9 #include "tao/PI/PI.h"
10 #include "Server_Task.h"
12 //////////////////////////////////////////////////////////////////////////
14 ACE_TString collocated_ior_file(ACE_TEXT("collocated_server.ior"));
15 ACE_TString server_ior_file(ACE_TEXT("server.ior"));
17 //////////////////////////////////////////////////////////////////////////
19 int
20 parse_args (int argc, ACE_TCHAR *argv[])
22 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("s:o:"));
23 int c;
25 while ((c = get_opts ()) != -1)
26 switch (c)
28 case 's':
29 server_ior_file = get_opts.opt_arg ();
30 break;
31 case 'o':
32 collocated_ior_file = get_opts.opt_arg ();
33 break;
34 case '?':
35 default:
36 ACE_ERROR_RETURN ((LM_ERROR,
37 "usage: %s "
38 "-s <server_iorfile>"
39 "-o <collocated_iorfile>"
40 "\n",
41 argv [0]),
42 -1);
45 // Indicates successful parsing of the command line
46 return 0;
49 int
50 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
52 int failed = 0;
54 ACE_CString server_orb;
55 server_orb.set ("server_orb");
56 ACE_CString client_orb;
57 client_orb.set ("client_orb");
59 try
61 ACE_Argv_Type_Converter satc (argc, argv);
62 CORBA::ORB_var sorb =
63 CORBA::ORB_init (satc.get_argc (),
64 satc.get_TCHAR_argv (),
65 server_orb.c_str ());
67 ACE_Argv_Type_Converter catc (argc, argv);
68 CORBA::ORB_var corb =
69 CORBA::ORB_init (catc.get_argc (),
70 catc.get_TCHAR_argv (),
71 client_orb.c_str ());
73 if (parse_args (argc, argv) != 0)
74 return 1;
77 ACE_Manual_Event me;
79 Server_Task server_task (collocated_ior_file.c_str(),
80 sorb.in (),
81 me,
82 ACE_Thread_Manager::instance ());
84 if (server_task.activate (THR_NEW_LWP | THR_JOINABLE,
86 1) == -1)
88 ACE_ERROR ((LM_ERROR, "Error activating server task\n"));
91 // Wait for the server thread to do some processing
92 me.wait ();
94 Client_Task client_task (corb.in (),
95 ACE_Thread_Manager::instance (),
96 collocated_ior_file, server_ior_file);
98 if (client_task.activate (THR_NEW_LWP | THR_JOINABLE,
100 1) == -1)
102 ACE_ERROR ((LM_ERROR, "Error activating client task\n"));
105 ACE_Thread_Manager::instance ()->wait ();
108 sorb->destroy ();
110 catch (const CORBA::Exception& ex)
112 ex._tao_print_exception ("Exception caught:");
113 return 1;
116 if (failed)
118 ACE_DEBUG ((LM_ERROR, "Test failed.\n") );
121 return 0;