From: ribes Date: Tue, 24 Mar 2009 16:09:39 +0000 (+0000) Subject: - Parallel Container can now load cpp and python components X-Git-Tag: new_launcher_alpha_091119~43 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=58a9c7624b7fbf9772f849bbdc8098f3f44c5f26;p=modules%2Fkernel.git - Parallel Container can now load cpp and python components --- diff --git a/src/ParallelContainer/SALOME_ParallelContainerProxyDummy.cxx b/src/ParallelContainer/SALOME_ParallelContainerProxyDummy.cxx index 0d4ba4520..3b078228e 100644 --- a/src/ParallelContainer/SALOME_ParallelContainerProxyDummy.cxx +++ b/src/ParallelContainer/SALOME_ParallelContainerProxyDummy.cxx @@ -49,6 +49,8 @@ #include "SALOMETraceCollector.hxx" #include "OpUtil.hxx" +#include "Container_init_python.hxx" + #ifdef DEBUG_PARALLEL #include using namespace std; @@ -72,6 +74,7 @@ int main(int argc, char* argv[]) #endif // Initialise the ORB. CORBA::ORB_var orb = CORBA::ORB_init(argc, argv); + KERNEL_PYTHON::init_python(argc,argv); std::string containerName(""); if(argc > 1) { @@ -129,6 +132,9 @@ int main(int argc, char* argv[]) ns->Register(pCont, _containerName.c_str()); pman->activate(); orb->run(); + PyGILState_Ensure(); + //Delete python container that destroy orb from python (pyCont._orb.destroy()) + Py_Finalize(); delete ns; } catch (PaCO::PACO_Exception& e) diff --git a/src/ParallelContainer/SALOME_ParallelContainerProxy_i.cxx b/src/ParallelContainer/SALOME_ParallelContainerProxy_i.cxx index 8fc2d3ee8..60c35a3a4 100644 --- a/src/ParallelContainer/SALOME_ParallelContainerProxy_i.cxx +++ b/src/ParallelContainer/SALOME_ParallelContainerProxy_i.cxx @@ -48,6 +48,18 @@ Container_proxy_impl_final::Container_proxy_impl_final(CORBA::ORB_ptr orb, // Init SALOME Naming Service _NS = new SALOME_NamingService(); _NS->init_orb(_orb); + + // Init Python container part + CORBA::Object_var container_node = _poa->id_to_reference(*_id); + CORBA::String_var sior = _orb->object_to_string(container_node); + std::string myCommand="pyCont = SALOME_Container.SALOME_Container_i('"; + myCommand += _containerName + "','"; + myCommand += sior; + myCommand += "')\n"; + Py_ACQUIRE_NEW_THREAD; + PyRun_SimpleString("import SALOME_Container\n"); + PyRun_SimpleString((char*)myCommand.c_str()); + Py_RELEASE_NEW_THREAD; } Container_proxy_impl_final:: ~Container_proxy_impl_final() { @@ -127,6 +139,7 @@ Container_proxy_impl_final::load_component_Library(const char* componentName) MESSAGE("Begin of load_component_Library on proxy : " << componentName) std::string aCompName = componentName; + CORBA::Boolean ret = true; if (_libtype_map.count(aCompName) == 0) { _numInstanceMutex.lock(); // lock to be alone @@ -179,39 +192,68 @@ Container_proxy_impl_final::load_component_Library(const char* componentName) #endif } } + else + { + MESSAGE("Try to import Python component "<string_to_object(_infos.nodes[i]); - Engines::Container_var node = Engines::Container::_narrow(object); - if (!CORBA::is_nil(node)) + for (CORBA::ULong i = 0; i < _infos.nodes.length(); i++) { - try + MESSAGE("Call load_component_Library work node : " << i); + CORBA::Object_var object = _orb->string_to_object(_infos.nodes[i]); + Engines::Container_var node = Engines::Container::_narrow(object); + if (!CORBA::is_nil(node)) { - node->load_component_Library(componentName); - MESSAGE("Call load_component_Library done node : " << i); + 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; + } } - catch (...) + else { - INFOS("Exception catch during load_component_Library of node : " << i); + INFOS("Cannot call load_component_Library node " << i << " ref is nil !"); ret = false; } } - else - { - INFOS("Cannot call load_component_Library node " << i << " ref is nil !"); - ret = false; - } } // If ret is false -> lib is not loaded ! if (!ret) + { + INFOS("Cannot call load_component_Library " << aCompName); _libtype_map.erase(aCompName); + } return ret; } @@ -232,7 +274,12 @@ Container_proxy_impl_final::create_component_instance(const char* componentName, // If it is a sequential component if (_libtype_map[aCompName] == "seq") + { + _numInstanceMutex.lock() ; // lock on the instance number + _numInstance++ ; + _numInstanceMutex.unlock() ; return Engines::Container_proxy_impl::create_component_instance(componentName, studyId); + } // Parallel Component ! Engines::Component_var component_proxy = Engines::Component::_nil(); diff --git a/src/ParallelContainer/SALOME_ParallelContainerProxy_i.hxx b/src/ParallelContainer/SALOME_ParallelContainerProxy_i.hxx index abc6b54b0..6e4c56db4 100644 --- a/src/ParallelContainer/SALOME_ParallelContainerProxy_i.hxx +++ b/src/ParallelContainer/SALOME_ParallelContainerProxy_i.hxx @@ -36,6 +36,9 @@ #include #include +#include +#include "Container_init_python.hxx" + class Container_proxy_impl_final : virtual public Engines::PACO_Container_proxy_impl, virtual public ParallelGlobalProcessVar_i diff --git a/src/ParallelContainer/SALOME_ParallelContainer_i.cxx b/src/ParallelContainer/SALOME_ParallelContainer_i.cxx index ef4310a8c..00b219a3d 100644 --- a/src/ParallelContainer/SALOME_ParallelContainer_i.cxx +++ b/src/ParallelContainer/SALOME_ParallelContainer_i.cxx @@ -396,6 +396,9 @@ Engines_Parallel_Container_i::create_component_instance(const char*genericRegist string impl_name = aCompName +string("Engine.dll"); #endif + _numInstanceMutex.lock(); + _numInstance++; + // Test if the component lib is loaded std::string type_of_lib("Not Loaded"); void* handle = _library_map[impl_name]; @@ -407,6 +410,7 @@ Engines_Parallel_Container_i::create_component_instance(const char*genericRegist if (type_of_lib == "Not Loaded") { std::cerr << "Component library is not loaded or imported ! lib was : " << aCompName << std::endl; + _numInstanceMutex.unlock(); return Engines::Component::_nil(); } @@ -416,6 +420,7 @@ Engines_Parallel_Container_i::create_component_instance(const char*genericRegist else iobject = createPythonInstance(aCompName, studyId); + _numInstanceMutex.unlock(); return iobject._retn(); } @@ -734,10 +739,7 @@ Engines_Parallel_Container_i::createPythonInstance(string genericRegisterName, i Engines::Component_var iobject = Engines::Component::_nil(); - _numInstanceMutex.lock(); - _numInstance++; int numInstance = _numInstance; - _numInstanceMutex.unlock(); char aNumI[12]; sprintf( aNumI , "%d" , numInstance ) ; string instanceName = genericRegisterName + "_inst_" + aNumI ; @@ -829,11 +831,7 @@ Engines_Parallel_Container_i::createCPPInstance(string genericRegisterName, Engines::Component_var iobject = Engines::Component::_nil() ; try { - _numInstanceMutex.lock(); - _numInstance++; int numInstance = _numInstance; - _numInstanceMutex.unlock(); - char aNumI[12]; sprintf( aNumI , "%d" , numInstance ); string instanceName = aGenRegisterName + "_inst_" + aNumI;