Salome HOME
bos #26457 Factorization of ORB initialization
[modules/kernel.git] / src / NamingService / SALOME_NamingService.cxx
index 348bf746ebf1e5c3e9da17e346dbf90ed3589ac8..b8daccf6c45d41223ca5f5870ac9f1a7b885f311 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2020  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
@@ -28,6 +28,7 @@
 //
 #include "SALOME_NamingService.hxx"
 #include "ServiceUnreachable.hxx"
+#include "OpUtil.hxx"
 
 #include "utilities.h"
 
@@ -73,6 +74,11 @@ SALOME_NamingService::SALOME_NamingService(CORBA::ORB_ptr orb)
   _initialize_root_context();
 }
 
+SALOME_NamingService_Abstract *SALOME_NamingService::clone()
+{
+  return new SALOME_NamingService(_orb);
+}
+
 // ============================================================================
 /*! \brief Standard destructor.
  *
@@ -87,6 +93,11 @@ 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.
  *
@@ -103,10 +114,7 @@ void SALOME_NamingService::init_orb(CORBA::ORB_ptr 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
-    }
+    _orb = KERNEL::GetRefToORB(); // Here we make the assumption that the orb has already been initialized
 
   _initialize_root_context();
 }
@@ -134,7 +142,7 @@ void SALOME_NamingService::init_orb(CORBA::ORB_ptr orb)
 
 void SALOME_NamingService::Register(CORBA::Object_ptr ObjRef,
                                     const char* Path)
-  throw(ServiceUnreachable)
+  
 {
   Utils_Locker lock (&_myMutex);
 
@@ -256,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{
@@ -329,7 +337,7 @@ void SALOME_NamingService::Register(CORBA::Object_ptr ObjRef,
 // ============================================================================
 
 CORBA::Object_ptr SALOME_NamingService::Resolve(const char* Path)
-  throw(ServiceUnreachable)
+  
 {
   Utils_Locker lock (&_myMutex);
 
@@ -413,7 +421,7 @@ CORBA::Object_ptr SALOME_NamingService::Resolve(const char* Path)
 // ============================================================================
 
 CORBA::Object_ptr SALOME_NamingService::ResolveFirst(const char* Path)
-  throw(ServiceUnreachable)
+  
 {
   Utils_Locker lock (&_myMutex);
 
@@ -481,7 +489,7 @@ SALOME_NamingService::ResolveComponent(const char* hostname,
                                        const char* containerName,
                                        const char* componentName,
                                        const int nbproc)
-  throw(ServiceUnreachable)
+  
 {
   Utils_Locker lock (&_myMutex);
 
@@ -525,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
@@ -548,111 +556,6 @@ 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,containerNameCpp(containerName);
-
-  if (containerNameCpp.empty())
-    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 )
-    {
-          std::ostringstream suffix;
-          suffix << "_" << nbproc;
-      ret += suffix.str();
-    }
-
-  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
-                        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 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.
  *
@@ -668,7 +571,7 @@ std::string SALOME_NamingService::BuildContainerNameForNS(const Engines::Contain
 // ============================================================================
 
 int SALOME_NamingService::Find(const char* name)
-throw(ServiceUnreachable)
+
 {
   Utils_Locker lock (&_myMutex);
 
@@ -710,7 +613,7 @@ throw(ServiceUnreachable)
  */
 // ============================================================================
 
-bool SALOME_NamingService::Create_Directory(const char* Path) throw(ServiceUnreachable)
+bool SALOME_NamingService::Create_Directory(const char* Path) 
 {
   Utils_Locker lock (&_myMutex);
 
@@ -751,7 +654,7 @@ bool SALOME_NamingService::Create_Directory(const char* Path) throw(ServiceUnrea
  */
 // ============================================================================
 
-bool SALOME_NamingService::Change_Directory(const char* Path) throw(ServiceUnreachable)
+bool SALOME_NamingService::Change_Directory(const char* Path) 
 {
   Utils_Locker lock (&_myMutex);
 
@@ -849,7 +752,7 @@ bool SALOME_NamingService::Change_Directory(const char* Path) throw(ServiceUnrea
  */
 // ============================================================================
 
-char *SALOME_NamingService::Current_Directory() throw(ServiceUnreachable)
+char *SALOME_NamingService::Current_Directory() 
 {
   Utils_Locker lock (&_myMutex);
 
@@ -877,7 +780,7 @@ char *SALOME_NamingService::Current_Directory() 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 += "/";
@@ -899,7 +802,7 @@ char *SALOME_NamingService::Current_Directory() throw(ServiceUnreachable)
  */
 // ============================================================================
 
-void SALOME_NamingService::list() throw(ServiceUnreachable)
+void SALOME_NamingService::list() 
 {
   Utils_Locker lock (&_myMutex)
 
@@ -959,7 +862,7 @@ void SALOME_NamingService::list() throw(ServiceUnreachable)
  */
 // ============================================================================
 
-std::vector<std::string> SALOME_NamingService::list_directory() throw(ServiceUnreachable)
+std::vector<std::string> SALOME_NamingService::list_directory() 
 {
   Utils_Locker lock (&_myMutex);
   std::vector<std::string> dirList ;
@@ -1012,7 +915,7 @@ std::vector<std::string> SALOME_NamingService::list_directory() throw(ServiceUnr
  */
 // ============================================================================
 
-std::vector<std::string> SALOME_NamingService::list_subdirs() throw(ServiceUnreachable)
+std::vector<std::string> SALOME_NamingService::list_subdirs() 
 {
   Utils_Locker lock (&_myMutex);
   std::vector<std::string> dirList ;
@@ -1062,7 +965,7 @@ std::vector<std::string> SALOME_NamingService::list_subdirs() throw(ServiceUnrea
 // ============================================================================
 
 std::vector<std::string> SALOME_NamingService::list_directory_recurs()
-throw(ServiceUnreachable)
+
 {
   Utils_Locker lock (&_myMutex);
 
@@ -1087,7 +990,7 @@ throw(ServiceUnreachable)
 // ============================================================================
 
 void SALOME_NamingService::Destroy_Name(const char* Path)
-throw(ServiceUnreachable)
+
 {
   Utils_Locker lock (&_myMutex);
 
@@ -1176,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
@@ -1240,7 +1143,7 @@ throw(ServiceUnreachable)
  */
 // ============================================================================
 
-void SALOME_NamingService::Destroy_Directory(const char* Path) throw(ServiceUnreachable)
+void SALOME_NamingService::Destroy_Directory(const char* Path) 
 {
   Utils_Locker lock (&_myMutex);
 
@@ -1408,7 +1311,7 @@ void SALOME_NamingService::Destroy_Directory(const char* Path) throw(ServiceUnre
  */
 // ============================================================================
 
-void SALOME_NamingService::Destroy_FullDirectory(const char* Path) throw(ServiceUnreachable)
+void SALOME_NamingService::Destroy_FullDirectory(const char* Path) 
 {
   //no need to lock here because method calls are threadsafe.
   if( Change_Directory(Path) )
@@ -1494,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);
@@ -1503,15 +1406,15 @@ SALOME_NamingService::_createContextNameDir(std::string path,
   int dim;
   if (onlyDir)                  // only directory part
     {
-      dim = splitPath.size()-1; // omit final object
+      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]);
@@ -1527,7 +1430,7 @@ SALOME_NamingService::_createContextNameDir(std::string path,
 //        MESSAGE("--- " <<splitPath[i] <<".dir");
         }
     }
-  return dim;
+  return dim; //TODO: return <int> or <size_t>?
 }
 
 // ============================================================================