1 #include "ace/Arg_Shifter.h"
2 #include "ace/Get_Opt.h"
8 /***************************************************************************/
10 Event_StructuredPushConsumer::Event_StructuredPushConsumer (Events
*test_client
)
11 : test_client_ (test_client
)
16 Event_StructuredPushConsumer::push_structured_event (
17 const CosNotification::StructuredEvent
& notification
21 notification
.filterable_data
[0].value
>>= event_num
;
25 "Received event# %d\n",
28 this->test_client_
->on_event_received ();
31 /***************************************************************************/
33 Event_StructuredPushSupplier::Event_StructuredPushSupplier (
36 : test_client_ (test_client
)
40 Event_StructuredPushSupplier::~Event_StructuredPushSupplier (void)
44 /***************************************************************************/
46 : use_default_admin_ (0), event_count_ (5)
50 Events::~Events (void)
55 Events::init (int argc
,
58 // Initialize the base class.
59 Notify_Test_Client::init (argc
,
62 // Create all participents.
65 CosNotifyChannelAdmin::AdminID adminid
;
67 if (use_default_admin_
== 1)
69 this->supplier_admin_
=
70 this->ec_
->default_supplier_admin ();
74 this->supplier_admin_
=
75 this->ec_
->new_for_suppliers (this->ifgop_
,
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 ();
88 this->consumer_admin_
=
89 this->ec_
->new_for_consumers (this->ifgop_
,
93 ACE_ASSERT (!CORBA::is_nil (consumer_admin_
.in ()));
95 ACE_NEW_RETURN (this->consumer_
,
96 Event_StructuredPushConsumer (this),
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),
105 consumer2
->init (root_poa_
.in ());
106 consumer2
->connect (this->consumer_admin_
.in ());
108 ACE_NEW_RETURN (this->supplier_
,
109 Event_StructuredPushSupplier (this),
111 this->supplier_
->init (root_poa_
.in ());
113 this->supplier_
->connect (this->supplier_admin_
.in ());
121 Events::parse_args (int argc
,
124 ACE_Arg_Shifter
arg_shifter (argc
,
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)
146 "-use_default_admin "
147 "-events event_count\n",
150 arg_shifter
.consume_arg ();
156 arg_shifter
.ignore_arg ();
164 Events::create_EC (void)
166 CosNotifyChannelAdmin::ChannelID id
;
168 this->ec_
= notify_factory_
->create_channel (this->initial_qos_
,
169 this->initial_admin_
,
172 /****************************************************************/
174 CosNotification::AdminProperties admin(2);
178 CORBA::string_dup(CosNotification::MaxQueueLength);
180 admin[0].value <<= (CORBA::Long)5;
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 ()));
195 Events::on_event_received (void)
197 ++this->result_count_
;
200 ACE_DEBUG ((LM_DEBUG
,
201 "event count = #%d\n",
202 this->result_count_
.value ()));
204 if (this->result_count_
== 2 * this->event_count_
)
211 Events::run_test (void)
214 CosNotification::StructuredEvent event
;
221 event
.header
.fixed_header
.event_type
.domain_name
= CORBA::string_dup("*");
223 event
.header
.fixed_header
.event_type
.type_name
= CORBA::string_dup("*");
225 event
.header
.fixed_header
.event_name
= CORBA::string_dup("myevent");
227 // OptionalHeaderFields.
229 // sequence<Property>: string name, any value
230 CosNotification::PropertySeq
& qos
= event
.header
.variable_header
;
231 qos
.length (1); // put nothing here
233 // FilterableEventBody
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
;
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
);
262 Events::end_test (void)
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"));
281 ACE_DEBUG ((LM_DEBUG
,
282 "Events test failed!\n"));
287 /***************************************************************************/
290 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
294 if (events
.parse_args (argc
, argv
) == -1)
308 catch (const CORBA::Exception
& se
)
310 se
._tao_print_exception ("Error: ");
318 status
= events
.check_results ();
320 catch (const CORBA::Exception
& se
)
322 se
._tao_print_exception ("Error: ");