]> SALOME platform Git repositories - modules/kernel.git/commitdiff
Salome HOME
Deal with multi pyevaluator objects in containers + manage multi thread invokation. agy/BugParaLaunchOnPyScripts cbr/crowdin_V7_7_BR
authorAnthony Geay <anthony.geay@edf.fr>
Fri, 25 Sep 2015 08:02:02 +0000 (10:02 +0200)
committerAnthony Geay <anthony.geay@edf.fr>
Fri, 25 Sep 2015 08:02:02 +0000 (10:02 +0200)
src/Container/Container_i.cxx
src/Container/SALOME_Container_i.hxx

index 0b8b19116ba9869be7a2302179ea9457f0941fdd..e18381210093125254361e4728feec0610556464 100644 (file)
@@ -254,10 +254,18 @@ Engines_Container_i::~Engines_Container_i()
     delete _id;
   if(_NS)
     delete _NS;
-  if(!CORBA::is_nil(_dftPyNode))
-    _dftPyNode->UnRegister();
-  if(!CORBA::is_nil(_dftPyScriptNode))
-    _dftPyScriptNode->UnRegister();
+  for(std::map<std::string,Engines::PyNode_var>::iterator it=_dftPyNode.begin();it!=_dftPyNode.end();it++)
+    {
+      Engines::PyNode_var tmpVar((*it).second);
+      if(!CORBA::is_nil(tmpVar))
+        tmpVar->UnRegister();
+    }
+  for(std::map<std::string,Engines::PyScriptNode_var>::iterator it=_dftPyScriptNode.begin();it!=_dftPyScriptNode.end();it++)
+    {
+      Engines::PyScriptNode_var tmpVar((*it).second);
+      if(!CORBA::is_nil(tmpVar))
+        tmpVar->UnRegister();
+    }
 }
 
 //=============================================================================
@@ -1679,16 +1687,25 @@ Engines::PyNode_ptr Engines_Container_i::createPyNode(const char* nodeName, cons
     std::string astr=PyString_AsString(result);
     Py_DECREF(res);
     PyGILState_Release(gstate);
-
     if(ierr==0)
       {
-        CORBA::Object_var obj = _orb->string_to_object(astr.c_str());
-        node = Engines::PyNode::_narrow(obj);
-        if(!CORBA::is_nil(_dftPyNode))
-          _dftPyNode->UnRegister();
-        _dftPyNode = node;
-        if(!CORBA::is_nil(_dftPyNode))
-          _dftPyNode->Register();
+        Utils_Locker lck(&_mutexForDftPy);
+        CORBA::Object_var obj=_orb->string_to_object(astr.c_str());
+        node=Engines::PyNode::_narrow(obj);
+        std::map<std::string,Engines::PyNode_var>::iterator it(_dftPyNode.find(nodeName));
+        if(it==_dftPyNode.end())
+          {
+            _dftPyNode[nodeName]=node;
+          }
+        else
+          {
+            Engines::PyNode_var oldNode((*it).second);
+            if(!CORBA::is_nil(oldNode))
+              oldNode->UnRegister();
+            (*it).second=node;
+          }
+        if(!CORBA::is_nil(node))
+          node->Register();
         return node._retn();
       }
     else
@@ -1698,7 +1715,6 @@ Engines::PyNode_ptr Engines_Container_i::createPyNode(const char* nodeName, cons
         es.text = astr.c_str();
         throw SALOME::SALOME_Exception(es);
       }
-
 }
 
 //=============================================================================
@@ -1708,10 +1724,18 @@ Engines::PyNode_ptr Engines_Container_i::createPyNode(const char* nodeName, cons
 //=============================================================================
 Engines::PyNode_ptr  Engines_Container_i::getDefaultPyNode(const char *nodeName)
 {
-  if(!CORBA::is_nil(_dftPyNode))
-    return Engines::PyNode::_duplicate(_dftPyNode);
-  else
+  Utils_Locker lck(&_mutexForDftPy);
+  std::map<std::string,Engines::PyNode_var>::iterator it(_dftPyNode.find(nodeName));
+  if(it==_dftPyNode.end())
     return Engines::PyNode::_nil();
+  else
+    {
+      Engines::PyNode_var tmpVar((*it).second);
+      if(!CORBA::is_nil(tmpVar))
+        return Engines::PyNode::_duplicate(tmpVar);
+      else
+        return Engines::PyNode::_nil();
+    }
 }
 
 //=============================================================================
@@ -1749,13 +1773,23 @@ Engines::PyScriptNode_ptr Engines_Container_i::createPyScriptNode(const char* no
 
     if(ierr==0)
       {
-        CORBA::Object_var obj = _orb->string_to_object(astr.c_str());
-        node = Engines::PyScriptNode::_narrow(obj);
-        if(!CORBA::is_nil(_dftPyScriptNode))
-          _dftPyScriptNode->UnRegister();
-        _dftPyScriptNode = node;
-        if(!CORBA::is_nil(_dftPyScriptNode))
-          _dftPyScriptNode->Register();
+        Utils_Locker lck(&_mutexForDftPy);
+        CORBA::Object_var obj=_orb->string_to_object(astr.c_str());
+        node=Engines::PyScriptNode::_narrow(obj);
+        std::map<std::string,Engines::PyScriptNode_var>::iterator it(_dftPyScriptNode.find(nodeName));
+        if(it==_dftPyScriptNode.end())
+          {
+            _dftPyScriptNode[nodeName]=node;
+          }
+        else
+          {
+            Engines::PyScriptNode_var oldNode((*it).second);
+            if(!CORBA::is_nil(oldNode))
+              oldNode->UnRegister();
+            (*it).second=node;
+          }
+        if(!CORBA::is_nil(node))
+          node->Register();
         return node._retn();
       }
     else
@@ -1774,10 +1808,18 @@ Engines::PyScriptNode_ptr Engines_Container_i::createPyScriptNode(const char* no
 //=============================================================================
 Engines::PyScriptNode_ptr Engines_Container_i::getDefaultPyScriptNode(const char *nodeName)
 {
-  if(!CORBA::is_nil(_dftPyScriptNode))
-    return Engines::PyScriptNode::_duplicate(_dftPyScriptNode);
-  else
+  Utils_Locker lck(&_mutexForDftPy);
+  std::map<std::string,Engines::PyScriptNode_var>::iterator it(_dftPyScriptNode.find(nodeName));
+  if(it==_dftPyScriptNode.end())
     return Engines::PyScriptNode::_nil();
+  else
+    {
+      Engines::PyScriptNode_var tmpVar((*it).second);
+      if(!CORBA::is_nil(tmpVar))
+        return Engines::PyScriptNode::_duplicate(tmpVar);
+      else
+        return Engines::PyScriptNode::_nil();
+    }
 }
 
 //=============================================================================
index 83d8f4fe940314d138610fd9fc5b4c28ba9a9728..9a49dd04dfaf66346c8872e8fa714ac012a6cd0f 100644 (file)
@@ -30,6 +30,7 @@
 #define _SALOME_CONTAINER_I_HXX_
 
 #include "SALOME_Container.hxx"
+#include "Utils_Mutex.hxx"
 
 #include <SALOMEconfig.h>
 #include CORBA_SERVER_HEADER(SALOME_Component)
@@ -161,8 +162,9 @@ protected:
   std::map<std::string,Engines::EngineComponent_var> _listInstances_map;
   std::map<std::string,Engines::fileRef_var> _fileRef_map;
   std::map<std::string,Engines::Salome_file_var> _Salome_file_map;
-  Engines::PyScriptNode_var _dftPyScriptNode;
-  Engines::PyNode_var _dftPyNode;
+  std::map<std::string,Engines::PyScriptNode_var> _dftPyScriptNode;
+  std::map<std::string,Engines::PyNode_var> _dftPyNode;
+  Utils_Mutex _mutexForDftPy;
   std::list<std::string> _tmp_files;
   Engines::fileTransfer_var _fileTransfer;