Salome HOME
merge from branch BR_V511_PR 15 12 2009
[modules/kernel.git] / src / NamingService / SALOME_NamingService.cxx
index 965982293b32d97fd5e03564deb4631bb21248c4..8cf3c9268e9d20157cca622e869e2686b9e3739d 100644 (file)
@@ -1,6 +1,6 @@
-//  SALOME NamingService : wrapping NamingService services
+//  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
 //
-//  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+//  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
 //
 //  This library is free software; you can redistribute it and/or
 //  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
-//
-//
+//  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>
 
 using namespace std;
 
+/*! \class SALOME_NamingService
+    \brief A class to manage the SALOME naming service
+
+*/
+
 // ============================================================================
 /*! \brief Default Constructor without ORB reference.
  *
@@ -63,7 +68,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,6 +91,7 @@ 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
  */ 
 // ============================================================================
@@ -95,7 +101,13 @@ 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();
 }
@@ -339,7 +351,7 @@ CORBA::Object_ptr SALOME_NamingService::Resolve(const char* Path)
 
   CosNaming::Name context_name;
   vector<string> splitPath;
-  int dimension_resultat = _createContextNameDir(Path,
+  _createContextNameDir(Path,
                                                 context_name,
                                                 splitPath,
                                                 false);
@@ -514,7 +526,8 @@ SALOME_NamingService::ResolveComponent(const char* hostname,
   else
     {
       SCRUTE(name);
-      if (Change_Directory(name.c_str()))
+      string basename = name;
+      if (Change_Directory(basename.c_str()))
        {
          vector<string> contList = list_subdirs();
 
@@ -538,6 +551,8 @@ SALOME_NamingService::ResolveComponent(const char* hostname,
 
              if ( !CORBA::is_nil(obj) )
                return obj;
+              else
+                Change_Directory(basename.c_str());
            }
        }
 
@@ -611,6 +626,34 @@ SALOME_NamingService::ContainerName(const Engines::MachineParameters& params)
   return ret;
 }
 
+string 
+SALOME_NamingService::ContainerName(const Engines::ContainerParameters& params)
+{
+  int nbproc;
+
+  if ( !params.isMPI )
+    nbproc = 0;
+  else if ( (params.resource_params.nb_node <= 0) && (params.resource_params.nb_proc_per_node <= 0) )
+    nbproc = 1;
+  else if ( params.resource_params.nb_node == 0 )
+    nbproc = params.resource_params.nb_proc_per_node;
+  else if ( params.resource_params.nb_proc_per_node == 0 )
+    nbproc = params.resource_params.nb_node;
+  else
+    nbproc = params.resource_params.nb_node * params.resource_params.nb_proc_per_node;
+
+  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.
  *
@@ -661,6 +704,19 @@ BuildContainerNameForNS(const Engines::MachineParameters& params,
   return ret;
 }
 
+string
+SALOME_NamingService::
+BuildContainerNameForNS(const Engines::ContainerParameters& params,
+                       const char *hostname)
+{
+  string ret = "/Containers/";
+  ret += hostname;
+  ret += "/";
+  ret += ContainerName(params);
+
+  return ret;
+}
+
 // ============================================================================
 /*! \brief search a name in current directory.
  *
@@ -803,7 +859,7 @@ throw(ServiceUnreachable)
 //   SCRUTE(path);
   CosNaming::Name context_name;
   vector<string> splitPath;
-  int dimension_resultat = _createContextNameDir(path.c_str(),
+  _createContextNameDir(path.c_str(),
                                                 context_name,
                                                 splitPath,
                                                 true);
@@ -1818,3 +1874,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;
+}
+