Changes to attempt to silence bcc64x
[ACE_TAO.git] / TAO / orbsvcs / tests / Notify / Basic / ConnectDisconnect.cpp
blob84eb77280601ec49f8a6135e3ed5c65691a4d7fb
1 #include "ace/Arg_Shifter.h"
2 #include "ace/Get_Opt.h"
3 #include "tao/debug.h"
4 #include "ConnectDisconnect.h"
7 #define CD_IMPLEMENT_ENTITY(X)\
9 CD_##X::CD_##X (ConnectDisconnect* cd, int id) \
10 :CD_Entity (cd, id) \
11 { \
14 CD_Entity::CD_Entity (ConnectDisconnect* cd, int id)
15 :id_ (id),
16 cd_ (cd)
20 CD_Entity::~CD_Entity ()
22 if (TAO_debug_level)
24 ACE_DEBUG ((LM_DEBUG, "Entity #%d destroyed\n", this->id_));
27 cd_->on_entity_destroyed ();
30 CD_IMPLEMENT_ENTITY(PushConsumer)
31 CD_IMPLEMENT_ENTITY(StructuredPushConsumer)
32 CD_IMPLEMENT_ENTITY(SequencePushConsumer)
34 CD_IMPLEMENT_ENTITY(PushSupplier)
35 CD_IMPLEMENT_ENTITY(StructuredPushSupplier)
36 CD_IMPLEMENT_ENTITY(SequencePushSupplier)
38 //*****************************************************************************************************
40 ConnectDisconnect::ConnectDisconnect ()
41 :any_consumer_ (0),
42 structured_consumer_ (0),
43 sequence_consumer_ (0),
44 any_supplier_ (0),
45 structured_supplier_ (0),
46 sequence_supplier_ (0),
47 count_ (3),
48 consumers_ (3),
49 suppliers_ (3)
53 ConnectDisconnect::~ConnectDisconnect ()
55 delete [] this->any_consumer_;
56 delete [] this->structured_consumer_;
57 delete [] this->sequence_consumer_;
59 delete [] this->any_supplier_;
60 delete [] this->structured_supplier_;
61 delete [] this->sequence_supplier_;
64 void
65 ConnectDisconnect::on_entity_destroyed ()
67 this->result_count_++;
69 if (TAO_debug_level)
70 ACE_DEBUG ((LM_DEBUG,
71 "result_count = %d\n",
72 this->result_count_.value ()));
75 int
76 ConnectDisconnect::init (int argc,
77 ACE_TCHAR* argv [])
79 // Initialize the base class.
80 Notify_Test_Client::init (argc,
81 argv);
83 // Create all participants.
84 this->create_EC ();
86 CosNotifyChannelAdmin::AdminID adminid;
88 this->supplier_admin_ =
89 ec_->new_for_suppliers (this->ifgop_,
90 adminid);
92 ACE_ASSERT (!CORBA::is_nil (supplier_admin_.in ()));
94 this->consumer_admin_ =
95 ec_->new_for_consumers (this->ifgop_,
96 adminid);
98 ACE_ASSERT (!CORBA::is_nil (consumer_admin_.in ()));
100 // How many are we counting..?
101 this->expected_count_ = count_ * (consumers_ * 3 + suppliers_ * 3);
103 // Create the consumers and suppliers.
105 // Arrays of Consumers.
106 ACE_NEW_RETURN (this->any_consumer_,
107 TAO_Notify_Tests_PushConsumer*[this->consumers_],
108 -1);
109 ACE_NEW_RETURN (this->structured_consumer_,
110 TAO_Notify_Tests_StructuredPushConsumer*[this->consumers_],
111 -1);
112 ACE_NEW_RETURN (this->sequence_consumer_,
113 TAO_Notify_Tests_SequencePushConsumer*[this->consumers_],
114 -1);
116 // Arrays of Suppliers.
117 ACE_NEW_RETURN (this->any_supplier_,
118 TAO_Notify_Tests_PushSupplier*[this->suppliers_],
119 -1);
120 ACE_NEW_RETURN (this->structured_supplier_,
121 TAO_Notify_Tests_StructuredPushSupplier*[this->suppliers_],
122 -1);
123 ACE_NEW_RETURN (this->sequence_supplier_,
124 TAO_Notify_Tests_SequencePushSupplier*[this->suppliers_],
125 -1);
127 consumer_start(0);
128 return 0;
132 ConnectDisconnect::parse_args(int argc, ACE_TCHAR *argv[])
134 ACE_Arg_Shifter arg_shifter (argc,
135 argv);
137 const ACE_TCHAR *current_arg = 0;
139 while (arg_shifter.is_anything_left ())
141 if (0 != (current_arg = arg_shifter.get_the_parameter (ACE_TEXT("-count"))))
143 this->count_ = ACE_OS::atoi (current_arg);
144 arg_shifter.consume_arg ();
146 else if (0 != (current_arg = arg_shifter.get_the_parameter (ACE_TEXT("-consumers"))))
148 this->consumers_ = ACE_OS::atoi (current_arg);
149 arg_shifter.consume_arg ();
151 else if (0 != (current_arg = arg_shifter.get_the_parameter (ACE_TEXT("-suppliers"))))
153 this->suppliers_ = ACE_OS::atoi (current_arg);
154 arg_shifter.consume_arg ();
156 else if (arg_shifter.cur_arg_strncasecmp (ACE_TEXT("-?")) == 0)
158 ACE_DEBUG((LM_DEBUG,
159 "usage: %s "
160 "-count testcount\n"
161 "-consumers number_of_consumers"
162 "-suppliers number_of_suppliers",
163 argv[0],
164 argv[0]));
166 arg_shifter.consume_arg ();
168 return -1;
170 else
172 arg_shifter.ignore_arg ();
176 return 0;
179 void
180 ConnectDisconnect::create_EC ()
182 CosNotifyChannelAdmin::ChannelID id;
184 this->ec_ = notify_factory_->create_channel (this->initial_qos_,
185 this->initial_admin_,
186 id);
188 ACE_ASSERT (!CORBA::is_nil (ec_.in ()));
191 void
192 ConnectDisconnect::run_test ()
194 for (int iterations = 0; iterations < count_; ++iterations)
196 int i = 0;
198 for (i = 0; i < this->consumers_; ++i)
200 // Create and connect Any consumers.
201 ACE_NEW (this->any_consumer_[i],
202 CD_PushConsumer (this,
203 i));
204 this->any_consumer_[i]->init (root_poa_.in ());
205 this->any_consumer_[i]->connect (this->consumer_admin_.in ());
207 // Create and connect Structured consumers.
208 ACE_NEW (this->structured_consumer_[i],
209 CD_StructuredPushConsumer (this,
210 i));
211 this->structured_consumer_[i]->init (root_poa_.in ());
212 this->structured_consumer_[i]->connect (this->consumer_admin_.in ());
214 // Create and connect Sequence consumers.
215 ACE_NEW (this->sequence_consumer_[i],
216 CD_SequencePushConsumer (this,
217 i));
218 this->sequence_consumer_[i]->init (root_poa_.in ());
219 this->sequence_consumer_[i]->connect (this->consumer_admin_.in ());
222 for (i = 0; i < this->suppliers_; ++i)
224 ACE_NEW (this->any_supplier_[i],
225 CD_PushSupplier (this,
226 i));
227 this->any_supplier_[i]->init (root_poa_.in ());
228 this->any_supplier_[i]->connect (this->supplier_admin_.in ());
230 // Create and connect Structured suppliers.
231 ACE_NEW (this->structured_supplier_[i],
232 CD_StructuredPushSupplier (this,
233 i));
234 this->structured_supplier_[i]->init (root_poa_.in ());
235 this->structured_supplier_[i]->connect (this->supplier_admin_.in ());
237 // Create and connect Sequence suppliers.
238 ACE_NEW (this->sequence_supplier_[i],
239 CD_SequencePushSupplier (this,
240 i));
241 this->sequence_supplier_[i]->init (root_poa_.in ());
242 this->sequence_supplier_[i]->connect (this->supplier_admin_.in ());
245 for (i = 0; i < this->consumers_; ++i)
247 // Disconnnect Any consumers.
248 this->any_consumer_[i]->disconnect ();
250 // Disconnect Structured Consumers.
251 this->structured_consumer_[i]->disconnect ();
253 // Disconnect Sequence Consumers.
254 this->sequence_consumer_[i]->disconnect ();
257 for (i = 0; i < this->suppliers_; ++i)
259 // Disconnnect Any suppliers.
260 this->any_supplier_[i]->disconnect ();
262 // Disconnect Structured Suppliers.
263 this->structured_supplier_[i]->disconnect ();
265 // Disconnect Sequence Suppliers.
266 this->sequence_supplier_[i]->disconnect ();
271 void
272 ConnectDisconnect::end_test ()
274 consumer_done(0);
278 ConnectDisconnect::check_results ()
280 ACE_DEBUG ((LM_DEBUG, "result_count_ = %d", this->result_count_.value ()));
281 ACE_DEBUG ((LM_DEBUG, " expected_count_ = %d\n", this->expected_count_));
283 if (this->result_count_ != this->expected_count_)
285 ACE_DEBUG ((LM_DEBUG, "ConnectDisconnect test failed\n"));
287 else
289 ACE_DEBUG ((LM_DEBUG, "ConnectDisconnect test succeeded\n"));
292 // Destroy the channel.
293 this->ec_->destroy ();
295 return 0;
298 /***************************************************************************/
301 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
303 ConnectDisconnect client;
305 if (client.parse_args (argc, argv) == -1)
307 return 1;
312 client.init (argc, argv);
314 client.run_test ();
316 client.end_test ();
318 catch (const CORBA::Exception& se)
320 se._tao_print_exception ("Error: ");
321 return 1;
324 int status = 0;
328 status = client.check_results ();
330 catch (const CORBA::Exception& se)
332 se._tao_print_exception ("Error: ");
333 status = 1;
336 return status;