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

orb.cc

00001 /*
00002 *  Name:      orb.cc
00003 *  Author:    Rafael Jesus Alcantara Perez
00004 *  Summary:   CORBA ORB class
00005 *  Date:      $Date: 2003/04/14 00:18:35 $
00006 *  Revision:  $Revision: 1.1 $
00007 *
00008 *  Copyright (C) 2001-2002  Rafael Jesus Alcantara Perez <rafa@dedalo-ing.com>
00009 *
00010 *  This program is free software; you can redistribute it and/or modify
00011 *  it under the terms of the GNU General Public License as published by
00012 *  the Free Software Foundation; either version 2 of the License, or
00013 *  (at your option) any later version.
00014 *
00015 *  This program 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
00018 *  GNU General Public License for more details.
00019 *
00020 *  You should have received a copy of the GNU General Public License
00021 *  along with this program; if not, write to the Free Software
00022 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
00023 *  MA 02111-1307, USA.
00024 */
00025 
00026 #include <mpcl/net/corba/exceptions.hh>
00027 #include <mpcl/net/corba/orb.hh>
00028 
00029 
00030 //
00031 //  C O N S T R U C T O R S
00032 //
00033 
00034 mpcl::net::corba::TOrb::
00035 TOrb (int iPARAMETER_COUNT, const char** ppkcPARAMETERS) :
00036   gIsColocated        (false)                            ,
00037   gHasNameService     (false)                            ,
00038   qtOrb               ()                                 ,
00039   qtPoa               ()                                 ,
00040   qtPoaManager        ()                                 ,
00041   qtRootNamingContext ()
00042 {
00043 
00044   CORBA::Object_var   qtObject;
00045 
00046   //
00047   //  Obtains object references for the root POA and the COS Naming Service.
00048   //
00049   qtOrb        = CORBA::ORB_init (iPARAMETER_COUNT, const_cast<char**> (ppkcPARAMETERS));
00050   qtObject     = qtOrb->resolve_initial_references ("RootPOA");
00051   qtPoa        = PortableServer::POA::_narrow (qtObject);
00052   qtPoaManager = qtPoa->the_POAManager();
00053   // <FIXME id="NameService" comment="the only exception catched should be CORBA::ORB::InvalidName">
00054   try
00055   {
00056     qtObject            = qtOrb->resolve_initial_references ("NameService");
00057     qtRootNamingContext = CosNaming::NamingContext::_narrow (qtObject);
00058     gHasNameService     = true;
00059   }
00060   //
00061   //  Silently ignores COS Naming Service failure.
00062   //
00063   catch (const CORBA::ORB::InvalidName&) {}
00064   catch (const CORBA::SystemException&) {}
00065   // </FIXME>
00066 
00067 }  // TOrb()
00068 
00069 
00070 CosNaming::NamingContext_var mpcl::net::corba::TOrb::
00071 bindContext ( CosNaming::NamingContext_var& rqtNAMING_CONTEXT ,
00072               const text::TString&          rkyCONTEXT_NAME   )
00073 {
00074 
00075   CosNaming::NamingContext_var   qtNamingContext;
00076 
00077   if ( !gHasNameService )
00078   {
00079     throw TNoNameServiceException ("can not bind naming context", __FILE__, __LINE__);
00080   }
00081   else
00082   {
00083     CosNaming::Name   tContextName;
00084 
00085     tContextName.length (1);
00086     tContextName [0].id   = rkyCONTEXT_NAME.c_str();
00087     tContextName [0].kind = "";
00088     try
00089     {
00090       //
00091       //  Binds the context to root.
00092       //
00093       qtNamingContext = rqtNAMING_CONTEXT->bind_new_context (tContextName);
00094     }
00095     catch (const CosNaming::NamingContext::AlreadyBound&)
00096     {
00097       //
00098       //  If the context already exists,  this exception will be raised.  In this
00099       //  case, just  resolve the  name and assign  qtNamingContext to the object
00100       //  returned.
00101       //
00102       CORBA::Object_var   qtObject = rqtNAMING_CONTEXT->resolve (tContextName);
00103 
00104       qtNamingContext = CosNaming::NamingContext::_narrow (qtObject);
00105       if( CORBA::is_nil (qtNamingContext) )
00106       {
00107         throw TNarrowFailedException ("on naming context", __FILE__, __LINE__);
00108       }
00109     }
00110   }
00111   return qtNamingContext;
00112 
00113 }  // bindContext()

Generated on Mon Oct 13 02:35:23 2003 for MPCL by doxygen1.2.18