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 ()
11 consumer_admin_count_ (3),
12 supplier_admin_count_ (3)
16 IdAssignment::~IdAssignment ()
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"));
90 CosNaming::NamingContext_var rootNC
=
91 CosNaming::NamingContext::_narrow (rootObj
.in ());
93 CosNaming::Name
name (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"));
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
,
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()))
135 " (%P|%t) Unable to find event channel\n"));
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 ()))
156 " (%P|%t) Unable to find event channel\n"));
160 CosNotifyChannelAdmin::SupplierAdmin_var supplier_admin
=
161 ec
->new_for_suppliers (ifgop
,
164 if (CORBA::is_nil (supplier_admin
.in ()))
165 ACE_ERROR_RETURN ((LM_ERROR
,
166 " (%P|%t) Unable to create supplier admin\n"),0);
169 ACE_DEBUG ((LM_DEBUG
,
170 "created supplier admin\n"));
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 ()))
188 " (%P|%t) Unable to find event channel\n"));
192 CosNotifyChannelAdmin::ConsumerAdmin_var consumer_admin
=
193 ec
->new_for_consumers (ifgop
,
196 if (CORBA::is_nil (consumer_admin
.in ()))
197 ACE_ERROR_RETURN ((LM_ERROR
,
198 " (%P|%t) Unable to create consumer admin\n"),0);
201 ACE_DEBUG ((LM_DEBUG
,
202 "created consumer admin\n"));
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 ()))
217 " (%P|%t) Unable to find event channel\n"));
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"),
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"),
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"),
247 ACE_DEBUG ((LM_DEBUG
,
248 "passed default consumer admin test.\n"));
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 ()))
263 " (%P|%t) Unable to find event channel\n"));
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"),
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"),
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"),
293 ACE_DEBUG ((LM_DEBUG
,
294 "passed default supplier admin test.\n"));
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 ()))
313 " (%P|%t) Unable to find event channel\n"));
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 ();
329 ACE_DEBUG ((LM_DEBUG
,
330 "destroyed consumer admin\n"));
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 ();
360 ACE_DEBUG ((LM_DEBUG
,
361 "destroyed supplier admin\n"));
365 IdAssignment::run_test()
367 CosNotifyChannelAdmin::ChannelID
* ec_id
= 0;
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 // *******************************************************************
383 for (i
= 0; i
< this->iter_
; ++i
)
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_
;
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)
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_
;
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)
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
]);
427 //******************************************************************************
428 // Repeat, but this time destroy the admins explicity.
429 for (i
= 0; i
< this->iter_
; ++i
)
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.
441 cons_count
< this->consumer_admin_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.
460 cons_count
< this->consumer_admin_count_
;
463 this->destroy_consumer_admin (ec_id
[ec_count
],
464 consumer_admin_id
[cons_count
]);
467 // Destroy supplier admins
469 supp_count
< this->supplier_admin_count_
;
472 this->destroy_supplier_admin (ec_id
[ec_count
],
473 supplier_admin_id
[supp_count
]);
479 for (ec_count
= 0; ec_count
< this->ec_count_
; ++ec_count
)
481 this->destroy_ec (ec_id
[ec_count
]);
486 //********************************************************************************
489 int ACE_TMAIN (int argc
, ACE_TCHAR
*argv
[])
495 test
.parse_args (argc
,
503 catch (const CORBA::Exception
& ex
)
505 ex
._tao_print_exception ("Error: ");
509 ACE_DEBUG ((LM_DEBUG
,
510 "IdAssignment test suceeded\n"));