2 //=============================================================================
6 * This is a simple test client implementation. Also looks out
7 * for forwarding exceptions
9 * @author Irfan Pyarali
11 //=============================================================================
14 #include "ace/streams.h"
15 #include "ace/Get_Opt.h"
16 #include "ace/Read_Buffer.h"
19 static ACE_TCHAR
*IOR
= 0;
20 static int servers
= 2;
21 static int iterations
= 3;
24 parse_args (int argc
, ACE_TCHAR
**argv
)
26 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("s:i:k:"));
29 while ((c
= get_opts ()) != -1)
33 IOR
= get_opts
.opt_arg ();
36 servers
= ACE_OS::atoi (get_opts
.opt_arg ());
39 iterations
= ACE_OS::atoi (get_opts
.opt_arg ());
43 ACE_ERROR_RETURN ((LM_ERROR
,
53 ACE_ERROR_RETURN ((LM_ERROR
,
54 "Please specify the IOR for the servant\n"),
57 // Indicates successful parsing of command line.
62 do_calls (test_ptr test
)
64 for (int j
= 1; j
<= servers
; j
++)
66 for (int i
= 1; i
<= iterations
; i
++)
68 // Invoke the doit() method of the test reference.
69 CORBA::Long result
= test
->doit ();
71 // Print the result of doit () method of the test reference.
73 "doit() returned %d\n",
77 // Don't forward the last server
81 "Asking server to forward next time\n"));
89 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
94 CORBA::ORB_var orb
= CORBA::ORB_init (argc
, argv
);
96 // Initialize options based on command-line arguments.
97 int parse_args_result
=
98 parse_args (argc
, argv
);
99 if (parse_args_result
!= 0)
100 return parse_args_result
;
102 // Get an object reference from the argument string.
103 CORBA::Object_var object
=
104 orb
->string_to_object (IOR
);
106 // Try to narrow the object reference to a test reference.
108 test::_narrow (object
.in ());
110 do_calls (test
.in ());
116 catch (const CORBA::Exception
& ex
)
118 ex
._tao_print_exception ("Exception caught in client");