Changes to attempt to silence bcc64x
[ACE_TAO.git] / TAO / orbsvcs / tests / Notify / Timeout / Structured_Supplier.cpp
blob5a8e6fe258d073ce2e2170a5e1b299a4cffc03cc
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 "sigS.h"
11 #include "Notify_StructuredPushSupplier.h"
12 #include "Notify_Test_Client.h"
14 // ******************************************************************
15 // Data Section
16 // ******************************************************************
18 static TAO_Notify_Tests_StructuredPushSupplier* supplier_1 = 0;
19 static int max_events = 10;
20 static const ACE_TCHAR* ior_output_file = ACE_TEXT("supplier.ior");
22 // ******************************************************************
23 // Subroutine Section
24 // ******************************************************************
26 class sig_i : public POA_sig
28 public:
29 sig_i(CORBA::ORB_ptr orb)
30 : orb_(orb)
31 , started_(false)
35 void go ()
37 started_ = true;
40 void done ()
42 started_ = false;
45 void wait_for_startup()
47 while (! started_) {
48 ACE_Time_Value tv(0, 100 * 1000); // 100ms
49 orb_->run(tv);
53 private:
54 CORBA::ORB_ptr orb_;
55 bool started_;
59 class Supplier_Client : public Notify_Test_Client
61 public:
62 virtual int parse_args (int argc, ACE_TCHAR* argv[]);
65 int
66 Supplier_Client::parse_args (int argc, ACE_TCHAR *argv[])
68 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("o:"));
69 int c;
71 while ((c = get_opts ()) != -1)
72 switch (c)
74 case 'o':
75 ior_output_file = get_opts.optarg;
76 break;
78 default:
79 ACE_ERROR_RETURN ((LM_ERROR,
80 "usage: %s "
81 "-o <iorfile>"
82 "\n",
83 argv [0]),
84 -1);
87 // Indicates successful parsing of the command line
88 return 0;
92 static CosNotifyChannelAdmin::SupplierAdmin_ptr
93 create_supplieradmin (CosNotifyChannelAdmin::EventChannel_ptr ec)
95 CosNotifyChannelAdmin::AdminID adminid = 0;
96 CosNotifyChannelAdmin::SupplierAdmin_var admin =
97 ec->new_for_suppliers (CosNotifyChannelAdmin::AND_OP, adminid);
99 return CosNotifyChannelAdmin::SupplierAdmin::_duplicate (admin.in ());
103 static void
104 SendEvent (int id)
106 CosNotification::StructuredEvent event;
108 event.header.fixed_header.event_type.domain_name = CORBA::string_dup ("DOC_TAO");
109 event.header.fixed_header.event_type.type_name = CORBA::string_dup ("examples");
111 event.filterable_data.length (1);
112 event.filterable_data[0].name = CORBA::string_dup ("id");
113 event.filterable_data[0].value <<= id;
117 supplier_1->send_event (event);
119 catch (const CORBA::Exception& e)
121 e._tao_print_exception ("Error: ");
125 static void
126 create_suppliers (CosNotifyChannelAdmin::SupplierAdmin_ptr admin,
127 PortableServer::POA_ptr poa)
129 // startup the supplier
130 ACE_NEW_THROW_EX (supplier_1,
131 TAO_Notify_Tests_StructuredPushSupplier (),
132 CORBA::NO_MEMORY ());
134 supplier_1->init (poa);
135 supplier_1->connect (admin);
137 CosNotification::EventTypeSeq added (1);
138 CosNotification::EventTypeSeq removed (1);
139 added.length (1);
140 removed.length (1);
141 added[0].domain_name = CORBA::string_dup ("DOC_TAO");
142 added[0].type_name = CORBA::string_dup ("examples");
144 removed[0].domain_name = CORBA::string_dup ("*");
145 removed[0].type_name = CORBA::string_dup ("*");
147 supplier_1->offer_change (added, removed);
151 // ******************************************************************
152 // Main Section
153 // ******************************************************************
155 int ACE_TMAIN (int argc, ACE_TCHAR* argv[])
157 int status = 0;
160 Supplier_Client client;
161 status = client.init (argc, argv);
163 if (status == 0)
165 CosNotifyChannelAdmin::EventChannel_var ec =
166 client.create_event_channel ("MyEventChannel", 0);
168 CORBA::ORB_ptr orb = client.orb ();
170 sig_i* sig_impl;
171 ACE_NEW_RETURN (sig_impl, sig_i (orb), 1);
172 PortableServer::ServantBase_var owner_transfer(sig_impl);
174 CORBA::Object_var object =
175 orb->resolve_initial_references ("RootPOA");
176 PortableServer::POA_var root_poa =
177 PortableServer::POA::_narrow (object.in ());
179 PortableServer::ObjectId_var id =
180 root_poa->activate_object (sig_impl);
182 object = root_poa->id_to_reference (id.in ());
184 sig_var sig = sig::_narrow (object.in ());
186 CORBA::String_var ior = orb->object_to_string (sig.in ());
188 // Output the IOR to the <ior_output_file>
189 FILE *output_file= ACE_OS::fopen (ior_output_file, "w");
190 if (output_file != 0)
192 ACE_OS::fprintf (output_file, "%s", ior.in ());
193 ACE_OS::fclose (output_file);
196 CosNotifyChannelAdmin::SupplierAdmin_var admin =
197 create_supplieradmin (ec.in ());
198 if (!CORBA::is_nil (admin.in ()))
200 create_suppliers (admin.in (), client.root_poa ());
202 sig_impl->wait_for_startup();
204 ACE_DEBUG ((LM_DEBUG,
205 "1 supplier sending %d events...\n", max_events));
206 for (int i = 0; i < max_events; ++i)
208 ACE_DEBUG ((LM_DEBUG, "+"));
209 SendEvent (i);
211 ACE_DEBUG ((LM_DEBUG,
212 "\nSupplier sent %d events.\n", max_events));
214 ACE_OS::unlink (ior_output_file);
215 supplier_1->disconnect ();
217 ec->destroy ();
221 catch (const CORBA::Exception& e)
223 e._tao_print_exception ("Supplier Error: ");
224 status = 1;
227 return status;