Revert "Use a variable on the stack to not have a temporary in the call"
[ACE_TAO.git] / TAO / tests / CSD_Strategy_Tests / TP_Test_4 / ClientApp.cpp
blobc271f1cba48df787e5d9506a5b008035655e994a
1 #include "ClientApp.h"
2 #include "AppHelper.h"
3 #include "TestAppExceptionC.h"
4 #include "Foo_C_ClientEngine.h"
5 #include "ace/Get_Opt.h"
8 ClientApp::ClientApp()
9 : TestAppBase("TP_Test_4_Client"),
10 ior_(ACE_TEXT("Not Set")),
11 client_kind_(0),
12 client_id_(0)
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();
37 return result;
41 int
42 ClientApp::init(int argc, ACE_TCHAR* argv[])
44 this->orb_ = CORBA::ORB_init(argc, argv);
46 // Parse the command-line args for this application.
47 // * Raises -1 if problems are encountered.
48 // * Returns 1 if the usage statement was explicitly requested.
49 // * Returns 0 otherwise.
50 return this->parse_args(argc, argv);
54 void
55 ClientApp::client_setup()
57 // Turn the ior_ into a Foo_C obj ref.
58 Foo_C_var foo = RefHelper<Foo_C>::string_to_ref(this->orb_.in(),
59 this->ior_.c_str());
61 // Create the ClientEngine object, and give it the Foo_C obj ref.
62 this->engine_ = new Foo_C_ClientEngine(foo.in(), this->client_id_);
66 int
67 ClientApp::run_engine()
69 bool result = this->engine_->execute();
71 return result ? 0 : -1;
75 void
76 ClientApp::cleanup()
81 int
82 ClientApp::parse_args(int argc, ACE_TCHAR* argv[])
84 this->exe_name_ = argv[0];
86 ACE_Get_Opt get_opts(argc, argv, ACE_TEXT("i:k:n:"));
88 int c;
90 while ((c = get_opts()) != -1)
92 int result = 0;
93 switch (c)
95 case 'i':
96 this->ior_ = get_opts.opt_arg();
97 break;
99 case 'k':
100 result = set_arg(this->client_kind_,
101 get_opts.opt_arg(),
103 "client_kind");
104 break;
106 case 'n':
107 result = set_arg(this->client_id_,
108 get_opts.opt_arg(),
110 "client_id");
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[-k <client_kind>]\n"
139 "\t[-n <client_id>]\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: Invalid 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;
189 return 0;