From: prascle Date: Wed, 19 Jan 2005 06:57:12 +0000 (+0000) Subject: PR: bug 7769 loader aborts when logger not found in naming service, X-Git-Tag: HEAD_20050120~2 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=17748dde7e8014e8c781c4ba91b70edfb08b8bfb;p=modules%2Fkernel.git PR: bug 7769 loader aborts when logger not found in naming service, class renamed in coherence with library name. --- diff --git a/src/SALOMETraceCollector/LocalTrace_WaitForServerReadiness.cxx b/src/SALOMETraceCollector/LocalTrace_WaitForServerReadiness.cxx deleted file mode 100644 index 75a09525a..000000000 --- a/src/SALOMETraceCollector/LocalTrace_WaitForServerReadiness.cxx +++ /dev/null @@ -1,131 +0,0 @@ -// Copyright (C) 2004 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, -// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org -// -// -// -// File : LocalTrace_WaitForServerReadiness.cxx -// Author : Paul RASCLE (EDF) -// Module : KERNEL -// $Header$ - -#include "LocalTrace_WaitForServerReadiness.hxx" -#include -#include - -using namespace std; - -// ============================================================================ -/*! - * Wait until a server is registered in naming service. - * \param serverName name of the server to find. - * When SALOME_NamingService is available, - * use NamingService_WaitForServerReadiness instead. - * This function is needed when macro MESSAGE used by SALOME_NamingService - * is not available (inside LocalTrace methods, for instance !). - * Direct access to CORBA Name Service. Look for serverName at Name service - * Root without extensions. - */ -// ============================================================================ - -CORBA::Object_ptr LocalTrace_WaitForServerReadiness(CORBA::ORB_ptr orb, - string serverName) -{ - long TIMESleep = 250000000; - int NumberOfTries = 40; - - timespec ts_req; - ts_req.tv_nsec=TIMESleep; - ts_req.tv_sec=0; - timespec ts_rem; - ts_rem.tv_nsec=0; - ts_rem.tv_sec=0; - - CORBA::Object_var obj; - - try - { - // NB. You can't use SALOME_NamingService class because - // it uses MESSAGE macro - // Otherwise, you will get segmentation fault. - - CosNaming::NamingContext_var inc; - CosNaming::Name name; - name.length(1); - name[0].id = CORBA::string_dup(serverName.c_str()); - CORBA::Object_var theObj; - - for (int itry=0; itry < NumberOfTries; itry++) - { - try - { - if(!CORBA::is_nil(orb)) - theObj = orb->resolve_initial_references("NameService"); - if (!CORBA::is_nil(theObj)) - inc = CosNaming::NamingContext::_narrow(theObj); - } - catch( CORBA::COMM_FAILURE& ) - { - cout << "LocalTrace_WaitForServerReadiness: " - << "CORBA::COMM_FAILURE: " - << "Unable to contact the Naming Service" << endl; - } - catch(...) - { - cout << "LocalTrace_WaitForServerReadiness: " - << "Unknown exception dealing with Naming Service" << endl; - } - - if(!CORBA::is_nil(inc)) - { - obj = inc->resolve(name); - if (!CORBA::is_nil(obj)) - { - cout << "LocalTrace_WaitForServerReadiness: " - << serverName << " found in CORBA Name Service" << endl; - break; - } - } - int a = nanosleep(&ts_req,&ts_rem); - cout << "LocalTrace_WaitForServerReadiness: retry look for" - << serverName << endl; - } - } - catch (const CosNaming::NamingContext::NotFound&) - { - cout << "Caught exception: Naming Service can't found Logger"; - } - catch (CORBA::COMM_FAILURE&) - { - cout << "Caught CORBA::SystemException CommFailure."; - } - catch (CORBA::SystemException&) - { - cout << "Caught CORBA::SystemException."; - } - catch (CORBA::Exception&) - { - cout << "Caught CORBA::Exception."; - } - catch (...) - { - cout << "Caught unknown exception."; - } - return obj._retn(); -} - diff --git a/src/SALOMETraceCollector/LocalTrace_WaitForServerReadiness.hxx b/src/SALOMETraceCollector/LocalTrace_WaitForServerReadiness.hxx deleted file mode 100644 index a5e1c9a89..000000000 --- a/src/SALOMETraceCollector/LocalTrace_WaitForServerReadiness.hxx +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright (C) 2004 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, -// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org -// -// -// -// File : LocalTrace_WaitForServerReadiness.hxx -// Author : Paul RASCLE (EDF) -// Module : KERNEL -// $Header$ - -#ifndef _LOCALTRACE_WAITFORSERVERREADINESS_HXX_ -#define _LOCALTRACE_WAITFORSERVERREADINESS_HXX_ - -#include -#include - -CORBA::Object_ptr LocalTrace_WaitForServerReadiness(CORBA::ORB_ptr theOrb, - std::string serverName); - -#endif diff --git a/src/SALOMETraceCollector/Makefile.in b/src/SALOMETraceCollector/Makefile.in index 394805883..3df7820fd 100644 --- a/src/SALOMETraceCollector/Makefile.in +++ b/src/SALOMETraceCollector/Makefile.in @@ -36,7 +36,7 @@ VPATH=.:@srcdir@:@top_srcdir@/idl # header files EXPORT_HEADERS= SALOMETraceCollector.hxx \ - LocalTrace_WaitForServerReadiness.hxx + TraceCollector_WaitForServerReadiness.hxx EXPORT_PYSCRIPTS = @@ -44,7 +44,7 @@ EXPORT_PYSCRIPTS = LIB = libSALOMETraceCollector.la LIB_SRC = SALOMETraceCollector.cxx \ - LocalTrace_WaitForServerReadiness.cxx + TraceCollector_WaitForServerReadiness.cxx LIB_CLIENT_IDL = Logger.idl LDFLAGS+= diff --git a/src/SALOMETraceCollector/SALOMETraceCollector.cxx b/src/SALOMETraceCollector/SALOMETraceCollector.cxx index 933670635..1c0709848 100644 --- a/src/SALOMETraceCollector/SALOMETraceCollector.cxx +++ b/src/SALOMETraceCollector/SALOMETraceCollector.cxx @@ -33,7 +33,7 @@ using namespace std; #include "SALOMETraceCollector.hxx" -#include "LocalTrace_WaitForServerReadiness.hxx" +#include "TraceCollector_WaitForServerReadiness.hxx" //#include "SALOME_Log.hxx" #include #include CORBA_CLIENT_HEADER(Logger) @@ -50,6 +50,9 @@ CORBA::ORB_ptr SALOMETraceCollector::_orb = 0; // ============================================================================ /*! + * This class replaces LocalTraceCollector, which is to use outside SALOME, + * without CORBA. + * * guarantees a unique object instance of the class (singleton thread safe) * a separate thread for loop to print traces is launched. * \param typeTrace 0=standard out, 1=file(/tmp/tracetest.log), 2=CORBA log @@ -155,7 +158,7 @@ void* SALOMETraceCollector::run(void *bid) } break; case 2 : // --- trace collection via CORBA - obj = LocalTrace_WaitForServerReadiness(_orb,"Logger"); + obj = TraceCollector_WaitForServerReadiness(_orb,"Logger"); if (!CORBA::is_nil(obj)) m_pInterfaceLogger = SALOME_Logger::Logger::_narrow(obj); if (CORBA::is_nil(m_pInterfaceLogger)) diff --git a/src/SALOMETraceCollector/SALOMETraceCollector.hxx b/src/SALOMETraceCollector/SALOMETraceCollector.hxx index 846c4adf2..7d1b4bbb8 100644 --- a/src/SALOMETraceCollector/SALOMETraceCollector.hxx +++ b/src/SALOMETraceCollector/SALOMETraceCollector.hxx @@ -31,6 +31,8 @@ #include #include "LocalTraceBufferPool.hxx" +//! See LocalTraceCollector instead of SALOMETraceCollector for usage without CORBA + class SALOMETraceCollector { public: diff --git a/src/SALOMETraceCollector/TraceCollector_WaitForServerReadiness.cxx b/src/SALOMETraceCollector/TraceCollector_WaitForServerReadiness.cxx new file mode 100644 index 000000000..9e91b71d9 --- /dev/null +++ b/src/SALOMETraceCollector/TraceCollector_WaitForServerReadiness.cxx @@ -0,0 +1,139 @@ +// Copyright (C) 2004 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File : TraceCollector_WaitForServerReadiness.cxx +// Author : Paul RASCLE (EDF) +// Module : KERNEL +// $Header$ + +#include "TraceCollector_WaitForServerReadiness.hxx" +#include +#include + +using namespace std; + +// ============================================================================ +/*! + * Wait until a server is registered in naming service. + * \param serverName name of the server to find. + * When SALOME_NamingService is available, + * use NamingService_WaitForServerReadiness instead. + * This function is needed when macro MESSAGE used by SALOME_NamingService + * is not available (inside LocalTrace methods, for instance !). + * Direct access to CORBA Name Service. Look for serverName at Name service + * Root without extensions. + */ +// ============================================================================ + +CORBA::Object_ptr TraceCollector_WaitForServerReadiness(CORBA::ORB_ptr orb, + string serverName) +{ + long TIMESleep = 500000000; + int NumberOfTries = 40; + + timespec ts_req; + ts_req.tv_nsec=TIMESleep; + ts_req.tv_sec=0; + timespec ts_rem; + ts_rem.tv_nsec=0; + ts_rem.tv_sec=0; + + CORBA::Object_var obj; + + try + { + // NB. You can't use SALOME_NamingService class because + // it uses MESSAGE macro + // Otherwise, you will get segmentation fault. + + CosNaming::NamingContext_var inc; + CosNaming::Name name; + name.length(1); + name[0].id = CORBA::string_dup(serverName.c_str()); + CORBA::Object_var theObj=CORBA::Object::_nil(); + + for (int itry=0; itry < NumberOfTries; itry++) + { + try + { + if(!CORBA::is_nil(orb)) + theObj = orb->resolve_initial_references("NameService"); + if (!CORBA::is_nil(theObj)) + inc = CosNaming::NamingContext::_narrow(theObj); + } + catch( CORBA::COMM_FAILURE& ) + { + cout << "TraceCollector_WaitForServerReadiness: " + << "CORBA::COMM_FAILURE: " + << "Unable to contact the Naming Service" << endl; + } + catch(...) + { + cout << "TraceCollector_WaitForServerReadiness: " + << "Unknown exception dealing with Naming Service" << endl; + } + + obj=CORBA::Object::_nil(); + if(!CORBA::is_nil(inc)) + { + try + { + obj = inc->resolve(name); + if (!CORBA::is_nil(obj)) + { + cout << "TraceCollector_WaitForServerReadiness: " + << serverName << " found in CORBA Name Service" << endl; + break; + } + } + catch (const CosNaming::NamingContext::NotFound&) + { + cout << "Caught exception: Naming Service can't found Logger"; + } + } + int a = nanosleep(&ts_req,&ts_rem); + cout << "TraceCollector_WaitForServerReadiness: retry look for" + << serverName << endl; + } + } + catch (const CosNaming::NamingContext::NotFound&) + { + cout << "Caught exception: Naming Service can't found Logger"; + } + catch (CORBA::COMM_FAILURE&) + { + cout << "Caught CORBA::SystemException CommFailure."; + } + catch (CORBA::SystemException&) + { + cout << "Caught CORBA::SystemException."; + } + catch (CORBA::Exception&) + { + cout << "Caught CORBA::Exception."; + } + catch (...) + { + cout << "Caught unknown exception."; + } + return obj._retn(); +} + diff --git a/src/SALOMETraceCollector/TraceCollector_WaitForServerReadiness.hxx b/src/SALOMETraceCollector/TraceCollector_WaitForServerReadiness.hxx new file mode 100644 index 000000000..c31d11684 --- /dev/null +++ b/src/SALOMETraceCollector/TraceCollector_WaitForServerReadiness.hxx @@ -0,0 +1,36 @@ +// Copyright (C) 2004 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File : LocalTrace_WaitForServerReadiness.hxx +// Author : Paul RASCLE (EDF) +// Module : KERNEL +// $Header$ + +#ifndef _TRACECOLLECTOR_WAITFORSERVERREADINESS_HXX_ +#define _TRACECOLLECTOR_WAITFORSERVERREADINESS_HXX_ + +#include +#include + +CORBA::Object_ptr TraceCollector_WaitForServerReadiness(CORBA::ORB_ptr theOrb, + std::string serverName); + +#endif