1 #include "Notify_SequencePushSupplier.h"
3 #include "Notify_Test_Client.h"
5 #include "orbsvcs/CosNotifyChannelAdminS.h"
6 #include "orbsvcs/CosNotifyCommC.h"
7 #include "orbsvcs/CosNamingC.h"
8 #include "orbsvcs/TimeBaseC.h"
10 #include "tao/ORB_Core.h"
12 #include "ace/Get_Opt.h"
13 #include "ace/OS_NS_unistd.h"
14 #include "ace/OS_NS_strings.h"
17 static TAO_Notify_Tests_SequencePushSupplier
* 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");
21 static const int BATCH_SIZE
= 5;
23 class sig_i
: public POA_sig
26 sig_i(CORBA::ORB_ptr orb
)
42 void wait_for_startup()
45 ACE_Time_Value
tv(0, 100 * 1000); // 100ms
50 void wait_for_completion()
53 ACE_Time_Value
tv(0, 100 * 1000); // 100ms
63 class Supplier_Client
: public Notify_Test_Client
66 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::strcasecmp (order
, ACE_TEXT ("fifo")) == 0)
83 order_policy
= CosNotification::FifoOrder
;
85 else if (ACE_OS::strcasecmp (order
, ACE_TEXT ("priority")) == 0)
87 order_policy
= CosNotification::PriorityOrder
;
89 else if (ACE_OS::strcasecmp (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> -d"
127 // Indicates successful parsing of the command line
131 static CosNotifyChannelAdmin::SupplierAdmin_ptr
132 create_supplieradmin (CosNotifyChannelAdmin::EventChannel_ptr ec
)
134 CosNotifyChannelAdmin::AdminID adminid
= 0;
135 CosNotifyChannelAdmin::SupplierAdmin_var admin
=
136 ec
->new_for_suppliers (CosNotifyChannelAdmin::AND_OP
,
140 return CosNotifyChannelAdmin::SupplierAdmin::_duplicate (admin
.in ());
145 SendBatch (int batch_id
)
147 CosNotification::EventBatch events
;
148 events
.length(BATCH_SIZE
);
149 for (CORBA::Long i
= 0; i
< BATCH_SIZE
; ++i
)
151 int id
= batch_id
* BATCH_SIZE
+ i
;
153 CosNotification::StructuredEvent event
;
155 event
.header
.fixed_header
.event_type
.domain_name
= CORBA::string_dup ("a");
156 event
.header
.fixed_header
.event_type
.type_name
= CORBA::string_dup ("b");
157 event
.header
.fixed_header
.event_name
= CORBA::string_dup ("c");
159 event
.header
.variable_header
.length (3);
160 event
.header
.variable_header
[0].name
=
161 CORBA::string_dup ("id");
162 event
.header
.variable_header
[0].value
<<= (CORBA::Long
)id
;
163 event
.header
.variable_header
[1].name
=
164 CORBA::string_dup (CosNotification::Priority
);
165 event
.header
.variable_header
[1].value
<<= (CORBA::Short
)(id
);
166 event
.header
.variable_header
[2].name
=
167 CORBA::string_dup (CosNotification::Timeout
);
168 event
.header
.variable_header
[2].value
<<= (TimeBase::TimeT
) (num_events
- id
);
172 supplier_1
->send_events (events
);
176 create_suppliers (CosNotifyChannelAdmin::SupplierAdmin_ptr admin
,
177 PortableServer::POA_ptr poa
)
179 ACE_NEW_THROW_EX (supplier_1
,
180 TAO_Notify_Tests_SequencePushSupplier (),
181 CORBA::NO_MEMORY ());
183 supplier_1
->init (poa
);
185 supplier_1
->connect (admin
);
189 // ******************************************************************
191 // ******************************************************************
193 int ACE_TMAIN (int argc
, ACE_TCHAR
*argv
[])
195 std::unique_ptr
<sig_i
> sig_impl
;
198 Supplier_Client client
;
199 int status
= client
.init (argc
, argv
);
200 ACE_UNUSED_ARG(status
);
201 ACE_ASSERT(status
== 0);
203 CosNotifyChannelAdmin::EventChannel_var ec
=
204 client
.create_event_channel ("MyEventChannel", 0);
206 CosNotification::QoSProperties
qos (1);
208 qos
[0].name
= CORBA::string_dup (CosNotification::OrderPolicy
);
209 qos
[0].value
<<= order_policy
;
212 CORBA::ORB_ptr orb
= client
.orb ();
214 sig_impl
.reset( new sig_i(orb
));
215 sig_var sig
= sig_impl
->_this ();
217 CORBA::String_var ior
=
218 orb
->object_to_string (sig
.in ());
220 if (ior_output_file
!= 0)
222 FILE *output_file
= ACE_OS::fopen (ior_output_file
, "w");
223 if (output_file
== 0)
224 ACE_ERROR_RETURN ((LM_ERROR
,
225 "Cannot open output file %s for "
230 ACE_OS::fprintf (output_file
, "%s", ior
.in ());
231 ACE_OS::fclose (output_file
);
234 CosNotifyChannelAdmin::SupplierAdmin_var admin
=
235 create_supplieradmin (ec
.in ());
236 ACE_ASSERT(!CORBA::is_nil (admin
.in ()));
237 create_suppliers (admin
.in (), client
.root_poa ());
239 sig_impl
->wait_for_startup();
241 ACE_DEBUG((LM_DEBUG
, "1 supplier sending %d events...\n", num_events
));
242 for (int i
= 0; i
< num_events
/ BATCH_SIZE
; ++i
)
244 ACE_DEBUG((LM_DEBUG
, "+"));
247 ACE_DEBUG((LM_DEBUG
, "\nSupplier sent %d events.\n", num_events
));
249 sig_impl
->wait_for_completion();
251 ACE_OS::unlink (ior_output_file
);
253 supplier_1
->disconnect();
259 catch (const CORBA::Exception
& e
)
261 e
._tao_print_exception ("Error: ");