More tests update
[ACE_TAO.git] / TAO / tests / Nested_Event_Loop / client.cpp
blob4c06f40fb06729cae009d4011a2843f33eb3bd6b
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[])
70 try
72 // Initialize the ORB.
73 CORBA::ORB_var orb =
74 CORBA::ORB_init (argc, argv);
76 // Initialize options based on command-line arguments.
77 int parse_args_result = parse_args (argc, argv);
78 if (parse_args_result != 0)
79 return parse_args_result;
81 CORBA::Object_var object =
82 orb->resolve_initial_references ("RootPOA");
84 PortableServer::POA_var root_poa =
85 PortableServer::POA::_narrow (object.in ());
87 PortableServer::POAManager_var poa_manager =
88 root_poa->the_POAManager ();
90 poa_manager->activate ();
92 // Get an object reference from the argument string.
93 object = orb->string_to_object (IOR);
95 // Try to narrow the object reference to a <server> reference.
96 server_var server_object = server::_narrow (object.in ());
98 client_i * servant = 0;
99 ACE_NEW_RETURN (servant,
100 client_i(server_object.in ()),
102 PortableServer::ServantBase_var client_transfer(servant);
104 servant->loop (event_loop_depth,
105 event_loop_iterations);
107 // Shutdown server.
108 if (shutdown_server)
110 server_object->shutdown ();
113 root_poa->destroy (1,
116 catch (const CORBA::Exception& ex)
118 ex._tao_print_exception ("Exception caught:");
119 return -1;
123 return 0;