1 // ******************************************************************
3 // ******************************************************************
5 #include "ace/Get_Opt.h"
6 #include "ace/OS_NS_unistd.h"
8 #include "tao/ORB_Core.h"
11 #include "Notify_StructuredPushSupplier.h"
12 #include "Notify_Test_Client.h"
14 // ******************************************************************
16 // ******************************************************************
18 static TAO_Notify_Tests_StructuredPushSupplier
* supplier_1
= 0;
19 static int max_events
= 10;
20 static const ACE_TCHAR
* ior_output_file
= ACE_TEXT("supplier.ior");
22 // ******************************************************************
24 // ******************************************************************
26 class sig_i
: public POA_sig
29 sig_i(CORBA::ORB_ptr orb
)
45 void wait_for_startup()
48 ACE_Time_Value
tv(0, 100 * 1000); // 100ms
59 class Supplier_Client
: public Notify_Test_Client
62 virtual int parse_args (int argc
, ACE_TCHAR
* argv
[]);
66 Supplier_Client::parse_args (int argc
, ACE_TCHAR
*argv
[])
68 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("o:"));
71 while ((c
= get_opts ()) != -1)
75 ior_output_file
= get_opts
.optarg
;
79 ACE_ERROR_RETURN ((LM_ERROR
,
87 // Indicates successful parsing of the command line
92 static CosNotifyChannelAdmin::SupplierAdmin_ptr
93 create_supplieradmin (CosNotifyChannelAdmin::EventChannel_ptr ec
)
95 CosNotifyChannelAdmin::AdminID adminid
= 0;
96 CosNotifyChannelAdmin::SupplierAdmin_var admin
=
97 ec
->new_for_suppliers (CosNotifyChannelAdmin::AND_OP
, adminid
);
99 return CosNotifyChannelAdmin::SupplierAdmin::_duplicate (admin
.in ());
106 CosNotification::StructuredEvent event
;
108 event
.header
.fixed_header
.event_type
.domain_name
= CORBA::string_dup ("DOC_TAO");
109 event
.header
.fixed_header
.event_type
.type_name
= CORBA::string_dup ("examples");
111 event
.filterable_data
.length (1);
112 event
.filterable_data
[0].name
= CORBA::string_dup ("id");
113 event
.filterable_data
[0].value
<<= id
;
117 supplier_1
->send_event (event
);
119 catch (const CORBA::Exception
& e
)
121 e
._tao_print_exception ("Error: ");
126 create_suppliers (CosNotifyChannelAdmin::SupplierAdmin_ptr admin
,
127 PortableServer::POA_ptr poa
)
129 // startup the supplier
130 ACE_NEW_THROW_EX (supplier_1
,
131 TAO_Notify_Tests_StructuredPushSupplier (),
132 CORBA::NO_MEMORY ());
134 supplier_1
->init (poa
);
135 supplier_1
->connect (admin
);
137 CosNotification::EventTypeSeq
added (1);
138 CosNotification::EventTypeSeq
removed (1);
141 added
[0].domain_name
= CORBA::string_dup ("DOC_TAO");
142 added
[0].type_name
= CORBA::string_dup ("examples");
144 removed
[0].domain_name
= CORBA::string_dup ("*");
145 removed
[0].type_name
= CORBA::string_dup ("*");
147 supplier_1
->offer_change (added
, removed
);
151 // ******************************************************************
153 // ******************************************************************
155 int ACE_TMAIN (int argc
, ACE_TCHAR
* argv
[])
160 Supplier_Client client
;
161 status
= client
.init (argc
, argv
);
165 CosNotifyChannelAdmin::EventChannel_var ec
=
166 client
.create_event_channel ("MyEventChannel", 0);
168 CORBA::ORB_ptr orb
= client
.orb ();
171 ACE_NEW_RETURN (sig_impl
, sig_i (orb
), 1);
172 PortableServer::ServantBase_var
owner_transfer(sig_impl
);
174 CORBA::Object_var object
=
175 orb
->resolve_initial_references ("RootPOA");
176 PortableServer::POA_var root_poa
=
177 PortableServer::POA::_narrow (object
.in ());
179 PortableServer::ObjectId_var id
=
180 root_poa
->activate_object (sig_impl
);
182 object
= root_poa
->id_to_reference (id
.in ());
184 sig_var sig
= sig::_narrow (object
.in ());
186 CORBA::String_var ior
= orb
->object_to_string (sig
.in ());
188 // Output the IOR to the <ior_output_file>
189 FILE *output_file
= ACE_OS::fopen (ior_output_file
, "w");
190 if (output_file
!= 0)
192 ACE_OS::fprintf (output_file
, "%s", ior
.in ());
193 ACE_OS::fclose (output_file
);
196 CosNotifyChannelAdmin::SupplierAdmin_var admin
=
197 create_supplieradmin (ec
.in ());
198 if (!CORBA::is_nil (admin
.in ()))
200 create_suppliers (admin
.in (), client
.root_poa ());
202 sig_impl
->wait_for_startup();
204 ACE_DEBUG ((LM_DEBUG
,
205 "1 supplier sending %d events...\n", max_events
));
206 for (int i
= 0; i
< max_events
; ++i
)
208 ACE_DEBUG ((LM_DEBUG
, "+"));
211 ACE_DEBUG ((LM_DEBUG
,
212 "\nSupplier sent %d events.\n", max_events
));
214 ACE_OS::unlink (ior_output_file
);
215 supplier_1
->disconnect ();
221 catch (const CORBA::Exception
& e
)
223 e
._tao_print_exception ("Supplier Error: ");