Changes to attempt to silence bcc64x
[ACE_TAO.git] / TAO / orbsvcs / tests / Notify / Bug_1385_Regression / Structured_Supplier.cpp
blob7da4193f69434d70e4ef3f528a2afeb3d3aa93a6
1 // ******************************************************************
2 // Include Section
3 // ******************************************************************
5 #include "ace/Get_Opt.h"
6 #include "ace/OS_NS_unistd.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"
15 #include "goS.h"
16 #include "Notify_StructuredPushSupplier.h"
17 #include "Notify_Test_Client.h"
18 #include <memory>
20 // ******************************************************************
21 // Data Section
22 // ******************************************************************
24 static TAO_Notify_Tests_StructuredPushSupplier* supplier_1 = 0;
25 static int max_events = 10;
26 static const ACE_TCHAR *ior_output_file = ACE_TEXT ("supplier.ior");
28 // ******************************************************************
29 // Subroutine Section
30 // ******************************************************************
31 class sig_i : public POA_sig
33 public:
34 sig_i (CORBA::ORB_ptr orb)
35 : orb_ (orb),
36 started_ (false)
40 void go ()
42 started_ = true;
45 void done ()
47 started_ = false;
50 void wait_for_startup ()
52 while (!started_)
54 ACE_Time_Value tv (0, 100 * 1000); // 100ms
55 orb_->run (tv);
59 void wait_for_completion ()
61 while (started_)
63 ACE_Time_Value tv (0, 100 * 1000); // 100ms
64 orb_->run (tv);
68 private:
69 CORBA::ORB_ptr orb_;
70 bool started_;
73 class Supplier_Client : public Notify_Test_Client
75 public:
76 virtual int parse_args (int argc, ACE_TCHAR *argv[]);
79 int
80 Supplier_Client::parse_args (int argc, ACE_TCHAR *argv[])
82 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("o:e:"));
83 int c;
85 while ((c = get_opts ()) != -1)
86 switch (c)
88 case 'e':
89 max_events = ACE_OS::atoi (get_opts.optarg);
90 break;
92 case 'o':
93 ior_output_file = get_opts.optarg;
94 break;
96 default:
97 ACE_ERROR_RETURN ((LM_ERROR,
98 "usage: %s "
99 "-o <iorfile> -e <# of events> -d"
100 "\n",
101 argv [0]),
102 -1);
105 // Indicates successful parsing of the command line
106 return 0;
110 static CosNotifyChannelAdmin::SupplierAdmin_ptr
111 create_supplieradmin (CosNotifyChannelAdmin::EventChannel_ptr ec)
113 CosNotifyChannelAdmin::AdminID adminid = 0;
114 CosNotifyChannelAdmin::SupplierAdmin_var admin =
115 ec->new_for_suppliers (CosNotifyChannelAdmin::AND_OP, adminid);
117 return CosNotifyChannelAdmin::SupplierAdmin::_duplicate (admin.in ());
121 static void
122 SendEvent (int id)
124 CosNotification::StructuredEvent event;
126 event.header.fixed_header.event_type.domain_name = CORBA::string_dup ("DOC_TAO");
127 event.header.fixed_header.event_type.type_name = CORBA::string_dup ("examples");
129 event.filterable_data.length (1);
130 event.filterable_data[0].name = CORBA::string_dup ("id");
131 event.filterable_data[0].value <<= id;
135 supplier_1->send_event (event);
137 catch (const CORBA::Exception& e)
139 e._tao_print_exception ("Error: ");
143 static void
144 create_suppliers (CosNotifyChannelAdmin::SupplierAdmin_ptr admin,
145 PortableServer::POA_ptr poa)
147 // startup the supplier
148 ACE_NEW_THROW_EX (supplier_1,
149 TAO_Notify_Tests_StructuredPushSupplier (),
150 CORBA::NO_MEMORY ());
152 supplier_1->init (poa);
153 supplier_1->connect (admin);
155 CosNotification::EventTypeSeq added (1);
156 CosNotification::EventTypeSeq removed (1);
157 added.length (1);
158 removed.length (1);
159 added[0].domain_name = CORBA::string_dup ("DOC_TAO");
160 added[0].type_name = CORBA::string_dup ("examples");
162 removed[0].domain_name = CORBA::string_dup ("*");
163 removed[0].type_name = CORBA::string_dup ("*");
165 supplier_1->offer_change (added, removed);
169 // ******************************************************************
170 // Main Section
171 // ******************************************************************
173 int ACE_TMAIN (int argc, ACE_TCHAR *argv[])
175 int status = 0;
176 std::unique_ptr<sig_i> sig_impl;
179 Supplier_Client client;
180 status = client.init (argc, argv);
182 if (status == 0)
184 CosNotifyChannelAdmin::EventChannel_var ec =
185 client.create_event_channel ("MyEventChannel", 0);
187 CORBA::ORB_ptr orb = client.orb ();
189 // Activate the signaler with the POA
190 sig_impl.reset ( new sig_i (orb));
191 sig_var sig = sig_impl->_this ();
193 CORBA::String_var ior =
194 orb->object_to_string (sig.in ());
196 // If the ior_output_file exists, output the ior to it
197 if (ior_output_file != 0)
199 FILE *output_file= ACE_OS::fopen (ior_output_file, "w");
200 if (output_file == 0)
201 ACE_ERROR_RETURN ((LM_ERROR,
202 "Cannot open output file %s for "
203 "writing IOR: %C",
204 ior_output_file,
205 ior.in ()),
207 ACE_OS::fprintf (output_file, "%s", ior.in ());
208 ACE_OS::fclose (output_file);
211 CosNotifyChannelAdmin::SupplierAdmin_var admin =
212 create_supplieradmin (ec.in ());
213 if (!CORBA::is_nil (admin.in ()))
215 create_suppliers (admin.in (), client.root_poa ());
217 sig_impl->wait_for_startup ();
219 ACE_DEBUG ((LM_DEBUG,
220 "1 supplier sending %d events...\n", max_events));
221 for (int i = 0; i < max_events; ++i)
223 ACE_DEBUG ((LM_DEBUG, "+"));
224 SendEvent (i);
226 ACE_DEBUG ((LM_DEBUG,
227 "\nSupplier sent %d events.\n", max_events));
229 sig_impl->wait_for_completion ();
231 ACE_OS::unlink (ior_output_file);
233 supplier_1->disconnect ();
235 ec->destroy ();
239 catch (const CORBA::Exception& e)
241 e._tao_print_exception ("Error: ");
242 status = 1;
245 return status;