2 //=============================================================================
3 // File : RegistryService.cxx
4 // Created : Mon Nov 5 17:26:23 CET 2001
5 // Author : Pascale NOYRET - Antoine YESSAYAN, EDF
7 // Copyright : EDF 2001
9 //=============================================================================
12 # include "RegistryService.hxx"
13 # include "OpUtil.hxx"
14 # include "utilities.h"
23 /* ------------------------------*/
24 /* Constructeurs et Destructeurs */
25 /* ------------------------------*/
27 RegistryService::RegistryService( void ) : _SessionName(0), _Compteur(0)
29 MESSAGE("Passage dans RegistryService::RegistryService()") ;
34 RegistryService::~RegistryService()
36 BEGIN_OF("RegistryService::~RegistryService()") ;
37 map<int,client_infos *>::iterator im;
38 for (im=_reg.begin();im!=_reg.end(); im++)
40 const client_infos &lesInfos = *(*im).second ;
41 MESSAGE("Deletion") ; SCRUTE( lesInfos._name ) ;
44 ASSERT(_reg.size()==0) ;
45 for (im=_fin.begin();im!=_fin.end(); im++)
47 const client_infos &lesInfos = *(*im).second ;
48 MESSAGE("Deletion") ; SCRUTE( lesInfos._name ) ;
51 ASSERT(_fin.size()==0) ;
55 delete [] _SessionName ;
58 END_OF("RegistryService::~RegistryService()") ;
61 /* ------------------------------*/
63 /* ------------------------------*/
65 CORBA::ULong RegistryService::size ( void )
67 ASSERT(_SessionName) ;
68 ASSERT(strlen(_SessionName)>0) ;
73 CORBA::ULong RegistryService::add( const Registry::Infos & infos )
75 BEGIN_OF("RegistryService::add") ;
76 ASSERT(_SessionName) ;
77 ASSERT(strlen(_SessionName)>0) ;
78 client_infos *ptr_Component = new client_infos( infos ) ;
79 ASSERT(ptr_Component) ;
80 SCRUTE(ptr_Component->_name) ;
83 _reg[_Compteur]=ptr_Component;
85 END_OF("RegistryService::add") ;
86 return (CORBA::ULong)_Compteur ;
90 void RegistryService::remove( const CORBA::ULong id)
92 BEGIN_OF("RegistryService::remove") ;
94 ASSERT(_SessionName) ;
95 ASSERT(strlen(_SessionName)>0) ;
97 ASSERT(_reg.find(id)!=_reg.end())
98 _reg[id]->_status=TERMINATED;
99 _reg[id]->_ts_end = time(NULL) ;
102 SCRUTE(_fin.size()) ;
104 map<int,client_infos *>::iterator pos = _reg.find ( id ) ;
106 SCRUTE(_reg.size()) ;
107 SCRUTE(_fin.size()) ;
109 END_OF("RegistryService::remove") ;
115 void RegistryService::hello( const CORBA::ULong id )
117 BEGIN_OF("RegistryService::hello") ;
119 ASSERT(_SessionName) ;
120 ASSERT(strlen(_SessionName)>0) ;
122 ASSERT(_reg.find(id)!=_reg.end())
123 _reg[id]->_ts_hello = time(NULL) ;
125 END_OF("RegistryService::hello") ;
130 void RegistryService::end( void )
132 ASSERT(_SessionName) ;
133 ASSERT(strlen(_SessionName)>0) ;
134 BEGIN_OF( "RegistryService::end( void )" ) ;
135 exit( EXIT_SUCCESS ) ;
139 Registry::AllInfos* RegistryService::getall( void )
141 ASSERT(_SessionName) ;
142 ASSERT(strlen(_SessionName)>0) ;
143 return RegistryService::makeseq(_reg) ;
146 Registry::AllInfos* RegistryService::history( void )
148 ASSERT(_SessionName) ;
149 ASSERT(strlen(_SessionName)>0) ;
150 return RegistryService::makeseq(_fin) ;
153 Registry::AllInfos* RegistryService::makeseq(map<int,client_infos *> &mymap )
157 Registry::AllInfos *all = new Registry::AllInfos ;
159 const int RegLength = mymap.size();
160 all->length(RegLength);
162 map<int,client_infos *>::iterator im;
163 for (im=mymap.begin();im!=mymap.end(); im++)
166 Registry::Infos &infos = (*all)[i] ;
167 const client_infos &lesInfos = *(*im).second ;
168 infos.name = CORBA::string_dup( lesInfos._name ) ;
169 infos.pid = lesInfos._pid ;
170 infos.pwname = lesInfos._pwname ;
171 infos.machine = CORBA::string_dup( lesInfos._machine ) ;
172 infos.adip = CORBA::string_dup( lesInfos._adip ) ;
173 infos.uid = lesInfos._uid ;
174 infos.tc_start = lesInfos._ts_start + lesInfos._difftime ;
175 infos.tc_hello = lesInfos._ts_hello + lesInfos._difftime ;
176 infos.tc_end = lesInfos._ts_end + lesInfos._difftime ;
177 infos.difftime = lesInfos._difftime ;
178 infos.cdir = CORBA::string_dup( lesInfos._cdir ) ;
179 infos.status = lesInfos._status ;
188 /* ------------------------------*/
190 /* ------------------------------*/
192 RegistryService::client_infos::client_infos( const Registry::Infos &infos ):\
193 _ior(duplicate(infos.ior)),\
194 _name(duplicate(infos.name)),\
196 _machine(duplicate(infos.machine)),\
197 _adip(duplicate(infos.adip)),\
199 _pwname(duplicate(infos.pwname)),\
200 _ts_start(time(NULL)),\
201 _difftime(infos.tc_start - _ts_start),\
202 _cdir(duplicate(infos.cdir)),\
203 _ts_hello(_ts_start),\
211 RegistryService::client_infos::~client_infos()
213 delete [] (char*)_ior ; (char*&)_ior = NULL ;
214 delete [] (char*)_name ; (char*&)_name = NULL ;
215 delete [] (char*)_machine ; (char*&)_machine = NULL ;
216 delete [] (char*)_pwname ; (char*&)_pwname = NULL ;
217 delete [] (char*)_adip ; (char*&)_adip = NULL ;
218 delete [] (char*)_cdir ; (char*&)_cdir = NULL ;
221 void RegistryService::SessionName( const char *sessionName )
223 ASSERT(sessionName) ;
224 ASSERT(strlen(sessionName)>0) ;
225 _SessionName = duplicate(sessionName) ;
228 void RegistryService::ping()
230 MESSAGE(" RegistryService::ping() pid "<< getpid());