Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / examples / CSD_Strategy / ThreadPool / ClientApp.cpp
blobe932771d85db3ef5765ef8eb29416dcf9b1fa468
1 #include "ClientApp.h"
2 #include "FooC.h"
3 #include "ace/Get_Opt.h"
4 #include "ace/Log_Msg.h"
7 ClientApp::ClientApp()
12 ClientApp::~ClientApp()
17 int
18 ClientApp::run (int argc, ACE_TCHAR* argv[])
20 CORBA::ORB_var orb
21 = CORBA::ORB_init (argc, argv);
23 // Parse the command-line args for this application.
24 // * Raises -1 if problems are encountered.
25 // * Returns 1 if the usage statement was explicitly requested.
26 // * Returns 0 otherwise.
27 int result = this->parse_args (argc, argv);
28 if (result != 0)
30 return result;
33 CORBA::Object_var obj
34 = orb->string_to_object(this->ior_.c_str());
36 if (CORBA::is_nil(obj.in()))
38 ACE_ERROR((LM_ERROR,
39 "(%P|%t) Failed to convert IOR string to obj ref.\n"));
40 throw TestException();
43 Foo_var foo = Foo::_narrow(obj.in());
45 if (CORBA::is_nil(foo.in()))
47 ACE_ERROR((LM_ERROR,
48 "(%P|%t) Failed to narrow obj ref to Foo interface.\n"));
49 throw TestException();
52 for (CORBA::Long i = 1; i <= 100; i++)
54 foo->op1();
55 foo->op2(i);
56 CORBA::Long value = foo->op3();
58 ACE_DEBUG((LM_DEBUG,
59 "(%P|%t) ===> Value retrieved from op3() == %d\n",
60 value));
62 for (CORBA::Long j = 1; j <= 5; j++)
64 foo->op4(495 + (i * 5) + j);
67 try
69 foo->op5();
71 catch (const FooException& )
73 ACE_DEBUG((LM_DEBUG,
74 "(%P|%t) ===> Caught FooException - as expected.\n"));
79 ACE_DEBUG((LM_DEBUG,
80 "(%P|%t) ===> Tell server that we are done().\n"));
82 foo->done();
84 ACE_DEBUG((LM_DEBUG,
85 "(%P|%t) ===> Back from done().\n"));
87 return 0;
91 int
92 ClientApp::parse_args(int argc, ACE_TCHAR* argv[])
94 this->exe_name_ = argv[0];
96 ACE_Get_Opt get_opts(argc, argv, ACE_TEXT("i:"));
98 int c;
100 while ((c = get_opts()) != -1)
102 switch (c)
104 case 'i':
105 this->ior_ = get_opts.opt_arg();
106 break;
108 case '?':
109 this->usage_statement();
110 return 1;
112 default:
113 this->usage_statement();
114 return -1;
118 return 0;
122 void
123 ClientApp::usage_statement()
125 ACE_ERROR((LM_ERROR,
126 "Usage: %s [options]\n\n"
127 "OPTIONS:\n\n"
128 "\t[-i <ior>]\n"
129 "\t[-?]\n\n",
130 this->exe_name_.c_str()));