1 // ******************************************************************
3 // ******************************************************************
5 #include "ace/Get_Opt.h"
7 #include "tao/ORB_Core.h"
9 #include "orbsvcs/CosNotifyChannelAdminS.h"
10 #include "orbsvcs/CosNotifyCommC.h"
11 #include "orbsvcs/CosNamingC.h"
12 #include "Notify_StructuredPushSupplier.h"
15 #include "Notify_Test_Client.h"
17 #include "ace/OS_NS_unistd.h"
20 // ******************************************************************
22 // ******************************************************************
24 static const unsigned int supplier_max
= 32;
25 static TAO_Notify_Tests_StructuredPushSupplier
* suppliers
[supplier_max
] = {0};
26 static unsigned int supplier_count
= 1;
27 static int event_count
= 1;
28 static const ACE_TCHAR
*ior_output_file
= ACE_TEXT ("supplier.ior");
30 // ******************************************************************
32 // ******************************************************************
33 class sig_i
: public POA_sig
36 sig_i(CORBA::ORB_ptr orb
)
52 void wait_for_startup()
55 ACE_Time_Value
tv(0, 100 * 1000); // 100ms
60 void wait_for_completion()
63 ACE_Time_Value
tv(0, 100 * 1000); // 100ms
73 class Consumer_Client
: public Notify_Test_Client
76 virtual int parse_args (int argc
, ACE_TCHAR
*argv
[]);
81 Consumer_Client::parse_args (int argc
, ACE_TCHAR
*argv
[])
83 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("o:e:fc:"));
86 while ((c
= get_opts ()) != -1)
90 supplier_count
= ACE_OS::atoi (get_opts
.optarg
);
91 if (supplier_count
> supplier_max
)
93 supplier_count
= supplier_max
;
98 event_count
= ACE_OS::atoi (get_opts
.optarg
);
102 ior_output_file
= get_opts
.optarg
;
106 ACE_ERROR_RETURN ((LM_ERROR
,
108 "-o <iorfile> -e <# of events>"
114 // Indicates successful parsing of the command line
119 static CosNotifyChannelAdmin::SupplierAdmin_ptr
120 create_supplieradmin (CosNotifyChannelAdmin::EventChannel_ptr ec
)
122 CosNotifyChannelAdmin::AdminID adminid
= 0;
123 CosNotifyChannelAdmin::SupplierAdmin_var admin
=
124 ec
->new_for_suppliers (CosNotifyChannelAdmin::AND_OP
,
128 return CosNotifyChannelAdmin::SupplierAdmin::_duplicate (admin
.in ());
136 CosNotification::StructuredEvent event
;
138 event
.header
.fixed_header
.event_type
.domain_name
= CORBA::string_dup ("a");
139 event
.header
.fixed_header
.event_type
.type_name
= CORBA::string_dup ("b");
140 event
.header
.fixed_header
.event_name
= CORBA::string_dup ("test");
144 for (unsigned int i
= 0; i
< supplier_count
; i
++)
146 suppliers
[i
]->send_event (event
);
149 catch (const CORBA::Exception
& e
)
151 e
._tao_print_exception ("Error: ");
156 create_suppliers (CosNotifyChannelAdmin::SupplierAdmin_ptr admin
,
157 Notify_Test_Client
* client
)
159 for (unsigned int i
= 0; i
< supplier_count
; i
++)
161 ACE_NEW_THROW_EX (suppliers
[i
],
162 TAO_Notify_Tests_StructuredPushSupplier (),
163 CORBA::NO_MEMORY ());
165 suppliers
[i
]->init (client
->root_poa ());
167 suppliers
[i
]->connect (admin
);
172 disconnect_suppliers ()
174 for (unsigned int i
= 0; i
< supplier_count
; ++i
)
176 suppliers
[i
]->disconnect ();
180 // ******************************************************************
182 // ******************************************************************
184 int ACE_TMAIN (int argc
, ACE_TCHAR
*argv
[])
186 std::unique_ptr
<sig_i
> sig_impl
;
189 Consumer_Client client
;
190 int status
= client
.init (argc
, argv
);
191 ACE_UNUSED_ARG(status
);
192 ACE_ASSERT(status
== 0);
194 CosNotifyChannelAdmin::EventChannel_var ec
=
195 client
.create_event_channel ("MyEventChannel", 0);
197 CORBA::ORB_ptr orb
= client
.orb ();
199 sig_impl
.reset( new sig_i(orb
));
200 sig_var sig
= sig_impl
->_this ();
202 CORBA::String_var ior
=
203 orb
->object_to_string (sig
.in ());
205 if (ior_output_file
!= 0)
207 FILE *output_file
= ACE_OS::fopen (ior_output_file
, "w");
208 if (output_file
== 0)
209 ACE_ERROR_RETURN ((LM_ERROR
,
210 "Cannot open output file %s for "
215 ACE_OS::fprintf (output_file
, "%s", ior
.in ());
216 ACE_OS::fclose (output_file
);
219 CosNotifyChannelAdmin::SupplierAdmin_var admin
=
220 create_supplieradmin (ec
.in ());
221 ACE_ASSERT(!CORBA::is_nil (admin
.in ()));
222 create_suppliers (admin
.in (), &client
);
224 sig_impl
->wait_for_startup();
226 ACE_DEBUG((LM_DEBUG
, "%i supplier(s) sending %d events...\n", supplier_count
, event_count
));
227 for (int i
= 0; i
< event_count
; ++i
)
229 ACE_DEBUG((LM_DEBUG
, "+"));
232 ACE_DEBUG((LM_DEBUG
, "\nEach Supplier sent %d events.\n", event_count
));
234 sig_impl
->wait_for_completion();
236 ACE_OS::unlink (ior_output_file
);
238 disconnect_suppliers();
244 catch (const CORBA::Exception
& e
)
246 e
._tao_print_exception ("Error: ");