OmniEvents
|
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 #include <cstdio> 00050 00051 #ifdef HAVE_STD_IOSTREAM 00052 using namespace std; 00053 #endif 00054 00055 #include "CosEventChannelAdmin.hh" 00056 00057 static void usage(int argc, char **argv); 00058 static CosEventChannelAdmin::EventChannel_ptr getChannel(const char* sior); 00059 00060 CORBA::ORB_ptr orb; 00061 00062 int 00063 main(int argc, char **argv) 00064 { 00065 int result =1; 00066 00067 // 00068 // Start orb. 00069 #if defined(HAVE_OMNIORB4) 00070 orb=CORBA::ORB_init(argc,argv,"omniORB4"); 00071 #else 00072 orb=CORBA::ORB_init(argc,argv,"omniORB3"); 00073 #endif 00074 00075 // Process Options 00076 int c; 00077 00078 while((c = getopt(argc,argv,"h")) != EOF) 00079 { 00080 switch (c) 00081 { 00082 case 'h': usage(argc,argv); 00083 exit(0); 00084 00085 default : usage(argc,argv); 00086 exit(-1); 00087 } 00088 } 00089 00090 if(optind!=argc-2) 00091 { 00092 usage(argc,argv); 00093 exit(-1); 00094 } 00095 00096 // 00097 // Use one big try...catch block. 00098 // 'action' variable keeps track of what we're doing. 00099 const char* action ="start"; 00100 try 00101 { 00102 using namespace CosEventChannelAdmin; 00103 00104 action="convert URI into reference to source channel"; 00105 EventChannel_var from_channel =getChannel(argv[optind]); 00106 00107 action="convert URI into reference to destination channel"; 00108 EventChannel_var to_channel =getChannel(argv[optind+1]); 00109 00110 action="obtain ConsumerAdmin"; 00111 ConsumerAdmin_var cadmin =from_channel->for_consumers(); 00112 00113 action="obtain ProxyPushSupplier"; 00114 ProxyPushSupplier_var supplier =cadmin->obtain_push_supplier(); 00115 00116 action="obtain SupplierAdmin"; 00117 SupplierAdmin_var sadmin =to_channel->for_suppliers(); 00118 00119 action="obtain ProxyPushConsumer"; 00120 ProxyPushConsumer_var consumer =sadmin->obtain_push_consumer(); 00121 00122 action="connect PushConsumer"; 00123 consumer->connect_push_supplier(supplier.in()); 00124 00125 action="connect PushSupplier"; 00126 supplier->connect_push_consumer(consumer.in()); 00127 00128 // 00129 // Clean up nicely. 00130 action="destroy orb"; 00131 orb->destroy(); 00132 00133 // 00134 // If we get here, then everything has worked OK. 00135 result=0; 00136 00137 } 00138 catch(CORBA::TRANSIENT& ex) { // _narrow() 00139 cerr<<"Failed to "<<action<<". TRANSIENT"<<endl; 00140 } 00141 catch(CORBA::OBJECT_NOT_EXIST& ex) { // _narrow() 00142 cerr<<"Failed to "<<action<<". OBJECT_NOT_EXIST"<<endl; 00143 } 00144 catch(CORBA::SystemException& ex) { 00145 cerr<<"Failed to "<<action<<"."; 00146 #if defined(HAVE_OMNIORB4) 00147 cerr<<" "<<ex._name(); 00148 if(ex.NP_minorString()) 00149 cerr<<" ("<<ex.NP_minorString()<<")"; 00150 #endif 00151 cerr<<endl; 00152 } 00153 catch(CORBA::Exception& ex) { 00154 cerr<<"Failed to "<<action<<"." 00155 #if defined(HAVE_OMNIORB4) 00156 " "<<ex._name() 00157 #endif 00158 <<endl; 00159 } 00160 00161 return result; 00162 } 00163 00164 00165 static void 00166 usage(int argc, char **argv) 00167 { 00168 cerr<< 00169 "\nConnect (federate) two event channels.\n" 00170 "syntax: "<<(argc?argv[0]:"eventf")<<" OPTIONS [FROM_CHANNEL] [TO_CHANNEL]\n" 00171 "\n" 00172 "FROM/TO_CHANNEL: The event channels must be specified as a URI.\n" 00173 " This may be an IOR, or a corbaloc::: or corbaname::: URI.\n" 00174 "\n" 00175 "OPTIONS:\n" 00176 " -h display this help text\n" << endl; 00177 } 00178 00179 00180 // 00181 // Obtain object reference to EventChannel 00182 static CosEventChannelAdmin::EventChannel_ptr 00183 getChannel(const char* sior) 00184 { 00185 // convert URI from command line into object reference"; 00186 CORBA::Object_var obj =orb->string_to_object(sior); 00187 00188 // narrow object reference to event channel"; 00189 CosEventChannelAdmin::EventChannel_var channel = 00190 CosEventChannelAdmin::EventChannel::_narrow(obj); 00191 if(CORBA::is_nil(channel)) 00192 throw CORBA::OBJECT_NOT_EXIST(); 00193 00194 return channel._retn(); 00195 }