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"
113 #include "SALOME_NamingService.hxx"
114 #include "SALOME_LifeCycleCORBA.hxx"
117 #include <libxml/parser.h>
118 #include <omniORB4/CORBA.h>
127 using namespace YACS::ENGINE;
129 void RuntimeSALOME::setRuntime(
long flags,
int argc,
char* argv[])
131 if (! Runtime::_singleton)
134 Runtime::_singleton = r;
137 DEBTRACE(
"RuntimeSALOME::setRuntime() done !");
142 YASSERT(RuntimeSALOME::getSingleton());
143 return dynamic_cast< RuntimeSALOME*
>(RuntimeSALOME::getSingleton());
150 RuntimeSALOME::RuntimeSALOME()
155 void RuntimeSALOME::initBuiltins()
158 std::map<std::string,TypeCode*>& typeMap=_builtinCatalog->_typeMap;
159 std::map<std::string,Node*>& nodeMap=_builtinCatalog->_nodeMap;
160 std::map<std::string,ComposedNode*>& composednodeMap=_builtinCatalog->_composednodeMap;
161 std::map<std::string,ComponentDefinition*>& componentMap=_builtinCatalog->_componentMap;
162 nodeMap[
"PyFunction"]=
new PyFuncNode(
"PyFunction");
163 nodeMap[
"PyScript"]=
new PythonNode(
"PyScript");
164 nodeMap[
"CORBANode"]=
new CORBANode(
"CORBANode");
165 nodeMap[
"XmlNode"]=
new XmlNode(
"XmlNode");
166 nodeMap[
"SalomeNode"]=
new SalomeNode(
"SalomeNode");
167 nodeMap[
"CppNode"]=
new CppNode(
"CppNode");
169 nodeMap[
"PresetNode"]=
new PresetNode(
"PresetNode");
170 nodeMap[
"OutNode"]=
new OutNode(
"OutNode");
171 nodeMap[
"StudyInNode"]=
new StudyInNode(
"StudyInNode");
172 nodeMap[
"StudyOutNode"]=
new StudyOutNode(
"StudyOutNode");
173 composednodeMap[
"OptimizerLoop"]=createOptimizerLoop(
"OptimizerLoop",
"",
"",
true);
174 typeMap[
"dblevec"]= createSequenceTc(
"dblevec",
"dblevec",_tc_double);
175 typeMap[
"intvec"]= createSequenceTc(
"intvec",
"intvec",_tc_int);
176 typeMap[
"stringvec"]= createSequenceTc(
"stringvec",
"stringvec",_tc_string);
177 typeMap[
"boolvec"]= createSequenceTc(
"boolvec",
"boolvec",_tc_bool);
178 typeMap[
"seqdblevec"]= createSequenceTc(
"seqdblevec",
"seqdblevec",typeMap[
"dblevec"]);
179 typeMap[
"seqintvec"]= createSequenceTc(
"seqintvec",
"seqintvec",typeMap[
"intvec"]);
180 typeMap[
"seqstringvec"]= createSequenceTc(
"seqstringvec",
"seqstringvec",typeMap[
"stringvec"]);
181 typeMap[
"seqboolvec"]= createSequenceTc(
"seqboolvec",
"seqboolvec",typeMap[
"boolvec"]);
182 std::list<TypeCodeObjref *> ltc;
183 typeMap[
"pyobj"]= createInterfaceTc(
"python:obj:1.0",
"pyobj",ltc);
184 typeMap[
"seqpyobj"]= createSequenceTc(
"seqpyobj",
"seqpyobj",typeMap[
"pyobj"]);
185 composednodeMap[
"Bloc"]=createBloc(
"Bloc");
186 composednodeMap[
"Switch"]=createSwitch(
"Switch");
187 composednodeMap[
"WhileLoop"]=createWhileLoop(
"WhileLoop");
188 composednodeMap[
"ForLoop"]=createForLoop(
"ForLoop");
189 composednodeMap[
"ForEachLoop_double"]=createForEachLoop(
"ForEachLoop_double",Runtime::_tc_double);
190 composednodeMap[
"ForEachLoop_string"]=createForEachLoop(
"ForEachLoop_string",Runtime::_tc_string);
191 composednodeMap[
"ForEachLoop_int"]=createForEachLoop(
"ForEachLoop_int",Runtime::_tc_int);
192 composednodeMap[
"ForEachLoop_bool"]=createForEachLoop(
"ForEachLoop_bool",Runtime::_tc_bool);
193 composednodeMap[
"ForEachLoop_pyobj"]=createForEachLoop(
"ForEachLoop_pyobj",typeMap[
"pyobj"]);;
196 typeMap[
"dataref"]=
t;
199 RuntimeSALOME::RuntimeSALOME(
long flags,
int argc,
char* argv[])
202 if ((flags - flags & RuntimeSALOME::IsPyExt) == 0)
203 flags += RuntimeSALOME::UseCorba + RuntimeSALOME::UsePython
204 + RuntimeSALOME::UseCpp + RuntimeSALOME::UseXml;
207 if (flags & RuntimeSALOME::UseSalome)
208 flags |= RuntimeSALOME::UseCorba;
211 if (flags & RuntimeSALOME::UseCorba)
212 flags |= RuntimeSALOME::UsePython;
214 _useCorba = flags & RuntimeSALOME::UseCorba;
215 _usePython = flags & RuntimeSALOME::UsePython;
216 _useCpp = flags & RuntimeSALOME::UseCpp;
217 _useXml = flags & RuntimeSALOME::UseXml;
222 if (_useCpp) _setOfImplementation.insert(CppNode::IMPL_NAME);
223 if (_usePython) _setOfImplementation.insert(PythonNode::IMPL_NAME);
224 if (_useCorba) _setOfImplementation.insert(CORBANode::IMPL_NAME);
225 if (_useXml) _setOfImplementation.insert(XmlNode::IMPL_NAME);
226 init(flags, argc, argv);
229 RuntimeSALOME::~RuntimeSALOME()
231 DEBTRACE(
"RuntimeSALOME::~RuntimeSALOME");
233 std::map<std::string, CatalogLoader*>::const_iterator pt;
234 for(pt=_catalogLoaderFactoryMap.begin();pt!=_catalogLoaderFactoryMap.end();pt++)
255 void RuntimeSALOME::init(
long flags,
int argc,
char* argv[])
257 bool ispyext = flags & RuntimeSALOME::IsPyExt;
260 PortableServer::POA_var root_poa;
261 PortableServer::POAManager_var pman;
262 CORBA::Object_var obj;
263 int nbargs = 0;
char **args = 0;
264 _orb = CORBA::ORB_init (nbargs, args);
265 obj = _orb->resolve_initial_references(
"RootPOA");
266 root_poa = PortableServer::POA::_narrow(obj);
267 pman = root_poa->the_POAManager();
271 DEBTRACE(
"_orb refCount: " << ((omniOrbORB*)_orb.in())->pd_refCount);
273 obj = _orb->resolve_initial_references(
"DynAnyFactory");
274 _dynFactory = DynamicAny::DynAnyFactory::_narrow(obj);
279 DEBTRACE(
"RuntimeSALOME::init, is python extension = " << ispyext);
282 if (!Py_IsInitialized())
284 #if PY_VERSION_HEX < 0x02040000 // python version earlier than 2.4.0
289 if (argc > 0 && argv != NULL)
290 PySys_SetArgv(argc, argv);
295 char defaultName[] =
"SALOME_YACS_RUNTIME";
296 pyArgv[0] = defaultName;
297 PySys_SetArgv(pyArgc, pyArgv);
299 PyEval_InitThreads();
304 PyObject *mainmod,*pyapi,*res ;
306 PyGILState_STATE gstate;
307 gstate = PyGILState_Ensure();
309 mainmod = PyImport_AddModule(
"__main__");
310 globals = PyModule_GetDict(mainmod);
313 if (PyDict_GetItemString(globals,
"__builtins__") == NULL)
315 PyObject *bimod = PyImport_ImportModule(
"__builtin__");
316 if (bimod == NULL || PyDict_SetItemString(globals,
"__builtins__", bimod) != 0)
317 Py_FatalError(
"can't add __builtins__ to __main__");
321 _bltins = PyEval_GetBuiltins();
327 _omnipy = PyImport_ImportModule((
char*)
"_omnipy");
331 PyErr_SetString(PyExc_ImportError, (
char*)
"Cannot import _omnipy");
334 pyapi = PyObject_GetAttrString(_omnipy, (
char*)
"API");
342 res=PyRun_String(
"\n"
343 "from math import *\n"
345 "sys.path.insert(0,'.')\n"
346 "from omniORB import CORBA\n"
347 "from omniORB import any\n"
348 "orb = CORBA.ORB_init([], CORBA.ORB_ID)\n"
349 "#print sys.getrefcount(orb)\n"
355 Py_file_input,globals,globals );
363 _pyorb = PyDict_GetItemString(globals,
"orb");
367 pyany = PyDict_GetItemString(globals,
"any");
371 DEBTRACE(
"_orb refCount: " << ((omniOrbORB*)_orb.in())->pd_refCount);
375 PyGILState_Release(gstate);
384 void RuntimeSALOME::fini()
388 PyGILState_STATE gstate = PyGILState_Ensure();
390 DEBTRACE(
"_orb refCount: " << ((omniOrbORB*)_orb.in())->pd_refCount);
392 PyObject *mainmod, *globals;
393 mainmod = PyImport_AddModule(
"__main__");
394 globals = PyModule_GetDict(mainmod);
398 res=PyRun_String(
"orb.destroy()\n"
400 Py_file_input,globals,globals );
406 std::map<std::string,Node*>& nodeMap=_builtinCatalog->_nodeMap;
407 delete nodeMap[
"PyFunction"];
408 delete nodeMap[
"PyScript"];
409 delete nodeMap[
"SalomePythonNode"];
410 nodeMap.erase(
"PyFunction");
411 nodeMap.erase(
"PyScript");
412 nodeMap.erase(
"SalomePythonNode");
416 DEBTRACE(
"_orb refCount: " << ((omniOrbORB*)_orb.in())->pd_refCount);
424 DEBTRACE(
"_orb refCount: " << ((omniOrbORB*)_orb.in())->pd_refCount);
431 std::string RuntimeSALOME::getVersion()
const
433 #ifdef YACS_DEVELOPMENT
434 return CORBA::string_dup(YACS_VERSION_STR
"dev");
436 return CORBA::string_dup(YACS_VERSION_STR);
440 Proc* RuntimeSALOME::createProc(
const std::string& name)
445 TypeCode * RuntimeSALOME::createInterfaceTc(
const std::string&
id,
const std::string& name,
446 std::list<TypeCodeObjref *> ltc)
449 if(
id ==
"") myName =
"IDL:" + name +
":1.0";
451 return TypeCode::interfaceTc(myName.c_str(),name.c_str(),ltc);
454 TypeCode * RuntimeSALOME::createSequenceTc(
const std::string&
id,
455 const std::string& name,
458 return TypeCode::sequenceTc(
id.c_str(),name.c_str(),content);
461 TypeCodeStruct * RuntimeSALOME::createStructTc(
const std::string&
id,
const std::string& name)
464 if(
id ==
"") myName =
"IDL:" + name +
":1.0";
466 return (
TypeCodeStruct *)TypeCode::structTc(myName.c_str(),name.c_str());
469 Bloc* RuntimeSALOME::createBloc(
const std::string& name)
471 return new Bloc(name);
474 WhileLoop* RuntimeSALOME::createWhileLoop(
const std::string& name)
479 ForLoop* RuntimeSALOME::createForLoop(
const std::string& name)
484 OptimizerLoop* RuntimeSALOME::createOptimizerLoop(
const std::string& name,
const std::string& algLib,
const std::string& factoryName,
485 bool algInitOnFile,
const std::string& kind,
Proc * procForTypes)
493 DataNode* RuntimeSALOME::createInDataNode(
const std::string& kind,
const std::string& name)
501 else if(kind ==
"study" )
505 std::string msg=
"DataNode kind ("+kind+
") unknown";
509 DataNode* RuntimeSALOME::createOutDataNode(
const std::string& kind,
const std::string& name)
515 else if(kind ==
"study" )
520 std::string msg=
"OutDataNode kind ("+kind+
") unknown";
524 InlineFuncNode* RuntimeSALOME::createFuncNode(
const std::string& kind,
const std::string& name)
527 if(kind ==
"" || kind == SalomeNode::KIND || kind == PythonNode::KIND)
532 if(kind == DistributedPythonNode::KIND)
534 std::string msg=
"FuncNode kind ("+kind+
") unknown";
538 InlineNode* RuntimeSALOME::createScriptNode(
const std::string& kind,
const std::string& name)
541 if(kind ==
"" || kind == SalomeNode::KIND || kind == PythonNode::KIND)
546 std::string msg=
"ScriptNode kind ("+kind+
") unknown";
550 ServiceNode* RuntimeSALOME::createRefNode(
const std::string& kind,
const std::string& name)
553 if(kind ==
"" || kind == SalomeNode::KIND || kind == CORBANode::KIND)
558 else if(kind == XmlNode::KIND)
563 std::string msg=
"RefNode kind ("+kind+
") unknown";
567 ServiceNode* RuntimeSALOME::createCompoNode(
const std::string& kind,
const std::string& name)
570 if(kind ==
"" || kind == SalomeNode::KIND )
575 else if (kind == CppNode::KIND)
580 std::string msg=
"CompoNode kind ("+kind+
") unknown";
584 ServiceInlineNode *RuntimeSALOME::createSInlineNode(
const std::string& kind,
const std::string& name)
586 if(kind ==
"" || kind == SalomeNode::KIND )
588 std::string msg=
"CompoNode kind ("+kind+
") unknown";
593 const std::string& kind)
596 if(kind ==
"" || kind == SalomeComponent::KIND)
598 else if(kind == CORBAComponent::KIND)
600 else if(kind == SalomePythonComponent::KIND)
602 else if (kind == CppComponent::KIND)
604 else if (kind == SalomeHPComponent::KIND)
606 std::string msg=
"Component Instance kind ("+kind+
") unknown";
610 Container *RuntimeSALOME::createContainer(
const std::string& kind)
612 if(kind ==
"" || kind == SalomeContainer::KIND)
614 if(kind==SalomeHPContainer::KIND)
616 else if (kind == CppContainer::KIND)
618 std::string msg=
"Container kind ("+kind+
") unknown";
622 InputPort * RuntimeSALOME::createInputPort(
const std::string& name,
623 const std::string& impl,
627 if(impl == CppNode::IMPL_NAME)
631 else if(impl == PythonNode::IMPL_NAME)
635 else if(impl == CORBANode::IMPL_NAME)
639 else if(impl == XmlNode::IMPL_NAME)
646 msg <<
"Cannot create " << impl <<
" InputPort" ;
647 msg <<
" (" << __FILE__ <<
":" << __LINE__ <<
")";
652 OutputPort * RuntimeSALOME::createOutputPort(
const std::string& name,
653 const std::string& impl,
657 if(impl == CppNode::IMPL_NAME)
661 else if(impl == PythonNode::IMPL_NAME)
665 else if(impl == CORBANode::IMPL_NAME)
669 else if(impl == XmlNode::IMPL_NAME)
676 msg <<
"Cannot create " << impl <<
" OutputPort" ;
677 msg <<
" (" << __FILE__ <<
":" << __LINE__ <<
")";
720 const std::string& impl,
723 string imp_source=source->getNode()->getImplementation();
724 if(imp_source == PythonNode::IMPL_NAME)
728 else if(imp_source == CppNode::IMPL_NAME)
732 else if(imp_source == CORBANode::IMPL_NAME)
736 else if(imp_source == XmlNode::IMPL_NAME)
740 else if(imp_source == Runtime::RUNTIME_ENGINE_INTERACTION_IMPL_NAME)
742 return adaptNeutral(source,impl,type,init);
747 msg <<
"Cannot adapt " << imp_source <<
" InputPort to " << impl;
748 msg <<
" (" << __FILE__ <<
":" << __LINE__ <<
")";
763 const std::string& impl,
766 return adaptNeutral((
InputPort *)source,impl,type,init);
779 if(inport->edGetType()->isAdaptable(type))
786 msg <<
"Cannot connect Corba output port with type: " << type->id() ;
787 msg <<
" to Neutral input port " << inport->getName() <<
" with type: " << inport->edGetType()->id();
789 msg <<
" ("<<__FILE__ <<
":" << __LINE__<<
")";
804 if(inport->edGetType()->isAdaptable(type))
810 else if(type->kind()==
Sequence && type->contentType()->kind()==
Objref && inport->edGetType()->kind()==
Objref)
816 msg <<
"Cannot connect Python output port with type: " << type->id() ;
817 msg <<
" to Neutral input port " << inport->getName() <<
" with type: " << inport->edGetType()->id();
819 msg <<
" ("<<__FILE__ <<
":" << __LINE__<<
")";
834 if(inport->edGetType()->isAdaptable(type))
841 msg <<
"Cannot connect Xml output port with type: " << type->id() ;
842 msg <<
" to Neutral input port " << inport->getName() <<
" with type: " << inport->edGetType()->id();
844 msg <<
" ("<<__FILE__ <<
":" << __LINE__<<
")";
858 DEBTRACE(
"RuntimeSALOME::adaptNeutralToCpp(InputPort* inport" );
866 msg <<
"Cannot connect Cpp output port with type: " << type->id() ;
867 msg <<
" to Neutral input port " << inport->getName() <<
" with type: " << inport->edGetType()->id();
869 msg <<
" ("<<__FILE__ <<
":" << __LINE__<<
")";
883 const std::string& impl,
886 if(impl == CppNode::IMPL_NAME)
888 return adaptNeutralToCpp(source,type);
890 else if(impl == PythonNode::IMPL_NAME)
892 return adaptNeutralToPython(source,type);
894 else if(impl == CORBANode::IMPL_NAME)
896 return adaptNeutralToCorba(source,type);
898 else if(impl == XmlNode::IMPL_NAME )
900 return adaptNeutralToXml(source,type);
902 else if(impl == Runtime::RUNTIME_ENGINE_INTERACTION_IMPL_NAME)
910 msg <<
"Cannot connect InputPort : unknown implementation " << impl;
911 msg <<
" (" <<__FILE__ <<
":" <<__LINE__ <<
")";
932 msg <<
"Cannot connect Corba output port with type: " << type->id() ;
933 msg <<
" to Xml input port " << inport->getName() <<
" with type: " << inport->edGetType()->id();
935 msg <<
" ("<<__FILE__ <<
":" << __LINE__<<
")";
949 if(inport->edGetType()->isAdaptable(type))
952 return new PyXml(inport);
956 msg <<
"Cannot connect Python output port with type: " << type->id() ;
957 msg <<
" to Xml input port " << inport->getName() <<
" with type: " << inport->edGetType()->id();
959 msg <<
" ("<<__FILE__ <<
":" << __LINE__<<
")";
973 DEBTRACE(
"RuntimeSALOME::adaptXmlToCpp(InputPort* inport" );
974 DEBTRACE(type->kind() <<
" " << inport->edGetType()->kind() );
975 if(type->isAdaptable(inport->edGetType()))
978 return new CppXml(inport);
982 msg <<
"Cannot connect Cpp output port with type: " << type->id() ;
983 msg <<
" to Xml input port " << inport->getName() <<
" with type: " << inport->edGetType()->id();
985 msg <<
" ("<<__FILE__ <<
":" << __LINE__<<
")";
999 if(inport->edGetType()->isAdaptable(type))
1006 msg <<
"Cannot connect Xml InputPort to OutputNeutralPort : " ;
1007 msg <<
"(" <<__FILE__ <<
":" <<__LINE__<<
")";
1024 if(inport->edGetType()->isAdaptable(type))
1028 msg <<
"Cannot connect Xml output port with type: " << type->id() ;
1029 msg <<
" to Xml input port " << inport->
getName() <<
" with type: " << inport->edGetType()->id();
1031 msg <<
" ("<<__FILE__ <<
":" << __LINE__<<
")";
1046 const std::string& impl,
1049 if(impl == CORBANode::IMPL_NAME)
1051 return adaptXmlToCorba(source,type);
1053 else if(impl == PythonNode::IMPL_NAME)
1055 return adaptXmlToPython(source,type);
1057 else if(impl == CppNode::IMPL_NAME)
1059 return adaptXmlToCpp(source,type);
1061 else if(impl == XmlNode::IMPL_NAME )
1063 return adaptXmlToXml(source,type,init);
1065 else if(impl == Runtime::RUNTIME_ENGINE_INTERACTION_IMPL_NAME)
1067 return adaptXmlToNeutral(source,type);
1072 msg <<
"Cannot connect InputXmlPort to " << impl <<
" implementation";
1073 msg <<
" (" << __FILE__ <<
":" << __LINE__ <<
")";
1088 if(type->isA(inport->edGetType()))
1102 msg <<
"Cannot connect Corba output port with type: " << type->id() ;
1103 msg <<
" to CORBA input port " << inport->getName() <<
" with type: " << inport->edGetType()->id();
1105 msg <<
" ("<<__FILE__ <<
":" << __LINE__<<
")";
1120 if(inport->edGetType()->kind() ==
Double)
1124 else if(inport->edGetType()->kind() ==
Int)
1128 else if(inport->edGetType()->kind() ==
String)
1132 else if(inport->edGetType()->kind() ==
Bool)
1136 else if(inport->edGetType()->kind() ==
Objref )
1145 msg <<
"Cannot connect Python output port with type: " << type->id() ;
1146 msg <<
" to CORBA input port " << inport->getName() <<
" with incompatible objref type: " << inport->edGetType()->id();
1147 msg <<
" (" << __FILE__ <<
":" <<__LINE__ <<
")";
1151 else if(inport->edGetType()->kind() ==
Sequence)
1160 msg <<
"Cannot convert this sequence type " ;
1161 msg << __FILE__ <<
":" <<__LINE__;
1174 msg <<
"Cannot convert this struct type " << type->id() <<
" to " << inport->edGetType()->id();
1175 msg << __FILE__ <<
":" <<__LINE__;
1181 msg <<
"Cannot connect Python output port with type: " << type->id() ;
1182 msg <<
" to CORBA input port " << inport->getName() <<
" with type: " << inport->edGetType()->id();
1184 msg <<
" ("<<__FILE__ <<
":" << __LINE__<<
")";
1200 if(inport->edGetType()->isAdaptable(type))
1207 msg <<
"Cannot connect Xml output port with type: " << type->id() ;
1208 msg <<
" to Corba input port " << inport->getName() <<
" with type: " << inport->edGetType()->id();
1210 msg <<
" ("<<__FILE__ <<
":" << __LINE__<<
")";
1225 DEBTRACE(
"RuntimeSALOME::adaptCorbaToCpp(InputCorbaPort* inport" );
1233 msg <<
"Cannot connect Cpp output port with type: " << type->id() ;
1234 msg <<
" to Corba input port " << inport->getName() <<
" with type: " << inport->edGetType()->id();
1236 msg <<
" ("<<__FILE__ <<
":" << __LINE__<<
")";
1251 if(inport->edGetType()->kind() ==
Double)
1255 else if(inport->edGetType()->kind() ==
Int)
1259 else if(inport->edGetType()->kind() ==
String)
1263 else if(inport->edGetType()->kind() ==
Bool)
1267 else if(inport->edGetType()->kind() ==
Objref)
1271 else if(inport->edGetType()->kind() ==
Sequence)
1278 msg <<
"Cannot convert this sequence type " ;
1279 msg << __FILE__ <<
":" <<__LINE__;
1283 else if(inport->edGetType()->kind() ==
Struct)
1290 msg <<
"Cannot connect Neutral output port with type: " << type->id() ;
1291 msg <<
" to Corba input port " << inport->getName() <<
" with type: " << inport->edGetType()->id();
1293 msg <<
" ("<<__FILE__ <<
":" << __LINE__<<
")";
1308 const std::string& impl,
1311 if(impl == CppNode::IMPL_NAME)
1313 return adaptCorbaToCpp(source,type);
1315 else if(impl == PythonNode::IMPL_NAME)
1317 return adaptCorbaToPython(source,type);
1319 else if(impl == CORBANode::IMPL_NAME)
1322 return adaptCorbaToCorba(source,type);
1324 return adaptCorbaToCorba(source,type);
1326 else if(impl == XmlNode::IMPL_NAME )
1328 return adaptCorbaToXml(source,type);
1330 else if(impl == Runtime::RUNTIME_ENGINE_INTERACTION_IMPL_NAME)
1332 return adaptCorbaToNeutral(source,type);
1337 msg <<
"Cannot connect InputCorbaPort : unknown implementation " ;
1338 msg << __FILE__ <<
":" <<__LINE__;
1357 return new PyInit(inport);
1368 msg <<
"Cannot connect Python output port with type: " << type->id() ;
1369 msg <<
" to Python input port " << inport->getName() <<
" with type: " << inport->edGetType()->id();
1371 msg <<
" ("<<__FILE__ <<
":" << __LINE__<<
")";
1386 DEBTRACE(
"RuntimeSALOME::adaptPythonToCpp(InputPyPort* inport" );
1390 return new CppPy(inport);
1394 msg <<
"Cannot connect Cpp output port with type: " << type->id() ;
1395 msg <<
" to Python input port " << inport->getName() <<
" with type: " << inport->edGetType()->id();
1397 msg <<
" ("<<__FILE__ <<
":" << __LINE__<<
")";
1412 if(inport->edGetType()->kind() ==
Double)
1416 else if(inport->edGetType()->kind() ==
Int)
1420 else if(inport->edGetType()->kind() ==
String)
1424 else if(inport->edGetType()->kind() ==
Bool)
1428 else if(inport->edGetType()->kind() ==
Objref)
1432 else if(inport->edGetType()->kind() ==
Sequence)
1439 msg <<
"Cannot convert this sequence type " ;
1440 msg << __FILE__ <<
":" <<__LINE__;
1444 else if(inport->edGetType()->kind() ==
Struct)
1451 msg <<
"Cannot connect Neutral output port with type: " << type->id() ;
1452 msg <<
" to Python input port " << inport->getName() <<
" with type: " << inport->edGetType()->id();
1454 msg <<
" ("<<__FILE__ <<
":" << __LINE__<<
")";
1470 if(inport->edGetType()->kind() ==
Double)
1474 else if(inport->edGetType()->kind() ==
Int)
1478 else if(inport->edGetType()->kind() ==
String)
1482 else if(inport->edGetType()->kind() ==
Bool)
1486 else if(inport->edGetType()->kind() ==
Objref)
1495 msg <<
"Cannot connect InputCorbaPort : incompatible objref types " << type->id() <<
" " << inport->edGetType()->id();
1496 msg <<
" " << __FILE__ <<
":" <<__LINE__;
1500 else if(inport->edGetType()->kind() ==
Sequence)
1509 msg <<
"Cannot convert this sequence type " ;
1510 msg << __FILE__ <<
":" <<__LINE__;
1523 msg <<
"Cannot convert this struct type " << type->id() <<
" to " << inport->edGetType()->id();
1524 msg <<
" " << __FILE__ <<
":" <<__LINE__;
1530 msg <<
"Cannot connect Corba output port with type: " << type->id() ;
1531 msg <<
" to Python input port " << inport->getName() <<
" with type: " << inport->edGetType()->id();
1533 msg <<
" ("__FILE__ <<
":" << __LINE__ <<
")";
1549 if(inport->edGetType()->isAdaptable(type))
1556 msg <<
"Cannot connect Xml output port with type: " << type->id() ;
1557 msg <<
" to Python input port " << inport->getName() <<
" with type: " << inport->edGetType()->id();
1559 msg <<
" ("<<__FILE__ <<
":" << __LINE__<<
")";
1574 const std::string& impl,
1577 if(impl == CppNode::IMPL_NAME)
1579 return adaptPythonToCpp(source,type);
1581 else if(impl == PythonNode::IMPL_NAME)
1583 return adaptPythonToPython(source,type,init);
1585 else if(impl == CORBANode::IMPL_NAME)
1587 return adaptPythonToCorba(source,type);
1589 else if(impl == Runtime::RUNTIME_ENGINE_INTERACTION_IMPL_NAME)
1591 return adaptPythonToNeutral(source,type);
1593 else if(impl == XmlNode::IMPL_NAME)
1595 return adaptPythonToXml(source,type);
1600 msg <<
"Cannot connect InputPyPort : unknown implementation " << impl;
1601 msg <<
" ("<<__FILE__ <<
":" << __LINE__<<
")";
1617 DEBTRACE(
"RuntimeSALOME::adaptCppToCorba(InputCppPort* inport)");
1625 msg <<
"Cannot connect Corba output port with type: " << type->id() ;
1626 msg <<
" to Cpp input port " << inport->getName() <<
" with type: " << inport->edGetType()->id();
1628 msg <<
" ("<<__FILE__ <<
":" << __LINE__<<
")";
1642 DEBTRACE(
"RuntimeSALOME::adaptCppToPython(InputCppPort* inport)");
1646 return new PyCpp(inport);
1650 msg <<
"Cannot connect Python output port with type: " << type->id() ;
1651 msg <<
" to Cpp input port " << inport->getName() <<
" with type: " << inport->edGetType()->id();
1653 msg <<
" ("<<__FILE__ <<
":" << __LINE__<<
")";
1667 DEBTRACE(
"RuntimeSALOME::adaptCppToCpp(InputPort* inport" );
1668 DEBTRACE(type->kind() <<
" " << inport->edGetType()->kind() );
1669 if(type->isAdaptable(inport->edGetType()))
1672 return new CppCpp(inport);
1676 msg <<
"Cannot connect Cpp output port with type: " << type->id() ;
1677 msg <<
" to Cpp input port " << inport->getName() <<
" with type: " << inport->edGetType()->id();
1679 msg <<
" ("<<__FILE__ <<
":" << __LINE__<<
")";
1693 DEBTRACE(
"RuntimeSALOME::adaptCppToNeutral(InputPort* inport" );
1694 DEBTRACE(type->kind() <<
" " << inport->edGetType()->kind() );
1695 if(type->isAdaptable(inport->edGetType()))
1702 msg <<
"Cannot connect Neutral output port with type: " << type->id() ;
1703 msg <<
" to Cpp input port " << inport->getName() <<
" with type: " << inport->edGetType()->id();
1705 msg <<
" ("<<__FILE__ <<
":" << __LINE__<<
")";
1713 DEBTRACE(
"RuntimeSALOME::adaptCppToXml(InputCppPort* inport" );
1717 return new XmlCpp(inport);
1721 msg <<
"Cannot connect Xml output port with type: " << type->id() ;
1722 msg <<
" to Cpp input port " << inport->getName() <<
" with type: " << inport->edGetType()->id();
1724 msg <<
" ("<<__FILE__ <<
":" << __LINE__<<
")";
1739 const std::string& impl,
1742 DEBTRACE(
"RuntimeSALOME::adapt(InputCppPort* source)");
1743 if(impl == CORBANode::IMPL_NAME)
1745 return adaptCppToCorba(source,type);
1747 else if(impl == PythonNode::IMPL_NAME)
1749 return adaptCppToPython(source,type);
1751 else if(impl == XmlNode::IMPL_NAME)
1753 return adaptCppToXml(source,type);
1755 else if(impl == CppNode::IMPL_NAME)
1757 return adaptCppToCpp(source, type);
1759 else if(impl == Runtime::RUNTIME_ENGINE_INTERACTION_IMPL_NAME)
1761 return adaptCppToNeutral(source, type);
1766 msg <<
"Cannot connect InputCppPort to " << impl <<
" implementation";
1767 msg <<
" (" << __FILE__ <<
":" << __LINE__ <<
")";
1779 CORBA::ORB_ptr RuntimeSALOME::getOrb()
1784 PyObject * RuntimeSALOME::getPyOrb()
1789 PyObject * RuntimeSALOME::getBuiltins()
1794 DynamicAny::DynAnyFactory_ptr RuntimeSALOME::getDynFactory()
1799 PyObject * RuntimeSALOME::get_omnipy()
1816 return (
void *)Py_None;
1820 std::string RuntimeSALOME::convertNeutralAsString(
TypeCode * type,
Any *data)
1828 PyGILState_STATE gstate = PyGILState_Ensure();
1839 PyGILState_Release(gstate);
1853 PyObject* RuntimeSALOME::convertStringToPyObject(
const std::string& s)
1858 PyGILState_STATE gstate = PyGILState_Ensure();
1859 mainmod = PyImport_AddModule(
"__main__");
1860 globals = PyModule_GetDict(mainmod);
1861 PyObject* d = PyDict_New();
1863 ob= PyRun_String( s.c_str(), Py_eval_input, globals, d);
1870 PySys_SetObject((
char *)
"stderr", new_stderr);
1872 PySys_SetObject((
char *)
"stderr", PySys_GetObject((
char *)
"__stderr__"));
1873 Py_DECREF(new_stderr);
1874 PyGILState_Release(gstate);
1877 PyGILState_Release(gstate);