1 // ******************************************************************
3 // ******************************************************************
5 #include "ace/Get_Opt.h"
6 #include "ace/Argv_Type_Converter.h"
8 #include "tao/ORB_Core.h"
10 #include "orbsvcs/CosNotifyChannelAdminS.h"
11 #include "orbsvcs/CosNotifyCommC.h"
12 #include "orbsvcs/CosNamingC.h"
13 #include "orbsvcs/TimeBaseC.h"
14 #include "Notify_SequencePushSupplier.h"
17 #include "Notify_Test_Client.h"
20 // ******************************************************************
22 // ******************************************************************
24 static TAO_Notify_Tests_SequencePushSupplier
* supplier_1
= 0;
25 static const ACE_TCHAR
* ior_output_file
= ACE_TEXT ("supplier.ior");
27 // ******************************************************************
29 // ******************************************************************
31 // The supplier will not start sending events until the
32 // go() operation is invoked.
33 class sig_i
: public POA_sig
36 sig_i (CORBA::ORB_ptr orb
)
52 void wait_for_startup ()
56 ACE_Time_Value
tv (0, 100 * 1000); // 100ms
61 void wait_for_completion ()
65 ACE_Time_Value
tv (0, 100 * 1000); // 100ms
75 class Supplier_Client
: public Notify_Test_Client
78 virtual int parse_args (int argc
, ACE_TCHAR
* argv
[]);
83 Supplier_Client::parse_args (int argc
, ACE_TCHAR
*argv
[])
85 ACE_Argv_Type_Converter
argcon (argc
, argv
);
86 ACE_Get_Opt
get_opts (argcon
.get_argc (),
87 argcon
.get_TCHAR_argv (), ACE_TEXT ("o:"));
90 while ((c
= get_opts ()) != -1)
94 ior_output_file
= get_opts
.optarg
;
98 ACE_ERROR_RETURN ((LM_ERROR
,
106 // Indicates successful parsing of the command line
111 static CosNotifyChannelAdmin::SupplierAdmin_ptr
112 create_supplieradmin (CosNotifyChannelAdmin::EventChannel_ptr ec
)
114 CosNotifyChannelAdmin::AdminID adminid
= 0;
115 CosNotifyChannelAdmin::SupplierAdmin_var admin
=
116 ec
->new_for_suppliers (CosNotifyChannelAdmin::AND_OP
,
120 return CosNotifyChannelAdmin::SupplierAdmin::_duplicate (admin
.in ());
125 create_suppliers (CosNotifyChannelAdmin::SupplierAdmin_ptr admin
,
126 PortableServer::POA_ptr poa
)
128 ACE_NEW_THROW_EX (supplier_1
,
129 TAO_Notify_Tests_SequencePushSupplier (),
130 CORBA::NO_MEMORY ());
132 supplier_1
->init (poa
);
134 supplier_1
->connect (admin
);
138 // ******************************************************************
140 // ******************************************************************
143 ACE_TMAIN (int argc
, ACE_TCHAR
* argv
[])
146 std::unique_ptr
<sig_i
> sig_impl
;
149 Supplier_Client client
;
150 ACE_Argv_Type_Converter
argcon (argc
, argv
);
151 status
= client
.init (argcon
.get_argc (), argcon
.get_TCHAR_argv ());
155 CosNotifyChannelAdmin::EventChannel_var ec
=
156 client
.create_event_channel ("MyEventChannel", 0);
158 sig_impl
.reset (new sig_i (client
.orb ()));
159 sig_var sig
= sig_impl
->_this ();
161 // If the ior_output_file exists, output the ior to it
162 if (ior_output_file
!= 0)
164 CORBA::String_var ior
=
165 client
.orb ()->object_to_string (sig
.in ());
167 FILE *output_file
= ACE_OS::fopen (ior_output_file
, ACE_TEXT ("w"));
168 ACE_ASSERT (output_file
!= 0);
169 ACE_OS::fprintf (output_file
, "%s", ior
.in ());
170 ACE_OS::fclose (output_file
);
173 CosNotifyChannelAdmin::SupplierAdmin_var admin
=
174 create_supplieradmin (ec
.in ());
175 ACE_ASSERT (!CORBA::is_nil (admin
.in ()));
177 create_suppliers (admin
.in (), client
.root_poa ());
179 sig_impl
->wait_for_startup ();
181 // If this is changed, you should update max_events
182 // found in Notify_Push_Consumer.cpp
184 int num_events
= 80 / batch_size
;
185 ACE_DEBUG ((LM_DEBUG
,
186 "1 supplier sending %d batches of %d events...\n",
187 num_events
, batch_size
));
188 CosNotification::EventBatch events
;
189 events
.length(batch_size
);
190 for (int i
= 0; i
< num_events
; ++i
)
192 supplier_1
->send_events (events
);
194 ACE_DEBUG ((LM_DEBUG
, "\nSupplier sent %d events.\n", num_events
));
196 sig_impl
->wait_for_completion ();
198 ACE_OS::unlink (ior_output_file
);
200 supplier_1
->disconnect ();
205 catch (const CORBA::Exception
& e
)
207 e
._tao_print_exception ("Error: ");