Merge pull request #2316 from jwillemsen/jwi-taskcommenttypo
[ACE_TAO.git] / TAO / orbsvcs / tests / Notify / Basic / Updates.cpp
blob5910612b6fb26442e877b7067f0f250396ce349c
1 #include "ace/Arg_Shifter.h"
2 #include "ace/Get_Opt.h"
3 #include "tao/debug.h"
4 #include "Updates.h"
7 Updates_StructuredPushConsumer::Updates_StructuredPushConsumer (Updates *test_client)
8 : test_client_ (test_client)
12 void
13 Updates_StructuredPushConsumer::offer_change (
14 const CosNotification::EventTypeSeq & added,
15 const CosNotification::EventTypeSeq & removed
18 if (TAO_debug_level)
19 ACE_DEBUG ((LM_DEBUG, "StructuredPushConsumer::offer_change invoked:\n"));
20 this->test_client_->types_changed (added, removed);
23 /***************************************************************************/
25 Updates_StructuredPushSupplier::Updates_StructuredPushSupplier (Updates* test_client)
26 :test_client_ (test_client)
30 Updates_StructuredPushSupplier::~Updates_StructuredPushSupplier ()
34 void
35 Updates_StructuredPushSupplier::subscription_change (
36 const CosNotification::EventTypeSeq & added,
37 const CosNotification::EventTypeSeq & removed
40 if (TAO_debug_level)
41 ACE_DEBUG ((LM_DEBUG, "StructuredPushSupplier::subscription_change invoked:\n"));
42 this->test_client_->types_changed (added, removed);
45 /***************************************************************************/
47 Updates::Updates ()
48 : added_count_ (0), removed_count_ (0)
52 Updates::~Updates ()
56 int
57 Updates::init (int argc,
58 ACE_TCHAR* argv [])
60 // Initialize base class.
61 Notify_Test_Client::init (argc,
62 argv);
64 // Create all participents.
65 this->create_EC ();
67 CosNotifyChannelAdmin::AdminID adminid;
69 supplier_admin_ =
70 ec_->new_for_suppliers (this->ifgop_,
71 adminid);
73 ACE_ASSERT (!CORBA::is_nil (supplier_admin_.in ()));
75 consumer_admin_ =
76 ec_->new_for_consumers (this->ifgop_,
77 adminid);
79 ACE_ASSERT (!CORBA::is_nil (consumer_admin_.in ()));
81 ACE_NEW_RETURN (consumer_,
82 Updates_StructuredPushConsumer (this),
83 -1);
84 consumer_->init (root_poa_.in ());
86 consumer_->connect (this->consumer_admin_.in ());
88 ACE_NEW_RETURN (supplier_,
89 Updates_StructuredPushSupplier (this),
90 -1);
91 supplier_->init (root_poa_.in ());
93 supplier_->connect (this->supplier_admin_.in ());
95 return 0;
98 void
99 Updates::create_EC ()
101 CosNotifyChannelAdmin::ChannelID id;
103 ec_ = notify_factory_->create_channel (initial_qos_,
104 initial_admin_,
105 id);
107 ACE_ASSERT (!CORBA::is_nil (ec_.in ()));
110 void
111 Updates::types_changed (const CosNotification::EventTypeSeq & added,
112 const CosNotification::EventTypeSeq & removed)
114 if (TAO_debug_level)
116 ACE_DEBUG ((LM_DEBUG, "Added Types..\n"));
117 this->print_event_types (added);
119 ACE_DEBUG ((LM_DEBUG, "Removed Types..\n"));
120 this->print_event_types (removed);
123 ACE_GUARD (TAO_SYNCH_MUTEX, mon, this->lock_);
125 this->added_count_ += added.length ();
126 this->removed_count_ += removed.length ();
129 void
130 Updates::print_event_types (const CosNotification::EventTypeSeq &types)
132 for (CORBA::ULong i = 0; i < types.length (); ++i)
134 ACE_DEBUG ((LM_DEBUG, "(%s, %s)\n", types[i].domain_name.in (), types[i].type_name. in()));
138 void
139 Updates::add_type (CosNotification::EventTypeSeq& type_seq, const char* type)
141 // Make space.
142 int index = type_seq.length ();
143 type_seq.length (index + 1);
145 type_seq[index].domain_name = CORBA::string_dup (type);
146 type_seq[index].type_name = CORBA::string_dup (type);
149 void
150 Updates::wait_for_updates (int expected_added, int expected_removed)
152 while (1)
154 if (added_count_ == expected_added &&
155 removed_count_ == expected_removed)
156 break;
158 ACE_Time_Value tv(0, 100 * 1000);
159 orb_->run(tv);
163 void
164 Updates::reset_counts ()
166 ACE_GUARD (TAO_SYNCH_MUTEX, mon, this->lock_);
167 this->added_count_ = 0;
168 this->removed_count_ = 0;
171 void
172 Updates::run_test ()
174 this->test_subscription_change ();
176 if (TAO_debug_level)
177 ACE_DEBUG ((LM_DEBUG, "Finished testing subscription_change!\n"));
179 this->test_offer_change ();
181 ACE_DEBUG ((LM_DEBUG, "Updates test has run successfully!\n"));
184 void
185 Updates::test_subscription_change ()
188 // reset counts.
189 this->reset_counts ();
191 /// Currently we're subscribed for "*"
192 /// Add RED, GREEN and BLUE
193 /// Remove ORANGE and PINK
195 CosNotification::EventTypeSeq added, removed;
197 this->add_type (added, "RED");
198 this->add_type (added, "GREEN");
199 this->add_type (added, "BLUE");
201 this->add_type (removed, "ORANGE");
202 this->add_type (removed, "PINK");
204 if (TAO_debug_level)
206 ACE_DEBUG ((LM_DEBUG, "Calling subscription_change with added types:\n"));
207 this->print_event_types (added);
208 ACE_DEBUG ((LM_DEBUG, "Calling subscription_change with removed types:\n"));
209 this->print_event_types (removed);
212 this->consumer_->get_proxy_supplier ()->subscription_change (added, removed);
214 this->wait_for_updates (3, 0); // The supplier should receive Added (RED, GREEN, BLUE)
216 // Get the subscriptions visible to the supplier.
217 CosNotification::EventTypeSeq_var obtained =
218 this->supplier_->get_proxy_consumer ()->obtain_subscription_types (CosNotifyChannelAdmin::ALL_NOW_UPDATES_ON);
220 if (TAO_debug_level)
222 ACE_DEBUG ((LM_DEBUG, "obtain_subscription_types\n"));
223 this->print_event_types (obtained.in ());
228 // reset counts.
229 this->reset_counts ();
231 // Now, add PURPLE, RED and GREEN
232 CosNotification::EventTypeSeq added, removed;
234 this->add_type (added, "PURPLE");
235 this->add_type (added, "GREEN");
236 this->add_type (added, "BLUE");
238 if (TAO_debug_level)
240 ACE_DEBUG ((LM_DEBUG, "Calling subscription_change with added types:\n"));
241 this->print_event_types (added);
242 ACE_DEBUG ((LM_DEBUG, "Calling subscription_change with removed types:\n"));
243 this->print_event_types (removed);
246 this->consumer_->get_proxy_supplier ()->subscription_change (added, removed);
248 this->wait_for_updates (1, 0); // The supplier should receive Added (PURPLE).
250 // Get the subscriptions visible to the supplier.
251 CosNotification::EventTypeSeq_var obtained =
252 this->supplier_->get_proxy_consumer ()->obtain_subscription_types (CosNotifyChannelAdmin::ALL_NOW_UPDATES_ON);
254 if (TAO_debug_level)
256 ACE_DEBUG ((LM_DEBUG, "obtain_subscription_types\n"));
257 this->print_event_types (obtained.in ());
262 // reset counts.
263 this->reset_counts ();
265 // Next, Remove everything by subcribing to "*"
266 CosNotification::EventTypeSeq added, removed;
268 this->add_type (added, "*");
270 if (TAO_debug_level)
272 ACE_DEBUG ((LM_DEBUG, "Calling subscription_change with added types:\n"));
273 this->print_event_types (added);
274 ACE_DEBUG ((LM_DEBUG, "Calling subscription_change with removed types:\n"));
275 this->print_event_types (removed);
278 this->consumer_->get_proxy_supplier ()->subscription_change (added, removed);
280 this->wait_for_updates (0, 4);
281 // The supplier should receive Remove {RED, GREEN} out of the 4 actally removed (RED, GREEN, BLUE, PURPLE) becaue that whats it offered for.
283 // Get the subscriptions visible to the supplier.
284 CosNotification::EventTypeSeq_var obtained =
285 this->supplier_->get_proxy_consumer ()->obtain_subscription_types (CosNotifyChannelAdmin::ALL_NOW_UPDATES_ON);
287 if (TAO_debug_level)
289 ACE_DEBUG ((LM_DEBUG, "obtain_subscription_types\n"));
290 this->print_event_types (obtained.in ());
296 void
297 Updates::test_offer_change ()
300 // reset counts.
301 this->reset_counts ();
303 /// Currently we're subscribed for "*"
304 /// Add RED, GREEN and BLUE
305 /// Remove ORANGE and PINK
307 CosNotification::EventTypeSeq added, removed;
309 this->add_type (added, "RED");
310 this->add_type (added, "GREEN");
311 this->add_type (added, "BLUE");
313 this->add_type (removed, "ORANGE");
314 this->add_type (removed, "PINK");
316 if (TAO_debug_level)
318 ACE_DEBUG ((LM_DEBUG, "Calling offer_change with added types:\n"));
319 this->print_event_types (added);
320 ACE_DEBUG ((LM_DEBUG, "Calling offer_change with removed types:\n"));
321 this->print_event_types (removed);
324 this->supplier_->get_proxy_consumer ()->offer_change (added, removed);
326 this->wait_for_updates (3, 0); // The consumer should receive Added (RED, GREEN, BLUE)
328 // Get the offers visible to the supplier.
329 CosNotification::EventTypeSeq_var obtained =
330 this->consumer_->get_proxy_supplier ()->obtain_offered_types (CosNotifyChannelAdmin::ALL_NOW_UPDATES_ON);
332 if (TAO_debug_level)
334 ACE_DEBUG ((LM_DEBUG, "obtain_offer_types\n"));
335 this->print_event_types (obtained.in ());
340 // reset counts.
341 this->reset_counts ();
343 // Now, add PURPLE, RED and GREEN
344 CosNotification::EventTypeSeq added, removed;
346 this->add_type (added, "PURPLE");
347 this->add_type (added, "GREEN");
348 this->add_type (added, "BLUE");
350 if (TAO_debug_level)
352 ACE_DEBUG ((LM_DEBUG, "Calling offer_change with added types:\n"));
353 this->print_event_types (added);
354 ACE_DEBUG ((LM_DEBUG, "Calling offer_change with removed types:\n"));
355 this->print_event_types (removed);
358 this->supplier_->get_proxy_consumer ()->offer_change (added, removed);
360 this->wait_for_updates (1, 0); // The consumer should receive Added (PURPLE).
362 // Get the offers visible to the consumer.
363 CosNotification::EventTypeSeq_var obtained =
364 this->consumer_->get_proxy_supplier ()->obtain_offered_types (CosNotifyChannelAdmin::ALL_NOW_UPDATES_ON);
366 if (TAO_debug_level)
368 ACE_DEBUG ((LM_DEBUG, "obtain_offer_types\n"));
369 this->print_event_types (obtained.in ());
374 // reset counts.
375 this->reset_counts ();
377 // Next, Remove everything by subcribing to "*"
378 CosNotification::EventTypeSeq added, removed;
380 this->add_type (added, "*");
382 if (TAO_debug_level)
384 ACE_DEBUG ((LM_DEBUG, "Calling offer_change with added types:\n"));
385 this->print_event_types (added);
386 ACE_DEBUG ((LM_DEBUG, "Calling offer_change with removed types:\n"));
387 this->print_event_types (removed);
390 this->supplier_->get_proxy_consumer ()->offer_change (added, removed);
392 this->wait_for_updates (0, 4);
393 // The consumer should receive Remove {RED, GREEN} out of the 4 actally removed (RED, GREEN, BLUE, PURPLE) becaue that whats it offered for.
395 // Get the offers visible to the consumer.
396 CosNotification::EventTypeSeq_var obtained =
397 this->consumer_->get_proxy_supplier ()->obtain_offered_types (CosNotifyChannelAdmin::ALL_NOW_UPDATES_ON);
399 if (TAO_debug_level)
401 ACE_DEBUG ((LM_DEBUG, "obtain_offer_types\n"));
402 this->print_event_types (obtained.in ());
408 /***************************************************************************/
411 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
413 Updates updates;
417 updates.init (argc,
418 argv);
420 updates.run_test ();
422 catch (const CORBA::SystemException& se)
424 se._tao_print_exception ("Error: ");
425 return 1;
428 return 0;