Salome HOME
bos #26457 Factorization of ORB initialization
[modules/kernel.git] / src / NamingService / SALOME_NamingService.cxx
index 03ce58b31de1be81ddf1de77264b367ea4a78b02..b8daccf6c45d41223ca5f5870ac9f1a7b885f311 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2021  CEA/DEN, EDF R&D, OPEN CASCADE
 //
 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
@@ -6,7 +6,7 @@
 // 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.
+// version 2.1 of the License, or (at your option) any later version.
 //
 // This library is distributed in the hope that it will be useful,
 // but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -28,6 +28,7 @@
 //
 #include "SALOME_NamingService.hxx"
 #include "ServiceUnreachable.hxx"
+#include "OpUtil.hxx"
 
 #include "utilities.h"
 
@@ -36,7 +37,7 @@
 #include <string>
 #include <cstdio>
 
-#ifdef WNT
+#ifdef WIN32
 #define strdup _strdup
 #endif
 
  *
  *  After Default Constructor, one needs to initialize ORB.
  *  \sa init_orb(CORBA::ORB_ptr orb), SALOME_NamingService(CORBA::ORB_ptr orb)
- */ 
+ */
 // ============================================================================
 
 SALOME_NamingService::SALOME_NamingService()
 {
-  MESSAGE("SALOME_NamingService default constructor");
   _orb = CORBA::ORB::_nil();
   _root_context = CosNaming::NamingContext::_nil();
 }
 
 // ============================================================================
-/*! \brief Standard Constructor, with ORB reference. 
- * 
+/*! \brief Standard Constructor, with ORB reference.
+ *
  * Initializes the naming service root context
  * \param orb CORBA::ORB_ptr arguments
- */ 
+ */
 // ============================================================================
 
 SALOME_NamingService::SALOME_NamingService(CORBA::ORB_ptr orb)
 {
-  MESSAGE("SALOME_NamingService creation");
   _orb = CORBA::ORB::_duplicate(orb);
   _initialize_root_context();
 }
 
+SALOME_NamingService_Abstract *SALOME_NamingService::clone()
+{
+  return new SALOME_NamingService(_orb);
+}
+
 // ============================================================================
 /*! \brief Standard destructor.
  *
  *  The standard destructor does nothing special.
- */ 
+ */
 // ============================================================================
 
 SALOME_NamingService::~SALOME_NamingService()
@@ -89,28 +93,28 @@ SALOME_NamingService::~SALOME_NamingService()
   //MESSAGE("SALOME_NamingService destruction");
 }
 
+std::vector< std::string > SALOME_NamingService::repr()
+{
+  return std::vector< std::string >();
+}
+
 // ============================================================================
 /*! \brief initializes ORB reference and naming service root context.
- * 
+ *
  *  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);
   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
-    }
+    _orb = KERNEL::GetRefToORB(); // Here we make the assumption that the orb has already been initialized
 
   _initialize_root_context();
 }
@@ -128,24 +132,22 @@ void SALOME_NamingService::init_orb(CORBA::ORB_ptr orb)
  *               as an absolute pathname. Else, pathname is taken as a relative
  *               path, to current context. Prefer absolute pathname, relative
  *               pathname are not safe, when SALOME_NamingService object is
- *               shared or use in multithreaded context. 
+ *               shared or use in multithreaded context.
  *               If the path ends with '/', only a directory is created.
  * \sa           Change_Directory(const char* Path),
  *               Create_Directory(const char* Path)
  *               CORBA::Object_ptr Resolve(const char* Path)
- */ 
+ */
 // ============================================================================
 
 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;
@@ -167,7 +169,7 @@ void SALOME_NamingService::Register(CORBA::Object_ptr ObjRef,
     // 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);
@@ -262,9 +264,9 @@ void SALOME_NamingService::Register(CORBA::Object_ptr ObjRef,
   // --- 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);
+  size_t sizePath = splitPath.size();
+  if (sizePath > (size_t)dimension_resultat){
+    ASSERT(sizePath == (size_t)dimension_resultat+1);
     context_name.length(1);
 
     try{
@@ -319,9 +321,9 @@ void SALOME_NamingService::Register(CORBA::Object_ptr ObjRef,
 
 // ============================================================================
 /*! \brief get the CORBA object reference associated to a name.
- * 
+ *
  *  get the CORBA object reference associated to a complete name with a path.
- *  If the NamingService is out, the exception ServiceUnreachable is thrown 
+ *  If the NamingService is out, the exception ServiceUnreachable is thrown
  * \param Path pathname. If the pathname begins with a '/', pathname is taken
  *             as an absolute pathname. Else, pathname is taken as a relative
  *             path, to current context. Prefer absolute pathname, relative
@@ -331,18 +333,16 @@ void SALOME_NamingService::Register(CORBA::Object_ptr ObjRef,
  *             or nil reference in other cases.
  * \sa         Register(CORBA::Object_ptr ObjRef, const char* Path),
  *             Change_Directory(const char* Path)
- */ 
+ */
 // ============================================================================
 
 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] == '/')
     {
@@ -408,11 +408,11 @@ CORBA::Object_ptr SALOME_NamingService::Resolve(const char* Path)
 }
 
 // ============================================================================
-/*! \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*.
- *  If the NamingService is out, the exception ServiceUnreachable is thrown 
+ *  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)"
  * \return     the object reference if found, or nil reference.
@@ -421,12 +421,9 @@ 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);
 
   std::string thePath = Path;
   std::string basePath = "";
@@ -449,21 +446,19 @@ CORBA::Object_ptr SALOME_NamingService::ResolveFirst(const char* Path)
     isOk =true;
   else
     isOk = Change_Directory(basePath.c_str());
-  
+
   if (isOk)
     {
       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++;
         }
     }
@@ -480,13 +475,13 @@ CORBA::Object_ptr SALOME_NamingService::ResolveFirst(const char* Path)
  *  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 
+                        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.
  * \return the object reference
- */ 
+ */
 // ============================================================================
 
 CORBA::Object_ptr
@@ -494,10 +489,8 @@ SALOME_NamingService::ResolveComponent(const char* hostname,
                                        const char* containerName,
                                        const char* componentName,
                                        const int nbproc)
-  throw(ServiceUnreachable)
+  
 {
-//   MESSAGE("ResolveComponent");
-
   Utils_Locker lock (&_myMutex);
 
   std::string name = "/Containers/";
@@ -540,7 +533,7 @@ SALOME_NamingService::ResolveComponent(const char* hostname,
 
               if ( nbproc >= 1 )
                 {
-                  char *str_nbproc = new char[8];
+                  char *str_nbproc = new char[16];
                   sprintf(str_nbproc, "_%d", nbproc);
                   if( strstr(name.c_str(),str_nbproc) == NULL)
                     continue; // check only containers with _%d in name
@@ -563,135 +556,23 @@ SALOME_NamingService::ResolveComponent(const char* hostname,
     }
 }
 
-// ============================================================================
-/*! \brief provide a default container name if empty.
- *
- *  the given container name is returned unchanged, unless it is empty.
- * \param  containerName
- * \return container name, where empty input is replaced by "FactoryServer",
- *         without the path.
- * \sa BuildContainerNameForNS(const char *containerName, const char *hostname)
- */
-// ============================================================================
-
-std::string SALOME_NamingService::ContainerName(const char *containerName)
-{
-  std::string ret;
-
-  if (strlen(containerName) == 0)
-    ret = "FactoryServer";
-  else
-    ret = containerName;
-
-  return ret;
-}
-
-// ============================================================================
-/*! \brief build a container name, given a ContainerParameters struct.
- *
- *  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::ContainerParameters& params,
- *                             const char *hostname)
- */
-// ============================================================================
-
-std::string 
-SALOME_NamingService::ContainerName(const Engines::ContainerParameters& params)
-{
-  int nbproc;
-
-  if ( !params.isMPI )
-    nbproc = 0;
-  else if ( params.nb_proc <= 0 )
-    nbproc = 1;
-  else
-    nbproc = params.nb_proc;
-
-  std::string ret = ContainerName(params.container_name);
-
-  if ( nbproc >= 1 )
-    {
-      char *suffix = new char[8];
-      sprintf(suffix, "_%d", nbproc);
-      ret += suffix;
-    }
-
-  return ret;
-}
-
-// ============================================================================
-/*! \brief build a string representing a container in Naming Service.
- *
- *  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 containerName name of the container in which the component is
-                        instanciated.
- * \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)
- */
-// ============================================================================
-
-std::string SALOME_NamingService::BuildContainerNameForNS(const char *containerName,
-                                                     const char *hostname)
-{
-  std::string ret = "/Containers/";
-  ret += hostname;
-  ret += "/";
-  ret += ContainerName(containerName);
-
-  return ret;
-}
-
-// ============================================================================
-/*! \brief build a string representing a container in Naming Service.
- *
- *  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)
- */
-// ============================================================================
-
-std::string
-SALOME_NamingService::
-BuildContainerNameForNS(const Engines::ContainerParameters& params,
-                        const char *hostname)
-{
-  std::string ret = "/Containers/";
-  ret += hostname;
-  ret += "/";
-  ret += ContainerName(params);
-
-  return ret;
-}
-
 // ============================================================================
 /*! \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)
- */ 
+ */
 // ============================================================================
 
 int SALOME_NamingService::Find(const char* name)
-throw(ServiceUnreachable)
-{
-  MESSAGE("BEGIN OF Find " << name);
 
+{
   Utils_Locker lock (&_myMutex);
 
   CORBA::Long occurence_number = 0 ;
@@ -714,7 +595,7 @@ throw(ServiceUnreachable)
 // ============================================================================
 /*! \brief Creates a directory (context_name)
  *
- *  Creates a directory (context_name) relative to the current directory 
+ *  Creates a directory (context_name) relative to the current directory
  *  (current context) or relative to the root directory (root context), if
  *  the path given begins with a '/'.
  *  If the NamingService is out, the exception ServiceUnreachable is thrown.
@@ -723,20 +604,17 @@ throw(ServiceUnreachable)
  *               as an absolute pathname. Else, pathname is taken as a relative
  *               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
+ *               shared or use in multithreaded context.
+ *  \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) 
 {
-  MESSAGE("BEGIN OF Create_Directory");
-
   Utils_Locker lock (&_myMutex);
 
   std::string path(Path);
@@ -750,13 +628,12 @@ throw(ServiceUnreachable)
 
   if (path == "/")
     {
-      MESSAGE("Create Directory '/', just change to root_context");
       _current_context = _root_context;
       return true;
     }
 
   // --- path must end with '/'
-  
+
   if (path[path.length()-1] != '/') path += '/';
 
   Register(CORBA::Object::_nil(), path.c_str());
@@ -774,13 +651,11 @@ throw(ServiceUnreachable)
  *  If the NamingService is out, the exception ServiceUnreachable is thrown.
  * \param  Path the new current directory
  * \return true if the change succeeded
- */ 
+ */
 // ============================================================================
 
-bool SALOME_NamingService::Change_Directory(const char* Path)
-throw(ServiceUnreachable)
+bool SALOME_NamingService::Change_Directory(const char* Path) 
 {
-//   MESSAGE("BEGIN OF Change_Directory " << Path);
   Utils_Locker lock (&_myMutex);
 
   std::string path(Path);
@@ -794,7 +669,6 @@ throw(ServiceUnreachable)
 
   if (path == "/")
     {
-//       MESSAGE("Change_Directory is called to go to the root_context");
       _current_context = _root_context;
       return true;
     }
@@ -802,7 +676,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;
@@ -810,7 +684,7 @@ throw(ServiceUnreachable)
   // --- need to resolve directory path
 
   ASSERT(!CORBA::is_nil(current_context));
-  
+
   if (path[path.length()-1] != '/') path += '/';
 //   SCRUTE(path);
   CosNaming::Name context_name;
@@ -819,9 +693,9 @@ throw(ServiceUnreachable)
                                                  context_name,
                                                  splitPath,
                                                  true);
-  
+
   // --- Context creation
-  
+
   try
     {
       CORBA::Object_var obj = current_context->resolve(context_name);
@@ -830,11 +704,11 @@ throw(ServiceUnreachable)
       _current_context = current_context;
       changeOK = true;
     }
-  
+
   catch (CosNaming::NamingContext::NotFound& ex)
     {
       CosNaming::Name n = ex.rest_of_name;
-      
+
       if (ex.why == CosNaming::NamingContext::missing_node)
         MESSAGE( "Change_Directory() : " << (char *) n[0].id
                << " (" << (char *) n[0].kind << ") not found");
@@ -847,17 +721,17 @@ throw(ServiceUnreachable)
                << " (" << (char *) n[0].kind
                << ") is not an object" );
     }
-  
+
   catch (CosNaming::NamingContext::CannotProceed&)
     {
       INFOS("Change_Directory(): CosNaming::NamingContext::CannotProceed");
     }
-  
+
   catch (CosNaming::NamingContext::InvalidName&)
     {
       INFOS("Change_Directory(): CosNaming::NamingContext::InvalidName");
     }
-  
+
   catch (CORBA::SystemException&)
     {
       INFOS("Change_Directory():CORBA::SystemException : unable to contact"
@@ -875,14 +749,11 @@ throw(ServiceUnreachable)
  *  If the NamingService is out, the exception ServiceUnreachable is thrown.
  * \return the path of the current_context
  * \sa  _current_directory
- */ 
+ */
 // ============================================================================
 
-char* SALOME_NamingService::Current_Directory()
-throw(ServiceUnreachable)
+char *SALOME_NamingService::Current_Directory() 
 {
-  MESSAGE("BEGIN OF Current_Directory");
-
   Utils_Locker lock (&_myMutex);
 
   CosNaming::NamingContext_var ref_context = _current_context;
@@ -909,7 +780,7 @@ throw(ServiceUnreachable)
     }
 
   std::string path;
-  lengthPath = splitPath.size();
+  lengthPath = (int)splitPath.size(); //!< TODO: conversion from size_t to int
   for (int k = 0 ; k < lengthPath ;k++)
     {
       path += "/";
@@ -928,14 +799,11 @@ throw(ServiceUnreachable)
  *  List and print via trace all directories and objects in the current
  *  context. Trace must be activated: compile option _DEBUG_
  *  If the NamingService is out, the exception ServiceUnreachable is thrown
- */ 
+ */
 // ============================================================================
 
-void SALOME_NamingService::list()
-throw(ServiceUnreachable)
+void SALOME_NamingService::list() 
 {
-  MESSAGE("Begin of list");
-
   Utils_Locker lock (&_myMutex)
 
     ;
@@ -958,8 +826,6 @@ throw(ServiceUnreachable)
 
           if (binding->binding_type == CosNaming::ncontext)
             {
-              MESSAGE( "Context : " << bindingName[0].id );
-
               try
                 {
                   Change_Directory(bindingName[0].id);
@@ -977,7 +843,7 @@ throw(ServiceUnreachable)
 
           else if (binding->binding_type == CosNaming::nobject)
             {
-              MESSAGE( "Object : " << bindingName[0].id );
+              MESSAGE( "list(): no Object : " << bindingName[0].id );
             }
         }
 
@@ -993,13 +859,12 @@ throw(ServiceUnreachable)
  *  If the NamingService is out, the exception ServiceUnreachable is thrown.
  * \return list of strings with objects found.
  * \sa vector<string> list_directory_recurs()
- */ 
+ */
 // ============================================================================
 
-std::vector<std::string> SALOME_NamingService::list_directory()
-throw(ServiceUnreachable)
+std::vector<std::string> SALOME_NamingService::list_directory() 
 {
-//   MESSAGE("list_directory");
+  Utils_Locker lock (&_myMutex);
   std::vector<std::string> dirList ;
   dirList.resize(0);
 
@@ -1047,13 +912,12 @@ throw(ServiceUnreachable)
  *  If the NamingService is out, the exception ServiceUnreachable is thrown.
  * \return list of strings with directories found.
  * \sa vector<string> list_directory()
- */ 
+ */
 // ============================================================================
 
-std::vector<std::string> SALOME_NamingService::list_subdirs()
-throw(ServiceUnreachable)
+std::vector<std::string> SALOME_NamingService::list_subdirs() 
 {
-  MESSAGE("list_subdirs");
+  Utils_Locker lock (&_myMutex);
   std::vector<std::string> dirList ;
   dirList.resize(0);
 
@@ -1081,8 +945,8 @@ throw(ServiceUnreachable)
         }
     }
 
-  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();
 
@@ -1097,14 +961,12 @@ throw(ServiceUnreachable)
  *  If the NamingService is out, the exception ServiceUnreachable is thrown.
  * \return list of strings with objects found.
  * \sa vector<string> list_directory()
- */ 
+ */
 // ============================================================================
 
 std::vector<std::string> SALOME_NamingService::list_directory_recurs()
-throw(ServiceUnreachable)
-{
-  MESSAGE("list_directory_recurs");
 
+{
   Utils_Locker lock (&_myMutex);
 
   std::vector<std::string> dirList ;
@@ -1122,16 +984,14 @@ throw(ServiceUnreachable)
 /*! \brief destroy an entry in naming service.
  *
  *  Destroy an association Path - Object Reference.
- *  If the NamingService is out, the exception ServiceUnreachable is thrown 
+ *  If the NamingService is out, the exception ServiceUnreachable is thrown
  * \param Path object path
- */ 
+ */
 // ============================================================================
 
 void SALOME_NamingService::Destroy_Name(const char* Path)
-throw(ServiceUnreachable)
-{
-  MESSAGE("BEGIN OF Destroy_Name " << Path);
 
+{
   Utils_Locker lock (&_myMutex);
 
   std::string path(Path);
@@ -1219,10 +1079,10 @@ throw(ServiceUnreachable)
   // --- The current directory is now the directory where the object should
   //     be destroyed
 
-  int sizePath = splitPath.size();
-  if (sizePath > dimension_resultat)
+  size_t sizePath = splitPath.size();
+  if (sizePath > (size_t)dimension_resultat)
     {
-      ASSERT(sizePath == dimension_resultat+1);
+      ASSERT(sizePath == (size_t)dimension_resultat+1);
       context_name.length(1);
 
       try
@@ -1232,10 +1092,10 @@ throw(ServiceUnreachable)
           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);
+          //SCRUTE(context_name[0].id);
+
           _current_context->unbind(context_name);
-          MESSAGE("The object " << context_name[0].id << " has been deleted");
+          //MESSAGE("The object " << context_name[0].id << " has been deleted");
         }
 
       catch (CosNaming::NamingContext::NotFound& ex)
@@ -1280,14 +1140,11 @@ throw(ServiceUnreachable)
  *  Destroy an empty directory in Naming Service.
  *  If the NamingService is out, the exception ServiceUnreachable is thrown.
  * \param Path directory path
- */ 
+ */
 // ============================================================================
 
-void SALOME_NamingService::Destroy_Directory(const char* Path)
-throw(ServiceUnreachable)
+void SALOME_NamingService::Destroy_Directory(const char* Path) 
 {
-  MESSAGE("BEGIN OF Destroy_Directory " << Path);
-
   Utils_Locker lock (&_myMutex);
 
   std::string path(Path);
@@ -1379,7 +1236,6 @@ throw(ServiceUnreachable)
   try
     {
       _current_context->destroy();
-      MESSAGE( "The context " << path << " has been deleted" );
       isContextDestroyed = true;
     }
 
@@ -1407,9 +1263,6 @@ throw(ServiceUnreachable)
       try
         {
           _current_context->unbind(context_name);
-          MESSAGE( "The bind to the context "
-                   << context_name[0].id
-                   << " has been deleted" );
         }
 
       catch (CosNaming::NamingContext::NotFound& ex)
@@ -1452,23 +1305,22 @@ throw(ServiceUnreachable)
 /*! \brief Destroy a directory with its contents.
  *
  *  Destroy the objects associations in a directory, and the directory itself,
- *  if there is no subdirectories. 
+ *  if there is no subdirectories.
  *  If the NamingService is out, the exception ServiceUnreachable is thrown.
  * \param Path the directory path.
- */ 
+ */
 // ============================================================================
 
-void SALOME_NamingService::Destroy_FullDirectory(const char* Path)
-throw(ServiceUnreachable)
+void SALOME_NamingService::Destroy_FullDirectory(const char* Path) 
 {
-  MESSAGE("begin of Destroy_FullDirectory " << Path);
+  //no need to lock here because method calls are threadsafe.
   if( Change_Directory(Path) )
     {
       std::vector<std::string> contList = list_directory();
 
       for (unsigned int ind = 0; ind < contList.size(); ind++)
         Destroy_Name(contList[ind].c_str());
-      
+
       Destroy_Directory(Path);
     }
 }
@@ -1477,14 +1329,13 @@ throw(ServiceUnreachable)
 /*! \brief  initialize root context (root directory)
  *
  * the root context initialisation must be done when the SALOME_NamingService
- * instance is created and before any othe call. See constructors.
- */ 
+ * instance is created and before any other call. See constructors.
+ */
 // ============================================================================
 
 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");
@@ -1516,12 +1367,12 @@ 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.
  *  \return             dimension of context_name
- */ 
+ */
 // ============================================================================
 
 int
@@ -1546,7 +1397,7 @@ SALOME_NamingService::_createContextNameDir(std::string path,
         endWithDelim = true;
       if (endIdx == std::string::npos)
         endIdx = path.length();
-      int lsub = endIdx - begIdx;
+      size_t lsub = endIdx - begIdx;
       if (lsub >= 1)
         splitPath.push_back(path.substr(begIdx, lsub));
       begIdx = path.find_first_not_of(delims, endIdx);
@@ -1555,15 +1406,15 @@ SALOME_NamingService::_createContextNameDir(std::string path,
   int dim;
   if (onlyDir)                  // only directory part
     {
-      dim = splitPath.size()-1; // omit final object
-      if (endWithDelim)         // unless the path ends with a delimiter 
+      dim = (int)splitPath.size()-1; // omit final object
+      if (endWithDelim)         // unless the path ends with a delimiter
         dim++;
       endWithDelim = true;
     }
   else
-    dim = splitPath.size();     // directories and final object
+    dim = (int)splitPath.size();     // directories and final object
 
-  context_name.length(dim);
+  context_name.length((CORBA::ULong)dim);
   for (int i=0; i<dim; i++)
     {
 //       SCRUTE(splitPath[i]);
@@ -1579,27 +1430,25 @@ SALOME_NamingService::_createContextNameDir(std::string path,
 //        MESSAGE("--- " <<splitPath[i] <<".dir");
         }
     }
-  return dim;
+  return dim; //TODO: return <int> or <size_t>?
 }
 
 // ============================================================================
 /*! \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;
@@ -1617,40 +1466,40 @@ void SALOME_NamingService::_Find(const char* name,
       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");
+                  //MESSAGE("One occurrence was found");
                   occurence_number++;
-                  
+
                   // --- We keep in memory the directory where
-                  //     one occurence was found
-                  
+                  //     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;
 
@@ -1659,14 +1508,14 @@ void SALOME_NamingService::_Find(const char* name,
 
 // ============================================================================
 /*! \brief find the current directory path.
- * 
+ *
  *  Parse the naming service tree to find the current context and give the
  *  associated directory path (relative to root context).
- * \param splitPath 
+ * \param splitPath
  * \param lengthResult
  * \param contextToFind
  * \param notFound
- */ 
+ */
 // ============================================================================
 
 void
@@ -1676,8 +1525,6 @@ _current_directory(std::vector<std::string>& splitPath,
                    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;
@@ -1709,14 +1556,14 @@ _current_directory(std::vector<std::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,
@@ -1729,8 +1576,8 @@ _current_directory(std::vector<std::string>& splitPath,
 
                       _current_context = ref_context;
 
-                      MESSAGE("Just before the delete of "
-                              << splitPath[lengthResult-1]);
+                      // MESSAGE("Just before the delete of "
+                      //         << splitPath[lengthResult-1]);
                       splitPath.pop_back();
                       lengthResult--;
                     }
@@ -1741,7 +1588,7 @@ _current_directory(std::vector<std::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,7 +1606,7 @@ _current_directory(std::vector<std::string>& splitPath,
  *  \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(std::vector<std::string>& myList,
@@ -1838,4 +1685,3 @@ CORBA::ORB_ptr SALOME_NamingService::orb()
 {
   return _orb;
 }
-