Merge pull request #1551 from DOCGroup/plm_jira_333
[ACE_TAO.git] / TAO / orbsvcs / tests / Notify / Basic / IdAssignment.cpp
blob26893522ce802ed91cb2aeb2452c3d5749729e42
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 (void)
9 : iter_ (3),
10 ec_count_ (3),
11 consumer_admin_count_ (3),
12 supplier_admin_count_ (3)
16 IdAssignment::~IdAssignment (void)
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;
91 CosNaming::NamingContext_var rootNC =
92 CosNaming::NamingContext::_narrow (rootObj.in ());
94 CosNaming::Name name (1);
95 name.length (1);
96 name[0].id = CORBA::string_dup ("NotifyEventChannelFactory");
98 CORBA::Object_var obj = rootNC->resolve (name);
100 if (CORBA::is_nil (obj.in ()))
102 ACE_ERROR ((LM_ERROR,
103 " (%P|%t) Unable to locate Notify_Service\n"));
104 return;
107 this->notify_factory_ =
108 CosNotifyChannelAdmin::EventChannelFactory::_narrow (
109 obj.in()
114 CosNotifyChannelAdmin::ChannelID
115 IdAssignment::create_ec (void)
117 CosNotifyChannelAdmin::ChannelID id;
118 CosNotification::QoSProperties initial_qos;
119 CosNotification::AdminProperties initial_admin;
120 CosNotifyChannelAdmin::EventChannel_var ec =
121 this->notify_factory_->create_channel (initial_qos,
122 initial_admin,
123 id);
125 return id;
129 void
130 IdAssignment::destroy_ec(CosNotifyChannelAdmin::ChannelID id)
132 CosNotifyChannelAdmin::EventChannel_var ec =
133 this->notify_factory_->get_event_channel (id);
136 if (CORBA::is_nil (ec.in()))
138 ACE_ERROR((LM_ERROR,
139 " (%P|%t) Unable to find event channel\n"));
140 return;
143 ec->destroy ();
146 CosNotifyChannelAdmin::AdminID
147 IdAssignment::create_supplier_admin (CosNotifyChannelAdmin::ChannelID channel_id)
149 CosNotifyChannelAdmin::AdminID adminid;
150 CosNotifyChannelAdmin::InterFilterGroupOperator ifgop =
151 CosNotifyChannelAdmin::OR_OP;
153 CosNotifyChannelAdmin::EventChannel_var ec =
154 this->notify_factory_->get_event_channel (channel_id);
157 if (CORBA::is_nil (ec.in ()))
159 ACE_ERROR((LM_ERROR,
160 " (%P|%t) Unable to find event channel\n"));
161 return 0;
164 CosNotifyChannelAdmin::SupplierAdmin_var supplier_admin =
165 ec->new_for_suppliers (ifgop,
166 adminid);
168 if (CORBA::is_nil (supplier_admin.in ()))
169 ACE_ERROR_RETURN ((LM_ERROR,
170 " (%P|%t) Unable to create supplier admin\n"),0);
172 if (TAO_debug_level)
173 ACE_DEBUG ((LM_DEBUG,
174 "created supplier admin\n"));
176 return adminid;
179 CosNotifyChannelAdmin::AdminID
180 IdAssignment::create_consumer_admin (CosNotifyChannelAdmin::ChannelID channel_id)
182 CosNotifyChannelAdmin::AdminID adminid;
183 CosNotifyChannelAdmin::InterFilterGroupOperator ifgop =
184 CosNotifyChannelAdmin::OR_OP;
186 CosNotifyChannelAdmin::EventChannel_var ec =
187 this->notify_factory_->get_event_channel (channel_id);
189 if (CORBA::is_nil (ec.in ()))
191 ACE_ERROR((LM_ERROR,
192 " (%P|%t) Unable to find event channel\n"));
193 return 0;
196 CosNotifyChannelAdmin::ConsumerAdmin_var consumer_admin =
197 ec->new_for_consumers (ifgop,
198 adminid);
200 if (CORBA::is_nil (consumer_admin.in ()))
201 ACE_ERROR_RETURN ((LM_ERROR,
202 " (%P|%t) Unable to create consumer admin\n"),0);
204 if (TAO_debug_level)
205 ACE_DEBUG ((LM_DEBUG,
206 "created consumer admin\n"));
208 return adminid;
212 bool
213 IdAssignment::default_consumer_admin_test (CosNotifyChannelAdmin::ChannelID channel_id)
215 CosNotifyChannelAdmin::EventChannel_var ec =
216 this->notify_factory_->get_event_channel (channel_id);
218 if (CORBA::is_nil (ec.in ()))
220 ACE_ERROR((LM_ERROR,
221 " (%P|%t) Unable to find event channel\n"));
222 return false;
225 CosNotifyChannelAdmin::ConsumerAdmin_var default_consumer_admin =
226 ec->get_consumeradmin (0);
228 if (CORBA::is_nil (default_consumer_admin.in()))
230 ACE_ERROR_RETURN ((LM_ERROR,
231 " (%P|%t) Unable to create default consumer admin\n"),
232 false);
235 CosNotifyChannelAdmin::ConsumerAdmin_var def = ec->default_consumer_admin ();
236 if (CORBA::is_nil (default_consumer_admin.in()))
238 ACE_ERROR_RETURN ((LM_ERROR,
239 " (%P|%t) Unable to get default consumer admin\n"),
240 false);
243 if (! default_consumer_admin->_is_equivalent(def.in ()))
245 ACE_ERROR_RETURN ((LM_ERROR,
246 " (%P|%t) failed for default consumer admin checking\n"),
247 false);
250 if (TAO_debug_level)
251 ACE_DEBUG ((LM_DEBUG,
252 "passed default consumer admin test.\n"));
254 return true;
258 bool
259 IdAssignment::default_supplier_admin_test (CosNotifyChannelAdmin::ChannelID channel_id)
261 CosNotifyChannelAdmin::EventChannel_var ec =
262 this->notify_factory_->get_event_channel (channel_id);
264 if (CORBA::is_nil (ec.in ()))
266 ACE_ERROR((LM_ERROR,
267 " (%P|%t) Unable to find event channel\n"));
268 return false;
271 CosNotifyChannelAdmin::SupplierAdmin_var default_supplier_admin =
272 ec->get_supplieradmin (0);
274 if (CORBA::is_nil (default_supplier_admin.in()))
276 ACE_ERROR_RETURN ((LM_ERROR,
277 " (%P|%t) Unable to create default supplier admin\n"),
278 false);
281 CosNotifyChannelAdmin::SupplierAdmin_var def = ec->default_supplier_admin ();
282 if (CORBA::is_nil (default_supplier_admin.in()))
284 ACE_ERROR_RETURN ((LM_ERROR,
285 " (%P|%t) Unable to get default supplier admin\n"),
286 false);
289 if (! default_supplier_admin->_is_equivalent(def.in ()))
291 ACE_ERROR_RETURN ((LM_ERROR,
292 " (%P|%t) failed for default supplier admin checking\n"),
293 false);
296 if (TAO_debug_level)
297 ACE_DEBUG ((LM_DEBUG,
298 "passed default supplier admin test.\n"));
300 return true;
304 void
305 IdAssignment::destroy_consumer_admin (
306 CosNotifyChannelAdmin::ChannelID channel_id,
307 CosNotifyChannelAdmin::AdminID admin_id
310 CosNotifyChannelAdmin::EventChannel_var ec =
311 this->notify_factory_->get_event_channel (channel_id);
314 if (CORBA::is_nil (ec.in ()))
316 ACE_ERROR((LM_ERROR,
317 " (%P|%t) Unable to find event channel\n"));
318 return;
321 CosNotifyChannelAdmin::ConsumerAdmin_var consumer_admin =
322 ec->get_consumeradmin (admin_id);
324 if (CORBA::is_nil (consumer_admin.in()))
326 ACE_ERROR ((LM_ERROR,
327 " (%P|%t) Unable to get consumer admin\n"));
330 consumer_admin->destroy ();
332 if (TAO_debug_level)
333 ACE_DEBUG ((LM_DEBUG,
334 "destroyed consumer admin\n"));
338 void
339 IdAssignment::destroy_supplier_admin (
340 CosNotifyChannelAdmin::ChannelID channel_id,
341 CosNotifyChannelAdmin::AdminID admin_id
344 CosNotifyChannelAdmin::EventChannel_var ec =
345 this->notify_factory_->get_event_channel (channel_id);
348 if (CORBA::is_nil (ec.in ()))
350 ACE_ERROR ((LM_ERROR,
351 " (%P|%t) Unable to find event channel\n"));
354 CosNotifyChannelAdmin::SupplierAdmin_var supplier_admin =
355 ec->get_supplieradmin (admin_id);
357 if (CORBA::is_nil (supplier_admin.in ()))
358 ACE_ERROR ((LM_ERROR,
359 " (%P|%t) Unable to get supplier admin\n"));
361 supplier_admin->destroy ();
363 if (TAO_debug_level)
364 ACE_DEBUG ((LM_DEBUG,
365 "destroyed supplier admin\n"));
368 void
369 IdAssignment::run_test(void)
371 CosNotifyChannelAdmin::ChannelID* ec_id = 0;
372 ACE_NEW (ec_id,
373 CosNotifyChannelAdmin::ChannelID [this->ec_count_]);
375 CosNotifyChannelAdmin::AdminID* consumer_admin_id = 0;
376 ACE_NEW (consumer_admin_id,
377 CosNotifyChannelAdmin::AdminID [this->consumer_admin_count_]);
379 CosNotifyChannelAdmin::AdminID* supplier_admin_id = 0;
380 ACE_NEW (supplier_admin_id,
381 CosNotifyChannelAdmin::AdminID [this->supplier_admin_count_]);
383 // *******************************************************************
385 int i;
387 for (i = 0; i < this->iter_; ++i)
389 int ec_count;
391 for (ec_count = 0; ec_count < this->ec_count_; ++ec_count)
393 ec_id[ec_count] = this->create_ec ();
395 // Connect <consumer_admin_count_> number of consumers
396 // to the current ec.
397 for (int cons_count = 0;
398 cons_count < this->consumer_admin_count_;
399 ++cons_count)
401 consumer_admin_id [cons_count] =
402 this->create_consumer_admin (ec_id [ec_count]);
405 if (this->default_consumer_admin_test (ec_id[ec_count]) == false)
406 ACE_OS::exit (1);
408 // Connect <supplier_admin_count_> number of suppliers
409 // to the current ec.
410 for (int supp_count = 0;
411 supp_count < this->supplier_admin_count_;
412 ++supp_count)
414 supplier_admin_id [supp_count] =
415 this->create_supplier_admin (ec_id [ec_count]);
418 if (this->default_supplier_admin_test (ec_id[ec_count]) == false)
419 ACE_OS::exit (1);
422 // Destroy the ec, the admins should destroy too.
423 for (ec_count = 0; ec_count < this->ec_count_; ++ec_count)
425 this->destroy_ec (ec_id[ec_count]);
428 } // for
431 //******************************************************************************
432 // Repeat, but this time destroy the admins explicity.
433 for (i = 0; i < this->iter_; ++i)
435 int ec_count;
437 for (ec_count = 0; ec_count < this->ec_count_; ++ec_count)
439 ec_id[ec_count] = this->create_ec ();
441 int cons_count, supp_count;
442 // Connect <consumer_admin_count_> number of consumers
443 // to the current ec.
444 for (cons_count = 0;
445 cons_count < this->consumer_admin_count_;
446 ++cons_count)
448 consumer_admin_id[cons_count] =
449 this->create_consumer_admin (ec_id[ec_count]);
452 // Connect <supplier_admin_count_> number of suppliers
453 // to the current ec.
454 for (supp_count = 0; supp_count < this->supplier_admin_count_; ++supp_count)
456 supplier_admin_id[supp_count] =
457 this->create_supplier_admin (ec_id[ec_count]);
460 // Destroy the admins.
462 // Destroy consumer admins.
463 for (cons_count = 0;
464 cons_count < this->consumer_admin_count_;
465 ++cons_count)
467 this->destroy_consumer_admin (ec_id[ec_count],
468 consumer_admin_id[cons_count]);
471 // Destroy supplier admins
472 for (supp_count = 0;
473 supp_count < this->supplier_admin_count_;
474 ++supp_count)
476 this->destroy_supplier_admin (ec_id[ec_count],
477 supplier_admin_id[supp_count]);
482 // Destroy the ec,
483 for (ec_count = 0; ec_count < this->ec_count_; ++ec_count)
485 this->destroy_ec (ec_id[ec_count]);
488 } // for
490 //********************************************************************************
493 int ACE_TMAIN (int argc, ACE_TCHAR *argv[])
497 IdAssignment test;
499 test.parse_args (argc,
500 argv);
502 test.init (argc,
503 argv);
505 test.run_test ();
507 catch (const CORBA::Exception& ex)
509 ex._tao_print_exception ("Error: ");
510 return 1;
513 ACE_DEBUG ((LM_DEBUG,
514 "IdAssignment test suceeded\n"));
515 return 0;