=default for generated implementation copy ctor
[ACE_TAO.git] / TAO / performance-tests / CSD_Strategy / TestApps / ClientApp.cpp
blobb751465096fa238f06a3c6f160fbe0436415db68
1 #include "ClientApp.h"
2 #include "TestInf/AppHelper.h"
3 #include "TestInf/TestAppExceptionC.h"
4 #include "TestServant/Foo_ClientEngine.h"
5 #include "ace/Get_Opt.h"
8 ClientApp::ClientApp()
9 : TestAppBase("CSD_PT_ClientApp"),
10 ior_(ACE_TEXT("Not Set")),
11 client_id_(0),
12 num_loops_(1)
17 ClientApp::~ClientApp()
22 int
23 ClientApp::run_i(int argc, ACE_TCHAR* argv[])
25 int result = this->init(argc, argv);
26 if (result != 0)
28 return result;
31 this->client_setup();
33 result = this->run_engine();
35 this->cleanup();
36 return result;
40 int
41 ClientApp::init(int argc, ACE_TCHAR* argv[])
43 this->orb_ = CORBA::ORB_init(argc, argv);
45 // Parse the command-line args for this application.
46 // * Returns -1 if problems are encountered.
47 // * Returns 1 if the usage statement was explicitly requested.
48 // * Returns 0 otherwise.
49 return this->parse_args(argc, argv);
53 void
54 ClientApp::client_setup()
56 // Turn the ior_ into a Foo obj ref.
57 Foo_var foo = RefHelper<Foo>::string_to_ref(this->orb_.in(),
58 this->ior_.c_str());
60 // Create the ClientEngine object, and give it the Foo obj ref.
61 this->engine_ = new Foo_ClientEngine(foo.in(), this->client_id_);
65 int
66 ClientApp::run_engine()
68 bool result = this->engine_->execute(this->num_loops_);
69 return result ? 0 : -1;
73 void
74 ClientApp::cleanup()
79 int
80 ClientApp::parse_args(int argc, ACE_TCHAR* argv[])
82 this->exe_name_ = argv[0];
84 ACE_Get_Opt get_opts(argc, argv, ACE_TEXT("i:n:l:"));
86 int c;
88 while ((c = get_opts()) != -1)
90 int result = 0;
91 switch (c)
93 case 'i':
94 this->ior_ = get_opts.opt_arg();
95 break;
97 case 'n':
98 result = this->set_arg(this->client_id_,
99 get_opts.opt_arg(),
101 "client_id",
103 break;
105 case 'l':
106 result = this->set_arg(this->num_loops_,
107 get_opts.opt_arg(),
109 "num_loops",
111 break;
113 case '?':
114 this->usage_statement();
115 return 1;
117 default:
118 this->usage_statement();
119 return -1;
122 if (result != 0)
124 return result;
128 return this->arg_dependency_checks();
131 void
132 ClientApp::usage_statement()
134 ACE_ERROR((LM_ERROR,
135 "Usage: %s [options]\n\n"
136 "OPTIONS:\n\n"
137 "\t[-i <ior>]\n"
138 "\t[-n <client_id>]\n"
139 "\t[-l <num_loops>]\n"
140 "\t[-?]\n\n",
141 this->exe_name_.c_str()));
146 ClientApp::arg_dependency_checks()
148 if (this->ior_ == ACE_TEXT("Not Set"))
150 ACE_ERROR((LM_ERROR,
151 "Error: Missing required command-line option (-i <ior>).\n"));
152 this->usage_statement();
153 return -1;
156 if (this->client_id_ <= 0)
158 ACE_ERROR((LM_ERROR,
159 "Error: Required command-line option (-n <client id>).\n"
160 " The client id should be positive integer.\n"));
161 this->usage_statement();
162 return -1;
165 return 0;
170 ClientApp::set_arg(unsigned& value,
171 const ACE_TCHAR* arg,
172 char opt,
173 const char* name,
174 int min)
176 int tmp = ACE_OS::atoi(arg);
178 if (tmp < min)
180 ACE_ERROR((LM_ERROR,
181 "Error: -%c <%s> must be integer type with a value of, "
182 "at least, %d.\n", opt, name, min));
183 this->usage_statement();
184 return -1;
187 value = tmp;
188 return 0;