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 // ******************************************************************
25 static TAO_Notify_Tests_StructuredPushSupplier
* supplier_1
= 0;
26 static CORBA::Boolean use_deadline_ordering
= 0;
27 static int num_events
= 40;
28 static const ACE_TCHAR
*ior_output_file
= ACE_TEXT ("supplier.ior");
30 // ******************************************************************
32 // ******************************************************************
34 // The supplier will not start sending events until the
35 // go() operation is invoked.
36 class sig_i
: public POA_sig
39 sig_i(CORBA::ORB_ptr orb
)
55 void wait_for_startup()
58 ACE_Time_Value
tv(0, 100 * 1000); // 100ms
63 void wait_for_completion()
66 ACE_Time_Value
tv(0, 100 * 1000); // 100ms
76 class Supplier_Client
: public Notify_Test_Client
79 virtual int parse_args (int argc
, ACE_TCHAR
*argv
[]);
84 Supplier_Client::parse_args (int argc
, ACE_TCHAR
*argv
[])
86 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("o:e:d"));
89 while ((c
= get_opts ()) != -1)
93 use_deadline_ordering
= 1;
94 #if !defined (ACE_HAS_TIMED_MESSAGE_BLOCKS)
95 ACE_ERROR_RETURN ((LM_ERROR
,
96 "This order policy requires timed message "
97 "blocks.\nPlease #define "
98 "ACE_HAS_TIMED_MESSAGE_BLOCKS in your "
102 #endif /* ACE_HAS_TIMED_MESSAGE_BLOCKS */
104 num_events
= ACE_OS::atoi (get_opts
.optarg
);
108 ior_output_file
= get_opts
.optarg
;
112 ACE_ERROR_RETURN ((LM_ERROR
,
114 "-o <iorfile> -e <# of events> -d"
120 // Indicates successful parsing of the command line
125 static CosNotifyChannelAdmin::SupplierAdmin_ptr
126 create_supplieradmin (CosNotifyChannelAdmin::EventChannel_ptr ec
)
128 CosNotifyChannelAdmin::AdminID adminid
= 0;
129 CosNotifyChannelAdmin::SupplierAdmin_var admin
=
130 ec
->new_for_suppliers (CosNotifyChannelAdmin::AND_OP
,
134 return CosNotifyChannelAdmin::SupplierAdmin::_duplicate (admin
.in ());
141 CosNotification::StructuredEvent event
;
143 event
.header
.fixed_header
.event_type
.domain_name
= CORBA::string_dup ("a");
144 event
.header
.fixed_header
.event_type
.type_name
= CORBA::string_dup ("b");
145 event
.header
.fixed_header
.event_name
= CORBA::string_dup ("c");
147 event
.header
.variable_header
.length (3);
149 event
.header
.variable_header
[0].name
= CORBA::string_dup ("Id");
150 event
.header
.variable_header
[0].value
<<= (CORBA::Long
)id
;
152 event
.header
.variable_header
[1].name
=
153 CORBA::string_dup (CosNotification::Priority
);
154 event
.header
.variable_header
[1].value
<<= (CORBA::Short
) (id
);
156 event
.header
.variable_header
[2].name
=
157 CORBA::string_dup (CosNotification::Timeout
);
158 event
.header
.variable_header
[2].value
<<= (TimeBase::TimeT
) (id
* 10000);
160 supplier_1
->send_event (event
);
164 create_suppliers (CosNotifyChannelAdmin::SupplierAdmin_ptr admin
,
165 PortableServer::POA_ptr poa
)
167 ACE_NEW_THROW_EX (supplier_1
,
168 TAO_Notify_Tests_StructuredPushSupplier (),
169 CORBA::NO_MEMORY ());
171 supplier_1
->init (poa
);
173 supplier_1
->connect (admin
);
177 // ******************************************************************
179 // ******************************************************************
181 int ACE_TMAIN (int argc
, ACE_TCHAR
*argv
[])
184 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 if (use_deadline_ordering
)
197 CosNotification::QoSProperties
qos (1);
199 qos
[0].name
= CORBA::string_dup (CosNotification::OrderPolicy
);
200 qos
[0].value
<<= (CORBA::Short
)CosNotification::DeadlineOrder
;
204 sig_impl
.reset( new sig_i(client
.orb()));
205 sig_var sig
= sig_impl
->_this ();
207 // If the ior_output_file exists, output the ior to it
208 if (ior_output_file
!= 0)
210 CORBA::String_var ior
=
211 client
.orb ()->object_to_string (sig
.in ());
213 FILE *output_file
= ACE_OS::fopen (ior_output_file
, "w");
214 ACE_ASSERT (output_file
!= 0);
215 ACE_OS::fprintf (output_file
, "%s", ior
.in ());
216 ACE_OS::fclose (output_file
);
219 CosNotifyChannelAdmin::SupplierAdmin_var admin
=
220 create_supplieradmin (ec
.in ());
221 ACE_ASSERT(!CORBA::is_nil (admin
.in ()));
223 create_suppliers (admin
.in (), client
.root_poa ());
225 sig_impl
->wait_for_startup();
227 ACE_DEBUG((LM_DEBUG
, "1 supplier sending %d events...\n", num_events
));
228 for (int i
= 0; i
< num_events
; ++i
)
230 ACE_DEBUG((LM_DEBUG
, "+"));
233 ACE_DEBUG((LM_DEBUG
, "\nSupplier sent %d events.\n", num_events
));
235 sig_impl
->wait_for_completion();
237 ACE_OS::unlink (ior_output_file
);
239 supplier_1
->disconnect();
244 catch (const CORBA::Exception
& e
)
246 e
._tao_print_exception ("Error: ");