Salome HOME
Fix a bug causing concurrent access problems to the Resources Manager
[modules/kernel.git] / src / Container / SALOME_ContainerManager.hxx
index 8a4f942bd86cebe6fac8e8cac6ede7642df98801..fc55e7579f9e76140a31508b49a593de0da11a05 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
+// 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
@@ -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
 #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 <string>
 #include <set>
 
 class SALOME_NamingService;
+class SALOME_ResourcesManager_Client;
 
-class CONTAINER_EXPORT SALOME_ContainerManager:
-  public POA_Engines::ContainerManager
+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
-  Engines::Container_ptr
-  GiveContainer(const Engines::ContainerParameters& params);
+  Engines::Container_ptr GiveContainer(const Engines::ContainerParameters& params);
 
   void ShutdownContainers();
 
@@ -67,16 +67,17 @@ protected:
 
   std::string BuildCommandToLaunchRemoteContainer(const std::string & resource_name,
                                                   const Engines::ContainerParameters& params, 
-                                                  const std::string& container_exe="SALOME_Container");
+                                                  const std::string& container_exe="SALOME_Container") const;
 
   std::string BuildCommandToLaunchLocalContainer(const Engines::ContainerParameters& params,
                                                  const std::string& machinesFile,
-                                                 const std::string& container_exe="SALOME_Container");
+                                                 const std::string& container_exe,//"SALOME_Container"
+                                                 std::string& tmpFileName) const;
 
   std::string BuildTempFileToLaunchRemoteContainer(const std::string& resource_name,
-                                                   const Engines::ContainerParameters& params) throw(SALOME_Exception);
+                                                   const Engines::ContainerParameters& params, std::string& tmpFileName) const;
 
-  void RmTmpFile(std::string& tmpFile);
+  static void RmTmpFile(std::string& tmpFile);
 
   void AddOmninamesParams(std::string& command) const;
 
@@ -84,17 +85,15 @@ protected:
 
   void AddOmninamesParams(std::ofstream& fileStream) const;
 
-  std::string BuildTemporaryFileName() const;
+  static std::string BuildTemporaryFileName();
 
-  std::string GetMPIZeroNode(const std::string machine, const std::string machinesFile);
+  std::string GetMPIZeroNode(const std::string machine, const std::string machinesFile) const;
 
   std::string machinesFile(const int nbproc);
 
   std::set<pid_t> getpidofprogram(const std::string program);
 
-  std::string getCommandToRunRemoteProcess(AccessProtocolType protocol,
-                                           const std::string & hostname,
-                                           const std::string & username);
+ static std::string getCommandToRunRemoteProcess(AccessProtocolType protocol, const std::string & hostname, const std::string & username);
 
   Engines::Container_ptr
   LaunchContainer(const Engines::ContainerParameters& params,
@@ -106,16 +105,9 @@ protected:
   CORBA::ORB_var _orb;
   PortableServer::POA_var _poa;
 
-  SALOME_ResourcesManager *_ResManager;
+  SALOME_ResourcesManager_Client *_resManager;
   SALOME_NamingService *_NS;
 
-  //! attribute that contains current tmp files generated
-  std::string _TmpFileName;
-
-  //! contains the rsh or ssh command to access directly to machine.
-  //  Only used by this->RmTmpFile in case of a remote launch.
-  std::string _CommandForRemAccess;
-
   //! different behaviour if $APPLI exists (SALOME Application) 
   bool _isAppliSalomeDefined;
 
@@ -124,6 +116,9 @@ protected:
 
   static omni_mutex _numInstanceMutex ; // lib and instance protection
 
+  //! attributes to allow concurrency for // GiveContainer
+  Utils_Mutex _giveContainerMutex1;
+
   pid_t _pid_mpiServer;
 
   // Begin of PacO++ Parallel extension
@@ -163,5 +158,11 @@ protected:
                           const std::string& name,
                           SALOME_ContainerManager::actual_launch_machine_t & vect_machine);
   // End of PaCO++ Parallel extension
+public:
+  static char *GetenvThreadSafe(const char *name);
+  static int SystemThreadSafe(const char *command);
+private:
+  static Utils_Mutex _getenvMutex;
+  static Utils_Mutex _systemMutex;
 };
 #endif