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 orb->destroy();
00129
00130
00131
00132 result=0;
00133
00134 }
00135 catch(CORBA::TRANSIENT& ex) {
00136 cerr<<"Failed to "<<action<<". TRANSIENT"<<endl;
00137 }
00138 catch(CORBA::OBJECT_NOT_EXIST& ex) {
00139 cerr<<"Failed to "<<action<<". OBJECT_NOT_EXIST"<<endl;
00140 }
00141 catch(CORBA::SystemException& ex) {
00142 cerr<<"Failed to "<<action<<".";
00143 #if defined(HAVE_OMNIORB4)
00144 cerr<<" "<<ex._name();
00145 if(ex.NP_minorString())
00146 cerr<<" ("<<ex.NP_minorString()<<")";
00147 #endif
00148 cerr<<endl;
00149 }
00150 catch(CORBA::Exception& ex) {
00151 cerr<<"Failed to "<<action<<"."
00152 #if defined(HAVE_OMNIORB4)
00153 " "<<ex._name()
00154 #endif
00155 <<endl;
00156 }
00157
00158 return result;
00159 }
00160
00161
00162 static void
00163 usage(int argc, char **argv)
00164 {
00165 cerr<<
00166 "\nConnect (federate) two event channels.\n"
00167 "syntax: "<<(argc?argv[0]:"eventf")<<" OPTIONS [FROM_CHANNEL] [TO_CHANNEL]\n"
00168 "\n"
00169 "FROM/TO_CHANNEL: The event channels must be specified as a URI.\n"
00170 " This may be an IOR, or a corbaloc::: or corbaname::: URI.\n"
00171 "\n"
00172 "OPTIONS:\n"
00173 " -h display this help text\n" << endl;
00174 }
00175
00176
00177
00178
00179 static CosEventChannelAdmin::EventChannel_ptr
00180 getChannel(const char* sior)
00181 {
00182
00183 CORBA::Object_var obj =orb->string_to_object(sior);
00184
00185
00186 CosEventChannelAdmin::EventChannel_var channel =
00187 CosEventChannelAdmin::EventChannel::_narrow(obj);
00188 if(CORBA::is_nil(channel))
00189 throw CORBA::OBJECT_NOT_EXIST();
00190
00191 return channel._retn();
00192 }