]> SALOME platform Git repositories - modules/kernel.git/blob - src/Registry/RegistryConnexion.cxx
Salome HOME
merge from branch BR_V5_DEV
[modules/kernel.git] / src / Registry / RegistryConnexion.cxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, 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.
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 //  SALOME Registry : Registry server implementation
23 //  File   : RegistryConnexion.cxx
24 //  Author : Pascale NOYRET - Antoine YESSAYAN, EDF
25 //  Module : SALOME
26 //  $Header$
27 //
28 # include "Utils_ORB_INIT.hxx"
29 # include "RegistryConnexion.hxx"
30 # include "SALOME_NamingService.hxx"
31 # include "Utils_Identity.hxx"
32 # include "Utils_SINGLETON.hxx"
33 # include "Utils_CommException.hxx"
34 # include "OpUtil.hxx"
35 # include "utilities.h"
36
37 extern "C"
38 {
39 # include <stdio.h>
40 }
41 using namespace std;
42
43
44 Registry::Components_var Connexion( int argc , char **argv , const char *ptrSessionName ) throw( CommException )
45 {
46         Registry::Components_var varComponents = 0 ;
47         ASSERT(ptrSessionName) ;
48         ASSERT(strlen(ptrSessionName)>0) ;
49         const char *registryName = "Registry" ;
50
51         try
52         {
53                 ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance() ;
54                 ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting()) ;
55                 CORBA::ORB_var &orb = init( argc , argv ) ;
56         
57                 SALOME_NamingService &naming = *SINGLETON_<SALOME_NamingService>::Instance() ;
58                 ASSERT(SINGLETON_<SALOME_NamingService>::IsAlreadyExisting()) ;
59                 naming.init_orb( orb ) ;
60
61                 // Recuperation de la reference de l'objet
62                 CORBA::Object_var object = naming.Resolve( registryName ) ;
63                 if(CORBA::is_nil(object)) throw CommException( "unable to find the RegistryService" ) ;
64
65                 // Specialisation de l'objet generique
66                 varComponents = Registry::Components::_narrow( object ) ;
67                 ASSERT(! CORBA::is_nil(varComponents)) ;
68         }
69         catch( ... )
70         {
71                 throw CommException ( "NamingService Connexion Error" ) ;
72         }
73         return varComponents ;
74 }
75
76
77 RegistryConnexion::RegistryConnexion( int argc , char **argv , const char *ior , const char *ptrSessionName, const char *componentName ): \
78         _Ior(duplicate(ior)), _VarComponents( Connexion(argc,argv,ptrSessionName) ), _SessionName(ptrSessionName),_Name(""), _Id(0)
79 {
80         this->add( componentName ) ;
81 }
82
83
84 RegistryConnexion::RegistryConnexion( void ): _Ior(0), _VarComponents( 0 ), _Name(""), _Id(0)
85 {
86         INTERRUPTION(EXIT_FAILURE) ;
87 }
88
89
90 RegistryConnexion::~RegistryConnexion()
91 {
92         BEGIN_OF("RegistryConnexion::~RegistryConnexion()" ) ;
93         if( _Id != 0 )
94         {
95                 ASSERT(_SessionName!="" ) ;
96                 ASSERT(_Name!="" ) ;
97                 _VarComponents->remove( _Id ) ;
98         }
99         _Id   = 0 ;
100 #ifndef WIN32
101         delete [] _Ior;
102 #else
103         delete [] (char*) _Ior;
104 #endif
105         _Ior = 0;
106         _SessionName = "";
107         _Name = "" ;
108         END_OF("RegistryConnexion::~RegistryConnexion()" ) ;
109 }
110
111
112 void RegistryConnexion::add( const char *aName )
113 {
114         ASSERT(_SessionName!="" ) ;
115         ASSERT(_Name=="" ) ;
116         ASSERT(_Id==0 ) ;
117         ASSERT(aName) ;
118         SCRUTE(aName) ;
119         ASSERT(strlen( aName )>0) ;
120
121         const Identity lesInfos( aName ) ;
122         Registry::Infos infos ;
123                 infos.name      = CORBA::string_dup( lesInfos.name() ) ;
124                 infos.pid       = lesInfos.pid() ;
125                 infos.machine   = CORBA::string_dup( lesInfos.host_char() ) ;
126                 infos.adip      = CORBA::string_dup( lesInfos.adip() ) ;
127                 infos.uid       = (long)lesInfos.uid() ;
128                 infos.pwname    = CORBA::string_dup( lesInfos.pwname() ) ;
129                 infos.tc_start  = lesInfos.start() ;
130                 infos.tc_hello  = 0 ;
131                 infos.tc_end    = 0 ;
132                 infos.difftime  = 0 ;
133                 infos.cdir      = CORBA::string_dup( lesInfos.rep() ) ;
134                 infos.status    = -1 ;
135                 infos.ior       = CORBA::string_dup(_Ior);
136
137         ASSERT(!CORBA::is_nil(this->_VarComponents)) ;
138
139         CORBA::ULong id = _VarComponents->add( infos ) ;
140
141         SCRUTE(aName) ; SCRUTE(id) ;
142         ASSERT(id) ;
143
144         _Id   = id ;
145         _Name = aName ;
146
147         return ;
148 }
149
150
151 void RegistryConnexion::remove( void )
152 {
153         ASSERT(_Id>0) ;
154         ASSERT(!CORBA::is_nil(this->_VarComponents)) ;
155         _VarComponents->remove( _Id ) ;
156
157         _Name = "" ;
158         _Id   = 0 ;
159
160         return ;
161 }