Revert "Use a variable on the stack to not have a temporary in the call"
[ACE_TAO.git] / TAO / orbsvcs / tests / Notify / Basic / LifeCycle.cpp
blobfff98c3ee41f6daf4a89ec4356313219d803ccc7
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 <orbsvcs/CosNotifyChannelAdminC.h>
8 #include "LifeCycle.h"
10 LifeCycle::LifeCycle ()
11 : count_ (10)
15 LifeCycle::~LifeCycle ()
19 int
20 LifeCycle::parse_args (int argc,
21 ACE_TCHAR *argv[])
23 ACE_Arg_Shifter arg_shifter (argc,
24 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("-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)
38 ACE_DEBUG ((LM_DEBUG,
39 "usage: %s "
40 "-count testcount\n",
41 argv[0],
42 argv[0]));
44 arg_shifter.consume_arg ();
46 return -1;
48 else
50 arg_shifter.ignore_arg ();
54 return 0;
57 void
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 ()))
67 ACE_ERROR ((LM_ERROR,
68 " (%P|%t) Unable to resolve naming service !\n"));
69 return;
72 CosNaming::NamingContext_var rootNC =
73 CosNaming::NamingContext::_narrow (rootObj.in ());
75 CosNaming::Name name (1);
76 name.length (1);
77 name[0].id = CORBA::string_dup ("NotifyEventChannelFactory");
79 CORBA::Object_var obj = rootNC->resolve (name);
81 notify_factory_ =
82 CosNotifyChannelAdmin::EventChannelFactory::_narrow (obj.in());
84 if (CORBA::is_nil (notify_factory_.in ()))
86 ACE_ERROR ((LM_ERROR,
87 " (%P|%t) Unable to locate Notify_Service\n"));
89 return;
93 void
94 LifeCycle::run_test()
96 for (int i = 0; i < this->count_; ++i)
98 this->create_ec ();
100 this->create_supplier_admin ();
102 this->create_consumer_admin ();
104 this->destroy_consumer_admin ();
106 this->destroy_supplier_admin ();
108 this->destroy_ec ();
112 void
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,
120 initial_admin,
121 id);
123 if (CORBA::is_nil (ec_.in ())) {
124 ACE_ERROR ((LM_ERROR,
125 " (%P|%t) Unable to create event channel\n"));
126 return;
129 if (TAO_debug_level)
130 ACE_DEBUG ((LM_DEBUG,
131 "created event channel\n"));
134 void
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,
142 adminid);
144 if (CORBA::is_nil (supplier_admin_.in ()))
146 ACE_ERROR ((LM_ERROR,
147 " (%P|%t) Unable to create supplier admin\n"));
148 return;
151 if (TAO_debug_level)
152 ACE_DEBUG ((LM_DEBUG,
153 "created supplier admin\n"));
156 void
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"));
169 return;
172 if (TAO_debug_level)
173 ACE_DEBUG ((LM_DEBUG,
174 "created consumer admin\n"));
177 void
178 LifeCycle::destroy_supplier_admin ()
180 this->supplier_admin_->destroy ();
182 if (TAO_debug_level)
183 ACE_DEBUG ((LM_DEBUG,
184 "destroyed supplier admin\n"));
187 void
188 LifeCycle::destroy_consumer_admin ()
190 this->consumer_admin_->destroy ();
192 if (TAO_debug_level)
193 ACE_DEBUG ((LM_DEBUG,
194 "destroyed consumer admin\n"));
197 void
198 LifeCycle::destroy_ec ()
200 this->ec_->destroy ();
202 if (TAO_debug_level)
203 ACE_DEBUG ((LM_DEBUG,
204 "destroyed event channel\n"));
209 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
213 LifeCycle test;
215 test.parse_args (argc,
216 argv);
218 test.init (argc,
219 argv);
221 test.run_test ();
223 catch (const CORBA::Exception& ex)
225 ex._tao_print_exception ("Error: ");
226 return 1;
229 return 0;