1 #include "Notify_StructuredPushSupplier.h"
4 #include "Notify_Test_Client.h"
6 #include "orbsvcs/CosNotifyChannelAdminS.h"
7 #include "orbsvcs/CosNotifyCommC.h"
8 #include "orbsvcs/CosNamingC.h"
9 #include "orbsvcs/TimeBaseC.h"
11 #include "tao/ORB_Core.h"
13 #include "ace/Get_Opt.h"
14 #include "ace/OS_NS_unistd.h"
17 static TAO_Notify_Tests_StructuredPushSupplier
* supplier_1
= 0;
18 static CORBA::Short order_policy
= CosNotification::FifoOrder
;
19 static int num_events
= 30;
20 static const ACE_TCHAR
*ior_output_file
= ACE_TEXT ("supplier.ior");
22 class sig_i
: public POA_sig
25 sig_i(CORBA::ORB_ptr orb
)
41 void wait_for_startup()
44 ACE_Time_Value
tv(0, 100 * 1000); // 100ms
49 void wait_for_completion()
52 ACE_Time_Value
tv(0, 100 * 1000); // 100ms
62 class Supplier_Client
: public Notify_Test_Client
65 virtual int parse_args (int argc
, ACE_TCHAR
*argv
[]);
70 Supplier_Client::parse_args (int argc
, ACE_TCHAR
*argv
[])
72 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("o:e:d:"));
75 while ((c
= get_opts ()) != -1)
80 const ACE_TCHAR
* order
= get_opts
.optarg
;
81 if (ACE_OS::strcmp (order
, ACE_TEXT ("fifo")) == 0)
83 order_policy
= CosNotification::FifoOrder
;
85 else if (ACE_OS::strcmp (order
, ACE_TEXT ("priority")) == 0)
87 order_policy
= CosNotification::PriorityOrder
;
89 else if (ACE_OS::strcmp (order
, ACE_TEXT ("deadline")) == 0)
91 order_policy
= CosNotification::DeadlineOrder
;
92 #if !defined (ACE_HAS_TIMED_MESSAGE_BLOCKS)
93 ACE_ERROR_RETURN ((LM_ERROR
,
94 "This order policy requires timed message "
95 "blocks.\nPlease #define "
96 "ACE_HAS_TIMED_MESSAGE_BLOCKS in your "
102 ACE_ERROR_RETURN ((LM_ERROR
,
103 "Unknown order policy: %s\n",
111 num_events
= ACE_OS::atoi (get_opts
.optarg
);
115 ior_output_file
= get_opts
.optarg
;
119 ACE_ERROR_RETURN ((LM_ERROR
,
121 "-o <iorfile> -e <# of events> "
122 "-d <fifo|priority|deadline>"
128 // Indicates successful parsing of the command line
133 static CosNotifyChannelAdmin::SupplierAdmin_ptr
134 create_supplieradmin (CosNotifyChannelAdmin::EventChannel_ptr ec
)
136 CosNotifyChannelAdmin::AdminID adminid
= 0;
137 CosNotifyChannelAdmin::SupplierAdmin_var admin
=
138 ec
->new_for_suppliers (CosNotifyChannelAdmin::AND_OP
,
142 return CosNotifyChannelAdmin::SupplierAdmin::_duplicate (admin
.in ());
149 CosNotification::StructuredEvent event
;
151 event
.header
.fixed_header
.event_type
.domain_name
= CORBA::string_dup ("a");
152 event
.header
.fixed_header
.event_type
.type_name
= CORBA::string_dup ("b");
153 event
.header
.fixed_header
.event_name
= CORBA::string_dup ("test");
155 event
.header
.variable_header
.length (3);
156 event
.header
.variable_header
[0].name
= CORBA::string_dup ("id");
157 event
.header
.variable_header
[0].value
<<= (CORBA::Long
) id
;
158 event
.header
.variable_header
[1].name
=
159 CORBA::string_dup (CosNotification::Priority
);
160 event
.header
.variable_header
[1].value
<<= (CORBA::Short
) id
;
161 event
.header
.variable_header
[2].name
=
162 CORBA::string_dup (CosNotification::Timeout
);
163 event
.header
.variable_header
[2].value
<<= (TimeBase::TimeT
) (num_events
- id
);
167 supplier_1
->send_event (event
);
169 catch (const CORBA::Exception
& e
)
171 e
._tao_print_exception ("Error: ");
176 create_suppliers (CosNotifyChannelAdmin::SupplierAdmin_ptr admin
,
177 PortableServer::POA_ptr poa
)
179 // startup the supplier
180 ACE_NEW_THROW_EX (supplier_1
,
181 TAO_Notify_Tests_StructuredPushSupplier (),
182 CORBA::NO_MEMORY ());
184 supplier_1
->init (poa
);
186 supplier_1
->connect (admin
);
189 int ACE_TMAIN (int argc
, ACE_TCHAR
*argv
[])
191 std::unique_ptr
<sig_i
> sig_impl
;
194 Supplier_Client client
;
195 int status
= client
.init (argc
, argv
);
196 ACE_UNUSED_ARG(status
);
197 ACE_ASSERT(status
== 0);
199 CosNotifyChannelAdmin::EventChannel_var ec
=
200 client
.create_event_channel ("MyEventChannel", 0);
202 CosNotification::QoSProperties
qos (1);
204 qos
[0].name
= CORBA::string_dup (CosNotification::OrderPolicy
);
205 qos
[0].value
<<= order_policy
;
208 CORBA::ORB_ptr orb
= client
.orb ();
210 sig_impl
.reset( new sig_i(orb
));
211 sig_var sig
= sig_impl
->_this ();
213 CORBA::String_var ior
=
214 orb
->object_to_string (sig
.in ());
216 if (ior_output_file
!= 0)
218 FILE *output_file
= ACE_OS::fopen (ior_output_file
, "w");
219 if (output_file
== 0)
220 ACE_ERROR_RETURN ((LM_ERROR
,
221 "Cannot open output file %s for "
226 ACE_OS::fprintf (output_file
, "%s", ior
.in ());
227 ACE_OS::fclose (output_file
);
230 CosNotifyChannelAdmin::SupplierAdmin_var admin
=
231 create_supplieradmin (ec
.in ());
232 ACE_ASSERT(!CORBA::is_nil (admin
.in ()));
233 create_suppliers (admin
.in (), client
.root_poa ());
235 sig_impl
->wait_for_startup();
237 ACE_DEBUG((LM_DEBUG
, "1 supplier sending %d events...\n", num_events
));
238 for (int i
= 0; i
< num_events
; ++i
)
240 ACE_DEBUG((LM_DEBUG
, "+"));
243 ACE_DEBUG((LM_DEBUG
, "\nSupplier sent %d events.\n", num_events
));
245 sig_impl
->wait_for_completion();
247 ACE_OS::unlink (ior_output_file
);
249 supplier_1
->disconnect();
255 catch (const CORBA::Exception
& e
)
257 e
._tao_print_exception ("Error: ");