Merge pull request #2309 from mitza-oci/warnings
[ACE_TAO.git] / TAO / tests / Nested_Event_Loop / client.cpp
blob17ecae6352ecf9cd434af7d530226d1fb5cc369b
1 #include "ace/Get_Opt.h"
2 #include "ace/Read_Buffer.h"
3 #include "test_i.h"
5 #include "tao/Strategies/advanced_resource.h"
7 // Name of file contains ior.
8 static const ACE_TCHAR *IOR = ACE_TEXT ("file://ior");
10 // Default event_loop_depth.
11 static CORBA::ULong event_loop_depth = 6;
13 // Default event_loop_iterations.
14 static CORBA::ULong event_loop_iterations = 6;
16 // Flag indicates whether to shutdown remote server or not upon client
17 // shutdown.
18 static int shutdown_server = 0;
20 static int
21 parse_args (int argc, ACE_TCHAR **argv)
23 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("k:d:i:x"));
24 int c;
26 while ((c = get_opts ()) != -1)
27 switch (c)
29 case 'k':
30 IOR = get_opts.opt_arg ();
31 break;
33 case 'i':
34 event_loop_iterations = ACE_OS::atoi (get_opts.opt_arg ());
35 break;
37 case 'd':
38 event_loop_depth = ACE_OS::atoi (get_opts.opt_arg ());
39 break;
41 case 'x':
42 shutdown_server = 1;
43 break;
45 case '?':
46 default:
47 ACE_ERROR_RETURN ((LM_ERROR,
48 "usage: %s "
49 "-k IOR "
50 "-i event loop iterations "
51 "-d event loop depth "
52 "-x shutdown server "
53 "\n",
54 argv [0]),
55 -1);
58 if (IOR == 0)
59 ACE_ERROR_RETURN ((LM_ERROR,
60 "Please specify the IOR for the servant\n"), -1);
62 // Indicates successful parsing of command line.
63 return 0;
66 int
67 ACE_TMAIN (int argc, ACE_TCHAR *argv[])
69 try
71 // Initialize the ORB.
72 CORBA::ORB_var orb =
73 CORBA::ORB_init (argc, argv);
75 // Initialize options based on command-line arguments.
76 int parse_args_result = parse_args (argc, argv);
77 if (parse_args_result != 0)
78 return parse_args_result;
80 CORBA::Object_var object =
81 orb->resolve_initial_references ("RootPOA");
83 PortableServer::POA_var root_poa =
84 PortableServer::POA::_narrow (object.in ());
86 PortableServer::POAManager_var poa_manager =
87 root_poa->the_POAManager ();
89 poa_manager->activate ();
91 // Get an object reference from the argument string.
92 object = orb->string_to_object (IOR);
94 // Try to narrow the object reference to a <server> reference.
95 server_var server_object = server::_narrow (object.in ());
97 client_i * servant = 0;
98 ACE_NEW_RETURN (servant,
99 client_i(server_object.in ()),
101 PortableServer::ServantBase_var client_transfer(servant);
103 servant->loop (event_loop_depth,
104 event_loop_iterations);
106 // Shutdown server.
107 if (shutdown_server)
109 server_object->shutdown ();
112 root_poa->destroy (true, true);
114 catch (const CORBA::Exception& ex)
116 ex._tao_print_exception ("Exception caught:");
117 return -1;
121 return 0;