Merge pull request #2309 from mitza-oci/warnings
[ACE_TAO.git] / TAO / orbsvcs / tests / Security / MT_SSLIOP / client.cpp
blob553c898e047a5cdb1e682a6f5cc5074bd13947a6
1 #include "ace/Get_Opt.h"
2 #include "Client_Worker.h"
5 const ACE_TCHAR *ior = ACE_TEXT("file://test.ior");
6 ACE_TCHAR *another_ior = 0;
8 int niterations = 5;
9 int do_shutdown = 0;
10 int nthreads = 5;
12 int
13 parse_args (int argc, ACE_TCHAR *argv[])
15 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("k:n:i:x"));
16 int c;
18 while ((c = get_opts ()) != -1)
19 switch (c)
21 case 'k':
22 ior = get_opts.opt_arg ();
23 break;
25 case 'n':
26 nthreads = ACE_OS::atoi (get_opts.opt_arg ());
27 break;
29 case 'i':
30 niterations = ACE_OS::atoi (get_opts.opt_arg ());
31 break;
33 case 'x':
34 do_shutdown = 1;
35 break;
37 case '?':
38 default:
39 ACE_ERROR_RETURN ((LM_ERROR,
40 "usage: %s "
41 "-k <ior> "
42 "-n <nthreads>"
43 "-i <niterations> "
44 "\n",
45 argv [0]),
46 -1);
48 // Indicates successful parsing of the command line
49 return 0;
52 int
53 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
55 try
57 // Initialize the ORB
58 CORBA::ORB_var orb =
59 CORBA::ORB_init (argc, argv);
61 if (parse_args (argc, argv) != 0)
62 return 1;
64 int len = ACE_OS::strlen(ior) + 1;
65 another_ior = new ACE_TCHAR[len + 1];
66 ACE_OS::strcpy(another_ior, ior);
67 another_ior[len-1] = '1';
68 another_ior[len] = '\0';
70 // Get Object Reference using IOR file
71 CORBA::Object_var object =
72 orb->string_to_object (ior);
74 // Cast to Appropriate Type
75 Simple_Server_var server =
76 Simple_Server::_narrow (object.in ());
78 if (CORBA::is_nil (server.in ()))
80 ACE_ERROR_RETURN ((LM_ERROR,
81 "Object reference <%s> is nil\n", ior),
82 1);
86 object =
87 orb->string_to_object (another_ior);
89 // Cast to Appropriate Type
90 Another_One_var another =
91 Another_One::_narrow (object.in ());
94 Client_Worker client (server.in (),
95 another.in (),
96 niterations);
98 if (client.activate (THR_NEW_LWP | THR_JOINABLE, nthreads) != 0)
99 ACE_ERROR_RETURN ((LM_ERROR,
100 " (%P|%t) Cannot Activate Client Threads\n"),
103 client.thr_mgr ()->wait ();
105 ACE_DEBUG ((LM_DEBUG,
106 "(%P|%t) threads finished\n"));
108 // Shut down the server if -x option given in command line
109 if (do_shutdown)
111 server->shutdown ();
114 // Destroying the ORB..
115 orb->destroy ();
118 catch (const CORBA::Exception& ex)
120 ex._tao_print_exception ("Exception caught:");
121 return 1;
125 return 0;