Changes to attempt to silence bcc64x
[ACE_TAO.git] / TAO / orbsvcs / tests / Notify / Basic / Simple.cpp
blob81c53e7c4fd186bc97b6e1a0ad86159810a2186e
1 #include "ace/Arg_Shifter.h"
2 #include "ace/Get_Opt.h"
3 #include "tao/debug.h"
4 #include "Simple.h"
7 //***************************************************************************
9 Event_AnyPushConsumer::Event_AnyPushConsumer (Simple_Test *test_client)
10 : test_client_ (test_client)
14 void
15 Event_AnyPushConsumer::push (const CORBA::Any & data)
17 int event_num;
18 data >>= event_num;
20 if (TAO_debug_level)
21 ACE_DEBUG ((LM_DEBUG,
22 "Received event# %d\n",
23 event_num));
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 ()
42 : event_count_ (5)
46 Simple_Test::~Simple_Test ()
50 int
51 Simple_Test::init (int argc,
52 ACE_TCHAR* argv [])
54 // Initialized the base class.
55 Notify_Test_Client::init (argc,
56 argv);
58 // Create all participents.
59 this->create_EC ();
61 CosNotifyChannelAdmin::AdminID adminid;
63 supplier_admin_ =
64 this->ec_->new_for_suppliers (this->ifgop_,
65 adminid);
67 ACE_ASSERT (!CORBA::is_nil (supplier_admin_.in ()));
69 consumer_admin_ =
70 this->ec_->new_for_consumers (this->ifgop_,
71 adminid);
73 ACE_ASSERT (!CORBA::is_nil (consumer_admin_.in ()));
75 ACE_NEW_RETURN (this->consumer_,
76 Event_AnyPushConsumer (this),
77 -1);
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),
84 -1);
85 consumer2->init (root_poa_.in ());
86 consumer2->connect (this->consumer_admin_.in ());
88 ACE_NEW_RETURN (this->supplier_,
89 Event_AnyPushSupplier (this),
90 -1);
91 this->supplier_->init (root_poa_.in ());
93 this->supplier_->connect (this->supplier_admin_.in ());
95 consumer_start(0);
97 return 0;
101 Simple_Test::parse_args (int argc,
102 ACE_TCHAR *argv[])
104 ACE_Arg_Shifter arg_shifter (argc,
105 argv);
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,
120 "usage: %s "
121 "-events event_count\n",
122 argv[0],
123 argv[0]));
125 arg_shifter.consume_arg ();
127 return -1;
129 else
131 arg_shifter.ignore_arg ();
134 return 0;
137 void
138 Simple_Test::create_EC ()
140 CosNotifyChannelAdmin::ChannelID id;
142 this->ec_ = notify_factory_->create_channel (this->initial_qos_,
143 this->initial_admin_,
144 id);
146 ACE_ASSERT (!CORBA::is_nil (ec_.in ()));
149 void
150 Simple_Test::on_event_received ()
152 ++this->result_count_;
154 if (TAO_debug_level)
155 ACE_DEBUG ((LM_DEBUG,
156 "event count = #%d\n",
157 this->result_count_.value ()));
159 if (this->result_count_ == 2 * this->event_count_)
161 this->end_test ();
165 void
166 Simple_Test::run_test ()
168 CORBA::Any data;
170 for (int i = 0; i < this->event_count_; ++i)
172 data <<= (CORBA::Long)i;
174 this->supplier_->send_event (data);
178 void
179 Simple_Test::end_test ()
181 consumer_done(0);
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"));
194 return 0;
196 else
198 ACE_DEBUG ((LM_DEBUG,
199 "Events test failed!\n"));
200 return 1;
204 //***************************************************************************
207 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
209 Simple_Test events;
211 if (events.parse_args (argc, argv) == -1)
213 return 1;
218 events.init (argc,
219 argv);
221 events.run_test ();
223 events.ORB_run();
225 catch (const CORBA::Exception& se)
227 se._tao_print_exception ("Error: ");
228 return 1;
231 int status = 0;
235 status = events.check_results ();
237 catch (const CORBA::Exception& se)
239 se._tao_print_exception ("Error: ");
240 status = 1;
243 return status;