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