140 # include <iostream.h>
143 #ifdef HAVE_STD_IOSTREAM
157 #include "CosEventComm.hh"
158 #include "CosEventChannelAdmin.hh"
161 static void usage(
int argc,
char **argv);
163 class Supplier_i :
virtual public POA_CosEventComm::PushSupplier {
171 cout <<
"Push Supplier: disconnected." << endl;
174 int main (
int argc,
char** argv)
177 CORBA::ORB_ptr
orb = CORBA::ORB_init(argc,argv);
182 int sleepInterval =0;
183 const char* channelName =
"EventChannel";
186 while ((c =
getopt(argc,argv,
"d:rs:n:h")) != EOF)
190 case 'd': discnum = atoi(
optarg);
193 case 'r': refnil =
true;
196 case 's': sleepInterval = atoi(
optarg);
199 case 'n': channelName =
optarg;
203 default :
usage(argc,argv);
209 #if defined(HAVE_SIGNAL_H) && defined(SIGPIPE)
211 signal(SIGPIPE, SIG_IGN);
215 CosEventChannelAdmin::EventChannel_var channel;
217 const char* action=
"";
219 CORBA::Object_var obj;
229 action=
"resolve initial reference 'RootPOA'";
230 obj=
orb->resolve_initial_references(
"RootPOA");
231 PortableServer::POA_var rootPoa =PortableServer::POA::_narrow(obj);
232 if(CORBA::is_nil(rootPoa))
233 throw CORBA::OBJECT_NOT_EXIST();
235 action=
"activate the RootPOA's POAManager";
236 PortableServer::POAManager_var pman =rootPoa->the_POAManager();
245 action=
"convert URI from command line into object reference";
250 action=
"resolve initial reference 'NameService'";
251 obj=
orb->resolve_initial_references(
"NameService");
252 CosNaming::NamingContext_var rootContext=
253 CosNaming::NamingContext::_narrow(obj);
254 if(CORBA::is_nil(rootContext))
255 throw CORBA::OBJECT_NOT_EXIST();
257 action=
"find EventChannel in NameService";
258 cout << action << endl;
259 obj=rootContext->resolve(
str2name(channelName));
262 action=
"narrow object reference to event channel";
263 channel=CosEventChannelAdmin::EventChannel::_narrow(obj);
264 if(CORBA::is_nil(channel))
266 cerr <<
"Failed to narrow Event Channel reference." << endl;
271 catch(CORBA::ORB::InvalidName& ex) {
272 cerr<<
"Failed to "<<action<<
". ORB::InvalidName"<<endl;
275 catch(CosNaming::NamingContext::InvalidName& ex) {
276 cerr<<
"Failed to "<<action<<
". NamingContext::InvalidName"<<endl;
279 catch(CosNaming::NamingContext::NotFound& ex) {
280 cerr<<
"Failed to "<<action<<
". NamingContext::NotFound"<<endl;
283 catch(CosNaming::NamingContext::CannotProceed& ex) {
284 cerr<<
"Failed to "<<action<<
". NamingContext::CannotProceed"<<endl;
287 catch(CORBA::TRANSIENT& ex) {
288 cerr<<
"Failed to "<<action<<
". TRANSIENT"<<endl;
291 catch(CORBA::OBJECT_NOT_EXIST& ex) {
292 cerr<<
"Failed to "<<action<<
". OBJECT_NOT_EXIST"<<endl;
295 catch(CORBA::SystemException& ex) {
296 cerr<<
"Failed to "<<action<<
".";
297 #if defined(HAVE_OMNIORB4)
298 cerr<<
" "<<ex._name();
299 if(ex.NP_minorString())
300 cerr<<
" ("<<ex.NP_minorString()<<
")";
305 catch(CORBA::Exception& ex) {
306 cerr<<
"Failed to "<<action<<
"."
307 #if defined(HAVE_OMNIORB4)
316 CosEventChannelAdmin::SupplierAdmin_var supplier_admin;
320 supplier_admin = channel->for_suppliers ();
321 if (CORBA::is_nil(supplier_admin))
323 cerr <<
"Event Channel returned nil Supplier Admin!"
329 catch (CORBA::COMM_FAILURE& ex) {
330 cerr <<
"Caught COMM_FAILURE Exception "
331 <<
"obtaining Supplier Admin! Retrying..."
336 cout <<
"Obtained SupplierAdmin." << endl;
342 CosEventChannelAdmin::ProxyPushConsumer_var proxy_consumer;
346 proxy_consumer = supplier_admin->obtain_push_consumer ();
347 if (CORBA::is_nil(proxy_consumer))
349 cerr <<
"Supplier Admin returned nil proxy_consumer!"<< endl;
354 catch (CORBA::COMM_FAILURE& ex) {
355 cerr <<
"Caught COMM_FAILURE Exception "
356 <<
"obtaining Proxy Push Consumer! Retrying..."
361 cout <<
"Obtained ProxyPushConsumer." << endl;
365 CosEventComm::PushSupplier_var sptr =CosEventComm::PushSupplier::_nil();
367 sptr = supplier->_this();
373 proxy_consumer->connect_push_supplier(sptr.in());
376 catch (CORBA::BAD_PARAM& ex) {
377 cerr <<
"Caught BAD_PARAM Exception connecting Push Supplier!"
381 catch (CosEventChannelAdmin::AlreadyConnected& ex) {
382 cerr <<
"Proxy Push Consumer already connected!"
386 catch (CORBA::COMM_FAILURE& ex) {
387 cerr <<
"Caught COMM_FAILURE Exception "
388 <<
"connecting Push Supplier! Retrying..."
393 cout <<
"Connected Push Supplier." << endl;
396 for (
int i=0; (discnum == 0) || (i < discnum); i++)
399 any <<= (CORBA::ULong) l++;
401 cout <<
"Push Supplier: push() called. " << flush;
402 proxy_consumer->push(any);
403 cout <<
"Data : " << l-1 << endl;
405 catch(CosEventComm::Disconnected&) {
406 cout <<
"Failed. Caught Disconnected Exception!" << endl;
408 catch(CORBA::COMM_FAILURE&) {
409 cout <<
"Failed. Caught COMM_FAILURE Exception!" << endl;
417 proxy_consumer->disconnect_push_consumer();
420 catch (CORBA::COMM_FAILURE& ex) {
421 cerr <<
"Caught COMM_FAILURE Exception "
422 <<
"disconnecting Push Supplier! Retrying..."
427 cout <<
"ProxyPushConsumer disconnected." << endl;
430 cout <<
"Sleeping " << sleepInterval <<
" seconds." << endl;
431 omni_thread::sleep(sleepInterval);
442 "\nCreate a PushSupplier to send events to a channel.\n"
443 "syntax: "<<(argc?argv[0]:
"pushsupp")<<
" OPTIONS [CHANNEL_URI]\n"
445 "CHANNEL_URI: The event channel may be specified as a URI.\n"
446 " This may be an IOR, or a corbaloc::: or corbaname::: URI.\n"
448 "OPTIONS: DEFAULT:\n"
449 " -d NUM disconnect after sending NUM events [0 - never disconnect]\n"
450 " -r connect using a nil reference\n"
451 " -s SECS sleep SECS seconds after disconnecting [0]\n"
452 " -n NAME channel name (if URI is not specified) [\"EventChannel\"]\n"
453 " -h display this help text\n" << endl;
int getopt(int argc, char *argv[], const char *optionS)
CosNaming::Name str2name(const char *namestr)
Converts stringified name to naming service name.
int main(int argc, char **argv)
The main process entry point.
static void usage(int argc, char **argv)
void disconnect_push_supplier()