1 // ******************************************************************
3 // ******************************************************************
5 #include "ace/Get_Opt.h"
6 #include "ace/Auto_Ptr.h"
7 #include "ace/Argv_Type_Converter.h"
9 #include "tao/ORB_Core.h"
11 #include "orbsvcs/CosNotifyChannelAdminS.h"
12 #include "orbsvcs/CosNotifyCommC.h"
13 #include "orbsvcs/CosNamingC.h"
14 #include "orbsvcs/TimeBaseC.h"
15 #include "Notify_SequencePushSupplier.h"
18 #include "Notify_Test_Client.h"
21 // ******************************************************************
23 // ******************************************************************
25 static TAO_Notify_Tests_SequencePushSupplier
* supplier_1
= 0;
26 static const ACE_TCHAR
* ior_output_file
= ACE_TEXT ("supplier.ior");
28 // ******************************************************************
30 // ******************************************************************
32 // The supplier will not start sending events until the
33 // go() operation is invoked.
34 class sig_i
: public POA_sig
37 sig_i (CORBA::ORB_ptr orb
)
53 void wait_for_startup ()
57 ACE_Time_Value
tv (0, 100 * 1000); // 100ms
62 void wait_for_completion ()
66 ACE_Time_Value
tv (0, 100 * 1000); // 100ms
76 class Supplier_Client
: public Notify_Test_Client
79 virtual int parse_args (int argc
, ACE_TCHAR
* argv
[]);
84 Supplier_Client::parse_args (int argc
, ACE_TCHAR
*argv
[])
86 ACE_Argv_Type_Converter
argcon (argc
, argv
);
87 ACE_Get_Opt
get_opts (argcon
.get_argc (),
88 argcon
.get_TCHAR_argv (), ACE_TEXT ("o:"));
91 while ((c
= get_opts ()) != -1)
95 ior_output_file
= get_opts
.optarg
;
99 ACE_ERROR_RETURN ((LM_ERROR
,
107 // Indicates successful parsing of the command line
112 static CosNotifyChannelAdmin::SupplierAdmin_ptr
113 create_supplieradmin (CosNotifyChannelAdmin::EventChannel_ptr ec
)
115 CosNotifyChannelAdmin::AdminID adminid
= 0;
116 CosNotifyChannelAdmin::SupplierAdmin_var admin
=
117 ec
->new_for_suppliers (CosNotifyChannelAdmin::AND_OP
,
121 return CosNotifyChannelAdmin::SupplierAdmin::_duplicate (admin
.in ());
126 create_suppliers (CosNotifyChannelAdmin::SupplierAdmin_ptr admin
,
127 PortableServer::POA_ptr poa
)
129 ACE_NEW_THROW_EX (supplier_1
,
130 TAO_Notify_Tests_SequencePushSupplier (),
131 CORBA::NO_MEMORY ());
133 supplier_1
->init (poa
);
135 supplier_1
->connect (admin
);
139 // ******************************************************************
141 // ******************************************************************
144 ACE_TMAIN (int argc
, ACE_TCHAR
* argv
[])
147 ACE_Auto_Ptr
<sig_i
> sig_impl
;
150 Supplier_Client client
;
151 ACE_Argv_Type_Converter
argcon (argc
, argv
);
152 status
= client
.init (argcon
.get_argc (), argcon
.get_TCHAR_argv ());
156 CosNotifyChannelAdmin::EventChannel_var ec
=
157 client
.create_event_channel ("MyEventChannel", 0);
159 sig_impl
.reset (new sig_i (client
.orb ()));
160 sig_var sig
= sig_impl
->_this ();
162 // If the ior_output_file exists, output the ior to it
163 if (ior_output_file
!= 0)
165 CORBA::String_var ior
=
166 client
.orb ()->object_to_string (sig
.in ());
168 FILE *output_file
= ACE_OS::fopen (ior_output_file
, ACE_TEXT ("w"));
169 ACE_ASSERT (output_file
!= 0);
170 ACE_OS::fprintf (output_file
, "%s", ior
.in ());
171 ACE_OS::fclose (output_file
);
174 CosNotifyChannelAdmin::SupplierAdmin_var admin
=
175 create_supplieradmin (ec
.in ());
176 ACE_ASSERT (!CORBA::is_nil (admin
.in ()));
178 create_suppliers (admin
.in (), client
.root_poa ());
180 sig_impl
->wait_for_startup ();
182 // If this is changed, you should update max_events
183 // found in Notify_Push_Consumer.cpp
185 int num_events
= 80 / batch_size
;
186 ACE_DEBUG ((LM_DEBUG
,
187 "1 supplier sending %d batches of %d events...\n",
188 num_events
, batch_size
));
189 CosNotification::EventBatch events
;
190 events
.length(batch_size
);
191 for (int i
= 0; i
< num_events
; ++i
)
193 supplier_1
->send_events (events
);
195 ACE_DEBUG ((LM_DEBUG
, "\nSupplier sent %d events.\n", num_events
));
197 sig_impl
->wait_for_completion ();
199 ACE_OS::unlink (ior_output_file
);
201 supplier_1
->disconnect ();
206 catch (const CORBA::Exception
& e
)
208 e
._tao_print_exception ("Error: ");