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 "orbsvcs/TimeBaseC.h"
13 #include "Notify_StructuredPushSupplier.h"
16 #include "Notify_Test_Client.h"
18 #include "ace/OS_NS_unistd.h"
21 // ******************************************************************
23 // ******************************************************************
25 static TAO_Notify_Tests_StructuredPushSupplier
* supplier_1
= 0;
26 static int max_events
= 20;
27 static const ACE_TCHAR
* ior_output_file
= ACE_TEXT ("supplier.ior");
29 // ******************************************************************
31 // ******************************************************************
32 class sig_i
: public POA_sig
35 sig_i(CORBA::ORB_ptr orb
)
51 void wait_for_startup()
54 ACE_Time_Value
tv(0, 100 * 1000); // 100ms
59 void wait_for_completion()
62 ACE_Time_Value
tv(0, 100 * 1000); // 100ms
71 class Supplier_Client
: public Notify_Test_Client
74 virtual int parse_args (int argc
, ACE_TCHAR
*argv
[]);
79 Supplier_Client::parse_args (int argc
, ACE_TCHAR
*argv
[])
81 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("o:e:d"));
84 while ((c
= get_opts ()) != -1)
88 max_events
= ACE_OS::atoi (get_opts
.optarg
);
92 ior_output_file
= get_opts
.optarg
;
96 ACE_ERROR_RETURN ((LM_ERROR
,
98 "-o <iorfile> -e <# of events> -d"
104 // Indicates successful parsing of the command line
109 static CosNotifyChannelAdmin::SupplierAdmin_ptr
110 create_supplieradmin (CosNotifyChannelAdmin::EventChannel_ptr ec
)
112 CosNotifyChannelAdmin::AdminID adminid
= 0;
113 CosNotifyChannelAdmin::SupplierAdmin_var admin
=
114 ec
->new_for_suppliers (CosNotifyChannelAdmin::AND_OP
,
118 return CosNotifyChannelAdmin::SupplierAdmin::_duplicate (admin
.in ());
125 CosNotification::StructuredEvent event
;
127 event
.header
.fixed_header
.event_type
.domain_name
= CORBA::string_dup ("");
128 event
.header
.fixed_header
.event_type
.type_name
= CORBA::string_dup ("");
129 event
.header
.fixed_header
.event_name
= CORBA::string_dup ("blocking-test");
131 event
.filterable_data
.length (1);
132 event
.filterable_data
[0].name
= CORBA::string_dup ("id");
133 event
.filterable_data
[0].value
<<= id
;
137 supplier_1
->send_event (event
);
139 catch (const CORBA::Exception
& e
)
141 e
._tao_print_exception ("Error: ");
146 create_suppliers (CosNotifyChannelAdmin::SupplierAdmin_ptr admin
,
147 PortableServer::POA_ptr poa
)
149 // startup the supplier
150 ACE_NEW_THROW_EX (supplier_1
,
151 TAO_Notify_Tests_StructuredPushSupplier (),
152 CORBA::NO_MEMORY ());
154 supplier_1
->init (poa
);
156 supplier_1
->connect (admin
);
160 // ******************************************************************
162 // ******************************************************************
164 int ACE_TMAIN (int argc
, ACE_TCHAR
*argv
[])
167 std::unique_ptr
<sig_i
> sig_impl
;
170 Supplier_Client client
;
171 status
= client
.init (argc
, argv
);
175 CosNotifyChannelAdmin::EventChannel_var ec
=
176 client
.create_event_channel ("MyEventChannel", 0);
178 CORBA::ORB_ptr orb
= client
.orb ();
180 // Activate the signaler with the POA
181 sig_impl
.reset( new sig_i(orb
));
182 sig_var sig
= sig_impl
->_this ();
184 CORBA::String_var ior
=
185 orb
->object_to_string (sig
.in ());
187 // If the ior_output_file exists, output the ior to it
188 if (ior_output_file
!= 0)
190 FILE *output_file
= ACE_OS::fopen (ior_output_file
, "w");
191 if (output_file
== 0)
192 ACE_ERROR_RETURN ((LM_ERROR
,
193 "Cannot open output file %s for "
198 ACE_OS::fprintf (output_file
, "%s", ior
.in ());
199 ACE_OS::fclose (output_file
);
202 CosNotifyChannelAdmin::SupplierAdmin_var admin
=
203 create_supplieradmin (ec
.in ());
204 if (!CORBA::is_nil (admin
.in ()))
206 create_suppliers (admin
.in (), client
.root_poa ());
208 sig_impl
->wait_for_startup();
210 ACE_DEBUG((LM_DEBUG
, "1 supplier sending %d events...\n", max_events
));
211 for (int i
= 0; i
< max_events
; ++i
)
213 ACE_DEBUG((LM_DEBUG
, "+"));
216 ACE_DEBUG((LM_DEBUG
, "\nSupplier sent %d events.\n", max_events
));
218 sig_impl
->wait_for_completion();
220 ACE_OS::unlink (ior_output_file
);
222 supplier_1
->disconnect();
228 catch (const CORBA::Exception
& e
)
230 e
._tao_print_exception ("Error: ");