Merge pull request #2317 from jwillemsen/jwi-deleteop
[ACE_TAO.git] / TAO / orbsvcs / examples / LoadBalancing / client.cpp
blobdc9a42c16385fbf4a5ce1eadba0f1d654224b749
1 #include "TestC.h"
2 #include "ace/Get_Opt.h"
3 #include "ace/streams.h"
5 const ACE_TCHAR *ior = ACE_TEXT("file://obj.ior");
7 int niterations = 100;
8 int number;
10 int
11 parse_args (int argc, ACE_TCHAR *argv[])
13 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("k:n:i:"));
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 'n':
24 number = ACE_OS::atoi (get_opts.opt_arg ());
25 break;
27 case 'i':
28 niterations = ACE_OS::atoi (get_opts.opt_arg ());
29 break;
31 case '?':
32 default:
33 ACE_ERROR_RETURN ((LM_ERROR,
34 "usage: %s "
35 "-k <ior> "
36 "-i <niterations> "
37 "\n",
38 argv [0]),
39 -1);
41 // Indicates successful parsing of the command line
42 return 0;
45 int
46 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
48 try
50 CORBA::ORB_var orb =
51 CORBA::ORB_init (argc, argv);
53 if (parse_args (argc, argv) != 0)
54 return 1;
56 CORBA::Object_var tmp =
57 orb->string_to_object (ior);
59 Test::StockFactory_var stockfactory =
60 Test::StockFactory::_narrow (tmp.in ());
62 if (CORBA::is_nil (stockfactory.in ()))
64 ACE_ERROR_RETURN ((LM_DEBUG,
65 "Nil Test::StockFactory reference <%s>\n",
66 ior),
67 1);
70 ACE_DEBUG ((LM_DEBUG, "Starting Client %d\n", number));
72 for (int i = 0; i < niterations; ++i)
74 Test::Stock_var stock =
75 stockfactory->get_stock ("RHAT");
77 CORBA::String_var full_name = stock->full_name ();
79 CORBA::Double price = stock->price ();
81 ACE_DEBUG ((LM_DEBUG, "The price of a stock in \"%s\" is $%f\n",
82 full_name.in (),
83 price));
86 //stockfactory->shutdown ();
88 orb->destroy ();
90 catch (const CORBA::Exception& ex)
92 ex._tao_print_exception ("Exception caught in client.cpp:");
93 return 1;
96 return 0;