Salome HOME
Typo-fix by Kunda
[modules/kernel.git] / src / NamingService / SALOME_NamingService.cxx
index bce5f23380f99cd43714396c7f2400a235ebdcaa..a8c213b03a47f8604dfeff249cb5f0c0e7d21a8b 100644 (file)
@@ -1,31 +1,31 @@
-//  SALOME NamingService : wrapping NamingService services
-//
-//  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
-//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+// Copyright (C) 2007-2016  CEA/DEN, EDF R&D, OPEN CASCADE
 //
-//  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.
+// Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
 //
-//  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.
+// 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, or (at your option) any later version.
 //
-//  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
+// 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.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
+
+//  SALOME NamingService : wrapping NamingService services
 //  File   : SALOME_NamingService.cxx
 //  Author : Estelle Deville
 //  Module : SALOME
 //  $Header$
-
+//
 #include "SALOME_NamingService.hxx"
 #include "ServiceUnreachable.hxx"
 
 #include <iostream>
 #include <cstring>
 #include <string>
+#include <cstdio>
+
+#ifdef WIN32
+#define strdup _strdup
+#endif
 
-using namespace std;
+/*! \class SALOME_NamingService
+    \brief A class to manage the SALOME naming service
+
+*/
 
 // ============================================================================
 /*! \brief Default Constructor without ORB reference.
@@ -47,7 +55,6 @@ using namespace std;
 
 SALOME_NamingService::SALOME_NamingService()
 {
-  MESSAGE("SALOME_NamingService default constructor");
   _orb = CORBA::ORB::_nil();
   _root_context = CosNaming::NamingContext::_nil();
 }
@@ -62,8 +69,7 @@ SALOME_NamingService::SALOME_NamingService()
 
 SALOME_NamingService::SALOME_NamingService(CORBA::ORB_ptr orb)
 {
-  MESSAGE("SALOME_NamingService creation");
-  _orb = orb ;
+  _orb = CORBA::ORB::_duplicate(orb);
   _initialize_root_context();
 }
 
@@ -86,16 +92,21 @@ SALOME_NamingService::~SALOME_NamingService()
  * 
  *  Initializes ORB reference and naming service root context.
  *  For use after default constructor.
+ *  If param orb is null, the orb is initialized
  *  \param orb CORBA::ORB_ptr arguments
  */ 
 // ============================================================================
 
 void SALOME_NamingService::init_orb(CORBA::ORB_ptr orb)
 {
-  MESSAGE("SALOME_NamingService initialisation");
-
   Utils_Locker lock (&_myMutex);
-  _orb = orb;
+  if(orb)
+    _orb = CORBA::ORB::_duplicate(orb);
+  else
+    {
+      int argc=0;
+      _orb = CORBA::ORB_init(argc, 0); // Here we make the assumption that the orb has already been initialized
+    }
 
   _initialize_root_context();
 }
@@ -125,203 +136,179 @@ void SALOME_NamingService::Register(CORBA::Object_ptr ObjRef,
                                     const char* Path)
   throw(ServiceUnreachable)
 {
-  MESSAGE("BEGIN OF Register: " << Path);
-
   Utils_Locker lock (&_myMutex);
 
   // --- _current_context is replaced to the _root_context
-  //     if the Path begins whith '/'
+  //     if the Path begins with '/'
 
-  if (Path[0] == '/')
-    {
-      _current_context = _root_context;
-    }
+  if (Path[0] == '/'){
+    _current_context = _root_context;
+  }
 
   // --- the resolution of the directory path has to be done
   //      to place the current_context to the correct node
 
   CosNaming::Name context_name;
-  vector<string> splitPath;
+  std::vector<std::string> splitPath;
   int dimension_resultat = _createContextNameDir(Path,
-                                                context_name,
-                                                splitPath,
-                                                true);
+                                                 context_name,
+                                                 splitPath,
+                                                 true);
 
   CORBA::Boolean not_exist = false;
 
-  if (dimension_resultat > 0)
-    {
-      // A directory is treated (not only an object name)
-      // test if the directory where ObjRef should be recorded already exists
-      // If not, create the new context
-
-      try
-        {
-          CORBA::Object_var obj = _current_context->resolve(context_name);
-          _current_context = CosNaming::NamingContext::_narrow(obj);
-        }
-
-      catch (CosNaming::NamingContext::NotFound &)
-        {
-          // --- failed to resolve, therefore assume cold start
-          not_exist = true;
-        }
-
-      catch (CosNaming::NamingContext::InvalidName &)
-        {
-          INFOS("Register() : CosNaming::NamingContext::InvalidName");
-        }
-
-      catch (CosNaming::NamingContext::CannotProceed &)
-        {
-          INFOS("Register() : CosNaming::NamingContext::CannotProceed");
-        }
-
-      catch (CORBA::SystemException&)
-        {
-          INFOS("Register() : CORBA::SystemException: "
-                << "unable to contact the naming service");
-          throw ServiceUnreachable();
-        }
-
-      if (not_exist)
-        {
-          try
-            {
-              context_name.length(1);
-              for (int i = 0 ; i < dimension_resultat ;i++)
-                {
-                  context_name[0].id =
-                    CORBA::string_dup(splitPath[i].c_str());
-                  context_name[0].kind = CORBA::string_dup("dir");
-                  // SCRUTE(_context_name[0].id);
-                  // --- check if the path is created
-                  try
-                    {
-                      // --- if the context is already created, nothing to do
-                      CORBA::Object_var obj =
-                        _current_context->resolve(context_name);
-                      _current_context =
-                        CosNaming::NamingContext::_narrow(obj);
-                    }
-
-                  catch (CosNaming::NamingContext::NotFound &)
-                    {
-                      // --- the context must be created
-                      CosNaming::NamingContext_var temp_context =
-                        _current_context->bind_new_context(context_name);
-                      _current_context = temp_context;
-                    }
-                }
-            }
-
-          catch (CosNaming::NamingContext::AlreadyBound&)
-            {
-              INFOS("Register() : CosNaming::NamingContext::AlreadyBound");
-            }
+  if (dimension_resultat > 0){
+    // A directory is treated (not only an object name)
+    // test if the directory where ObjRef should be recorded already exists
+    // If not, create the new context
+    
+    try{
+      CORBA::Object_var obj = _current_context->resolve(context_name);
+      _current_context = CosNaming::NamingContext::_narrow(obj);
+    }
 
-          catch (CosNaming::NamingContext::NotFound& ex)
-            {
-              CosNaming::Name n = ex.rest_of_name;
+    catch (CosNaming::NamingContext::NotFound &){
+      // --- failed to resolve, therefore assume cold start
+      not_exist = true;
+    }
 
-              if (ex.why == CosNaming::NamingContext::missing_node)
-                INFOS("Register() : " << (char *) n[0].id
-                      << " (" << (char *) n[0].kind << ") not found");
+    catch (CosNaming::NamingContext::InvalidName &){
+      INFOS("Register() : CosNaming::NamingContext::InvalidName");
+    }
 
-              if (ex.why == CosNaming::NamingContext::not_context)
-                INFOS("Register() : " << (char *) n[0].id
-                      << " (" << (char *) n[0].kind
-                      << ") is not a context");
+    catch (CosNaming::NamingContext::CannotProceed &){
+      INFOS("Register() : CosNaming::NamingContext::CannotProceed");
+    }
 
-              if (ex.why == CosNaming::NamingContext::not_object)
-                INFOS("Register() : " << (char *) n[0].id
-                      << " (" << (char *) n[0].kind
-                      << ") is not an object");
-            }
+    catch (CORBA::SystemException&){
+      INFOS("Register() : CORBA::SystemException: "
+            << "unable to contact the naming service");
+      throw ServiceUnreachable();
+    }
 
-          catch (CosNaming::NamingContext::CannotProceed&)
-            {
-              INFOS("Register(): CosNaming::NamingContext::CannotProceed");
-            }
+    if (not_exist){
+      try{
+        context_name.length(1);
+        for (int i = 0 ; i < dimension_resultat ;i++){
+          context_name[0].id = CORBA::string_dup(splitPath[i].c_str());
+          context_name[0].kind = CORBA::string_dup("dir");
+          // SCRUTE(_context_name[0].id);
+          // --- check if the path is created
+          try{
+            // --- if the context is already created, nothing to do
+            CORBA::Object_var obj = _current_context->resolve(context_name);
+            _current_context = CosNaming::NamingContext::_narrow(obj);
+          }
 
-          catch (CosNaming::NamingContext::InvalidName&)
-            {
-              INFOS("Register(): CosNaming::NamingContext::InvalidName");
+          catch (CosNaming::NamingContext::NotFound &){
+            try{
+              // --- the context must be created
+              CosNaming::NamingContext_var temp_context =
+                _current_context->bind_new_context(context_name);
+              _current_context = temp_context;
             }
-
-          catch (CORBA::SystemException&)
-            {
-              INFOS("Register():CORBA::SystemException: "
-                    << "unable to contact the naming service");
-              throw ServiceUnreachable();
+            catch (CosNaming::NamingContext::AlreadyBound&){
+              CORBA::Object_var obj = _current_context->resolve(context_name);
+              _current_context = CosNaming::NamingContext::_narrow(obj);
             }
+          }
         }
+      }
+
+      catch (CosNaming::NamingContext::AlreadyBound&){
+        INFOS("Register() : CosNaming::NamingContext::AlreadyBound");
+      }
+
+      catch (CosNaming::NamingContext::NotFound& ex){
+        CosNaming::Name n = ex.rest_of_name;
+
+        if (ex.why == CosNaming::NamingContext::missing_node)
+          INFOS("Register() : " << (char *) n[0].id
+                << " (" << (char *) n[0].kind << ") not found");
+
+        if (ex.why == CosNaming::NamingContext::not_context)
+          INFOS("Register() : " << (char *) n[0].id
+                << " (" << (char *) n[0].kind
+                << ") is not a context");
+
+        if (ex.why == CosNaming::NamingContext::not_object)
+          INFOS("Register() : " << (char *) n[0].id
+                << " (" << (char *) n[0].kind
+                << ") is not an object");
+      }
+
+      catch (CosNaming::NamingContext::CannotProceed&){
+        INFOS("Register(): CosNaming::NamingContext::CannotProceed");
+      }
+
+      catch (CosNaming::NamingContext::InvalidName&){
+        INFOS("Register(): CosNaming::NamingContext::InvalidName");
+      }
+
+      catch (CORBA::SystemException&){
+        INFOS("Register():CORBA::SystemException: "
+              << "unable to contact the naming service");
+        throw ServiceUnreachable();
+      }
     }
+  }
 
   // --- The current directory is now the directory where the object should
   //     be recorded
 
   int sizePath = splitPath.size();
-  if (sizePath > dimension_resultat)
-    {
-      ASSERT(sizePath == dimension_resultat+1);
-      context_name.length(1);
+  if (sizePath > dimension_resultat){
+    ASSERT(sizePath == dimension_resultat+1);
+    context_name.length(1);
 
-      try
-       {
-         // --- the last element is an object and not a directory
+    try{
+      // --- the last element is an object and not a directory
 
-         context_name[0].id =
-           CORBA::string_dup(splitPath[dimension_resultat].c_str());
-         context_name[0].kind = CORBA::string_dup("object");
-         //SCRUTE(context_name[0].id);
+      context_name[0].id = CORBA::string_dup(splitPath[dimension_resultat].c_str());
+      context_name[0].kind = CORBA::string_dup("object");
+      //SCRUTE(context_name[0].id);
 
-         _current_context->bind(context_name, ObjRef);
-       }
+      _current_context->bind(context_name, ObjRef);
+    }
 
-      catch (CosNaming::NamingContext::NotFound& ex)
-       {
-         CosNaming::Name n = ex.rest_of_name;
+    catch (CosNaming::NamingContext::NotFound& ex){
+      CosNaming::Name n = ex.rest_of_name;
 
-         if (ex.why == CosNaming::NamingContext::missing_node)
-           INFOS("Register() : " << (char *) n[0].id
-                 << " (" << (char *) n[0].kind << ") not found");
+      if (ex.why == CosNaming::NamingContext::missing_node)
+        INFOS("Register() : " << (char *) n[0].id
+              << " (" << (char *) n[0].kind << ") not found");
 
-         if (ex.why == CosNaming::NamingContext::not_context)
-           INFOS("Register() : " << (char *) n[0].id
-                 << " (" << (char *) n[0].kind
-                 << ") is not a context");
+      if (ex.why == CosNaming::NamingContext::not_context)
+        INFOS("Register() : " << (char *) n[0].id
+              << " (" << (char *) n[0].kind
+              << ") is not a context");
 
-         if (ex.why == CosNaming::NamingContext::not_object)
-           INFOS("Register() : " << (char *) n[0].id
-                 << " (" << (char *) n[0].kind
-                 << ") is not an object");
-       }
+      if (ex.why == CosNaming::NamingContext::not_object)
+        INFOS("Register() : " << (char *) n[0].id
+              << " (" << (char *) n[0].kind
+              << ") is not an object");
+    }
 
-      catch (CosNaming::NamingContext::CannotProceed&)
-       {
-         INFOS("Register(): CosNaming::NamingContext::CannotProceed");
-       }
+    catch (CosNaming::NamingContext::CannotProceed&){
+      INFOS("Register(): CosNaming::NamingContext::CannotProceed");
+    }
 
-      catch (CosNaming::NamingContext::InvalidName&)
-       {
-         INFOS("Register(): CosNaming::NamingContext::InvalidName");
-       }
+    catch (CosNaming::NamingContext::InvalidName&){
+      INFOS("Register(): CosNaming::NamingContext::InvalidName");
+    }
 
-      catch (CosNaming::NamingContext::AlreadyBound&)
-       {
-         INFOS("Register(): CosNaming::NamingContext::AlreadyBound, "
-               << "object will be rebind");
-         _current_context->rebind(context_name, ObjRef);
-       }
+    catch (CosNaming::NamingContext::AlreadyBound&){
+      INFOS("Register(): CosNaming::NamingContext::AlreadyBound, "
+            << "object will be rebind");
+      _current_context->rebind(context_name, ObjRef);
+    }
 
-      catch (CORBA::SystemException&)
-       {
-         INFOS("!!!Register(): CORBA::SystemException: "
-               << "unable to contact the naming service");
-         throw ServiceUnreachable();
-       }
+    catch (CORBA::SystemException&){
+      INFOS("!!!Register(): CORBA::SystemException: "
+            << "unable to contact the naming service");
+      throw ServiceUnreachable();
     }
+  }
 }
 
 // ============================================================================
@@ -344,12 +331,10 @@ void SALOME_NamingService::Register(CORBA::Object_ptr ObjRef,
 CORBA::Object_ptr SALOME_NamingService::Resolve(const char* Path)
   throw(ServiceUnreachable)
 {
-  MESSAGE("BEGIN OF Resolve: " << Path);
-
   Utils_Locker lock (&_myMutex);
 
   // --- _current_context is replaced to the _root_context
-  //     if the Path begins whith '/'
+  //     if the Path begins with '/'
 
   if (Path[0] == '/')
     {
@@ -360,15 +345,15 @@ CORBA::Object_ptr SALOME_NamingService::Resolve(const char* Path)
   //     to place the current_context to the correct node
 
   CosNaming::Name context_name;
-  vector<string> splitPath;
-  int dimension_resultat = _createContextNameDir(Path,
-                                                context_name,
-                                                splitPath,
-                                                false);
+  std::vector<std::string> splitPath;
+  _createContextNameDir(Path,
+                                                 context_name,
+                                                 splitPath,
+                                                 false);
 
   ASSERT(!CORBA::is_nil(_current_context));
 
-  CORBA::Object_ptr obj =  CORBA::Object::_nil();
+  CORBA::Object_var obj =  CORBA::Object::_nil();
 
   try
     {
@@ -380,7 +365,7 @@ CORBA::Object_ptr SALOME_NamingService::Resolve(const char* Path)
       CosNaming::Name n = ex.rest_of_name;
 
       if (ex.why == CosNaming::NamingContext::missing_node)
-        INFOS("Resolve() : " << (char *) n[0].id
+        MESSAGE("Resolve() : " << (char *) n[0].id
               << " (" << (char *) n[0].kind << ") not found");
 
       if (ex.why == CosNaming::NamingContext::not_context)
@@ -411,14 +396,14 @@ CORBA::Object_ptr SALOME_NamingService::Resolve(const char* Path)
       throw ServiceUnreachable();
     }
 
-  return obj;
+  return obj._retn();
 }
 
 // ============================================================================
-/*! \brief get the CORBA object reference associated to an uncomplete name.
+/*! \brief get the CORBA object reference associated to an incomplete name.
  *
- *  get the CORBA object reference associated to an uncomplete name with a
- *  path. Look for the first occurence of name*.
+ *  get the CORBA object reference associated to an incomplete name with a
+ *  path. Look for the first occurrence of name*.
  *  If the NamingService is out, the exception ServiceUnreachable is thrown 
  * \param Path pathname under the form "/path/name" (Absolute reference !)
  *             search the fist reference like "/path(.dir)/name*(.kind)"
@@ -430,26 +415,23 @@ CORBA::Object_ptr SALOME_NamingService::Resolve(const char* Path)
 CORBA::Object_ptr SALOME_NamingService::ResolveFirst(const char* Path)
   throw(ServiceUnreachable)
 {
-  MESSAGE("ResolveFirst");
-
   Utils_Locker lock (&_myMutex);
-  SCRUTE(Path);
 
-  string thePath = Path;
-  string basePath = "";
-  string name = thePath;
+  std::string thePath = Path;
+  std::string basePath = "";
+  std::string name = thePath;
 
-  string::size_type idx = thePath.rfind('/');
+  std::string::size_type idx = thePath.rfind('/');
 
-  if (idx != string::npos) // at least one '/' found
+  if (idx != std::string::npos) // at least one '/' found
     {
       basePath = thePath.substr(0, idx);
       name = thePath.substr(idx + 1);
-      SCRUTE(basePath);
+//       SCRUTE(basePath);
     }
 
-  SCRUTE(name);
-  CORBA::Object_ptr obj = CORBA::Object::_nil();
+//   SCRUTE(name);
+  CORBA::Object_var obj = CORBA::Object::_nil();
 
   bool isOk = false;
   if (basePath.empty())
@@ -459,23 +441,21 @@ CORBA::Object_ptr SALOME_NamingService::ResolveFirst(const char* Path)
   
   if (isOk)
     {
-      vector<string> listElem = list_directory();
-      vector<string>::iterator its = listElem.begin();
+      std::vector<std::string> listElem = list_directory();
+      std::vector<std::string>::iterator its = listElem.begin();
       
       while (its != listElem.end())
-       {
-         MESSAGE(*its);
-         
-         if ((*its).find(name) == 0)
-           {
-             return Resolve((*its).c_str());
-           }
-         
-         its++;
-       }
+        {
+          if ((*its).find(name) == 0)
+            {
+              return Resolve((*its).c_str());
+            }
+          
+          its++;
+        }
     }
 
-  return obj;
+  return obj._retn();
 }
 
 // ============================================================================
@@ -486,9 +466,9 @@ CORBA::Object_ptr SALOME_NamingService::ResolveFirst(const char* Path)
  *  number of processors.
  *  If the NamingService is out, the exception ServiceUnreachable is thrown.
  * \param hostname      name of the machine on which the component is searched.
- * \param containername name of the container in which the component is
-                        instanciated.
- * \param componentname name of the component we are looking for an existing 
+ * \param containerName name of the container in which the component is
+                        instantiated.
+ * \param componentName name of the component we are looking for an existing 
                         instance.
  * \param nbproc        in case of multi processor machine, container name is
  *                      suffixed with _nbproc.
@@ -498,16 +478,14 @@ CORBA::Object_ptr SALOME_NamingService::ResolveFirst(const char* Path)
 
 CORBA::Object_ptr
 SALOME_NamingService::ResolveComponent(const char* hostname,
-                                      const char* containerName,
-                                      const char* componentName,
-                                      const int nbproc)
+                                       const char* containerName,
+                                       const char* componentName,
+                                       const int nbproc)
   throw(ServiceUnreachable)
 {
-  MESSAGE("ResolveComponent");
-
   Utils_Locker lock (&_myMutex);
 
-  string name = "/Containers/";
+  std::string name = "/Containers/";
 
   name += hostname;
 
@@ -520,7 +498,7 @@ SALOME_NamingService::ResolveComponent(const char* hostname,
           char *newContainerName = new char[strlen(containerName) + 8];
           sprintf(newContainerName, "%s_%d", containerName, nbproc);
           name += newContainerName;
-         delete [] newContainerName;
+          delete [] newContainerName;
         }
 
       else
@@ -536,32 +514,35 @@ SALOME_NamingService::ResolveComponent(const char* hostname,
   else
     {
       SCRUTE(name);
-      if (Change_Directory(name.c_str()))
-       {
-         vector<string> contList = list_subdirs();
-
-         for (unsigned int ind = 0; ind < contList.size(); ind++)
-           {
-             name = contList[ind].c_str();
-
-             if ( nbproc >= 1 )
-               {
-                 char *str_nbproc = new char[8];
-                 sprintf(str_nbproc, "_%d", nbproc);
-                 if( strstr(name.c_str(),str_nbproc) == NULL)
-                   continue; // check only containers with _%d in name
-                 delete [] str_nbproc;
-               }
-
-             name += "/";
-             name += componentName;
-             SCRUTE(name);
-             CORBA::Object_ptr obj = ResolveFirst(name.c_str());
-
-             if ( !CORBA::is_nil(obj) )
-               return obj;
-           }
-       }
+      std::string basename = name;
+      if (Change_Directory(basename.c_str()))
+        {
+          std::vector<std::string> contList = list_subdirs();
+
+          for (unsigned int ind = 0; ind < contList.size(); ind++)
+            {
+              name = contList[ind].c_str();
+
+              if ( nbproc >= 1 )
+                {
+                  char *str_nbproc = new char[8];
+                  sprintf(str_nbproc, "_%d", nbproc);
+                  if( strstr(name.c_str(),str_nbproc) == NULL)
+                    continue; // check only containers with _%d in name
+                  delete [] str_nbproc;
+                }
+
+              name += "/";
+              name += componentName;
+              SCRUTE(name);
+              CORBA::Object_ptr obj = ResolveFirst(name.c_str());
+
+              if ( !CORBA::is_nil(obj) )
+                return obj;
+              else
+                Change_Directory(basename.c_str());
+            }
+        }
 
       return CORBA::Object::_nil();
     }
@@ -578,11 +559,11 @@ SALOME_NamingService::ResolveComponent(const char* hostname,
  */
 // ============================================================================
 
-string SALOME_NamingService::ContainerName(const char *containerName)
+std::string SALOME_NamingService::ContainerName(const char *containerName)
 {
-  string ret;
+  std::string ret,containerNameCpp(containerName);
 
-  if (strlen(containerName) == 0)
+  if (containerNameCpp.empty())
     ret = "FactoryServer";
   else
     ret = containerName;
@@ -591,43 +572,36 @@ string SALOME_NamingService::ContainerName(const char *containerName)
 }
 
 // ============================================================================
-/*! \brief build a container name, given a MachineParameters struct.
+/*! \brief build a container name, given a ContainerParameters struct.
  *
- *  Build a container name with a MachineParameters struct. In case of multi
- *  processor machine, container name is suffixed with _nbproc. nproc equals
- *  (number of nodes)*(number of processor per nodes).
- * \param params struct from which we get container name (may be
- *               empty),  number of nodes and number of processor
- *               per node.
+ *  Build a container name with a ContainerParameters struct. In case of multi
+ *  processor machine, container name is suffixed with number of processors.
+ * \param params struct from which we get container name (may be empty) and
+ *               number of processors.
  * \return a container name without the path.
- * \sa BuildContainerNameForNS(const Engines::MachineParameters& params,
+ * \sa BuildContainerNameForNS(const Engines::ContainerParameters& params,
  *                             const char *hostname)
  */
 // ============================================================================
 
-string 
-SALOME_NamingService::ContainerName(const Engines::MachineParameters& params)
+std::string SALOME_NamingService::ContainerName(const Engines::ContainerParameters& params)
 {
   int nbproc;
 
   if ( !params.isMPI )
     nbproc = 0;
-  else if ( (params.nb_node <= 0) && (params.nb_proc_per_node <= 0) )
+  else if ( params.nb_proc <= 0 )
     nbproc = 1;
-  else if ( params.nb_node == 0 )
-    nbproc = params.nb_proc_per_node;
-  else if ( params.nb_proc_per_node == 0 )
-    nbproc = params.nb_node;
   else
-    nbproc = params.nb_node * params.nb_proc_per_node;
+    nbproc = params.nb_proc;
 
-  string ret = ContainerName(params.container_name);
+  std::string ret(ContainerName(params.container_name));
 
   if ( nbproc >= 1 )
     {
-      char *suffix = new char[8];
-      sprintf(suffix, "_%d", nbproc);
-      ret += suffix;
+          std::ostringstream suffix;
+          suffix << "_" << nbproc;
+      ret += suffix.str();
     }
 
   return ret;
@@ -639,19 +613,17 @@ SALOME_NamingService::ContainerName(const Engines::MachineParameters& params)
  *  Build a string representing the absolute pathname of a container in
  *  SALOME_NamingService. This form gives a suffixed containerName in case of
  *  multi processor machine.
- * \param params struct from which we get container name (may be
- *               empty),  number of nodes and number of processor
- *               per node.
- * /param hostname name of the host of the container, without domain names.
- * /return the path under the form /Containers/hostname/containerName
- * /sa ContainerName(const Engines::MachineParameters& params)
+ * \param containerName name of the container in which the component is
+                        instantiated.
+ * \param hostname name of the host of the container, without domain names.
+ * \return the path under the form /Containers/hostname/containerName
+ * \sa ContainerName(const Engines::MachineParameters& params)
  */
 // ============================================================================
 
-string SALOME_NamingService::BuildContainerNameForNS(const char *containerName,
-                                                    const char *hostname)
+std::string SALOME_NamingService::BuildContainerNameForNS(const char *containerName, const char *hostname)
 {
-  string ret = "/Containers/";
+  std::string ret("/Containers/");
   ret += hostname;
   ret += "/";
   ret += ContainerName(containerName);
@@ -664,19 +636,16 @@ string SALOME_NamingService::BuildContainerNameForNS(const char *containerName,
  *
  *  Build a string representing the absolute pathname of a container in
  *  SALOME_NamingService.
- * /param params used as it is, or replaced by FactoryServer if empty.
- * /param hostname name of the host of the container, without domain names.
- * /return the path under the form /Containers/hostname/containerName
- * /sa ContainerName(const char *containerName)
+ * \param params used as it is, or replaced by FactoryServer if empty.
+ * \param hostname name of the host of the container, without domain names.
+ * \return the path under the form /Containers/hostname/containerName
+ * \sa ContainerName(const char *containerName)
  */
 // ============================================================================
 
-string
-SALOME_NamingService::
-BuildContainerNameForNS(const Engines::MachineParameters& params,
-                       const char *hostname)
+std::string SALOME_NamingService::BuildContainerNameForNS(const Engines::ContainerParameters& params, const char *hostname)
 {
-  string ret = "/Containers/";
+  std::string ret("/Containers/");
   ret += hostname;
   ret += "/";
   ret += ContainerName(params);
@@ -688,12 +657,12 @@ BuildContainerNameForNS(const Engines::MachineParameters& params,
 /*! \brief search a name in current directory.
  *
  *  Search a name in the current directory. after call, the current directory
- *  is changed to the directory containing the last occurence of name found.
- *  If no occurence found (see return value), current directory remains
+ *  is changed to the directory containing the last occurrence of name found.
+ *  If no occurrence found (see return value), current directory remains
  *  unchanged.
  *
  * \param  name the name to search.
- * \return number of occurences found.
+ * \return number of occurrences found.
  * \sa Change_Directory(const char* Path)
  */ 
 // ============================================================================
@@ -701,8 +670,6 @@ BuildContainerNameForNS(const Engines::MachineParameters& params,
 int SALOME_NamingService::Find(const char* name)
 throw(ServiceUnreachable)
 {
-  MESSAGE("BEGIN OF Find " << name);
-
   Utils_Locker lock (&_myMutex);
 
   CORBA::Long occurence_number = 0 ;
@@ -735,22 +702,19 @@ throw(ServiceUnreachable)
  *               path, to current context. Prefer absolute pathname, relative
  *               pathname are not safe, when SALOME_NamingService object is
  *               shared or use in multithreaded context.   
- *  \return true if successfull
- *          (creation not strictly garanteed if true, because Register may
+ *  \return true if successful
+ *          (creation not strictly guaranteed if true, because Register may
  *           catch some specific unlikely exception without throw anything
  *           --- to be corrected ---)
  *  \sa RegisterCORBA::Object_ptr ObjRef, const char* Path)
  */ 
 // ============================================================================
 
-bool SALOME_NamingService::Create_Directory(const char* Path)
-throw(ServiceUnreachable)
+bool SALOME_NamingService::Create_Directory(const char* Path) throw(ServiceUnreachable)
 {
-  MESSAGE("BEGIN OF Create_Directory");
-
   Utils_Locker lock (&_myMutex);
 
-  string path(Path);
+  std::string path(Path);
 
   // --- if path empty, nothing to create, no context change
 
@@ -761,7 +725,6 @@ throw(ServiceUnreachable)
 
   if (path == "/")
     {
-      MESSAGE("Create Directory '/', just change to root_context");
       _current_context = _root_context;
       return true;
     }
@@ -788,13 +751,11 @@ throw(ServiceUnreachable)
  */ 
 // ============================================================================
 
-bool SALOME_NamingService::Change_Directory(const char* Path)
-throw(ServiceUnreachable)
+bool SALOME_NamingService::Change_Directory(const char* Path) throw(ServiceUnreachable)
 {
-  MESSAGE("BEGIN OF Change_Directory " << Path);
   Utils_Locker lock (&_myMutex);
 
-  string path(Path);
+  std::string path(Path);
 
   // --- if path empty, nothing to do
 
@@ -805,7 +766,6 @@ throw(ServiceUnreachable)
 
   if (path == "/")
     {
-      MESSAGE("Change_Directory is called to go to the root_context");
       _current_context = _root_context;
       return true;
     }
@@ -813,7 +773,7 @@ throw(ServiceUnreachable)
   CosNaming::NamingContext_var current_context = _current_context;
   bool changeOK = false;
 
-  // --- replace _current_context with _root_context if Path begins whith '/'
+  // --- replace _current_context with _root_context if Path begins with '/'
 
   if (path[0] == '/')
     current_context = _root_context;
@@ -823,13 +783,13 @@ throw(ServiceUnreachable)
   ASSERT(!CORBA::is_nil(current_context));
   
   if (path[path.length()-1] != '/') path += '/';
-  SCRUTE(path);
+//   SCRUTE(path);
   CosNaming::Name context_name;
-  vector<string> splitPath;
-  int dimension_resultat = _createContextNameDir(path.c_str(),
-                                                context_name,
-                                                splitPath,
-                                                true);
+  std::vector<std::string> splitPath;
+  _createContextNameDir(path.c_str(),
+                                                 context_name,
+                                                 splitPath,
+                                                 true);
   
   // --- Context creation
   
@@ -847,16 +807,16 @@ throw(ServiceUnreachable)
       CosNaming::Name n = ex.rest_of_name;
       
       if (ex.why == CosNaming::NamingContext::missing_node)
-       INFOS( "Change_Directory() : " << (char *) n[0].id
-              << " (" << (char *) n[0].kind << ") not found");
+        MESSAGE( "Change_Directory() : " << (char *) n[0].id
+               << " (" << (char *) n[0].kind << ") not found");
       if (ex.why == CosNaming::NamingContext::not_context)
-       INFOS("Change_Directory() : " << (char *) n[0].id
-             << " (" << (char *) n[0].kind
-                 << ") is not a context" );
+        INFOS("Change_Directory() : " << (char *) n[0].id
+              << " (" << (char *) n[0].kind
+                  << ") is not a context" );
       if (ex.why == CosNaming::NamingContext::not_object)
-       INFOS( "Change_Directory() : " << (char *) n[0].id
-              << " (" << (char *) n[0].kind
-              << ") is not an object" );
+        INFOS( "Change_Directory() : " << (char *) n[0].id
+               << " (" << (char *) n[0].kind
+               << ") is not an object" );
     }
   
   catch (CosNaming::NamingContext::CannotProceed&)
@@ -872,7 +832,7 @@ throw(ServiceUnreachable)
   catch (CORBA::SystemException&)
     {
       INFOS("Change_Directory():CORBA::SystemException : unable to contact"
-           << "the naming service");
+            << "the naming service");
       throw ServiceUnreachable();
     }
 
@@ -889,16 +849,13 @@ throw(ServiceUnreachable)
  */ 
 // ============================================================================
 
-char* SALOME_NamingService::Current_Directory()
-throw(ServiceUnreachable)
+char *SALOME_NamingService::Current_Directory() throw(ServiceUnreachable)
 {
-  MESSAGE("BEGIN OF Current_Directory");
-
   Utils_Locker lock (&_myMutex);
 
   CosNaming::NamingContext_var ref_context = _current_context;
 
-  vector<string> splitPath;
+  std::vector<std::string> splitPath;
   splitPath.resize(0);
   int lengthPath = 0;
   bool notFound = true ;
@@ -919,7 +876,7 @@ throw(ServiceUnreachable)
       throw ServiceUnreachable();
     }
 
-  string path;
+  std::string path;
   lengthPath = splitPath.size();
   for (int k = 0 ; k < lengthPath ;k++)
     {
@@ -942,11 +899,8 @@ throw(ServiceUnreachable)
  */ 
 // ============================================================================
 
-void SALOME_NamingService::list()
-throw(ServiceUnreachable)
+void SALOME_NamingService::list() throw(ServiceUnreachable)
 {
-  MESSAGE("Begin of list");
-
   Utils_Locker lock (&_myMutex)
 
     ;
@@ -964,33 +918,31 @@ throw(ServiceUnreachable)
   if (! CORBA::is_nil(binding_iterator))
     {
       while (binding_iterator->next_one(binding))
-       {
-         CosNaming::Name bindingName = binding->binding_name;
-
-         if (binding->binding_type == CosNaming::ncontext)
-           {
-             MESSAGE( "Context : " << bindingName[0].id );
-
-             try
-               {
-                 Change_Directory(bindingName[0].id);
-               }
-
-             catch (ServiceUnreachable&)
-               {
-                 INFOS( "list(): ServiceUnreachable" )
-                   throw ServiceUnreachable();
-               }
-
-             list();
-             _current_context = ref_context ;
-           }
-
-         else if (binding->binding_type == CosNaming::nobject)
-           {
-             MESSAGE( "Object : " << bindingName[0].id );
-           }
-       }
+        {
+          CosNaming::Name bindingName = binding->binding_name;
+
+          if (binding->binding_type == CosNaming::ncontext)
+            {
+              try
+                {
+                  Change_Directory(bindingName[0].id);
+                }
+
+              catch (ServiceUnreachable&)
+                {
+                  INFOS( "list(): ServiceUnreachable" )
+                    throw ServiceUnreachable();
+                }
+
+              list();
+              _current_context = ref_context ;
+            }
+
+          else if (binding->binding_type == CosNaming::nobject)
+            {
+              MESSAGE( "list(): no Object : " << bindingName[0].id );
+            }
+        }
 
       binding_iterator->destroy();
     }
@@ -1007,11 +959,10 @@ throw(ServiceUnreachable)
  */ 
 // ============================================================================
 
-vector<string> SALOME_NamingService::list_directory()
-throw(ServiceUnreachable)
+std::vector<std::string> SALOME_NamingService::list_directory() throw(ServiceUnreachable)
 {
-  MESSAGE("list_directory");
-  vector<string> dirList ;
+  Utils_Locker lock (&_myMutex);
+  std::vector<std::string> dirList ;
   dirList.resize(0);
 
   CosNaming::BindingList_var binding_list;
@@ -1034,12 +985,14 @@ throw(ServiceUnreachable)
 
       if (binding->binding_type == CosNaming::nobject)
         {
-          dirList.push_back(CORBA::string_dup(bindingName[0].id));
+          // remove memory leak
+          // dirList.push_back(CORBA::string_dup(bindingName[0].id));
+          dirList.push_back(std::string(bindingName[0].id));
         }
     }
 
-  for (unsigned int ind = 0; ind < dirList.size(); ind++)
-    MESSAGE("list_directory : Object : " << dirList[ind]);
+//   for (unsigned int ind = 0; ind < dirList.size(); ind++)
+//     MESSAGE("list_directory : Object : " << dirList[ind]);
 
   binding_iterator->destroy();
 
@@ -1059,11 +1012,10 @@ throw(ServiceUnreachable)
  */ 
 // ============================================================================
 
-vector<string> SALOME_NamingService::list_subdirs()
-throw(ServiceUnreachable)
+std::vector<std::string> SALOME_NamingService::list_subdirs() throw(ServiceUnreachable)
 {
-  MESSAGE("list_subdirs");
-  vector<string> dirList ;
+  Utils_Locker lock (&_myMutex);
+  std::vector<std::string> dirList ;
   dirList.resize(0);
 
   CosNaming::BindingList_var binding_list;
@@ -1086,12 +1038,12 @@ throw(ServiceUnreachable)
 
       if (binding->binding_type == CosNaming::ncontext)
         {
-          dirList.push_back(CORBA::string_dup(bindingName[0].id));
+          dirList.push_back(bindingName[0].id.in());
         }
     }
 
-  for (unsigned int ind = 0; ind < dirList.size(); ind++)
-    MESSAGE("list_directory : Object : " << dirList[ind]);
+  // for (unsigned int ind = 0; ind < dirList.size(); ind++)
+  //   MESSAGE("list_directory : Object : " << dirList[ind]);
 
   binding_iterator->destroy();
 
@@ -1109,19 +1061,19 @@ throw(ServiceUnreachable)
  */ 
 // ============================================================================
 
-vector<string> SALOME_NamingService::list_directory_recurs()
+std::vector<std::string> SALOME_NamingService::list_directory_recurs()
 throw(ServiceUnreachable)
 {
-  MESSAGE("list_directory_recurs");
-
   Utils_Locker lock (&_myMutex);
 
-  vector<string> dirList ;
+  std::vector<std::string> dirList ;
 
-  string currentDir = Current_Directory();
+  char* currentDir = Current_Directory();
 
   _list_directory_recurs(dirList, "", currentDir);
 
+  free(currentDir);
+
   return dirList;
 }
 
@@ -1137,11 +1089,9 @@ throw(ServiceUnreachable)
 void SALOME_NamingService::Destroy_Name(const char* Path)
 throw(ServiceUnreachable)
 {
-  MESSAGE("BEGIN OF Destroy_Name " << Path);
-
   Utils_Locker lock (&_myMutex);
 
-  string path(Path);
+  std::string path(Path);
 
   // --- if path empty, nothing to do
 
@@ -1161,11 +1111,11 @@ throw(ServiceUnreachable)
   // --- context of the directory containing the object
 
   CosNaming::Name context_name;
-  vector<string> splitPath;
+  std::vector<std::string> splitPath;
   int dimension_resultat = _createContextNameDir(path.c_str(),
-                                                context_name,
-                                                splitPath,
-                                                true);
+                                                 context_name,
+                                                 splitPath,
+                                                 true);
 
   bool exist = false;
 
@@ -1178,7 +1128,7 @@ throw(ServiceUnreachable)
         {
           CORBA::Object_var obj = _current_context->resolve(context_name);
           _current_context = CosNaming::NamingContext::_narrow(obj);
-         exist = true;
+          exist = true;
         }
 
       catch (CosNaming::NamingContext::NotFound &ex)
@@ -1191,14 +1141,14 @@ throw(ServiceUnreachable)
           if (ex.why == CosNaming::NamingContext::missing_node)
             INFOS( "Destroy_Name(): " << (char *) n[0].id
                    << " (" << (char *) n[0].kind << ") not found" );
-         if (ex.why == CosNaming::NamingContext::not_context)
-           INFOS( "Destroy_Name() : " << (char *) n[0].id
-                  << " (" << (char *) n[0].kind
-                  << ") is not a context" );
-         if (ex.why == CosNaming::NamingContext::not_object)
-           INFOS( "Destroy_Name() : " << (char *) n[0].id
-                  << " (" << (char *) n[0].kind
-                  << ") is not an object" );
+          if (ex.why == CosNaming::NamingContext::not_context)
+            INFOS( "Destroy_Name() : " << (char *) n[0].id
+                   << " (" << (char *) n[0].kind
+                   << ") is not a context" );
+          if (ex.why == CosNaming::NamingContext::not_object)
+            INFOS( "Destroy_Name() : " << (char *) n[0].id
+                   << " (" << (char *) n[0].kind
+                   << ") is not an object" );
         }
 
       catch (CosNaming::NamingContext::InvalidName &)
@@ -1233,29 +1183,29 @@ throw(ServiceUnreachable)
       context_name.length(1);
 
       try
-       {
-         // --- the last element is an object and not a directory
+        {
+          // --- the last element is an object and not a directory
 
-         context_name[0].id =
-           CORBA::string_dup(splitPath[dimension_resultat].c_str());
-         context_name[0].kind = CORBA::string_dup("object");
-         SCRUTE(context_name[0].id);
+          context_name[0].id =
+            CORBA::string_dup(splitPath[dimension_resultat].c_str());
+          context_name[0].kind = CORBA::string_dup("object");
+          //SCRUTE(context_name[0].id);
  
-         _current_context->unbind(context_name);
-         MESSAGE("The object " << context_name[0].id << " has been deleted");
-       }
+          _current_context->unbind(context_name);
+          //MESSAGE("The object " << context_name[0].id << " has been deleted");
+        }
 
       catch (CosNaming::NamingContext::NotFound& ex)
-       {
-         CosNaming::Name n = ex.rest_of_name;
-
-         if (ex.why == CosNaming::NamingContext::missing_node)
-           INFOS( "Destroy_Name() : " << (char *) n[0].id
-                  << " (" << (char *) n[0].kind << ") not found" );
-         if (ex.why == CosNaming::NamingContext::not_context)
-           INFOS( "Destroy_Name() : " << (char *) n[0].id
-                  << " (" << (char *) n[0].kind
-                  << ") is not a context" );
+        {
+          CosNaming::Name n = ex.rest_of_name;
+
+          if (ex.why == CosNaming::NamingContext::missing_node)
+            INFOS( "Destroy_Name() : " << (char *) n[0].id
+                   << " (" << (char *) n[0].kind << ") not found" );
+          if (ex.why == CosNaming::NamingContext::not_context)
+            INFOS( "Destroy_Name() : " << (char *) n[0].id
+                   << " (" << (char *) n[0].kind
+                   << ") is not a context" );
           if (ex.why == CosNaming::NamingContext::not_object)
             INFOS( "Destroy_Name() : " << (char *) n[0].id
                    << " (" << (char *) n[0].kind
@@ -1263,21 +1213,21 @@ throw(ServiceUnreachable)
           }
 
       catch (CosNaming::NamingContext::CannotProceed&)
-       {
-         INFOS( "Destroy_Name(): CosNaming::NamingContext::CannotProceed");
-       }
+        {
+          INFOS( "Destroy_Name(): CosNaming::NamingContext::CannotProceed");
+        }
 
       catch (CosNaming::NamingContext::InvalidName&)
-       {
-         INFOS( "Destroy_Name(): CosNaming::NamingContext::InvalidName");
-       }
+        {
+          INFOS( "Destroy_Name(): CosNaming::NamingContext::InvalidName");
+        }
 
       catch (CORBA::SystemException&)
-       {
-         INFOS( "Destroy_Name(): CORBA::SystemException: unable to contact"
-                << " the naming service");
-         throw ServiceUnreachable();
-       }
+        {
+          INFOS( "Destroy_Name(): CORBA::SystemException: unable to contact"
+                 << " the naming service");
+          throw ServiceUnreachable();
+        }
     }
 }
 
@@ -1290,14 +1240,11 @@ throw(ServiceUnreachable)
  */ 
 // ============================================================================
 
-void SALOME_NamingService::Destroy_Directory(const char* Path)
-throw(ServiceUnreachable)
+void SALOME_NamingService::Destroy_Directory(const char* Path) throw(ServiceUnreachable)
 {
-  MESSAGE("BEGIN OF Destroy_Directory " << Path);
-
   Utils_Locker lock (&_myMutex);
 
-  string path(Path);
+  std::string path(Path);
 
   // --- if path empty, nothing to do
 
@@ -1319,11 +1266,11 @@ throw(ServiceUnreachable)
   // --- context of the directory
 
   CosNaming::Name context_name;
-  vector<string> splitPath;
+  std::vector<std::string> splitPath;
   int dimension_resultat = _createContextNameDir(path.c_str(),
-                                                context_name,
-                                                splitPath,
-                                                true);
+                                                 context_name,
+                                                 splitPath,
+                                                 true);
   bool exist = false;
 
   if (dimension_resultat > 0)
@@ -1335,7 +1282,7 @@ throw(ServiceUnreachable)
         {
           CORBA::Object_var obj = _current_context->resolve(context_name);
           _current_context = CosNaming::NamingContext::_narrow(obj);
-         exist = true;
+          exist = true;
         }
 
       catch (CosNaming::NamingContext::NotFound &ex)
@@ -1348,14 +1295,14 @@ throw(ServiceUnreachable)
           if (ex.why == CosNaming::NamingContext::missing_node)
             INFOS( "Destroy_Directory(): " << (char *) n[0].id
                    << " (" << (char *) n[0].kind << ") not found" );
-         if (ex.why == CosNaming::NamingContext::not_context)
-           INFOS( "Destroy_Directory() : " << (char *) n[0].id
-                  << " (" << (char *) n[0].kind
-                  << ") is not a context" );
-         if (ex.why == CosNaming::NamingContext::not_object)
-           INFOS( "Destroy_Directory() : " << (char *) n[0].id
-                  << " (" << (char *) n[0].kind
-                  << ") is not an object" );
+          if (ex.why == CosNaming::NamingContext::not_context)
+            INFOS( "Destroy_Directory() : " << (char *) n[0].id
+                   << " (" << (char *) n[0].kind
+                   << ") is not a context" );
+          if (ex.why == CosNaming::NamingContext::not_object)
+            INFOS( "Destroy_Directory() : " << (char *) n[0].id
+                   << " (" << (char *) n[0].kind
+                   << ") is not an object" );
         }
 
       catch (CosNaming::NamingContext::InvalidName &)
@@ -1386,7 +1333,6 @@ throw(ServiceUnreachable)
   try
     {
       _current_context->destroy();
-      MESSAGE( "The context " << path << " has been deleted" );
       isContextDestroyed = true;
     }
 
@@ -1412,46 +1358,43 @@ throw(ServiceUnreachable)
   if (isContextDestroyed)
     {
       try
-       {
-         _current_context->unbind(context_name);
-         MESSAGE( "The bind to the context "
-                  << context_name[0].id
-                  << " has been deleted" );
-       }
+        {
+          _current_context->unbind(context_name);
+        }
 
       catch (CosNaming::NamingContext::NotFound& ex)
-       {
-         CosNaming::Name n = ex.rest_of_name;
-
-         if (ex.why == CosNaming::NamingContext::missing_node)
-           INFOS( "Destroy_Directory() : " << (char *) n[0].id
-                  << " (" << (char *) n[0].kind << ") not found" );
-         if (ex.why == CosNaming::NamingContext::not_context)
-           INFOS( "Destroy_Directory() : " << (char *) n[0].id
-                  << " (" << (char *) n[0].kind
-                  << ") is not a context" );
-         if (ex.why == CosNaming::NamingContext::not_object)
-           INFOS( "Destroy_Directory() : " << (char *) n[0].id
-                  << " (" << (char *) n[0].kind
-                  << ") is not an object" );
-       }
+        {
+          CosNaming::Name n = ex.rest_of_name;
+
+          if (ex.why == CosNaming::NamingContext::missing_node)
+            INFOS( "Destroy_Directory() : " << (char *) n[0].id
+                   << " (" << (char *) n[0].kind << ") not found" );
+          if (ex.why == CosNaming::NamingContext::not_context)
+            INFOS( "Destroy_Directory() : " << (char *) n[0].id
+                   << " (" << (char *) n[0].kind
+                   << ") is not a context" );
+          if (ex.why == CosNaming::NamingContext::not_object)
+            INFOS( "Destroy_Directory() : " << (char *) n[0].id
+                   << " (" << (char *) n[0].kind
+                   << ") is not an object" );
+        }
 
       catch (CosNaming::NamingContext::CannotProceed&)
-       {
-         INFOS("Destroy_Directory: CosNaming::NamingContext::CannotProceed");
-       }
+        {
+          INFOS("Destroy_Directory: CosNaming::NamingContext::CannotProceed");
+        }
 
       catch (CosNaming::NamingContext::InvalidName&)
-       {
-         INFOS("Destroy_Directory: CosNaming::NamingContext::InvalidName");
-           }
+        {
+          INFOS("Destroy_Directory: CosNaming::NamingContext::InvalidName");
+            }
 
       catch (CORBA::SystemException&)
-       {
-         INFOS("Destroy_Directory:CORBA::SystemException : unable to contact"
-                << " the naming service");
-         throw ServiceUnreachable();
-       }
+        {
+          INFOS("Destroy_Directory:CORBA::SystemException : unable to contact"
+                 << " the naming service");
+          throw ServiceUnreachable();
+        }
     }
 }
 
@@ -1465,16 +1408,15 @@ throw(ServiceUnreachable)
  */ 
 // ============================================================================
 
-void SALOME_NamingService::Destroy_FullDirectory(const char* Path)
-throw(ServiceUnreachable)
+void SALOME_NamingService::Destroy_FullDirectory(const char* Path) throw(ServiceUnreachable)
 {
-  MESSAGE("begin of Destroy_FullDirectory " << Path);
+  //no need to lock here because method calls are threadsafe.
   if( Change_Directory(Path) )
     {
-      vector<string> contList = list_directory();
+      std::vector<std::string> contList = list_directory();
 
       for (unsigned int ind = 0; ind < contList.size(); ind++)
-       Destroy_Name(contList[ind].c_str());
+        Destroy_Name(contList[ind].c_str());
       
       Destroy_Directory(Path);
     }
@@ -1490,8 +1432,7 @@ throw(ServiceUnreachable)
 
 void SALOME_NamingService::_initialize_root_context()
 {
-  //MESSAGE("Get the root context");
-
+  //no lock here because initialization is expected to be done once.
   try
     {
       CORBA::Object_var obj = _orb->resolve_initial_references("NameService");
@@ -1523,7 +1464,7 @@ void SALOME_NamingService::_initialize_root_context()
  *  \param context_name CosNaming structure to put the path.
  *  \param splitPath    a vector of string with subdirectories and final
  *                      object, if any.
- *  \param onlyDir      if true, final object (if any) is ommited
+ *  \param onlyDir      if true, final object (if any) is omitted
  *                      in context_name.
  *                      if false, final object (if any) is included in
  *                      context_name.
@@ -1532,30 +1473,30 @@ void SALOME_NamingService::_initialize_root_context()
 // ============================================================================
 
 int
-SALOME_NamingService::_createContextNameDir(string path,
-                                           CosNaming::Name& context_name,
-                                           vector<string>& splitPath,
-                                           bool onlyDir)
+SALOME_NamingService::_createContextNameDir(std::string path,
+                                            CosNaming::Name& context_name,
+                                            std::vector<std::string>& splitPath,
+                                            bool onlyDir)
 {
   if (path.empty())
     return 0;
 
-  string::size_type begIdx, endIdx;
-  const string delims("/");
+  std::string::size_type begIdx, endIdx;
+  const std::string delims("/");
   splitPath.resize(0);
   bool endWithDelim = false;
 
   begIdx = path.find_first_not_of(delims);
-  while (begIdx != string::npos)
+  while (begIdx != std::string::npos)
     {
       endIdx = path.find_first_of(delims, begIdx);
       if (endIdx == path.length()-1)
-       endWithDelim = true;
-      if (endIdx == string::npos)
-       endIdx = path.length();
+        endWithDelim = true;
+      if (endIdx == std::string::npos)
+        endIdx = path.length();
       int lsub = endIdx - begIdx;
       if (lsub >= 1)
-       splitPath.push_back(path.substr(begIdx, lsub));
+        splitPath.push_back(path.substr(begIdx, lsub));
       begIdx = path.find_first_not_of(delims, endIdx);
     }
 
@@ -1564,7 +1505,7 @@ SALOME_NamingService::_createContextNameDir(string path,
     {
       dim = splitPath.size()-1; // omit final object
       if (endWithDelim)         // unless the path ends with a delimiter 
-       dim++;
+        dim++;
       endWithDelim = true;
     }
   else
@@ -1573,18 +1514,18 @@ SALOME_NamingService::_createContextNameDir(string path,
   context_name.length(dim);
   for (int i=0; i<dim; i++)
     {
-      SCRUTE(splitPath[i]);
+//       SCRUTE(splitPath[i]);
       context_name[i].id = CORBA::string_dup(splitPath[i].c_str());
       if (!endWithDelim && (i == dim-1)) // here, the last string is an object
-       {
-         context_name[i].kind = CORBA::string_dup("object");
-         MESSAGE("--- " <<splitPath[i] <<".object");
-       }
+        {
+          context_name[i].kind = CORBA::string_dup("object");
+//        MESSAGE("--- " <<splitPath[i] <<".object");
+        }
       else
-       {
-         context_name[i].kind = CORBA::string_dup("dir");
-         MESSAGE("--- " <<splitPath[i] <<".dir");
-       }
+        {
+          context_name[i].kind = CORBA::string_dup("dir");
+//        MESSAGE("--- " <<splitPath[i] <<".dir");
+        }
     }
   return dim;
 }
@@ -1593,20 +1534,18 @@ SALOME_NamingService::_createContextNameDir(string path,
 /*! \brief search a name in current directory.
  *
  *  Search a name in the current directory. after call, the current directory
- *  is changed to the directory containing the last occurence of name found.
- *  If no occurence found (see return value), current directory remains
+ *  is changed to the directory containing the last occurrence of name found.
+ *  If no occurrence found (see return value), current directory remains
  *  unchanged. The call is recursive.
  *
  * \param  name the name to search.
- * \param  occurence_number number of occurence already found (incremented)
+ * \param  occurence_number number of occurrence already found (incremented)
  */ 
 // ============================================================================
 
 void SALOME_NamingService::_Find(const char* name,
                                  CORBA::Long& occurence_number)
 {
-  MESSAGE("BEGIN OF _Find "<<  occurence_number << " " << name);
-
   CosNaming::BindingList_var binding_list;
   CosNaming::BindingIterator_var binding_iterator;
   CosNaming::Binding_var binding;
@@ -1622,42 +1561,42 @@ void SALOME_NamingService::_Find(const char* name,
   if (! CORBA::is_nil(binding_iterator))
     {
       while (binding_iterator->next_one(binding))
-       {
-         CosNaming::Name bindingName = binding->binding_name;
-         
-         if (binding->binding_type == CosNaming::ncontext)
-           {
-             // --- We work on a directory,
-             //     the search should be done in this directory
-             
-             Change_Directory(bindingName[0].id);
-             _Find(name, occurence_number);
-             
-             // --- We'll go back to the initial context
-             
-             _current_context = ref_context ;
-           }
-         
-         else if (binding->binding_type == CosNaming::nobject)
-           {
-             // --- We work on an object...
-             
-             if (!strcmp( bindingName[0].id, name))
-               {
-                 //MESSAGE("One occurence was found");
-                 occurence_number++;
-                 
-                 // --- We keep in memory the directory where
-                 //     one occurence was found
-                 
-                 found_context = _current_context ;
-               }
-           }
-       }
+        {
+          CosNaming::Name bindingName = binding->binding_name;
+          
+          if (binding->binding_type == CosNaming::ncontext)
+            {
+              // --- We work on a directory,
+              //     the search should be done in this directory
+              
+              Change_Directory(bindingName[0].id);
+              _Find(name, occurence_number);
+              
+              // --- We'll go back to the initial context
+              
+              _current_context = ref_context ;
+            }
+          
+          else if (binding->binding_type == CosNaming::nobject)
+            {
+              // --- We work on an object...
+              
+              if (!strcmp( bindingName[0].id, name))
+                {
+                  //MESSAGE("One occurrence was found");
+                  occurence_number++;
+                  
+                  // --- We keep in memory the directory where
+                  //     one occurrence was found
+                  
+                  found_context = _current_context ;
+                }
+            }
+        }
       
       binding_iterator->destroy();
     }
-  // --- We go to the last directory where an occurence was found
+  // --- We go to the last directory where an occurrence was found
 
   _current_context = found_context;
 
@@ -1672,19 +1611,17 @@ void SALOME_NamingService::_Find(const char* name,
  * \param splitPath 
  * \param lengthResult
  * \param contextToFind
- * \param _notFound
+ * \param notFound
  */ 
 // ============================================================================
 
 void
 SALOME_NamingService::
-_current_directory(vector<string>& splitPath,
-                  int& lengthResult,
-                  CosNaming::NamingContext_var contextToFind,
-                  bool& notFound)
+_current_directory(std::vector<std::string>& splitPath,
+                   int& lengthResult,
+                   CosNaming::NamingContext_var contextToFind,
+                   bool& notFound)
 {
-  MESSAGE("BEGIN OF _current_Directory");
-
   CosNaming::BindingList_var binding_list;
   CosNaming::BindingIterator_var binding_iterator;
   CosNaming::Binding_var binding;
@@ -1707,7 +1644,8 @@ _current_directory(vector<string>& splitPath,
             {
               // --- directory, search in it
 
-             splitPath.push_back(CORBA::string_dup(bindingName[0].id));
+              const char* bindingNameid=bindingName[0].id;
+              splitPath.push_back(bindingNameid);
               lengthResult++;
 
               CORBA::Object_var obj = _current_context->resolve(bindingName);
@@ -1715,19 +1653,19 @@ _current_directory(vector<string>& splitPath,
 
               if (temp_context->_is_equivalent(contextToFind))
                 {
-                  MESSAGE("The context is found, we stop the search");
+                  //MESSAGE("The context is found, we stop the search");
                   notFound = false;
-                  SCRUTE(notFound);
+                  //SCRUTE(notFound);
                 }
 
               if (notFound)
                 {
-                  SCRUTE(bindingName[0].id);
+                  //SCRUTE(bindingName[0].id);
                   Change_Directory(bindingName[0].id);
                   _current_directory(splitPath,
-                                    lengthResult,
+                                     lengthResult,
                                      contextToFind,
-                                    notFound);
+                                     notFound);
 
                   if (notFound)
                     {
@@ -1735,9 +1673,9 @@ _current_directory(vector<string>& splitPath,
 
                       _current_context = ref_context;
 
-                      MESSAGE("Just before the delete of "
-                             << splitPath[lengthResult-1]);
-                     splitPath.pop_back();
+                      // MESSAGE("Just before the delete of "
+                      //         << splitPath[lengthResult-1]);
+                      splitPath.pop_back();
                       lengthResult--;
                     }
                 }
@@ -1747,7 +1685,7 @@ _current_directory(vector<string>& splitPath,
       binding_iterator->destroy();
     }
 
-  // --- return to the last directory where an occurence was found
+  // --- return to the last directory where an occurrence was found
 
   _current_context = ref_context ;
 }
@@ -1759,20 +1697,18 @@ _current_directory(vector<string>& splitPath,
  *  get a list of all the objects in the current directory, with recursion
  *  on the subdirectories. Only the objects are listed, not the directories.
  *  If the NamingService is out, the exception ServiceUnreachable is thrown.
- * \param myList the list of objects
- * \
-Function :_list_directory_recurs.
- * Purpose  : method to list recursively all the objects contained in the tree of absCurDirectory/relativeSubDir.
- *  \param myList The list that will be filled.
- *  \param relativeSubDir The directory from absCurDirectory in which the objects are found.
- *  \param absCurDirectory The directory in ABSOLUTE form.
  *  _current_context must refer to absCurDirectory.
+ *
+ *  \param myList          The list that will be filled.
+ *  \param relativeSubDir  The directory relative to absCurDirectory in which
+ *                         the objects are found.
+ *  \param absCurDirectory The current directory, absolute path
  */ 
 // ============================================================================
 
-void SALOME_NamingService::_list_directory_recurs(vector<string>& myList,
-                                                 string relativeSubDir,
-                                                 string absCurDirectory)
+void SALOME_NamingService::_list_directory_recurs(std::vector<std::string>& myList,
+                                                  std::string relativeSubDir,
+                                                  std::string absCurDirectory)
 {
   CosNaming::BindingList_var binding_list;
   CosNaming::BindingIterator_var binding_iterator;
@@ -1781,7 +1717,7 @@ void SALOME_NamingService::_list_directory_recurs(vector<string>& myList,
   unsigned long nb = 0 ; // --- only for thethe use of BindingIterator
                          //     to access the bindings
 
-  string absDir;
+  std::string absDir;
 
   CosNaming::NamingContext_var ref_context = _current_context;
 
@@ -1800,23 +1736,23 @@ void SALOME_NamingService::_list_directory_recurs(vector<string>& myList,
   if (! CORBA::is_nil(binding_iterator))
     {
       while (binding_iterator->next_one(binding))
-       {
-         CosNaming::Name bindingName = binding->binding_name;
-
-         if (binding->binding_type == CosNaming::ncontext)
-           {
-             string relativeSdir(bindingName[0].id);
-             _list_directory_recurs(myList, relativeSdir, absDir);
-           }
-
-         else if (binding->binding_type == CosNaming::nobject)
-           {
-             string objName(bindingName[0].id);
-             string elt = absDir + "/" + objName;
-             SCRUTE(elt);
-             myList.push_back(elt);
-           }
-       }
+        {
+          CosNaming::Name bindingName = binding->binding_name;
+
+          if (binding->binding_type == CosNaming::ncontext)
+            {
+              std::string relativeSdir(bindingName[0].id);
+              _list_directory_recurs(myList, relativeSdir, absDir);
+            }
+
+          else if (binding->binding_type == CosNaming::nobject)
+            {
+              std::string objName(bindingName[0].id);
+              std::string elt = absDir + "/" + objName;
+              SCRUTE(elt);
+              myList.push_back(elt);
+            }
+        }
 
       binding_iterator->destroy();
     }
@@ -1838,3 +1774,12 @@ char * SALOME_NamingService::getIORaddr()
   return _orb->object_to_string(_root_context);
 }
 
+/*! \brief get the orb used by the naming service
+ *
+ *  \return the orb
+ */
+CORBA::ORB_ptr SALOME_NamingService::orb()
+{
+  return _orb;
+}
+