1 // Copyright (C) 2007-2020 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, or (at your option) any later version.
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
23 // SALOME Registry : Registry server implementation
24 // File : RegistryService.cxx
25 // Author : Pascale NOYRET - Antoine YESSAYAN, EDF
29 # include "RegistryService.hxx"
30 # include "OpUtil.hxx"
31 # include "utilities.h"
42 #define getpid _getpid
45 /* ------------------------------*/
46 /* Constructors and Destructors */
47 /* ------------------------------*/
49 RegistryService::RegistryService( void ) : _SessionName(0), _Compteur(0)
51 MESSAGE("RegistryService::RegistryService()") ;
52 _orb = CORBA::ORB::_nil();
55 RegistryService::~RegistryService()
57 BEGIN_OF("RegistryService::~RegistryService()") ;
58 std::map<int,client_infos *>::iterator im;
59 for (im=_reg.begin();im!=_reg.end(); im++)
61 MESSAGE("Delete _reg item " << im->second->_name) ;
64 for (im=_fin.begin();im!=_fin.end(); im++)
66 MESSAGE("Delete _fin item " << im->second->_name) ;
72 delete [] (char*)_SessionName ;
75 END_OF("RegistryService::~RegistryService()") ;
78 /* ------------------------------*/
80 /* ------------------------------*/
82 CORBA::ULong RegistryService::size ( void )
84 ASSERT(_SessionName) ;
85 ASSERT(strlen(_SessionName)>0) ;
89 CORBA::ULong RegistryService::add( const Registry::Infos & infos )
91 BEGIN_OF("RegistryService::add") ;
92 ASSERT(_SessionName) ;
93 ASSERT(strlen(_SessionName)>0) ;
94 client_infos *ptr_Component = new client_infos( infos ) ;
95 ASSERT(ptr_Component) ;
96 SCRUTE(ptr_Component->_name) ;
99 _reg[_Compteur]=ptr_Component;
101 END_OF("RegistryService::add") ;
102 return (CORBA::ULong)_Compteur ;
105 void RegistryService::remove( CORBA::ULong id)
107 BEGIN_OF("RegistryService::remove") ;
109 ASSERT(_SessionName) ;
110 ASSERT(strlen(_SessionName)>0) ;
112 ASSERT(_reg.find(id)!=_reg.end())
113 _reg[id]->_status=TERMINATED;
114 _reg[id]->_ts_end = time(NULL) ;
119 SCRUTE(_reg.size()) ;
120 SCRUTE(_fin.size()) ;
122 END_OF("RegistryService::remove") ;
127 void RegistryService::hello( CORBA::ULong id )
129 BEGIN_OF("RegistryService::hello") ;
131 ASSERT(_SessionName) ;
132 ASSERT(strlen(_SessionName)>0) ;
134 ASSERT(_reg.find(id)!=_reg.end())
135 _reg[id]->_ts_hello = time(NULL) ;
137 END_OF("RegistryService::hello") ;
141 void RegistryService::end( void )
143 ASSERT(_SessionName) ;
144 ASSERT(strlen(_SessionName)>0) ;
145 BEGIN_OF( "RegistryService::end( void )" ) ;
146 exit( EXIT_SUCCESS ) ;
149 Registry::AllInfos* RegistryService::getall( void )
151 ASSERT(_SessionName) ;
152 ASSERT(strlen(_SessionName)>0) ;
153 return RegistryService::makeseq(_reg) ;
156 Registry::AllInfos* RegistryService::history( void )
158 ASSERT(_SessionName) ;
159 ASSERT(strlen(_SessionName)>0) ;
160 return RegistryService::makeseq(_fin) ;
163 Registry::AllInfos* RegistryService::makeseq(std::map<int,client_infos *> &mymap )
167 Registry::AllInfos *all = new Registry::AllInfos ;
169 const int RegLength = mymap.size();
170 all->length(RegLength);
172 std::map<int,client_infos *>::iterator im;
173 for (im=mymap.begin();im!=mymap.end(); im++)
176 Registry::Infos &infos = (*all)[i] ;
177 const client_infos &lesInfos = *(*im).second ;
178 infos.name = CORBA::string_dup( lesInfos._name ) ;
179 infos.pid = lesInfos._pid ;
180 infos.pwname = lesInfos._pwname ;
181 infos.machine = CORBA::string_dup( lesInfos._machine ) ;
182 infos.adip = CORBA::string_dup( lesInfos._adip ) ;
183 infos.uid = lesInfos._uid ;
184 infos.tc_start = lesInfos._ts_start + lesInfos._difftime ;
185 infos.tc_hello = lesInfos._ts_hello + lesInfos._difftime ;
186 infos.tc_end = lesInfos._ts_end + lesInfos._difftime ;
187 infos.difftime = lesInfos._difftime ;
188 infos.cdir = CORBA::string_dup( lesInfos._cdir ) ;
189 infos.status = lesInfos._status ;
198 /* ------------------------------*/
200 /* ------------------------------*/
202 RegistryService::client_infos::client_infos( const Registry::Infos &infos ):\
203 _ior(duplicate(infos.ior)),\
204 _name(duplicate(infos.name)),\
206 _machine(duplicate(infos.machine)),\
207 _adip(duplicate(infos.adip)),\
209 _pwname(duplicate(infos.pwname)),\
210 _ts_start(time(NULL)),\
211 _difftime(infos.tc_start - _ts_start),\
212 _cdir(duplicate(infos.cdir)),\
213 _ts_hello(_ts_start),\
219 RegistryService::client_infos::~client_infos()
221 delete [] (char*)_ior ; (char*&)_ior = NULL ;
222 delete [] (char*)_name ; (char*&)_name = NULL ;
223 delete [] (char*)_machine ; (char*&)_machine = NULL ;
224 delete [] (char*)_pwname ; (char*&)_pwname = NULL ;
225 delete [] (char*)_adip ; (char*&)_adip = NULL ;
226 delete [] (char*)_cdir ; (char*&)_cdir = NULL ;
229 void RegistryService::SessionName( const char *sessionName )
231 ASSERT(sessionName) ;
232 ASSERT(strlen(sessionName)>0) ;
233 _SessionName = duplicate(sessionName) ;
236 void RegistryService::ping()
239 MESSAGE(" RegistryService::ping() pid "<< getpid());
241 MESSAGE(" RegistryService::ping() pid "<< _getpid());
245 CORBA::Long RegistryService::getPID()
247 return (CORBA::Long)getpid();