1 #include "PP_Test_Client.h"
3 #include "tao/Timeprobe.h"
4 #include "tao/TAO_Internal.h"
7 #include "ace/Read_Buffer.h"
8 #include "ace/OS_NS_stdio.h"
9 #include "ace/OS_NS_errno.h"
10 #include "ace/OS_NS_fcntl.h"
11 #include "ace/OS_NS_unistd.h"
12 #include "ace/OS_NS_string.h"
14 #if defined (ACE_ENABLE_TIMEPROBES)
16 static const char *PP_Test_Client_Timeprobe_Description
[] =
18 "PP_Test_Client::send_oneway - start",
19 "PP_Test_Client::send_oneway - end",
21 "PP_Test_Client::send_void - start",
22 "PP_Test_Client::send_void - end",
24 "PP_Test_Client::make_pluggable - start",
25 "PP_Test_Client::make_pluggable - end",
27 "PP_Test_Client::server_shutdown - start",
28 "PP_Test_Client::server_shutdown - end"
33 // Timeprobe description table start key
34 PP_TEST_CLIENT_SEND_ONEWAY_START
= 10000,
35 PP_TEST_CLIENT_SEND_ONEWAY_END
,
37 PP_TEST_CLIENT_SEND_VOID_START
,
38 PP_TEST_CLIENT_SEND_VOID_END
,
40 PP_TEST_CLIENT_MAKE_PLUGGABLE_START
,
41 PP_TEST_CLIENT_MAKE_PLUGGABLE_END
,
43 PP_TEST_CLIENT_SERVER_SHUTDOWN_START
,
44 PP_TEST_CLIENT_SERVER_SHUTDOWN_END
48 ACE_TIMEPROBE_EVENT_DESCRIPTIONS (PP_Test_Client_Timeprobe_Description
,
49 PP_TEST_CLIENT_SEND_ONEWAY_START
);
51 #endif /* ACE_ENABLE_TIMEPROBES */
54 PP_Test_Client::PP_Test_Client (int shutdown
)
59 objref_ (Pluggable_Test::_nil ()),
62 factory_ior_file_ (0),
63 f_handle_ (ACE_INVALID_HANDLE
),
69 // Reads the Cubit factory ior from a file
72 PP_Test_Client::read_ior (ACE_TCHAR
*filename
)
74 // Open the file for reading.
75 this->f_handle_
= ACE_OS::open (filename
,0);
77 if (this->f_handle_
== ACE_INVALID_HANDLE
)
79 ACE_ERROR_RETURN ((LM_ERROR
,
80 "Unable to open %s for writing: %p\n",
85 ACE_Read_Buffer
ior_buffer (this->f_handle_
);
87 char *data
= ior_buffer
.read ();
91 ACE_ERROR_RETURN ((LM_ERROR
,
92 "Unable to allocate memory to read ior: %p\n"),
96 this->factory_key_
= ACE_OS::strdup (ACE_TEXT_CHAR_TO_TCHAR(data
));
98 ior_buffer
.alloc ()->free (data
);
103 // Parses the command line arguments and returns an error status.
106 PP_Test_Client::parse_args ()
108 ACE_Get_Opt
get_opts (argc_
, argv_
, ACE_TEXT("ovdn:f:k:x"));
112 while ((c
= get_opts ()) != -1)
116 this->only_void_
= 1;
119 this->only_oneway_
= 1;
121 case 'd': // debug flag
124 case 'n': // loop count
126 (u_int
) ACE_OS::atoi (get_opts
.opt_arg ());
128 case 'f': // read the IOR from the file.
129 result
= this->read_ior (get_opts
.opt_arg ());
131 ACE_ERROR_RETURN ((LM_ERROR
,
132 "Unable to read ior from %s : %p\n",
133 get_opts
.opt_arg ()),
136 case 'k': // read the cubit IOR from the command-line.
138 ACE_OS::strdup (get_opts
.opt_arg ());
141 ACE_DEBUG ((LM_DEBUG
, "We will shutdown the server\n"));
146 ACE_ERROR_RETURN ((LM_ERROR
,
152 " [-f factory-obj-ref-key-file]"
160 // Indicates successful parsing of command line.
167 PP_Test_Client::send_oneway ()
171 ACE_FUNCTION_TIMEPROBE (PP_TEST_CLIENT_SEND_ONEWAY_START
);
172 this->objref_
->send_oneway ();
175 catch (const CORBA::Exception
& ex
)
177 ex
._tao_print_exception ("from send_oneway");
179 this->error_count_
++;
186 PP_Test_Client::send_void ()
190 ACE_FUNCTION_TIMEPROBE (PP_TEST_CLIENT_SEND_VOID_START
);
191 this->objref_
->send_void ();
194 catch (const CORBA::Exception
& ex
)
196 ex
._tao_print_exception ("from send_void");
198 this->error_count_
++;
204 // Execute client example code.
207 PP_Test_Client::run ()
209 if (this->only_void_
)
211 return this->run_void ();
214 if (this->only_oneway_
)
216 return this->run_oneway ();
221 // Show the results one type at a time.
224 this->call_count_
= 0;
225 this->error_count_
= 0;
227 for (i
= 0; i
< this->loop_count_
; i
++)
233 this->call_count_
= 0;
234 this->error_count_
= 0;
236 for (i
= 0; i
< this->loop_count_
; i
++)
238 this->send_oneway ();
241 // This causes a memPartFree on VxWorks.
242 ACE_FUNCTION_TIMEPROBE (PP_TEST_CLIENT_SERVER_SHUTDOWN_START
);
243 this->shutdown_server (this->shutdown_
);
245 return this->error_count_
== 0 ? 0 : 1;
249 PP_Test_Client::shutdown_server (int do_shutdown
)
255 ACE_DEBUG ((LM_DEBUG
,
256 "shutdown on Pluggable_Test object\n"));
258 this->objref_
->shutdown ();
261 ACE_DEBUG ((LM_DEBUG
,
262 "server, please ACE_OS::exit"));
265 catch (const CORBA::Exception
& ex
)
267 ex
._tao_print_exception ("from shutdown_server");
275 PP_Test_Client::run_oneway ()
282 this->call_count_
= 0;
283 this->error_count_
= 0;
285 for (i
= 0; i
< this->loop_count_
; i
++)
287 this->send_oneway ();
292 ACE_DEBUG ((LM_DEBUG
,
293 "shutdown on Pluggable_Test object\n"));
295 ACE_FUNCTION_TIMEPROBE (PP_TEST_CLIENT_SERVER_SHUTDOWN_START
);
297 this->objref_
->shutdown ();
299 ACE_DEBUG ((LM_DEBUG
,
300 "server, please ACE_OS::exit"));
303 catch (const CORBA::Exception
& ex
)
305 ex
._tao_print_exception ("from objref_->shutdown");
309 return this->error_count_
== 0 ? 0 : 1;
313 PP_Test_Client::run_void ()
320 this->call_count_
= 0;
321 this->error_count_
= 0;
323 for (i
= 0; i
< this->loop_count_
; i
++)
330 ACE_DEBUG ((LM_DEBUG
,
331 "shutdown on Pluggable_Test object\n"));
333 ACE_FUNCTION_TIMEPROBE (PP_TEST_CLIENT_SERVER_SHUTDOWN_START
);
335 this->objref_
->shutdown ();
337 ACE_DEBUG ((LM_DEBUG
,
338 "server, please ACE_OS::exit"));
341 catch (const CORBA::Exception
& ex
)
343 ex
._tao_print_exception ("from objref_->shutdown");
347 return this->error_count_
== 0 ? 0 : 1;
350 PP_Test_Client::~PP_Test_Client ()
352 // Free resources and close the IOR files.
353 if (this->factory_ior_file_
)
355 ACE_OS::fclose (this->factory_ior_file_
);
358 if (this->f_handle_
!= ACE_INVALID_HANDLE
)
360 ACE_OS::close (this->f_handle_
);
363 if (this->factory_key_
!= 0)
365 ACE_OS::free (this->factory_key_
);
370 PP_Test_Client::init (int argc
, ACE_TCHAR
**argv
)
378 this->orb_
= CORBA::ORB_init (this->argc_
,
381 // Parse command line and verify parameters.
382 if (this->parse_args () == -1)
387 if (this->factory_key_
== 0)
389 ACE_ERROR_RETURN ((LM_ERROR
,
390 "%s: no factory key specified\n",
395 CORBA::Object_var factory_object
=
396 this->orb_
->string_to_object (this->factory_key_
);
399 Pluggable_Test_Factory::_narrow (factory_object
.in());
401 if (CORBA::is_nil (this->factory_
.in ()))
403 ACE_ERROR_RETURN ((LM_ERROR
,
404 "invalid factory key <%s>\n",
409 ACE_DEBUG ((LM_DEBUG
,
410 "Factory received OK\n"));
412 // Now retrieve the Pluggable_Test obj ref corresponding to the key.
413 ACE_FUNCTION_TIMEPROBE (PP_TEST_CLIENT_MAKE_PLUGGABLE_START
);
415 this->objref_
= this->factory_
->make_pluggable_test ();
417 if (CORBA::is_nil (this->objref_
.in ()))
419 ACE_ERROR_RETURN ((LM_ERROR
,
420 "null objref returned by factory\n"),
424 catch (const CORBA::Exception
& ex
)
426 ex
._tao_print_exception ("Pluggable_Test::init");