Use =default for skeleton copy constructor
[ACE_TAO.git] / TAO / performance-tests / POA / Demux / demux_test_client.cpp
blobf76ede02eed90cd6c99ce12166ccc06e7c808561
1 //=============================================================================
2 /**
3 * @file demux_test_client.cpp
5 * @author Aniruddha Gokhale
6 */
7 //=============================================================================
10 #include "demux_test_client.h"
11 #include "tao/debug.h"
12 #include "ace/OS_NS_stdio.h"
13 #include "ace/OS_NS_time.h"
14 #include "ace/OS_NS_string.h"
16 // Constructor
17 Demux_Test_Client::Demux_Test_Client ()
18 : argc_ (0),
19 argv_ (0),
20 is_ (Demux_Test_Client::LINEAR),
21 num_POAs_ (1),
22 // default number of child POAs is 1 and each one will always have 1 object
23 num_objs_ (1),
24 num_ops_ (1),
25 demux_test_ (TAO_DEMUX_TEST_MAX_POAS * TAO_DEMUX_TEST_MAX_OBJS),
26 loop_count_ (1),
27 ior_fp_ (0),
28 result_fp_ (0),
29 step_ (5)
33 // destructor
34 Demux_Test_Client::~Demux_Test_Client ()
39 // initialize the Demux_Test_Client
42 int
43 Demux_Test_Client::init (int argc, ACE_TCHAR *argv [])
45 this->argc_ = argc;
46 this->argv_ = argv;
48 // Grab the ORB
49 try
51 // get the underlying ORB
52 this->orb_ =
53 CORBA::ORB_init (argc, argv);
55 catch (const CORBA::Exception& ex)
57 ex._tao_print_exception ("ORB_init");
58 throw;
61 // now parse the rest of the arguments to determine the POA depth, the number
62 // of objects with each POA and other info
64 if (this->parse_args () == -1)
65 ACE_ERROR_RETURN ((LM_ERROR,
66 "(%N:%l) Demux_Test_Client::init - "
67 "parse_args failed\n"),
68 -1);
70 if (this->init_operation_db () == -1)
71 ACE_ERROR_RETURN ((LM_ERROR,
72 "(%N:%l) Demux_Test_Client::init - "
73 "init_operation_db failed\n"),
74 -1);
76 // now read all the IORS
77 CORBA::ULong i, j;
79 for (i = 0; i < this->num_POAs_; ++i)
80 for (j = 0; j < this->num_objs_; ++j)
82 char str [1024 * 10];
83 ACE_OS::memset (str, 0, sizeof (str));
85 if (fscanf (this->ior_fp_, "%s", str) == EOF)
87 ACE_ERROR_RETURN ((LM_ERROR,
88 "IOR database has less entries than required\n"),
89 -1);
92 // Get the IOR and output it to the file
93 try
95 CORBA::Object_var objref = this->orb_->string_to_object (str);
97 // now narrow to Demux_Test object
99 this->demux_test_[i * j] = Demux_Test::_narrow (objref.in ());
102 if (CORBA::is_nil (this->demux_test_[i * j].in ()))
104 ACE_ERROR_RETURN ((LM_ERROR,
105 "ObjRef for IOR %s (POA %d, OBJ %d) is NULL\n",
106 str, i, j),
107 -1);
110 catch (const CORBA::Exception& ex)
112 ex._tao_print_exception ("object_to_string");
113 throw;
115 } // j and i loop
117 ACE_OS::fclose (this->ior_fp_);
119 // success
120 return 0;
123 // parse command line arguments (if any).
125 Demux_Test_Client::parse_args ()
127 ACE_Get_Opt get_opts (this->argc_, this->argv_, ACE_TEXT("df:m:n:o:p:i:s:"));
128 int c;
130 while ((c = get_opts ()) != -1)
131 switch (c)
133 case 'd': // debug flag
134 TAO_debug_level++;
135 break;
136 case 'f':
137 this->ior_fp_ = ACE_OS::fopen (get_opts.opt_arg (), "w");
138 if (this->ior_fp_ == 0)
139 ACE_ERROR_RETURN ((LM_ERROR,
140 "Unable to open %s for writing: %p\n",
141 get_opts.opt_arg ()), -1);
142 break;
143 case 'm':
144 this->num_ops_ = ACE_OS::atoi (get_opts.opt_arg ());
145 if (this->num_ops_ > TAO_DEMUX_TEST_MAX_OPS)
147 ACE_ERROR_RETURN ((LM_ERROR,
148 "%d exceeds the maximum of "
149 "%d objects per POA\n",
150 this->num_objs_,
151 TAO_DEMUX_TEST_MAX_OPS),
152 -1);
154 break;
155 case 'n':
156 this->loop_count_ = ACE_OS::atoi (get_opts.opt_arg ());
157 break;
158 case 'o':
159 this->num_objs_ = ACE_OS::atoi (get_opts.opt_arg ());
160 if (this->num_objs_ > TAO_DEMUX_TEST_MAX_OBJS)
162 ACE_ERROR_RETURN ((LM_ERROR,
163 "%d exceeds the maximum of "
164 "%d objects per POA\n",
165 this->num_objs_,
166 TAO_DEMUX_TEST_MAX_OBJS),
167 -1);
169 break;
170 case 'p':
171 this->num_POAs_ = ACE_OS::atoi (get_opts.opt_arg ());
172 if (this->num_POAs_ > TAO_DEMUX_TEST_MAX_POAS)
174 ACE_ERROR_RETURN ((LM_ERROR,
175 "%d exceeds the maximum of "
176 "%d POAs\n",
177 this->num_objs_,
178 TAO_DEMUX_TEST_MAX_POAS),
179 -1);
181 break;
182 case 'i':
183 switch (*get_opts.opt_arg ())
185 case 'L':
186 this->is_ = Demux_Test_Client::LINEAR;
187 break;
188 case 'R':
189 this->is_ = Demux_Test_Client::RANDOM;
190 break;
191 case 'B':
192 this->is_ = Demux_Test_Client::BEST;
193 break;
194 case 'W':
195 this->is_ = Demux_Test_Client::WORST;
196 break;
198 break;
199 case 's':
200 this->step_ = ACE_OS::atoi (get_opts.opt_arg ());
201 if (this->step_ > this->num_objs_)
202 ACE_ERROR_RETURN ((LM_ERROR,
203 "%d exceeds the no. of Objs specified"),
204 this->step_);
205 break;
206 case '?':
207 default:
208 ACE_ERROR_RETURN ((LM_ERROR,
209 "usage: %s"
210 " [-d]"
211 " [-m <num ops>]"
212 " [-o <num objs>]"
213 " [-p <num POAs]"
214 " [-i <invoke strategy>"
215 " [-f <IOR file>]"
216 " [-n <loop count>]"
217 "\n"
218 "Invocation Strategy: L(linear), R(random)"
219 "B(best), W(worst)\n",
220 this->argv_ [0]),
221 -1);
224 if (!this->ior_fp_)
226 // open default IOR file
227 this->ior_fp_ = ACE_OS::fopen ("ior.dat", "r");
228 if (this->ior_fp_ == 0)
229 ACE_ERROR_RETURN ((LM_ERROR,
230 "Unable to open file ior.dat for reading\n"), -1);
232 return 0;
235 // The main program for Demux_Test
237 Demux_Test_Client::run ()
239 // open a temporary results file
240 if ((this->result_fp_ = ACE_OS::fopen ("results.dat", "w")) == 0)
242 ACE_ERROR_RETURN ((LM_ERROR,
243 "Demux_Test_Client::run - "
244 "Failed to open the results file for writing\n"),
245 -1);
249 switch (this->is_)
251 case Demux_Test_Client::LINEAR:
252 (void) this->run_linear_test ();
253 break;
254 case Demux_Test_Client::RANDOM:
255 (void) this->run_random_test ();
256 break;
257 case Demux_Test_Client::BEST:
258 (void) this->run_best_test ();
259 break;
260 case Demux_Test_Client::WORST:
261 (void) this->run_worst_test ();
262 break;
265 catch (const CORBA::Exception& ex)
267 ex._tao_print_exception ("run failed");
268 ACE_ERROR ((LM_ERROR,
269 "(%N:%l) Demux_Test_Client::run - "
270 "Error running the Client\n"));
271 throw;
274 ACE_OS::fclose (this->result_fp_);
275 this->result_fp_ = 0;
279 // call the shutdown method one the first object
280 this->demux_test_[0]->shutdown ();
282 catch (const CORBA::Exception& ex)
284 ex._tao_print_exception ("shutdown failed");
285 ACE_ERROR ((LM_ERROR,
286 "(%N:%l) Demux_Test_Client::run - "
287 "Error running the Client\n"));
288 throw;
291 // now print the results
292 if (this->print_results () == -1)
294 ACE_ERROR_RETURN ((LM_ERROR,
295 "Demux_Test_Client::run - "
296 "Print results failed\n"),
297 -1);
300 return 0;
304 Demux_Test_Client::run_linear_test ()
306 CORBA::ULong j, k, l, m;
307 ACE_hrtime_t start, end;
309 m = 0;
310 for (j = 0; j < this->num_POAs_; ++j)
311 for (k = 0; k < this->num_objs_; k+=this->step_)
312 for (l = 0; l < this->num_ops_; ++l)
314 start = ACE_OS::gethrtime ();
316 // invoke the method
317 this->op_db_[l].op_ (this->demux_test_[j * k].in ());
319 end = ACE_OS::gethrtime ();
321 m++;
322 ACE_OS::fprintf (this->result_fp_, "%d %f\n", m,
323 1.0 * ACE_UINT64_DBLCAST_ADAPTER (end - start));
326 return 0;
330 Demux_Test_Client::run_random_test ()
332 ACE_DEBUG ((LM_DEBUG,
333 "ERROR : Random test\n"));
334 return 0;
338 Demux_Test_Client::run_best_test ()
340 ACE_DEBUG ((LM_DEBUG,
341 "ERROR : Best Test\n"));
342 return 0;
346 Demux_Test_Client::run_worst_test ()
348 ACE_DEBUG ((LM_DEBUG,
349 "ERROR : Worst test\n"));
350 return 0;
354 Demux_Test_Client::print_results ()
356 ACE_DEBUG ((LM_DEBUG,
357 "******** "));
358 switch (this->is_)
360 case Demux_Test_Client::LINEAR:
361 ACE_DEBUG ((LM_DEBUG,
362 "Linear Strategy ******\n"));
363 break;
364 case Demux_Test_Client::RANDOM:
365 ACE_DEBUG ((LM_DEBUG,
366 "Random Strategy ******\n"));
367 break;
368 case Demux_Test_Client::BEST:
369 ACE_DEBUG ((LM_DEBUG,
370 "Best Strategy ******\n"));
371 break;
372 case Demux_Test_Client::WORST:
373 ACE_DEBUG ((LM_DEBUG,
374 "Worst Strategy ******\n"));
375 break;
378 return 0;
381 // include the generated code
382 #include "demux_test_client.inl"