Changes to attempt to silence bcc64x
[ACE_TAO.git] / TAO / orbsvcs / tests / Notify / Bug_2561_Regression / Supplier.cpp
blobde467fb135a210bae109518ff4cf6ad6201470dc
1 // ******************************************************************
2 // Include Section
3 // ******************************************************************
5 #include "ace/Get_Opt.h"
6 #include "ace/Argv_Type_Converter.h"
8 #include "tao/ORB_Core.h"
10 #include "orbsvcs/CosNotifyChannelAdminS.h"
11 #include "orbsvcs/CosNotifyCommC.h"
12 #include "orbsvcs/CosNamingC.h"
13 #include "orbsvcs/TimeBaseC.h"
14 #include "Notify_SequencePushSupplier.h"
15 #include "goS.h"
17 #include "Notify_Test_Client.h"
18 #include <memory>
20 // ******************************************************************
21 // Data Section
22 // ******************************************************************
24 static TAO_Notify_Tests_SequencePushSupplier* supplier_1 = 0;
25 static const ACE_TCHAR* ior_output_file = ACE_TEXT ("supplier.ior");
27 // ******************************************************************
28 // Subroutine Section
29 // ******************************************************************
31 // The supplier will not start sending events until the
32 // go() operation is invoked.
33 class sig_i : public POA_sig
35 public:
36 sig_i (CORBA::ORB_ptr orb)
37 : orb_ (orb)
38 , started_ (false)
42 void go ()
44 started_ = true;
47 void done ()
49 started_ = false;
52 void wait_for_startup ()
54 while (! started_)
56 ACE_Time_Value tv (0, 100 * 1000); // 100ms
57 orb_->run (tv);
61 void wait_for_completion ()
63 while (started_)
65 ACE_Time_Value tv (0, 100 * 1000); // 100ms
66 orb_->run (tv);
70 private:
71 CORBA::ORB_ptr orb_;
72 bool started_;
75 class Supplier_Client : public Notify_Test_Client
77 public:
78 virtual int parse_args (int argc, ACE_TCHAR* argv[]);
82 int
83 Supplier_Client::parse_args (int argc, ACE_TCHAR *argv[])
85 ACE_Argv_Type_Converter argcon (argc, argv);
86 ACE_Get_Opt get_opts (argcon.get_argc (),
87 argcon.get_TCHAR_argv (), ACE_TEXT ("o:"));
88 int c;
90 while ((c = get_opts ()) != -1)
91 switch (c)
93 case 'o':
94 ior_output_file = get_opts.optarg;
95 break;
97 default:
98 ACE_ERROR_RETURN ((LM_ERROR,
99 "usage: %s "
100 "-o <iorfile> "
101 "\n",
102 argv [0]),
103 -1);
106 // Indicates successful parsing of the command line
107 return 0;
111 static CosNotifyChannelAdmin::SupplierAdmin_ptr
112 create_supplieradmin (CosNotifyChannelAdmin::EventChannel_ptr ec)
114 CosNotifyChannelAdmin::AdminID adminid = 0;
115 CosNotifyChannelAdmin::SupplierAdmin_var admin =
116 ec->new_for_suppliers (CosNotifyChannelAdmin::AND_OP,
117 adminid);
120 return CosNotifyChannelAdmin::SupplierAdmin::_duplicate (admin.in ());
124 static void
125 create_suppliers (CosNotifyChannelAdmin::SupplierAdmin_ptr admin,
126 PortableServer::POA_ptr poa)
128 ACE_NEW_THROW_EX (supplier_1,
129 TAO_Notify_Tests_SequencePushSupplier (),
130 CORBA::NO_MEMORY ());
132 supplier_1->init (poa);
134 supplier_1->connect (admin);
138 // ******************************************************************
139 // Main Section
140 // ******************************************************************
143 ACE_TMAIN (int argc, ACE_TCHAR* argv[])
145 int status = 0;
146 std::unique_ptr<sig_i> sig_impl;
149 Supplier_Client client;
150 ACE_Argv_Type_Converter argcon (argc, argv);
151 status = client.init (argcon.get_argc (), argcon.get_TCHAR_argv ());
153 if (status == 0)
155 CosNotifyChannelAdmin::EventChannel_var ec =
156 client.create_event_channel ("MyEventChannel", 0);
158 sig_impl.reset (new sig_i (client.orb ()));
159 sig_var sig = sig_impl->_this ();
161 // If the ior_output_file exists, output the ior to it
162 if (ior_output_file != 0)
164 CORBA::String_var ior =
165 client.orb ()->object_to_string (sig.in ());
167 FILE *output_file= ACE_OS::fopen (ior_output_file, ACE_TEXT ("w"));
168 ACE_ASSERT (output_file != 0);
169 ACE_OS::fprintf (output_file, "%s", ior.in ());
170 ACE_OS::fclose (output_file);
173 CosNotifyChannelAdmin::SupplierAdmin_var admin =
174 create_supplieradmin (ec.in ());
175 ACE_ASSERT (!CORBA::is_nil (admin.in ()));
177 create_suppliers (admin.in (), client.root_poa ());
179 sig_impl->wait_for_startup ();
181 // If this is changed, you should update max_events
182 // found in Notify_Push_Consumer.cpp
183 int batch_size = 4;
184 int num_events = 80 / batch_size;
185 ACE_DEBUG ((LM_DEBUG,
186 "1 supplier sending %d batches of %d events...\n",
187 num_events, batch_size));
188 CosNotification::EventBatch events;
189 events.length(batch_size);
190 for (int i = 0; i < num_events; ++i)
192 supplier_1->send_events (events);
194 ACE_DEBUG ((LM_DEBUG, "\nSupplier sent %d events.\n", num_events));
196 sig_impl->wait_for_completion ();
198 ACE_OS::unlink (ior_output_file);
200 supplier_1->disconnect ();
202 ec->destroy ();
205 catch (const CORBA::Exception& e)
207 e._tao_print_exception ("Error: ");
208 status = 1;
211 return status;