Changes to attempt to silence bcc64x
[ACE_TAO.git] / TAO / orbsvcs / tests / Notify / Basic / IdAssignment.cpp
blobf4185a34d3af9966dc656f00c11a76d8c3250329
1 #include "ace/Arg_Shifter.h"
2 #include "ace/Get_Opt.h"
3 #include "tao/debug.h"
4 #include "orbsvcs/CosNamingC.h"
5 #include "orbsvcs/CosNotifyCommC.h"
6 #include "IdAssignment.h"
8 IdAssignment::IdAssignment ()
9 : iter_ (3),
10 ec_count_ (3),
11 consumer_admin_count_ (3),
12 supplier_admin_count_ (3)
16 IdAssignment::~IdAssignment ()
20 int
21 IdAssignment::parse_args (int argc,
22 ACE_TCHAR *argv[])
24 ACE_Arg_Shifter arg_shifter (argc, argv);
26 const ACE_TCHAR *current_arg = 0;
28 while (arg_shifter.is_anything_left ())
30 if (0 != (current_arg = arg_shifter.get_the_parameter (ACE_TEXT ("-iter"))))
32 this->iter_ = ACE_OS::atoi (current_arg);
33 // The number of times to repeat the test.
34 arg_shifter.consume_arg ();
36 if (0 != (current_arg = arg_shifter.get_the_parameter (ACE_TEXT ("-ec_count"))))
38 this->ec_count_ = ACE_OS::atoi (current_arg);
39 arg_shifter.consume_arg ();
41 if (0 != (current_arg = arg_shifter.get_the_parameter (ACE_TEXT ("-ca_count"))))
43 this->consumer_admin_count_ = ACE_OS::atoi (current_arg);
44 arg_shifter.consume_arg ();
46 if (0 != (current_arg = arg_shifter.get_the_parameter (ACE_TEXT ("-sa_count"))))
48 this->supplier_admin_count_ = ACE_OS::atoi (current_arg);
49 arg_shifter.consume_arg ();
51 else if (arg_shifter.cur_arg_strncasecmp (ACE_TEXT ("-?")) == 0)
53 ACE_DEBUG((LM_DEBUG,
54 "usage: %s "
55 "-iter <count>",
56 "-ec_count <count>",
57 "-ca_count <count>",
58 "-sa_count <count>\n",
59 argv[0]));
61 arg_shifter.consume_arg ();
63 return -1;
65 else
67 arg_shifter.ignore_arg ();
71 return 0;
74 void
75 IdAssignment::init (int argc,
76 ACE_TCHAR *argv[])
78 CORBA::ORB_var orb = CORBA::ORB_init (argc,
79 argv);
81 CORBA::Object_var rootObj =
82 orb->resolve_initial_references ("NameService");
84 if (CORBA::is_nil (rootObj.in ()))
86 ACE_ERROR ((LM_ERROR,
87 " (%P|%t) Unable to resolve naming service !\n"));
88 return;
90 CosNaming::NamingContext_var rootNC =
91 CosNaming::NamingContext::_narrow (rootObj.in ());
93 CosNaming::Name name (1);
94 name.length (1);
95 name[0].id = CORBA::string_dup ("NotifyEventChannelFactory");
97 CORBA::Object_var obj = rootNC->resolve (name);
99 if (CORBA::is_nil (obj.in ()))
101 ACE_ERROR ((LM_ERROR,
102 " (%P|%t) Unable to locate Notify_Service\n"));
103 return;
106 this->notify_factory_ =
107 CosNotifyChannelAdmin::EventChannelFactory::_narrow (obj.in());
110 CosNotifyChannelAdmin::ChannelID
111 IdAssignment::create_ec ()
113 CosNotifyChannelAdmin::ChannelID id;
114 CosNotification::QoSProperties initial_qos;
115 CosNotification::AdminProperties initial_admin;
116 CosNotifyChannelAdmin::EventChannel_var ec =
117 this->notify_factory_->create_channel (initial_qos,
118 initial_admin,
119 id);
121 return id;
125 void
126 IdAssignment::destroy_ec(CosNotifyChannelAdmin::ChannelID id)
128 CosNotifyChannelAdmin::EventChannel_var ec =
129 this->notify_factory_->get_event_channel (id);
132 if (CORBA::is_nil (ec.in()))
134 ACE_ERROR((LM_ERROR,
135 " (%P|%t) Unable to find event channel\n"));
136 return;
139 ec->destroy ();
142 CosNotifyChannelAdmin::AdminID
143 IdAssignment::create_supplier_admin (CosNotifyChannelAdmin::ChannelID channel_id)
145 CosNotifyChannelAdmin::AdminID adminid;
146 CosNotifyChannelAdmin::InterFilterGroupOperator ifgop =
147 CosNotifyChannelAdmin::OR_OP;
149 CosNotifyChannelAdmin::EventChannel_var ec =
150 this->notify_factory_->get_event_channel (channel_id);
153 if (CORBA::is_nil (ec.in ()))
155 ACE_ERROR((LM_ERROR,
156 " (%P|%t) Unable to find event channel\n"));
157 return 0;
160 CosNotifyChannelAdmin::SupplierAdmin_var supplier_admin =
161 ec->new_for_suppliers (ifgop,
162 adminid);
164 if (CORBA::is_nil (supplier_admin.in ()))
165 ACE_ERROR_RETURN ((LM_ERROR,
166 " (%P|%t) Unable to create supplier admin\n"),0);
168 if (TAO_debug_level)
169 ACE_DEBUG ((LM_DEBUG,
170 "created supplier admin\n"));
172 return adminid;
175 CosNotifyChannelAdmin::AdminID
176 IdAssignment::create_consumer_admin (CosNotifyChannelAdmin::ChannelID channel_id)
178 CosNotifyChannelAdmin::AdminID adminid;
179 CosNotifyChannelAdmin::InterFilterGroupOperator ifgop =
180 CosNotifyChannelAdmin::OR_OP;
182 CosNotifyChannelAdmin::EventChannel_var ec =
183 this->notify_factory_->get_event_channel (channel_id);
185 if (CORBA::is_nil (ec.in ()))
187 ACE_ERROR((LM_ERROR,
188 " (%P|%t) Unable to find event channel\n"));
189 return 0;
192 CosNotifyChannelAdmin::ConsumerAdmin_var consumer_admin =
193 ec->new_for_consumers (ifgop,
194 adminid);
196 if (CORBA::is_nil (consumer_admin.in ()))
197 ACE_ERROR_RETURN ((LM_ERROR,
198 " (%P|%t) Unable to create consumer admin\n"),0);
200 if (TAO_debug_level)
201 ACE_DEBUG ((LM_DEBUG,
202 "created consumer admin\n"));
204 return adminid;
208 bool
209 IdAssignment::default_consumer_admin_test (CosNotifyChannelAdmin::ChannelID channel_id)
211 CosNotifyChannelAdmin::EventChannel_var ec =
212 this->notify_factory_->get_event_channel (channel_id);
214 if (CORBA::is_nil (ec.in ()))
216 ACE_ERROR((LM_ERROR,
217 " (%P|%t) Unable to find event channel\n"));
218 return false;
221 CosNotifyChannelAdmin::ConsumerAdmin_var default_consumer_admin =
222 ec->get_consumeradmin (0);
224 if (CORBA::is_nil (default_consumer_admin.in()))
226 ACE_ERROR_RETURN ((LM_ERROR,
227 " (%P|%t) Unable to create default consumer admin\n"),
228 false);
231 CosNotifyChannelAdmin::ConsumerAdmin_var def = ec->default_consumer_admin ();
232 if (CORBA::is_nil (default_consumer_admin.in()))
234 ACE_ERROR_RETURN ((LM_ERROR,
235 " (%P|%t) Unable to get default consumer admin\n"),
236 false);
239 if (! default_consumer_admin->_is_equivalent(def.in ()))
241 ACE_ERROR_RETURN ((LM_ERROR,
242 " (%P|%t) failed for default consumer admin checking\n"),
243 false);
246 if (TAO_debug_level)
247 ACE_DEBUG ((LM_DEBUG,
248 "passed default consumer admin test.\n"));
250 return true;
254 bool
255 IdAssignment::default_supplier_admin_test (CosNotifyChannelAdmin::ChannelID channel_id)
257 CosNotifyChannelAdmin::EventChannel_var ec =
258 this->notify_factory_->get_event_channel (channel_id);
260 if (CORBA::is_nil (ec.in ()))
262 ACE_ERROR((LM_ERROR,
263 " (%P|%t) Unable to find event channel\n"));
264 return false;
267 CosNotifyChannelAdmin::SupplierAdmin_var default_supplier_admin =
268 ec->get_supplieradmin (0);
270 if (CORBA::is_nil (default_supplier_admin.in()))
272 ACE_ERROR_RETURN ((LM_ERROR,
273 " (%P|%t) Unable to create default supplier admin\n"),
274 false);
277 CosNotifyChannelAdmin::SupplierAdmin_var def = ec->default_supplier_admin ();
278 if (CORBA::is_nil (default_supplier_admin.in()))
280 ACE_ERROR_RETURN ((LM_ERROR,
281 " (%P|%t) Unable to get default supplier admin\n"),
282 false);
285 if (! default_supplier_admin->_is_equivalent(def.in ()))
287 ACE_ERROR_RETURN ((LM_ERROR,
288 " (%P|%t) failed for default supplier admin checking\n"),
289 false);
292 if (TAO_debug_level)
293 ACE_DEBUG ((LM_DEBUG,
294 "passed default supplier admin test.\n"));
296 return true;
300 void
301 IdAssignment::destroy_consumer_admin (
302 CosNotifyChannelAdmin::ChannelID channel_id,
303 CosNotifyChannelAdmin::AdminID admin_id
306 CosNotifyChannelAdmin::EventChannel_var ec =
307 this->notify_factory_->get_event_channel (channel_id);
310 if (CORBA::is_nil (ec.in ()))
312 ACE_ERROR((LM_ERROR,
313 " (%P|%t) Unable to find event channel\n"));
314 return;
317 CosNotifyChannelAdmin::ConsumerAdmin_var consumer_admin =
318 ec->get_consumeradmin (admin_id);
320 if (CORBA::is_nil (consumer_admin.in()))
322 ACE_ERROR ((LM_ERROR,
323 " (%P|%t) Unable to get consumer admin\n"));
326 consumer_admin->destroy ();
328 if (TAO_debug_level)
329 ACE_DEBUG ((LM_DEBUG,
330 "destroyed consumer admin\n"));
334 void
335 IdAssignment::destroy_supplier_admin (
336 CosNotifyChannelAdmin::ChannelID channel_id,
337 CosNotifyChannelAdmin::AdminID admin_id
340 CosNotifyChannelAdmin::EventChannel_var ec =
341 this->notify_factory_->get_event_channel (channel_id);
344 if (CORBA::is_nil (ec.in ()))
346 ACE_ERROR ((LM_ERROR,
347 " (%P|%t) Unable to find event channel\n"));
350 CosNotifyChannelAdmin::SupplierAdmin_var supplier_admin =
351 ec->get_supplieradmin (admin_id);
353 if (CORBA::is_nil (supplier_admin.in ()))
354 ACE_ERROR ((LM_ERROR,
355 " (%P|%t) Unable to get supplier admin\n"));
357 supplier_admin->destroy ();
359 if (TAO_debug_level)
360 ACE_DEBUG ((LM_DEBUG,
361 "destroyed supplier admin\n"));
364 void
365 IdAssignment::run_test()
367 CosNotifyChannelAdmin::ChannelID* ec_id = 0;
368 ACE_NEW (ec_id,
369 CosNotifyChannelAdmin::ChannelID [this->ec_count_]);
371 CosNotifyChannelAdmin::AdminID* consumer_admin_id = 0;
372 ACE_NEW (consumer_admin_id,
373 CosNotifyChannelAdmin::AdminID [this->consumer_admin_count_]);
375 CosNotifyChannelAdmin::AdminID* supplier_admin_id = 0;
376 ACE_NEW (supplier_admin_id,
377 CosNotifyChannelAdmin::AdminID [this->supplier_admin_count_]);
379 // *******************************************************************
381 int i;
383 for (i = 0; i < this->iter_; ++i)
385 int ec_count;
387 for (ec_count = 0; ec_count < this->ec_count_; ++ec_count)
389 ec_id[ec_count] = this->create_ec ();
391 // Connect <consumer_admin_count_> number of consumers
392 // to the current ec.
393 for (int cons_count = 0;
394 cons_count < this->consumer_admin_count_;
395 ++cons_count)
397 consumer_admin_id [cons_count] =
398 this->create_consumer_admin (ec_id [ec_count]);
401 if (this->default_consumer_admin_test (ec_id[ec_count]) == false)
402 ACE_OS::exit (1);
404 // Connect <supplier_admin_count_> number of suppliers
405 // to the current ec.
406 for (int supp_count = 0;
407 supp_count < this->supplier_admin_count_;
408 ++supp_count)
410 supplier_admin_id [supp_count] =
411 this->create_supplier_admin (ec_id [ec_count]);
414 if (this->default_supplier_admin_test (ec_id[ec_count]) == false)
415 ACE_OS::exit (1);
418 // Destroy the ec, the admins should destroy too.
419 for (ec_count = 0; ec_count < this->ec_count_; ++ec_count)
421 this->destroy_ec (ec_id[ec_count]);
424 } // for
427 //******************************************************************************
428 // Repeat, but this time destroy the admins explicity.
429 for (i = 0; i < this->iter_; ++i)
431 int ec_count;
433 for (ec_count = 0; ec_count < this->ec_count_; ++ec_count)
435 ec_id[ec_count] = this->create_ec ();
437 int cons_count, supp_count;
438 // Connect <consumer_admin_count_> number of consumers
439 // to the current ec.
440 for (cons_count = 0;
441 cons_count < this->consumer_admin_count_;
442 ++cons_count)
444 consumer_admin_id[cons_count] =
445 this->create_consumer_admin (ec_id[ec_count]);
448 // Connect <supplier_admin_count_> number of suppliers
449 // to the current ec.
450 for (supp_count = 0; supp_count < this->supplier_admin_count_; ++supp_count)
452 supplier_admin_id[supp_count] =
453 this->create_supplier_admin (ec_id[ec_count]);
456 // Destroy the admins.
458 // Destroy consumer admins.
459 for (cons_count = 0;
460 cons_count < this->consumer_admin_count_;
461 ++cons_count)
463 this->destroy_consumer_admin (ec_id[ec_count],
464 consumer_admin_id[cons_count]);
467 // Destroy supplier admins
468 for (supp_count = 0;
469 supp_count < this->supplier_admin_count_;
470 ++supp_count)
472 this->destroy_supplier_admin (ec_id[ec_count],
473 supplier_admin_id[supp_count]);
478 // Destroy the ec,
479 for (ec_count = 0; ec_count < this->ec_count_; ++ec_count)
481 this->destroy_ec (ec_id[ec_count]);
484 } // for
486 //********************************************************************************
489 int ACE_TMAIN (int argc, ACE_TCHAR *argv[])
493 IdAssignment test;
495 test.parse_args (argc,
496 argv);
498 test.init (argc,
499 argv);
501 test.run_test ();
503 catch (const CORBA::Exception& ex)
505 ex._tao_print_exception ("Error: ");
506 return 1;
509 ACE_DEBUG ((LM_DEBUG,
510 "IdAssignment test suceeded\n"));
511 return 0;