2 //=============================================================================
3 // File : RegistryConnexion.cxx
4 // Created : Mon Nov 5 17:26:23 CET 2001
5 // Author : Pascale NOYRET - Antoine YESSAYAN, EDF
7 // Copyright : EDF 2001
9 //=============================================================================
12 # include "Utils_ORB_INIT.hxx"
13 # include "RegistryConnexion.hxx"
14 # include "SALOME_NamingService.hxx"
15 # include "Utils_Identity.hxx"
16 # include "Utils_SINGLETON.hxx"
17 # include "Utils_CommException.hxx"
18 # include "OpUtil.hxx"
19 # include "utilities.h"
27 Registry::Components_var Connexion( int argc , char **argv , const char *ptrSessionName ) throw( CommException )
29 Registry::Components_var varComponents = 0 ;
30 ASSERT(ptrSessionName) ;
31 ASSERT(strlen(ptrSessionName)>0) ;
32 const char *registryName = "Registry" ;
36 ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance() ;
37 ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting()) ;
38 CORBA::ORB_var &orb = init( argc , argv ) ;
40 SALOME_NamingService &naming = *SINGLETON_<SALOME_NamingService>::Instance() ;
41 ASSERT(SINGLETON_<SALOME_NamingService>::IsAlreadyExisting()) ;
42 naming.init_orb( orb ) ;
44 // Recuperation de la reference de l'objet
45 CORBA::Object_var object = naming.Resolve( registryName ) ;
46 if(CORBA::is_nil(object)) throw CommException( "unable to find the RegistryService" ) ;
48 // Specialisation de l'objet generique
49 varComponents = Registry::Components::_narrow( object ) ;
50 ASSERT(! CORBA::is_nil(varComponents)) ;
54 throw CommException ( "NamingService Connexion Error" ) ;
56 return varComponents ;
60 RegistryConnexion::RegistryConnexion( int argc , char **argv , const char *ior , const char *ptrSessionName, const char *componentName ): \
61 _Ior(duplicate(ior)), _VarComponents( Connexion(argc,argv,ptrSessionName) ), _SessionName(ptrSessionName),_Name(""), _Id(0)
63 this->add( componentName ) ;
67 RegistryConnexion::RegistryConnexion( void ): _Ior(0), _VarComponents( 0 ), _Name(""), _Id(0)
69 INTERRUPTION(EXIT_FAILURE) ;
73 RegistryConnexion::~RegistryConnexion()
75 BEGIN_OF("RegistryConnexion::~RegistryConnexion()" ) ;
78 ASSERT(_SessionName!="" ) ;
80 _VarComponents->remove( _Id ) ;
87 END_OF("RegistryConnexion::~RegistryConnexion()" ) ;
91 void RegistryConnexion::add( const char *aName )
93 ASSERT(_SessionName!="" ) ;
98 ASSERT(strlen( aName )>0) ;
100 const Identity lesInfos( aName ) ;
101 Registry::Infos infos ;
102 infos.name = CORBA::string_dup( lesInfos.name() ) ;
103 infos.pid = lesInfos.pid() ;
104 infos.machine = CORBA::string_dup( lesInfos.host_char() ) ;
105 infos.adip = CORBA::string_dup( lesInfos.adip() ) ;
106 infos.uid = lesInfos.uid() ;
107 infos.pwname = CORBA::string_dup( lesInfos.pwname() ) ;
108 infos.tc_start = lesInfos.start() ;
112 infos.cdir = CORBA::string_dup( lesInfos.rep() ) ;
114 infos.ior = CORBA::string_dup(_Ior);
116 ASSERT(!CORBA::is_nil(this->_VarComponents)) ;
118 CORBA::ULong id = _VarComponents->add( infos ) ;
120 SCRUTE(aName) ; SCRUTE(id) ;
130 void RegistryConnexion::remove( void )
133 ASSERT(!CORBA::is_nil(this->_VarComponents)) ;
134 _VarComponents->remove( _Id ) ;