X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2Fruntime%2FRuntimeSALOME.cxx;h=cfabfd4796475f75022861af6347e90949dfd6df;hb=0716fd562e4f709b42f40ce827a9ca02ac70634f;hp=58e5e8e504cc69a5066ac71237fdc590d02c295c;hpb=5e3d4c34b008ce0726db84073c523ef58441a3c5;p=modules%2Fyacs.git diff --git a/src/runtime/RuntimeSALOME.cxx b/src/runtime/RuntimeSALOME.cxx index 58e5e8e50..cfabfd479 100644 --- a/src/runtime/RuntimeSALOME.cxx +++ b/src/runtime/RuntimeSALOME.cxx @@ -1,4 +1,4 @@ -// Copyright (C) 2006-2014 CEA/DEN, EDF R&D +// Copyright (C) 2006-2016 CEA/DEN, EDF R&D // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public @@ -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 @@ -110,6 +112,12 @@ #ifdef SALOME_KERNEL #include "SALOME_NamingService.hxx" #include "SALOME_LifeCycleCORBA.hxx" +#include "SALOME_NamingService.hxx" +#include "SALOME_ResourcesManager.hxx" +#include "SALOME_ContainerManager.hxx" +#include "SALOMEconfig.h" +#include CORBA_CLIENT_HEADER(SALOME_ContainerManager) + #endif #include @@ -137,8 +145,8 @@ void RuntimeSALOME::setRuntime(long flags, int argc, char* argv[]) // singleton RuntimeSALOME* YACS::ENGINE::getSALOMERuntime() { - YASSERT(Runtime::_singleton); - return dynamic_cast< RuntimeSALOME* >(Runtime::_singleton); + YASSERT(RuntimeSALOME::getSingleton()); + return dynamic_cast< RuntimeSALOME* >(RuntimeSALOME::getSingleton()); } /** @@ -179,6 +187,16 @@ 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; @@ -275,14 +293,26 @@ void RuntimeSALOME::init(long flags, int argc, char* argv[]) Py_InitializeEx(0); // do not install signal handlers #endif if (argc > 0 && argv != NULL) - PySys_SetArgv(argc, argv); + { + 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; - PySys_SetArgv(pyArgc, pyArgv); + for (int i = 0; i < pyArgc; i++) + { + changed_pyArgv[i] = Py_DecodeLocale(pyArgv[i], NULL); + } + PySys_SetArgv(pyArgc, changed_pyArgv); } PyEval_InitThreads(); /* Create (and acquire) the interpreter lock (for threads)*/ PyEval_SaveThread(); /* Release the thread state */ @@ -300,7 +330,7 @@ void RuntimeSALOME::init(long flags, int argc, char* argv[]) 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); @@ -324,7 +354,7 @@ void RuntimeSALOME::init(long flags, int argc, char* argv[]) { goto out; } - _api = (omniORBpyAPI*)PyCObject_AsVoidPtr(pyapi); + _api = (omniORBpyAPI*)PyCapsule_GetPointer(pyapi,"_omnipy.API"); Py_DECREF(pyapi); res=PyRun_String("\n" @@ -334,7 +364,7 @@ void RuntimeSALOME::init(long flags, int argc, char* argv[]) "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" @@ -416,6 +446,44 @@ void RuntimeSALOME::fini() } } +std::vector< std::pair > RuntimeSALOME::getCatalogOfComputeNodes() const +{ + CORBA::ORB_ptr orb(getOrb()); + SALOME_NamingService namingService; + try + { + namingService.init_orb(orb); + } + catch(SALOME_Exception& e) + { + throw Exception("SalomeContainerToolsSpreadOverTheResDecorator::getParameters : Unable to contact the SALOME Naming Service"); + } + CORBA::Object_var obj(namingService.Resolve(SALOME_ResourcesManager::_ResourcesManagerNameInNS)); + if(CORBA::is_nil(obj)) + throw Exception("SalomeContainerToolsSpreadOverTheResDecorator::getParameters : Unable to access to the resource manager !"); + Engines::ResourcesManager_var resManager(Engines::ResourcesManager::_narrow(obj)); + if(CORBA::is_nil(resManager)) + throw Exception("SalomeContainerToolsSpreadOverTheResDecorator::getParameters : Internal error ! The entry attached to the res manager in NS does not have right type !"); + std::vector< std::pair > ret; + { + Engines::ResourceList *rl(0); + Engines::IntegerList *il(0); + resManager->ListAllAvailableResources(rl,il); + int sz(rl->length()); + if(il->length()!=sz) + throw Exception("SalomeContainerToolsSpreadOverTheResDecorator::getParameters : Internal error ! Invalid size !"); + ret.resize(sz); + for(int i=0;i(s,(*il)[i]); + } + delete rl; + delete il; + } + return ret; +} + std::string RuntimeSALOME::getVersion() const { #ifdef YACS_DEVELOPMENT @@ -632,7 +700,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()); } } @@ -662,7 +730,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()); } } @@ -733,7 +801,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()); } } @@ -794,6 +862,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() ; @@ -1053,7 +1126,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()); } } @@ -1747,7 +1820,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()); } } @@ -1759,22 +1832,22 @@ InputPort* RuntimeSALOME::adapt(InputCppPort* source, // return result; // } -CORBA::ORB_ptr RuntimeSALOME::getOrb() +CORBA::ORB_ptr RuntimeSALOME::getOrb() const { return _orb; } -PyObject * RuntimeSALOME::getPyOrb() +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; } @@ -1805,6 +1878,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); @@ -1813,7 +1890,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;