Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

rmeventc.cc

Go to the documentation of this file.
00001 //                            Package   : omniEvents
00002 // rmeventc.cc                Created   : 2003/12/21
00003 //                            Author    : Alex Tingle
00004 //
00005 //    Copyright (C) 2003 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 #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   // Start orb.
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   // Process Options
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   // Use one big try...catch block.
00093   // 'action' variable keeps track of what we're doing.
00094   const char* action ="start";
00095   try
00096   {
00097     CORBA::Object_var obj;
00098     
00099     //
00100     // Obtain object reference to EventChannel
00101     // (from command-line argument or from the Naming Service).
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       // Get Name Service root context.
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       // Obtain reference to the Event Channel.
00120       action="find Event Channel in naming service";
00121       obj=rootContext->resolve(ecName);
00122 
00123       //
00124       // Unbind the Channel's reference in the naming service.
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     // Destroy the EventChannel.
00137     action="destroy Event Channel";
00138     channel->destroy();
00139     
00140     //
00141     // If we get here, then everything has worked OK.
00142     result=0;
00143 
00144   }
00145   catch(CORBA::ORB::InvalidName& ex) { // resolve_initial_references
00146      cerr<<"Failed to "<<action<<". ORB::InvalidName"<<endl;
00147   }
00148   catch(CosNaming::NamingContext::InvalidName& ex) { // resolve
00149      cerr<<"Failed to "<<action<<". NamingContext::InvalidName"<<endl;
00150   }
00151   catch(CosNaming::NamingContext::NotFound& ex) { // resolve
00152      cerr<<"Failed to "<<action<<". NamingContext::NotFound"<<endl;
00153   }
00154   catch(CosNaming::NamingContext::CannotProceed& ex) { // resolve
00155      cerr<<"Failed to "<<action<<". NamingContext::CannotProceed"<<endl;
00156   }
00157   catch(CORBA::TRANSIENT& ex) { // _narrow()
00158      cerr<<"Failed to "<<action<<". TRANSIENT"<<endl;
00159   }
00160   catch(CORBA::OBJECT_NOT_EXIST& ex) { // _narrow()
00161      cerr<<"Failed to "<<action<<". OBJECT_NOT_EXIST"<<endl;
00162   }
00163   catch(CORBA::SystemException& ex) {
00164      cerr<<"Failed to "<<action<<".";
00165 #if defined(HAVE_OMNIORB4)
00166      cerr<<" "<<ex._name();
00167      if(ex.NP_minorString())
00168          cerr<<" ("<<ex.NP_minorString()<<")";
00169 #endif
00170      cerr<<endl;
00171   }
00172   catch(CORBA::Exception& ex) {
00173      cerr<<"Failed to "<<action<<"."
00174 #if defined(HAVE_OMNIORB4)
00175        " "<<ex._name()
00176 #endif
00177        <<endl;
00178   }
00179 
00180   return result;
00181 }
00182 
00183 static void
00184 usage(int argc, char **argv)
00185 {
00186   cerr<<
00187 "\nDestroy an EventChannel.\n"
00188 "syntax: "<<(argc?argv[0]:"rmeventc")<<" OPTIONS [CHANNEL_URI]\n"
00189 "\n"
00190 "CHANNEL_URI: The event channel may be specified as a URI.\n"
00191 " This may be an IOR, or a corbaloc::: or corbaname::: URI.\n"
00192 "\n"
00193 "OPTIONS:                                         DEFAULT:\n"
00194 " -n NAME  channel name (if URI is not specified)  [\"EventChannel\"]\n"
00195 " -h       display this help text\n" << endl;
00196 }
00197 

Generated on Fri Nov 19 17:42:21 2004 for OmniEvents by doxygen1.2.15