Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / tests / Single_Read / client.cpp
bloba2c13bc6ef7542ff9bb0c90dc3c1f6ded0c602b5
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[])
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 // Get an object reference from the argument string.
82 CORBA::Object_var object =
83 orb->string_to_object (IOR);
85 // Try to narrow the object reference to a <test> reference.
86 test_var test_object = test::_narrow (object.in ());
88 test::data the_data0 (data_bytes);
89 the_data0.length (data_bytes);
91 data_bytes *= 10;
92 test::data the_data1 (data_bytes);
93 the_data1.length (data_bytes);
95 data_bytes /= 100;
96 test::data the_data2 (data_bytes);
97 the_data2.length (data_bytes);
99 for (CORBA::ULong i = 1; i <= iterations; ++i)
101 ACE_DEBUG ((LM_DEBUG,
102 "client: Iteration %d @ %T\n",
103 i));
105 // Invoke the oneway method.
106 test_object->method (i,
107 the_data0);
109 // Invoke the oneway method.
110 test_object->method (i,
111 the_data1);
113 // Invoke the oneway method.
114 test_object->method (i,
115 the_data2);
118 // Shutdown server.
119 if (shutdown_server)
121 ACE_DEBUG ((LM_DEBUG,
122 "(%P|%t) Sending a shutdown call..\n"));
123 test_object->shutdown ();
126 // Destroy the ORB. On some platforms, e.g., Win32, the socket
127 // library is closed at the end of main(). This means that any
128 // socket calls made after main() fail. Hence if we wait for
129 // static destructors to flush the queues, it will be too late.
130 // Therefore, we use explicit destruction here and flush the
131 // queues before main() ends.
132 orb->destroy ();
134 catch (const CORBA::Exception& ex)
136 ex._tao_print_exception ("Exception caught:");
137 return -1;
141 return 0;