1 #include "ace/Arg_Shifter.h"
2 #include "ace/Get_Opt.h"
7 /***************************************************************************/
9 Event_StructuredPushConsumer::Event_StructuredPushConsumer (Events
*test_client
)
10 : test_client_ (test_client
)
15 Event_StructuredPushConsumer::push_structured_event (
16 const CosNotification::StructuredEvent
& notification
20 notification
.filterable_data
[0].value
>>= event_num
;
24 "Received event# %d\n",
27 this->test_client_
->on_event_received ();
30 /***************************************************************************/
32 Event_StructuredPushSupplier::Event_StructuredPushSupplier (
35 : test_client_ (test_client
)
39 Event_StructuredPushSupplier::~Event_StructuredPushSupplier ()
43 /***************************************************************************/
45 : use_default_admin_ (0), event_count_ (5)
54 Events::init (int argc
,
57 // Initialize the base class.
58 Notify_Test_Client::init (argc
,
61 // Create all participents.
64 CosNotifyChannelAdmin::AdminID adminid
;
66 if (use_default_admin_
== 1)
68 this->supplier_admin_
=
69 this->ec_
->default_supplier_admin ();
73 this->supplier_admin_
=
74 this->ec_
->new_for_suppliers (this->ifgop_
,
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 ();
87 this->consumer_admin_
=
88 this->ec_
->new_for_consumers (this->ifgop_
,
92 ACE_ASSERT (!CORBA::is_nil (consumer_admin_
.in ()));
94 ACE_NEW_RETURN (this->consumer_
,
95 Event_StructuredPushConsumer (this),
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),
104 consumer2
->init (root_poa_
.in ());
105 consumer2
->connect (this->consumer_admin_
.in ());
107 ACE_NEW_RETURN (this->supplier_
,
108 Event_StructuredPushSupplier (this),
110 this->supplier_
->init (root_poa_
.in ());
112 this->supplier_
->connect (this->supplier_admin_
.in ());
120 Events::parse_args (int argc
,
123 ACE_Arg_Shifter
arg_shifter (argc
,
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)
144 "-use_default_admin "
145 "-events event_count\n",
148 arg_shifter
.consume_arg ();
154 arg_shifter
.ignore_arg ();
164 CosNotifyChannelAdmin::ChannelID id
;
166 this->ec_
= notify_factory_
->create_channel (this->initial_qos_
,
167 this->initial_admin_
,
170 /****************************************************************/
172 CosNotification::AdminProperties admin(2);
176 CORBA::string_dup(CosNotification::MaxQueueLength);
178 admin[0].value <<= (CORBA::Long)5;
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 ()));
193 Events::on_event_received ()
195 ++this->result_count_
;
198 ACE_DEBUG ((LM_DEBUG
,
199 "event count = #%d\n",
200 this->result_count_
.value ()));
202 if (this->result_count_
== 2 * this->event_count_
)
212 CosNotification::StructuredEvent event
;
219 event
.header
.fixed_header
.event_type
.domain_name
= CORBA::string_dup("*");
221 event
.header
.fixed_header
.event_type
.type_name
= CORBA::string_dup("*");
223 event
.header
.fixed_header
.event_name
= CORBA::string_dup("myevent");
225 // OptionalHeaderFields.
227 // sequence<Property>: string name, any value
228 CosNotification::PropertySeq
& qos
= event
.header
.variable_header
;
229 qos
.length (1); // put nothing here
231 // FilterableEventBody
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
;
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
);
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"));
279 ACE_DEBUG ((LM_DEBUG
,
280 "Events test failed!\n"));
285 /***************************************************************************/
288 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
292 if (events
.parse_args (argc
, argv
) == -1)
306 catch (const CORBA::Exception
& se
)
308 se
._tao_print_exception ("Error: ");
316 status
= events
.check_results ();
318 catch (const CORBA::Exception
& se
)
320 se
._tao_print_exception ("Error: ");