Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class 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     // Clean up nicely.
00142     action="destroy orb";
00143     orb->destroy();
00144 
00145     //
00146     // If we get here, then everything has worked OK.
00147     result=0;
00148 
00149   }
00150   catch(CORBA::ORB::InvalidName& ex) { // resolve_initial_references
00151      cerr<<"Failed to "<<action<<". ORB::InvalidName"<<endl;
00152   }
00153   catch(CosNaming::NamingContext::InvalidName& ex) { // resolve
00154      cerr<<"Failed to "<<action<<". NamingContext::InvalidName"<<endl;
00155   }
00156   catch(CosNaming::NamingContext::NotFound& ex) { // resolve
00157      cerr<<"Failed to "<<action<<". NamingContext::NotFound"<<endl;
00158   }
00159   catch(CosNaming::NamingContext::CannotProceed& ex) { // resolve
00160      cerr<<"Failed to "<<action<<". NamingContext::CannotProceed"<<endl;
00161   }
00162   catch(CORBA::TRANSIENT& ex) { // _narrow()
00163      cerr<<"Failed to "<<action<<". TRANSIENT"<<endl;
00164   }
00165   catch(CORBA::OBJECT_NOT_EXIST& ex) { // _narrow()
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 

Generated on Fri Aug 26 20:56:14 2005 for OmniEvents by  doxygen 1.4.3-20050530