1 #include "ace/Arg_Shifter.h"
2 #include "ace/Get_Opt.h"
4 #include "orbsvcs/CosNamingC.h"
5 #include "orbsvcs/CosNotifyCommC.h"
6 #include "IdAssignment.h"
8 IdAssignment::IdAssignment (void)
11 consumer_admin_count_ (3),
12 supplier_admin_count_ (3)
16 IdAssignment::~IdAssignment (void)
21 IdAssignment::parse_args (int argc
,
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)
58 "-sa_count <count>\n",
61 arg_shifter
.consume_arg ();
67 arg_shifter
.ignore_arg ();
75 IdAssignment::init (int argc
,
78 CORBA::ORB_var orb
= CORBA::ORB_init (argc
,
81 CORBA::Object_var rootObj
=
82 orb
->resolve_initial_references ("NameService");
84 if (CORBA::is_nil (rootObj
.in ()))
87 " (%P|%t) Unable to resolve naming service !\n"));
91 CosNaming::NamingContext_var rootNC
=
92 CosNaming::NamingContext::_narrow (rootObj
.in ());
94 CosNaming::Name
name (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"));
107 this->notify_factory_
=
108 CosNotifyChannelAdmin::EventChannelFactory::_narrow (
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
,
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()))
139 " (%P|%t) Unable to find event channel\n"));
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 ()))
160 " (%P|%t) Unable to find event channel\n"));
164 CosNotifyChannelAdmin::SupplierAdmin_var supplier_admin
=
165 ec
->new_for_suppliers (ifgop
,
168 if (CORBA::is_nil (supplier_admin
.in ()))
169 ACE_ERROR_RETURN ((LM_ERROR
,
170 " (%P|%t) Unable to create supplier admin\n"),0);
173 ACE_DEBUG ((LM_DEBUG
,
174 "created supplier admin\n"));
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 ()))
192 " (%P|%t) Unable to find event channel\n"));
196 CosNotifyChannelAdmin::ConsumerAdmin_var consumer_admin
=
197 ec
->new_for_consumers (ifgop
,
200 if (CORBA::is_nil (consumer_admin
.in ()))
201 ACE_ERROR_RETURN ((LM_ERROR
,
202 " (%P|%t) Unable to create consumer admin\n"),0);
205 ACE_DEBUG ((LM_DEBUG
,
206 "created consumer admin\n"));
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 ()))
221 " (%P|%t) Unable to find event channel\n"));
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"),
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"),
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"),
251 ACE_DEBUG ((LM_DEBUG
,
252 "passed default consumer admin test.\n"));
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 ()))
267 " (%P|%t) Unable to find event channel\n"));
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"),
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"),
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"),
297 ACE_DEBUG ((LM_DEBUG
,
298 "passed default supplier admin test.\n"));
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 ()))
317 " (%P|%t) Unable to find event channel\n"));
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 ();
333 ACE_DEBUG ((LM_DEBUG
,
334 "destroyed consumer admin\n"));
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 ();
364 ACE_DEBUG ((LM_DEBUG
,
365 "destroyed supplier admin\n"));
369 IdAssignment::run_test(void)
371 CosNotifyChannelAdmin::ChannelID
* ec_id
= 0;
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 // *******************************************************************
387 for (i
= 0; i
< this->iter_
; ++i
)
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_
;
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)
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_
;
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)
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
]);
431 //******************************************************************************
432 // Repeat, but this time destroy the admins explicity.
433 for (i
= 0; i
< this->iter_
; ++i
)
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.
445 cons_count
< this->consumer_admin_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.
464 cons_count
< this->consumer_admin_count_
;
467 this->destroy_consumer_admin (ec_id
[ec_count
],
468 consumer_admin_id
[cons_count
]);
471 // Destroy supplier admins
473 supp_count
< this->supplier_admin_count_
;
476 this->destroy_supplier_admin (ec_id
[ec_count
],
477 supplier_admin_id
[supp_count
]);
483 for (ec_count
= 0; ec_count
< this->ec_count_
; ++ec_count
)
485 this->destroy_ec (ec_id
[ec_count
]);
490 //********************************************************************************
493 int ACE_TMAIN (int argc
, ACE_TCHAR
*argv
[])
499 test
.parse_args (argc
,
507 catch (const CORBA::Exception
& ex
)
509 ex
._tao_print_exception ("Error: ");
513 ACE_DEBUG ((LM_DEBUG
,
514 "IdAssignment test suceeded\n"));