1 //=============================================================================
3 * @file demux_test_client.cpp
5 * @author Aniruddha Gokhale
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"
17 Demux_Test_Client::Demux_Test_Client ()
20 is_ (Demux_Test_Client::LINEAR
),
22 // default number of child POAs is 1 and each one will always have 1 object
25 demux_test_ (TAO_DEMUX_TEST_MAX_POAS
* TAO_DEMUX_TEST_MAX_OBJS
),
34 Demux_Test_Client::~Demux_Test_Client ()
39 // initialize the Demux_Test_Client
43 Demux_Test_Client::init (int argc
, ACE_TCHAR
*argv
[])
51 // get the underlying ORB
53 CORBA::ORB_init (argc
, argv
);
55 catch (const CORBA::Exception
& ex
)
57 ex
._tao_print_exception ("ORB_init");
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"),
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"),
76 // now read all the IORS
79 for (i
= 0; i
< this->num_POAs_
; ++i
)
80 for (j
= 0; j
< this->num_objs_
; ++j
)
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"),
92 // Get the IOR and output it to the file
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",
110 catch (const CORBA::Exception
& ex
)
112 ex
._tao_print_exception ("object_to_string");
117 ACE_OS::fclose (this->ior_fp_
);
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:"));
130 while ((c
= get_opts ()) != -1)
133 case 'd': // debug flag
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);
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",
151 TAO_DEMUX_TEST_MAX_OPS
),
156 this->loop_count_
= ACE_OS::atoi (get_opts
.opt_arg ());
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",
166 TAO_DEMUX_TEST_MAX_OBJS
),
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 "
178 TAO_DEMUX_TEST_MAX_POAS
),
183 switch (*get_opts
.opt_arg ())
186 this->is_
= Demux_Test_Client::LINEAR
;
189 this->is_
= Demux_Test_Client::RANDOM
;
192 this->is_
= Demux_Test_Client::BEST
;
195 this->is_
= Demux_Test_Client::WORST
;
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"),
208 ACE_ERROR_RETURN ((LM_ERROR
,
214 " [-i <invoke strategy>"
218 "Invocation Strategy: L(linear), R(random)"
219 "B(best), W(worst)\n",
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);
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"),
251 case Demux_Test_Client::LINEAR
:
252 (void) this->run_linear_test ();
254 case Demux_Test_Client::RANDOM
:
255 (void) this->run_random_test ();
257 case Demux_Test_Client::BEST
:
258 (void) this->run_best_test ();
260 case Demux_Test_Client::WORST
:
261 (void) this->run_worst_test ();
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"));
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"));
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"),
304 Demux_Test_Client::run_linear_test ()
306 CORBA::ULong j
, k
, l
, m
;
307 ACE_hrtime_t start
, end
;
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 ();
317 this->op_db_
[l
].op_ (this->demux_test_
[j
* k
].in ());
319 end
= ACE_OS::gethrtime ();
322 ACE_OS::fprintf (this->result_fp_
, "%d %f\n", m
,
323 1.0 * ACE_UINT64_DBLCAST_ADAPTER (end
- start
));
330 Demux_Test_Client::run_random_test ()
332 ACE_DEBUG ((LM_DEBUG
,
333 "ERROR : Random test\n"));
338 Demux_Test_Client::run_best_test ()
340 ACE_DEBUG ((LM_DEBUG
,
341 "ERROR : Best Test\n"));
346 Demux_Test_Client::run_worst_test ()
348 ACE_DEBUG ((LM_DEBUG
,
349 "ERROR : Worst test\n"));
354 Demux_Test_Client::print_results ()
356 ACE_DEBUG ((LM_DEBUG
,
360 case Demux_Test_Client::LINEAR
:
361 ACE_DEBUG ((LM_DEBUG
,
362 "Linear Strategy ******\n"));
364 case Demux_Test_Client::RANDOM
:
365 ACE_DEBUG ((LM_DEBUG
,
366 "Random Strategy ******\n"));
368 case Demux_Test_Client::BEST
:
369 ACE_DEBUG ((LM_DEBUG
,
370 "Best Strategy ******\n"));
372 case Demux_Test_Client::WORST
:
373 ACE_DEBUG ((LM_DEBUG
,
374 "Worst Strategy ******\n"));
381 // include the generated code
382 #include "demux_test_client.inl"