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 (void)
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 (void)
172 ACE_FUNCTION_TIMEPROBE (PP_TEST_CLIENT_SEND_ONEWAY_START
);
173 this->objref_
->send_oneway ();
176 catch (const CORBA::Exception
& ex
)
178 ex
._tao_print_exception ("from send_oneway");
180 this->error_count_
++;
187 PP_Test_Client::send_void (void)
192 ACE_FUNCTION_TIMEPROBE (PP_TEST_CLIENT_SEND_VOID_START
);
193 this->objref_
->send_void ();
196 catch (const CORBA::Exception
& ex
)
198 ex
._tao_print_exception ("from send_void");
200 this->error_count_
++;
206 // Execute client example code.
209 PP_Test_Client::run ()
211 if (this->only_void_
)
213 return this->run_void ();
216 if (this->only_oneway_
)
218 return this->run_oneway ();
223 // Show the results one type at a time.
226 this->call_count_
= 0;
227 this->error_count_
= 0;
229 for (i
= 0; i
< this->loop_count_
; i
++)
235 this->call_count_
= 0;
236 this->error_count_
= 0;
238 for (i
= 0; i
< this->loop_count_
; i
++)
240 this->send_oneway ();
243 // This causes a memPartFree on VxWorks.
244 ACE_FUNCTION_TIMEPROBE (PP_TEST_CLIENT_SERVER_SHUTDOWN_START
);
245 this->shutdown_server (this->shutdown_
);
247 return this->error_count_
== 0 ? 0 : 1;
251 PP_Test_Client::shutdown_server (int do_shutdown
)
258 ACE_DEBUG ((LM_DEBUG
,
259 "shutdown on Pluggable_Test object\n"));
261 this->objref_
->shutdown ();
264 ACE_DEBUG ((LM_DEBUG
,
265 "server, please ACE_OS::exit"));
268 catch (const CORBA::Exception
& ex
)
270 ex
._tao_print_exception ("from shutdown_server");
278 PP_Test_Client::run_oneway (void)
286 this->call_count_
= 0;
287 this->error_count_
= 0;
289 for (i
= 0; i
< this->loop_count_
; i
++)
291 this->send_oneway ();
296 ACE_DEBUG ((LM_DEBUG
,
297 "shutdown on Pluggable_Test object\n"));
299 ACE_FUNCTION_TIMEPROBE (PP_TEST_CLIENT_SERVER_SHUTDOWN_START
);
301 this->objref_
->shutdown ();
303 ACE_DEBUG ((LM_DEBUG
,
304 "server, please ACE_OS::exit"));
307 catch (const CORBA::Exception
& ex
)
309 ex
._tao_print_exception ("from objref_->shutdown");
313 return this->error_count_
== 0 ? 0 : 1;
317 PP_Test_Client::run_void (void)
325 this->call_count_
= 0;
326 this->error_count_
= 0;
328 for (i
= 0; i
< this->loop_count_
; i
++)
335 ACE_DEBUG ((LM_DEBUG
,
336 "shutdown on Pluggable_Test object\n"));
338 ACE_FUNCTION_TIMEPROBE (PP_TEST_CLIENT_SERVER_SHUTDOWN_START
);
340 this->objref_
->shutdown ();
342 ACE_DEBUG ((LM_DEBUG
,
343 "server, please ACE_OS::exit"));
346 catch (const CORBA::Exception
& ex
)
348 ex
._tao_print_exception ("from objref_->shutdown");
352 return this->error_count_
== 0 ? 0 : 1;
355 PP_Test_Client::~PP_Test_Client (void)
357 // Free resources and close the IOR files.
358 if (this->factory_ior_file_
)
360 ACE_OS::fclose (this->factory_ior_file_
);
363 if (this->f_handle_
!= ACE_INVALID_HANDLE
)
365 ACE_OS::close (this->f_handle_
);
368 if (this->factory_key_
!= 0)
370 ACE_OS::free (this->factory_key_
);
375 PP_Test_Client::init (int argc
, ACE_TCHAR
**argv
)
383 this->orb_
= CORBA::ORB_init (this->argc_
,
386 // Parse command line and verify parameters.
387 if (this->parse_args () == -1)
392 if (this->factory_key_
== 0)
394 ACE_ERROR_RETURN ((LM_ERROR
,
395 "%s: no factory key specified\n",
400 CORBA::Object_var factory_object
=
401 this->orb_
->string_to_object (this->factory_key_
);
404 Pluggable_Test_Factory::_narrow (factory_object
.in());
406 if (CORBA::is_nil (this->factory_
.in ()))
408 ACE_ERROR_RETURN ((LM_ERROR
,
409 "invalid factory key <%s>\n",
414 ACE_DEBUG ((LM_DEBUG
,
415 "Factory received OK\n"));
417 // Now retrieve the Pluggable_Test obj ref corresponding to the key.
418 ACE_FUNCTION_TIMEPROBE (PP_TEST_CLIENT_MAKE_PLUGGABLE_START
);
420 this->objref_
= this->factory_
->make_pluggable_test ();
422 if (CORBA::is_nil (this->objref_
.in ()))
424 ACE_ERROR_RETURN ((LM_ERROR
,
425 "null objref returned by factory\n"),
429 catch (const CORBA::Exception
& ex
)
431 ex
._tao_print_exception ("Pluggable_Test::init");