Back to index

salome-kernel  6.5.0
RegistryConnexion.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 //  SALOME Registry : Registry server implementation
00024 //  File   : RegistryConnexion.cxx
00025 //  Author : Pascale NOYRET - Antoine YESSAYAN, EDF
00026 //  Module : SALOME
00027 //  $Header: /home/server/cvs/KERNEL/KERNEL_SRC/src/Registry/RegistryConnexion.cxx,v 1.8.2.1.14.2.12.1 2012-04-12 14:05:19 vsr Exp $
00028 //
00029 # include "Utils_ORB_INIT.hxx"
00030 # include "RegistryConnexion.hxx"
00031 # include "SALOME_NamingService.hxx"
00032 # include "Utils_Identity.hxx"
00033 # include "Utils_SINGLETON.hxx"
00034 # include "Utils_CommException.hxx"
00035 # include "OpUtil.hxx"
00036 # include "utilities.h"
00037 
00038 extern "C"
00039 {
00040 # include <stdio.h>
00041 }
00042 
00043 Registry::Components_var Connexion( int argc , char **argv , const char *ptrSessionName ) throw( CommException )
00044 {
00045         Registry::Components_var varComponents = 0 ;
00046         ASSERT(ptrSessionName) ;
00047         ASSERT(strlen(ptrSessionName)>0) ;
00048         const char *registryName = "Registry" ;
00049 
00050         try
00051         {
00052                 ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance() ;
00053                 ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting()) ;
00054                 CORBA::ORB_var &orb = init( argc , argv ) ;
00055         
00056                 SALOME_NamingService &naming = *SINGLETON_<SALOME_NamingService>::Instance() ;
00057                 ASSERT(SINGLETON_<SALOME_NamingService>::IsAlreadyExisting()) ;
00058                 naming.init_orb( orb ) ;
00059 
00060                 // Recuperation de la reference de l'objet
00061                 CORBA::Object_var object = naming.Resolve( registryName ) ;
00062                 if(CORBA::is_nil(object)) throw CommException( "unable to find the RegistryService" ) ;
00063 
00064                 // Specialisation de l'objet generique
00065                 varComponents = Registry::Components::_narrow( object ) ;
00066                 ASSERT(! CORBA::is_nil(varComponents)) ;
00067         }
00068         catch( ... )
00069         {
00070                 throw CommException ( "NamingService Connexion Error" ) ;
00071         }
00072         return varComponents ;
00073 }
00074 
00075 
00076 RegistryConnexion::RegistryConnexion( int argc , char **argv , const char *ior , const char *ptrSessionName, const char *componentName ): \
00077         _Ior(duplicate(ior)), _VarComponents( Connexion(argc,argv,ptrSessionName) ), _SessionName(ptrSessionName),_Name(""), _Id(0)
00078 {
00079         this->add( componentName ) ;
00080 }
00081 
00082 
00083 RegistryConnexion::RegistryConnexion( void ): _Ior(0), _VarComponents( 0 ), _Name(""), _Id(0)
00084 {
00085         INTERRUPTION(EXIT_FAILURE) ;
00086 }
00087 
00088 
00089 RegistryConnexion::~RegistryConnexion()
00090 {
00091         BEGIN_OF("RegistryConnexion::~RegistryConnexion()" ) ;
00092         if( _Id != 0 )
00093         {
00094                 ASSERT(_SessionName!="" ) ;
00095                 ASSERT(_Name!="" ) ;
00096                 _VarComponents->remove( _Id ) ;
00097         }
00098         _Id   = 0 ;
00099         delete [] (char*) _Ior;
00100         _Ior = 0;
00101         _SessionName = "";
00102         _Name = "" ;
00103         END_OF("RegistryConnexion::~RegistryConnexion()" ) ;
00104 }
00105 
00106 
00107 void RegistryConnexion::add( const char *aName )
00108 {
00109         ASSERT(_SessionName!="" ) ;
00110         ASSERT(_Name=="" ) ;
00111         ASSERT(_Id==0 ) ;
00112         ASSERT(aName) ;
00113         SCRUTE(aName) ;
00114         ASSERT(strlen( aName )>0) ;
00115 
00116         const Identity lesInfos( aName ) ;
00117         Registry::Infos infos ;
00118                 infos.name        = CORBA::string_dup( lesInfos.name() ) ;
00119                 infos.pid        = lesInfos.pid() ;
00120                 infos.machine        = CORBA::string_dup( lesInfos.host_char() ) ;
00121                 infos.adip        = CORBA::string_dup( lesInfos.adip() ) ;
00122                 infos.uid        = (long)lesInfos.uid() ;
00123                 infos.pwname        = CORBA::string_dup( lesInfos.pwname() ) ;
00124                 infos.tc_start        = lesInfos.start() ;
00125                 infos.tc_hello        = 0 ;
00126                 infos.tc_end        = 0 ;
00127                 infos.difftime        = 0 ;
00128                 infos.cdir        = CORBA::string_dup( lesInfos.rep() ) ;
00129                 infos.status        = -1 ;
00130                 infos.ior        = CORBA::string_dup(_Ior);
00131 
00132         ASSERT(!CORBA::is_nil(this->_VarComponents)) ;
00133 
00134         CORBA::ULong id = _VarComponents->add( infos ) ;
00135 
00136         SCRUTE(aName) ; SCRUTE(id) ;
00137         ASSERT(id) ;
00138 
00139         _Id   = id ;
00140         _Name = aName ;
00141 
00142         return ;
00143 }
00144 
00145 
00146 void RegistryConnexion::remove( void )
00147 {
00148         ASSERT(_Id>0) ;
00149         ASSERT(!CORBA::is_nil(this->_VarComponents)) ;
00150         _VarComponents->remove( _Id ) ;
00151 
00152         _Name = "" ;
00153         _Id   = 0 ;
00154 
00155         return ;
00156 }