1 // ******************************************************************
3 // ******************************************************************
5 #include "ace/Auto_Ptr.h"
6 #include "ace/Get_Opt.h"
7 #include "ace/OS_NS_unistd.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"
17 #include "Notify_StructuredPushSupplier.h"
18 #include "Notify_Test_Client.h"
21 // ******************************************************************
23 // ******************************************************************
25 static TAO_Notify_Tests_StructuredPushSupplier
* supplier_1
= 0;
26 static int max_events
= 10;
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 ()
55 ACE_Time_Value
tv (0, 100 * 1000); // 100ms
60 void wait_for_completion ()
64 ACE_Time_Value
tv (0, 100 * 1000); // 100ms
74 class Supplier_Client
: public Notify_Test_Client
77 virtual int parse_args (int argc
, ACE_TCHAR
*argv
[]);
81 Supplier_Client::parse_args (int argc
, ACE_TCHAR
*argv
[])
83 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("o:e:"));
86 while ((c
= get_opts ()) != -1)
90 max_events
= ACE_OS::atoi (get_opts
.optarg
);
94 ior_output_file
= get_opts
.optarg
;
98 ACE_ERROR_RETURN ((LM_ERROR
,
100 "-o <iorfile> -e <# of events> -d"
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
, adminid
);
118 return CosNotifyChannelAdmin::SupplierAdmin::_duplicate (admin
.in ());
125 CosNotification::StructuredEvent event
;
127 event
.header
.fixed_header
.event_type
.domain_name
= CORBA::string_dup ("DOC_TAO");
128 event
.header
.fixed_header
.event_type
.type_name
= CORBA::string_dup ("examples");
130 event
.filterable_data
.length (1);
131 event
.filterable_data
[0].name
= CORBA::string_dup ("id");
132 event
.filterable_data
[0].value
<<= id
;
136 supplier_1
->send_event (event
);
138 catch (const CORBA::Exception
& e
)
140 e
._tao_print_exception ("Error: ");
145 create_suppliers (CosNotifyChannelAdmin::SupplierAdmin_ptr admin
,
146 PortableServer::POA_ptr poa
)
148 // startup the supplier
149 ACE_NEW_THROW_EX (supplier_1
,
150 TAO_Notify_Tests_StructuredPushSupplier (),
151 CORBA::NO_MEMORY ());
153 supplier_1
->init (poa
);
154 supplier_1
->connect (admin
);
156 CosNotification::EventTypeSeq
added (1);
157 CosNotification::EventTypeSeq
removed (1);
160 added
[0].domain_name
= CORBA::string_dup ("DOC_TAO");
161 added
[0].type_name
= CORBA::string_dup ("examples");
163 removed
[0].domain_name
= CORBA::string_dup ("*");
164 removed
[0].type_name
= CORBA::string_dup ("*");
166 supplier_1
->offer_change (added
, removed
);
170 // ******************************************************************
172 // ******************************************************************
174 int ACE_TMAIN (int argc
, ACE_TCHAR
*argv
[])
177 ACE_Auto_Ptr
< sig_i
> sig_impl
;
180 Supplier_Client client
;
181 status
= client
.init (argc
, argv
);
185 CosNotifyChannelAdmin::EventChannel_var ec
=
186 client
.create_event_channel ("MyEventChannel", 0);
188 CORBA::ORB_ptr orb
= client
.orb ();
190 // Activate the signaler with the POA
191 sig_impl
.reset ( new sig_i ( orb
) );
192 sig_var sig
= sig_impl
->_this ();
194 CORBA::String_var ior
=
195 orb
->object_to_string (sig
.in ());
197 // If the ior_output_file exists, output the ior to it
198 if (ior_output_file
!= 0)
200 FILE *output_file
= ACE_OS::fopen (ior_output_file
, "w");
201 if (output_file
== 0)
202 ACE_ERROR_RETURN ((LM_ERROR
,
203 "Cannot open output file %s for "
208 ACE_OS::fprintf (output_file
, "%s", ior
.in ());
209 ACE_OS::fclose (output_file
);
212 CosNotifyChannelAdmin::SupplierAdmin_var admin
=
213 create_supplieradmin (ec
.in ());
214 if (!CORBA::is_nil (admin
.in ()))
216 create_suppliers (admin
.in (), client
.root_poa ());
218 sig_impl
->wait_for_startup ();
220 ACE_DEBUG ((LM_DEBUG
,
221 "1 supplier sending %d events...\n", max_events
));
222 for (int i
= 0; i
< max_events
; ++i
)
224 ACE_DEBUG ((LM_DEBUG
, "+"));
227 ACE_DEBUG ((LM_DEBUG
,
228 "\nSupplier sent %d events.\n", max_events
));
230 sig_impl
->wait_for_completion ();
232 ACE_OS::unlink (ior_output_file
);
234 supplier_1
->disconnect ();
240 catch (const CORBA::Exception
& e
)
242 e
._tao_print_exception ("Error: ");