00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
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>
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
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
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
00096
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
00128 action="destroy orb";
00129 orb->destroy();
00130
00131
00132
00133 result=0;
00134
00135 }
00136 catch(CORBA::TRANSIENT& ex) {
00137 cerr<<"Failed to "<<action<<". TRANSIENT"<<endl;
00138 }
00139 catch(CORBA::OBJECT_NOT_EXIST& ex) {
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
00180 static CosEventChannelAdmin::EventChannel_ptr
00181 getChannel(const char* sior)
00182 {
00183
00184 CORBA::Object_var obj =orb->string_to_object(sior);
00185
00186
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 }