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(
bool isFinalizingPython)
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");
453 if( isFinalizingPython )
456 DEBTRACE(
"_orb refCount: " << ((omniOrbORB*)_orb.in())->pd_refCount);
464 DEBTRACE(
"_orb refCount: " << ((omniOrbORB*)_orb.in())->pd_refCount);
471 PyObject *RuntimeSALOME::launchSubProcess(
const std::vector<std::string>& cmds)
473 std::ostringstream oss; oss <<
"from subprocess import Popen" << std::endl;
474 oss <<
"p = Popen([";
475 for(
auto i = 0 ;
i < cmds.size() ; ++
i)
477 oss <<
" " <<
"\"" << cmds[
i] <<
"\"";
478 if(
i < cmds.size()-1)
485 AutoPyRef context = PyDict_New();
486 PyDict_SetItemString( context,
"__builtins__", getBuiltins() );
487 std::string errorDetails;
490 PythonNode::ExecuteLocalInternal(oss.str().c_str(),context,errorDetails);
494 std::cerr << e.
what() << std::endl << errorDetails << std::endl;
497 PyObject *ret = PyDict_GetItemString(context,
"p");
503 std::vector< std::pair<std::string,int> > RuntimeSALOME::getCatalogOfComputeNodes()
const
505 CORBA::ORB_ptr
orb(getOrb());
511 catch(SALOME_Exception& e)
513 throw Exception(
"RuntimeSALOME::getCatalogOfComputeNodes : Unable to contact the SALOME Naming Service");
515 CORBA::Object_var obj(namingService.
Resolve(SALOME_ResourcesManager::_ResourcesManagerNameInNS));
516 if(CORBA::is_nil(obj))
517 throw Exception(
"RuntimeSALOME::getCatalogOfComputeNodes : Unable to access to the resource manager !");
518 Engines::ResourcesManager_var resManager(Engines::ResourcesManager::_narrow(obj));
519 if(CORBA::is_nil(resManager))
520 throw Exception(
"RuntimeSALOME::getCatalogOfComputeNodes : Internal error ! The entry attached to the res manager in NS does not have right type !");
521 std::vector< std::pair<std::string,int> > ret;
522 Engines::ResourceParameters params;
524 params.hostname =
"";
528 params.cpu_clock = 0;
530 params.nb_proc_per_node = 0;
532 params.can_launch_batch_jobs =
false;
533 params.can_run_containers =
true;
534 params.componentList.length(0);
537 Engines::ResourceList_var resourceList;
538 resourceList = resManager->GetFittingResources(params);
539 ret.reserve(resourceList->length());
540 for(
int i = 0;
i<resourceList->length();
i++)
542 const char* resource_name = resourceList[
i];
543 std::string std_resource_name = resource_name;
544 Engines::ResourceDefinition_var resource_definition
545 = resManager->GetResourceDefinition(resource_name);
546 int nb_cores = resource_definition->nb_node *
547 resource_definition->nb_proc_per_node;
548 ret.push_back(std::pair<std::string,int>(resource_name, nb_cores));
551 catch(SALOME::SALOME_Exception& e)
554 message=e.details.text.in();
561 std::string RuntimeSALOME::getVersion()
const
563 #ifdef YACS_DEVELOPMENT
564 return CORBA::string_dup(YACS_VERSION_STR
"dev");
566 return CORBA::string_dup(YACS_VERSION_STR);
570 Proc* RuntimeSALOME::createProc(
const std::string& name)
575 TypeCode * RuntimeSALOME::createInterfaceTc(
const std::string&
id,
const std::string& name,
576 std::list<TypeCodeObjref *> ltc)
579 if(
id ==
"") myName =
"IDL:" + name +
":1.0";
581 return TypeCode::interfaceTc(myName.c_str(),name.c_str(),ltc);
584 TypeCode * RuntimeSALOME::createSequenceTc(
const std::string&
id,
585 const std::string& name,
588 return TypeCode::sequenceTc(
id.c_str(),name.c_str(),content);
591 TypeCodeStruct * RuntimeSALOME::createStructTc(
const std::string&
id,
const std::string& name)
594 if(
id ==
"") myName =
"IDL:" + name +
":1.0";
596 return (
TypeCodeStruct *)TypeCode::structTc(myName.c_str(),name.c_str());
599 Bloc* RuntimeSALOME::createBloc(
const std::string& name)
601 return new Bloc(name);
604 WhileLoop* RuntimeSALOME::createWhileLoop(
const std::string& name)
609 ForLoop* RuntimeSALOME::createForLoop(
const std::string& name)
614 OptimizerLoop* RuntimeSALOME::createOptimizerLoop(
const std::string& name,
const std::string& algLib,
const std::string& factoryName,
615 bool algInitOnFile,
const std::string& kind,
Proc * procForTypes)
623 DataNode* RuntimeSALOME::createInDataNode(
const std::string& kind,
const std::string& name)
631 else if(kind ==
"study" )
635 std::string msg=
"DataNode kind ("+kind+
") unknown";
639 DataNode* RuntimeSALOME::createOutDataNode(
const std::string& kind,
const std::string& name)
645 else if(kind ==
"study" )
650 std::string msg=
"OutDataNode kind ("+kind+
") unknown";
654 InlineFuncNode* RuntimeSALOME::createFuncNode(
const std::string& kind,
const std::string& name)
657 if(kind ==
"" || kind == SalomeNode::KIND || kind == PythonNode::KIND)
662 if(kind == DistributedPythonNode::KIND)
664 std::string msg=
"FuncNode kind ("+kind+
") unknown";
668 InlineNode* RuntimeSALOME::createScriptNode(
const std::string& kind,
const std::string& name)
671 if(kind ==
"" || kind == SalomeNode::KIND || kind == PythonNode::KIND)
676 std::string msg=
"ScriptNode kind ("+kind+
") unknown";
680 ServiceNode* RuntimeSALOME::createRefNode(
const std::string& kind,
const std::string& name)
683 if(kind ==
"" || kind == SalomeNode::KIND || kind == CORBANode::KIND)
688 else if(kind == XmlNode::KIND)
693 std::string msg=
"RefNode kind ("+kind+
") unknown";
697 ServiceNode* RuntimeSALOME::createCompoNode(
const std::string& kind,
const std::string& name)
700 if(kind ==
"" || kind == SalomeNode::KIND )
705 else if (kind == CppNode::KIND)
710 std::string msg=
"CompoNode kind ("+kind+
") unknown";
714 ServiceInlineNode *RuntimeSALOME::createSInlineNode(
const std::string& kind,
const std::string& name)
716 if(kind ==
"" || kind == SalomeNode::KIND )
718 std::string msg=
"CompoNode kind ("+kind+
") unknown";
723 const std::string& kind)
726 if(kind ==
"" || kind == SalomeComponent::KIND)
728 else if(kind == CORBAComponent::KIND)
730 else if(kind == SalomePythonComponent::KIND)
732 else if (kind == CppComponent::KIND)
734 else if (kind == SalomeHPComponent::KIND)
736 std::string msg=
"Component Instance kind ("+kind+
") unknown";
740 Container *RuntimeSALOME::createContainer(
const std::string& kind)
742 if(kind ==
"" || kind == SalomeContainer::KIND)
744 if(kind==SalomeHPContainer::KIND)
746 else if (kind == CppContainer::KIND)
748 std::string msg=
"Container kind ("+kind+
") unknown";
752 InputPort * RuntimeSALOME::createInputPort(
const std::string& name,
753 const std::string& impl,
757 if(impl == CppNode::IMPL_NAME)
761 else if(impl == PythonNode::IMPL_NAME)
765 else if(impl == CORBANode::IMPL_NAME)
769 else if(impl == XmlNode::IMPL_NAME)
776 msg <<
"Cannot create " << impl <<
" InputPort" ;
777 msg <<
" (" << __FILE__ <<
":" << __LINE__ <<
")";
782 OutputPort * RuntimeSALOME::createOutputPort(
const std::string& name,
783 const std::string& impl,
787 if(impl == CppNode::IMPL_NAME)
791 else if(impl == PythonNode::IMPL_NAME)
795 else if(impl == CORBANode::IMPL_NAME)
799 else if(impl == XmlNode::IMPL_NAME)
806 msg <<
"Cannot create " << impl <<
" OutputPort" ;
807 msg <<
" (" << __FILE__ <<
":" << __LINE__ <<
")";
850 const std::string& impl,
854 if(imp_source == PythonNode::IMPL_NAME)
858 else if(imp_source == CppNode::IMPL_NAME)
862 else if(imp_source == CORBANode::IMPL_NAME)
866 else if(imp_source == XmlNode::IMPL_NAME)
870 else if(imp_source == Runtime::RUNTIME_ENGINE_INTERACTION_IMPL_NAME)
872 return adaptNeutral(source,impl,type,init);
877 msg <<
"Cannot adapt " << imp_source <<
" InputPort to " << impl;
878 msg <<
" (" << __FILE__ <<
":" << __LINE__ <<
")";
893 const std::string& impl,
896 return adaptNeutral((
InputPort *)source,impl,type,init);
916 msg <<
"Cannot connect Corba output port with type: " << type->
id() ;
917 msg <<
" to Neutral input port " << inport->
getName() <<
" with type: " << inport->
edGetType()->
id();
919 msg <<
" ("<<__FILE__ <<
":" << __LINE__<<
")";
946 msg <<
"Cannot connect Python output port with type: " << type->
id() ;
947 msg <<
" to Neutral input port " << inport->
getName() <<
" with type: " << inport->
edGetType()->
id();
949 msg <<
" ("<<__FILE__ <<
":" << __LINE__<<
")";
971 msg <<
"Cannot connect Xml output port with type: " << type->
id() ;
972 msg <<
" to Neutral input port " << inport->
getName() <<
" with type: " << inport->
edGetType()->
id();
974 msg <<
" ("<<__FILE__ <<
":" << __LINE__<<
")";
988 DEBTRACE(
"RuntimeSALOME::adaptNeutralToCpp(InputPort* inport" );
996 msg <<
"Cannot connect Cpp output port with type: " << type->
id() ;
997 msg <<
" to Neutral input port " << inport->
getName() <<
" with type: " << inport->
edGetType()->
id();
999 msg <<
" ("<<__FILE__ <<
":" << __LINE__<<
")";
1013 const std::string& impl,
1016 if(impl == CppNode::IMPL_NAME)
1018 return adaptNeutralToCpp(source,type);
1020 else if(impl == PythonNode::IMPL_NAME)
1022 return adaptNeutralToPython(source,type);
1024 else if(impl == CORBANode::IMPL_NAME)
1026 return adaptNeutralToCorba(source,type);
1028 else if(impl == XmlNode::IMPL_NAME )
1030 return adaptNeutralToXml(source,type);
1032 else if(impl == Runtime::RUNTIME_ENGINE_INTERACTION_IMPL_NAME)
1040 msg <<
"Cannot connect InputPort : unknown implementation " << impl;
1041 msg <<
" (" <<__FILE__ <<
":" <<__LINE__ <<
")";
1062 msg <<
"Cannot connect Corba output port with type: " << type->
id() ;
1063 msg <<
" to Xml input port " << inport->
getName() <<
" with type: " << inport->
edGetType()->
id();
1065 msg <<
" ("<<__FILE__ <<
":" << __LINE__<<
")";
1082 return new PyXml(inport);
1086 msg <<
"Cannot connect Python output port with type: " << type->
id() ;
1087 msg <<
" to Xml input port " << inport->
getName() <<
" with type: " << inport->
edGetType()->
id();
1089 msg <<
" ("<<__FILE__ <<
":" << __LINE__<<
")";
1103 DEBTRACE(
"RuntimeSALOME::adaptXmlToCpp(InputPort* inport" );
1108 return new CppXml(inport);
1112 msg <<
"Cannot connect Cpp output port with type: " << type->
id() ;
1113 msg <<
" to Xml input port " << inport->
getName() <<
" with type: " << inport->
edGetType()->
id();
1115 msg <<
" ("<<__FILE__ <<
":" << __LINE__<<
")";
1136 msg <<
"Cannot connect Xml InputPort to OutputNeutralPort : " ;
1137 msg <<
"(" <<__FILE__ <<
":" <<__LINE__<<
")";
1158 msg <<
"Cannot connect Xml output port with type: " << type->
id() ;
1159 msg <<
" to Xml input port " << inport->
getName() <<
" with type: " << inport->
edGetType()->
id();
1161 msg <<
" ("<<__FILE__ <<
":" << __LINE__<<
")";
1176 const std::string& impl,
1179 if(impl == CORBANode::IMPL_NAME)
1181 return adaptXmlToCorba(source,type);
1183 else if(impl == PythonNode::IMPL_NAME)
1185 return adaptXmlToPython(source,type);
1187 else if(impl == CppNode::IMPL_NAME)
1189 return adaptXmlToCpp(source,type);
1191 else if(impl == XmlNode::IMPL_NAME )
1193 return adaptXmlToXml(source,type,init);
1195 else if(impl == Runtime::RUNTIME_ENGINE_INTERACTION_IMPL_NAME)
1197 return adaptXmlToNeutral(source,type);
1202 msg <<
"Cannot connect InputXmlPort to " << impl <<
" implementation";
1203 msg <<
" (" << __FILE__ <<
":" << __LINE__ <<
")";
1232 msg <<
"Cannot connect Corba output port with type: " << type->
id() ;
1233 msg <<
" to CORBA input port " << inport->
getName() <<
" with type: " << inport->
edGetType()->
id();
1235 msg <<
" ("<<__FILE__ <<
":" << __LINE__<<
")";
1275 msg <<
"Cannot connect Python output port with type: " << type->
id() ;
1276 msg <<
" to CORBA input port " << inport->
getName() <<
" with incompatible objref type: " << inport->
edGetType()->
id();
1277 msg <<
" (" << __FILE__ <<
":" <<__LINE__ <<
")";
1290 msg <<
"Cannot convert this sequence type " ;
1291 msg << __FILE__ <<
":" <<__LINE__;
1304 msg <<
"Cannot convert this struct type " << type->
id() <<
" to " << inport->
edGetType()->
id();
1305 msg << __FILE__ <<
":" <<__LINE__;
1311 msg <<
"Cannot connect Python output port with type: " << type->
id() ;
1312 msg <<
" to CORBA input port " << inport->
getName() <<
" with type: " << inport->
edGetType()->
id();
1314 msg <<
" ("<<__FILE__ <<
":" << __LINE__<<
")";
1337 msg <<
"Cannot connect Xml output port with type: " << type->
id() ;
1338 msg <<
" to Corba input port " << inport->
getName() <<
" with type: " << inport->
edGetType()->
id();
1340 msg <<
" ("<<__FILE__ <<
":" << __LINE__<<
")";
1355 DEBTRACE(
"RuntimeSALOME::adaptCorbaToCpp(InputCorbaPort* inport" );
1363 msg <<
"Cannot connect Cpp output port with type: " << type->
id() ;
1364 msg <<
" to Corba input port " << inport->
getName() <<
" with type: " << inport->
edGetType()->
id();
1366 msg <<
" ("<<__FILE__ <<
":" << __LINE__<<
")";
1408 msg <<
"Cannot convert this sequence type " ;
1409 msg << __FILE__ <<
":" <<__LINE__;
1420 msg <<
"Cannot connect Neutral output port with type: " << type->
id() ;
1421 msg <<
" to Corba input port " << inport->
getName() <<
" with type: " << inport->
edGetType()->
id();
1423 msg <<
" ("<<__FILE__ <<
":" << __LINE__<<
")";
1438 const std::string& impl,
1441 if(impl == CppNode::IMPL_NAME)
1443 return adaptCorbaToCpp(source,type);
1445 else if(impl == PythonNode::IMPL_NAME)
1447 return adaptCorbaToPython(source,type);
1449 else if(impl == CORBANode::IMPL_NAME)
1452 return adaptCorbaToCorba(source,type);
1454 return adaptCorbaToCorba(source,type);
1456 else if(impl == XmlNode::IMPL_NAME )
1458 return adaptCorbaToXml(source,type);
1460 else if(impl == Runtime::RUNTIME_ENGINE_INTERACTION_IMPL_NAME)
1462 return adaptCorbaToNeutral(source,type);
1467 msg <<
"Cannot connect InputCorbaPort : unknown implementation " ;
1468 msg << __FILE__ <<
":" <<__LINE__;
1487 return new PyInit(inport);
1498 msg <<
"Cannot connect Python output port with type: " << type->
id() ;
1499 msg <<
" to Python input port " << inport->
getName() <<
" with type: " << inport->
edGetType()->
id();
1501 msg <<
" ("<<__FILE__ <<
":" << __LINE__<<
")";
1516 DEBTRACE(
"RuntimeSALOME::adaptPythonToCpp(InputPyPort* inport" );
1520 return new CppPy(inport);
1524 msg <<
"Cannot connect Cpp output port with type: " << type->
id() ;
1525 msg <<
" to Python input port " << inport->
getName() <<
" with type: " << inport->
edGetType()->
id();
1527 msg <<
" ("<<__FILE__ <<
":" << __LINE__<<
")";
1569 msg <<
"Cannot convert this sequence type " ;
1570 msg << __FILE__ <<
":" <<__LINE__;
1581 msg <<
"Cannot connect Neutral output port with type: " << type->
id() ;
1582 msg <<
" to Python input port " << inport->
getName() <<
" with type: " << inport->
edGetType()->
id();
1584 msg <<
" ("<<__FILE__ <<
":" << __LINE__<<
")";
1625 msg <<
"Cannot connect InputCorbaPort : incompatible objref types " << type->
id() <<
" " << inport->
edGetType()->
id();
1626 msg <<
" " << __FILE__ <<
":" <<__LINE__;
1639 msg <<
"Cannot convert this sequence type " ;
1640 msg << __FILE__ <<
":" <<__LINE__;
1653 msg <<
"Cannot convert this struct type " << type->
id() <<
" to " << inport->
edGetType()->
id();
1654 msg <<
" " << __FILE__ <<
":" <<__LINE__;
1660 msg <<
"Cannot connect Corba output port with type: " << type->
id() ;
1661 msg <<
" to Python input port " << inport->
getName() <<
" with type: " << inport->
edGetType()->
id();
1663 msg <<
" ("__FILE__ <<
":" << __LINE__ <<
")";
1686 msg <<
"Cannot connect Xml output port with type: " << type->
id() ;
1687 msg <<
" to Python input port " << inport->
getName() <<
" with type: " << inport->
edGetType()->
id();
1689 msg <<
" ("<<__FILE__ <<
":" << __LINE__<<
")";
1704 const std::string& impl,
1707 if(impl == CppNode::IMPL_NAME)
1709 return adaptPythonToCpp(source,type);
1711 else if(impl == PythonNode::IMPL_NAME)
1713 return adaptPythonToPython(source,type,init);
1715 else if(impl == CORBANode::IMPL_NAME)
1717 return adaptPythonToCorba(source,type);
1719 else if(impl == Runtime::RUNTIME_ENGINE_INTERACTION_IMPL_NAME)
1721 return adaptPythonToNeutral(source,type);
1723 else if(impl == XmlNode::IMPL_NAME)
1725 return adaptPythonToXml(source,type);
1730 msg <<
"Cannot connect InputPyPort : unknown implementation " << impl;
1731 msg <<
" ("<<__FILE__ <<
":" << __LINE__<<
")";
1747 DEBTRACE(
"RuntimeSALOME::adaptCppToCorba(InputCppPort* inport)");
1755 msg <<
"Cannot connect Corba output port with type: " << type->
id() ;
1756 msg <<
" to Cpp input port " << inport->
getName() <<
" with type: " << inport->
edGetType()->
id();
1758 msg <<
" ("<<__FILE__ <<
":" << __LINE__<<
")";
1772 DEBTRACE(
"RuntimeSALOME::adaptCppToPython(InputCppPort* inport)");
1776 return new PyCpp(inport);
1780 msg <<
"Cannot connect Python output port with type: " << type->
id() ;
1781 msg <<
" to Cpp input port " << inport->
getName() <<
" with type: " << inport->
edGetType()->
id();
1783 msg <<
" ("<<__FILE__ <<
":" << __LINE__<<
")";
1797 DEBTRACE(
"RuntimeSALOME::adaptCppToCpp(InputPort* inport" );
1802 return new CppCpp(inport);
1806 msg <<
"Cannot connect Cpp output port with type: " << type->
id() ;
1807 msg <<
" to Cpp input port " << inport->
getName() <<
" with type: " << inport->
edGetType()->
id();
1809 msg <<
" ("<<__FILE__ <<
":" << __LINE__<<
")";
1823 DEBTRACE(
"RuntimeSALOME::adaptCppToNeutral(InputPort* inport" );
1832 msg <<
"Cannot connect Neutral output port with type: " << type->
id() ;
1833 msg <<
" to Cpp input port " << inport->
getName() <<
" with type: " << inport->
edGetType()->
id();
1835 msg <<
" ("<<__FILE__ <<
":" << __LINE__<<
")";
1843 DEBTRACE(
"RuntimeSALOME::adaptCppToXml(InputCppPort* inport" );
1847 return new XmlCpp(inport);
1851 msg <<
"Cannot connect Xml output port with type: " << type->
id() ;
1852 msg <<
" to Cpp input port " << inport->
getName() <<
" with type: " << inport->
edGetType()->
id();
1854 msg <<
" ("<<__FILE__ <<
":" << __LINE__<<
")";
1869 const std::string& impl,
1872 DEBTRACE(
"RuntimeSALOME::adapt(InputCppPort* source)");
1873 if(impl == CORBANode::IMPL_NAME)
1875 return adaptCppToCorba(source,type);
1877 else if(impl == PythonNode::IMPL_NAME)
1879 return adaptCppToPython(source,type);
1881 else if(impl == XmlNode::IMPL_NAME)
1883 return adaptCppToXml(source,type);
1885 else if(impl == CppNode::IMPL_NAME)
1887 return adaptCppToCpp(source, type);
1889 else if(impl == Runtime::RUNTIME_ENGINE_INTERACTION_IMPL_NAME)
1891 return adaptCppToNeutral(source, type);
1896 msg <<
"Cannot connect InputCppPort to " << impl <<
" implementation";
1897 msg <<
" (" << __FILE__ <<
":" << __LINE__ <<
")";
1909 CORBA::ORB_ptr RuntimeSALOME::getOrb()
const
1920 CORBA::Object_var RuntimeSALOME::getFromNS(
const char *entry)
const
1922 CORBA::Object_var ret;
1923 std::string entryCpp(entry);
1924 if(entryCpp.substr(0,4) ==
"IOR:")
1926 ret = _orb->string_to_object( entry );
1930 auto pos = entryCpp.find_last_of(
'/');
1931 std::string entry1( entryCpp.substr(pos+1,std::string::npos) );
1932 pos = entry1.find_last_of(
'.');
1933 std::string entry2( entry1.substr(0,pos) );
1934 Engines::EmbeddedNamingService_var ns = GetEmbeddedNamingService();
1935 std::unique_ptr<Engines::IORType> iorRet( ns->Resolve( entry2.c_str() ) );
1936 auto len = iorRet->length();
1937 std::unique_ptr<char[]> iorTrans(
new char[len+1]); iorTrans[len] =
'\0';
1938 for(
auto i = 0 ;
i < len ; ++
i) iorTrans[
i] = (*iorRet)[
i];
1939 ret = _orb->string_to_object(iorTrans.get());
1944 PyObject * RuntimeSALOME::getPyOrb()
const
1949 PyObject * RuntimeSALOME::getBuiltins()
const
1954 DynamicAny::DynAnyFactory_ptr RuntimeSALOME::getDynFactory()
const
1959 PyObject * RuntimeSALOME::get_omnipy()
1964 omniORBpyAPI* RuntimeSALOME::getApi()
1976 return (
void *)Py_None;
1980 std::string RuntimeSALOME::convertNeutralAsString(
TypeCode * type,
Any *data)
1988 PyGILState_STATE gstate = PyGILState_Ensure();
1999 PyGILState_Release(gstate);
2013 PyObject* RuntimeSALOME::convertStringToPyObject(
const std::string& s)
2018 PyGILState_STATE gstate = PyGILState_Ensure();
2019 mainmod = PyImport_AddModule(
"__main__");
2020 globals = PyModule_GetDict(mainmod);
2021 PyObject* d = PyDict_New();
2023 ob= PyRun_String( s.c_str(), Py_eval_input, globals, d);
2030 PySys_SetObject((
char *)
"stderr", new_stderr);
2032 PySys_SetObject((
char *)
"stderr", PySys_GetObject((
char *)
"__stderr__"));
2033 Py_DECREF(new_stderr);
2034 PyGILState_Release(gstate);
2037 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)