Back to index

salome-kernel  6.5.0
RegistryService.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 //  SALOME Registry : Registry server implementation
00024 //  File   : RegistryService.cxx
00025 //  Author : Pascale NOYRET - Antoine YESSAYAN, EDF
00026 //  Module : SALOME
00027 //  $Header: /home/server/cvs/KERNEL/KERNEL_SRC/src/Registry/RegistryService.cxx,v 1.9.2.1.14.2.12.1 2012-04-12 14:05:19 vsr Exp $
00028 //
00029 # include "RegistryService.hxx"
00030 # include "OpUtil.hxx"
00031 # include "utilities.h"
00032 
00033 extern "C"
00034 {
00035 # include <time.h>
00036 }
00037 
00038 #ifndef WIN32
00039 #include <unistd.h>
00040 #else
00041 #include <process.h>
00042 #define getpid _getpid
00043 #endif
00044 
00045 /* ------------------------------*/
00046 /* Constructors and Destructors  */
00047 /* ------------------------------*/
00048 
00049 RegistryService::RegistryService( void ) : _SessionName(0), _Compteur(0)
00050 {
00051         MESSAGE("RegistryService::RegistryService()") ;
00052         _orb = CORBA::ORB::_nil();
00053 }
00054 
00055 RegistryService::~RegistryService()
00056 {
00057         BEGIN_OF("RegistryService::~RegistryService()") ;
00058         std::map<int,client_infos *>::iterator im;
00059         for (im=_reg.begin();im!=_reg.end(); im++)
00060           {
00061                 MESSAGE("Delete _reg item " << im->second->_name) ; 
00062                 delete im->second;
00063           }
00064         for (im=_fin.begin();im!=_fin.end(); im++)
00065           {
00066                 MESSAGE("Delete _fin item " << im->second->_name) ; 
00067                 delete im->second;
00068           }
00069         _Compteur = -1 ;
00070         if ( _SessionName )
00071           {
00072                 delete [] (char*)_SessionName ;
00073                 _SessionName = 0 ;
00074           }
00075         END_OF("RegistryService::~RegistryService()") ;
00076 }
00077 
00078 /* ------------------------------*/
00079 /* IDL contracts                 */
00080 /* ------------------------------*/
00081 
00082 CORBA::ULong RegistryService::size ( void )
00083 {
00084         ASSERT(_SessionName) ;
00085         ASSERT(strlen(_SessionName)>0) ;
00086         return _reg.size() ;
00087 }
00088 
00089 CORBA::ULong RegistryService::add( const Registry::Infos & infos )
00090 {
00091         BEGIN_OF("RegistryService::add") ;
00092         ASSERT(_SessionName) ;
00093         ASSERT(strlen(_SessionName)>0) ;
00094         client_infos *ptr_Component = new client_infos( infos ) ;
00095         ASSERT(ptr_Component) ;
00096         SCRUTE(ptr_Component->_name) ;
00097 
00098         _Compteur++;
00099         _reg[_Compteur]=ptr_Component;
00100 
00101         END_OF("RegistryService::add") ;
00102         return (CORBA::ULong)_Compteur ;
00103 }
00104 
00105 void RegistryService::remove( CORBA::ULong id)
00106 {
00107         BEGIN_OF("RegistryService::remove") ;
00108         SCRUTE(id) ;
00109         ASSERT(_SessionName) ;
00110         ASSERT(strlen(_SessionName)>0) ;
00111         
00112         ASSERT(_reg.find(id)!=_reg.end()) 
00113         _reg[id]->_status=TERMINATED;
00114         _reg[id]->_ts_end = time(NULL) ;
00115 
00116         _fin[id]=_reg[id];
00117         _reg.erase(id);
00118 
00119         SCRUTE(_reg.size()) ;
00120         SCRUTE(_fin.size()) ;
00121 
00122         END_OF("RegistryService::remove") ;
00123         return ;
00124 }
00125 
00126 
00127 void RegistryService::hello( CORBA::ULong id )
00128 {
00129         BEGIN_OF("RegistryService::hello") ;
00130         SCRUTE(id) ;
00131         ASSERT(_SessionName) ;
00132         ASSERT(strlen(_SessionName)>0) ;
00133 
00134         ASSERT(_reg.find(id)!=_reg.end()) 
00135         _reg[id]->_ts_hello = time(NULL) ;
00136                 
00137         END_OF("RegistryService::hello") ;
00138         return ;
00139 }
00140 
00141 void RegistryService::end( void )
00142 {
00143         ASSERT(_SessionName) ;
00144         ASSERT(strlen(_SessionName)>0) ;
00145         BEGIN_OF( "RegistryService::end( void )" ) ;
00146         exit( EXIT_SUCCESS ) ;
00147 }
00148 
00149 Registry::AllInfos* RegistryService::getall( void )
00150 {
00151         ASSERT(_SessionName) ;
00152         ASSERT(strlen(_SessionName)>0) ;
00153         return RegistryService::makeseq(_reg) ;
00154 }
00155 
00156 Registry::AllInfos* RegistryService::history( void )
00157 {
00158         ASSERT(_SessionName) ;
00159         ASSERT(strlen(_SessionName)>0) ;
00160         return RegistryService::makeseq(_fin) ;
00161 }
00162 
00163 Registry::AllInfos* RegistryService::makeseq(std::map<int,client_infos *> &mymap )
00164 {
00165         int i=0 ;
00166 
00167         Registry::AllInfos *all = new Registry::AllInfos ;
00168         ASSERT(all) ;
00169         const int RegLength = mymap.size();
00170         all->length(RegLength);
00171 
00172         std::map<int,client_infos *>::iterator im;
00173         for (im=mymap.begin();im!=mymap.end(); im++)
00174         {
00175 
00176                 Registry::Infos &infos = (*all)[i] ;
00177                 const client_infos &lesInfos = *(*im).second ;
00178                 infos.name        = CORBA::string_dup( lesInfos._name ) ;
00179                 infos.pid        = lesInfos._pid ;
00180                 infos.pwname        = lesInfos._pwname ;
00181                 infos.machine        = CORBA::string_dup( lesInfos._machine ) ;
00182                 infos.adip        = CORBA::string_dup( lesInfos._adip ) ;
00183                 infos.uid        = lesInfos._uid ;
00184                 infos.tc_start        = lesInfos._ts_start + lesInfos._difftime ;
00185                 infos.tc_hello        = lesInfos._ts_hello + lesInfos._difftime ;
00186                 infos.tc_end        = lesInfos._ts_end + lesInfos._difftime ;
00187                 infos.difftime        = lesInfos._difftime ;
00188                 infos.cdir        = CORBA::string_dup( lesInfos._cdir ) ;
00189                 infos.status        = lesInfos._status ;
00190 
00191                 i++;
00192         }
00193 
00194         return all ;
00195 }
00196 
00197 
00198 /* ------------------------------*/
00199 /* Others                        */
00200 /* ------------------------------*/
00201 
00202 RegistryService::client_infos::client_infos( const Registry::Infos &infos ):\
00203                                                                         _ior(duplicate(infos.ior)),\
00204                                                                         _name(duplicate(infos.name)),\
00205                                                                         _pid(infos.pid),\
00206                                                                         _machine(duplicate(infos.machine)),\
00207                                                                         _adip(duplicate(infos.adip)),\
00208                                                                         _uid(infos.uid),\
00209                                                                         _pwname(duplicate(infos.pwname)),\
00210                                                                         _ts_start(time(NULL)),\
00211                                                                         _difftime(infos.tc_start - _ts_start),\
00212                                                                         _cdir(duplicate(infos.cdir)),\
00213                                                                         _ts_hello(_ts_start),\
00214                                                                         _ts_end(0),\
00215                                                                         _status(RUNNING)
00216 {
00217 }
00218 
00219 RegistryService::client_infos::~client_infos()
00220 {
00221         delete [] (char*)_ior ; (char*&)_ior = NULL  ;
00222         delete [] (char*)_name ; (char*&)_name = NULL  ;
00223         delete [] (char*)_machine ; (char*&)_machine = NULL ;
00224         delete [] (char*)_pwname ; (char*&)_pwname = NULL ;
00225         delete [] (char*)_adip ; (char*&)_adip = NULL ;
00226         delete [] (char*)_cdir ; (char*&)_cdir = NULL ;
00227 }
00228 
00229 void RegistryService::SessionName( const char *sessionName )
00230 {
00231         ASSERT(sessionName) ;
00232         ASSERT(strlen(sessionName)>0) ;
00233         _SessionName = duplicate(sessionName) ;
00234         return ;
00235 }
00236 void RegistryService::ping()
00237 {
00238 #ifndef WIN32
00239   MESSAGE(" RegistryService::ping() pid "<< getpid());
00240 #else
00241   MESSAGE(" RegistryService::ping() pid "<< _getpid());
00242 #endif
00243 }
00244 
00245 CORBA::Long RegistryService::getPID()
00246 {
00247   return (CORBA::Long)getpid();
00248 }