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 #if defined(_DEBUG_) || defined(_DEBUG)
63 const client_infos &lesInfos = *(*im).second ;
64 MESSAGE("Deletion") ; SCRUTE( lesInfos._name ) ;
68 ASSERT(_reg.size()==0) ;
69 for (im=_fin.begin();im!=_fin.end(); im++)
71 #if defined(_DEBUG_) || defined(_DEBUG)
72 const client_infos &lesInfos = *(*im).second ;
73 MESSAGE("Deletion") ; SCRUTE( lesInfos._name ) ;
77 ASSERT(_fin.size()==0) ;
82 delete [] _SessionName ;
84 delete [] (char*)_SessionName ;
88 END_OF("RegistryService::~RegistryService()") ;
91 /* ------------------------------*/
93 /* ------------------------------*/
95 CORBA::ULong RegistryService::size ( void )
97 ASSERT(_SessionName) ;
98 ASSERT(strlen(_SessionName)>0) ;
103 CORBA::ULong RegistryService::add( const Registry::Infos & infos )
105 BEGIN_OF("RegistryService::add") ;
106 ASSERT(_SessionName) ;
107 ASSERT(strlen(_SessionName)>0) ;
108 client_infos *ptr_Component = new client_infos( infos ) ;
109 ASSERT(ptr_Component) ;
110 SCRUTE(ptr_Component->_name) ;
113 _reg[_Compteur]=ptr_Component;
115 END_OF("RegistryService::add") ;
116 return (CORBA::ULong)_Compteur ;
120 void RegistryService::remove( const CORBA::ULong id)
122 void RegistryService::remove( CORBA::ULong id)
125 BEGIN_OF("RegistryService::remove") ;
127 ASSERT(_SessionName) ;
128 ASSERT(strlen(_SessionName)>0) ;
130 ASSERT(_reg.find(id)!=_reg.end())
131 _reg[id]->_status=TERMINATED;
132 _reg[id]->_ts_end = time(NULL) ;
135 SCRUTE(_fin.size()) ;
137 map<int,client_infos *>::iterator pos = _reg.find ( id ) ;
139 SCRUTE(_reg.size()) ;
140 SCRUTE(_fin.size()) ;
142 END_OF("RegistryService::remove") ;
148 void RegistryService::hello( const CORBA::ULong id )
150 void RegistryService::hello( CORBA::ULong id )
153 BEGIN_OF("RegistryService::hello") ;
155 ASSERT(_SessionName) ;
156 ASSERT(strlen(_SessionName)>0) ;
158 ASSERT(_reg.find(id)!=_reg.end())
159 _reg[id]->_ts_hello = time(NULL) ;
161 END_OF("RegistryService::hello") ;
166 void RegistryService::end( void )
168 ASSERT(_SessionName) ;
169 ASSERT(strlen(_SessionName)>0) ;
170 BEGIN_OF( "RegistryService::end( void )" ) ;
171 exit( EXIT_SUCCESS ) ;
175 Registry::AllInfos* RegistryService::getall( void )
177 ASSERT(_SessionName) ;
178 ASSERT(strlen(_SessionName)>0) ;
179 return RegistryService::makeseq(_reg) ;
182 Registry::AllInfos* RegistryService::history( void )
184 ASSERT(_SessionName) ;
185 ASSERT(strlen(_SessionName)>0) ;
186 return RegistryService::makeseq(_fin) ;
189 Registry::AllInfos* RegistryService::makeseq(map<int,client_infos *> &mymap )
193 Registry::AllInfos *all = new Registry::AllInfos ;
195 const int RegLength = mymap.size();
196 all->length(RegLength);
198 map<int,client_infos *>::iterator im;
199 for (im=mymap.begin();im!=mymap.end(); im++)
202 Registry::Infos &infos = (*all)[i] ;
203 const client_infos &lesInfos = *(*im).second ;
204 infos.name = CORBA::string_dup( lesInfos._name ) ;
205 infos.pid = lesInfos._pid ;
206 infos.pwname = lesInfos._pwname ;
207 infos.machine = CORBA::string_dup( lesInfos._machine ) ;
208 infos.adip = CORBA::string_dup( lesInfos._adip ) ;
209 infos.uid = lesInfos._uid ;
210 infos.tc_start = lesInfos._ts_start + lesInfos._difftime ;
211 infos.tc_hello = lesInfos._ts_hello + lesInfos._difftime ;
212 infos.tc_end = lesInfos._ts_end + lesInfos._difftime ;
213 infos.difftime = lesInfos._difftime ;
214 infos.cdir = CORBA::string_dup( lesInfos._cdir ) ;
215 infos.status = lesInfos._status ;
224 /* ------------------------------*/
226 /* ------------------------------*/
228 RegistryService::client_infos::client_infos( const Registry::Infos &infos ):\
229 _ior(duplicate(infos.ior)),\
230 _name(duplicate(infos.name)),\
232 _machine(duplicate(infos.machine)),\
233 _adip(duplicate(infos.adip)),\
235 _pwname(duplicate(infos.pwname)),\
236 _ts_start(time(NULL)),\
237 _difftime(infos.tc_start - _ts_start),\
238 _cdir(duplicate(infos.cdir)),\
239 _ts_hello(_ts_start),\
247 RegistryService::client_infos::~client_infos()
249 delete [] (char*)_ior ; (char*&)_ior = NULL ;
250 delete [] (char*)_name ; (char*&)_name = NULL ;
251 delete [] (char*)_machine ; (char*&)_machine = NULL ;
252 delete [] (char*)_pwname ; (char*&)_pwname = NULL ;
253 delete [] (char*)_adip ; (char*&)_adip = NULL ;
254 delete [] (char*)_cdir ; (char*&)_cdir = NULL ;
257 void RegistryService::SessionName( const char *sessionName )
259 ASSERT(sessionName) ;
260 ASSERT(strlen(sessionName)>0) ;
261 _SessionName = duplicate(sessionName) ;
264 void RegistryService::ping()
267 MESSAGE(" RegistryService::ping() pid "<< getpid());
269 MESSAGE(" RegistryService::ping() pid "<< _getpid());
273 CORBA::Long RegistryService::getPID()
275 return (CORBA::Long)getpid();