]> SALOME platform Git repositories - modules/kernel.git/blobdiff - src/NamingService/SALOME_NamingService.cxx
Salome HOME
Typo-fix by Kunda
[modules/kernel.git] / src / NamingService / SALOME_NamingService.cxx
index 638fee21eada1792d5ae1b6c3aa13751a4acc6d9..a8c213b03a47f8604dfeff249cb5f0c0e7d21a8b 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2014  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2016  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
@@ -55,7 +55,6 @@
 
 SALOME_NamingService::SALOME_NamingService()
 {
-  MESSAGE("SALOME_NamingService default constructor");
   _orb = CORBA::ORB::_nil();
   _root_context = CosNaming::NamingContext::_nil();
 }
@@ -70,7 +69,6 @@ SALOME_NamingService::SALOME_NamingService()
 
 SALOME_NamingService::SALOME_NamingService(CORBA::ORB_ptr orb)
 {
-  MESSAGE("SALOME_NamingService creation");
   _orb = CORBA::ORB::_duplicate(orb);
   _initialize_root_context();
 }
@@ -101,8 +99,6 @@ SALOME_NamingService::~SALOME_NamingService()
 
 void SALOME_NamingService::init_orb(CORBA::ORB_ptr orb)
 {
-  MESSAGE("SALOME_NamingService initialisation");
-
   Utils_Locker lock (&_myMutex);
   if(orb)
     _orb = CORBA::ORB::_duplicate(orb);
@@ -140,12 +136,10 @@ 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;
@@ -337,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] == '/')
     {
@@ -408,10 +400,10 @@ 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*.
+ *  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)"
@@ -423,10 +415,7 @@ 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 = "";
@@ -457,8 +446,6 @@ CORBA::Object_ptr SALOME_NamingService::ResolveFirst(const char* Path)
       
       while (its != listElem.end())
         {
-          MESSAGE(*its);
-          
           if ((*its).find(name) == 0)
             {
               return Resolve((*its).c_str());
@@ -480,7 +467,7 @@ 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.
+                        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
@@ -496,8 +483,6 @@ SALOME_NamingService::ResolveComponent(const char* hostname,
                                        const int nbproc)
   throw(ServiceUnreachable)
 {
-//   MESSAGE("ResolveComponent");
-
   Utils_Locker lock (&_myMutex);
 
   std::string name = "/Containers/";
@@ -576,9 +561,9 @@ SALOME_NamingService::ResolveComponent(const char* hostname,
 
 std::string SALOME_NamingService::ContainerName(const char *containerName)
 {
-  std::string ret;
+  std::string ret,containerNameCpp(containerName);
 
-  if (strlen(containerName) == 0)
+  if (containerNameCpp.empty())
     ret = "FactoryServer";
   else
     ret = containerName;
@@ -599,8 +584,7 @@ std::string SALOME_NamingService::ContainerName(const char *containerName)
  */
 // ============================================================================
 
-std::string 
-SALOME_NamingService::ContainerName(const Engines::ContainerParameters& params)
+std::string SALOME_NamingService::ContainerName(const Engines::ContainerParameters& params)
 {
   int nbproc;
 
@@ -611,13 +595,13 @@ SALOME_NamingService::ContainerName(const Engines::ContainerParameters& params)
   else
     nbproc = params.nb_proc;
 
-  std::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;
@@ -630,17 +614,16 @@ SALOME_NamingService::ContainerName(const Engines::ContainerParameters& params)
  *  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.
+                        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)
  */
 // ============================================================================
 
-std::string SALOME_NamingService::BuildContainerNameForNS(const char *containerName,
-                                                     const char *hostname)
+std::string SALOME_NamingService::BuildContainerNameForNS(const char *containerName, const char *hostname)
 {
-  std::string ret = "/Containers/";
+  std::string ret("/Containers/");
   ret += hostname;
   ret += "/";
   ret += ContainerName(containerName);
@@ -660,12 +643,9 @@ std::string SALOME_NamingService::BuildContainerNameForNS(const char *containerN
  */
 // ============================================================================
 
-std::string
-SALOME_NamingService::
-BuildContainerNameForNS(const Engines::ContainerParameters& params,
-                        const char *hostname)
+std::string SALOME_NamingService::BuildContainerNameForNS(const Engines::ContainerParameters& params, const char *hostname)
 {
-  std::string ret = "/Containers/";
+  std::string ret("/Containers/");
   ret += hostname;
   ret += "/";
   ret += ContainerName(params);
@@ -677,12 +657,12 @@ BuildContainerNameForNS(const Engines::ContainerParameters& 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)
  */ 
 // ============================================================================
@@ -690,8 +670,6 @@ BuildContainerNameForNS(const Engines::ContainerParameters& params,
 int SALOME_NamingService::Find(const char* name)
 throw(ServiceUnreachable)
 {
-  MESSAGE("BEGIN OF Find " << name);
-
   Utils_Locker lock (&_myMutex);
 
   CORBA::Long occurence_number = 0 ;
@@ -724,19 +702,16 @@ 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);
 
   std::string path(Path);
@@ -750,7 +725,6 @@ throw(ServiceUnreachable)
 
   if (path == "/")
     {
-      MESSAGE("Create Directory '/', just change to root_context");
       _current_context = _root_context;
       return true;
     }
@@ -777,10 +751,8 @@ 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);
 
   std::string path(Path);
@@ -794,7 +766,6 @@ throw(ServiceUnreachable)
 
   if (path == "/")
     {
-//       MESSAGE("Change_Directory is called to go to the root_context");
       _current_context = _root_context;
       return true;
     }
@@ -802,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;
@@ -878,11 +849,8 @@ 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;
@@ -931,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)
 
     ;
@@ -958,8 +923,6 @@ throw(ServiceUnreachable)
 
           if (binding->binding_type == CosNaming::ncontext)
             {
-              MESSAGE( "Context : " << bindingName[0].id );
-
               try
                 {
                   Change_Directory(bindingName[0].id);
@@ -977,7 +940,7 @@ throw(ServiceUnreachable)
 
           else if (binding->binding_type == CosNaming::nobject)
             {
-              MESSAGE( "Object : " << bindingName[0].id );
+              MESSAGE( "list(): no Object : " << bindingName[0].id );
             }
         }
 
@@ -996,10 +959,9 @@ throw(ServiceUnreachable)
  */ 
 // ============================================================================
 
-std::vector<std::string> SALOME_NamingService::list_directory()
-throw(ServiceUnreachable)
+std::vector<std::string> SALOME_NamingService::list_directory() throw(ServiceUnreachable)
 {
-//   MESSAGE("list_directory");
+  Utils_Locker lock (&_myMutex);
   std::vector<std::string> dirList ;
   dirList.resize(0);
 
@@ -1050,10 +1012,9 @@ throw(ServiceUnreachable)
  */ 
 // ============================================================================
 
-std::vector<std::string> SALOME_NamingService::list_subdirs()
-throw(ServiceUnreachable)
+std::vector<std::string> SALOME_NamingService::list_subdirs() throw(ServiceUnreachable)
 {
-  MESSAGE("list_subdirs");
+  Utils_Locker lock (&_myMutex);
   std::vector<std::string> dirList ;
   dirList.resize(0);
 
@@ -1081,8 +1042,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();
 
@@ -1103,8 +1064,6 @@ throw(ServiceUnreachable)
 std::vector<std::string> SALOME_NamingService::list_directory_recurs()
 throw(ServiceUnreachable)
 {
-  MESSAGE("list_directory_recurs");
-
   Utils_Locker lock (&_myMutex);
 
   std::vector<std::string> dirList ;
@@ -1130,8 +1089,6 @@ throw(ServiceUnreachable)
 void SALOME_NamingService::Destroy_Name(const char* Path)
 throw(ServiceUnreachable)
 {
-  MESSAGE("BEGIN OF Destroy_Name " << Path);
-
   Utils_Locker lock (&_myMutex);
 
   std::string path(Path);
@@ -1232,10 +1189,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)
@@ -1283,11 +1240,8 @@ 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);
 
   std::string path(Path);
@@ -1379,7 +1333,6 @@ throw(ServiceUnreachable)
   try
     {
       _current_context->destroy();
-      MESSAGE( "The context " << path << " has been deleted" );
       isContextDestroyed = true;
     }
 
@@ -1407,9 +1360,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)
@@ -1458,10 +1408,9 @@ 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) )
     {
       std::vector<std::string> contList = list_directory();
@@ -1483,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");
@@ -1516,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.
@@ -1586,20 +1534,18 @@ SALOME_NamingService::_createContextNameDir(std::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;
@@ -1637,11 +1583,11 @@ void SALOME_NamingService::_Find(const char* name,
               
               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 ;
                 }
@@ -1650,7 +1596,7 @@ void SALOME_NamingService::_Find(const char* name,
       
       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;
 
@@ -1676,8 +1622,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 +1653,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 +1673,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 +1685,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 ;
 }