]> SALOME platform Git repositories - modules/kernel.git/commitdiff
Salome HOME
Fix a bug causing concurrent access problems to the Resources Manager
authorRenaud Barate <renaud.barate@edf.fr>
Thu, 8 Jan 2015 09:44:06 +0000 (10:44 +0100)
committerRenaud Barate <renaud.barate@edf.fr>
Thu, 8 Jan 2015 09:44:06 +0000 (10:44 +0100)
Since the development of parallel container launch, the container
manager is multi-threaded, but it used directly the resource manager
which is not thread safe. With this fix, all calls from the container
manager to the resource manager are done through CORBA, and since the
resource manager runs in a single-thread POA, thread-safety is ensured.

src/Container/SALOME_ContainerManager.cxx
src/Container/SALOME_ContainerManager.hxx
src/Launcher/SALOME_Launcher.cxx
src/LifeCycleCORBA/SALOME_LifeCycleCORBA.cxx
src/LifeCycleCORBA/TestContainerManager.cxx
src/ResourcesManager/CMakeLists.txt
src/ResourcesManager/SALOME_ResourcesManager.hxx
src/ResourcesManager/SALOME_ResourcesManager_Client.cxx [new file with mode: 0644]
src/ResourcesManager/SALOME_ResourcesManager_Client.hxx [new file with mode: 0644]
src/ResourcesManager/SALOME_ResourcesManager_Common.cxx [new file with mode: 0644]
src/ResourcesManager/SALOME_ResourcesManager_Common.hxx [new file with mode: 0644]

index 8a33c0fec0ff6711f252c1480ebef3ead3b9976e..ee9a30adc2710627815a117ffc8ca6bdc992964a 100644 (file)
@@ -22,6 +22,7 @@
 
 #include "SALOME_ContainerManager.hxx"
 #include "SALOME_NamingService.hxx"
+#include "SALOME_ResourcesManager_Client.hxx"
 #include "SALOME_ModuleCatalog.hh"
 #include "Basics_Utils.hxx"
 #include "Basics_DirUtils.hxx"
@@ -68,11 +69,12 @@ Utils_Mutex SALOME_ContainerManager::_systemMutex;
  */
 //=============================================================================
 
-SALOME_ContainerManager::SALOME_ContainerManager(CORBA::ORB_ptr orb, PortableServer::POA_var poa, SALOME_ResourcesManager *rm, SALOME_NamingService *ns):_nbprocUsed(1)
+SALOME_ContainerManager::SALOME_ContainerManager(CORBA::ORB_ptr orb, PortableServer::POA_var poa, SALOME_NamingService *ns)
+  : _nbprocUsed(1)
 {
   MESSAGE("constructor");
   _NS = ns;
-  _ResManager = rm;
+  _resManager = new SALOME_ResourcesManager_Client(ns);
 
   PortableServer::POAManager_var pman = poa->the_POAManager();
   _orb = CORBA::ORB::_duplicate(orb) ;
@@ -148,6 +150,7 @@ SALOME_ContainerManager::SALOME_ContainerManager(CORBA::ORB_ptr orb, PortableSer
 SALOME_ContainerManager::~SALOME_ContainerManager()
 {
   MESSAGE("destructor");
+  delete _resManager;
 #ifdef HAVE_MPI2
 #ifdef WITHOPENMPI
   if( GetenvThreadSafe("OMPI_URI_FILE") != NULL ){
@@ -299,21 +302,22 @@ Engines::Container_ptr SALOME_ContainerManager::GiveContainer(const Engines::Con
 
   // Step 2: Get all possibleResources from the parameters
   // Consider only resources that can run containers
-  local_params.resource_params.can_run_containers = true;
-  Engines::ResourceList_var possibleResources = _ResManager->GetFittingResources(local_params.resource_params);
-  MESSAGE("[GiveContainer] - length of possible resources " << possibleResources->length());
+  resourceParams resource_params = resourceParameters_CORBAtoCPP(local_params.resource_params);
+  resource_params.can_run_containers = true;
+  std::vector<std::string> possibleResources = _resManager->GetFittingResources(resource_params);
+  MESSAGE("[GiveContainer] - length of possible resources " << possibleResources.size());
   std::vector<std::string> local_resources;
 
   // Step 3: if mode is "get" keep only machines with existing containers 
   if(mode == "get")
   {
-    for(unsigned int i=0; i < possibleResources->length(); i++)
+    for(unsigned int i=0; i < possibleResources.size(); i++)
     {
-      Engines::Container_ptr cont = FindContainer(params, possibleResources[i].in());
+      Engines::Container_ptr cont = FindContainer(params, possibleResources[i]);
       try
       {
         if(!cont->_non_existent())
-          local_resources.push_back(std::string(possibleResources[i]));
+          local_resources.push_back(possibleResources[i]);
       }
       catch(CORBA::Exception&) {}
     }
@@ -326,8 +330,7 @@ Engines::Container_ptr SALOME_ContainerManager::GiveContainer(const Engines::Con
     }
   }
   else
-    for(unsigned int i=0; i < possibleResources->length(); i++)
-      local_resources.push_back(std::string(possibleResources[i]));
+    local_resources = possibleResources;
 
   // Step 4: select the resource where to get/start the container
   bool resource_available = true;
@@ -341,7 +344,7 @@ Engines::Container_ptr SALOME_ContainerManager::GiveContainer(const Engines::Con
     {
       try
       {
-        resource_selected = _ResManager->GetImpl()->Find(params.resource_params.policy.in(), resources);
+        resource_selected = _resManager->Find(params.resource_params.policy.in(), resources);
         // Remove resource_selected from vector
         std::vector<std::string>::iterator it;
         for (it=resources.begin() ; it < resources.end(); it++ )
@@ -359,8 +362,8 @@ Engines::Container_ptr SALOME_ContainerManager::GiveContainer(const Engines::Con
       MESSAGE("[GiveContainer] Resource selected is: " << resource_selected);
 
       // Step 5: Create container name
-      Engines::ResourceDefinition_var resource_definition = _ResManager->GetResourceDefinition(resource_selected.c_str());
-      std::string hostname(resource_definition->hostname.in());
+      ParserResourcesType resource_definition = _resManager->GetResourceDefinition(resource_selected);
+      std::string hostname(resource_definition.HostName);
       std::string containerNameInNS;
       if(params.isMPI){
         int nbproc;
@@ -508,7 +511,7 @@ SALOME_ContainerManager::LaunchContainer(const Engines::ContainerParameters& par
       {
         // Preparing remote command
         std::string command = "";
-        const ParserResourcesType resInfo(_ResManager->GetImpl()->GetResourcesDescr(resource_selected));
+        const ParserResourcesType resInfo(_resManager->GetResourceDefinition(resource_selected));
         command = getCommandToRunRemoteProcess(resInfo.Protocol, resInfo.HostName, resInfo.UserName);
         if (resInfo.AppliPath != "")
           command += resInfo.AppliPath;
@@ -684,8 +687,8 @@ Engines::Container_ptr SALOME_ContainerManager::FindContainer(const Engines::Con
 Engines::Container_ptr
 SALOME_ContainerManager::FindContainer(const Engines::ContainerParameters& params, const std::string& resource)
 {
-  Engines::ResourceDefinition_var resource_definition = _ResManager->GetResourceDefinition(resource.c_str());
-  std::string hostname(resource_definition->hostname.in());
+  ParserResourcesType resource_definition = _resManager->GetResourceDefinition(resource);
+  std::string hostname(resource_definition.HostName);
   std::string containerNameInNS(_NS->BuildContainerNameForNS(params, hostname.c_str()));
   MESSAGE("[FindContainer] Try to find a container  " << containerNameInNS << " on resource " << resource);
   CORBA::Object_var obj = _NS->Resolve(containerNameInNS.c_str());
@@ -755,9 +758,7 @@ SALOME_ContainerManager::BuildCommandToLaunchRemoteContainer(const std::string&
   else
   {
     int nbproc;
-    Engines::ResourceDefinition_var resource_definition = _ResManager->GetResourceDefinition(resource_name.c_str());
-    std::string hostname(resource_definition->hostname.in());
-    const ParserResourcesType resInfo(_ResManager->GetImpl()->GetResourcesDescr(resource_name));
+    const ParserResourcesType resInfo(_resManager->GetResourceDefinition(resource_name));
 
     if (params.isMPI)
     {
@@ -1038,14 +1039,14 @@ std::string SALOME_ContainerManager::BuildTemporaryFileName()
  */ 
 //=============================================================================
 
-std::string SALOME_ContainerManager::BuildTempFileToLaunchRemoteContainer (const std::string& resource_name, const Engines::ContainerParameters& params, std::string& tmpFileName) const throw(SALOME_Exception)
+std::string SALOME_ContainerManager::BuildTempFileToLaunchRemoteContainer (const std::string& resource_name, const Engines::ContainerParameters& params, std::string& tmpFileName) const
 {
   int status;
 
   tmpFileName = BuildTemporaryFileName();
   std::ofstream tempOutputFile;
   tempOutputFile.open(tmpFileName.c_str(), std::ofstream::out );
-  const ParserResourcesType resInfo(_ResManager->GetImpl()->GetResourcesDescr(resource_name));
+  const ParserResourcesType resInfo(_resManager->GetResourceDefinition(resource_name));
   tempOutputFile << "#! /bin/sh" << std::endl;
 
   // --- set env vars
@@ -1175,7 +1176,7 @@ std::string SALOME_ContainerManager::GetMPIZeroNode(const std::string machine, c
     {
       if (_isAppliSalomeDefined)
         {
-          const ParserResourcesType resInfo(_ResManager->GetImpl()->GetResourcesDescr(machine));
+          const ParserResourcesType resInfo(_resManager->GetResourceDefinition(machine));
 
           if (resInfo.Protocol == rsh)
             command = "rsh ";
@@ -1346,17 +1347,18 @@ SALOME_ContainerManager::checkPaCOParameters(Engines::ContainerParameters & para
   }
 
   // Step 2 : check resource_selected
-  Engines::ResourceDefinition_var resource_definition = _ResManager->GetResourceDefinition(resource_selected.c_str());
-  std::string protocol = resource_definition->protocol.in();
-  std::string username = resource_definition->username.in();
-  std::string applipath = resource_definition->applipath.in();
+  const ParserResourcesType resource_definition = _resManager->GetResourceDefinition(resource_selected);
+  //std::string protocol = resource_definition->protocol.in();
+  std::string username = resource_definition.UserName;
+  std::string applipath = resource_definition.AppliPath;
 
-  if (protocol == "" || username == "" || applipath == "")
+  //if (protocol == "" || username == "" || applipath == "")
+  if (username == "" || applipath == "")
   {
     INFOS("[checkPaCOParameters] resource selected is not well defined");
-    INFOS("[checkPaCOParameters] resource name: " << resource_definition->name.in());
-    INFOS("[checkPaCOParameters] resource hostname: " << resource_definition->hostname.in());
-    INFOS("[checkPaCOParameters] resource protocol: " << protocol);
+    INFOS("[checkPaCOParameters] resource name: " << resource_definition.Name);
+    INFOS("[checkPaCOParameters] resource hostname: " << resource_definition.HostName);
+    INFOS("[checkPaCOParameters] resource protocol: " << resource_definition.getAccessProtocolTypeStr());
     INFOS("[checkPaCOParameters] resource username: " << username);
     INFOS("[checkPaCOParameters] resource applipath: " << applipath);
     result = false;
index 3aa4b4a7e04c237e5c2fa8f4b55833b1ede9ec2c..fc55e7579f9e76140a31508b49a593de0da11a05 100644 (file)
@@ -28,8 +28,7 @@
 #include <SALOMEconfig.h>
 #include CORBA_CLIENT_HEADER(SALOME_Component)
 #include CORBA_CLIENT_HEADER(SALOME_ContainerManager)
-#include "SALOME_ResourcesManager.hxx"
-#include "SALOME_LoadRateManager.hxx"
+#include "SALOME_ResourcesCatalog_Parser.hxx"
 
 #include "Utils_Mutex.hxx"
 
 #include <set>
 
 class SALOME_NamingService;
+class SALOME_ResourcesManager_Client;
 
 class CONTAINER_EXPORT SALOME_ContainerManager : public POA_Engines::ContainerManager
 {
 
 public:
-  SALOME_ContainerManager(CORBA::ORB_ptr orb, PortableServer::POA_var poa, SALOME_ResourcesManager *rm, SALOME_NamingService *ns);
+  SALOME_ContainerManager(CORBA::ORB_ptr orb, PortableServer::POA_var poa, SALOME_NamingService *ns);
   ~SALOME_ContainerManager();
 
   // Corba Methods
@@ -75,7 +75,7 @@ protected:
                                                  std::string& tmpFileName) const;
 
   std::string BuildTempFileToLaunchRemoteContainer(const std::string& resource_name,
-                                                   const Engines::ContainerParameters& params, std::string& tmpFileName) const throw(SALOME_Exception);
+                                                   const Engines::ContainerParameters& params, std::string& tmpFileName) const;
 
   static void RmTmpFile(std::string& tmpFile);
 
@@ -105,7 +105,7 @@ protected:
   CORBA::ORB_var _orb;
   PortableServer::POA_var _poa;
 
-  SALOME_ResourcesManager *_ResManager;
+  SALOME_ResourcesManager_Client *_resManager;
   SALOME_NamingService *_NS;
 
   //! different behaviour if $APPLI exists (SALOME Application) 
index 3c16fdf7a026ca21a57ab77c4544de17e4bd0a67..707b2947063a4f74915e74d2d5dfd508a44ea31c 100644 (file)
@@ -24,6 +24,7 @@
 #include "BatchTest.hxx"
 #include "OpUtil.hxx"
 #include "SALOME_ContainerManager.hxx"
+#include "SALOME_ResourcesManager.hxx"
 #include "Utils_CorbaException.hxx"
 
 
@@ -59,7 +60,7 @@ SALOME_Launcher::SALOME_Launcher(CORBA::ORB_ptr orb, PortableServer::POA_var poa
   _NS = new SALOME_NamingService(orb);
   _ResManager = new SALOME_ResourcesManager(orb,poa,_NS);
   _l.SetResourcesManager(_ResManager->GetImpl());
-  _ContManager = new SALOME_ContainerManager(orb,poa,_ResManager,_NS);
+  _ContManager = new SALOME_ContainerManager(orb,poa,_NS);
   _ResManager->_remove_ref();
   _ContManager->_remove_ref();
 
index 41e294e025b75d11480fb38d1b34a7c95477e9bb..5473178da525278f28f4993c0122704ada775414 100644 (file)
@@ -50,6 +50,7 @@
 #include CORBA_CLIENT_HEADER(Logger)
 #include CORBA_CLIENT_HEADER(SALOME_Launcher)
 
+#include "SALOME_ResourcesManager.hxx"
 #include "SALOME_ContainerManager.hxx"
 #include "SALOME_Component_i.hxx"
 #include "SALOME_NamingService.hxx"
index 175ff62eb8d308e32e6ef4d3e95e9f079f7ffb7b..40e2afabe46fac6c288d00313febbd51a37a3da3 100644 (file)
@@ -30,6 +30,7 @@
 #endif
 #include <SALOMEconfig.h>
 #include "SALOME_NamingService.hxx"
+#include "SALOME_ResourcesManager.hxx"
 #include "SALOME_ContainerManager.hxx"
 #include "SALOME_LifeCycleCORBA.hxx"
 #include "NamingService_WaitForServerReadiness.hxx"
index 1bfa3cae66f514ce191d5140dafff87ae29ce3cb..f637a4d8d3a04552f747b1bd993e1896fcf5d020 100755 (executable)
@@ -54,7 +54,12 @@ INSTALL(TARGETS ResourcesManager EXPORT ${PROJECT_NAME}TargetGroup
     DESTINATION ${SALOME_INSTALL_LIBS})
 
 IF(NOT SALOME_LAUNCHER_ONLY)
-  ADD_LIBRARY(SalomeResourcesManager SALOME_ResourcesManager.cxx)
+  SET(SalomeResourcesManager_SOURCES
+    SALOME_ResourcesManager.cxx
+    SALOME_ResourcesManager_Client.cxx
+    SALOME_ResourcesManager_Common.cxx
+  )
+  ADD_LIBRARY(SalomeResourcesManager ${SalomeResourcesManager_SOURCES})
   TARGET_LINK_LIBRARIES(SalomeResourcesManager ResourcesManager ${COMMON_LIBS})
   INSTALL(TARGETS SalomeResourcesManager EXPORT ${PROJECT_NAME}TargetGroup
         DESTINATION ${SALOME_INSTALL_LIBS})
@@ -66,5 +71,7 @@ SET(COMMON_HEADERS_HXX
   SALOME_LoadRateManager.hxx
   SALOME_ResourcesCatalog_Parser.hxx
   SALOME_ResourcesManager.hxx
+  SALOME_ResourcesManager_Client.hxx
+  SALOME_ResourcesManager_Common.hxx
   )
 INSTALL(FILES ${COMMON_HEADERS_HXX} DESTINATION ${SALOME_INSTALL_HEADERS})
index e24c908a542e0cda04e0ee4d145e2b0ce9da518c..fbbdba5157808d0c1db4248c4ca490295c886c50 100644 (file)
 #include <vector>
 #include "ResourcesManager.hxx"
 
-
-#ifdef WIN32
-# if defined SALOMERESOURCESMANAGER_EXPORTS || defined SalomeResourcesManager_EXPORTS
-#  define SALOMERESOURCESMANAGER_EXPORT __declspec( dllexport )
-# else
-#  define SALOMERESOURCESMANAGER_EXPORT __declspec( dllimport )
-# endif
-#else
-# define SALOMERESOURCESMANAGER_EXPORT
-#endif
+#include "SALOME_ResourcesManager_Common.hxx"
 
 #ifdef WIN32
 #pragma warning(disable:4275) // Disable warning interface non dll
diff --git a/src/ResourcesManager/SALOME_ResourcesManager_Client.cxx b/src/ResourcesManager/SALOME_ResourcesManager_Client.cxx
new file mode 100644 (file)
index 0000000..5b0ea02
--- /dev/null
@@ -0,0 +1,64 @@
+// Copyright (C) 2007-2014  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
+//
+// 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.
+//
+// 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
+//
+
+#include "SALOME_ResourcesManager_Client.hxx"
+#include "SALOME_ResourcesManager.hxx"
+
+using namespace std;
+
+SALOME_ResourcesManager_Client::SALOME_ResourcesManager_Client(SALOME_NamingService *ns)
+  : _rm(Engines::ResourcesManager::_nil())
+{
+  CORBA::Object_var objRM = ns->Resolve(SALOME_ResourcesManager::_ResourcesManagerNameInNS);
+  if (!CORBA::is_nil(objRM))
+    _rm = Engines::ResourcesManager::_narrow(objRM);
+  if (CORBA::is_nil(_rm))
+    throw SALOME_Exception("Cannot get SALOME ResourcesManager");
+}
+
+SALOME_ResourcesManager_Client::~SALOME_ResourcesManager_Client()
+{
+  
+}
+
+vector<string> SALOME_ResourcesManager_Client::GetFittingResources(const resourceParams& params)
+{
+  Engines::ResourceParameters_var corba_params = resourceParameters_CPPtoCORBA(params);
+  Engines::ResourceList_var corba_rl = _rm->GetFittingResources(corba_params);
+  vector<string> res = resourceList_CORBAtoCPP(corba_rl);
+  return res;
+}
+
+string SALOME_ResourcesManager_Client::Find(const string & policy, const vector<string> & listOfResources)
+{
+  Engines::ResourceList_var corba_rl = resourceList_CPPtoCORBA(listOfResources);
+  CORBA::String_var corba_res = _rm->Find(policy.c_str(), corba_rl);
+  string res = corba_res.in();
+  return res;
+}
+
+ParserResourcesType SALOME_ResourcesManager_Client::GetResourceDefinition(const std::string & name)
+{
+  Engines::ResourceDefinition_var corba_res = _rm->GetResourceDefinition(name.c_str());
+  ParserResourcesType res = resourceDefinition_CORBAtoCPP(corba_res);
+  return res;
+}
diff --git a/src/ResourcesManager/SALOME_ResourcesManager_Client.hxx b/src/ResourcesManager/SALOME_ResourcesManager_Client.hxx
new file mode 100644 (file)
index 0000000..ae6a291
--- /dev/null
@@ -0,0 +1,52 @@
+// Copyright (C) 2007-2014  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
+//
+// 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.
+//
+// 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
+//
+
+#ifndef __SALOME_RESOURCESMANAGER_CLIENT_HXX__
+#define __SALOME_RESOURCESMANAGER_CLIENT_HXX__
+
+#include "SALOME_ResourcesManager_Common.hxx"
+
+class SALOME_NamingService;
+
+// This class is fully thread-safe because the ResourcesManager CORBA object
+// runs in a single-thread POA.
+class SALOMERESOURCESMANAGER_EXPORT SALOME_ResourcesManager_Client
+{
+public:
+
+  SALOME_ResourcesManager_Client(SALOME_NamingService *ns);
+  ~SALOME_ResourcesManager_Client();
+
+  std::vector<std::string> GetFittingResources(const resourceParams& params);
+  //std::string FindFirst(const std::vector<std::string>& listOfResources) const;
+  std::string Find(const std::string & policy, const std::vector<std::string> & listOfResources);
+  ParserResourcesType GetResourceDefinition(const std::string & name);
+  //void AddResource(const ParserResourcesType & new_resource, bool write, const std::string & xml_file);
+  //void RemoveResource(const std::string & name, bool write, const std::string & xml_file);
+
+protected:
+
+  Engines::ResourcesManager_var _rm;
+
+};
+
+#endif
diff --git a/src/ResourcesManager/SALOME_ResourcesManager_Common.cxx b/src/ResourcesManager/SALOME_ResourcesManager_Common.cxx
new file mode 100644 (file)
index 0000000..7969362
--- /dev/null
@@ -0,0 +1,114 @@
+// Copyright (C) 2007-2014  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
+//
+// 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.
+//
+// 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
+//
+
+#include "SALOME_ResourcesManager_Common.hxx"
+
+using namespace std;
+
+template <class T>
+vector<string> strvec_CORBAtoCPP(const T & strvecCorba)
+{
+  vector<string> strvecCpp;
+  for(unsigned int i=0; i<strvecCorba.length(); i++)
+    strvecCpp.push_back(string(strvecCorba[i]));
+  return strvecCpp;
+}
+
+template <class T>
+typename T::_var_type strvec_CPPtoCORBA(const vector<string> & strvecCpp)
+{
+  typename T::_var_type strvecCorba = new T;
+  strvecCorba->length(strvecCpp.size());
+  for(unsigned int i=0;i<strvecCpp.size();i++)
+    strvecCorba[i] = strvecCpp[i].c_str();
+  return strvecCorba;
+}
+
+resourceParams resourceParameters_CORBAtoCPP(const Engines::ResourceParameters & params)
+{
+  resourceParams p;
+  p.name = params.name;
+  p.hostname = params.hostname;
+  p.can_launch_batch_jobs = params.can_launch_batch_jobs;
+  p.can_run_containers = params.can_run_containers;
+  p.OS = params.OS;
+  p.nb_proc = params.nb_proc;
+  p.nb_node = params.nb_node;
+  p.nb_proc_per_node = params.nb_proc_per_node;
+  p.cpu_clock = params.cpu_clock;
+  p.mem_mb = params.mem_mb;
+  p.componentList = strvec_CORBAtoCPP<Engines::CompoList>(params.componentList);
+  p.resourceList = resourceList_CORBAtoCPP(params.resList);
+  return p;
+}
+
+Engines::ResourceParameters_var resourceParameters_CPPtoCORBA(const resourceParams & params)
+{
+  Engines::ResourceParameters_var p = new Engines::ResourceParameters;
+  p->name = params.name.c_str();
+  p->hostname = params.hostname.c_str();
+  p->can_launch_batch_jobs = params.can_launch_batch_jobs;
+  p->can_run_containers = params.can_run_containers;
+  p->OS = params.OS.c_str();
+  p->nb_proc = params.nb_proc;
+  p->nb_node = params.nb_node;
+  p->nb_proc_per_node = params.nb_proc_per_node;
+  p->cpu_clock = params.cpu_clock;
+  p->mem_mb = params.mem_mb;
+  p->componentList = strvec_CPPtoCORBA<Engines::CompoList>(params.componentList);
+  p->resList = resourceList_CPPtoCORBA(params.resourceList);
+  return p;
+}
+
+vector<string> resourceList_CORBAtoCPP(const Engines::ResourceList & resList)
+{
+  return strvec_CORBAtoCPP<Engines::ResourceList>(resList);
+}
+
+Engines::ResourceList_var resourceList_CPPtoCORBA(const vector<string> & resList)
+{
+  return strvec_CPPtoCORBA<Engines::ResourceList>(resList);
+}
+
+ParserResourcesType resourceDefinition_CORBAtoCPP(const Engines::ResourceDefinition & resDef)
+{
+  ParserResourcesType resource;
+  resource.Name = resDef.name;
+  resource.HostName = resDef.hostname;
+  resource.setResourceTypeStr(resDef.type.in());
+  resource.OS = resDef.OS;
+  resource.AppliPath = resDef.applipath;
+  resource.DataForSort._memInMB = resDef.mem_mb;
+  resource.DataForSort._CPUFreqMHz = resDef.cpu_clock;
+  resource.DataForSort._nbOfNodes = resDef.nb_node;
+  resource.DataForSort._nbOfProcPerNode = resDef.nb_proc_per_node;
+  resource.UserName = resDef.username;
+  resource.can_launch_batch_jobs = resDef.can_launch_batch_jobs;
+  resource.can_run_containers = resDef.can_run_containers;
+  resource.working_directory = resDef.working_directory;
+  resource.setBatchTypeStr(resDef.batch.in());
+  resource.setMpiImplTypeStr(resDef.mpiImpl.in());
+  resource.setAccessProtocolTypeStr(resDef.protocol.in());
+  resource.setClusterInternalProtocolStr(resDef.iprotocol.in());
+  resource.ComponentsList = strvec_CORBAtoCPP<Engines::CompoList>(resDef.componentList);
+  return resource;
+}
diff --git a/src/ResourcesManager/SALOME_ResourcesManager_Common.hxx b/src/ResourcesManager/SALOME_ResourcesManager_Common.hxx
new file mode 100644 (file)
index 0000000..5eb745b
--- /dev/null
@@ -0,0 +1,50 @@
+// Copyright (C) 2007-2014  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
+//
+// 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.
+//
+// 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
+//
+
+#ifndef __SALOME_RESOURCESMANAGER_COMMON_HXX__
+#define __SALOME_RESOURCESMANAGER_COMMON_HXX__
+
+#ifdef WIN32
+# if defined SALOMERESOURCESMANAGER_EXPORTS || defined SalomeResourcesManager_EXPORTS
+#  define SALOMERESOURCESMANAGER_EXPORT __declspec( dllexport )
+# else
+#  define SALOMERESOURCESMANAGER_EXPORT __declspec( dllimport )
+# endif
+#else
+# define SALOMERESOURCESMANAGER_EXPORT
+#endif
+
+#include <SALOMEconfig.h>
+#include CORBA_CLIENT_HEADER(SALOME_ResourcesManager)
+
+#include "ResourcesManager.hxx"
+
+// Functions for CPP <-> CORBA conversions
+// All those functions are thread-safe
+SALOMERESOURCESMANAGER_EXPORT resourceParams resourceParameters_CORBAtoCPP(const Engines::ResourceParameters & params);
+SALOMERESOURCESMANAGER_EXPORT Engines::ResourceParameters_var resourceParameters_CPPtoCORBA(const resourceParams & params);
+
+SALOMERESOURCESMANAGER_EXPORT std::vector<std::string> resourceList_CORBAtoCPP(const Engines::ResourceList & resList);
+SALOMERESOURCESMANAGER_EXPORT Engines::ResourceList_var resourceList_CPPtoCORBA(const std::vector<std::string> & resList);
+
+SALOMERESOURCESMANAGER_EXPORT ParserResourcesType resourceDefinition_CORBAtoCPP(const Engines::ResourceDefinition & resDef);
+#endif