Salome HOME
updated copyright message
[modules/kernel.git] / src / Registry / RegistryConnexion.cxx
1 // Copyright (C) 2007-2023  CEA, EDF, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 //  SALOME Registry : Registry server implementation
24 //  File   : RegistryConnexion.cxx
25 //  Author : Pascale NOYRET - Antoine YESSAYAN, EDF
26 //  Module : SALOME
27 //  $Header$
28 //
29 # include "RegistryConnexion.hxx"
30 # include "SALOME_NamingService.hxx"
31 # include "Utils_Identity.hxx"
32 # include "Utils_CommException.hxx"
33 # include "OpUtil.hxx"
34 # include "utilities.h"
35
36 # include <cstdio>
37
38 Registry::Components_var Connexion(SALOME_NamingService_Abstract *naming)
39 {
40         Registry::Components_var varComponents = 0 ;
41         const char *registryName = "Registry" ;
42
43         try
44         {
45                 // Recuperation de la reference de l'objet
46                 CORBA::Object_var object = naming->Resolve( registryName ) ;
47                 if(CORBA::is_nil(object)) throw CommException( "unable to find the RegistryService" ) ;
48
49                 // Specialisation de l'objet generique
50                 varComponents = Registry::Components::_narrow( object ) ;
51                 ASSERT(! CORBA::is_nil(varComponents)) ;
52         }
53         catch( ... )
54         {
55                 throw CommException ( "NamingService Connexion Error" ) ;
56         }
57         return varComponents ;
58 }
59
60
61 RegistryConnexion::RegistryConnexion(const char *ior , const char *ptrSessionName, const char *componentName, SALOME_NamingService_Abstract *ns ): \
62         _Ior(duplicate(ior)), _VarComponents( Connexion(ns) ), _SessionName(ptrSessionName),_Name(""), _Id(0)
63 {
64         this->add( componentName ) ;
65 }
66
67
68 RegistryConnexion::RegistryConnexion( void ): _Ior(0), _VarComponents( 0 ), _Name(""), _Id(0)
69 {
70         INTERRUPTION(EXIT_FAILURE) ;
71 }
72
73
74 RegistryConnexion::~RegistryConnexion()
75 {
76         BEGIN_OF("RegistryConnexion::~RegistryConnexion()" ) ;
77         if( _Id != 0 )
78         {
79                 ASSERT(_SessionName!="" ) ;
80                 ASSERT(_Name!="" ) ;
81                 _VarComponents->remove( _Id ) ;
82         }
83         _Id   = 0 ;
84         delete [] (char*) _Ior;
85         _Ior = 0;
86         _SessionName = "";
87         _Name = "" ;
88         END_OF("RegistryConnexion::~RegistryConnexion()" ) ;
89 }
90
91
92 void RegistryConnexion::add( const char *aName )
93 {
94         ASSERT(_SessionName!="" ) ;
95         ASSERT(_Name=="" ) ;
96         ASSERT(_Id==0 ) ;
97         ASSERT(aName) ;
98         SCRUTE(aName) ;
99         ASSERT(strlen( aName )>0) ;
100
101         const Identity lesInfos( aName ) ;
102         Registry::Infos infos ;
103                 infos.name        = CORBA::string_dup( lesInfos.name() ) ;
104                 infos.pid         = lesInfos.pid() ;
105                 infos.machine     = CORBA::string_dup( lesInfos.host_char() ) ;
106                 infos.adip        = CORBA::string_dup( lesInfos.adip() ) ;
107                 infos.uid         = (CORBA::Long)lesInfos.uid() ; //!< TODO: pointer truncation from const PSID to long
108                 infos.pwname      = CORBA::string_dup( lesInfos.pwname() ) ;
109                 infos.tc_start    = (CORBA::Long)lesInfos.start() ; //!< TODO: conversation from const time_t to CORBA::Long
110                 infos.tc_hello    = 0 ;
111                 infos.tc_end      = 0 ;
112                 infos.difftime    = 0 ;
113                 infos.cdir        = CORBA::string_dup( lesInfos.rep() ) ;
114                 infos.status      = -1 ;
115                 infos.ior         = CORBA::string_dup(_Ior);
116
117         ASSERT(!CORBA::is_nil(this->_VarComponents)) ;
118
119         CORBA::ULong id = _VarComponents->add( infos ) ;
120
121         SCRUTE(aName) ; SCRUTE(id) ;
122         ASSERT(id) ;
123
124         _Id   = id ;
125         _Name = aName ;
126
127         return ;
128 }
129
130
131 void RegistryConnexion::remove( void )
132 {
133         ASSERT(_Id>0) ;
134         ASSERT(!CORBA::is_nil(this->_VarComponents)) ;
135         _VarComponents->remove( _Id ) ;
136
137         _Name = "" ;
138         _Id   = 0 ;
139
140         return ;
141 }