Salome HOME
ADD a end user module (services.py) to help the manipulation of SALOME KERNEL service...
[modules/kernel.git] / src / ParallelContainer / SALOME_ParallelContainerProxy_i.cxx
index ec268dc0192590ab2e80f30b7f0ec8843358ecca..9006a973c2a00929f0bc717f8f4bc7bb81aba55d 100644 (file)
@@ -1,35 +1,36 @@
-//  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2011  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
+// 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.
+// 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.
 //
-//  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.
+// 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
+// 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
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
+
 //  SALOME_ParallelContainerProxy : implementation of container and engine for Parallel Kernel
 //  File   : SALOME_ParallelContainerProxy_i.cxx
 //  Author : André RIBES, EDF
-
+//
 #include "SALOME_ParallelContainerProxy_i.hxx"
 
 Container_proxy_impl_final::Container_proxy_impl_final(CORBA::ORB_ptr orb, 
-                                                      paco_fabrique_thread * fab_thread, 
-                                                      PortableServer::POA_ptr poa,
-                                                      std::string containerName,
-                                                      bool is_a_return_proxy) :
+                                                       paco_fabrique_thread * fab_thread, 
+                                                       PortableServer::POA_ptr poa,
+                                                       std::string containerName,
+                                                       bool is_a_return_proxy) :
   Engines::PACO_Container_proxy_impl(orb, fab_thread, is_a_return_proxy),
   Engines::Container_proxy_impl(orb, fab_thread, is_a_return_proxy),
   InterfaceManager_impl(orb, fab_thread, is_a_return_proxy)
@@ -111,12 +112,12 @@ Container_proxy_impl_final::Shutdown()
     {
       try 
       {
-       node->Shutdown();
-       MESSAGE("Shutdown done node : " << i);
+        node->Shutdown();
+        MESSAGE("Shutdown done node : " << i);
       }
       catch (...)
       {
-       INFOS("Exception catch during Shutdown of node : " << i);
+        INFOS("Exception catch during Shutdown of node : " << i);
       }
     }
     else
@@ -136,9 +137,11 @@ Container_proxy_impl_final::Shutdown()
 // déterminer si on doit créer une instance sequentielle
 // ou parallèle d'un composant dans la méthode create_component_instance
 CORBA::Boolean 
-Container_proxy_impl_final::load_component_Library(const char* componentName)
+Container_proxy_impl_final::load_component_Library(const char* componentName, CORBA::String_out reason)
 {
-  MESSAGE("Begin of load_component_Library on proxy : " << componentName)
+  MESSAGE("Begin of load_component_Library on proxy : " << componentName);
+  reason=CORBA::string_dup("");
+
   std::string aCompName = componentName;
 
   CORBA::Boolean ret = true;
@@ -182,15 +185,15 @@ Container_proxy_impl_final::load_component_Library(const char* componentName)
 #endif
       if (paco_test_fct)
       {
-       // PaCO Component found
-       MESSAGE("PACO LIB FOUND");
-       _libtype_map[aCompName] = "par";
+        // PaCO Component found
+        MESSAGE("PACO LIB FOUND");
+        _libtype_map[aCompName] = "par";
       }
       else
       {
-       MESSAGE("SEQ LIB FOUND");
+        MESSAGE("SEQ LIB FOUND");
 #ifndef WIN32
-       MESSAGE("dlerror() result is : " << dlerror());
+        MESSAGE("dlerror() result is : " << dlerror());
 #endif
       }
     }
@@ -207,20 +210,20 @@ Container_proxy_impl_final::load_component_Library(const char* componentName)
       PyObject *globals = PyModule_GetDict(mainmod);
       PyObject *pyCont = PyDict_GetItemString(globals, "pyCont");
       PyObject *result = PyObject_CallMethod(pyCont,
-                                            (char*)"import_component",
-                                            (char*)"s",componentName);
-      int ret_p= PyInt_AsLong(result);
+                                             (char*)"import_component",
+                                             (char*)"s",componentName);
+      std::string ret_p= PyString_AsString(result);
       Py_XDECREF(result);
       Py_RELEASE_NEW_THREAD;
 
-      if (ret_p) // import possible: Python component
+      if (ret_p=="") // import possible: Python component
       {
-       MESSAGE("import Python: " << aCompName <<" OK");
+        MESSAGE("import Python: " << aCompName <<" OK");
       }
       else
       {
-       MESSAGE("Error in importing Python component : " << aCompName);
-       ret = false;
+        MESSAGE("Error in importing Python component : " << aCompName);
+        ret = false;
       }
     }
     _numInstanceMutex.unlock();
@@ -236,21 +239,24 @@ Container_proxy_impl_final::load_component_Library(const char* componentName)
       Engines::Container_var node = Engines::Container::_narrow(object);
       if (!CORBA::is_nil(node))
       {
-       try 
-       {
-         node->load_component_Library(componentName);
-         MESSAGE("Call load_component_Library done node : " << i);
-       }
-       catch (...)
-       {
-         INFOS("Exception catch during load_component_Library of node : " << i);
-         ret = false;
-       }
+        char* reason;
+        try 
+        {
+          node->load_component_Library(componentName,reason);
+          MESSAGE("Call load_component_Library done node : " << i);
+          CORBA::string_free(reason);
+        }
+        catch (...)
+        {
+          INFOS("Exception catch during load_component_Library of node : " << i);
+          CORBA::string_free(reason);
+          ret = false;
+        }
       }
       else
       {
-       INFOS("Cannot call load_component_Library node " << i << " ref is nil !");
-       ret = false;
+        INFOS("Cannot call load_component_Library node " << i << " ref is nil !");
+        ret = false;
       }
     }
   }
@@ -264,19 +270,32 @@ Container_proxy_impl_final::load_component_Library(const char* componentName)
   return ret;
 }
 
+Engines::EngineComponent_ptr 
+Container_proxy_impl_final::create_component_instance(const char* componentName, ::CORBA::Long studyId)
+{
+  Engines::FieldsDict_var env = new Engines::FieldsDict;
+  char* reason;
+  Engines::EngineComponent_ptr compo = create_component_instance_env(componentName, studyId, env, reason);
+  CORBA::string_free(reason);
+  return compo;
+}
+
 // Il y a deux cas :
 // Composant sequentiel -> on le créer sur le noeud 0 (on pourrait faire une répartition de charge)
 // Composant parallèle -> création du proxy ici puis appel de la création de chaque objet participant
 // au composant parallèle
-Engines::Component_ptr 
-Container_proxy_impl_final::create_component_instance(const char* componentName, ::CORBA::Long studyId)
+Engines::EngineComponent_ptr 
+Container_proxy_impl_final::create_component_instance_env(const char* componentName, ::CORBA::Long studyId,
+                                                          const Engines::FieldsDict& env, CORBA::String_out reason)
 {
+  reason=CORBA::string_dup("");
+
   std::string aCompName = componentName;
   if (_libtype_map.count(aCompName) == 0)
   {
     // Component is not loaded !
     INFOS("Proxy: component is not loaded ! : " << aCompName);
-    return Engines::Component::_nil();
+    return Engines::EngineComponent::_nil();
   }
 
   // If it is a sequential component
@@ -290,7 +309,7 @@ Container_proxy_impl_final::create_component_instance(const char* componentName,
   }
 
   // Parallel Component !
-  Engines::Component_var component_proxy = Engines::Component::_nil();
+  Engines::EngineComponent_var component_proxy = Engines::EngineComponent::_nil();
 
   // On commence par créer le proxy
 #ifndef WIN32
@@ -310,7 +329,7 @@ Container_proxy_impl_final::create_component_instance(const char* componentName,
 #ifndef WIN32
     INFOS("dlerror() result is : " << dlerror());
 #endif
-    return Engines::Component::_nil() ;
+    return Engines::EngineComponent::_nil() ;
   }
   try {
     _numInstanceMutex.lock() ; // lock on the instance number
@@ -327,16 +346,16 @@ Container_proxy_impl_final::create_component_instance(const char* componentName,
     Container_proxy_impl_final::proxy_object * proxy = new Container_proxy_impl_final::proxy_object();
     
     proxy->proxy_id = (component_proxy_factory) (_orb, 
-                                                _fab_thread,
-                                                _poa, 
-                                                _id,
-                                                &(proxy->proxy_regist),
-                                                instanceName.c_str(), 
-                                                _parallel_object_topology.total);
+                                                 _fab_thread,
+                                                 _poa, 
+                                                 _id,
+                                                 &(proxy->proxy_regist),
+                                                 instanceName.c_str(), 
+                                                 _parallel_object_topology.total);
 
     // --- get reference & servant from id
     CORBA::Object_var obj = _poa->id_to_reference(*(proxy->proxy_id));
-    component_proxy = Engines::Component::_narrow(obj);
+    component_proxy = Engines::EngineComponent::_narrow(obj);
     proxy->proxy_corba_ref = component_proxy;
 
     if (!CORBA::is_nil(component_proxy))
@@ -353,14 +372,14 @@ Container_proxy_impl_final::create_component_instance(const char* componentName,
     else
     {
       INFOS("The factory returns a nil object !");
-      return Engines::Component::_nil();
+      return Engines::EngineComponent::_nil();
     }
       
   }
   catch (...)
   {
     INFOS( "Exception catched in Proxy creation" );
-    return Engines::Component::_nil();
+    return Engines::EngineComponent::_nil();
   }
 
   // Create on each node a work node
@@ -373,24 +392,24 @@ Container_proxy_impl_final::create_component_instance(const char* componentName,
     {
       try 
       {
-       node->create_paco_component_node_instance(componentName, _containerName.c_str(), studyId);
-       MESSAGE("Call create_paco_component_node_instance done on node : " << i);
+        node->create_paco_component_node_instance(componentName, _containerName.c_str(), studyId);
+        MESSAGE("Call create_paco_component_node_instance done on node : " << i);
       }
       catch (SALOME::SALOME_Exception & ex)
       {
-       INFOS("SALOME_EXCEPTION : " << ex.details.text);
-       return Engines::Component::_nil();
+        INFOS("SALOME_EXCEPTION : " << ex.details.text);
+        return Engines::EngineComponent::_nil();
       }
       catch (...)
       {
-       INFOS("Unknown Exception catch during create_paco_component_node_instance on node : " << i);
-       return Engines::Component::_nil();
+        INFOS("Unknown Exception catch during create_paco_component_node_instance on node : " << i);
+        return Engines::EngineComponent::_nil();
       }
     }
     else
     {
       INFOS("Cannot call create_paco_component_node_instance on node " << i << " ref is nil !");
-      return Engines::Component::_nil();
+      return Engines::EngineComponent::_nil();
     }
   }