Merge pull request #1551 from DOCGroup/plm_jira_333
[ACE_TAO.git] / TAO / orbsvcs / tests / Bug_4080_Regression / client.cpp
blobe5adde74096e69b41058326a36b1ee26185dc205
2 #include "ace/Get_Opt.h"
3 #include "ace/OS_NS_unistd.h"
4 #include "tao/Object_T.h"
5 #include "testC.h"
7 ACE_TCHAR const *ior = ACE_TEXT ("file://test.ior");
8 CORBA::ULong threads = 2u;
10 int
11 parse_args (int argc, ACE_TCHAR *argv[])
13 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT ("k:t:"));
14 int c;
16 while ((c = get_opts ()) != -1)
17 switch (c)
19 case 'k':
20 ior = get_opts.opt_arg ();
21 break;
23 case 't':
24 threads = ACE_OS::strtoul (get_opts.opt_arg (), 0, 10);
25 break;
27 case '?':
28 default:
29 ACE_ERROR_RETURN ((LM_ERROR,
30 ACE_TEXT ("usage: %s ")
31 ACE_TEXT ("-k <ior> ")
32 ACE_TEXT ("-t <number of threads server has> ")
33 ACE_TEXT ("\n"),
34 argv [0]),
35 -1);
38 ACE_DEBUG ((LM_DEBUG,
39 ACE_TEXT ("args to be used: -k '%s' -t %d\n"),
40 ior,
41 threads));
43 // Indicates sucessful parsing of the command line
44 return 0;
47 int
48 ACE_TMAIN (int argc, ACE_TCHAR *argv[])
50 try
52 CORBA::ORB_var orb = CORBA::ORB_init (argc, argv);
54 if (parse_args (argc, argv) != 0)
55 ACE_ERROR_RETURN ((LM_ERROR,
56 ACE_TEXT ("ERROR: wrong arguments\n")),
57 -1);
59 CORBA::Object_var obj = orb->string_to_object (ior);
61 // Create Hello reference.
62 Test::UIPMC_Object_var test =
63 TAO::Narrow_Utils<Test::UIPMC_Object>::unchecked_narrow (obj.in ());
65 if (CORBA::is_nil (test.in ()))
66 ACE_ERROR_RETURN ((LM_ERROR,
67 ACE_TEXT ("ERROR: IOR is not an UIPMC_Object\n")),
68 -1);
70 for (CORBA::ULong j = 0u; j < threads; ++j)
72 try
74 ACE_DEBUG ((LM_DEBUG, "Sending request %u\n", (unsigned) (j+1u)));
75 test->process ();
77 catch (const CORBA::Exception& ex)
79 ex._tao_print_exception ("Exception caught during send\n");
83 // Give a chance to flush all OS buffers for client.
84 while (orb->work_pending ())
85 orb->perform_work ();
87 ACE_DEBUG ((LM_DEBUG, "Client shutting down\n"));
88 orb->destroy ();
90 catch (const CORBA::Exception& ex)
92 ex._tao_print_exception ("Exception caught in client main ():");
93 return -1;
96 ACE_DEBUG ((LM_DEBUG,
97 ACE_TEXT ("\nClient finished successfully\n")));
98 return 0;