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 #include "naming.h"
00055
00056 static void usage(int argc, char **argv);
00057
00058 int
00059 main(int argc, char **argv)
00060 {
00061 int result =1;
00062
00063
00064
00065 #if defined(HAVE_OMNIORB4)
00066 CORBA::ORB_ptr orb = CORBA::ORB_init(argc,argv,"omniORB4");
00067 #else
00068 CORBA::ORB_ptr orb = CORBA::ORB_init(argc,argv,"omniORB3");
00069 #endif
00070
00071
00072 int c;
00073
00074 CosNaming::Name ecName =str2name("EventChannel");
00075
00076 while ((c = getopt(argc,argv,"n:h")) != EOF)
00077 {
00078 switch (c)
00079 {
00080 case 'n': ecName=str2name(optarg);
00081 break;
00082
00083 case 'h': usage(argc,argv);
00084 exit(0);
00085
00086 default : usage(argc,argv);
00087 exit(-1);
00088 }
00089 }
00090
00091
00092
00093
00094 const char* action ="start";
00095 try
00096 {
00097 CORBA::Object_var obj;
00098
00099
00100
00101
00102 if(optind<argc)
00103 {
00104 action="convert URI from command line into object reference";
00105 obj=orb->string_to_object(argv[optind]);
00106 }
00107 else
00108 {
00109
00110
00111 action="resolve initial reference 'NameService'";
00112 obj=orb->resolve_initial_references("NameService");
00113 CosNaming::NamingContext_var rootContext=
00114 CosNaming::NamingContext::_narrow(obj);
00115 if(CORBA::is_nil(rootContext))
00116 throw CORBA::OBJECT_NOT_EXIST();
00117
00118
00119
00120 action="find Event Channel in naming service";
00121 obj=rootContext->resolve(ecName);
00122
00123
00124
00125 action="unbind Event Channel from naming service";
00126 rootContext->unbind(ecName);
00127 }
00128
00129 action="narrow object reference to event channel";
00130 CosEventChannelAdmin::EventChannel_var channel =
00131 CosEventChannelAdmin::EventChannel::_narrow(obj);
00132 if(CORBA::is_nil(channel))
00133 throw CORBA::OBJECT_NOT_EXIST();
00134
00135
00136
00137 action="destroy Event Channel";
00138 channel->destroy();
00139
00140
00141
00142 action="destroy orb";
00143 orb->destroy();
00144
00145
00146
00147 result=0;
00148
00149 }
00150 catch(CORBA::ORB::InvalidName& ex) {
00151 cerr<<"Failed to "<<action<<". ORB::InvalidName"<<endl;
00152 }
00153 catch(CosNaming::NamingContext::InvalidName& ex) {
00154 cerr<<"Failed to "<<action<<". NamingContext::InvalidName"<<endl;
00155 }
00156 catch(CosNaming::NamingContext::NotFound& ex) {
00157 cerr<<"Failed to "<<action<<". NamingContext::NotFound"<<endl;
00158 }
00159 catch(CosNaming::NamingContext::CannotProceed& ex) {
00160 cerr<<"Failed to "<<action<<". NamingContext::CannotProceed"<<endl;
00161 }
00162 catch(CORBA::TRANSIENT& ex) {
00163 cerr<<"Failed to "<<action<<". TRANSIENT"<<endl;
00164 }
00165 catch(CORBA::OBJECT_NOT_EXIST& ex) {
00166 cerr<<"Failed to "<<action<<". OBJECT_NOT_EXIST"<<endl;
00167 }
00168 catch(CORBA::SystemException& ex) {
00169 cerr<<"Failed to "<<action<<".";
00170 #if defined(HAVE_OMNIORB4)
00171 cerr<<" "<<ex._name();
00172 if(ex.NP_minorString())
00173 cerr<<" ("<<ex.NP_minorString()<<")";
00174 #endif
00175 cerr<<endl;
00176 }
00177 catch(CORBA::Exception& ex) {
00178 cerr<<"Failed to "<<action<<"."
00179 #if defined(HAVE_OMNIORB4)
00180 " "<<ex._name()
00181 #endif
00182 <<endl;
00183 }
00184
00185 return result;
00186 }
00187
00188 static void
00189 usage(int argc, char **argv)
00190 {
00191 cerr<<
00192 "\nDestroy an EventChannel.\n"
00193 "syntax: "<<(argc?argv[0]:"rmeventc")<<" OPTIONS [CHANNEL_URI]\n"
00194 "\n"
00195 "CHANNEL_URI: The event channel may be specified as a URI.\n"
00196 " This may be an IOR, or a corbaloc::: or corbaname::: URI.\n"
00197 "\n"
00198 "OPTIONS: DEFAULT:\n"
00199 " -n NAME channel name (if URI is not specified) [\"EventChannel\"]\n"
00200 " -h display this help text\n" << endl;
00201 }
00202