23 #define private public
24 #define protected public
25 #include <omniORB4/CORBA.h>
26 #include <omniORB4/internal/typecode.h>
27 #include <omniORB4/internal/corbaOrb.h>
31 #include "YACS_version.h"
62 #include "PythonCppUtils.hxx"
115 #include "SALOME_LifeCycleCORBA.hxx"
116 #include "SALOME_ResourcesManager.hxx"
117 #include "SALOME_ContainerManager.hxx"
118 #include "SALOMEconfig.h"
119 #include "SALOME_Embedded_NamingService.hxx"
120 #include CORBA_CLIENT_HEADER(SALOME_ContainerManager)
124 #include <libxml/parser.h>
125 #include <omniORB4/CORBA.h>
138 std::unique_ptr<SALOME_NamingService_Container_Abstract> RuntimeSALOME::getNS()
144 void RuntimeSALOME::setRuntime(
long flags,
int argc,
char* argv[])
146 if (! Runtime::_singleton)
149 Runtime::_singleton =
r;
152 DEBTRACE(
"RuntimeSALOME::setRuntime() done !");
157 YASSERT(RuntimeSALOME::getSingleton());
158 return dynamic_cast< RuntimeSALOME*
>(RuntimeSALOME::getSingleton());
165 RuntimeSALOME::RuntimeSALOME()
170 void RuntimeSALOME::initBuiltins()
173 std::map<std::string,TypeCode*>& typeMap=_builtinCatalog->_typeMap;
174 std::map<std::string,Node*>& nodeMap=_builtinCatalog->_nodeMap;
175 std::map<std::string,ComposedNode*>& composednodeMap=_builtinCatalog->_composednodeMap;
176 std::map<std::string,ComponentDefinition*>& componentMap=_builtinCatalog->_componentMap;
177 nodeMap[
"PyFunction"]=
new PyFuncNode(
"PyFunction");
178 nodeMap[
"PyScript"]=
new PythonNode(
"PyScript");
179 nodeMap[
"CORBANode"]=
new CORBANode(
"CORBANode");
180 nodeMap[
"XmlNode"]=
new XmlNode(
"XmlNode");
181 nodeMap[
"SalomeNode"]=
new SalomeNode(
"SalomeNode");
182 nodeMap[
"CppNode"]=
new CppNode(
"CppNode");
184 nodeMap[
"PresetNode"]=
new PresetNode(
"PresetNode");
185 nodeMap[
"OutNode"]=
new OutNode(
"OutNode");
186 nodeMap[
"StudyInNode"]=
new StudyInNode(
"StudyInNode");
187 nodeMap[
"StudyOutNode"]=
new StudyOutNode(
"StudyOutNode");
188 composednodeMap[
"OptimizerLoop"]=createOptimizerLoop(
"OptimizerLoop",
"",
"",
true);
189 typeMap[
"dblevec"]= createSequenceTc(
"dblevec",
"dblevec",_tc_double);
190 typeMap[
"intvec"]= createSequenceTc(
"intvec",
"intvec",_tc_int);
191 typeMap[
"stringvec"]= createSequenceTc(
"stringvec",
"stringvec",_tc_string);
192 typeMap[
"boolvec"]= createSequenceTc(
"boolvec",
"boolvec",_tc_bool);
193 typeMap[
"seqdblevec"]= createSequenceTc(
"seqdblevec",
"seqdblevec",typeMap[
"dblevec"]);
194 typeMap[
"seqintvec"]= createSequenceTc(
"seqintvec",
"seqintvec",typeMap[
"intvec"]);
195 typeMap[
"seqstringvec"]= createSequenceTc(
"seqstringvec",
"seqstringvec",typeMap[
"stringvec"]);
196 typeMap[
"seqboolvec"]= createSequenceTc(
"seqboolvec",
"seqboolvec",typeMap[
"boolvec"]);
197 std::list<TypeCodeObjref *> ltc;
198 typeMap[
"pyobj"]= createInterfaceTc(
"python:obj:1.0",
"pyobj",ltc);
199 typeMap[
"seqpyobj"]= createSequenceTc(
"seqpyobj",
"seqpyobj",typeMap[
"pyobj"]);
200 composednodeMap[
"Bloc"]=createBloc(
"Bloc");
201 composednodeMap[
"Switch"]=createSwitch(
"Switch");
202 composednodeMap[
"WhileLoop"]=createWhileLoop(
"WhileLoop");
203 composednodeMap[
"ForLoop"]=createForLoop(
"ForLoop");
204 composednodeMap[
"ForEachLoop_double"]=createForEachLoop(
"ForEachLoop_double",Runtime::_tc_double);
205 composednodeMap[
"ForEachLoop_string"]=createForEachLoop(
"ForEachLoop_string",Runtime::_tc_string);
206 composednodeMap[
"ForEachLoop_int"]=createForEachLoop(
"ForEachLoop_int",Runtime::_tc_int);
207 composednodeMap[
"ForEachLoop_bool"]=createForEachLoop(
"ForEachLoop_bool",Runtime::_tc_bool);
208 composednodeMap[
"ForEachLoop_pyobj"]=createForEachLoop(
"ForEachLoop_pyobj",typeMap[
"pyobj"]);;
210 t->addMember(
"ref",_tc_string);
211 typeMap[
"dataref"]=
t;
214 RuntimeSALOME::RuntimeSALOME(
long flags,
int argc,
char* argv[])
217 if ((flags - flags & RuntimeSALOME::IsPyExt) == 0)
218 flags += RuntimeSALOME::UseCorba + RuntimeSALOME::UsePython
219 + RuntimeSALOME::UseCpp + RuntimeSALOME::UseXml;
222 if (flags & RuntimeSALOME::UseSalome)
223 flags |= RuntimeSALOME::UseCorba;
226 if (flags & RuntimeSALOME::UseCorba)
227 flags |= RuntimeSALOME::UsePython;
229 _useCorba = flags & RuntimeSALOME::UseCorba;
230 _usePython = flags & RuntimeSALOME::UsePython;
231 _useCpp = flags & RuntimeSALOME::UseCpp;
232 _useXml = flags & RuntimeSALOME::UseXml;
237 if (_useCpp) _setOfImplementation.insert(CppNode::IMPL_NAME);
238 if (_usePython) _setOfImplementation.insert(PythonNode::IMPL_NAME);
239 if (_useCorba) _setOfImplementation.insert(CORBANode::IMPL_NAME);
240 if (_useXml) _setOfImplementation.insert(XmlNode::IMPL_NAME);
241 init(flags, argc, argv);
244 RuntimeSALOME::~RuntimeSALOME()
246 DEBTRACE(
"RuntimeSALOME::~RuntimeSALOME");
248 std::map<std::string, CatalogLoader*>::const_iterator pt;
249 for(pt=_catalogLoaderFactoryMap.begin();pt!=_catalogLoaderFactoryMap.end();pt++)
253 _connectionManager.ShutdownWithExit();
256 void RuntimeSALOME::loadModulCatalog()
259 const char * SCRIPT =
"from salome_kernel import list_of_catalogs_regarding_environement\n"
260 "import KernelModuleCatalog\n"
261 "KernelModuleCatalog.myModuleCatalog( list_of_catalogs_regarding_environement() )\n";
262 PyRun_SimpleString(SCRIPT);
280 void RuntimeSALOME::init(
long flags,
int argc,
char* argv[])
282 bool ispyext = flags & RuntimeSALOME::IsPyExt;
285 PortableServer::POA_var root_poa;
286 PortableServer::POAManager_var pman;
287 CORBA::Object_var obj;
288 int nbargs = 0;
char **args = 0;
289 _orb = CORBA::ORB_init (nbargs, args);
290 obj = _orb->resolve_initial_references(
"RootPOA");
291 root_poa = PortableServer::POA::_narrow(obj);
292 pman = root_poa->the_POAManager();
296 DEBTRACE(
"_orb refCount: " << ((omniOrbORB*)_orb.in())->pd_refCount);
298 obj = _orb->resolve_initial_references(
"DynAnyFactory");
299 _dynFactory = DynamicAny::DynAnyFactory::_narrow(obj);
304 DEBTRACE(
"RuntimeSALOME::init, is python extension = " << ispyext);
307 if (!Py_IsInitialized())
309 #if PY_VERSION_HEX < 0x02040000
314 if (argc > 0 && argv != NULL)
316 wchar_t **changed_argv =
new wchar_t*[argc];
317 for (
int i = 0;
i < argc;
i++)
321 PySys_SetArgv(argc, changed_argv);
327 char defaultName[] =
"SALOME_YACS_RUNTIME";
328 wchar_t **changed_pyArgv =
new wchar_t*[pyArgc];
329 pyArgv[0] = defaultName;
330 for (
int i = 0;
i < pyArgc;
i++)
334 PySys_SetArgv(pyArgc, changed_pyArgv);
336 #if PY_VERSION_HEX < 0x03070000
337 PyEval_InitThreads();
343 PyObject *mainmod,*pyapi,*res ;
345 PyGILState_STATE gstate;
346 gstate = PyGILState_Ensure();
348 mainmod = PyImport_AddModule(
"__main__");
349 globals = PyModule_GetDict(mainmod);
352 if (PyDict_GetItemString(globals,
"__builtins__") == NULL)
354 PyObject *bimod = PyImport_ImportModule(
"builtins");
355 if (bimod == NULL || PyDict_SetItemString(globals,
"__builtins__", bimod) != 0)
356 Py_FatalError(
"can't add __builtins__ to __main__");
360 _bltins = PyEval_GetBuiltins();
366 _omnipy = PyImport_ImportModule((
char*)
"_omnipy");
370 PyErr_SetString(PyExc_ImportError, (
char*)
"Cannot import _omnipy");
373 pyapi = PyObject_GetAttrString(_omnipy, (
char*)
"API");
378 _api = (omniORBpyAPI*)PyCapsule_GetPointer(pyapi,
"_omnipy.API");
381 res=PyRun_String(
"\n"
382 "from math import *\n"
384 "sys.path.insert(0,'.')\n"
385 "from omniORB import CORBA\n"
386 "from omniORB import any\n"
387 "orb = CORBA.ORB_init([], CORBA.ORB_ID)\n"
388 "#print(sys.getrefcount(orb))\n"
394 Py_file_input,globals,globals );
402 _pyorb = PyDict_GetItemString(globals,
"orb");
406 pyany = PyDict_GetItemString(globals,
"any");
410 DEBTRACE(
"_orb refCount: " << ((omniOrbORB*)_orb.in())->pd_refCount);
414 PyGILState_Release(gstate);
423 void RuntimeSALOME::fini()
427 PyGILState_STATE gstate = PyGILState_Ensure();
429 DEBTRACE(
"_orb refCount: " << ((omniOrbORB*)_orb.in())->pd_refCount);
431 PyObject *mainmod, *globals;
432 mainmod = PyImport_AddModule(
"__main__");
433 globals = PyModule_GetDict(mainmod);
437 res=PyRun_String(
"orb.destroy()\n"
439 Py_file_input,globals,globals );
445 std::map<std::string,Node*>& nodeMap=_builtinCatalog->_nodeMap;
446 delete nodeMap[
"PyFunction"];
447 delete nodeMap[
"PyScript"];
448 delete nodeMap[
"SalomePythonNode"];
449 nodeMap.erase(
"PyFunction");
450 nodeMap.erase(
"PyScript");
451 nodeMap.erase(
"SalomePythonNode");
455 DEBTRACE(
"_orb refCount: " << ((omniOrbORB*)_orb.in())->pd_refCount);
463 DEBTRACE(
"_orb refCount: " << ((omniOrbORB*)_orb.in())->pd_refCount);
470 PyObject *RuntimeSALOME::launchSubProcess(
const std::vector<std::string>& cmds)
472 std::ostringstream oss; oss <<
"from subprocess import Popen" << std::endl;
473 oss <<
"p = Popen([";
474 for(
auto i = 0 ;
i < cmds.size() ; ++
i)
476 oss <<
" " <<
"\"" << cmds[
i] <<
"\"";
477 if(
i < cmds.size()-1)
484 AutoPyRef context = PyDict_New();
485 PyDict_SetItemString( context,
"__builtins__", getBuiltins() );
486 std::string errorDetails;
489 PythonNode::ExecuteLocalInternal(oss.str().c_str(),context,errorDetails);
493 std::cerr << e.
what() << std::endl << errorDetails << std::endl;
496 PyObject *ret = PyDict_GetItemString(context,
"p");
502 std::vector< std::pair<std::string,int> > RuntimeSALOME::getCatalogOfComputeNodes()
const
504 CORBA::ORB_ptr
orb(getOrb());
510 catch(SALOME_Exception& e)
512 throw Exception(
"RuntimeSALOME::getCatalogOfComputeNodes : Unable to contact the SALOME Naming Service");
514 CORBA::Object_var obj(namingService.
Resolve(SALOME_ResourcesManager::_ResourcesManagerNameInNS));
515 if(CORBA::is_nil(obj))
516 throw Exception(
"RuntimeSALOME::getCatalogOfComputeNodes : Unable to access to the resource manager !");
517 Engines::ResourcesManager_var resManager(Engines::ResourcesManager::_narrow(obj));
518 if(CORBA::is_nil(resManager))
519 throw Exception(
"RuntimeSALOME::getCatalogOfComputeNodes : Internal error ! The entry attached to the res manager in NS does not have right type !");
520 std::vector< std::pair<std::string,int> > ret;
521 Engines::ResourceParameters params;
523 params.hostname =
"";
527 params.cpu_clock = 0;
529 params.nb_proc_per_node = 0;
531 params.can_launch_batch_jobs =
false;
532 params.can_run_containers =
true;
533 params.componentList.length(0);
536 Engines::ResourceList_var resourceList;
537 resourceList = resManager->GetFittingResources(params);
538 ret.reserve(resourceList->length());
539 for(
int i = 0;
i<resourceList->length();
i++)
541 const char* resource_name = resourceList[
i];
542 std::string std_resource_name = resource_name;
543 Engines::ResourceDefinition_var resource_definition
544 = resManager->GetResourceDefinition(resource_name);
545 int nb_cores = resource_definition->nb_node *
546 resource_definition->nb_proc_per_node;
547 ret.push_back(std::pair<std::string,int>(resource_name, nb_cores));
550 catch(SALOME::SALOME_Exception& e)
553 message=e.details.text.in();
560 std::string RuntimeSALOME::getVersion()
const
562 #ifdef YACS_DEVELOPMENT
563 return CORBA::string_dup(YACS_VERSION_STR
"dev");
565 return CORBA::string_dup(YACS_VERSION_STR);
569 Proc* RuntimeSALOME::createProc(
const std::string& name)
574 TypeCode * RuntimeSALOME::createInterfaceTc(
const std::string&
id,
const std::string& name,
575 std::list<TypeCodeObjref *> ltc)
578 if(
id ==
"") myName =
"IDL:" + name +
":1.0";
580 return TypeCode::interfaceTc(myName.c_str(),name.c_str(),ltc);
583 TypeCode * RuntimeSALOME::createSequenceTc(
const std::string&
id,
584 const std::string& name,
587 return TypeCode::sequenceTc(
id.c_str(),name.c_str(),content);
590 TypeCodeStruct * RuntimeSALOME::createStructTc(
const std::string&
id,
const std::string& name)
593 if(
id ==
"") myName =
"IDL:" + name +
":1.0";
595 return (
TypeCodeStruct *)TypeCode::structTc(myName.c_str(),name.c_str());
598 Bloc* RuntimeSALOME::createBloc(
const std::string& name)
600 return new Bloc(name);
603 WhileLoop* RuntimeSALOME::createWhileLoop(
const std::string& name)
608 ForLoop* RuntimeSALOME::createForLoop(
const std::string& name)
613 OptimizerLoop* RuntimeSALOME::createOptimizerLoop(
const std::string& name,
const std::string& algLib,
const std::string& factoryName,
614 bool algInitOnFile,
const std::string& kind,
Proc * procForTypes)
622 DataNode* RuntimeSALOME::createInDataNode(
const std::string& kind,
const std::string& name)
630 else if(kind ==
"study" )
634 std::string msg=
"DataNode kind ("+kind+
") unknown";
638 DataNode* RuntimeSALOME::createOutDataNode(
const std::string& kind,
const std::string& name)
644 else if(kind ==
"study" )
649 std::string msg=
"OutDataNode kind ("+kind+
") unknown";
653 InlineFuncNode* RuntimeSALOME::createFuncNode(
const std::string& kind,
const std::string& name)
656 if(kind ==
"" || kind == SalomeNode::KIND || kind == PythonNode::KIND)
661 if(kind == DistributedPythonNode::KIND)
663 std::string msg=
"FuncNode kind ("+kind+
") unknown";
667 InlineNode* RuntimeSALOME::createScriptNode(
const std::string& kind,
const std::string& name)
670 if(kind ==
"" || kind == SalomeNode::KIND || kind == PythonNode::KIND)
675 std::string msg=
"ScriptNode kind ("+kind+
") unknown";
679 ServiceNode* RuntimeSALOME::createRefNode(
const std::string& kind,
const std::string& name)
682 if(kind ==
"" || kind == SalomeNode::KIND || kind == CORBANode::KIND)
687 else if(kind == XmlNode::KIND)
692 std::string msg=
"RefNode kind ("+kind+
") unknown";
696 ServiceNode* RuntimeSALOME::createCompoNode(
const std::string& kind,
const std::string& name)
699 if(kind ==
"" || kind == SalomeNode::KIND )
704 else if (kind == CppNode::KIND)
709 std::string msg=
"CompoNode kind ("+kind+
") unknown";
713 ServiceInlineNode *RuntimeSALOME::createSInlineNode(
const std::string& kind,
const std::string& name)
715 if(kind ==
"" || kind == SalomeNode::KIND )
717 std::string msg=
"CompoNode kind ("+kind+
") unknown";
722 const std::string& kind)
725 if(kind ==
"" || kind == SalomeComponent::KIND)
727 else if(kind == CORBAComponent::KIND)
729 else if(kind == SalomePythonComponent::KIND)
731 else if (kind == CppComponent::KIND)
733 else if (kind == SalomeHPComponent::KIND)
735 std::string msg=
"Component Instance kind ("+kind+
") unknown";
739 Container *RuntimeSALOME::createContainer(
const std::string& kind)
741 if(kind ==
"" || kind == SalomeContainer::KIND)
743 if(kind==SalomeHPContainer::KIND)
745 else if (kind == CppContainer::KIND)
747 std::string msg=
"Container kind ("+kind+
") unknown";
751 InputPort * RuntimeSALOME::createInputPort(
const std::string& name,
752 const std::string& impl,
756 if(impl == CppNode::IMPL_NAME)
760 else if(impl == PythonNode::IMPL_NAME)
764 else if(impl == CORBANode::IMPL_NAME)
768 else if(impl == XmlNode::IMPL_NAME)
775 msg <<
"Cannot create " << impl <<
" InputPort" ;
776 msg <<
" (" << __FILE__ <<
":" << __LINE__ <<
")";
781 OutputPort * RuntimeSALOME::createOutputPort(
const std::string& name,
782 const std::string& impl,
786 if(impl == CppNode::IMPL_NAME)
790 else if(impl == PythonNode::IMPL_NAME)
794 else if(impl == CORBANode::IMPL_NAME)
798 else if(impl == XmlNode::IMPL_NAME)
805 msg <<
"Cannot create " << impl <<
" OutputPort" ;
806 msg <<
" (" << __FILE__ <<
":" << __LINE__ <<
")";
849 const std::string& impl,
853 if(imp_source == PythonNode::IMPL_NAME)
857 else if(imp_source == CppNode::IMPL_NAME)
861 else if(imp_source == CORBANode::IMPL_NAME)
865 else if(imp_source == XmlNode::IMPL_NAME)
869 else if(imp_source == Runtime::RUNTIME_ENGINE_INTERACTION_IMPL_NAME)
871 return adaptNeutral(source,impl,type,init);
876 msg <<
"Cannot adapt " << imp_source <<
" InputPort to " << impl;
877 msg <<
" (" << __FILE__ <<
":" << __LINE__ <<
")";
892 const std::string& impl,
895 return adaptNeutral((
InputPort *)source,impl,type,init);
915 msg <<
"Cannot connect Corba output port with type: " << type->
id() ;
916 msg <<
" to Neutral input port " << inport->
getName() <<
" with type: " << inport->
edGetType()->
id();
918 msg <<
" ("<<__FILE__ <<
":" << __LINE__<<
")";
945 msg <<
"Cannot connect Python output port with type: " << type->
id() ;
946 msg <<
" to Neutral input port " << inport->
getName() <<
" with type: " << inport->
edGetType()->
id();
948 msg <<
" ("<<__FILE__ <<
":" << __LINE__<<
")";
970 msg <<
"Cannot connect Xml output port with type: " << type->
id() ;
971 msg <<
" to Neutral input port " << inport->
getName() <<
" with type: " << inport->
edGetType()->
id();
973 msg <<
" ("<<__FILE__ <<
":" << __LINE__<<
")";
987 DEBTRACE(
"RuntimeSALOME::adaptNeutralToCpp(InputPort* inport" );
995 msg <<
"Cannot connect Cpp output port with type: " << type->
id() ;
996 msg <<
" to Neutral input port " << inport->
getName() <<
" with type: " << inport->
edGetType()->
id();
998 msg <<
" ("<<__FILE__ <<
":" << __LINE__<<
")";
1012 const std::string& impl,
1015 if(impl == CppNode::IMPL_NAME)
1017 return adaptNeutralToCpp(source,type);
1019 else if(impl == PythonNode::IMPL_NAME)
1021 return adaptNeutralToPython(source,type);
1023 else if(impl == CORBANode::IMPL_NAME)
1025 return adaptNeutralToCorba(source,type);
1027 else if(impl == XmlNode::IMPL_NAME )
1029 return adaptNeutralToXml(source,type);
1031 else if(impl == Runtime::RUNTIME_ENGINE_INTERACTION_IMPL_NAME)
1039 msg <<
"Cannot connect InputPort : unknown implementation " << impl;
1040 msg <<
" (" <<__FILE__ <<
":" <<__LINE__ <<
")";
1061 msg <<
"Cannot connect Corba output port with type: " << type->
id() ;
1062 msg <<
" to Xml input port " << inport->
getName() <<
" with type: " << inport->
edGetType()->
id();
1064 msg <<
" ("<<__FILE__ <<
":" << __LINE__<<
")";
1081 return new PyXml(inport);
1085 msg <<
"Cannot connect Python output port with type: " << type->
id() ;
1086 msg <<
" to Xml input port " << inport->
getName() <<
" with type: " << inport->
edGetType()->
id();
1088 msg <<
" ("<<__FILE__ <<
":" << __LINE__<<
")";
1102 DEBTRACE(
"RuntimeSALOME::adaptXmlToCpp(InputPort* inport" );
1107 return new CppXml(inport);
1111 msg <<
"Cannot connect Cpp output port with type: " << type->
id() ;
1112 msg <<
" to Xml input port " << inport->
getName() <<
" with type: " << inport->
edGetType()->
id();
1114 msg <<
" ("<<__FILE__ <<
":" << __LINE__<<
")";
1135 msg <<
"Cannot connect Xml InputPort to OutputNeutralPort : " ;
1136 msg <<
"(" <<__FILE__ <<
":" <<__LINE__<<
")";
1157 msg <<
"Cannot connect Xml output port with type: " << type->
id() ;
1158 msg <<
" to Xml input port " << inport->
getName() <<
" with type: " << inport->
edGetType()->
id();
1160 msg <<
" ("<<__FILE__ <<
":" << __LINE__<<
")";
1175 const std::string& impl,
1178 if(impl == CORBANode::IMPL_NAME)
1180 return adaptXmlToCorba(source,type);
1182 else if(impl == PythonNode::IMPL_NAME)
1184 return adaptXmlToPython(source,type);
1186 else if(impl == CppNode::IMPL_NAME)
1188 return adaptXmlToCpp(source,type);
1190 else if(impl == XmlNode::IMPL_NAME )
1192 return adaptXmlToXml(source,type,init);
1194 else if(impl == Runtime::RUNTIME_ENGINE_INTERACTION_IMPL_NAME)
1196 return adaptXmlToNeutral(source,type);
1201 msg <<
"Cannot connect InputXmlPort to " << impl <<
" implementation";
1202 msg <<
" (" << __FILE__ <<
":" << __LINE__ <<
")";
1231 msg <<
"Cannot connect Corba output port with type: " << type->
id() ;
1232 msg <<
" to CORBA input port " << inport->
getName() <<
" with type: " << inport->
edGetType()->
id();
1234 msg <<
" ("<<__FILE__ <<
":" << __LINE__<<
")";
1274 msg <<
"Cannot connect Python output port with type: " << type->
id() ;
1275 msg <<
" to CORBA input port " << inport->
getName() <<
" with incompatible objref type: " << inport->
edGetType()->
id();
1276 msg <<
" (" << __FILE__ <<
":" <<__LINE__ <<
")";
1289 msg <<
"Cannot convert this sequence type " ;
1290 msg << __FILE__ <<
":" <<__LINE__;
1303 msg <<
"Cannot convert this struct type " << type->
id() <<
" to " << inport->
edGetType()->
id();
1304 msg << __FILE__ <<
":" <<__LINE__;
1310 msg <<
"Cannot connect Python output port with type: " << type->
id() ;
1311 msg <<
" to CORBA input port " << inport->
getName() <<
" with type: " << inport->
edGetType()->
id();
1313 msg <<
" ("<<__FILE__ <<
":" << __LINE__<<
")";
1336 msg <<
"Cannot connect Xml output port with type: " << type->
id() ;
1337 msg <<
" to Corba input port " << inport->
getName() <<
" with type: " << inport->
edGetType()->
id();
1339 msg <<
" ("<<__FILE__ <<
":" << __LINE__<<
")";
1354 DEBTRACE(
"RuntimeSALOME::adaptCorbaToCpp(InputCorbaPort* inport" );
1362 msg <<
"Cannot connect Cpp output port with type: " << type->
id() ;
1363 msg <<
" to Corba input port " << inport->
getName() <<
" with type: " << inport->
edGetType()->
id();
1365 msg <<
" ("<<__FILE__ <<
":" << __LINE__<<
")";
1407 msg <<
"Cannot convert this sequence type " ;
1408 msg << __FILE__ <<
":" <<__LINE__;
1419 msg <<
"Cannot connect Neutral output port with type: " << type->
id() ;
1420 msg <<
" to Corba input port " << inport->
getName() <<
" with type: " << inport->
edGetType()->
id();
1422 msg <<
" ("<<__FILE__ <<
":" << __LINE__<<
")";
1437 const std::string& impl,
1440 if(impl == CppNode::IMPL_NAME)
1442 return adaptCorbaToCpp(source,type);
1444 else if(impl == PythonNode::IMPL_NAME)
1446 return adaptCorbaToPython(source,type);
1448 else if(impl == CORBANode::IMPL_NAME)
1451 return adaptCorbaToCorba(source,type);
1453 return adaptCorbaToCorba(source,type);
1455 else if(impl == XmlNode::IMPL_NAME )
1457 return adaptCorbaToXml(source,type);
1459 else if(impl == Runtime::RUNTIME_ENGINE_INTERACTION_IMPL_NAME)
1461 return adaptCorbaToNeutral(source,type);
1466 msg <<
"Cannot connect InputCorbaPort : unknown implementation " ;
1467 msg << __FILE__ <<
":" <<__LINE__;
1486 return new PyInit(inport);
1497 msg <<
"Cannot connect Python output port with type: " << type->
id() ;
1498 msg <<
" to Python input port " << inport->
getName() <<
" with type: " << inport->
edGetType()->
id();
1500 msg <<
" ("<<__FILE__ <<
":" << __LINE__<<
")";
1515 DEBTRACE(
"RuntimeSALOME::adaptPythonToCpp(InputPyPort* inport" );
1519 return new CppPy(inport);
1523 msg <<
"Cannot connect Cpp output port with type: " << type->
id() ;
1524 msg <<
" to Python input port " << inport->
getName() <<
" with type: " << inport->
edGetType()->
id();
1526 msg <<
" ("<<__FILE__ <<
":" << __LINE__<<
")";
1568 msg <<
"Cannot convert this sequence type " ;
1569 msg << __FILE__ <<
":" <<__LINE__;
1580 msg <<
"Cannot connect Neutral output port with type: " << type->
id() ;
1581 msg <<
" to Python input port " << inport->
getName() <<
" with type: " << inport->
edGetType()->
id();
1583 msg <<
" ("<<__FILE__ <<
":" << __LINE__<<
")";
1624 msg <<
"Cannot connect InputCorbaPort : incompatible objref types " << type->
id() <<
" " << inport->
edGetType()->
id();
1625 msg <<
" " << __FILE__ <<
":" <<__LINE__;
1638 msg <<
"Cannot convert this sequence type " ;
1639 msg << __FILE__ <<
":" <<__LINE__;
1652 msg <<
"Cannot convert this struct type " << type->
id() <<
" to " << inport->
edGetType()->
id();
1653 msg <<
" " << __FILE__ <<
":" <<__LINE__;
1659 msg <<
"Cannot connect Corba output port with type: " << type->
id() ;
1660 msg <<
" to Python input port " << inport->
getName() <<
" with type: " << inport->
edGetType()->
id();
1662 msg <<
" ("__FILE__ <<
":" << __LINE__ <<
")";
1685 msg <<
"Cannot connect Xml output port with type: " << type->
id() ;
1686 msg <<
" to Python input port " << inport->
getName() <<
" with type: " << inport->
edGetType()->
id();
1688 msg <<
" ("<<__FILE__ <<
":" << __LINE__<<
")";
1703 const std::string& impl,
1706 if(impl == CppNode::IMPL_NAME)
1708 return adaptPythonToCpp(source,type);
1710 else if(impl == PythonNode::IMPL_NAME)
1712 return adaptPythonToPython(source,type,init);
1714 else if(impl == CORBANode::IMPL_NAME)
1716 return adaptPythonToCorba(source,type);
1718 else if(impl == Runtime::RUNTIME_ENGINE_INTERACTION_IMPL_NAME)
1720 return adaptPythonToNeutral(source,type);
1722 else if(impl == XmlNode::IMPL_NAME)
1724 return adaptPythonToXml(source,type);
1729 msg <<
"Cannot connect InputPyPort : unknown implementation " << impl;
1730 msg <<
" ("<<__FILE__ <<
":" << __LINE__<<
")";
1746 DEBTRACE(
"RuntimeSALOME::adaptCppToCorba(InputCppPort* inport)");
1754 msg <<
"Cannot connect Corba output port with type: " << type->
id() ;
1755 msg <<
" to Cpp input port " << inport->
getName() <<
" with type: " << inport->
edGetType()->
id();
1757 msg <<
" ("<<__FILE__ <<
":" << __LINE__<<
")";
1771 DEBTRACE(
"RuntimeSALOME::adaptCppToPython(InputCppPort* inport)");
1775 return new PyCpp(inport);
1779 msg <<
"Cannot connect Python output port with type: " << type->
id() ;
1780 msg <<
" to Cpp input port " << inport->
getName() <<
" with type: " << inport->
edGetType()->
id();
1782 msg <<
" ("<<__FILE__ <<
":" << __LINE__<<
")";
1796 DEBTRACE(
"RuntimeSALOME::adaptCppToCpp(InputPort* inport" );
1801 return new CppCpp(inport);
1805 msg <<
"Cannot connect Cpp output port with type: " << type->
id() ;
1806 msg <<
" to Cpp input port " << inport->
getName() <<
" with type: " << inport->
edGetType()->
id();
1808 msg <<
" ("<<__FILE__ <<
":" << __LINE__<<
")";
1822 DEBTRACE(
"RuntimeSALOME::adaptCppToNeutral(InputPort* inport" );
1831 msg <<
"Cannot connect Neutral output port with type: " << type->
id() ;
1832 msg <<
" to Cpp input port " << inport->
getName() <<
" with type: " << inport->
edGetType()->
id();
1834 msg <<
" ("<<__FILE__ <<
":" << __LINE__<<
")";
1842 DEBTRACE(
"RuntimeSALOME::adaptCppToXml(InputCppPort* inport" );
1846 return new XmlCpp(inport);
1850 msg <<
"Cannot connect Xml output port with type: " << type->
id() ;
1851 msg <<
" to Cpp input port " << inport->
getName() <<
" with type: " << inport->
edGetType()->
id();
1853 msg <<
" ("<<__FILE__ <<
":" << __LINE__<<
")";
1868 const std::string& impl,
1871 DEBTRACE(
"RuntimeSALOME::adapt(InputCppPort* source)");
1872 if(impl == CORBANode::IMPL_NAME)
1874 return adaptCppToCorba(source,type);
1876 else if(impl == PythonNode::IMPL_NAME)
1878 return adaptCppToPython(source,type);
1880 else if(impl == XmlNode::IMPL_NAME)
1882 return adaptCppToXml(source,type);
1884 else if(impl == CppNode::IMPL_NAME)
1886 return adaptCppToCpp(source, type);
1888 else if(impl == Runtime::RUNTIME_ENGINE_INTERACTION_IMPL_NAME)
1890 return adaptCppToNeutral(source, type);
1895 msg <<
"Cannot connect InputCppPort to " << impl <<
" implementation";
1896 msg <<
" (" << __FILE__ <<
":" << __LINE__ <<
")";
1908 CORBA::ORB_ptr RuntimeSALOME::getOrb()
const
1919 CORBA::Object_var RuntimeSALOME::getFromNS(
const char *entry)
const
1921 CORBA::Object_var ret;
1922 std::string entryCpp(entry);
1923 if(entryCpp.substr(0,4) ==
"IOR:")
1925 ret = _orb->string_to_object( entry );
1929 auto pos = entryCpp.find_last_of(
'/');
1930 std::string entry1( entryCpp.substr(pos+1,std::string::npos) );
1931 pos = entry1.find_last_of(
'.');
1932 std::string entry2( entry1.substr(0,pos) );
1933 Engines::EmbeddedNamingService_var ns = GetEmbeddedNamingService();
1934 std::unique_ptr<Engines::IORType> iorRet( ns->Resolve( entry2.c_str() ) );
1935 auto len = iorRet->length();
1936 std::unique_ptr<char[]> iorTrans(
new char[len+1]); iorTrans[len] =
'\0';
1937 for(
auto i = 0 ;
i < len ; ++
i) iorTrans[
i] = (*iorRet)[
i];
1938 ret = _orb->string_to_object(iorTrans.get());
1943 PyObject * RuntimeSALOME::getPyOrb()
const
1948 PyObject * RuntimeSALOME::getBuiltins()
const
1953 DynamicAny::DynAnyFactory_ptr RuntimeSALOME::getDynFactory()
const
1958 PyObject * RuntimeSALOME::get_omnipy()
1963 omniORBpyAPI* RuntimeSALOME::getApi()
1975 return (
void *)Py_None;
1979 std::string RuntimeSALOME::convertNeutralAsString(
TypeCode * type,
Any *data)
1987 PyGILState_STATE gstate = PyGILState_Ensure();
1998 PyGILState_Release(gstate);
2012 PyObject* RuntimeSALOME::convertStringToPyObject(
const std::string& s)
2017 PyGILState_STATE gstate = PyGILState_Ensure();
2018 mainmod = PyImport_AddModule(
"__main__");
2019 globals = PyModule_GetDict(mainmod);
2020 PyObject* d = PyDict_New();
2022 ob= PyRun_String( s.c_str(), Py_eval_input, globals, d);
2029 PySys_SetObject((
char *)
"stderr", new_stderr);
2031 PySys_SetObject((
char *)
"stderr", PySys_GetObject((
char *)
"__stderr__"));
2032 Py_DECREF(new_stderr);
2033 PyGILState_Release(gstate);
2036 PyGILState_Release(gstate);
static wchar_t * Py_DecodeLocale(const char *arg, size_t *size)
#define YASSERT(val)
YASSERT macro is always defined, used like assert, but throw a YACS::Exception instead of abort.
void init_orb(CORBA::ORB_ptr orb=0) override
CORBA::Object_ptr Resolve(const char *Path) override
: Interface for management of storage of data formated dynamically in its TypeCode....
Composed node to group elementary and composed nodes.
Class for CORBA component instance.
Class for CORBA Service Node.
Base class for all component instances.
Class for conversion from CORBA Output port to CORBA Input port.
Class for conversion from CORBA Output port to Python Input port.
Class for conversion from CORBA Output port to Python Input port.
Class for conversion from CORBA Output port to Python Input port.
Class for conversion from CORBA Output port to Python Input port.
Class for conversion from CORBA Output port to Python Input port.
Class for conversion from CORBA Output port to Python Input port.
Class for conversion of struct objects from CORBA Output port to Python Input port.
Class for conversion from C++ Output port to C++ Input port.
Class for C++ Nodes (in process component)
Class for data parameters specification.
TypeCode * edGetType() const
std::string getName() const
InputPort * edGetNbOfBranchesPort()
class for Input Property Ports
Class for calculation node (function) inlined (and executed) in the schema.
Class for calculation node (script) inlined (and executed) in the schema.
Class for conversion from Neutral Output port to Xml Input port.
Class for initialization of a Neutral port with YACS::ENGINE::Any* object.
Class for conversion from Neutral Output port to XML Input port.
Base class for all nodes.
std::string getImplementation() const
class to build optimization loops
Class for Output Calcium DataStream Ports.
Class for XML Output Ports.
Base class for all schema objects.
Base class for Proxy Input Ports.
Class for Salome component instance.
Class for Salome component Service Node.
class to build optimization loops
Class for calculation node associated with a component service.
Base class for all type objects.
virtual const char * id() const
virtual const TypeCode * contentType() const
virtual int isA(const char *repositoryId) const
virtual int isAdaptable(const TypeCode *tc) const
Check if this TypeCode is adaptable to a given TypeCode (tc)
virtual const char * shortName() const
const char * what(void) const noexcept
int isAdaptableCppPyObject(const TypeCode *t1, const TypeCode *t2)
std::string convertPyObjectToString(PyObject *ob)
int isAdaptableCorbaCorba(const TypeCode *t1, const TypeCode *t2)
YACSRUNTIMESALOME_EXPORT RuntimeSALOME * getSALOMERuntime()
int isAdaptableCppCorba(const TypeCode *t1, const TypeCode *t2)
int isAdaptableCorbaNeutral(const TypeCode *t1, const TypeCode *t2)
int isAdaptableCppXml(const TypeCode *t1, const TypeCode *t2)
PyObject * newPyStdOut(std::string &out)
int isAdaptablePyObjectCpp(const TypeCode *t1, const TypeCode *t2)
int isAdaptablePyObjectCorba(const TypeCode *t1, const TypeCode *t2)
int isAdaptablePyObjectPyObject(const TypeCode *t1, const TypeCode *t2)
int isAdaptableCorbaPyObject(const TypeCode *t1, const TypeCode *t2)
int isAdaptableCorbaCpp(const TypeCode *t1, const TypeCode *t2)
PyObject * convertNeutralPyObject(const TypeCode *t, YACS::ENGINE::Any *data)
int isAdaptableXmlCorba(const TypeCode *t1, const TypeCode *t2)
int isAdaptableNeutralCpp(const TypeCode *t1, const TypeCode *t2)
int isAdaptablePyObjectNeutral(const TypeCode *t1, const TypeCode *t2)
def adapt(obj, protocol, alternate=AdaptationError)