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.salome-platform.org/ or email : webmaster.salome@opencascade.com
24 // File : RegistryService.cxx
25 // Author : Pascale NOYRET - Antoine YESSAYAN, EDF
29 # include "RegistryService.hxx"
30 # include "OpUtil.hxx"
31 # include "utilities.h"
45 /* ------------------------------*/
46 /* Constructeurs et Destructeurs */
47 /* ------------------------------*/
49 RegistryService::RegistryService( void ) : _SessionName(0), _Compteur(0)
51 MESSAGE("Passage dans RegistryService::RegistryService()") ;
52 _orb = CORBA::ORB::_nil();
56 RegistryService::~RegistryService()
58 BEGIN_OF("RegistryService::~RegistryService()") ;
59 map<int,client_infos *>::iterator im;
60 for (im=_reg.begin();im!=_reg.end(); im++)
62 const client_infos &lesInfos = *(*im).second ;
63 MESSAGE("Deletion") ; SCRUTE( lesInfos._name ) ;
66 ASSERT(_reg.size()==0) ;
67 for (im=_fin.begin();im!=_fin.end(); im++)
69 const client_infos &lesInfos = *(*im).second ;
70 MESSAGE("Deletion") ; SCRUTE( lesInfos._name ) ;
73 ASSERT(_fin.size()==0) ;
78 delete [] _SessionName ;
80 delete [] (char*)_SessionName ;
84 END_OF("RegistryService::~RegistryService()") ;
87 /* ------------------------------*/
89 /* ------------------------------*/
91 CORBA::ULong RegistryService::size ( void )
93 ASSERT(_SessionName) ;
94 ASSERT(strlen(_SessionName)>0) ;
99 CORBA::ULong RegistryService::add( const Registry::Infos & infos )
101 BEGIN_OF("RegistryService::add") ;
102 ASSERT(_SessionName) ;
103 ASSERT(strlen(_SessionName)>0) ;
104 client_infos *ptr_Component = new client_infos( infos ) ;
105 ASSERT(ptr_Component) ;
106 SCRUTE(ptr_Component->_name) ;
109 _reg[_Compteur]=ptr_Component;
111 END_OF("RegistryService::add") ;
112 return (CORBA::ULong)_Compteur ;
116 void RegistryService::remove( const CORBA::ULong id)
118 void RegistryService::remove( CORBA::ULong id)
121 BEGIN_OF("RegistryService::remove") ;
123 ASSERT(_SessionName) ;
124 ASSERT(strlen(_SessionName)>0) ;
126 ASSERT(_reg.find(id)!=_reg.end())
127 _reg[id]->_status=TERMINATED;
128 _reg[id]->_ts_end = time(NULL) ;
131 SCRUTE(_fin.size()) ;
133 map<int,client_infos *>::iterator pos = _reg.find ( id ) ;
135 SCRUTE(_reg.size()) ;
136 SCRUTE(_fin.size()) ;
138 END_OF("RegistryService::remove") ;
144 void RegistryService::hello( const CORBA::ULong id )
146 void RegistryService::hello( CORBA::ULong id )
149 BEGIN_OF("RegistryService::hello") ;
151 ASSERT(_SessionName) ;
152 ASSERT(strlen(_SessionName)>0) ;
154 ASSERT(_reg.find(id)!=_reg.end())
155 _reg[id]->_ts_hello = time(NULL) ;
157 END_OF("RegistryService::hello") ;
162 void RegistryService::end( void )
164 ASSERT(_SessionName) ;
165 ASSERT(strlen(_SessionName)>0) ;
166 BEGIN_OF( "RegistryService::end( void )" ) ;
167 exit( EXIT_SUCCESS ) ;
171 Registry::AllInfos* RegistryService::getall( void )
173 ASSERT(_SessionName) ;
174 ASSERT(strlen(_SessionName)>0) ;
175 return RegistryService::makeseq(_reg) ;
178 Registry::AllInfos* RegistryService::history( void )
180 ASSERT(_SessionName) ;
181 ASSERT(strlen(_SessionName)>0) ;
182 return RegistryService::makeseq(_fin) ;
185 Registry::AllInfos* RegistryService::makeseq(map<int,client_infos *> &mymap )
189 Registry::AllInfos *all = new Registry::AllInfos ;
191 const int RegLength = mymap.size();
192 all->length(RegLength);
194 map<int,client_infos *>::iterator im;
195 for (im=mymap.begin();im!=mymap.end(); im++)
198 Registry::Infos &infos = (*all)[i] ;
199 const client_infos &lesInfos = *(*im).second ;
200 infos.name = CORBA::string_dup( lesInfos._name ) ;
201 infos.pid = lesInfos._pid ;
202 infos.pwname = lesInfos._pwname ;
203 infos.machine = CORBA::string_dup( lesInfos._machine ) ;
204 infos.adip = CORBA::string_dup( lesInfos._adip ) ;
205 infos.uid = lesInfos._uid ;
206 infos.tc_start = lesInfos._ts_start + lesInfos._difftime ;
207 infos.tc_hello = lesInfos._ts_hello + lesInfos._difftime ;
208 infos.tc_end = lesInfos._ts_end + lesInfos._difftime ;
209 infos.difftime = lesInfos._difftime ;
210 infos.cdir = CORBA::string_dup( lesInfos._cdir ) ;
211 infos.status = lesInfos._status ;
220 /* ------------------------------*/
222 /* ------------------------------*/
224 RegistryService::client_infos::client_infos( const Registry::Infos &infos ):\
225 _ior(duplicate(infos.ior)),\
226 _name(duplicate(infos.name)),\
228 _machine(duplicate(infos.machine)),\
229 _adip(duplicate(infos.adip)),\
231 _pwname(duplicate(infos.pwname)),\
232 _ts_start(time(NULL)),\
233 _difftime(infos.tc_start - _ts_start),\
234 _cdir(duplicate(infos.cdir)),\
235 _ts_hello(_ts_start),\
243 RegistryService::client_infos::~client_infos()
245 delete [] (char*)_ior ; (char*&)_ior = NULL ;
246 delete [] (char*)_name ; (char*&)_name = NULL ;
247 delete [] (char*)_machine ; (char*&)_machine = NULL ;
248 delete [] (char*)_pwname ; (char*&)_pwname = NULL ;
249 delete [] (char*)_adip ; (char*&)_adip = NULL ;
250 delete [] (char*)_cdir ; (char*&)_cdir = NULL ;
253 void RegistryService::SessionName( const char *sessionName )
255 ASSERT(sessionName) ;
256 ASSERT(strlen(sessionName)>0) ;
257 _SessionName = duplicate(sessionName) ;
260 void RegistryService::ping()
263 MESSAGE(" RegistryService::ping() pid "<< getpid());
265 MESSAGE(" RegistryService::ping() pid "<< _getpid());