Merge pull request #2309 from mitza-oci/warnings
[ACE_TAO.git] / TAO / orbsvcs / tests / Notify / XML_Persistence / main.cpp
blob3df1a5da8d2ec26bea9b7b3a0724efecc3273baf
2 #include "orbsvcs/CosNotificationC.h"
3 #include "orbsvcs/NotifyExtC.h"
4 #include "orbsvcs/Notify/Notify_EventChannelFactory_i.h"
6 // On MacOS X, the static initialization trick used
7 // in the CosNotification_Serv library does not work. Including the
8 // initializer class here works around the problem.
9 #if defined (__APPLE__)
10 #include "orbsvcs/Notify/CosNotify_Initializer.h"
11 #endif /* __APPLE__ */
13 #include "tao/TimeBaseC.h"
14 #include "tao/corba.h"
15 #include "tao/PortableServer/PortableServer.h"
17 #include "ace/OS_NS_string.h"
18 #include "ace/OS_NS_stdio.h"
19 #include "ace/Dynamic_Service.h"
20 #include "ace/ARGV.h"
22 class TestSupplier
23 : public POA_CosNotifyComm::StructuredPushSupplier
25 virtual void disconnect_structured_push_supplier()
29 virtual void subscription_change( const CosNotification::EventTypeSeq&,
30 const CosNotification::EventTypeSeq&)
35 class TestConsumer
36 : public POA_CosNotifyComm::StructuredPushConsumer
38 virtual void disconnect_structured_push_consumer()
42 virtual void offer_change( const CosNotification::EventTypeSeq&, const CosNotification::EventTypeSeq&)
46 virtual void push_structured_event(const CosNotification::StructuredEvent&)
51 int ACE_TMAIN (int ac, ACE_TCHAR *av[])
53 int retval = 1;
55 bool pass1 = false;
56 bool pass2 = false;
57 try
59 CORBA::ORB_var orb;
60 PortableServer::POA_var poa;
62 orb = CORBA::ORB_init (ac, av);
63 ACE_ASSERT(! CORBA::is_nil (orb.in ()));
65 if (ac > 2 && ACE_OS::strcmp (av[1], ACE_TEXT ("-pass")) == 0)
67 int pn = av[2][0] - '0';
68 switch (pn)
70 case 1:
71 pass1 = true;
72 pass2 = false;
73 break;
74 case 2:
75 pass1 = false;
76 pass2 = true;
77 break;
78 case 3:
79 pass1 = true;
80 pass2 = true;
81 break;
82 default:
83 ACE_OS::fprintf (stderr, "Illegal -pass command line option. Expecting 1, 2, or 3\n");
84 return -1;
87 if (! pass1 && !pass2)
89 FILE *f;
90 f = ACE_OS::fopen ("loadtest.xml", "r");
91 if (f != 0)
93 ACE_OS::fclose (f);
94 pass1 = false;
95 pass2 = true;
97 else
99 pass1 = true;
100 pass2 = false;
103 CORBA::Object_var obj =
104 orb->resolve_initial_references("RootPOA");
105 ACE_ASSERT(! CORBA::is_nil (obj.in ()));
106 poa = PortableServer::POA::_narrow(obj.in ());
107 ACE_ASSERT(! CORBA::is_nil (poa.in ()));
108 PortableServer::POAManager_var mgr = poa->the_POAManager();
109 mgr->activate();
111 CORBA::PolicyList policies (1);
112 policies.length (1);
114 policies[0] =
115 poa->create_lifespan_policy (PortableServer::PERSISTENT);
117 PortableServer::POA_var persistentPOA = poa->create_POA (
118 "PersistentPOA",
119 mgr.in (),
120 policies);
122 policies[0]->destroy ();
124 if (pass1)
126 CosNotifyChannelAdmin::EventChannelFactory_var cosecf =
127 TAO_Notify_EventChannelFactory_i::create(persistentPOA.in ());
129 NotifyExt::EventChannelFactory_var ecf =
130 NotifyExt::EventChannelFactory::_narrow (cosecf.in ());
132 if (CORBA::is_nil (ecf.in ()))
134 return -1;
137 CosNotification::QoSProperties qosprops(7);
138 CORBA::ULong i = 0;
140 qosprops.length(7);
141 qosprops[i].name = CORBA::string_dup(CosNotification::EventReliability);
142 qosprops[i++].value <<= CosNotification::Persistent;
143 qosprops[i].name = CORBA::string_dup(CosNotification::ConnectionReliability);
144 qosprops[i++].value <<= CosNotification::Persistent; // Required, or we won't persist much
145 qosprops[i].name = CORBA::string_dup(CosNotification::Priority);
146 qosprops[i++].value <<= CosNotification::HighestPriority;
147 qosprops[i].name = CORBA::string_dup(CosNotification::Timeout);
148 qosprops[i++].value <<= (TimeBase::TimeT) 42000; // 4.2 ms
149 qosprops[i].name = CORBA::string_dup(CosNotification::StopTimeSupported);
150 qosprops[i++].value <<= CORBA::Any::from_boolean(1);
151 qosprops[i].name = CORBA::string_dup(CosNotification::MaximumBatchSize);
152 qosprops[i++].value <<= (CORBA::Long) 555;
153 qosprops[i].name = CORBA::string_dup(CosNotification::PacingInterval);
154 qosprops[i++].value <<= (TimeBase::TimeT) 34300; // 3.4 ms
155 qosprops.length(i);
157 CosNotification::AdminProperties adminprops(4);
158 adminprops.length(4);
159 i = 0;
160 adminprops[i].name = CORBA::string_dup(CosNotification::MaxQueueLength);
161 adminprops[i++].value <<= (CORBA::Long) 1234;
162 adminprops[i].name = CORBA::string_dup(CosNotification::MaxConsumers);
163 adminprops[i++].value <<= (CORBA::Long) 3;
164 adminprops[i].name = CORBA::string_dup(CosNotification::MaxSuppliers);
165 adminprops[i++].value <<= (CORBA::Long) 3;
166 adminprops[i].name = CORBA::string_dup(CosNotification::RejectNewEvents);
167 adminprops[i++].value <<= CORBA::Any::from_boolean(1);
168 adminprops.length (i);
170 CosNotifyChannelAdmin::ChannelID ecid;
171 ::CosNotifyChannelAdmin::EventChannel_var ec =
172 ecf->create_channel(qosprops, adminprops, ecid);
174 CosNotifyChannelAdmin::AdminID consumer_admin_id;
175 CosNotifyChannelAdmin::ConsumerAdmin_var ca =
176 ec->new_for_consumers(CosNotifyChannelAdmin::OR_OP,
177 consumer_admin_id);
179 CosNotifyChannelAdmin::AdminID supplier_admin_id;
180 CosNotifyChannelAdmin::SupplierAdmin_var sa =
181 ec->new_for_suppliers(CosNotifyChannelAdmin::OR_OP,
182 supplier_admin_id);
184 CosNotifyChannelAdmin::ProxyID proxy_id;
185 CosNotifyChannelAdmin::ProxySupplier_var ps =
186 ca->obtain_notification_push_supplier(
187 CosNotifyChannelAdmin::STRUCTURED_EVENT,
188 proxy_id);
190 CosNotifyChannelAdmin::StructuredProxyPushSupplier_var strps =
191 CosNotifyChannelAdmin::StructuredProxyPushSupplier::_narrow(ps.in());
193 ps = ca->obtain_notification_push_supplier(
194 CosNotifyChannelAdmin::SEQUENCE_EVENT,
195 proxy_id);
197 CosNotifyChannelAdmin::SequenceProxyPushSupplier_var seqps =
198 CosNotifyChannelAdmin::SequenceProxyPushSupplier::_narrow(ps.in());
200 ps = ca->obtain_notification_push_supplier(
201 CosNotifyChannelAdmin::ANY_EVENT,
202 proxy_id);
204 CosNotifyChannelAdmin::ProxyPushSupplier_var anyps =
205 CosNotifyChannelAdmin::ProxyPushSupplier::_narrow(ps.in());
207 CosNotifyChannelAdmin::ProxyConsumer_var pc =
208 sa->obtain_notification_push_consumer(
209 CosNotifyChannelAdmin::STRUCTURED_EVENT,
210 proxy_id);
212 CosNotifyChannelAdmin::StructuredProxyPushConsumer_var strpc = CosNotifyChannelAdmin::StructuredProxyPushConsumer::_narrow(pc.in());
214 pc = sa->obtain_notification_push_consumer(
215 CosNotifyChannelAdmin::SEQUENCE_EVENT,
216 proxy_id);
218 CosNotifyChannelAdmin::SequenceProxyPushConsumer_var seqpc = CosNotifyChannelAdmin::SequenceProxyPushConsumer::_narrow(pc.in());
220 pc =
221 sa->obtain_notification_push_consumer(
222 CosNotifyChannelAdmin::ANY_EVENT,
223 proxy_id);
225 CosNotifyChannelAdmin::ProxyPushConsumer_var anypc = CosNotifyChannelAdmin::ProxyPushConsumer::_narrow(pc.in());
227 CosNotifyFilter::FilterFactory_var ff =
228 ec->default_filter_factory ();
230 CosNotifyFilter::Filter_var filter1 =
231 ff->create_filter("EXTENDED_TCL");
233 ACE_ASSERT(! CORBA::is_nil (filter1.in ()));
235 CosNotifyFilter::Filter_var filter2 =
236 ff->create_filter("EXTENDED_TCL");
238 ACE_ASSERT(! CORBA::is_nil (filter2.in ()));
240 CosNotifyFilter::ConstraintExpSeq constraint_list(1);
241 constraint_list.length(1);
242 constraint_list[0].event_types.length(0);
243 constraint_list[0].constraint_expr = CORBA::string_dup("Number == 100");
245 CosNotifyFilter::ConstraintInfoSeq_var cons_info1 = filter1->add_constraints(constraint_list);
246 CosNotifyFilter::ConstraintInfoSeq_var cons_info2 = filter2->add_constraints(constraint_list);
248 ca->add_filter (filter1.in());
250 sa->add_filter (filter2.in());
252 strps->add_filter (filter1.in());
254 seqps->add_filter (filter2.in());
256 anyps->add_filter (filter1.in());
258 strpc->add_filter (filter2.in());
260 seqpc->add_filter (filter1.in());
262 anypc->add_filter (filter1.in());
263 anypc->add_filter (filter2.in());
265 CosNotification::EventTypeSeq added1(1), removed1(0);
266 added1.length(1);
267 added1[0].domain_name = CORBA::string_dup("nightly_builds");
268 added1[0].type_name = CORBA::string_dup("*");
269 ca->subscription_change(added1, removed1);
271 // Connect a PushConsumer and PushSupplier
272 TestSupplier test_supplier_svt;
273 PortableServer::ObjectId_var oid1 = persistentPOA->activate_object (&test_supplier_svt);
274 CORBA::Object_var obj1 = persistentPOA->id_to_reference (oid1.in ());
275 CosNotifyComm::StructuredPushSupplier_var push_sup = CosNotifyComm::StructuredPushSupplier::_narrow (obj1.in ());
277 TestConsumer test_consumer_svt;
278 PortableServer::ObjectId_var oid2 = persistentPOA->activate_object (&test_consumer_svt);
279 CORBA::Object_var obj2 = persistentPOA->id_to_reference (oid2.in ());
280 CosNotifyComm::StructuredPushConsumer_var push_cons = CosNotifyComm::StructuredPushConsumer::_narrow (obj2.in ());
281 strpc->connect_structured_push_supplier(push_sup.in());
282 strps->connect_structured_push_consumer(push_cons.in());
284 strps->suspend_connection();
286 persistentPOA->deactivate_object (oid1.in ());
288 persistentPOA->deactivate_object (oid2.in ());
290 ecf->destroy();
291 ////////////////////////////////
292 // TODO make this not hardcoded
293 ACE_OS::rename ("abc.xml", "loadtest.xml");
294 } // end of pass 1
296 if (pass2)
298 // Create a new ecf, which should load itself from loadtest.xml
299 CosNotifyChannelAdmin::EventChannelFactory_var
300 cosecf = TAO_Notify_EventChannelFactory_i::create(persistentPOA.in ());
302 NotifyExt::EventChannelFactory_var
303 ecf = NotifyExt::EventChannelFactory::_narrow (cosecf.in ());
305 if (CORBA::is_nil (ecf.in ()))
307 return -1;
310 // Force a change, which should write out a new abc.xml.
311 ecf->save_topology ();
313 ecf->destroy();
316 poa->destroy (true, true);
317 orb->destroy ();
318 poa = PortableServer::POA::_nil ();
319 orb = CORBA::ORB::_nil ();
320 retval = 0;
322 catch (const CORBA::Exception& ex)
324 ex._tao_print_exception ("Error: Unexpected exception caught in main. ");
325 retval = -1;
327 catch (...)
329 ACE_DEBUG ((LM_DEBUG,
330 ACE_TEXT ("Error : Unknown exception caught in main.") ));
331 retval = -2;
333 return retval;