Changes to attempt to silence bcc64x
[ACE_TAO.git] / TAO / orbsvcs / tests / Notify / Basic / Events.cpp
blobfaffb62ee908328ddc190afde8909657537ce021
1 #include "ace/Arg_Shifter.h"
2 #include "ace/Get_Opt.h"
3 #include "tao/debug.h"
4 #include "Events.h"
7 /***************************************************************************/
9 Event_StructuredPushConsumer::Event_StructuredPushConsumer (Events *test_client)
10 : test_client_ (test_client)
14 void
15 Event_StructuredPushConsumer::push_structured_event (
16 const CosNotification::StructuredEvent & notification
19 int event_num;
20 notification.filterable_data[0].value >>= event_num;
22 if (TAO_debug_level)
23 ACE_DEBUG ((LM_DEBUG,
24 "Received event# %d\n",
25 event_num));
27 this->test_client_->on_event_received ();
30 /***************************************************************************/
32 Event_StructuredPushSupplier::Event_StructuredPushSupplier (
33 Events* test_client
35 : test_client_ (test_client)
39 Event_StructuredPushSupplier::~Event_StructuredPushSupplier ()
43 /***************************************************************************/
44 Events::Events ()
45 : use_default_admin_ (0), event_count_ (5)
49 Events::~Events ()
53 int
54 Events::init (int argc,
55 ACE_TCHAR* argv [])
57 // Initialize the base class.
58 Notify_Test_Client::init (argc,
59 argv);
61 // Create all participents.
62 this->create_EC ();
64 CosNotifyChannelAdmin::AdminID adminid;
66 if (use_default_admin_ == 1)
68 this->supplier_admin_ =
69 this->ec_->default_supplier_admin ();
71 else
73 this->supplier_admin_ =
74 this->ec_->new_for_suppliers (this->ifgop_,
75 adminid);
78 ACE_ASSERT (!CORBA::is_nil (supplier_admin_.in ()));
80 if (use_default_admin_ == 1)
82 this->consumer_admin_ =
83 this->ec_->default_consumer_admin ();
85 else
87 this->consumer_admin_ =
88 this->ec_->new_for_consumers (this->ifgop_,
89 adminid);
92 ACE_ASSERT (!CORBA::is_nil (consumer_admin_.in ()));
94 ACE_NEW_RETURN (this->consumer_,
95 Event_StructuredPushConsumer (this),
96 -1);
97 this->consumer_->init (root_poa_.in ());
98 this->consumer_->connect (this->consumer_admin_.in ());
100 Event_StructuredPushConsumer* consumer2 = 0;
101 ACE_NEW_RETURN (consumer2,
102 Event_StructuredPushConsumer (this),
103 -1);
104 consumer2->init (root_poa_.in ());
105 consumer2->connect (this->consumer_admin_.in ());
107 ACE_NEW_RETURN (this->supplier_,
108 Event_StructuredPushSupplier (this),
109 -1);
110 this->supplier_->init (root_poa_.in ());
112 this->supplier_->connect (this->supplier_admin_.in ());
114 consumer_start(0);
116 return 0;
120 Events::parse_args (int argc,
121 ACE_TCHAR *argv[])
123 ACE_Arg_Shifter arg_shifter (argc,
124 argv);
125 const ACE_TCHAR *current_arg = 0;
127 while (arg_shifter.is_anything_left ())
129 if (arg_shifter.cur_arg_strncasecmp (ACE_TEXT("-use_default_admin")) == 0)
131 this->use_default_admin_ = 1;
132 arg_shifter.consume_arg ();
134 else if (0 != (current_arg = arg_shifter.get_the_parameter (ACE_TEXT("-events"))))
136 this->event_count_ = ACE_OS::atoi (current_arg);
137 // The number of events to send/receive.
138 arg_shifter.consume_arg ();
140 else if (arg_shifter.cur_arg_strncasecmp (ACE_TEXT("-?")) == 0)
142 ACE_DEBUG((LM_DEBUG,
143 "usage: %s "
144 "-use_default_admin "
145 "-events event_count\n",
146 argv[0], argv[0]));
148 arg_shifter.consume_arg ();
150 return -1;
152 else
154 arg_shifter.ignore_arg ();
158 return 0;
161 void
162 Events::create_EC ()
164 CosNotifyChannelAdmin::ChannelID id;
166 this->ec_ = notify_factory_->create_channel (this->initial_qos_,
167 this->initial_admin_,
168 id);
170 /****************************************************************/
172 CosNotification::AdminProperties admin(2);
173 admin.length (2);
175 admin[0].name =
176 CORBA::string_dup(CosNotification::MaxQueueLength);
178 admin[0].value <<= (CORBA::Long)5;
180 admin[1].name =
181 CORBA::string_dup(CosNotification::MaxConsumers);
183 admin[1].value <<= (CORBA::Long)2;
185 ec_->set_admin (admin);
188 /****************************************************************/
189 ACE_ASSERT (!CORBA::is_nil (this->ec_.in ()));
192 void
193 Events::on_event_received ()
195 ++this->result_count_;
197 if (TAO_debug_level)
198 ACE_DEBUG ((LM_DEBUG,
199 "event count = #%d\n",
200 this->result_count_.value ()));
202 if (this->result_count_ == 2 * this->event_count_)
204 this->end_test ();
208 void
209 Events::run_test ()
211 // operations:
212 CosNotification::StructuredEvent event;
214 // EventHeader.
216 // FixedEventHeader.
217 // EventType.
218 // string.
219 event.header.fixed_header.event_type.domain_name = CORBA::string_dup("*");
220 // string
221 event.header.fixed_header.event_type.type_name = CORBA::string_dup("*");
222 // string
223 event.header.fixed_header.event_name = CORBA::string_dup("myevent");
225 // OptionalHeaderFields.
226 // PropertySeq.
227 // sequence<Property>: string name, any value
228 CosNotification::PropertySeq& qos = event.header.variable_header;
229 qos.length (1); // put nothing here
231 // FilterableEventBody
232 // PropertySeq
233 // sequence<Property>: string name, any value
234 event.filterable_data.length (3);
235 event.filterable_data[0].name = CORBA::string_dup("threshold");
237 event.filterable_data[1].name = CORBA::string_dup("temperature");
238 event.filterable_data[1].value <<= (CORBA::Long)70;
240 event.filterable_data[2].name = CORBA::string_dup("pressure");
241 event.filterable_data[2].value <<= (CORBA::Long)80;
243 CORBA::Short prio = CosNotification::LowestPriority;
245 for (int i = 0; i < this->event_count_; ++i)
247 event.filterable_data[0].value <<= (CORBA::Long)i;
249 // any
250 event.remainder_of_body <<= (CORBA::Long)i;
252 qos[0].name = CORBA::string_dup (CosNotification::Priority);
253 qos[0].value <<= (CORBA::Short)prio++;
255 this->supplier_->send_event (event);
259 void
260 Events::end_test ()
262 consumer_done(0);
266 Events::check_results ()
268 // Destroy the channel.
269 this->ec_->destroy ();
271 if (this->result_count_ == 2 * this->event_count_)
273 ACE_DEBUG ((LM_DEBUG,
274 "Events test success\n"));
275 return 0;
277 else
279 ACE_DEBUG ((LM_DEBUG,
280 "Events test failed!\n"));
281 return 1;
285 /***************************************************************************/
288 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
290 Events events;
292 if (events.parse_args (argc, argv) == -1)
294 return 1;
299 events.init (argc,
300 argv);
302 events.run_test ();
304 events.ORB_run();
306 catch (const CORBA::Exception& se)
308 se._tao_print_exception ("Error: ");
309 return 1;
312 int status = 0;
316 status = events.check_results ();
318 catch (const CORBA::Exception& se)
320 se._tao_print_exception ("Error: ");
321 status = 1;
324 return status;