Revert "Minor modernization of DynamicAny code"
[ACE_TAO.git] / TAO / tests / Single_Read / client.cpp
blob1db6e239f6b409f1e08184ec779d624a283c9833
1 #include "ace/Get_Opt.h"
2 #include "ace/Read_Buffer.h"
3 #include "testC.h"
5 // Name of file contains ior.
6 static const ACE_TCHAR *IOR = ACE_TEXT ("file://ior");
8 // Default iterations.
9 static u_long iterations = 20;
11 // Default number of bytes to send as data.
12 static CORBA::ULong data_bytes = 1000;
14 // Flag indicates whether to shutdown remote server or not upon client
15 // shutdown.
16 static int shutdown_server = 0;
18 static int
19 parse_args (int argc, ACE_TCHAR **argv)
21 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("k:i:d:x"));
22 int c;
24 while ((c = get_opts ()) != -1)
25 switch (c)
27 case 'k':
28 IOR = get_opts.opt_arg ();
29 break;
30 case 'i':
31 iterations = ACE_OS::atoi (get_opts.opt_arg ());
32 break;
33 case 'd':
34 data_bytes = ACE_OS::atoi (get_opts.opt_arg ());
35 break;
36 case 'x':
37 shutdown_server = 1;
38 break;
39 case '?':
40 default:
41 ACE_ERROR_RETURN ((LM_ERROR,
42 "usage: %s "
43 "-k IOR "
44 "-i iterations "
45 "-d data bytes "
46 "-x shutdown server "
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"), -1);
56 if (data_bytes < 10)
57 ACE_ERROR_RETURN ((LM_ERROR,
58 "Please specify a value of more than 10 bytes\n"),
59 -1);
61 // Indicates successful parsing of command line.
62 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 // Get an object reference from the argument string.
81 CORBA::Object_var object =
82 orb->string_to_object (IOR);
84 // Try to narrow the object reference to a <test> reference.
85 test_var test_object = test::_narrow (object.in ());
87 test::data the_data0 (data_bytes);
88 the_data0.length (data_bytes);
90 data_bytes *= 10;
91 test::data the_data1 (data_bytes);
92 the_data1.length (data_bytes);
94 data_bytes /= 100;
95 test::data the_data2 (data_bytes);
96 the_data2.length (data_bytes);
98 for (CORBA::ULong i = 1; i <= iterations; ++i)
100 ACE_DEBUG ((LM_DEBUG,
101 "client: Iteration %d @ %T\n",
102 i));
104 // Invoke the oneway method.
105 test_object->method (i,
106 the_data0);
108 // Invoke the oneway method.
109 test_object->method (i,
110 the_data1);
112 // Invoke the oneway method.
113 test_object->method (i,
114 the_data2);
117 // Shutdown server.
118 if (shutdown_server)
120 ACE_DEBUG ((LM_DEBUG,
121 "(%P|%t) Sending a shutdown call..\n"));
122 test_object->shutdown ();
125 // Destroy the ORB. On some platforms, e.g., Win32, the socket
126 // library is closed at the end of main(). This means that any
127 // socket calls made after main() fail. Hence if we wait for
128 // static destructors to flush the queues, it will be too late.
129 // Therefore, we use explicit destruction here and flush the
130 // queues before main() ends.
131 orb->destroy ();
133 catch (const CORBA::Exception& ex)
135 ex._tao_print_exception ("Exception caught:");
136 return -1;
140 return 0;