1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 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
22 // SALOME Registry : Registry server implementation
23 // File : RegistryService.cxx
24 // Author : Pascale NOYRET - Antoine YESSAYAN, EDF
28 # include "RegistryService.hxx"
29 # include "OpUtil.hxx"
30 # include "utilities.h"
44 /* ------------------------------*/
45 /* Constructeurs et Destructeurs */
46 /* ------------------------------*/
48 RegistryService::RegistryService( void ) : _SessionName(0), _Compteur(0)
50 MESSAGE("Passage dans RegistryService::RegistryService()") ;
51 _orb = CORBA::ORB::_nil();
55 RegistryService::~RegistryService()
57 BEGIN_OF("RegistryService::~RegistryService()") ;
58 map<int,client_infos *>::iterator im;
59 for (im=_reg.begin();im!=_reg.end(); im++)
61 #if defined(_DEBUG_) || defined(_DEBUG)
62 const client_infos &lesInfos = *(*im).second ;
63 MESSAGE("Deletion") ; SCRUTE( lesInfos._name ) ;
67 ASSERT(_reg.size()==0) ;
68 for (im=_fin.begin();im!=_fin.end(); im++)
70 #if defined(_DEBUG_) || defined(_DEBUG)
71 const client_infos &lesInfos = *(*im).second ;
72 MESSAGE("Deletion") ; SCRUTE( lesInfos._name ) ;
76 ASSERT(_fin.size()==0) ;
81 delete [] _SessionName ;
83 delete [] (char*)_SessionName ;
87 END_OF("RegistryService::~RegistryService()") ;
90 /* ------------------------------*/
92 /* ------------------------------*/
94 CORBA::ULong RegistryService::size ( void )
96 ASSERT(_SessionName) ;
97 ASSERT(strlen(_SessionName)>0) ;
102 CORBA::ULong RegistryService::add( const Registry::Infos & infos )
104 BEGIN_OF("RegistryService::add") ;
105 ASSERT(_SessionName) ;
106 ASSERT(strlen(_SessionName)>0) ;
107 client_infos *ptr_Component = new client_infos( infos ) ;
108 ASSERT(ptr_Component) ;
109 SCRUTE(ptr_Component->_name) ;
112 _reg[_Compteur]=ptr_Component;
114 END_OF("RegistryService::add") ;
115 return (CORBA::ULong)_Compteur ;
119 void RegistryService::remove( const CORBA::ULong id)
121 void RegistryService::remove( CORBA::ULong id)
124 BEGIN_OF("RegistryService::remove") ;
126 ASSERT(_SessionName) ;
127 ASSERT(strlen(_SessionName)>0) ;
129 ASSERT(_reg.find(id)!=_reg.end())
130 _reg[id]->_status=TERMINATED;
131 _reg[id]->_ts_end = time(NULL) ;
134 SCRUTE(_fin.size()) ;
136 map<int,client_infos *>::iterator pos = _reg.find ( id ) ;
138 SCRUTE(_reg.size()) ;
139 SCRUTE(_fin.size()) ;
141 END_OF("RegistryService::remove") ;
147 void RegistryService::hello( const CORBA::ULong id )
149 void RegistryService::hello( CORBA::ULong id )
152 BEGIN_OF("RegistryService::hello") ;
154 ASSERT(_SessionName) ;
155 ASSERT(strlen(_SessionName)>0) ;
157 ASSERT(_reg.find(id)!=_reg.end())
158 _reg[id]->_ts_hello = time(NULL) ;
160 END_OF("RegistryService::hello") ;
165 void RegistryService::end( void )
167 ASSERT(_SessionName) ;
168 ASSERT(strlen(_SessionName)>0) ;
169 BEGIN_OF( "RegistryService::end( void )" ) ;
170 exit( EXIT_SUCCESS ) ;
174 Registry::AllInfos* RegistryService::getall( void )
176 ASSERT(_SessionName) ;
177 ASSERT(strlen(_SessionName)>0) ;
178 return RegistryService::makeseq(_reg) ;
181 Registry::AllInfos* RegistryService::history( void )
183 ASSERT(_SessionName) ;
184 ASSERT(strlen(_SessionName)>0) ;
185 return RegistryService::makeseq(_fin) ;
188 Registry::AllInfos* RegistryService::makeseq(map<int,client_infos *> &mymap )
192 Registry::AllInfos *all = new Registry::AllInfos ;
194 const int RegLength = mymap.size();
195 all->length(RegLength);
197 map<int,client_infos *>::iterator im;
198 for (im=mymap.begin();im!=mymap.end(); im++)
201 Registry::Infos &infos = (*all)[i] ;
202 const client_infos &lesInfos = *(*im).second ;
203 infos.name = CORBA::string_dup( lesInfos._name ) ;
204 infos.pid = lesInfos._pid ;
205 infos.pwname = lesInfos._pwname ;
206 infos.machine = CORBA::string_dup( lesInfos._machine ) ;
207 infos.adip = CORBA::string_dup( lesInfos._adip ) ;
208 infos.uid = lesInfos._uid ;
209 infos.tc_start = lesInfos._ts_start + lesInfos._difftime ;
210 infos.tc_hello = lesInfos._ts_hello + lesInfos._difftime ;
211 infos.tc_end = lesInfos._ts_end + lesInfos._difftime ;
212 infos.difftime = lesInfos._difftime ;
213 infos.cdir = CORBA::string_dup( lesInfos._cdir ) ;
214 infos.status = lesInfos._status ;
223 /* ------------------------------*/
225 /* ------------------------------*/
227 RegistryService::client_infos::client_infos( const Registry::Infos &infos ):\
228 _ior(duplicate(infos.ior)),\
229 _name(duplicate(infos.name)),\
231 _machine(duplicate(infos.machine)),\
232 _adip(duplicate(infos.adip)),\
234 _pwname(duplicate(infos.pwname)),\
235 _ts_start(time(NULL)),\
236 _difftime(infos.tc_start - _ts_start),\
237 _cdir(duplicate(infos.cdir)),\
238 _ts_hello(_ts_start),\
246 RegistryService::client_infos::~client_infos()
248 delete [] (char*)_ior ; (char*&)_ior = NULL ;
249 delete [] (char*)_name ; (char*&)_name = NULL ;
250 delete [] (char*)_machine ; (char*&)_machine = NULL ;
251 delete [] (char*)_pwname ; (char*&)_pwname = NULL ;
252 delete [] (char*)_adip ; (char*&)_adip = NULL ;
253 delete [] (char*)_cdir ; (char*&)_cdir = NULL ;
256 void RegistryService::SessionName( const char *sessionName )
258 ASSERT(sessionName) ;
259 ASSERT(strlen(sessionName)>0) ;
260 _SessionName = duplicate(sessionName) ;
263 void RegistryService::ping()
266 MESSAGE(" RegistryService::ping() pid "<< getpid());
268 MESSAGE(" RegistryService::ping() pid "<< _getpid());
272 CORBA::Long RegistryService::getPID()
274 return (CORBA::Long)getpid();