Merge pull request #1551 from DOCGroup/plm_jira_333
[ACE_TAO.git] / TAO / orbsvcs / tests / Notify / Basic / Simple.cpp
blobddd0ad8f9ac62fe06cefe21689eb8208b603b6b6
1 #include "ace/Arg_Shifter.h"
2 #include "ace/Get_Opt.h"
3 #include "tao/debug.h"
4 #include "Simple.h"
8 //***************************************************************************
10 Event_AnyPushConsumer::Event_AnyPushConsumer (Simple_Test *test_client)
11 : test_client_ (test_client)
15 void
16 Event_AnyPushConsumer::push (const CORBA::Any & data)
18 int event_num;
19 data >>= event_num;
21 if (TAO_debug_level)
22 ACE_DEBUG ((LM_DEBUG,
23 "Received event# %d\n",
24 event_num));
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)
43 : event_count_ (5)
47 Simple_Test::~Simple_Test (void)
51 int
52 Simple_Test::init (int argc,
53 ACE_TCHAR* argv [])
55 // Initialized the base class.
56 Notify_Test_Client::init (argc,
57 argv);
59 // Create all participents.
60 this->create_EC ();
62 CosNotifyChannelAdmin::AdminID adminid;
64 supplier_admin_ =
65 this->ec_->new_for_suppliers (this->ifgop_,
66 adminid);
68 ACE_ASSERT (!CORBA::is_nil (supplier_admin_.in ()));
70 consumer_admin_ =
71 this->ec_->new_for_consumers (this->ifgop_,
72 adminid);
74 ACE_ASSERT (!CORBA::is_nil (consumer_admin_.in ()));
76 ACE_NEW_RETURN (this->consumer_,
77 Event_AnyPushConsumer (this),
78 -1);
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),
85 -1);
86 consumer2->init (root_poa_.in ());
87 consumer2->connect (this->consumer_admin_.in ());
89 ACE_NEW_RETURN (this->supplier_,
90 Event_AnyPushSupplier (this),
91 -1);
92 this->supplier_->init (root_poa_.in ());
94 this->supplier_->connect (this->supplier_admin_.in ());
96 consumer_start( 0 );
98 return 0;
102 Simple_Test::parse_args (int argc,
103 ACE_TCHAR *argv[])
105 ACE_Arg_Shifter arg_shifter (argc,
106 argv);
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,
121 "usage: %s "
122 "-events event_count\n",
123 argv[0],
124 argv[0]));
126 arg_shifter.consume_arg ();
128 return -1;
130 else
132 arg_shifter.ignore_arg ();
135 return 0;
138 void
139 Simple_Test::create_EC (void)
141 CosNotifyChannelAdmin::ChannelID id;
143 this->ec_ = notify_factory_->create_channel (this->initial_qos_,
144 this->initial_admin_,
145 id);
147 ACE_ASSERT (!CORBA::is_nil (ec_.in ()));
150 void
151 Simple_Test::on_event_received (void)
153 ++this->result_count_;
155 if (TAO_debug_level)
156 ACE_DEBUG ((LM_DEBUG,
157 "event count = #%d\n",
158 this->result_count_.value ()));
160 if (this->result_count_ == 2 * this->event_count_)
162 this->end_test ();
166 void
167 Simple_Test::run_test (void)
169 CORBA::Any data;
171 for (int i = 0; i < this->event_count_; ++i)
173 data <<= (CORBA::Long)i;
175 this->supplier_->send_event (data);
179 void
180 Simple_Test::end_test (void)
182 consumer_done( 0 );
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"));
195 return 0;
197 else
199 ACE_DEBUG ((LM_DEBUG,
200 "Events test failed!\n"));
201 return 1;
205 //***************************************************************************
208 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
210 Simple_Test events;
212 if (events.parse_args (argc, argv) == -1)
214 return 1;
219 events.init (argc,
220 argv);
222 events.run_test ();
224 events.ORB_run( );
226 catch (const CORBA::Exception& se)
228 se._tao_print_exception ("Error: ");
229 return 1;
232 int status = 0;
236 status = events.check_results ();
238 catch (const CORBA::Exception& se)
240 se._tao_print_exception ("Error: ");
241 status = 1;
244 return status;