Merge pull request #2309 from mitza-oci/warnings
[ACE_TAO.git] / TAO / orbsvcs / tests / Notify / Blocking / Structured_Supplier.cpp
blobc75a790f8c54d41048049858bb35280c91bd1fb5
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 int max_events = 20;
27 static const ACE_TCHAR* ior_output_file = ACE_TEXT ("supplier.ior");
29 // ******************************************************************
30 // Subroutine Section
31 // ******************************************************************
32 class sig_i : public POA_sig
34 public:
35 sig_i(CORBA::ORB_ptr orb)
36 : orb_(orb)
37 , started_(false)
41 void go ()
43 started_ = true;
46 void done ()
48 started_ = false;
51 void wait_for_startup()
53 while (! started_) {
54 ACE_Time_Value tv(0, 100 * 1000); // 100ms
55 orb_->run(tv);
59 void wait_for_completion()
61 while (started_) {
62 ACE_Time_Value tv(0, 100 * 1000); // 100ms
63 orb_->run(tv);
67 private:
68 CORBA::ORB_ptr orb_;
69 bool started_;
71 class Supplier_Client : public Notify_Test_Client
73 public:
74 virtual int parse_args (int argc, ACE_TCHAR *argv[]);
78 int
79 Supplier_Client::parse_args (int argc, ACE_TCHAR *argv[])
81 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("o:e:d"));
82 int c;
84 while ((c = get_opts ()) != -1)
85 switch (c)
87 case 'e':
88 max_events = ACE_OS::atoi (get_opts.optarg);
89 break;
91 case 'o':
92 ior_output_file = get_opts.optarg;
93 break;
95 default:
96 ACE_ERROR_RETURN ((LM_ERROR,
97 "usage: %s "
98 "-o <iorfile> -e <# of events> -d"
99 "\n",
100 argv [0]),
101 -1);
104 // Indicates successful parsing of the command line
105 return 0;
109 static CosNotifyChannelAdmin::SupplierAdmin_ptr
110 create_supplieradmin (CosNotifyChannelAdmin::EventChannel_ptr ec)
112 CosNotifyChannelAdmin::AdminID adminid = 0;
113 CosNotifyChannelAdmin::SupplierAdmin_var admin =
114 ec->new_for_suppliers (CosNotifyChannelAdmin::AND_OP,
115 adminid);
118 return CosNotifyChannelAdmin::SupplierAdmin::_duplicate (admin.in ());
122 static void
123 SendEvent (int id)
125 CosNotification::StructuredEvent event;
127 event.header.fixed_header.event_type.domain_name = CORBA::string_dup ("");
128 event.header.fixed_header.event_type.type_name = CORBA::string_dup ("");
129 event.header.fixed_header.event_name = CORBA::string_dup ("blocking-test");
131 event.filterable_data.length (1);
132 event.filterable_data[0].name = CORBA::string_dup ("id");
133 event.filterable_data[0].value <<= id;
137 supplier_1->send_event (event);
139 catch (const CORBA::Exception& e)
141 e._tao_print_exception ("Error: ");
145 static void
146 create_suppliers (CosNotifyChannelAdmin::SupplierAdmin_ptr admin,
147 PortableServer::POA_ptr poa)
149 // startup the supplier
150 ACE_NEW_THROW_EX (supplier_1,
151 TAO_Notify_Tests_StructuredPushSupplier (),
152 CORBA::NO_MEMORY ());
154 supplier_1->init (poa);
156 supplier_1->connect (admin);
160 // ******************************************************************
161 // Main Section
162 // ******************************************************************
164 int ACE_TMAIN (int argc, ACE_TCHAR *argv[])
166 int status = 0;
167 std::unique_ptr<sig_i> sig_impl;
170 Supplier_Client client;
171 status = client.init (argc, argv);
173 if (status == 0)
175 CosNotifyChannelAdmin::EventChannel_var ec =
176 client.create_event_channel ("MyEventChannel", 0);
178 CORBA::ORB_ptr orb = client.orb ();
180 // Activate the signaler with the POA
181 sig_impl.reset( new sig_i(orb));
182 sig_var sig = sig_impl->_this ();
184 CORBA::String_var ior =
185 orb->object_to_string (sig.in ());
187 // If the ior_output_file exists, output the ior to it
188 if (ior_output_file != 0)
190 FILE *output_file= ACE_OS::fopen (ior_output_file, "w");
191 if (output_file == 0)
192 ACE_ERROR_RETURN ((LM_ERROR,
193 "Cannot open output file %s for "
194 "writing IOR: %C",
195 ior_output_file,
196 ior.in ()),
198 ACE_OS::fprintf (output_file, "%s", ior.in ());
199 ACE_OS::fclose (output_file);
202 CosNotifyChannelAdmin::SupplierAdmin_var admin =
203 create_supplieradmin (ec.in ());
204 if (!CORBA::is_nil (admin.in ()))
206 create_suppliers (admin.in (), client.root_poa ());
208 sig_impl->wait_for_startup();
210 ACE_DEBUG((LM_DEBUG, "1 supplier sending %d events...\n", max_events));
211 for (int i = 0; i < max_events; ++i)
213 ACE_DEBUG((LM_DEBUG, "+"));
214 SendEvent (i);
216 ACE_DEBUG((LM_DEBUG, "\nSupplier sent %d events.\n", max_events));
218 sig_impl->wait_for_completion();
220 ACE_OS::unlink (ior_output_file);
222 supplier_1->disconnect();
224 ec->destroy();
228 catch (const CORBA::Exception& e)
230 e._tao_print_exception ("Error: ");
231 status = 1;
234 return status;