1 #include "ace/Arg_Shifter.h"
2 #include "ace/Get_Opt.h"
4 #include "ConnectDisconnect.h"
7 #define CD_IMPLEMENT_ENTITY(X)\
9 CD_##X::CD_##X (ConnectDisconnect* cd, int id) \
14 CD_Entity::CD_Entity (ConnectDisconnect
* cd
, int id
)
20 CD_Entity::~CD_Entity ()
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 ()
42 structured_consumer_ (0),
43 sequence_consumer_ (0),
45 structured_supplier_ (0),
46 sequence_supplier_ (0),
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_
;
65 ConnectDisconnect::on_entity_destroyed ()
67 this->result_count_
++;
71 "result_count = %d\n",
72 this->result_count_
.value ()));
76 ConnectDisconnect::init (int argc
,
79 // Initialize the base class.
80 Notify_Test_Client::init (argc
,
83 // Create all participants.
86 CosNotifyChannelAdmin::AdminID adminid
;
88 this->supplier_admin_
=
89 ec_
->new_for_suppliers (this->ifgop_
,
92 ACE_ASSERT (!CORBA::is_nil (supplier_admin_
.in ()));
94 this->consumer_admin_
=
95 ec_
->new_for_consumers (this->ifgop_
,
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_
],
109 ACE_NEW_RETURN (this->structured_consumer_
,
110 TAO_Notify_Tests_StructuredPushConsumer
*[this->consumers_
],
112 ACE_NEW_RETURN (this->sequence_consumer_
,
113 TAO_Notify_Tests_SequencePushConsumer
*[this->consumers_
],
116 // Arrays of Suppliers.
117 ACE_NEW_RETURN (this->any_supplier_
,
118 TAO_Notify_Tests_PushSupplier
*[this->suppliers_
],
120 ACE_NEW_RETURN (this->structured_supplier_
,
121 TAO_Notify_Tests_StructuredPushSupplier
*[this->suppliers_
],
123 ACE_NEW_RETURN (this->sequence_supplier_
,
124 TAO_Notify_Tests_SequencePushSupplier
*[this->suppliers_
],
132 ConnectDisconnect::parse_args(int argc
, ACE_TCHAR
*argv
[])
134 ACE_Arg_Shifter
arg_shifter (argc
,
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)
161 "-consumers number_of_consumers"
162 "-suppliers number_of_suppliers",
166 arg_shifter
.consume_arg ();
172 arg_shifter
.ignore_arg ();
180 ConnectDisconnect::create_EC ()
182 CosNotifyChannelAdmin::ChannelID id
;
184 this->ec_
= notify_factory_
->create_channel (this->initial_qos_
,
185 this->initial_admin_
,
188 ACE_ASSERT (!CORBA::is_nil (ec_
.in ()));
192 ConnectDisconnect::run_test ()
194 for (int iterations
= 0; iterations
< count_
; ++iterations
)
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,
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,
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,
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,
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,
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,
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 ();
272 ConnectDisconnect::end_test ()
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"));
289 ACE_DEBUG ((LM_DEBUG
, "ConnectDisconnect test succeeded\n"));
292 // Destroy the channel.
293 this->ec_
->destroy ();
298 /***************************************************************************/
301 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
303 ConnectDisconnect client
;
305 if (client
.parse_args (argc
, argv
) == -1)
312 client
.init (argc
, argv
);
318 catch (const CORBA::Exception
& se
)
320 se
._tao_print_exception ("Error: ");
328 status
= client
.check_results ();
330 catch (const CORBA::Exception
& se
)
332 se
._tao_print_exception ("Error: ");