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 /* Constructors and Destructors */
46 /* ------------------------------*/
48 RegistryService::RegistryService( void ) : _SessionName(0), _Compteur(0)
50 MESSAGE("RegistryService::RegistryService()") ;
51 _orb = CORBA::ORB::_nil();
54 RegistryService::~RegistryService()
56 BEGIN_OF("RegistryService::~RegistryService()") ;
57 map<int,client_infos *>::iterator im;
58 for (im=_reg.begin();im!=_reg.end(); im++)
60 MESSAGE("Delete _reg item " << im->second->_name) ;
63 for (im=_fin.begin();im!=_fin.end(); im++)
65 MESSAGE("Delete _fin item " << im->second->_name) ;
71 delete [] (char*)_SessionName ;
74 END_OF("RegistryService::~RegistryService()") ;
77 /* ------------------------------*/
79 /* ------------------------------*/
81 CORBA::ULong RegistryService::size ( void )
83 ASSERT(_SessionName) ;
84 ASSERT(strlen(_SessionName)>0) ;
88 CORBA::ULong RegistryService::add( const Registry::Infos & infos )
90 BEGIN_OF("RegistryService::add") ;
91 ASSERT(_SessionName) ;
92 ASSERT(strlen(_SessionName)>0) ;
93 client_infos *ptr_Component = new client_infos( infos ) ;
94 ASSERT(ptr_Component) ;
95 SCRUTE(ptr_Component->_name) ;
98 _reg[_Compteur]=ptr_Component;
100 END_OF("RegistryService::add") ;
101 return (CORBA::ULong)_Compteur ;
104 void RegistryService::remove( CORBA::ULong id)
106 BEGIN_OF("RegistryService::remove") ;
108 ASSERT(_SessionName) ;
109 ASSERT(strlen(_SessionName)>0) ;
111 ASSERT(_reg.find(id)!=_reg.end())
112 _reg[id]->_status=TERMINATED;
113 _reg[id]->_ts_end = time(NULL) ;
118 SCRUTE(_reg.size()) ;
119 SCRUTE(_fin.size()) ;
121 END_OF("RegistryService::remove") ;
126 void RegistryService::hello( CORBA::ULong id )
128 BEGIN_OF("RegistryService::hello") ;
130 ASSERT(_SessionName) ;
131 ASSERT(strlen(_SessionName)>0) ;
133 ASSERT(_reg.find(id)!=_reg.end())
134 _reg[id]->_ts_hello = time(NULL) ;
136 END_OF("RegistryService::hello") ;
140 void RegistryService::end( void )
142 ASSERT(_SessionName) ;
143 ASSERT(strlen(_SessionName)>0) ;
144 BEGIN_OF( "RegistryService::end( void )" ) ;
145 exit( EXIT_SUCCESS ) ;
148 Registry::AllInfos* RegistryService::getall( void )
150 ASSERT(_SessionName) ;
151 ASSERT(strlen(_SessionName)>0) ;
152 return RegistryService::makeseq(_reg) ;
155 Registry::AllInfos* RegistryService::history( void )
157 ASSERT(_SessionName) ;
158 ASSERT(strlen(_SessionName)>0) ;
159 return RegistryService::makeseq(_fin) ;
162 Registry::AllInfos* RegistryService::makeseq(map<int,client_infos *> &mymap )
166 Registry::AllInfos *all = new Registry::AllInfos ;
168 const int RegLength = mymap.size();
169 all->length(RegLength);
171 map<int,client_infos *>::iterator im;
172 for (im=mymap.begin();im!=mymap.end(); im++)
175 Registry::Infos &infos = (*all)[i] ;
176 const client_infos &lesInfos = *(*im).second ;
177 infos.name = CORBA::string_dup( lesInfos._name ) ;
178 infos.pid = lesInfos._pid ;
179 infos.pwname = lesInfos._pwname ;
180 infos.machine = CORBA::string_dup( lesInfos._machine ) ;
181 infos.adip = CORBA::string_dup( lesInfos._adip ) ;
182 infos.uid = lesInfos._uid ;
183 infos.tc_start = lesInfos._ts_start + lesInfos._difftime ;
184 infos.tc_hello = lesInfos._ts_hello + lesInfos._difftime ;
185 infos.tc_end = lesInfos._ts_end + lesInfos._difftime ;
186 infos.difftime = lesInfos._difftime ;
187 infos.cdir = CORBA::string_dup( lesInfos._cdir ) ;
188 infos.status = lesInfos._status ;
197 /* ------------------------------*/
199 /* ------------------------------*/
201 RegistryService::client_infos::client_infos( const Registry::Infos &infos ):\
202 _ior(duplicate(infos.ior)),\
203 _name(duplicate(infos.name)),\
205 _machine(duplicate(infos.machine)),\
206 _adip(duplicate(infos.adip)),\
208 _pwname(duplicate(infos.pwname)),\
209 _ts_start(time(NULL)),\
210 _difftime(infos.tc_start - _ts_start),\
211 _cdir(duplicate(infos.cdir)),\
212 _ts_hello(_ts_start),\
218 RegistryService::client_infos::~client_infos()
220 delete [] (char*)_ior ; (char*&)_ior = NULL ;
221 delete [] (char*)_name ; (char*&)_name = NULL ;
222 delete [] (char*)_machine ; (char*&)_machine = NULL ;
223 delete [] (char*)_pwname ; (char*&)_pwname = NULL ;
224 delete [] (char*)_adip ; (char*&)_adip = NULL ;
225 delete [] (char*)_cdir ; (char*&)_cdir = NULL ;
228 void RegistryService::SessionName( const char *sessionName )
230 ASSERT(sessionName) ;
231 ASSERT(strlen(sessionName)>0) ;
232 _SessionName = duplicate(sessionName) ;
235 void RegistryService::ping()
238 MESSAGE(" RegistryService::ping() pid "<< getpid());
240 MESSAGE(" RegistryService::ping() pid "<< _getpid());
244 CORBA::Long RegistryService::getPID()
246 return (CORBA::Long)getpid();