1 // SALOME Registry : Registry server implementation
3 // Copyright (C) 2003 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.
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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : RegistryService.cxx
25 // Author : Pascale NOYRET - Antoine YESSAYAN, EDF
29 # include "RegistryService.hxx"
30 # include "OpUtil.hxx"
31 # include "utilities.h"
41 /* ------------------------------*/
42 /* Constructeurs et Destructeurs */
43 /* ------------------------------*/
45 RegistryService::RegistryService( void ) : _SessionName(0), _Compteur(0)
47 MESSAGE("Passage dans RegistryService::RegistryService()") ;
52 RegistryService::~RegistryService()
54 BEGIN_OF("RegistryService::~RegistryService()") ;
55 map<int,client_infos *>::iterator im;
56 for (im=_reg.begin();im!=_reg.end(); im++)
58 const client_infos &lesInfos = *(*im).second ;
59 MESSAGE("Deletion") ; SCRUTE( lesInfos._name ) ;
62 ASSERT(_reg.size()==0) ;
63 for (im=_fin.begin();im!=_fin.end(); im++)
65 const client_infos &lesInfos = *(*im).second ;
66 MESSAGE("Deletion") ; SCRUTE( lesInfos._name ) ;
69 ASSERT(_fin.size()==0) ;
73 delete [] _SessionName ;
76 END_OF("RegistryService::~RegistryService()") ;
79 /* ------------------------------*/
81 /* ------------------------------*/
83 CORBA::ULong RegistryService::size ( void )
85 ASSERT(_SessionName) ;
86 ASSERT(strlen(_SessionName)>0) ;
91 CORBA::ULong RegistryService::add( const Registry::Infos & infos )
93 BEGIN_OF("RegistryService::add") ;
94 ASSERT(_SessionName) ;
95 ASSERT(strlen(_SessionName)>0) ;
96 client_infos *ptr_Component = new client_infos( infos ) ;
97 ASSERT(ptr_Component) ;
98 SCRUTE(ptr_Component->_name) ;
101 _reg[_Compteur]=ptr_Component;
103 END_OF("RegistryService::add") ;
104 return (CORBA::ULong)_Compteur ;
108 void RegistryService::remove( const CORBA::ULong id)
110 BEGIN_OF("RegistryService::remove") ;
112 ASSERT(_SessionName) ;
113 ASSERT(strlen(_SessionName)>0) ;
115 ASSERT(_reg.find(id)!=_reg.end())
116 _reg[id]->_status=TERMINATED;
117 _reg[id]->_ts_end = time(NULL) ;
120 SCRUTE(_fin.size()) ;
122 map<int,client_infos *>::iterator pos = _reg.find ( id ) ;
124 SCRUTE(_reg.size()) ;
125 SCRUTE(_fin.size()) ;
127 END_OF("RegistryService::remove") ;
133 void RegistryService::hello( const CORBA::ULong id )
135 BEGIN_OF("RegistryService::hello") ;
137 ASSERT(_SessionName) ;
138 ASSERT(strlen(_SessionName)>0) ;
140 ASSERT(_reg.find(id)!=_reg.end())
141 _reg[id]->_ts_hello = time(NULL) ;
143 END_OF("RegistryService::hello") ;
148 void RegistryService::end( void )
150 ASSERT(_SessionName) ;
151 ASSERT(strlen(_SessionName)>0) ;
152 BEGIN_OF( "RegistryService::end( void )" ) ;
153 exit( EXIT_SUCCESS ) ;
157 Registry::AllInfos* RegistryService::getall( void )
159 ASSERT(_SessionName) ;
160 ASSERT(strlen(_SessionName)>0) ;
161 return RegistryService::makeseq(_reg) ;
164 Registry::AllInfos* RegistryService::history( void )
166 ASSERT(_SessionName) ;
167 ASSERT(strlen(_SessionName)>0) ;
168 return RegistryService::makeseq(_fin) ;
171 Registry::AllInfos* RegistryService::makeseq(map<int,client_infos *> &mymap )
175 Registry::AllInfos *all = new Registry::AllInfos ;
177 const int RegLength = mymap.size();
178 all->length(RegLength);
180 map<int,client_infos *>::iterator im;
181 for (im=mymap.begin();im!=mymap.end(); im++)
184 Registry::Infos &infos = (*all)[i] ;
185 const client_infos &lesInfos = *(*im).second ;
186 infos.name = CORBA::string_dup( lesInfos._name ) ;
187 infos.pid = lesInfos._pid ;
188 infos.pwname = lesInfos._pwname ;
189 infos.machine = CORBA::string_dup( lesInfos._machine ) ;
190 infos.adip = CORBA::string_dup( lesInfos._adip ) ;
191 infos.uid = lesInfos._uid ;
192 infos.tc_start = lesInfos._ts_start + lesInfos._difftime ;
193 infos.tc_hello = lesInfos._ts_hello + lesInfos._difftime ;
194 infos.tc_end = lesInfos._ts_end + lesInfos._difftime ;
195 infos.difftime = lesInfos._difftime ;
196 infos.cdir = CORBA::string_dup( lesInfos._cdir ) ;
197 infos.status = lesInfos._status ;
206 /* ------------------------------*/
208 /* ------------------------------*/
210 RegistryService::client_infos::client_infos( const Registry::Infos &infos ):\
211 _ior(duplicate(infos.ior)),\
212 _name(duplicate(infos.name)),\
214 _machine(duplicate(infos.machine)),\
215 _adip(duplicate(infos.adip)),\
217 _pwname(duplicate(infos.pwname)),\
218 _ts_start(time(NULL)),\
219 _difftime(infos.tc_start - _ts_start),\
220 _cdir(duplicate(infos.cdir)),\
221 _ts_hello(_ts_start),\
229 RegistryService::client_infos::~client_infos()
231 delete [] (char*)_ior ; (char*&)_ior = NULL ;
232 delete [] (char*)_name ; (char*&)_name = NULL ;
233 delete [] (char*)_machine ; (char*&)_machine = NULL ;
234 delete [] (char*)_pwname ; (char*&)_pwname = NULL ;
235 delete [] (char*)_adip ; (char*&)_adip = NULL ;
236 delete [] (char*)_cdir ; (char*&)_cdir = NULL ;
239 void RegistryService::SessionName( const char *sessionName )
241 ASSERT(sessionName) ;
242 ASSERT(strlen(sessionName)>0) ;
243 _SessionName = duplicate(sessionName) ;
246 void RegistryService::ping()
248 MESSAGE(" RegistryService::ping() pid "<< getpid());