Salome HOME
PR: bug 7769 loader aborts when logger not found in naming service,
authorprascle <prascle>
Wed, 19 Jan 2005 06:57:12 +0000 (06:57 +0000)
committerprascle <prascle>
Wed, 19 Jan 2005 06:57:12 +0000 (06:57 +0000)
class renamed in coherence with library name.

src/SALOMETraceCollector/LocalTrace_WaitForServerReadiness.cxx [deleted file]
src/SALOMETraceCollector/LocalTrace_WaitForServerReadiness.hxx [deleted file]
src/SALOMETraceCollector/Makefile.in
src/SALOMETraceCollector/SALOMETraceCollector.cxx
src/SALOMETraceCollector/SALOMETraceCollector.hxx
src/SALOMETraceCollector/TraceCollector_WaitForServerReadiness.cxx [new file with mode: 0644]
src/SALOMETraceCollector/TraceCollector_WaitForServerReadiness.hxx [new file with mode: 0644]

diff --git a/src/SALOMETraceCollector/LocalTrace_WaitForServerReadiness.cxx b/src/SALOMETraceCollector/LocalTrace_WaitForServerReadiness.cxx
deleted file mode 100644 (file)
index 75a0952..0000000
+++ /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 <iostream>
-#include <ctime>
-
-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 (file)
index a5e1c9a..0000000
+++ /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 <CORBA.h> 
-#include <string>
-
-CORBA::Object_ptr  LocalTrace_WaitForServerReadiness(CORBA::ORB_ptr theOrb,
-                                                    std::string serverName);
-
-#endif
index 394805883714c499f403fa6f12e16530da3414c3..3df7820fdcc332bce319a0f96f6104a35a1e6e01 100644 (file)
@@ -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+= 
index 9336706359b76b55953d274e2ddcec9d4e213a20..1c070984869bc95190154f320a421a54873c7166 100644 (file)
@@ -33,7 +33,7 @@
 using namespace std;
 
 #include "SALOMETraceCollector.hxx"
-#include "LocalTrace_WaitForServerReadiness.hxx"
+#include "TraceCollector_WaitForServerReadiness.hxx"
 //#include "SALOME_Log.hxx"
 #include <SALOMEconfig.h>
 #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))
index 846c4adf28711efca9c7c3b6d9d5daeb28455ccf..7d1b4bbb801185abfb14746bc6113540820d80e6 100644 (file)
@@ -31,6 +31,8 @@
 #include <CORBA.h>
 #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 (file)
index 0000000..9e91b71
--- /dev/null
@@ -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 <iostream>
+#include <ctime>
+
+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 (file)
index 0000000..c31d116
--- /dev/null
@@ -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 <CORBA.h> 
+#include <string>
+
+CORBA::Object_ptr  TraceCollector_WaitForServerReadiness(CORBA::ORB_ptr theOrb,
+                                                        std::string serverName);
+
+#endif