1 #include "ace/Arg_Shifter.h"
2 #include "ace/Get_Opt.h"
4 #include <orbsvcs/CosNamingC.h>
5 #include <orbsvcs/CosNotifyCommC.h>
6 #include <orbsvcs/CosNotifyChannelAdminC.h>
10 LifeCycle::LifeCycle ()
15 LifeCycle::~LifeCycle ()
20 LifeCycle::parse_args (int argc
,
23 ACE_Arg_Shifter
arg_shifter (argc
,
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("-count"))))
32 this->count_
= ACE_OS::atoi (current_arg
);
33 // The number of times to create and destroy.
34 arg_shifter
.consume_arg ();
36 else if (arg_shifter
.cur_arg_strncasecmp (ACE_TEXT("-?")) == 0)
44 arg_shifter
.consume_arg ();
50 arg_shifter
.ignore_arg ();
58 LifeCycle::init (int argc
, ACE_TCHAR
*argv
[])
60 CORBA::ORB_var orb
= CORBA::ORB_init (argc
, argv
);
62 CORBA::Object_var rootObj
=
63 orb
->resolve_initial_references ("NameService");
65 if (CORBA::is_nil (rootObj
.in ()))
68 " (%P|%t) Unable to resolve naming service !\n"));
72 CosNaming::NamingContext_var rootNC
=
73 CosNaming::NamingContext::_narrow (rootObj
.in ());
75 CosNaming::Name
name (1);
77 name
[0].id
= CORBA::string_dup ("NotifyEventChannelFactory");
79 CORBA::Object_var obj
= rootNC
->resolve (name
);
82 CosNotifyChannelAdmin::EventChannelFactory::_narrow (obj
.in());
84 if (CORBA::is_nil (notify_factory_
.in ()))
87 " (%P|%t) Unable to locate Notify_Service\n"));
96 for (int i
= 0; i
< this->count_
; ++i
)
100 this->create_supplier_admin ();
102 this->create_consumer_admin ();
104 this->destroy_consumer_admin ();
106 this->destroy_supplier_admin ();
113 LifeCycle::create_ec ()
115 CosNotifyChannelAdmin::ChannelID id
;
116 CosNotification::QoSProperties initial_qos
;
117 CosNotification::AdminProperties initial_admin
;
119 this->ec_
= notify_factory_
->create_channel (initial_qos
,
123 if (CORBA::is_nil (ec_
.in ())) {
124 ACE_ERROR ((LM_ERROR
,
125 " (%P|%t) Unable to create event channel\n"));
130 ACE_DEBUG ((LM_DEBUG
,
131 "created event channel\n"));
135 LifeCycle::create_supplier_admin ()
137 CosNotifyChannelAdmin::AdminID adminid
;
138 CosNotifyChannelAdmin::InterFilterGroupOperator ifgop
=
139 CosNotifyChannelAdmin::OR_OP
;
141 supplier_admin_
= this->ec_
->new_for_suppliers (ifgop
,
144 if (CORBA::is_nil (supplier_admin_
.in ()))
146 ACE_ERROR ((LM_ERROR
,
147 " (%P|%t) Unable to create supplier admin\n"));
152 ACE_DEBUG ((LM_DEBUG
,
153 "created supplier admin\n"));
157 LifeCycle::create_consumer_admin ()
159 CosNotifyChannelAdmin::AdminID adminid
;
160 CosNotifyChannelAdmin::InterFilterGroupOperator ifgop
=
161 CosNotifyChannelAdmin::OR_OP
;
163 consumer_admin_
= ec_
->new_for_consumers (ifgop
, adminid
);
165 if (CORBA::is_nil (consumer_admin_
.in()))
167 ACE_ERROR ((LM_ERROR
,
168 " (%P|%t) Unable to find supplier admin\n"));
173 ACE_DEBUG ((LM_DEBUG
,
174 "created consumer admin\n"));
178 LifeCycle::destroy_supplier_admin ()
180 this->supplier_admin_
->destroy ();
183 ACE_DEBUG ((LM_DEBUG
,
184 "destroyed supplier admin\n"));
188 LifeCycle::destroy_consumer_admin ()
190 this->consumer_admin_
->destroy ();
193 ACE_DEBUG ((LM_DEBUG
,
194 "destroyed consumer admin\n"));
198 LifeCycle::destroy_ec ()
200 this->ec_
->destroy ();
203 ACE_DEBUG ((LM_DEBUG
,
204 "destroyed event channel\n"));
209 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
215 test
.parse_args (argc
,
223 catch (const CORBA::Exception
& ex
)
225 ex
._tao_print_exception ("Error: ");