X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fruntime%2FRuntimeSALOME.cxx;h=55401af07229a27a718aefaaae0b12b289f80cd1;hb=f3b03fff6def9f5240803333b9aac7ec316fa30c;hp=b20f46b96a06f0801fb2e51023dd8df9303df8d8;hpb=301fcc69dc7b0f1f3f1f1e844a22cfa722253c8d;p=modules%2Fyacs.git diff --git a/src/runtime/RuntimeSALOME.cxx b/src/runtime/RuntimeSALOME.cxx index b20f46b96..55401af07 100644 --- a/src/runtime/RuntimeSALOME.cxx +++ b/src/runtime/RuntimeSALOME.cxx @@ -1,9 +1,9 @@ -// Copyright (C) 2006-2013 CEA/DEN, EDF R&D +// Copyright (C) 2006-2023 CEA, EDF // // 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 @@ -35,6 +35,7 @@ #include "TypeCode.hxx" #include "WhileLoop.hxx" #include "ForLoop.hxx" +#include "ForEachLoop.hxx" #include "SalomeOptimizerLoop.hxx" #include "Bloc.hxx" #include "InputPort.hxx" @@ -42,6 +43,7 @@ #include "PresetPorts.hxx" #include "InputDataStreamPort.hxx" #include "OutputDataStreamPort.hxx" +#include "Switch.hxx" #include "SalomeProc.hxx" #include "PyStdout.hxx" //Catalog Loaders @@ -50,11 +52,14 @@ //Components #include "CORBAComponent.hxx" #include "SalomeComponent.hxx" +#include "SalomeHPComponent.hxx" #include "SalomePythonComponent.hxx" #include "CppComponent.hxx" #include "SalomeContainer.hxx" #include "CppContainer.hxx" +#include "SalomeHPContainer.hxx" +#include "PythonCppUtils.hxx" //Nodes #include "PythonNode.hxx" @@ -106,15 +111,23 @@ #include "CalStreamPort.hxx" #ifdef SALOME_KERNEL -#include "SALOME_NamingService.hxx" +#include "SALOME_NamingService_Wrapper.hxx" #include "SALOME_LifeCycleCORBA.hxx" +#include "SALOME_ResourcesManager.hxx" +#include "SALOME_ContainerManager.hxx" +#include "SALOMEconfig.h" +#include "SALOME_Embedded_NamingService.hxx" +#include CORBA_CLIENT_HEADER(SALOME_ContainerManager) + #endif #include #include #include #include +#include #include +#include //#define _DEVDEBUG_ #include "YacsTrace.hxx" @@ -122,11 +135,17 @@ using namespace std; using namespace YACS::ENGINE; -void RuntimeSALOME::setRuntime(long flags) // singleton creation (not thread safe!) +std::unique_ptr RuntimeSALOME::getNS() +{ + std::unique_ptr ret(new SALOME_NamingService_Wrapper); + return ret; +} + +void RuntimeSALOME::setRuntime(long flags, int argc, char* argv[]) // singleton creation (not thread safe!) { if (! Runtime::_singleton) { - RuntimeSALOME* r=new RuntimeSALOME(flags); + RuntimeSALOME* r=new RuntimeSALOME(flags, argc, argv); Runtime::_singleton = r; r->initBuiltins(); } @@ -135,8 +154,8 @@ void RuntimeSALOME::setRuntime(long flags) // singleton creation (not thread saf RuntimeSALOME* YACS::ENGINE::getSALOMERuntime() { - YASSERT(Runtime::_singleton); - return dynamic_cast< RuntimeSALOME* >(Runtime::_singleton); + YASSERT(RuntimeSALOME::getSingleton()); + return dynamic_cast< RuntimeSALOME* >(RuntimeSALOME::getSingleton()); } /** @@ -177,12 +196,22 @@ void RuntimeSALOME::initBuiltins() typeMap["seqboolvec"]= createSequenceTc("seqboolvec","seqboolvec",typeMap["boolvec"]); std::list ltc; typeMap["pyobj"]= createInterfaceTc("python:obj:1.0","pyobj",ltc); + typeMap["seqpyobj"]= createSequenceTc("seqpyobj","seqpyobj",typeMap["pyobj"]); + composednodeMap["Bloc"]=createBloc("Bloc"); + composednodeMap["Switch"]=createSwitch("Switch"); + composednodeMap["WhileLoop"]=createWhileLoop("WhileLoop"); + composednodeMap["ForLoop"]=createForLoop("ForLoop"); + composednodeMap["ForEachLoop_double"]=createForEachLoop("ForEachLoop_double",Runtime::_tc_double); + composednodeMap["ForEachLoop_string"]=createForEachLoop("ForEachLoop_string",Runtime::_tc_string); + composednodeMap["ForEachLoop_int"]=createForEachLoop("ForEachLoop_int",Runtime::_tc_int); + composednodeMap["ForEachLoop_bool"]=createForEachLoop("ForEachLoop_bool",Runtime::_tc_bool); + composednodeMap["ForEachLoop_pyobj"]=createForEachLoop("ForEachLoop_pyobj",typeMap["pyobj"]);; ENGINE::TypeCodeStruct *t = createStructTc("","Engines/dataref"); t->addMember("ref",_tc_string); typeMap["dataref"]= t; } -RuntimeSALOME::RuntimeSALOME(long flags) +RuntimeSALOME::RuntimeSALOME(long flags, int argc, char* argv[]) { // If all flags (apart the IsPyExt flags) are unset, force them to true if ((flags - flags & RuntimeSALOME::IsPyExt) == 0) @@ -209,7 +238,7 @@ RuntimeSALOME::RuntimeSALOME(long flags) if (_usePython) _setOfImplementation.insert(PythonNode::IMPL_NAME); if (_useCorba) _setOfImplementation.insert(CORBANode::IMPL_NAME); if (_useXml) _setOfImplementation.insert(XmlNode::IMPL_NAME); - init(flags); + init(flags, argc, argv); } RuntimeSALOME::~RuntimeSALOME() @@ -221,6 +250,16 @@ RuntimeSALOME::~RuntimeSALOME() { delete (*pt).second; } + _connectionManager.ShutdownWithExit(); +} + +void RuntimeSALOME::loadModulCatalog() +{ + AutoGIL agil; + const char * SCRIPT = "from salome_kernel import list_of_catalogs_regarding_environement\n" +"import KernelModuleCatalog\n" +"KernelModuleCatalog.myModuleCatalog( list_of_catalogs_regarding_environement() )\n"; + PyRun_SimpleString(SCRIPT); } //! CORBA and Python initialization @@ -233,10 +272,12 @@ RuntimeSALOME::~RuntimeSALOME() * bit1 (UseXml) true if python nodes are needed * bit1 (UseCpp) true if C++ nodes are needed * bit1 (UseSalome) true if Salome nodes are needed + * \param argc number of command line arguments (used to initialize the Python interpreter) + * \param argv command line arguments (used to initialize the Python interpreter) * */ -void RuntimeSALOME::init(long flags) +void RuntimeSALOME::init(long flags, int argc, char* argv[]) { bool ispyext = flags & RuntimeSALOME::IsPyExt; if (_useCorba) @@ -270,7 +311,31 @@ void RuntimeSALOME::init(long flags) #else Py_InitializeEx(0); // do not install signal handlers #endif + if (argc > 0 && argv != NULL) + { + wchar_t **changed_argv = new wchar_t*[argc]; + for (int i = 0; i < argc; i++) + { + changed_argv[i] = Py_DecodeLocale(argv[i], NULL); + } + PySys_SetArgv(argc, changed_argv); + } + else + { + int pyArgc = 1; + char* pyArgv[1]; + char defaultName[] = "SALOME_YACS_RUNTIME"; + wchar_t **changed_pyArgv = new wchar_t*[pyArgc]; + pyArgv[0] = defaultName; + for (int i = 0; i < pyArgc; i++) + { + changed_pyArgv[i] = Py_DecodeLocale(pyArgv[i], NULL); + } + PySys_SetArgv(pyArgc, changed_pyArgv); + } +#if PY_VERSION_HEX < 0x03070000 PyEval_InitThreads(); /* Create (and acquire) the interpreter lock (for threads)*/ +#endif PyEval_SaveThread(); /* Release the thread state */ //here we do not have the Global Interpreter Lock } @@ -286,7 +351,7 @@ void RuntimeSALOME::init(long flags) if (PyDict_GetItemString(globals, "__builtins__") == NULL) { - PyObject *bimod = PyImport_ImportModule("__builtin__"); + PyObject *bimod = PyImport_ImportModule("builtins"); if (bimod == NULL || PyDict_SetItemString(globals, "__builtins__", bimod) != 0) Py_FatalError("can't add __builtins__ to __main__"); Py_DECREF(bimod); @@ -310,7 +375,7 @@ void RuntimeSALOME::init(long flags) { goto out; } - _api = (omniORBpyAPI*)PyCObject_AsVoidPtr(pyapi); + _api = (omniORBpyAPI*)PyCapsule_GetPointer(pyapi,"_omnipy.API"); Py_DECREF(pyapi); res=PyRun_String("\n" @@ -320,7 +385,7 @@ void RuntimeSALOME::init(long flags) "from omniORB import CORBA\n" "from omniORB import any\n" "orb = CORBA.ORB_init([], CORBA.ORB_ID)\n" - "#print sys.getrefcount(orb)\n" + "#print(sys.getrefcount(orb))\n" "try:\n" " import SALOME\n" "except:\n" @@ -402,6 +467,96 @@ void RuntimeSALOME::fini() } } +PyObject *RuntimeSALOME::launchSubProcess(const std::vector& cmds) +{ + std::ostringstream oss; oss << "from subprocess import Popen" << std::endl; + oss << "p = Popen(["; + for(auto i = 0 ; i < cmds.size() ; ++i) + { + oss << " " << "\"" << cmds[i] << "\""; + if(i < cmds.size()-1) + oss << ", "; + else + oss << " "; + } + oss << "])"; + AutoGIL agil; + AutoPyRef context = PyDict_New(); + PyDict_SetItemString( context, "__builtins__", getBuiltins() ); + std::string errorDetails; + try + { + PythonNode::ExecuteLocalInternal(oss.str().c_str(),context,errorDetails); + } + catch(const YACS::Exception& e) + { + std::cerr << e.what() << std::endl << errorDetails << std::endl; + throw e; + } + PyObject *ret = PyDict_GetItemString(context,"p"); + Py_XINCREF(ret); + Py_XINCREF(ret); + return ret; +} + +std::vector< std::pair > RuntimeSALOME::getCatalogOfComputeNodes() const +{ + CORBA::ORB_ptr orb(getOrb()); + SALOME_NamingService_Wrapper namingService; + try + { + namingService.init_orb(orb); + } + catch(SALOME_Exception& e) + { + throw Exception("RuntimeSALOME::getCatalogOfComputeNodes : Unable to contact the SALOME Naming Service"); + } + CORBA::Object_var obj(namingService.Resolve(SALOME_ResourcesManager::_ResourcesManagerNameInNS)); + if(CORBA::is_nil(obj)) + throw Exception("RuntimeSALOME::getCatalogOfComputeNodes : Unable to access to the resource manager !"); + Engines::ResourcesManager_var resManager(Engines::ResourcesManager::_narrow(obj)); + if(CORBA::is_nil(resManager)) + throw Exception("RuntimeSALOME::getCatalogOfComputeNodes : Internal error ! The entry attached to the res manager in NS does not have right type !"); + std::vector< std::pair > ret; + Engines::ResourceParameters params; + params.name = ""; + params.hostname = ""; + params.OS = ""; + params.nb_proc = 0; + params.mem_mb = 0; + params.cpu_clock = 0; + params.nb_node = 0; + params.nb_proc_per_node = 0; + params.policy = ""; + params.can_launch_batch_jobs = false; + params.can_run_containers = true; + params.componentList.length(0); + try + { + Engines::ResourceList_var resourceList; + resourceList = resManager->GetFittingResources(params); + ret.reserve(resourceList->length()); + for(int i = 0; ilength(); i++) + { + const char* resource_name = resourceList[i]; + std::string std_resource_name = resource_name; + Engines::ResourceDefinition_var resource_definition + = resManager->GetResourceDefinition(resource_name); + int nb_cores = resource_definition->nb_node * + resource_definition->nb_proc_per_node; + ret.push_back(std::pair(resource_name, nb_cores)); + } + } + catch(SALOME::SALOME_Exception& e) + { + std::string message; + message=e.details.text.in(); + throw Exception(message); + } + + return ret; +} + std::string RuntimeSALOME::getVersion() const { #ifdef YACS_DEVELOPMENT @@ -575,15 +730,19 @@ ComponentInstance* RuntimeSALOME::createComponentInstance(const std::string& nam return new SalomePythonComponent(name); else if (kind == CppComponent::KIND) return new CppComponent(name); + else if (kind == SalomeHPComponent::KIND) + return new SalomeHPComponent(name); std::string msg="Component Instance kind ("+kind+") unknown"; throw Exception(msg); } Container *RuntimeSALOME::createContainer(const std::string& kind) { - if(kind == "" || kind == SalomeComponent::KIND) + if(kind == "" || kind == SalomeContainer::KIND) return new SalomeContainer; - else if (kind == CppComponent::KIND) + if(kind==SalomeHPContainer::KIND) + return new SalomeHPContainer; + else if (kind == CppContainer::KIND) return new CppContainer; std::string msg="Container kind ("+kind+") unknown"; throw Exception(msg); @@ -614,7 +773,7 @@ InputPort * RuntimeSALOME::createInputPort(const std::string& name, { stringstream msg; msg << "Cannot create " << impl << " InputPort" ; - msg << " ("__FILE__ << ":" << __LINE__ << ")"; + msg << " (" << __FILE__ << ":" << __LINE__ << ")"; throw Exception(msg.str()); } } @@ -644,7 +803,7 @@ OutputPort * RuntimeSALOME::createOutputPort(const std::string& name, { stringstream msg; msg << "Cannot create " << impl << " OutputPort" ; - msg << " ("__FILE__ << ":" << __LINE__ << ")"; + msg << " (" << __FILE__ << ":" << __LINE__ << ")"; throw Exception(msg.str()); } } @@ -688,7 +847,7 @@ OutputDataStreamPort* RuntimeSALOME::createOutputDataStreamPort(const std::strin */ InputPort* RuntimeSALOME::adapt(InputPort* source, const std::string& impl, - TypeCode * type,bool init) throw (ConversionException) + TypeCode * type,bool init) { string imp_source=source->getNode()->getImplementation(); if(imp_source == PythonNode::IMPL_NAME) @@ -715,7 +874,7 @@ InputPort* RuntimeSALOME::adapt(InputPort* source, { stringstream msg; msg << "Cannot adapt " << imp_source << " InputPort to " << impl; - msg << " ("__FILE__ << ":" << __LINE__ << ")"; + msg << " (" << __FILE__ << ":" << __LINE__ << ")"; throw ConversionException(msg.str()); } } @@ -731,7 +890,7 @@ InputPort* RuntimeSALOME::adapt(InputPort* source, */ InputPort* RuntimeSALOME::adapt(InPropertyPort* source, const std::string& impl, - TypeCode * type,bool init) throw (ConversionException) + TypeCode * type,bool init) { return adaptNeutral((InputPort *)source,impl,type,init); } @@ -743,7 +902,7 @@ InputPort* RuntimeSALOME::adapt(InPropertyPort* source, * \return an adaptated input port of type InputCorbaPort */ InputPort* RuntimeSALOME::adaptNeutralToCorba(InputPort* inport, - TypeCode * type) throw (ConversionException) + TypeCode * type) { // BEWARE : using the generic check if(inport->edGetType()->isAdaptable(type)) @@ -768,7 +927,7 @@ InputPort* RuntimeSALOME::adaptNeutralToCorba(InputPort* inport, * \return an adaptated input port of type InputPyPort */ InputPort* RuntimeSALOME::adaptNeutralToPython(InputPort* inport, - TypeCode * type) throw (ConversionException) + TypeCode * type) { // BEWARE : using the generic check if(inport->edGetType()->isAdaptable(type)) @@ -776,6 +935,11 @@ InputPort* RuntimeSALOME::adaptNeutralToPython(InputPort* inport, //convertible type return new PyNeutral(inport); } + //last chance : an py output that is seq[objref] can be connected to a neutral input objref (P13268) + else if(type->kind()==Sequence && type->contentType()->kind()==Objref && inport->edGetType()->kind()==Objref) + { + return new PyNeutral(inport); + } //non convertible type stringstream msg; msg << "Cannot connect Python output port with type: " << type->id() ; @@ -793,7 +957,7 @@ InputPort* RuntimeSALOME::adaptNeutralToPython(InputPort* inport, * \return an input port of type InputXmlPort */ InputPort* RuntimeSALOME::adaptNeutralToXml(InputPort* inport, - TypeCode * type) throw (ConversionException) + TypeCode * type) { // BEWARE : using the generic check if(inport->edGetType()->isAdaptable(type)) @@ -818,7 +982,7 @@ InputPort* RuntimeSALOME::adaptNeutralToXml(InputPort* inport, * \return an input port of type InputCppPort */ InputPort* RuntimeSALOME::adaptNeutralToCpp(InputPort* inport, - TypeCode * type) throw (ConversionException) + TypeCode * type) { DEBTRACE("RuntimeSALOME::adaptNeutralToCpp(InputPort* inport" ); if(isAdaptableNeutralCpp(type,inport->edGetType())) @@ -846,7 +1010,7 @@ InputPort* RuntimeSALOME::adaptNeutralToCpp(InputPort* inport, */ InputPort* RuntimeSALOME::adaptNeutral(InputPort* source, const std::string& impl, - TypeCode * type,bool init) throw (ConversionException) + TypeCode * type,bool init) { if(impl == CppNode::IMPL_NAME) { @@ -885,7 +1049,7 @@ InputPort* RuntimeSALOME::adaptNeutral(InputPort* source, */ InputPort* RuntimeSALOME::adaptXmlToCorba(InputXmlPort* inport, - TypeCode * type) throw (ConversionException) + TypeCode * type) { if(isAdaptableXmlCorba(type,inport->edGetType())) { @@ -909,7 +1073,7 @@ InputPort* RuntimeSALOME::adaptXmlToCorba(InputXmlPort* inport, * \return an adaptated input port of type InputPyPort */ InputPort* RuntimeSALOME::adaptXmlToPython(InputXmlPort* inport, - TypeCode * type) throw (ConversionException) + TypeCode * type) { if(inport->edGetType()->isAdaptable(type)) { @@ -933,7 +1097,7 @@ InputPort* RuntimeSALOME::adaptXmlToPython(InputXmlPort* inport, * \return an adaptated input port of type InputPyPort */ InputPort* RuntimeSALOME::adaptXmlToCpp(InputXmlPort* inport, - TypeCode * type) throw (ConversionException) + TypeCode * type) { DEBTRACE("RuntimeSALOME::adaptXmlToCpp(InputPort* inport" ); DEBTRACE(type->kind() << " " << inport->edGetType()->kind() ); @@ -959,7 +1123,7 @@ InputPort* RuntimeSALOME::adaptXmlToCpp(InputXmlPort* inport, * \return an adaptated input port of type Neutralxxxx */ InputPort* RuntimeSALOME::adaptXmlToNeutral(InputXmlPort* inport, - TypeCode * type) throw (ConversionException) + TypeCode * type) { if(inport->edGetType()->isAdaptable(type)) { @@ -981,7 +1145,7 @@ InputPort* RuntimeSALOME::adaptXmlToNeutral(InputXmlPort* inport, * \return an adaptated input port of type Xmlxxxx */ InputPort* RuntimeSALOME::adaptXmlToXml(InputXmlPort* inport, - TypeCode * type,bool init) throw (ConversionException) + TypeCode * type,bool init) { if(init) return new ProxyPort(inport); @@ -1009,7 +1173,7 @@ InputPort* RuntimeSALOME::adaptXmlToXml(InputXmlPort* inport, InputPort* RuntimeSALOME::adapt(InputXmlPort* source, const std::string& impl, - TypeCode * type,bool init) throw (ConversionException) + TypeCode * type,bool init) { if(impl == CORBANode::IMPL_NAME) { @@ -1035,7 +1199,7 @@ InputPort* RuntimeSALOME::adapt(InputXmlPort* source, { stringstream msg; msg << "Cannot connect InputXmlPort to " << impl << " implementation"; - msg << " ("__FILE__ << ":" << __LINE__ << ")"; + msg << " (" << __FILE__ << ":" << __LINE__ << ")"; throw ConversionException(msg.str()); } } @@ -1048,7 +1212,7 @@ InputPort* RuntimeSALOME::adapt(InputXmlPort* source, * \return an adaptator port of type InputCORBAPort */ InputPort* RuntimeSALOME::adaptCorbaToCorba(InputCorbaPort* inport, - TypeCode * type) throw (ConversionException) + TypeCode * type) { if(type->isA(inport->edGetType())) { @@ -1080,7 +1244,7 @@ InputPort* RuntimeSALOME::adaptCorbaToCorba(InputCorbaPort* inport, */ InputPort* RuntimeSALOME::adaptCorbaToPython(InputCorbaPort* inport, - TypeCode * type) throw (ConversionException) + TypeCode * type) { if(inport->edGetType()->kind() == Double) { @@ -1159,7 +1323,7 @@ InputPort* RuntimeSALOME::adaptCorbaToPython(InputCorbaPort* inport, */ InputPort* RuntimeSALOME::adaptCorbaToXml(InputCorbaPort* inport, - TypeCode * type) throw (ConversionException) + TypeCode * type) { // BEWARE : using the generic check if(inport->edGetType()->isAdaptable(type)) @@ -1185,7 +1349,7 @@ InputPort* RuntimeSALOME::adaptCorbaToXml(InputCorbaPort* inport, */ InputPort* RuntimeSALOME::adaptCorbaToCpp(InputCorbaPort* inport, - TypeCode * type) throw (ConversionException) + TypeCode * type) { DEBTRACE("RuntimeSALOME::adaptCorbaToCpp(InputCorbaPort* inport" ); if(isAdaptableCorbaCpp(type,inport->edGetType())) @@ -1211,7 +1375,7 @@ InputPort* RuntimeSALOME::adaptCorbaToCpp(InputCorbaPort* inport, */ InputPort* RuntimeSALOME::adaptCorbaToNeutral(InputCorbaPort* inport, - TypeCode * type) throw (ConversionException) + TypeCode * type) { if(inport->edGetType()->kind() == Double) { @@ -1271,7 +1435,7 @@ InputPort* RuntimeSALOME::adaptCorbaToNeutral(InputCorbaPort* inport, InputPort* RuntimeSALOME::adapt(InputCorbaPort* source, const std::string& impl, - TypeCode * type,bool init) throw (ConversionException) + TypeCode * type,bool init) { if(impl == CppNode::IMPL_NAME) { @@ -1316,7 +1480,7 @@ InputPort* RuntimeSALOME::adapt(InputCorbaPort* source, */ InputPort* RuntimeSALOME::adaptPythonToPython(InputPyPort* inport, - TypeCode * type,bool init) throw (ConversionException) + TypeCode * type,bool init) { if(init) return new PyInit(inport); @@ -1346,7 +1510,7 @@ InputPort* RuntimeSALOME::adaptPythonToPython(InputPyPort* inport, */ InputPort* RuntimeSALOME::adaptPythonToCpp(InputPyPort* inport, - TypeCode * type) throw (ConversionException) + TypeCode * type) { DEBTRACE("RuntimeSALOME::adaptPythonToCpp(InputPyPort* inport" ); if(isAdaptablePyObjectCpp(type,inport->edGetType())) @@ -1372,7 +1536,7 @@ InputPort* RuntimeSALOME::adaptPythonToCpp(InputPyPort* inport, */ InputPort* RuntimeSALOME::adaptPythonToNeutral(InputPyPort* inport, - TypeCode * type) throw (ConversionException) + TypeCode * type) { if(inport->edGetType()->kind() == Double) { @@ -1430,7 +1594,7 @@ InputPort* RuntimeSALOME::adaptPythonToNeutral(InputPyPort* inport, */ InputPort* RuntimeSALOME::adaptPythonToCorba(InputPyPort* inport, - TypeCode * type) throw (ConversionException) + TypeCode * type) { if(inport->edGetType()->kind() == Double) { @@ -1508,7 +1672,7 @@ InputPort* RuntimeSALOME::adaptPythonToCorba(InputPyPort* inport, */ InputPort* RuntimeSALOME::adaptPythonToXml(InputPyPort* inport, - TypeCode * type) throw (ConversionException) + TypeCode * type) { // BEWARE : using the generic check if(inport->edGetType()->isAdaptable(type)) @@ -1537,7 +1701,7 @@ InputPort* RuntimeSALOME::adaptPythonToXml(InputPyPort* inport, InputPort* RuntimeSALOME::adapt(InputPyPort* source, const std::string& impl, - TypeCode * type,bool init) throw (ConversionException) + TypeCode * type,bool init) { if(impl == CppNode::IMPL_NAME) { @@ -1577,7 +1741,7 @@ InputPort* RuntimeSALOME::adapt(InputPyPort* source, */ InputPort* RuntimeSALOME::adaptCppToCorba(InputCppPort* inport, - TypeCode * type) throw (ConversionException) + TypeCode * type) { DEBTRACE("RuntimeSALOME::adaptCppToCorba(InputCppPort* inport)"); if(isAdaptableCppCorba(type,inport->edGetType())) @@ -1602,7 +1766,7 @@ InputPort* RuntimeSALOME::adaptCppToCorba(InputCppPort* inport, * \return an adaptated input port of type InputPyPort */ InputPort* RuntimeSALOME::adaptCppToPython(InputCppPort* inport, - TypeCode * type) throw (ConversionException) + TypeCode * type) { DEBTRACE("RuntimeSALOME::adaptCppToPython(InputCppPort* inport)"); if(isAdaptableCppPyObject(type,inport->edGetType())) @@ -1627,7 +1791,7 @@ InputPort* RuntimeSALOME::adaptCppToPython(InputCppPort* inport, * \return an adaptated input port of type InputPyPort */ InputPort* RuntimeSALOME::adaptCppToCpp(InputCppPort* inport, - TypeCode * type) throw (ConversionException) + TypeCode * type) { DEBTRACE("RuntimeSALOME::adaptCppToCpp(InputPort* inport" ); DEBTRACE(type->kind() << " " << inport->edGetType()->kind() ); @@ -1653,7 +1817,7 @@ InputPort* RuntimeSALOME::adaptCppToCpp(InputCppPort* inport, * \return an adaptated input port of type InputPyPort */ InputPort* RuntimeSALOME::adaptCppToNeutral(InputCppPort* inport, - TypeCode * type) throw (ConversionException) + TypeCode * type) { DEBTRACE("RuntimeSALOME::adaptCppToNeutral(InputPort* inport" ); DEBTRACE(type->kind() << " " << inport->edGetType()->kind() ); @@ -1673,7 +1837,7 @@ InputPort* RuntimeSALOME::adaptCppToNeutral(InputCppPort* inport, } InputPort* RuntimeSALOME::adaptCppToXml(InputCppPort* inport, - TypeCode * type) throw (ConversionException) + TypeCode * type) { DEBTRACE("RuntimeSALOME::adaptCppToXml(InputCppPort* inport" ); if(isAdaptableCppXml(type,inport->edGetType())) @@ -1702,7 +1866,7 @@ InputPort* RuntimeSALOME::adaptCppToXml(InputCppPort* inport, InputPort* RuntimeSALOME::adapt(InputCppPort* source, const std::string& impl, - TypeCode * type,bool init) throw (ConversionException) + TypeCode * type,bool init) { DEBTRACE("RuntimeSALOME::adapt(InputCppPort* source)"); if(impl == CORBANode::IMPL_NAME) @@ -1729,7 +1893,7 @@ InputPort* RuntimeSALOME::adapt(InputCppPort* source, { stringstream msg; msg << "Cannot connect InputCppPort to " << impl << " implementation"; - msg << " ("__FILE__ << ":" << __LINE__ << ")"; + msg << " (" << __FILE__ << ":" << __LINE__ << ")"; throw ConversionException(msg.str()); } } @@ -1741,22 +1905,52 @@ InputPort* RuntimeSALOME::adapt(InputCppPort* source, // return result; // } -CORBA::ORB_ptr RuntimeSALOME::getOrb() +CORBA::ORB_ptr RuntimeSALOME::getOrb() const { return _orb; } -PyObject * RuntimeSALOME::getPyOrb() +/*! + * Retrieve from custom NS the entry. Custom NS is supposed to be hosted in current process. + * This method try to emulate CORBA ns convention : "corbaname:rir:#test.my_context/Echo.Object" is converted into "Echo" + * + * See Engines::EmbeddedNamingService + */ +CORBA::Object_var RuntimeSALOME::getFromNS(const char *entry) const +{ + CORBA::Object_var ret; + std::string entryCpp(entry); + if(entryCpp.substr(0,4) == "IOR:") + { + ret = _orb->string_to_object( entry ); + } + else + { + auto pos = entryCpp.find_last_of('/'); + std::string entry1( entryCpp.substr(pos+1,std::string::npos) ); + pos = entry1.find_last_of('.'); + std::string entry2( entry1.substr(0,pos) ); + Engines::EmbeddedNamingService_var ns = GetEmbeddedNamingService(); + std::unique_ptr iorRet( ns->Resolve( entry2.c_str() ) ); + auto len = iorRet->length(); + std::unique_ptr iorTrans(new char[len+1]); iorTrans[len] = '\0'; + for(auto i = 0 ; i < len ; ++i) iorTrans[i] = (*iorRet)[i]; + ret = _orb->string_to_object(iorTrans.get()); + } + return ret; +} + +PyObject * RuntimeSALOME::getPyOrb() const { return _pyorb; } -PyObject * RuntimeSALOME::getBuiltins() +PyObject * RuntimeSALOME::getBuiltins() const { return _bltins; } -DynamicAny::DynAnyFactory_ptr RuntimeSALOME::getDynFactory() +DynamicAny::DynAnyFactory_ptr RuntimeSALOME::getDynFactory() const { return _dynFactory; } @@ -1787,6 +1981,10 @@ std::string RuntimeSALOME::convertNeutralAsString(TypeCode * type, Any *data) PyObject* ob; if(data) { + // The call to PyGILState_Ensure was moved here because there was also + // a crash when calling convertNeutralPyObject with a sequence of pyobj. + // see also the comment below. + PyGILState_STATE gstate = PyGILState_Ensure(); ob=convertNeutralPyObject(type,data); std::string s=convertPyObjectToString(ob); @@ -1795,7 +1993,7 @@ std::string RuntimeSALOME::convertNeutralAsString(TypeCode * type, Any *data) // lock. I thus added the call to PyGILState_Ensure / PyGILState_Release. It worked fine in // Python 2.6 without this call. If anyone finds the real reason of this bug and another fix, // feel free to change this code. - PyGILState_STATE gstate = PyGILState_Ensure(); + //PyGILState_STATE gstate = PyGILState_Ensure(); Py_DECREF(ob); PyGILState_Release(gstate); return s;