Changes to attempt to silence bcc64x
[ACE_TAO.git] / TAO / orbsvcs / tests / Notify / Discarding / Structured_Supplier.cpp
blob2fb1055dc378368400564feb0975e246fb4de5ed
1 // ******************************************************************
2 // Include Section
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"
14 #include "goS.h"
16 #include "Notify_Test_Client.h"
18 #include "ace/OS_NS_unistd.h"
19 #include <memory>
21 // ******************************************************************
22 // Data Section
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 // ******************************************************************
31 // Subroutine Section
32 // ******************************************************************
34 // The supplier will not start sending events until the
35 // go() operation is invoked.
36 class sig_i : public POA_sig
38 public:
39 sig_i(CORBA::ORB_ptr orb)
40 : orb_(orb)
41 , started_(false)
45 void go ()
47 started_ = true;
50 void done ()
52 started_ = false;
55 void wait_for_startup()
57 while (! started_) {
58 ACE_Time_Value tv(0, 100 * 1000); // 100ms
59 orb_->run(tv);
63 void wait_for_completion()
65 while (started_) {
66 ACE_Time_Value tv(0, 100 * 1000); // 100ms
67 orb_->run(tv);
71 private:
72 CORBA::ORB_ptr orb_;
73 bool started_;
76 class Supplier_Client : public Notify_Test_Client
78 public:
79 virtual int parse_args (int argc, ACE_TCHAR *argv[]);
83 int
84 Supplier_Client::parse_args (int argc, ACE_TCHAR *argv[])
86 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("o:e:d"));
87 int c;
89 while ((c = get_opts ()) != -1)
90 switch (c)
92 case 'd':
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 "
99 "config.h\n"), -1);
100 #else
101 break;
102 #endif /* ACE_HAS_TIMED_MESSAGE_BLOCKS */
103 case 'e':
104 num_events = ACE_OS::atoi (get_opts.optarg);
105 break;
107 case 'o':
108 ior_output_file = get_opts.optarg;
109 break;
111 default:
112 ACE_ERROR_RETURN ((LM_ERROR,
113 "usage: %s "
114 "-o <iorfile> -e <# of events> -d"
115 "\n",
116 argv [0]),
117 -1);
120 // Indicates successful parsing of the command line
121 return 0;
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,
131 adminid);
134 return CosNotifyChannelAdmin::SupplierAdmin::_duplicate (admin.in ());
138 static void
139 SendEvent (int id)
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);
163 static void
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 // ******************************************************************
178 // Main Section
179 // ******************************************************************
181 int ACE_TMAIN (int argc, ACE_TCHAR *argv[])
183 int status = 0;
184 std::unique_ptr<sig_i> sig_impl;
187 Supplier_Client client;
188 status = client.init (argc, argv);
190 if (status == 0)
192 CosNotifyChannelAdmin::EventChannel_var ec =
193 client.create_event_channel ("MyEventChannel", 0);
195 if (use_deadline_ordering)
197 CosNotification::QoSProperties qos (1);
198 qos.length (1);
199 qos[0].name = CORBA::string_dup (CosNotification::OrderPolicy);
200 qos[0].value <<= (CORBA::Short)CosNotification::DeadlineOrder;
201 ec->set_qos (qos);
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, "+"));
231 SendEvent (i + 1);
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();
241 ec->destroy();
244 catch (const CORBA::Exception& e)
246 e._tao_print_exception ("Error: ");
247 status = 1;
250 return status;