1 #include "ace/Arg_Shifter.h"
2 #include "ace/Get_Opt.h"
8 //***************************************************************************
10 Event_AnyPushConsumer::Event_AnyPushConsumer (Simple_Test
*test_client
)
11 : test_client_ (test_client
)
16 Event_AnyPushConsumer::push (const CORBA::Any
& data
)
23 "Received event# %d\n",
26 this->test_client_
->on_event_received ();
29 //***************************************************************************
31 Event_AnyPushSupplier::Event_AnyPushSupplier (Simple_Test
* test_client
)
32 : test_client_ (test_client
)
36 Event_AnyPushSupplier::~Event_AnyPushSupplier (void)
40 //***************************************************************************
42 Simple_Test::Simple_Test (void)
47 Simple_Test::~Simple_Test (void)
52 Simple_Test::init (int argc
,
55 // Initialized the base class.
56 Notify_Test_Client::init (argc
,
59 // Create all participents.
62 CosNotifyChannelAdmin::AdminID adminid
;
65 this->ec_
->new_for_suppliers (this->ifgop_
,
68 ACE_ASSERT (!CORBA::is_nil (supplier_admin_
.in ()));
71 this->ec_
->new_for_consumers (this->ifgop_
,
74 ACE_ASSERT (!CORBA::is_nil (consumer_admin_
.in ()));
76 ACE_NEW_RETURN (this->consumer_
,
77 Event_AnyPushConsumer (this),
79 this->consumer_
->init (root_poa_
.in ());
80 this->consumer_
->connect (this->consumer_admin_
.in ());
82 Event_AnyPushConsumer
* consumer2
;
83 ACE_NEW_RETURN (consumer2
,
84 Event_AnyPushConsumer (this),
86 consumer2
->init (root_poa_
.in ());
87 consumer2
->connect (this->consumer_admin_
.in ());
89 ACE_NEW_RETURN (this->supplier_
,
90 Event_AnyPushSupplier (this),
92 this->supplier_
->init (root_poa_
.in ());
94 this->supplier_
->connect (this->supplier_admin_
.in ());
102 Simple_Test::parse_args (int argc
,
105 ACE_Arg_Shifter
arg_shifter (argc
,
108 const ACE_TCHAR
*current_arg
= 0;
110 while (arg_shifter
.is_anything_left ())
112 if (0 != (current_arg
= arg_shifter
.get_the_parameter (ACE_TEXT("-events"))))
114 this->event_count_
= ACE_OS::atoi (current_arg
);
115 // The number of events to send/receive.
116 arg_shifter
.consume_arg ();
118 else if (arg_shifter
.cur_arg_strncasecmp (ACE_TEXT("-?")) == 0)
120 ACE_DEBUG ((LM_DEBUG
,
122 "-events event_count\n",
126 arg_shifter
.consume_arg ();
132 arg_shifter
.ignore_arg ();
139 Simple_Test::create_EC (void)
141 CosNotifyChannelAdmin::ChannelID id
;
143 this->ec_
= notify_factory_
->create_channel (this->initial_qos_
,
144 this->initial_admin_
,
147 ACE_ASSERT (!CORBA::is_nil (ec_
.in ()));
151 Simple_Test::on_event_received (void)
153 ++this->result_count_
;
156 ACE_DEBUG ((LM_DEBUG
,
157 "event count = #%d\n",
158 this->result_count_
.value ()));
160 if (this->result_count_
== 2 * this->event_count_
)
167 Simple_Test::run_test (void)
171 for (int i
= 0; i
< this->event_count_
; ++i
)
173 data
<<= (CORBA::Long
)i
;
175 this->supplier_
->send_event (data
);
180 Simple_Test::end_test (void)
186 Simple_Test::check_results (void)
188 // Destroy the channel
189 this->ec_
->destroy ();
191 if (this->result_count_
== 2 * this->event_count_
)
193 ACE_DEBUG ((LM_DEBUG
,
194 "Events test success\n"));
199 ACE_DEBUG ((LM_DEBUG
,
200 "Events test failed!\n"));
205 //***************************************************************************
208 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
212 if (events
.parse_args (argc
, argv
) == -1)
226 catch (const CORBA::Exception
& se
)
228 se
._tao_print_exception ("Error: ");
236 status
= events
.check_results ();
238 catch (const CORBA::Exception
& se
)
240 se
._tao_print_exception ("Error: ");