Revert "Use a variable on the stack to not have a temporary in the call"
[ACE_TAO.git] / TAO / tests / POA / Forwarding / client.cpp
blob02356b5ad391063b4f3e50aa025b0acca73f38a3
2 //=============================================================================
3 /**
4 * @file client.cpp
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"
17 #include "testC.h"
19 static ACE_TCHAR *IOR = 0;
20 static int servers = 2;
21 static int iterations = 3;
23 static int
24 parse_args (int argc, ACE_TCHAR **argv)
26 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("s:i:k:"));
27 int c;
29 while ((c = get_opts ()) != -1)
30 switch (c)
32 case 'k':
33 IOR = get_opts.opt_arg ();
34 break;
35 case 's':
36 servers = ACE_OS::atoi (get_opts.opt_arg ());
37 break;
38 case 'i':
39 iterations = ACE_OS::atoi (get_opts.opt_arg ());
40 break;
41 case '?':
42 default:
43 ACE_ERROR_RETURN ((LM_ERROR,
44 "usage: %s"
45 "-k IOR\n"
46 "-i iterations\n"
47 "\n",
48 argv [0]),
49 -1);
52 if (IOR == 0)
53 ACE_ERROR_RETURN ((LM_ERROR,
54 "Please specify the IOR for the servant\n"),
55 -1);
57 // Indicates successful parsing of command line.
58 return 0;
61 void
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.
72 ACE_DEBUG ((LM_DEBUG,
73 "doit() returned %d\n",
74 result));
77 // Don't forward the last server
78 if (j != servers)
80 ACE_DEBUG ((LM_DEBUG,
81 "Asking server to forward next time\n"));
82 test->forward ();
88 int
89 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
91 try
93 // Initialize the ORB
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.
107 test_var test =
108 test::_narrow (object.in ());
110 do_calls (test.in ());
112 test->shutdown ();
114 orb->destroy ();
116 catch (const CORBA::Exception& ex)
118 ex._tao_print_exception ("Exception caught in client");
119 return -1;
122 return 0;