1 #include "ace/Arg_Shifter.h"
2 #include "ace/Get_Opt.h"
7 //***************************************************************************
9 Event_AnyPushConsumer::Event_AnyPushConsumer (Simple_Test
*test_client
)
10 : test_client_ (test_client
)
15 Event_AnyPushConsumer::push (const CORBA::Any
& data
)
22 "Received event# %d\n",
25 this->test_client_
->on_event_received ();
28 //***************************************************************************
30 Event_AnyPushSupplier::Event_AnyPushSupplier (Simple_Test
* test_client
)
31 : test_client_ (test_client
)
35 Event_AnyPushSupplier::~Event_AnyPushSupplier ()
39 //***************************************************************************
41 Simple_Test::Simple_Test ()
46 Simple_Test::~Simple_Test ()
51 Simple_Test::init (int argc
,
54 // Initialized the base class.
55 Notify_Test_Client::init (argc
,
58 // Create all participents.
61 CosNotifyChannelAdmin::AdminID adminid
;
64 this->ec_
->new_for_suppliers (this->ifgop_
,
67 ACE_ASSERT (!CORBA::is_nil (supplier_admin_
.in ()));
70 this->ec_
->new_for_consumers (this->ifgop_
,
73 ACE_ASSERT (!CORBA::is_nil (consumer_admin_
.in ()));
75 ACE_NEW_RETURN (this->consumer_
,
76 Event_AnyPushConsumer (this),
78 this->consumer_
->init (root_poa_
.in ());
79 this->consumer_
->connect (this->consumer_admin_
.in ());
81 Event_AnyPushConsumer
* consumer2
;
82 ACE_NEW_RETURN (consumer2
,
83 Event_AnyPushConsumer (this),
85 consumer2
->init (root_poa_
.in ());
86 consumer2
->connect (this->consumer_admin_
.in ());
88 ACE_NEW_RETURN (this->supplier_
,
89 Event_AnyPushSupplier (this),
91 this->supplier_
->init (root_poa_
.in ());
93 this->supplier_
->connect (this->supplier_admin_
.in ());
101 Simple_Test::parse_args (int argc
,
104 ACE_Arg_Shifter
arg_shifter (argc
,
107 const ACE_TCHAR
*current_arg
= 0;
109 while (arg_shifter
.is_anything_left ())
111 if (0 != (current_arg
= arg_shifter
.get_the_parameter (ACE_TEXT("-events"))))
113 this->event_count_
= ACE_OS::atoi (current_arg
);
114 // The number of events to send/receive.
115 arg_shifter
.consume_arg ();
117 else if (arg_shifter
.cur_arg_strncasecmp (ACE_TEXT("-?")) == 0)
119 ACE_DEBUG ((LM_DEBUG
,
121 "-events event_count\n",
125 arg_shifter
.consume_arg ();
131 arg_shifter
.ignore_arg ();
138 Simple_Test::create_EC ()
140 CosNotifyChannelAdmin::ChannelID id
;
142 this->ec_
= notify_factory_
->create_channel (this->initial_qos_
,
143 this->initial_admin_
,
146 ACE_ASSERT (!CORBA::is_nil (ec_
.in ()));
150 Simple_Test::on_event_received ()
152 ++this->result_count_
;
155 ACE_DEBUG ((LM_DEBUG
,
156 "event count = #%d\n",
157 this->result_count_
.value ()));
159 if (this->result_count_
== 2 * this->event_count_
)
166 Simple_Test::run_test ()
170 for (int i
= 0; i
< this->event_count_
; ++i
)
172 data
<<= (CORBA::Long
)i
;
174 this->supplier_
->send_event (data
);
179 Simple_Test::end_test ()
185 Simple_Test::check_results ()
187 // Destroy the channel
188 this->ec_
->destroy ();
190 if (this->result_count_
== 2 * this->event_count_
)
192 ACE_DEBUG ((LM_DEBUG
,
193 "Events test success\n"));
198 ACE_DEBUG ((LM_DEBUG
,
199 "Events test failed!\n"));
204 //***************************************************************************
207 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
211 if (events
.parse_args (argc
, argv
) == -1)
225 catch (const CORBA::Exception
& se
)
227 se
._tao_print_exception ("Error: ");
235 status
= events
.check_results ();
237 catch (const CORBA::Exception
& se
)
239 se
._tao_print_exception ("Error: ");