1 // ******************************************************************
3 // ******************************************************************
5 #include "ace/Get_Opt.h"
6 #include "ace/OS_NS_unistd.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"
16 #include "Notify_StructuredPushSupplier.h"
17 #include "Notify_Test_Client.h"
20 // ******************************************************************
22 // ******************************************************************
24 static TAO_Notify_Tests_StructuredPushSupplier
* supplier_1
= 0;
25 static int max_events
= 10;
26 static const ACE_TCHAR
*ior_output_file
= ACE_TEXT ("supplier.ior");
28 // ******************************************************************
30 // ******************************************************************
31 class sig_i
: public POA_sig
34 sig_i (CORBA::ORB_ptr orb
)
50 void wait_for_startup ()
54 ACE_Time_Value
tv (0, 100 * 1000); // 100ms
59 void wait_for_completion ()
63 ACE_Time_Value
tv (0, 100 * 1000); // 100ms
73 class Supplier_Client
: public Notify_Test_Client
76 virtual int parse_args (int argc
, ACE_TCHAR
*argv
[]);
80 Supplier_Client::parse_args (int argc
, ACE_TCHAR
*argv
[])
82 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("o:e:"));
85 while ((c
= get_opts ()) != -1)
89 max_events
= ACE_OS::atoi (get_opts
.optarg
);
93 ior_output_file
= get_opts
.optarg
;
97 ACE_ERROR_RETURN ((LM_ERROR
,
99 "-o <iorfile> -e <# of events> -d"
105 // Indicates successful parsing of the command line
110 static CosNotifyChannelAdmin::SupplierAdmin_ptr
111 create_supplieradmin (CosNotifyChannelAdmin::EventChannel_ptr ec
)
113 CosNotifyChannelAdmin::AdminID adminid
= 0;
114 CosNotifyChannelAdmin::SupplierAdmin_var admin
=
115 ec
->new_for_suppliers (CosNotifyChannelAdmin::AND_OP
, adminid
);
117 return CosNotifyChannelAdmin::SupplierAdmin::_duplicate (admin
.in ());
124 CosNotification::StructuredEvent event
;
126 event
.header
.fixed_header
.event_type
.domain_name
= CORBA::string_dup ("DOC_TAO");
127 event
.header
.fixed_header
.event_type
.type_name
= CORBA::string_dup ("examples");
129 event
.filterable_data
.length (1);
130 event
.filterable_data
[0].name
= CORBA::string_dup ("id");
131 event
.filterable_data
[0].value
<<= id
;
135 supplier_1
->send_event (event
);
137 catch (const CORBA::Exception
& e
)
139 e
._tao_print_exception ("Error: ");
144 create_suppliers (CosNotifyChannelAdmin::SupplierAdmin_ptr admin
,
145 PortableServer::POA_ptr poa
)
147 // startup the supplier
148 ACE_NEW_THROW_EX (supplier_1
,
149 TAO_Notify_Tests_StructuredPushSupplier (),
150 CORBA::NO_MEMORY ());
152 supplier_1
->init (poa
);
153 supplier_1
->connect (admin
);
155 CosNotification::EventTypeSeq
added (1);
156 CosNotification::EventTypeSeq
removed (1);
159 added
[0].domain_name
= CORBA::string_dup ("DOC_TAO");
160 added
[0].type_name
= CORBA::string_dup ("examples");
162 removed
[0].domain_name
= CORBA::string_dup ("*");
163 removed
[0].type_name
= CORBA::string_dup ("*");
165 supplier_1
->offer_change (added
, removed
);
169 // ******************************************************************
171 // ******************************************************************
173 int ACE_TMAIN (int argc
, ACE_TCHAR
*argv
[])
176 std::unique_ptr
<sig_i
> sig_impl
;
179 Supplier_Client client
;
180 status
= client
.init (argc
, argv
);
184 CosNotifyChannelAdmin::EventChannel_var ec
=
185 client
.create_event_channel ("MyEventChannel", 0);
187 CORBA::ORB_ptr orb
= client
.orb ();
189 // Activate the signaler with the POA
190 sig_impl
.reset ( new sig_i (orb
));
191 sig_var sig
= sig_impl
->_this ();
193 CORBA::String_var ior
=
194 orb
->object_to_string (sig
.in ());
196 // If the ior_output_file exists, output the ior to it
197 if (ior_output_file
!= 0)
199 FILE *output_file
= ACE_OS::fopen (ior_output_file
, "w");
200 if (output_file
== 0)
201 ACE_ERROR_RETURN ((LM_ERROR
,
202 "Cannot open output file %s for "
207 ACE_OS::fprintf (output_file
, "%s", ior
.in ());
208 ACE_OS::fclose (output_file
);
211 CosNotifyChannelAdmin::SupplierAdmin_var admin
=
212 create_supplieradmin (ec
.in ());
213 if (!CORBA::is_nil (admin
.in ()))
215 create_suppliers (admin
.in (), client
.root_poa ());
217 sig_impl
->wait_for_startup ();
219 ACE_DEBUG ((LM_DEBUG
,
220 "1 supplier sending %d events...\n", max_events
));
221 for (int i
= 0; i
< max_events
; ++i
)
223 ACE_DEBUG ((LM_DEBUG
, "+"));
226 ACE_DEBUG ((LM_DEBUG
,
227 "\nSupplier sent %d events.\n", max_events
));
229 sig_impl
->wait_for_completion ();
231 ACE_OS::unlink (ior_output_file
);
233 supplier_1
->disconnect ();
239 catch (const CORBA::Exception
& e
)
241 e
._tao_print_exception ("Error: ");