Merge pull request #1551 from DOCGroup/plm_jira_333
[ACE_TAO.git] / TAO / orbsvcs / tests / Notify / Bug_2561_Regression / Supplier.cpp
blobd434d603101f7ed868c56cf3cec0b126ba7c5838
1 // ******************************************************************
2 // Include Section
3 // ******************************************************************
5 #include "ace/Get_Opt.h"
6 #include "ace/Auto_Ptr.h"
7 #include "ace/Argv_Type_Converter.h"
9 #include "tao/ORB_Core.h"
11 #include "orbsvcs/CosNotifyChannelAdminS.h"
12 #include "orbsvcs/CosNotifyCommC.h"
13 #include "orbsvcs/CosNamingC.h"
14 #include "orbsvcs/TimeBaseC.h"
15 #include "Notify_SequencePushSupplier.h"
16 #include "goS.h"
18 #include "Notify_Test_Client.h"
21 // ******************************************************************
22 // Data Section
23 // ******************************************************************
25 static TAO_Notify_Tests_SequencePushSupplier* supplier_1 = 0;
26 static const ACE_TCHAR* ior_output_file = ACE_TEXT ("supplier.ior");
28 // ******************************************************************
29 // Subroutine Section
30 // ******************************************************************
32 // The supplier will not start sending events until the
33 // go() operation is invoked.
34 class sig_i : public POA_sig
36 public:
37 sig_i (CORBA::ORB_ptr orb)
38 : orb_ (orb)
39 , started_ (false)
43 void go (void)
45 started_ = true;
48 void done (void)
50 started_ = false;
53 void wait_for_startup ()
55 while (! started_)
57 ACE_Time_Value tv (0, 100 * 1000); // 100ms
58 orb_->run (tv);
62 void wait_for_completion ()
64 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_Argv_Type_Converter argcon (argc, argv);
87 ACE_Get_Opt get_opts (argcon.get_argc (),
88 argcon.get_TCHAR_argv (), ACE_TEXT ("o:"));
89 int c;
91 while ((c = get_opts ()) != -1)
92 switch (c)
94 case 'o':
95 ior_output_file = get_opts.optarg;
96 break;
98 default:
99 ACE_ERROR_RETURN ((LM_ERROR,
100 "usage: %s "
101 "-o <iorfile> "
102 "\n",
103 argv [0]),
104 -1);
107 // Indicates successful parsing of the command line
108 return 0;
112 static CosNotifyChannelAdmin::SupplierAdmin_ptr
113 create_supplieradmin (CosNotifyChannelAdmin::EventChannel_ptr ec)
115 CosNotifyChannelAdmin::AdminID adminid = 0;
116 CosNotifyChannelAdmin::SupplierAdmin_var admin =
117 ec->new_for_suppliers (CosNotifyChannelAdmin::AND_OP,
118 adminid);
121 return CosNotifyChannelAdmin::SupplierAdmin::_duplicate (admin.in ());
125 static void
126 create_suppliers (CosNotifyChannelAdmin::SupplierAdmin_ptr admin,
127 PortableServer::POA_ptr poa)
129 ACE_NEW_THROW_EX (supplier_1,
130 TAO_Notify_Tests_SequencePushSupplier (),
131 CORBA::NO_MEMORY ());
133 supplier_1->init (poa);
135 supplier_1->connect (admin);
139 // ******************************************************************
140 // Main Section
141 // ******************************************************************
144 ACE_TMAIN (int argc, ACE_TCHAR* argv[])
146 int status = 0;
147 ACE_Auto_Ptr<sig_i> sig_impl;
150 Supplier_Client client;
151 ACE_Argv_Type_Converter argcon (argc, argv);
152 status = client.init (argcon.get_argc (), argcon.get_TCHAR_argv ());
154 if (status == 0)
156 CosNotifyChannelAdmin::EventChannel_var ec =
157 client.create_event_channel ("MyEventChannel", 0);
159 sig_impl.reset (new sig_i (client.orb ()));
160 sig_var sig = sig_impl->_this ();
162 // If the ior_output_file exists, output the ior to it
163 if (ior_output_file != 0)
165 CORBA::String_var ior =
166 client.orb ()->object_to_string (sig.in ());
168 FILE *output_file= ACE_OS::fopen (ior_output_file, ACE_TEXT ("w"));
169 ACE_ASSERT (output_file != 0);
170 ACE_OS::fprintf (output_file, "%s", ior.in ());
171 ACE_OS::fclose (output_file);
174 CosNotifyChannelAdmin::SupplierAdmin_var admin =
175 create_supplieradmin (ec.in ());
176 ACE_ASSERT (!CORBA::is_nil (admin.in ()));
178 create_suppliers (admin.in (), client.root_poa ());
180 sig_impl->wait_for_startup ();
182 // If this is changed, you should update max_events
183 // found in Notify_Push_Consumer.cpp
184 int batch_size = 4;
185 int num_events = 80 / batch_size;
186 ACE_DEBUG ((LM_DEBUG,
187 "1 supplier sending %d batches of %d events...\n",
188 num_events, batch_size));
189 CosNotification::EventBatch events;
190 events.length(batch_size);
191 for (int i = 0; i < num_events; ++i)
193 supplier_1->send_events (events);
195 ACE_DEBUG ((LM_DEBUG, "\nSupplier sent %d events.\n", num_events));
197 sig_impl->wait_for_completion ();
199 ACE_OS::unlink (ior_output_file);
201 supplier_1->disconnect ();
203 ec->destroy ();
206 catch (const CORBA::Exception& e)
208 e._tao_print_exception ("Error: ");
209 status = 1;
212 return status;