Changes to attempt to silence bcc64x
[ACE_TAO.git] / TAO / orbsvcs / tests / Notify / Bug_2415_Regression / Supplier.cpp
blobd18e1b903c772ee9fd047ceccdb3c38a53605fc8
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 // ******************************************************************
24 const int PER_BATCH = 1;
25 static TAO_Notify_Tests_StructuredPushSupplier* supplier = 0;
26 static const ACE_TCHAR *ior_output_file = ACE_TEXT ("supplier.ior");
27 static const ACE_TCHAR *domain = ACE_TEXT ("domain1");
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_;
72 class Supplier_Client : public Notify_Test_Client
74 public:
75 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, "o:e:d:");
83 int c;
85 while ((c = get_opts ()) != -1)
86 switch (c)
88 case 'o':
89 ior_output_file = get_opts.optarg;
90 break;
92 case 'd':
93 domain = get_opts.optarg;
94 break;
96 default:
97 ACE_ERROR_RETURN ((LM_ERROR,
98 "usage: %s "
99 "-o <iorfile> -d <domain>"
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,
116 adminid);
119 return CosNotifyChannelAdmin::SupplierAdmin::_duplicate (admin.in ());
122 static void
123 SendEvent ()
125 static const char* types[] = { "good", "bad", "ugly" };
127 CosNotification::StructuredEvent event;
129 event.header.fixed_header.event_type.domain_name =
130 CORBA::string_dup (ACE_TEXT_ALWAYS_CHAR(domain));
131 event.header.fixed_header.event_type.type_name =
132 CORBA::string_dup ("Sequence Notification Push Demo Event");
134 event.header.fixed_header.event_name = CORBA::string_dup ("test event");
136 event.header.variable_header.length (2);
137 event.header.variable_header[0].name =
138 CORBA::string_dup (CosNotification::Priority);
139 event.header.variable_header[1].name =
140 CORBA::string_dup (CosNotification::Timeout);
142 event.filterable_data.length (3);
143 event.filterable_data[0].name = CORBA::string_dup ("objectId");
144 event.filterable_data[1].name = CORBA::string_dup ("type");
145 event.filterable_data[2].name = CORBA::string_dup ("enum");
147 event.header.variable_header[0].value <<= (CORBA::Short)1;
149 event.filterable_data[0].value <<= (CORBA::Long)0;
150 event.filterable_data[1].value <<= types[0];
151 event.filterable_data[2].value <<= (CORBA::Long)1;
155 supplier->send_event (event);
157 catch (const CORBA::Exception& e)
159 e._tao_print_exception ("Error: Supplier exception: ");
163 static void
164 create_suppliers (CosNotifyChannelAdmin::SupplierAdmin_ptr admin,
165 PortableServer::POA_ptr poa)
167 // start up the supplier
168 ACE_NEW_THROW_EX (supplier,
169 TAO_Notify_Tests_StructuredPushSupplier (),
170 CORBA::NO_MEMORY ());
172 supplier->init (poa);
173 supplier->connect (admin);
177 // ******************************************************************
178 // Main Section
179 // ******************************************************************
181 int ACE_TMAIN (int argc, ACE_TCHAR *argv[])
183 std::unique_ptr<sig_i> sig_impl;
184 int status = 0;
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 CORBA::ORB_ptr orb = client.orb ();
197 sig_impl.reset( new sig_i(orb));
198 sig_var sig = sig_impl->_this ();
200 CORBA::String_var ior =
201 orb->object_to_string (sig.in ());
203 // If the ior_output_file exists, output the ior to it
204 if (ior_output_file != 0)
206 FILE *output_file= ACE_OS::fopen (ior_output_file, "w");
207 if (output_file == 0)
208 ACE_ERROR_RETURN ((LM_ERROR,
209 "Cannot open output file for "
210 "writing IOR: %s",
211 ior_output_file),
213 ACE_OS::fprintf (output_file, "%s", ior.in ());
214 ACE_OS::fclose (output_file);
217 CosNotifyChannelAdmin::SupplierAdmin_var admin =
218 create_supplieradmin (ec.in ());
219 if (!CORBA::is_nil (admin.in ()))
221 create_suppliers (admin.in (), client.root_poa ());
223 sig_impl->wait_for_startup();
225 ACE_DEBUG((LM_DEBUG, " supplier sending event...\n"));
226 SendEvent ();
228 ACE_DEBUG((LM_DEBUG, "\nSupplier waiting for consumer...\n"));
230 sig_impl->wait_for_completion();
232 ACE_DEBUG((LM_DEBUG, "\nSupplier done.\n"));
234 ACE_OS::unlink (ior_output_file);
236 ec->destroy();
240 catch (const CORBA::Exception& e)
242 e._tao_print_exception ("Error: Supplier exception: ");
243 status = 1;
246 return status;