Merge pull request #1551 from DOCGroup/plm_jira_333
[ACE_TAO.git] / TAO / orbsvcs / tests / Notify / Basic / Events.cpp
blob6dfcd5110acf9817a4c66dc6de1760512f617391
1 #include "ace/Arg_Shifter.h"
2 #include "ace/Get_Opt.h"
3 #include "tao/debug.h"
4 #include "Events.h"
8 /***************************************************************************/
10 Event_StructuredPushConsumer::Event_StructuredPushConsumer (Events *test_client)
11 : test_client_ (test_client)
15 void
16 Event_StructuredPushConsumer::push_structured_event (
17 const CosNotification::StructuredEvent & notification
20 int event_num;
21 notification.filterable_data[0].value >>= event_num;
23 if (TAO_debug_level)
24 ACE_DEBUG ((LM_DEBUG,
25 "Received event# %d\n",
26 event_num));
28 this->test_client_->on_event_received ();
31 /***************************************************************************/
33 Event_StructuredPushSupplier::Event_StructuredPushSupplier (
34 Events* test_client
36 : test_client_ (test_client)
40 Event_StructuredPushSupplier::~Event_StructuredPushSupplier (void)
44 /***************************************************************************/
45 Events::Events (void)
46 : use_default_admin_ (0), event_count_ (5)
50 Events::~Events (void)
54 int
55 Events::init (int argc,
56 ACE_TCHAR* argv [])
58 // Initialize the base class.
59 Notify_Test_Client::init (argc,
60 argv);
62 // Create all participents.
63 this->create_EC ();
65 CosNotifyChannelAdmin::AdminID adminid;
67 if (use_default_admin_ == 1)
69 this->supplier_admin_ =
70 this->ec_->default_supplier_admin ();
72 else
74 this->supplier_admin_ =
75 this->ec_->new_for_suppliers (this->ifgop_,
76 adminid);
79 ACE_ASSERT (!CORBA::is_nil (supplier_admin_.in ()));
81 if (use_default_admin_ == 1)
83 this->consumer_admin_ =
84 this->ec_->default_consumer_admin ();
86 else
88 this->consumer_admin_ =
89 this->ec_->new_for_consumers (this->ifgop_,
90 adminid);
93 ACE_ASSERT (!CORBA::is_nil (consumer_admin_.in ()));
95 ACE_NEW_RETURN (this->consumer_,
96 Event_StructuredPushConsumer (this),
97 -1);
98 this->consumer_->init (root_poa_.in ());
99 this->consumer_->connect (this->consumer_admin_.in ());
101 Event_StructuredPushConsumer* consumer2 = 0;
102 ACE_NEW_RETURN (consumer2,
103 Event_StructuredPushConsumer (this),
104 -1);
105 consumer2->init (root_poa_.in ());
106 consumer2->connect (this->consumer_admin_.in ());
108 ACE_NEW_RETURN (this->supplier_,
109 Event_StructuredPushSupplier (this),
110 -1);
111 this->supplier_->init (root_poa_.in ());
113 this->supplier_->connect (this->supplier_admin_.in ());
115 consumer_start( 0 );
117 return 0;
121 Events::parse_args (int argc,
122 ACE_TCHAR *argv[])
124 ACE_Arg_Shifter arg_shifter (argc,
125 argv);
126 const ACE_TCHAR *current_arg = 0;
128 while (arg_shifter.is_anything_left ())
130 if (arg_shifter.cur_arg_strncasecmp (ACE_TEXT("-use_default_admin")) == 0)
132 this->use_default_admin_ = 1;
133 arg_shifter.consume_arg ();
136 else if (0 != (current_arg = arg_shifter.get_the_parameter (ACE_TEXT("-events"))))
138 this->event_count_ = ACE_OS::atoi (current_arg);
139 // The number of events to send/receive.
140 arg_shifter.consume_arg ();
142 else if (arg_shifter.cur_arg_strncasecmp (ACE_TEXT("-?")) == 0)
144 ACE_DEBUG((LM_DEBUG,
145 "usage: %s "
146 "-use_default_admin "
147 "-events event_count\n",
148 argv[0], argv[0]));
150 arg_shifter.consume_arg ();
152 return -1;
154 else
156 arg_shifter.ignore_arg ();
160 return 0;
163 void
164 Events::create_EC (void)
166 CosNotifyChannelAdmin::ChannelID id;
168 this->ec_ = notify_factory_->create_channel (this->initial_qos_,
169 this->initial_admin_,
170 id);
172 /****************************************************************/
174 CosNotification::AdminProperties admin(2);
175 admin.length (2);
177 admin[0].name =
178 CORBA::string_dup(CosNotification::MaxQueueLength);
180 admin[0].value <<= (CORBA::Long)5;
182 admin[1].name =
183 CORBA::string_dup(CosNotification::MaxConsumers);
185 admin[1].value <<= (CORBA::Long)2;
187 ec_->set_admin (admin);
190 /****************************************************************/
191 ACE_ASSERT (!CORBA::is_nil (this->ec_.in ()));
194 void
195 Events::on_event_received (void)
197 ++this->result_count_;
199 if (TAO_debug_level)
200 ACE_DEBUG ((LM_DEBUG,
201 "event count = #%d\n",
202 this->result_count_.value ()));
204 if (this->result_count_ == 2 * this->event_count_)
206 this->end_test ();
210 void
211 Events::run_test (void)
213 // operations:
214 CosNotification::StructuredEvent event;
216 // EventHeader.
218 // FixedEventHeader.
219 // EventType.
220 // string.
221 event.header.fixed_header.event_type.domain_name = CORBA::string_dup("*");
222 // string
223 event.header.fixed_header.event_type.type_name = CORBA::string_dup("*");
224 // string
225 event.header.fixed_header.event_name = CORBA::string_dup("myevent");
227 // OptionalHeaderFields.
228 // PropertySeq.
229 // sequence<Property>: string name, any value
230 CosNotification::PropertySeq& qos = event.header.variable_header;
231 qos.length (1); // put nothing here
233 // FilterableEventBody
234 // PropertySeq
235 // sequence<Property>: string name, any value
236 event.filterable_data.length (3);
237 event.filterable_data[0].name = CORBA::string_dup("threshold");
239 event.filterable_data[1].name = CORBA::string_dup("temperature");
240 event.filterable_data[1].value <<= (CORBA::Long)70;
242 event.filterable_data[2].name = CORBA::string_dup("pressure");
243 event.filterable_data[2].value <<= (CORBA::Long)80;
245 CORBA::Short prio = CosNotification::LowestPriority;
247 for (int i = 0; i < this->event_count_; ++i)
249 event.filterable_data[0].value <<= (CORBA::Long)i;
251 // any
252 event.remainder_of_body <<= (CORBA::Long)i;
254 qos[0].name = CORBA::string_dup (CosNotification::Priority);
255 qos[0].value <<= (CORBA::Short)prio++;
257 this->supplier_->send_event (event);
261 void
262 Events::end_test (void)
264 consumer_done( 0 );
268 Events::check_results (void)
270 // Destroy the channel.
271 this->ec_->destroy ();
273 if (this->result_count_ == 2 * this->event_count_)
275 ACE_DEBUG ((LM_DEBUG,
276 "Events test success\n"));
277 return 0;
279 else
281 ACE_DEBUG ((LM_DEBUG,
282 "Events test failed!\n"));
283 return 1;
287 /***************************************************************************/
290 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
292 Events events;
294 if (events.parse_args (argc, argv) == -1)
296 return 1;
301 events.init (argc,
302 argv);
304 events.run_test ();
306 events.ORB_run( );
308 catch (const CORBA::Exception& se)
310 se._tao_print_exception ("Error: ");
311 return 1;
314 int status = 0;
318 status = events.check_results ();
320 catch (const CORBA::Exception& se)
322 se._tao_print_exception ("Error: ");
323 status = 1;
326 return status;