1 // Copyright (C) 2007-2020 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // SALOME Registry : Registry server implementation
24 // File : RegistryConnexion.cxx
25 // Author : Pascale NOYRET - Antoine YESSAYAN, EDF
29 # include "Utils_ORB_INIT.hxx"
30 # include "RegistryConnexion.hxx"
31 # include "SALOME_NamingService.hxx"
32 # include "Utils_Identity.hxx"
33 # include "Utils_SINGLETON.hxx"
34 # include "Utils_CommException.hxx"
35 # include "OpUtil.hxx"
36 # include "utilities.h"
43 Registry::Components_var Connexion( int argc , char **argv , const char */*ptrSessionName*/ )
45 Registry::Components_var varComponents = 0 ;
46 const char *registryName = "Registry" ;
50 ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance() ;
51 ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting()) ;
52 CORBA::ORB_var &orb = init( argc , argv ) ;
54 SALOME_NamingService &naming = *SINGLETON_<SALOME_NamingService>::Instance() ;
55 ASSERT(SINGLETON_<SALOME_NamingService>::IsAlreadyExisting()) ;
56 naming.init_orb( orb ) ;
58 // Recuperation de la reference de l'objet
59 CORBA::Object_var object = naming.Resolve( registryName ) ;
60 if(CORBA::is_nil(object)) throw CommException( "unable to find the RegistryService" ) ;
62 // Specialisation de l'objet generique
63 varComponents = Registry::Components::_narrow( object ) ;
64 ASSERT(! CORBA::is_nil(varComponents)) ;
68 throw CommException ( "NamingService Connexion Error" ) ;
70 return varComponents ;
74 RegistryConnexion::RegistryConnexion( int argc , char **argv , const char *ior , const char *ptrSessionName, const char *componentName ): \
75 _Ior(duplicate(ior)), _VarComponents( Connexion(argc,argv,ptrSessionName) ), _SessionName(ptrSessionName),_Name(""), _Id(0)
77 this->add( componentName ) ;
81 RegistryConnexion::RegistryConnexion( void ): _Ior(0), _VarComponents( 0 ), _Name(""), _Id(0)
83 INTERRUPTION(EXIT_FAILURE) ;
87 RegistryConnexion::~RegistryConnexion()
89 BEGIN_OF("RegistryConnexion::~RegistryConnexion()" ) ;
92 ASSERT(_SessionName!="" ) ;
94 _VarComponents->remove( _Id ) ;
97 delete [] (char*) _Ior;
101 END_OF("RegistryConnexion::~RegistryConnexion()" ) ;
105 void RegistryConnexion::add( const char *aName )
107 ASSERT(_SessionName!="" ) ;
112 ASSERT(strlen( aName )>0) ;
114 const Identity lesInfos( aName ) ;
115 Registry::Infos infos ;
116 infos.name = CORBA::string_dup( lesInfos.name() ) ;
117 infos.pid = lesInfos.pid() ;
118 infos.machine = CORBA::string_dup( lesInfos.host_char() ) ;
119 infos.adip = CORBA::string_dup( lesInfos.adip() ) ;
120 infos.uid = (CORBA::Long)lesInfos.uid() ; //!< TODO: pointer truncation from const PSID to long
121 infos.pwname = CORBA::string_dup( lesInfos.pwname() ) ;
122 infos.tc_start = (CORBA::Long)lesInfos.start() ; //!< TODO: conversation from const time_t to CORBA::Long
126 infos.cdir = CORBA::string_dup( lesInfos.rep() ) ;
128 infos.ior = CORBA::string_dup(_Ior);
130 ASSERT(!CORBA::is_nil(this->_VarComponents)) ;
132 CORBA::ULong id = _VarComponents->add( infos ) ;
134 SCRUTE(aName) ; SCRUTE(id) ;
144 void RegistryConnexion::remove( void )
147 ASSERT(!CORBA::is_nil(this->_VarComponents)) ;
148 _VarComponents->remove( _Id ) ;