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