Merge pull request #1551 from DOCGroup/plm_jira_333
[ACE_TAO.git] / TAO / orbsvcs / tests / Security / MT_SSLIOP / client.cpp
bloba20b3a7266656c4a7fbffc24c3e1cb6014849f09
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)
22 case 'k':
23 ior = get_opts.opt_arg ();
24 break;
26 case 'n':
27 nthreads = ACE_OS::atoi (get_opts.opt_arg ());
28 break;
30 case 'i':
31 niterations = ACE_OS::atoi (get_opts.opt_arg ());
32 break;
34 case 'x':
35 do_shutdown = 1;
36 break;
38 case '?':
39 default:
40 ACE_ERROR_RETURN ((LM_ERROR,
41 "usage: %s "
42 "-k <ior> "
43 "-n <nthreads>"
44 "-i <niterations> "
45 "\n",
46 argv [0]),
47 -1);
49 // Indicates successful parsing of the command line
50 return 0;
53 int
54 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
56 try
58 // Initialize the ORB
59 CORBA::ORB_var orb =
60 CORBA::ORB_init (argc, argv);
62 if (parse_args (argc, argv) != 0)
63 return 1;
65 int len = ACE_OS::strlen(ior) + 1;
66 another_ior = new ACE_TCHAR[len + 1];
67 ACE_OS::strcpy(another_ior, ior);
68 another_ior[len-1] = '1';
69 another_ior[len] = '\0';
71 // Get Object Reference using IOR file
72 CORBA::Object_var object =
73 orb->string_to_object (ior);
75 // Cast to Appropriate Type
76 Simple_Server_var server =
77 Simple_Server::_narrow (object.in ());
79 if (CORBA::is_nil (server.in ()))
81 ACE_ERROR_RETURN ((LM_ERROR,
82 "Object reference <%s> is nil\n", ior),
83 1);
87 object =
88 orb->string_to_object (another_ior);
90 // Cast to Appropriate Type
91 Another_One_var another =
92 Another_One::_narrow (object.in ());
95 Client_Worker client (server.in (),
96 another.in (),
97 niterations);
99 if (client.activate (THR_NEW_LWP | THR_JOINABLE, nthreads) != 0)
100 ACE_ERROR_RETURN ((LM_ERROR,
101 " (%P|%t) Cannot Activate Client Threads\n"),
104 client.thr_mgr ()->wait ();
106 ACE_DEBUG ((LM_DEBUG,
107 "(%P|%t) threads finished\n"));
109 // Shut down the server if -x option given in command line
110 if (do_shutdown)
112 server->shutdown ();
115 // Destroying the ORB..
116 orb->destroy ();
119 catch (const CORBA::Exception& ex)
121 ex._tao_print_exception ("Exception caught:");
122 return 1;
126 return 0;