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 // ******************************************************************
24 const int PER_BATCH
= 1;
25 static TAO_Notify_Tests_StructuredPushSupplier
* supplier
= 0;
26 static const ACE_TCHAR
*ior_output_file
= ACE_TEXT ("supplier.ior");
27 static const ACE_TCHAR
*domain
= ACE_TEXT ("domain1");
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
72 class Supplier_Client
: public Notify_Test_Client
75 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
, "o:e:d:");
85 while ((c
= get_opts ()) != -1)
89 ior_output_file
= get_opts
.optarg
;
93 domain
= get_opts
.optarg
;
97 ACE_ERROR_RETURN ((LM_ERROR
,
99 "-o <iorfile> -d <domain>"
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
,
119 return CosNotifyChannelAdmin::SupplierAdmin::_duplicate (admin
.in ());
125 static const char* types
[] = { "good", "bad", "ugly" };
127 CosNotification::StructuredEvent event
;
129 event
.header
.fixed_header
.event_type
.domain_name
=
130 CORBA::string_dup (ACE_TEXT_ALWAYS_CHAR(domain
));
131 event
.header
.fixed_header
.event_type
.type_name
=
132 CORBA::string_dup ("Sequence Notification Push Demo Event");
134 event
.header
.fixed_header
.event_name
= CORBA::string_dup ("test event");
136 event
.header
.variable_header
.length (2);
137 event
.header
.variable_header
[0].name
=
138 CORBA::string_dup (CosNotification::Priority
);
139 event
.header
.variable_header
[1].name
=
140 CORBA::string_dup (CosNotification::Timeout
);
142 event
.filterable_data
.length (3);
143 event
.filterable_data
[0].name
= CORBA::string_dup ("objectId");
144 event
.filterable_data
[1].name
= CORBA::string_dup ("type");
145 event
.filterable_data
[2].name
= CORBA::string_dup ("enum");
147 event
.header
.variable_header
[0].value
<<= (CORBA::Short
)1;
149 event
.filterable_data
[0].value
<<= (CORBA::Long
)0;
150 event
.filterable_data
[1].value
<<= types
[0];
151 event
.filterable_data
[2].value
<<= (CORBA::Long
)1;
155 supplier
->send_event (event
);
157 catch (const CORBA::Exception
& e
)
159 e
._tao_print_exception ("Error: Supplier exception: ");
164 create_suppliers (CosNotifyChannelAdmin::SupplierAdmin_ptr admin
,
165 PortableServer::POA_ptr poa
)
167 // start up the supplier
168 ACE_NEW_THROW_EX (supplier
,
169 TAO_Notify_Tests_StructuredPushSupplier (),
170 CORBA::NO_MEMORY ());
172 supplier
->init (poa
);
173 supplier
->connect (admin
);
177 // ******************************************************************
179 // ******************************************************************
181 int ACE_TMAIN (int argc
, ACE_TCHAR
*argv
[])
183 std::unique_ptr
<sig_i
> sig_impl
;
187 Supplier_Client client
;
188 status
= client
.init (argc
, argv
);
192 CosNotifyChannelAdmin::EventChannel_var ec
=
193 client
.create_event_channel ("MyEventChannel", 0);
195 CORBA::ORB_ptr orb
= client
.orb ();
197 sig_impl
.reset( new sig_i(orb
));
198 sig_var sig
= sig_impl
->_this ();
200 CORBA::String_var ior
=
201 orb
->object_to_string (sig
.in ());
203 // If the ior_output_file exists, output the ior to it
204 if (ior_output_file
!= 0)
206 FILE *output_file
= ACE_OS::fopen (ior_output_file
, "w");
207 if (output_file
== 0)
208 ACE_ERROR_RETURN ((LM_ERROR
,
209 "Cannot open output file for "
213 ACE_OS::fprintf (output_file
, "%s", ior
.in ());
214 ACE_OS::fclose (output_file
);
217 CosNotifyChannelAdmin::SupplierAdmin_var admin
=
218 create_supplieradmin (ec
.in ());
219 if (!CORBA::is_nil (admin
.in ()))
221 create_suppliers (admin
.in (), client
.root_poa ());
223 sig_impl
->wait_for_startup();
225 ACE_DEBUG((LM_DEBUG
, " supplier sending event...\n"));
228 ACE_DEBUG((LM_DEBUG
, "\nSupplier waiting for consumer...\n"));
230 sig_impl
->wait_for_completion();
232 ACE_DEBUG((LM_DEBUG
, "\nSupplier done.\n"));
234 ACE_OS::unlink (ior_output_file
);
240 catch (const CORBA::Exception
& e
)
242 e
._tao_print_exception ("Error: Supplier exception: ");