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"
43 /* ------------------------------*/
44 /* Constructeurs et Destructeurs */
45 /* ------------------------------*/
47 RegistryService::RegistryService( void ) : _SessionName(0), _Compteur(0)
49 MESSAGE("Passage dans RegistryService::RegistryService()") ;
54 RegistryService::~RegistryService()
56 BEGIN_OF("RegistryService::~RegistryService()") ;
57 map<int,client_infos *>::iterator im;
58 for (im=_reg.begin();im!=_reg.end(); im++)
60 const client_infos &lesInfos = *(*im).second ;
61 MESSAGE("Deletion") ; SCRUTE( lesInfos._name ) ;
64 ASSERT(_reg.size()==0) ;
65 for (im=_fin.begin();im!=_fin.end(); im++)
67 const client_infos &lesInfos = *(*im).second ;
68 MESSAGE("Deletion") ; SCRUTE( lesInfos._name ) ;
71 ASSERT(_fin.size()==0) ;
76 delete [] _SessionName ;
78 delete [] (char*)_SessionName ;
82 END_OF("RegistryService::~RegistryService()") ;
85 /* ------------------------------*/
87 /* ------------------------------*/
89 CORBA::ULong RegistryService::size ( void )
91 ASSERT(_SessionName) ;
92 ASSERT(strlen(_SessionName)>0) ;
97 CORBA::ULong RegistryService::add( const Registry::Infos & infos )
99 BEGIN_OF("RegistryService::add") ;
100 ASSERT(_SessionName) ;
101 ASSERT(strlen(_SessionName)>0) ;
102 client_infos *ptr_Component = new client_infos( infos ) ;
103 ASSERT(ptr_Component) ;
104 SCRUTE(ptr_Component->_name) ;
107 _reg[_Compteur]=ptr_Component;
109 END_OF("RegistryService::add") ;
110 return (CORBA::ULong)_Compteur ;
114 void RegistryService::remove( const CORBA::ULong id)
116 void RegistryService::remove( CORBA::ULong id)
119 BEGIN_OF("RegistryService::remove") ;
121 ASSERT(_SessionName) ;
122 ASSERT(strlen(_SessionName)>0) ;
124 ASSERT(_reg.find(id)!=_reg.end())
125 _reg[id]->_status=TERMINATED;
126 _reg[id]->_ts_end = time(NULL) ;
129 SCRUTE(_fin.size()) ;
131 map<int,client_infos *>::iterator pos = _reg.find ( id ) ;
133 SCRUTE(_reg.size()) ;
134 SCRUTE(_fin.size()) ;
136 END_OF("RegistryService::remove") ;
142 void RegistryService::hello( const CORBA::ULong id )
144 void RegistryService::hello( CORBA::ULong id )
147 BEGIN_OF("RegistryService::hello") ;
149 ASSERT(_SessionName) ;
150 ASSERT(strlen(_SessionName)>0) ;
152 ASSERT(_reg.find(id)!=_reg.end())
153 _reg[id]->_ts_hello = time(NULL) ;
155 END_OF("RegistryService::hello") ;
160 void RegistryService::end( void )
162 ASSERT(_SessionName) ;
163 ASSERT(strlen(_SessionName)>0) ;
164 BEGIN_OF( "RegistryService::end( void )" ) ;
165 exit( EXIT_SUCCESS ) ;
169 Registry::AllInfos* RegistryService::getall( void )
171 ASSERT(_SessionName) ;
172 ASSERT(strlen(_SessionName)>0) ;
173 return RegistryService::makeseq(_reg) ;
176 Registry::AllInfos* RegistryService::history( void )
178 ASSERT(_SessionName) ;
179 ASSERT(strlen(_SessionName)>0) ;
180 return RegistryService::makeseq(_fin) ;
183 Registry::AllInfos* RegistryService::makeseq(map<int,client_infos *> &mymap )
187 Registry::AllInfos *all = new Registry::AllInfos ;
189 const int RegLength = mymap.size();
190 all->length(RegLength);
192 map<int,client_infos *>::iterator im;
193 for (im=mymap.begin();im!=mymap.end(); im++)
196 Registry::Infos &infos = (*all)[i] ;
197 const client_infos &lesInfos = *(*im).second ;
198 infos.name = CORBA::string_dup( lesInfos._name ) ;
199 infos.pid = lesInfos._pid ;
200 infos.pwname = lesInfos._pwname ;
201 infos.machine = CORBA::string_dup( lesInfos._machine ) ;
202 infos.adip = CORBA::string_dup( lesInfos._adip ) ;
203 infos.uid = lesInfos._uid ;
204 infos.tc_start = lesInfos._ts_start + lesInfos._difftime ;
205 infos.tc_hello = lesInfos._ts_hello + lesInfos._difftime ;
206 infos.tc_end = lesInfos._ts_end + lesInfos._difftime ;
207 infos.difftime = lesInfos._difftime ;
208 infos.cdir = CORBA::string_dup( lesInfos._cdir ) ;
209 infos.status = lesInfos._status ;
218 /* ------------------------------*/
220 /* ------------------------------*/
222 RegistryService::client_infos::client_infos( const Registry::Infos &infos ):\
223 _ior(duplicate(infos.ior)),\
224 _name(duplicate(infos.name)),\
226 _machine(duplicate(infos.machine)),\
227 _adip(duplicate(infos.adip)),\
229 _pwname(duplicate(infos.pwname)),\
230 _ts_start(time(NULL)),\
231 _difftime(infos.tc_start - _ts_start),\
232 _cdir(duplicate(infos.cdir)),\
233 _ts_hello(_ts_start),\
241 RegistryService::client_infos::~client_infos()
243 delete [] (char*)_ior ; (char*&)_ior = NULL ;
244 delete [] (char*)_name ; (char*&)_name = NULL ;
245 delete [] (char*)_machine ; (char*&)_machine = NULL ;
246 delete [] (char*)_pwname ; (char*&)_pwname = NULL ;
247 delete [] (char*)_adip ; (char*&)_adip = NULL ;
248 delete [] (char*)_cdir ; (char*&)_cdir = NULL ;
251 void RegistryService::SessionName( const char *sessionName )
253 ASSERT(sessionName) ;
254 ASSERT(strlen(sessionName)>0) ;
255 _SessionName = duplicate(sessionName) ;
258 void RegistryService::ping()
260 MESSAGE(" RegistryService::ping() pid "<< getpid());