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
31 # include "RegistryService.hxx"
32 # include "OpUtil.hxx"
33 # include "utilities.h"
42 /* ------------------------------*/
43 /* Constructeurs et Destructeurs */
44 /* ------------------------------*/
46 RegistryService::RegistryService( void ) : _SessionName(0), _Compteur(0)
48 MESSAGE("Passage dans RegistryService::RegistryService()") ;
53 RegistryService::~RegistryService()
55 BEGIN_OF("RegistryService::~RegistryService()") ;
56 map<int,client_infos *>::iterator im;
57 for (im=_reg.begin();im!=_reg.end(); im++)
59 const client_infos &lesInfos = *(*im).second ;
60 MESSAGE("Deletion") ; SCRUTE( lesInfos._name ) ;
63 ASSERT(_reg.size()==0) ;
64 for (im=_fin.begin();im!=_fin.end(); im++)
66 const client_infos &lesInfos = *(*im).second ;
67 MESSAGE("Deletion") ; SCRUTE( lesInfos._name ) ;
70 ASSERT(_fin.size()==0) ;
74 delete [] _SessionName ;
77 END_OF("RegistryService::~RegistryService()") ;
80 /* ------------------------------*/
82 /* ------------------------------*/
84 CORBA::ULong RegistryService::size ( void )
86 ASSERT(_SessionName) ;
87 ASSERT(strlen(_SessionName)>0) ;
92 CORBA::ULong RegistryService::add( const Registry::Infos & infos )
94 BEGIN_OF("RegistryService::add") ;
95 ASSERT(_SessionName) ;
96 ASSERT(strlen(_SessionName)>0) ;
97 client_infos *ptr_Component = new client_infos( infos ) ;
98 ASSERT(ptr_Component) ;
99 SCRUTE(ptr_Component->_name) ;
102 _reg[_Compteur]=ptr_Component;
104 END_OF("RegistryService::add") ;
105 return (CORBA::ULong)_Compteur ;
109 void RegistryService::remove( const CORBA::ULong id)
111 BEGIN_OF("RegistryService::remove") ;
113 ASSERT(_SessionName) ;
114 ASSERT(strlen(_SessionName)>0) ;
116 ASSERT(_reg.find(id)!=_reg.end())
117 _reg[id]->_status=TERMINATED;
118 _reg[id]->_ts_end = time(NULL) ;
121 SCRUTE(_fin.size()) ;
123 map<int,client_infos *>::iterator pos = _reg.find ( id ) ;
125 SCRUTE(_reg.size()) ;
126 SCRUTE(_fin.size()) ;
128 END_OF("RegistryService::remove") ;
134 void RegistryService::hello( const CORBA::ULong id )
136 BEGIN_OF("RegistryService::hello") ;
138 ASSERT(_SessionName) ;
139 ASSERT(strlen(_SessionName)>0) ;
141 ASSERT(_reg.find(id)!=_reg.end())
142 _reg[id]->_ts_hello = time(NULL) ;
144 END_OF("RegistryService::hello") ;
149 void RegistryService::end( void )
151 ASSERT(_SessionName) ;
152 ASSERT(strlen(_SessionName)>0) ;
153 BEGIN_OF( "RegistryService::end( void )" ) ;
154 exit( EXIT_SUCCESS ) ;
158 Registry::AllInfos* RegistryService::getall( void )
160 ASSERT(_SessionName) ;
161 ASSERT(strlen(_SessionName)>0) ;
162 return RegistryService::makeseq(_reg) ;
165 Registry::AllInfos* RegistryService::history( void )
167 ASSERT(_SessionName) ;
168 ASSERT(strlen(_SessionName)>0) ;
169 return RegistryService::makeseq(_fin) ;
172 Registry::AllInfos* RegistryService::makeseq(map<int,client_infos *> &mymap )
176 Registry::AllInfos *all = new Registry::AllInfos ;
178 const int RegLength = mymap.size();
179 all->length(RegLength);
181 map<int,client_infos *>::iterator im;
182 for (im=mymap.begin();im!=mymap.end(); im++)
185 Registry::Infos &infos = (*all)[i] ;
186 const client_infos &lesInfos = *(*im).second ;
187 infos.name = CORBA::string_dup( lesInfos._name ) ;
188 infos.pid = lesInfos._pid ;
189 infos.pwname = lesInfos._pwname ;
190 infos.machine = CORBA::string_dup( lesInfos._machine ) ;
191 infos.adip = CORBA::string_dup( lesInfos._adip ) ;
192 infos.uid = lesInfos._uid ;
193 infos.tc_start = lesInfos._ts_start + lesInfos._difftime ;
194 infos.tc_hello = lesInfos._ts_hello + lesInfos._difftime ;
195 infos.tc_end = lesInfos._ts_end + lesInfos._difftime ;
196 infos.difftime = lesInfos._difftime ;
197 infos.cdir = CORBA::string_dup( lesInfos._cdir ) ;
198 infos.status = lesInfos._status ;
207 /* ------------------------------*/
209 /* ------------------------------*/
211 RegistryService::client_infos::client_infos( const Registry::Infos &infos ):\
212 _ior(duplicate(infos.ior)),\
213 _name(duplicate(infos.name)),\
215 _machine(duplicate(infos.machine)),\
216 _adip(duplicate(infos.adip)),\
218 _pwname(duplicate(infos.pwname)),\
219 _ts_start(time(NULL)),\
220 _difftime(infos.tc_start - _ts_start),\
221 _cdir(duplicate(infos.cdir)),\
222 _ts_hello(_ts_start),\
230 RegistryService::client_infos::~client_infos()
232 delete [] (char*)_ior ; (char*&)_ior = NULL ;
233 delete [] (char*)_name ; (char*&)_name = NULL ;
234 delete [] (char*)_machine ; (char*&)_machine = NULL ;
235 delete [] (char*)_pwname ; (char*&)_pwname = NULL ;
236 delete [] (char*)_adip ; (char*&)_adip = NULL ;
237 delete [] (char*)_cdir ; (char*&)_cdir = NULL ;
240 void RegistryService::SessionName( const char *sessionName )
242 ASSERT(sessionName) ;
243 ASSERT(strlen(sessionName)>0) ;
244 _SessionName = duplicate(sessionName) ;
247 void RegistryService::ping()
249 MESSAGE(" RegistryService::ping() pid "<< getpid());