Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members

eventf.cc

Go to the documentation of this file.
00001 //                            Package   : omniEvents
00002 // eventf.cc                  Created   : 2004-05-30
00003 //                            Author    : Alex Tingle
00004 //
00005 //    Copyright (C) 2004 Alex Tingle
00006 //
00007 //    This file is part of the omniEvents application.
00008 //
00009 //    omniEvents is free software; you can redistribute it and/or
00010 //    modify it under the terms of the GNU Lesser General Public
00011 //    License as published by the Free Software Foundation; either
00012 //    version 2.1 of the License, or (at your option) any later version.
00013 //
00014 //    omniEvents is distributed in the hope that it will be useful,
00015 //    but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017 //    Lesser General Public License for more details.
00018 //
00019 //    You should have received a copy of the GNU Lesser General Public
00020 //    License along with this library; if not, write to the Free Software
00021 //    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00022 //
00023 // Description:
00024 //    Destroys the named EventChannel.
00025 //      
00026 
00027 #ifdef HAVE_CONFIG_H
00028 #  include "config.h"
00029 #endif
00030 
00031 #ifdef HAVE_GETOPT
00032 #  include <unistd.h>
00033 extern char* optarg;
00034 extern int optind;
00035 #else
00036 #  include "getopt.h"
00037 #endif
00038 
00039 #ifdef HAVE_STDLIB_H
00040 #  include <stdlib.h> // exit()
00041 #endif
00042 
00043 #ifdef HAVE_IOSTREAM
00044 #  include <iostream>
00045 #else
00046 #  include <iostream.h>
00047 #endif
00048 
00049 #ifdef HAVE_STD_IOSTREAM
00050 using namespace std;
00051 #endif
00052 
00053 #include "CosEventChannelAdmin.hh"
00054 
00055 static void usage(int argc, char **argv);
00056 static CosEventChannelAdmin::EventChannel_ptr getChannel(const char* sior);
00057 
00058 CORBA::ORB_ptr orb;
00059 
00060 int
00061 main(int argc, char **argv)
00062 {
00063   int result =1;
00064 
00065   //
00066   // Start orb.
00067 #if defined(HAVE_OMNIORB4)
00068   orb=CORBA::ORB_init(argc,argv,"omniORB4");
00069 #else
00070   orb=CORBA::ORB_init(argc,argv,"omniORB3");
00071 #endif
00072 
00073   // Process Options
00074   int c;
00075 
00076   while((c = getopt(argc,argv,"h")) != EOF)
00077   {
00078     switch (c)
00079     {
00080       case 'h': usage(argc,argv);
00081                 exit(0);
00082 
00083       default : usage(argc,argv);
00084                 exit(-1);
00085     }
00086   }
00087 
00088   if(optind!=argc-2)
00089   {
00090     usage(argc,argv);
00091     exit(-1);
00092   }
00093 
00094   //
00095   // Use one big try...catch block.
00096   // 'action' variable keeps track of what we're doing.
00097   const char* action ="start";
00098   try
00099   {
00100     using namespace CosEventChannelAdmin;
00101 
00102     action="convert URI into reference to source channel";
00103     EventChannel_var from_channel =getChannel(argv[optind]);
00104 
00105     action="convert URI into reference to destination channel";
00106     EventChannel_var to_channel   =getChannel(argv[optind+1]);
00107 
00108     action="obtain ConsumerAdmin";
00109     ConsumerAdmin_var cadmin =from_channel->for_consumers();
00110 
00111     action="obtain ProxyPushSupplier";
00112     ProxyPushSupplier_var supplier =cadmin->obtain_push_supplier();
00113 
00114     action="obtain SupplierAdmin";
00115     SupplierAdmin_var sadmin =to_channel->for_suppliers();
00116 
00117     action="obtain ProxyPushConsumer";
00118     ProxyPushConsumer_var consumer =sadmin->obtain_push_consumer();
00119 
00120     action="connect PushConsumer";
00121     consumer->connect_push_supplier(supplier.in());
00122 
00123     action="connect PushSupplier";
00124     supplier->connect_push_consumer(consumer.in());
00125 
00126     //
00127     // Clean up nicely.
00128     action="destroy orb";
00129     orb->destroy();
00130 
00131     //
00132     // If we get here, then everything has worked OK.
00133     result=0;
00134 
00135   }
00136   catch(CORBA::TRANSIENT& ex) { // _narrow()
00137      cerr<<"Failed to "<<action<<". TRANSIENT"<<endl;
00138   }
00139   catch(CORBA::OBJECT_NOT_EXIST& ex) { // _narrow()
00140      cerr<<"Failed to "<<action<<". OBJECT_NOT_EXIST"<<endl;
00141   }
00142   catch(CORBA::SystemException& ex) {
00143      cerr<<"Failed to "<<action<<".";
00144 #if defined(HAVE_OMNIORB4)
00145      cerr<<" "<<ex._name();
00146      if(ex.NP_minorString())
00147          cerr<<" ("<<ex.NP_minorString()<<")";
00148 #endif
00149      cerr<<endl;
00150   }
00151   catch(CORBA::Exception& ex) {
00152      cerr<<"Failed to "<<action<<"."
00153 #if defined(HAVE_OMNIORB4)
00154        " "<<ex._name()
00155 #endif
00156        <<endl;
00157   }
00158 
00159   return result;
00160 }
00161 
00162 
00163 static void
00164 usage(int argc, char **argv)
00165 {
00166   cerr<<
00167 "\nConnect (federate) two event channels.\n"
00168 "syntax: "<<(argc?argv[0]:"eventf")<<" OPTIONS [FROM_CHANNEL] [TO_CHANNEL]\n"
00169 "\n"
00170 "FROM/TO_CHANNEL: The event channels must be specified as a URI.\n"
00171 " This may be an IOR, or a corbaloc::: or corbaname::: URI.\n"
00172 "\n"
00173 "OPTIONS:\n"
00174 " -h  display this help text\n" << endl;
00175 }
00176 
00177 
00178 //
00179 // Obtain object reference to EventChannel
00180 static CosEventChannelAdmin::EventChannel_ptr
00181 getChannel(const char* sior)
00182 {
00183   // convert URI from command line into object reference";
00184   CORBA::Object_var obj =orb->string_to_object(sior);
00185 
00186   // narrow object reference to event channel";
00187   CosEventChannelAdmin::EventChannel_var channel =
00188     CosEventChannelAdmin::EventChannel::_narrow(obj);
00189   if(CORBA::is_nil(channel))
00190       throw CORBA::OBJECT_NOT_EXIST();
00191   
00192   return channel._retn();
00193 }

Generated on Fri Aug 26 20:56:14 2005 for OmniEvents by  doxygen 1.4.3-20050530