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

naming.cc

Go to the documentation of this file.
00001 // -*- Mode: C++; -*-
00002 //                            Package   : omniEvents
00003 // naming.cc                  Created   : 1/10/99
00004 //                            Author    : Paul Nader (pwn)
00005 //
00006 //    Copyright (C) 1998 Paul Nader.
00007 //
00008 //    This file is part of the omniEvents application.
00009 //
00010 //    omniEvents is free software; you can redistribute it and/or
00011 //    modify it under the terms of the GNU Lesser General Public
00012 //    License as published by the Free Software Foundation; either
00013 //    version 2.1 of the License, or (at your option) any later version.
00014 //
00015 //    omniEvents is distributed in the hope that it will be useful,
00016 //    but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018 //    Lesser General Public License for more details.
00019 //
00020 //    You should have received a copy of the GNU Lesser General Public
00021 //    License along with this library; if not, write to the Free Software
00022 //    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00023 //
00024 // Description:
00025 //
00026 //    naming Service Utility functions.
00027 //
00028 
00029 /*
00030   $Log: naming.cc,v $
00031   Revision 1.3  2003/12/01 09:03:13  alextingle
00032   Now reports more specific exceptions (only with omniORB4).
00033 
00034   Revision 1.2  2003/11/03 22:45:31  alextingle
00035   Removed all platform specific switches. Now uses autoconf, config.h.
00036 
00037   Revision 1.1.1.1  2002/09/25 19:00:35  shamus13
00038   Import of OmniEvents source tree from release 2.1.1
00039 
00040   Revision 1.3  2000/09/26 08:44:58  naderp
00041   Added stdlib.h include for exit function.
00042 
00043   Revision 1.2  2000/09/04 03:45:52  naderp
00044   Changed headers.
00045 
00046   Revision 1.1  1999/11/01 17:00:16  naderp
00047   Initial revision
00048 
00049 */
00050 
00051 #include "naming.h"
00052 
00053 #include <stdio.h> // for sscanf
00054 
00055 #ifdef HAVE_IOMANIP
00056 #  include <iomanip>
00057 #else
00058 #  include <iomanip.h>
00059 #endif
00060 
00061 #ifdef HAVE_STDLIB_H
00062 #  include <stdlib.h> // for exit
00063 #endif
00064 
00065 CosNaming::NamingContext_ptr
00066 getRootNamingContext(CORBA::ORB_ptr orb)
00067 {
00068   CosNaming::NamingContext_ptr rootContext;
00069   try {
00070 
00071      // Get initial reference.
00072      CORBA::Object_var initServ;
00073      initServ = orb->resolve_initial_references("NameService");
00074 
00075      // Narrow the object returned by resolve_initial_references()
00076      // to a CosNaming::NamingContext object:
00077      rootContext = CosNaming::NamingContext::_narrow(initServ);
00078      if (CORBA::is_nil(rootContext))
00079      {
00080         cerr << "Failed to narrow naming context." << endl;
00081         exit(1);
00082      }
00083   }
00084   catch(CORBA::ORB::InvalidName& ex) {
00085      cerr << "Service required is invalid [does not exist]." << endl;
00086      exit(1);
00087   }
00088   catch (CORBA::COMM_FAILURE& ex)
00089   {
00090      cerr << "Caught system exception COMM_FAILURE, unable to find the "
00091           << "naming service." << endl;
00092      exit(1);
00093   }
00094   catch (omniORB::fatalException& ex) {
00095      cerr << "Caught omniORB fatal exception" << endl;
00096      throw;
00097   }
00098   catch (CORBA::SystemException& ex) {
00099      cerr<<"System exception while resolving the naming service"
00100 #ifdef HAVE_OMNIORB4
00101          <<": "<<ex._name()<<" ("<<ex.NP_minorString()<<")"
00102 #endif
00103          << endl;
00104      exit(1);
00105   }
00106   catch (CORBA::Exception& ex) {
00107      cerr<<"CORBA exception while resolving the naming service"
00108 #ifdef HAVE_OMNIORB4
00109          <<": "<<ex._name()
00110 #endif
00111          << endl;
00112      exit(1);
00113   }
00114   
00115   return rootContext;
00116 }
00117 
00118 ostream& operator<<(ostream& os, const CosNaming::Name &n)
00119 {
00120    long length = n.length();
00121    for (long l=0; l<length; l++)
00122    {
00123       os << "\"" << (const char *) n[l].id << "\"/\"" << (const char *) n[l].kind << "\" ";
00124    }
00125    return os;
00126 }
00127 
00128 void
00129 bindName2Object(CosNaming::NamingContext_ptr c,
00130                 const CosNaming::Name & n,
00131                 CORBA::Object_ptr obj)
00132 {
00133 
00134   try {
00135     c->bind(n, obj);
00136   }
00137   catch(CosNaming::NamingContext::AlreadyBound& ex)
00138   {
00139     // overwrite previously bound object
00140     c->rebind(n, obj);
00141   }
00142   catch (CORBA::COMM_FAILURE& ex)
00143   {
00144      cerr << "Caught system exception COMM_FAILURE, unable to contact the "
00145           << "naming service." << endl;
00146      exit(1);
00147   }
00148   catch (omniORB::fatalException& ex) {
00149      cerr << "Caught omniORB fatal exception binding " << n << endl;
00150      throw;
00151   }
00152   catch (CORBA::SystemException& ex) {
00153      cerr<<"System exception binding "<<n
00154 #ifdef HAVE_OMNIORB4
00155          <<": "<<ex._name()<<" ("<<ex.NP_minorString()<<")"
00156 #endif
00157          << endl;
00158      exit(1);
00159   }
00160   catch (CORBA::Exception& ex) {
00161      cerr<<"CORBA exception binding "<<n
00162 #ifdef HAVE_OMNIORB4
00163          <<": "<<ex._name()
00164 #endif
00165          << endl;
00166      exit(1);
00167   }
00168 
00169 
00170 }
00171 ostream& operator<<(ostream& os, const omniORB::objectKey &k)
00172 {
00173   omniORB::seqOctets* ostr = omniORB::keyToOctetSequence(k);
00174   //
00175   // Record current flags
00176   os << hex;
00177   for (unsigned int i = 0; i < ostr->length(); i++) {
00178     os << setfill('0') << setw(2) << (int)(*ostr)[i];
00179   }
00180   os << dec;
00181   delete ostr;
00182   return os;
00183 }
00184 
00185 
00186 void
00187 str2key(omniORB::objectKey& k, char *str)
00188 {
00189   int l = strlen(str) / 2;
00190   omniORB::seqOctets os(l);
00191   os.length(l);
00192   char* p = str;
00193   for (int i = 0; i < l; i++) {
00194     int n;
00195     sscanf(p,"%02x",&n);
00196     os[i] = n;
00197     p += 2;
00198   }
00199   k = omniORB::octetSequenceToKey(os);
00200   delete [] str;
00201 }
00202 
00203 

Generated on Fri Dec 12 10:53:02 2003 for OmniEvents by doxygen1.2.15