4 #define protected public
5 #include <omniORB4/CORBA.h>
6 #include <omniORB4/internal/typecode.h>
7 #include <omniORB4/internal/corbaOrb.h>
10 #include "yacsconfig.h"
11 #include "RuntimeSALOME.hxx"
12 #include "SALOMEDispatcher.hxx"
14 #include "TypeCode.hxx"
15 #include "WhileLoop.hxx"
16 #include "ForLoop.hxx"
18 #include "InputPort.hxx"
19 #include "OutputPort.hxx"
20 #include "PresetPorts.hxx"
21 #include "InputDataStreamPort.hxx"
22 #include "OutputDataStreamPort.hxx"
23 #include "SalomeProc.hxx"
25 #include "SessionCataLoader.hxx"
28 #include "CORBAComponent.hxx"
29 #include "SalomeComponent.hxx"
30 #include "SalomePythonComponent.hxx"
31 #include "CppComponent.hxx"
33 #include "SalomeContainer.hxx"
34 #include "CppContainer.hxx"
37 #include "PythonNode.hxx"
38 #include "CORBANode.hxx"
39 #include "XMLNode.hxx"
40 #include "CppNode.hxx"
41 #include "PresetNode.hxx"
42 #include "OutNode.hxx"
43 #include "StudyNodes.hxx"
44 #include "SalomePythonNode.hxx"
47 #include "CORBACORBAConv.hxx"
48 #include "CORBAPythonConv.hxx"
49 #include "CORBAXMLConv.hxx"
50 #include "CORBACppConv.hxx"
51 #include "CORBANeutralConv.hxx"
53 #include "TypeConversions.hxx"
55 #include "PythonCORBAConv.hxx"
56 #include "PythonXMLConv.hxx"
57 #include "PythonCppConv.hxx"
58 #include "PythonNeutralConv.hxx"
61 #include "NeutralCORBAConv.hxx"
62 #include "NeutralPythonConv.hxx"
63 #include "NeutralXMLConv.hxx"
64 #include "NeutralCppConv.hxx"
67 #include "CppCORBAConv.hxx"
68 #include "CppPythonConv.hxx"
69 #include "CppXMLConv.hxx"
70 #include "CppCppConv.hxx"
71 #include "CppNeutralConv.hxx"
74 #include "XMLCORBAConv.hxx"
75 #include "XMLPythonConv.hxx"
76 #include "XMLCppConv.hxx"
77 #include "XMLNeutralConv.hxx"
79 //Calcium specific ports
80 #include "CalStreamPort.hxx"
83 #include "SALOME_NamingService.hxx"
84 #include "SALOME_LifeCycleCORBA.hxx"
87 #include <libxml/parser.h>
88 #include <omniORB4/CORBA.h>
94 #include "YacsTrace.hxx"
97 using namespace YACS::ENGINE;
99 void RuntimeSALOME::setRuntime(long flags) // singleton creation (not thread safe!)
101 if (! Runtime::_singleton)
103 RuntimeSALOME* r=new RuntimeSALOME(flags);
104 Runtime::_singleton = r;
107 DEBTRACE("RuntimeSALOME::setRuntime() done !");
110 RuntimeSALOME* YACS::ENGINE::getSALOMERuntime()
112 assert(Runtime::_singleton);
113 return dynamic_cast< RuntimeSALOME* >(Runtime::_singleton);
117 * Singleton creation, initialize converter map
120 RuntimeSALOME::RuntimeSALOME()
125 void RuntimeSALOME::initBuiltins()
127 //Fill the builtin catalog with nodes specific to the runtime
128 std::map<std::string,TypeCode*>& typeMap=_builtinCatalog->_typeMap;
129 std::map<std::string,Node*>& nodeMap=_builtinCatalog->_nodeMap;
130 std::map<std::string,ComposedNode*>& composednodeMap=_builtinCatalog->_composednodeMap;
131 std::map<std::string,ComponentDefinition*>& componentMap=_builtinCatalog->_componentMap;
132 nodeMap["PyFunction"]=new PyFuncNode("PyFunction");
133 nodeMap["PyScript"]=new PythonNode("PyScript");
134 nodeMap["CORBANode"]=new CORBANode("CORBANode");
135 nodeMap["XmlNode"]=new XmlNode("XmlNode");
136 nodeMap["SalomeNode"]=new SalomeNode("SalomeNode");
137 nodeMap["CppNode"]=new CppNode("CppNode");
138 nodeMap["SalomePythonNode"]=new SalomePythonNode("SalomePythonNode");
139 nodeMap["PresetNode"]=new PresetNode("PresetNode");
140 nodeMap["OutNode"]=new OutNode("OutNode");
141 nodeMap["StudyInNode"]=new StudyInNode("StudyInNode");
142 nodeMap["StudyOutNode"]=new StudyOutNode("StudyOutNode");
145 RuntimeSALOME::RuntimeSALOME(long flags)
147 // If all flags (apart the IsPyExt flags) are unset, force them to true
148 if ((flags - flags & RuntimeSALOME::IsPyExt) == 0)
149 flags += RuntimeSALOME::UseCorba + RuntimeSALOME::UsePython
150 + RuntimeSALOME::UseCpp + RuntimeSALOME::UseXml;
152 // Salome Nodes implies Corba Nodes
153 if (flags & RuntimeSALOME::UseSalome)
154 flags |= RuntimeSALOME::UseCorba;
156 // Corba Nodes implies Python Nodes
157 if (flags & RuntimeSALOME::UseCorba)
158 flags |= RuntimeSALOME::UsePython;
160 _useCorba = flags & RuntimeSALOME::UseCorba;
161 _usePython = flags & RuntimeSALOME::UsePython;
162 _useCpp = flags & RuntimeSALOME::UseCpp;
163 _useXml = flags & RuntimeSALOME::UseXml;
168 if (_useCpp) _setOfImplementation.insert(CppNode::IMPL_NAME);
169 if (_usePython) _setOfImplementation.insert(PythonNode::IMPL_NAME);
170 if (_useCorba) _setOfImplementation.insert(CORBANode::IMPL_NAME);
171 if (_useXml) _setOfImplementation.insert(XmlNode::IMPL_NAME);
175 RuntimeSALOME::~RuntimeSALOME()
177 DEBTRACE("RuntimeSALOME::~RuntimeSALOME");
178 // destroy catalog loader prototypes
179 std::map<std::string, CatalogLoader*>::const_iterator pt;
180 for(pt=_catalogLoaderFactoryMap.begin();pt!=_catalogLoaderFactoryMap.end();pt++)
186 //! CORBA and Python initialization
188 * \param flags contains several bits
189 * bit0 (ispyext) true when method is called from Python
190 * (Python initialization must not be done!)
191 * bit1 (UsePython) true if python nodes are needed
192 * bit1 (UseCorba) true if CORBA nodes are needed
193 * bit1 (UseXml) true if python nodes are needed
194 * bit1 (UseCpp) true if C++ nodes are needed
195 * bit1 (UseSalome) true if Salome nodes are needed
199 void RuntimeSALOME::init(long flags)
201 bool ispyext = flags & RuntimeSALOME::IsPyExt;
204 PortableServer::POA_var root_poa;
205 PortableServer::POAManager_var pman;
206 CORBA::Object_var obj;
207 int nbargs = 0; char **args = 0;
208 _orb = CORBA::ORB_init (nbargs, args);
209 obj = _orb->resolve_initial_references("RootPOA");
210 root_poa = PortableServer::POA::_narrow(obj);
211 pman = root_poa->the_POAManager();
215 DEBTRACE("_orb refCount: " << ((omniOrbORB*)_orb.in())->pd_refCount);
217 obj = _orb->resolve_initial_references("DynAnyFactory");
218 _dynFactory = DynamicAny::DynAnyFactory::_narrow(obj);
223 DEBTRACE("RuntimeSALOME::init, is python extension = " << ispyext);
225 // Initialize Python interpreter in embedded mode
226 if (!Py_IsInitialized())
228 Py_InitializeEx(0); // do not install signal handlers
229 PyEval_InitThreads(); /* Create (and acquire) the interpreter lock (for threads)*/
230 PyEval_SaveThread(); /* Release the thread state */
231 //here we do not have the Global Interpreter Lock
234 PyObject *mainmod,*pyapi,*res ;
236 PyGILState_STATE gstate;
237 gstate = PyGILState_Ensure(); // acquire the Global Interpreter Lock
239 mainmod = PyImport_AddModule("__main__");
240 globals = PyModule_GetDict(mainmod);
241 /* globals is a borrowed reference */
243 if (PyDict_GetItemString(globals, "__builtins__") == NULL)
245 PyObject *bimod = PyImport_ImportModule("__builtin__");
246 if (bimod == NULL || PyDict_SetItemString(globals, "__builtins__", bimod) != 0)
247 Py_FatalError("can't add __builtins__ to __main__");
251 _bltins = PyEval_GetBuiltins(); /* borrowed ref */
257 _omnipy = PyImport_ImportModule((char*)"_omnipy");
261 PyErr_SetString(PyExc_ImportError, (char*)"Cannot import _omnipy");
264 pyapi = PyObject_GetAttrString(_omnipy, (char*)"API");
269 _api = (omniORBpyAPI*)PyCObject_AsVoidPtr(pyapi);
272 res=PyRun_String("\n"
274 "sys.path.insert(0,'.')\n"
275 "from omniORB import CORBA\n"
276 "from omniORB import any\n"
277 "orb = CORBA.ORB_init([], CORBA.ORB_ID)\n"
278 "#print sys.getrefcount(orb)\n"
284 Py_file_input,globals,globals );
292 _pyorb = PyDict_GetItemString(globals,"orb");
293 /* PyDict_GetItemString returns a borrowed reference. There is no need to decref _pyorb */
296 pyany = PyDict_GetItemString(globals,"any");
297 /* PyDict_GetItemString returns a borrowed reference. There is no need to decref pyany */
300 DEBTRACE("_orb refCount: " << ((omniOrbORB*)_orb.in())->pd_refCount);
304 PyGILState_Release(gstate); // Release the Global Interpreter Lock
308 // initialize the catalogLoaderFactory map with the session one
309 _catalogLoaderFactoryMap["session"]=new SessionCataLoader;
313 void RuntimeSALOME::fini()
317 PyGILState_STATE gstate = PyGILState_Ensure();
319 DEBTRACE("_orb refCount: " << ((omniOrbORB*)_orb.in())->pd_refCount);
321 PyObject *mainmod, *globals;
322 mainmod = PyImport_AddModule("__main__");
323 globals = PyModule_GetDict(mainmod);
327 res=PyRun_String("orb.destroy()\n"
329 Py_file_input,globals,globals );
335 std::map<std::string,Node*>& nodeMap=_builtinCatalog->_nodeMap;
336 delete nodeMap["PyFunction"];
337 delete nodeMap["PyScript"];
338 delete nodeMap["SalomePythonNode"];
339 nodeMap.erase("PyFunction");
340 nodeMap.erase("PyScript");
341 nodeMap.erase("SalomePythonNode");
345 DEBTRACE("_orb refCount: " << ((omniOrbORB*)_orb.in())->pd_refCount);
353 DEBTRACE("_orb refCount: " << ((omniOrbORB*)_orb.in())->pd_refCount);
360 Proc* RuntimeSALOME::createProc(const std::string& name)
362 return new SalomeProc(name);
365 Bloc* RuntimeSALOME::createBloc(const std::string& name)
367 return new Bloc(name);
370 WhileLoop* RuntimeSALOME::createWhileLoop(const std::string& name)
372 return new WhileLoop(name);
375 ForLoop* RuntimeSALOME::createForLoop(const std::string& name)
377 return new ForLoop(name);
380 DataNode* RuntimeSALOME::createInDataNode(const std::string& kind,const std::string& name)
385 node = new PresetNode(name);
388 else if(kind == "study" )
390 return new StudyInNode(name);
392 std::string msg="DataNode kind ("+kind+") unknown";
393 throw Exception(msg);
396 DataNode* RuntimeSALOME::createOutDataNode(const std::string& kind,const std::string& name)
400 return new OutNode(name);
402 else if(kind == "study" )
404 return new StudyOutNode(name);
407 std::string msg="OutDataNode kind ("+kind+") unknown";
408 throw Exception(msg);
411 InlineFuncNode* RuntimeSALOME::createFuncNode(const std::string& kind,const std::string& name)
413 InlineFuncNode* node;
414 if(kind == "" || kind == SalomeNode::KIND || kind == PythonNode::KIND)
416 node = new PyFuncNode(name);
419 std::string msg="FuncNode kind ("+kind+") unknown";
420 throw Exception(msg);
423 InlineNode* RuntimeSALOME::createScriptNode(const std::string& kind,const std::string& name)
426 if(kind == "" || kind == SalomeNode::KIND || kind == PythonNode::KIND)
428 node = new PythonNode(name);
431 std::string msg="ScriptNode kind ("+kind+") unknown";
432 throw Exception(msg);
435 ServiceNode* RuntimeSALOME::createRefNode(const std::string& kind,const std::string& name)
438 if(kind == "" || kind == SalomeNode::KIND || kind == CORBANode::KIND)
440 node = new CORBANode(name);
443 else if(kind == XmlNode::KIND)
445 node = new XmlNode(name);
448 std::string msg="RefNode kind ("+kind+") unknown";
449 throw Exception(msg);
452 ServiceNode* RuntimeSALOME::createCompoNode(const std::string& kind,const std::string& name)
455 if(kind == "" || kind == SalomeNode::KIND )
457 node=new SalomeNode(name);
460 else if (kind == CppNode::KIND)
462 node = new CppNode(name);
465 std::string msg="CompoNode kind ("+kind+") unknown";
466 throw Exception(msg);
469 ServiceInlineNode *RuntimeSALOME::createSInlineNode(const std::string& kind, const std::string& name)
471 if(kind == "" || kind == SalomeNode::KIND )
472 return new SalomePythonNode(name);
473 std::string msg="CompoNode kind ("+kind+") unknown";
474 throw Exception(msg);
477 ComponentInstance* RuntimeSALOME::createComponentInstance(const std::string& name,
478 const std::string& kind)
480 ComponentInstance* compo;
481 if(kind == "" || kind == SalomeComponent::KIND)
482 return new SalomeComponent(name);
483 else if(kind == CORBAComponent::KIND)
484 return new CORBAComponent(name);
485 else if(kind == SalomePythonComponent::KIND)
486 return new SalomePythonComponent(name);
487 else if (kind == CppComponent::KIND)
488 return new CppComponent(name);
489 std::string msg="Component Instance kind ("+kind+") unknown";
490 throw Exception(msg);
493 Container *RuntimeSALOME::createContainer(const std::string& kind)
495 if(kind == "" || kind == SalomeComponent::KIND)
496 return new SalomeContainer;
497 else if (kind == CppComponent::KIND)
498 return new CppContainer;
499 std::string msg="Container kind ("+kind+") unknown";
500 throw Exception(msg);
503 InputPort * RuntimeSALOME::createInputPort(const std::string& name,
504 const std::string& impl,
508 if(impl == CppNode::IMPL_NAME)
510 return new InputCppPort(name, node, type);
512 else if(impl == PythonNode::IMPL_NAME)
514 return new InputPyPort(name, node, type);
516 else if(impl == CORBANode::IMPL_NAME)
518 return new InputCorbaPort(name, node, type);
520 else if(impl == XmlNode::IMPL_NAME)
522 return new InputXmlPort(name, node, type);
527 msg << "Cannot create " << impl << " InputPort" ;
528 msg << " ("__FILE__ << ":" << __LINE__ << ")";
529 throw Exception(msg.str());
533 OutputPort * RuntimeSALOME::createOutputPort(const std::string& name,
534 const std::string& impl,
538 if(impl == CppNode::IMPL_NAME)
540 return new OutputCppPort(name, node, type);
542 else if(impl == PythonNode::IMPL_NAME)
544 return new OutputPyPort(name, node, type);
546 else if(impl == CORBANode::IMPL_NAME)
548 return new OutputCorbaPort(name, node, type);
550 else if(impl == XmlNode::IMPL_NAME)
552 return new OutputXmlPort(name, node, type);
557 msg << "Cannot create " << impl << " OutputPort" ;
558 msg << " ("__FILE__ << ":" << __LINE__ << ")";
559 throw Exception(msg.str());
563 InputDataStreamPort* RuntimeSALOME::createInputDataStreamPort(const std::string& name,
564 Node *node,TypeCode *type)
566 DEBTRACE("createInputDataStreamPort: " << name << " " << type->shortName());
567 if(type->kind() == Objref && std::string(type->shortName(),7) == "CALCIUM")
569 return new InputCalStreamPort(name,node,type);
573 return new InputDataStreamPort(name,node,type);
577 OutputDataStreamPort* RuntimeSALOME::createOutputDataStreamPort(const std::string& name,
578 Node *node,TypeCode *type)
580 DEBTRACE("createOutputDataStreamPort: " << name << " " << type->shortName());
581 if(type->kind() == Objref && std::string(type->shortName(),7) == "CALCIUM")
583 return new OutputCalStreamPort(name,node,type);
587 return new OutputDataStreamPort(name,node,type);
591 //! Main adapter function : adapt an InputPort to be able to connect it to an OutputPort with a possible different implementation
593 * \param source : InputPort to be adapted
594 * \param impl : new implementation (C++, python, CORBA, XML, Neutral)
595 * \param type : data type provided by the InputPort
597 * \return : adapted InputPort
599 InputPort* RuntimeSALOME::adapt(InputPort* source,
600 const std::string& impl,
601 TypeCode * type) throw (ConversionException)
603 string imp_source=source->getNode()->getImplementation();
604 if(imp_source == PythonNode::IMPL_NAME)
606 return adapt((InputPyPort*)source,impl,type);
608 else if(imp_source == CppNode::IMPL_NAME)
610 return adapt((InputCppPort*)source,impl,type);
612 else if(imp_source == CORBANode::IMPL_NAME)
614 return adapt((InputCorbaPort*)source,impl,type);
616 else if(imp_source == XmlNode::IMPL_NAME)
618 return adapt((InputXmlPort*)source,impl,type);
620 else if(imp_source == Runtime::RUNTIME_ENGINE_INTERACTION_IMPL_NAME)
622 return adaptNeutral(source,impl,type);
627 msg << "Cannot adapt " << imp_source << " InputPort to " << impl;
628 msg << " ("__FILE__ << ":" << __LINE__ << ")";
629 throw ConversionException(msg.str());
633 //! Adapt a Neutral input port to a Corba output port
635 * \param inport : Neutral input port to adapt to Corba type type
636 * \param type : output port type
637 * \return an adaptated input port of type InputCorbaPort
639 InputPort* RuntimeSALOME::adaptNeutralToCorba(InputPort* inport,
640 TypeCode * type) throw (ConversionException)
642 // BEWARE : using the generic check
643 if(inport->edGetType()->isAdaptable(type))
645 //the output data is convertible to inport type
646 return new CorbaNeutral(inport);
648 //non convertible type
650 msg << "Cannot connect Neutral InputPort to OutputCorbaPort : " ;
651 msg << "(" <<__FILE__ << ":" <<__LINE__<< ")";
652 throw ConversionException(msg.str());
655 //! Adapt a Neutral input port to a Python output port
657 * \param inport : input port to adapt to Python type type
658 * \param type : output port type
659 * \return an adaptated input port of type InputPyPort
661 InputPort* RuntimeSALOME::adaptNeutralToPython(InputPort* inport,
662 TypeCode * type) throw (ConversionException)
664 // BEWARE : using the generic check
665 if(inport->edGetType()->isAdaptable(type))
668 return new PyNeutral(inport);
670 //non convertible type
672 msg << "Cannot connect Neutral InputPort to OutputPyPort : " ;
673 msg << "(" <<__FILE__ << ":" <<__LINE__<< ")";
674 throw ConversionException(msg.str());
677 //! Adapt a Neutral input port to a Xml output port
679 * \param inport : input port to adapt to Xml type type
680 * \param type : output port type
681 * \return an input port of type InputXmlPort
683 InputPort* RuntimeSALOME::adaptNeutralToXml(InputPort* inport,
684 TypeCode * type) throw (ConversionException)
686 // BEWARE : using the generic check
687 if(inport->edGetType()->isAdaptable(type))
690 return new XmlNeutral(inport);
692 //non convertible type
694 msg << "Cannot connect Neutral InputPort to OutputXmlPort : " ;
695 msg << "(" <<__FILE__ << ":" <<__LINE__<< ")";
696 throw ConversionException(msg.str());
699 //! Adapt a Neutral input port to a C++ output port
701 * \param inport : input port to adapt to C++ type type
702 * \param type : output port type
703 * \return an input port of type InputCppPort
705 InputPort* RuntimeSALOME::adaptNeutralToCpp(InputPort* inport,
706 TypeCode * type) throw (ConversionException)
708 DEBTRACE("RuntimeSALOME::adaptNeutralToCpp(InputPort* inport" );
709 if(isAdaptableNeutralCpp(type,inport->edGetType()))
712 return new CppNeutral(inport);
714 //non convertible type
716 msg << "Cannot connect Neutral " << inport->edGetType()->getKindRepr()
717 << " InputPort to " << type->getKindRepr() << " OutputCppPort : " ;
718 msg << "(" <<__FILE__ << ":" <<__LINE__<< ")";
719 throw ConversionException(msg.str());
722 //! Adapt a Neutral input port to connect it to an output port with a given implementation
724 * \param source : Neutral input port to adapt to implementation impl and type type
725 * \param impl : output port implementation (C++, Python, Corba, Xml or Neutral)
726 * \param type : output port supported type
727 * \return the adaptated port
729 InputPort* RuntimeSALOME::adaptNeutral(InputPort* source,
730 const std::string& impl,
731 TypeCode * type) throw (ConversionException)
733 if(impl == CppNode::IMPL_NAME)
735 return adaptNeutralToCpp(source,type);
737 else if(impl == PythonNode::IMPL_NAME)
739 return adaptNeutralToPython(source,type);
741 else if(impl == CORBANode::IMPL_NAME)
743 return adaptNeutralToCorba(source,type);
745 else if(impl == XmlNode::IMPL_NAME )
747 return adaptNeutralToXml(source,type);
749 else if(impl == Runtime::RUNTIME_ENGINE_INTERACTION_IMPL_NAME)
751 return new ProxyPort(source);
754 msg << "Cannot connect InputPort : unknown implementation " << impl;
755 msg << " (" <<__FILE__ << ":" <<__LINE__ << ")";
756 throw ConversionException(msg.str());
759 //! Adapt a XML input port to connect it to a CORBA output port
761 * \param inport : input port to adapt to CORBA type type
762 * \param type : type supported by output port
763 * \return an adaptator port of type InputCorbaPort
766 InputPort* RuntimeSALOME::adaptXmlToCorba(InputXmlPort* inport,
767 TypeCode * type) throw (ConversionException)
769 if(isAdaptableXmlCorba(type,inport->edGetType()))
771 //output type is convertible to input type
772 return new CorbaXml(inport);
774 //output type is not convertible
776 msg << "Cannot connect InputXmlPort to Corba output port " ;
777 msg << type->id() << " != " << inport->edGetType()->id();
778 msg << " ("__FILE__ << ":" << __LINE__ << ")";
779 throw ConversionException(msg.str());
782 //! Adapt a XML input port to a Python output port
784 * \param inport : input port to adapt to Python type type
785 * \param type : output port type
786 * \return an adaptated input port of type InputPyPort
788 InputPort* RuntimeSALOME::adaptXmlToPython(InputXmlPort* inport,
789 TypeCode * type) throw (ConversionException)
791 if(inport->edGetType()->isAdaptable(type))
793 //the output data is convertible to inport type
794 return new PyXml(inport);
796 //non convertible type
798 msg << "Cannot connect Xml InputPort to OutputPyPort : " ;
799 msg << "(" <<__FILE__ << ":" <<__LINE__<< ")";
800 throw ConversionException(msg.str());
803 //! Adapt a XML input port to a C++ output port
805 * \param inport : input port to adapt to C++ type type
806 * \param type : output port type
807 * \return an adaptated input port of type InputPyPort
809 InputPort* RuntimeSALOME::adaptXmlToCpp(InputXmlPort* inport,
810 TypeCode * type) throw (ConversionException)
812 DEBTRACE("RuntimeSALOME::adaptXmlToCpp(InputPort* inport" );
813 DEBTRACE(type->kind() << " " << inport->edGetType()->kind() );
814 if(type->isAdaptable(inport->edGetType()))
816 //the output data is convertible to inport type
817 return new CppXml(inport);
819 //non convertible type
821 msg << "Cannot connect Xml InputPort to OutputCppPort : " ;
822 msg << "(" <<__FILE__ << ":" <<__LINE__<< ")";
823 throw ConversionException(msg.str());
826 //! Adapt a XML input port to a Neutral output port
828 * \param inport : input port to adapt to Neutral type type
829 * \param type : output port type
830 * \return an adaptated input port of type Neutralxxxx
832 InputPort* RuntimeSALOME::adaptXmlToNeutral(InputXmlPort* inport,
833 TypeCode * type) throw (ConversionException)
835 if(inport->edGetType()->isAdaptable(type))
837 //the output data is convertible to inport type
838 return new NeutralXml(inport);
840 //non convertible type
842 msg << "Cannot connect Xml InputPort to OutputNeutralPort : " ;
843 msg << "(" <<__FILE__ << ":" <<__LINE__<< ")";
844 throw ConversionException(msg.str());
847 //! Adapt an Xml input port to an output port which implementation is given by impl
849 * \param source : input port to adapt to implementation impl and type type
850 * \param impl : output port implementation (C++, Python or Corba)
851 * \param type : output port supported type
852 * \return the adaptated port
855 InputPort* RuntimeSALOME::adapt(InputXmlPort* source,
856 const std::string& impl,
857 TypeCode * type) throw (ConversionException)
859 if(impl == CORBANode::IMPL_NAME)
861 return adaptXmlToCorba(source,type);
863 else if(impl == PythonNode::IMPL_NAME)
865 return adaptXmlToPython(source,type);
867 else if(impl == CppNode::IMPL_NAME)
869 return adaptXmlToCpp(source,type);
871 else if(impl == XmlNode::IMPL_NAME )
873 return new ProxyPort(source);
875 else if(impl == Runtime::RUNTIME_ENGINE_INTERACTION_IMPL_NAME)
877 return adaptXmlToNeutral(source,type);
882 msg << "Cannot connect InputXmlPort to " << impl << " implementation";
883 msg << " ("__FILE__ << ":" << __LINE__ << ")";
884 throw ConversionException(msg.str());
889 //! Adapt a CORBA input port to a CORBA output port
891 * \param inport : input port to adapt to CORBA outport data type
892 * \param type : outport data type
893 * \return an adaptator port of type InputCORBAPort
895 InputPort* RuntimeSALOME::adaptCorbaToCorba(InputCorbaPort* inport,
896 TypeCode * type) throw (ConversionException)
898 if(type->isA(inport->edGetType()))
900 //types are compatible : no conversion
901 //outport data type is more specific than inport required type
902 //so the inport can be used safely
903 return new ProxyPort(inport);
905 else if(isAdaptableCorbaCorba(type,inport->edGetType()))
907 //ouport data can be converted to inport data type
908 return new CorbaCorba(inport);
910 //outport data can not be converted
912 msg << "Cannot connect 2 CorbaPort with non convertible types: " ;
913 msg << type->id() << " != " << inport->edGetType()->id();
914 throw ConversionException(msg.str());
917 //! Adapt a CORBA input port to a Python output port
919 * \param inport : input port to adapt to Python type type
920 * \param type : outport data type
921 * \return an adaptator port of type InputPyPort
924 InputPort* RuntimeSALOME::adaptCorbaToPython(InputCorbaPort* inport,
925 TypeCode * type) throw (ConversionException)
927 if(inport->edGetType()->kind() == Double)
929 if(isAdaptableCorbaPyObject(type,inport->edGetType()))return new PyCorbaDouble(inport);
931 else if(inport->edGetType()->kind() == Int)
933 if(isAdaptableCorbaPyObject(type,inport->edGetType()))return new PyCorbaInt(inport);
935 else if(inport->edGetType()->kind() == String)
937 if(isAdaptableCorbaPyObject(type,inport->edGetType()))return new PyCorbaString(inport);
939 else if(inport->edGetType()->kind() == Bool)
941 if(isAdaptableCorbaPyObject(type,inport->edGetType()))return new PyCorbaBool(inport);
943 else if(inport->edGetType()->kind() == Objref )
945 if(isAdaptableCorbaPyObject(type,inport->edGetType()))
947 return new PyCorbaObjref(inport);
952 msg << "Cannot connect Python output port with type: " << type->id() ;
953 msg << " to CORBA input port " << inport->getName() << " with incompatible objref type: " << inport->edGetType()->id();
954 msg << " (" << __FILE__ << ":" <<__LINE__ << ")";
955 throw ConversionException(msg.str());
958 else if(inport->edGetType()->kind() == Sequence)
960 if(isAdaptableCorbaPyObject(type,inport->edGetType()))
962 return new PyCorbaSequence(inport);
967 msg << "Cannot convert this sequence type " ;
968 msg << __FILE__ << ":" <<__LINE__;
969 throw ConversionException(msg.str());
972 else if(inport->edGetType()->kind() == YACS::ENGINE::Struct)
974 if(isAdaptableCorbaPyObject(type,inport->edGetType()))
976 return new PyCorbaStruct(inport);
981 msg << "Cannot convert this struct type " << type->id() << " to " << inport->edGetType()->id();
982 msg << __FILE__ << ":" <<__LINE__;
983 throw ConversionException(msg.str());
986 // Adaptation not possible
988 msg << "Cannot connect Python output port with type: " << type->id() ;
989 msg << " to CORBA input port " << inport->getName() << " with type: " << inport->edGetType()->id();
990 msg << " (" << __FILE__ << ":" <<__LINE__ << ")";
991 throw ConversionException(msg.str());
994 //! Adapt a CORBA input port to connect it to a XML output port
996 * \param inport : input port to adapt to Xml type type
997 * \param type : type supported by output port
998 * \return an adaptator port of type InputXmlPort
1001 InputPort* RuntimeSALOME::adaptCorbaToXml(InputCorbaPort* inport,
1002 TypeCode * type) throw (ConversionException)
1004 // BEWARE : using the generic check
1005 if(inport->edGetType()->isAdaptable(type))
1007 //output type is convertible to input type
1008 return new XmlCorba(inport);
1010 //output type is not convertible
1012 msg << "Cannot connect InputCorbaPort with OutputXmlPort : " ;
1013 msg << __FILE__ << ":" <<__LINE__;
1014 throw ConversionException(msg.str());
1017 //! Adapt a CORBA input port to a C++ output port
1019 * \param inport : input port to adapt to C++ type type
1020 * \param type : outport data type
1021 * \return an adaptator port of type InputCPPPort
1024 InputPort* RuntimeSALOME::adaptCorbaToCpp(InputCorbaPort* inport,
1025 TypeCode * type) throw (ConversionException)
1027 DEBTRACE("RuntimeSALOME::adaptCorbaToCpp(InputCorbaPort* inport" );
1028 if(isAdaptableCorbaCpp(type,inport->edGetType()))
1030 //output type is convertible to input type
1031 return new CppCorba(inport);
1033 //output type is not convertible
1035 msg << "Cannot connect InputCorbaPort with OutputCppPort : " ;
1036 msg << __FILE__ << ":" <<__LINE__;
1037 throw ConversionException(msg.str());
1040 //! Adapt a CORBA input port to a neutral data
1042 * \param inport : InputPort to adapt to Neutral type type
1043 * \param type : outport data type
1044 * \return an adaptator port of type Neutralxxxx
1047 InputPort* RuntimeSALOME::adaptCorbaToNeutral(InputCorbaPort* inport,
1048 TypeCode * type) throw (ConversionException)
1050 if(inport->edGetType()->kind() == Double)
1052 if(isAdaptableCorbaNeutral(type,inport->edGetType()))return new NeutralCorbaDouble(inport);
1054 else if(inport->edGetType()->kind() == Int)
1056 if(isAdaptableCorbaNeutral(type,inport->edGetType()))return new NeutralCorbaInt(inport);
1058 else if(inport->edGetType()->kind() == String)
1060 if(isAdaptableCorbaNeutral(type,inport->edGetType())) return new NeutralCorbaString(inport);
1062 else if(inport->edGetType()->kind() == Bool)
1064 if(isAdaptableCorbaNeutral(type,inport->edGetType()))return new NeutralCorbaBool(inport);
1066 else if(inport->edGetType()->kind() == Objref)
1068 if(isAdaptableCorbaNeutral(type,inport->edGetType())) return new NeutralCorbaObjref(inport);
1070 else if(inport->edGetType()->kind() == Sequence)
1072 if(isAdaptableCorbaNeutral(type,inport->edGetType()))
1073 return new NeutralCorbaSequence(inport);
1077 msg << "Cannot convert this sequence type " ;
1078 msg << __FILE__ << ":" <<__LINE__;
1079 throw ConversionException(msg.str());
1083 // Adaptation not possible
1085 msg << "Cannot connect InputCorbaPort to Neutral output " ;
1086 msg << __FILE__ << ":" <<__LINE__;
1087 throw ConversionException(msg.str());
1090 //! Adapt a CORBA input port to an output which implementation and type are given by impl and type
1092 * \param source : input port to adapt to implementation impl and type type
1093 * \param impl : output port implementation (C++, Python or Corba)
1094 * \param type : outport data type
1095 * \return an adaptator port which type depends on impl
1098 InputPort* RuntimeSALOME::adapt(InputCorbaPort* source,
1099 const std::string& impl,
1100 TypeCode * type) throw (ConversionException)
1102 if(impl == CppNode::IMPL_NAME)
1104 return adaptCorbaToCpp(source,type);
1106 else if(impl == PythonNode::IMPL_NAME)
1108 return adaptCorbaToPython(source,type);
1110 else if(impl == CORBANode::IMPL_NAME)
1112 return adaptCorbaToCorba(source,type);
1114 else if(impl == XmlNode::IMPL_NAME )
1116 return adaptCorbaToXml(source,type);
1118 else if(impl == Runtime::RUNTIME_ENGINE_INTERACTION_IMPL_NAME)
1120 return adaptCorbaToNeutral(source,type);
1125 msg << "Cannot connect InputCorbaPort : unknown implementation " ;
1126 msg << __FILE__ << ":" <<__LINE__;
1127 throw ConversionException(msg.str());
1131 //! Adapt a Python input port to a Python output port
1133 * No need to make conversion or cast.
1134 * Only check, it's possible.
1135 * \param inport : InputPort to adapt to Python type type
1136 * \param type : outport data type
1137 * \return an adaptator port of type InputPyPort
1140 InputPort* RuntimeSALOME::adaptPythonToPython(InputPyPort* inport,
1141 TypeCode * type) throw (ConversionException)
1143 if(isAdaptablePyObjectPyObject(type,inport->edGetType()))
1145 //output data is convertible to input type
1146 //With python, no need to convert. Conversion will be done automatically
1147 //by the interpreter
1148 return new ProxyPort(inport);
1150 //output data is not convertible to input type
1152 msg << "Cannot connect Python output port with type: " << type->id() ;
1153 msg << " to Python input port " << inport->getName() << " with type: " << inport->edGetType()->id();
1154 msg << " ("<<__FILE__ << ":" << __LINE__<<")";
1155 throw ConversionException(msg.str());
1158 //! Adapt a Python input port to a C++ output port
1160 * \param inport : InputPort to adapt to C++ type type
1161 * \param type : outport data type
1162 * \return an adaptator port of C++ type (InputCppPort)
1165 InputPort* RuntimeSALOME::adaptPythonToCpp(InputPyPort* inport,
1166 TypeCode * type) throw (ConversionException)
1168 DEBTRACE("RuntimeSALOME::adaptPythonToCpp(InputPyPort* inport" );
1169 if(isAdaptablePyObjectCpp(type,inport->edGetType()))
1171 //output type is convertible to input type
1172 return new CppPy(inport);
1174 //output type is not convertible
1176 msg << "Cannot connect InputPythonPort with OutputCppPort : " ;
1177 msg << __FILE__ << ":" <<__LINE__;
1178 throw ConversionException(msg.str());
1181 //! Adapt a Python input port to a Neutral data port
1183 * \param inport : InputPort to adapt to Neutral type type
1184 * \param type : outport data type
1185 * \return an adaptator port of Neutral type (Neutralxxxx)
1188 InputPort* RuntimeSALOME::adaptPythonToNeutral(InputPyPort* inport,
1189 TypeCode * type) throw (ConversionException)
1191 if(inport->edGetType()->kind() == Double)
1193 if(isAdaptablePyObjectNeutral(type,inport->edGetType()))return new NeutralPyDouble(inport);
1195 else if(inport->edGetType()->kind() == Int)
1197 if(isAdaptablePyObjectNeutral(type,inport->edGetType()))return new NeutralPyInt(inport);
1199 else if(inport->edGetType()->kind() == String)
1201 if(isAdaptablePyObjectNeutral(type,inport->edGetType()))return new NeutralPyString(inport);
1203 else if(inport->edGetType()->kind() == Bool)
1205 if(isAdaptablePyObjectNeutral(type,inport->edGetType()))return new NeutralPyBool(inport);
1207 else if(inport->edGetType()->kind() == Objref)
1209 if(isAdaptablePyObjectNeutral(type,inport->edGetType()))return new NeutralPyObjref(inport);
1211 else if(inport->edGetType()->kind() == Sequence)
1213 if(isAdaptablePyObjectNeutral(type,inport->edGetType()))
1214 return new NeutralPySequence(inport);
1218 msg << "Cannot convert this sequence type " ;
1219 msg << __FILE__ << ":" <<__LINE__;
1220 throw ConversionException(msg.str());
1223 // Adaptation not possible
1225 msg << "Cannot connect InputPyPort to Neutral output " ;
1226 msg << "Output typeid: " << type->id() << " Input typeid: " << inport->edGetType()->id();
1227 msg << " ("__FILE__ << ":" << __LINE__ << ")";
1228 throw ConversionException(msg.str());
1231 //! Adapt a Python input port to a Corba output port
1233 * Always convert the data
1234 * \param inport : InputPort to adapt to Corba type type
1235 * \param type : outport data type
1236 * \return an adaptator port of Corba type (InputCorbaPort)
1239 InputPort* RuntimeSALOME::adaptPythonToCorba(InputPyPort* inport,
1240 TypeCode * type) throw (ConversionException)
1242 if(inport->edGetType()->kind() == Double)
1244 if(isAdaptablePyObjectCorba(type,inport->edGetType()))return new CorbaPyDouble(inport);
1246 else if(inport->edGetType()->kind() == Int)
1248 if(isAdaptablePyObjectCorba(type,inport->edGetType()))return new CorbaPyInt(inport);
1250 else if(inport->edGetType()->kind() == String)
1252 if(isAdaptablePyObjectCorba(type,inport->edGetType()))return new CorbaPyString(inport);
1254 else if(inport->edGetType()->kind() == Bool)
1256 if(isAdaptablePyObjectCorba(type,inport->edGetType()))return new CorbaPyBool(inport);
1258 else if(inport->edGetType()->kind() == Objref)
1260 if(isAdaptablePyObjectCorba(type,inport->edGetType()))
1262 return new CorbaPyObjref(inport);
1267 msg << "Cannot connect InputCorbaPort : incompatible objref types " << type->id() << " " << inport->edGetType()->id();
1268 msg << " " << __FILE__ << ":" <<__LINE__;
1269 throw ConversionException(msg.str());
1272 else if(inport->edGetType()->kind() == Sequence)
1274 if(isAdaptablePyObjectCorba(type,inport->edGetType()))
1276 return new CorbaPySequence(inport);
1281 msg << "Cannot convert this sequence type " ;
1282 msg << __FILE__ << ":" <<__LINE__;
1283 throw ConversionException(msg.str());
1286 else if(inport->edGetType()->kind() == YACS::ENGINE::Struct)
1288 if(isAdaptablePyObjectCorba(type,inport->edGetType()))
1290 return new CorbaPyStruct(inport);
1295 msg << "Cannot convert this struct type " << type->id() << " to " << inport->edGetType()->id();
1296 msg << " " << __FILE__ << ":" <<__LINE__;
1297 throw ConversionException(msg.str());
1300 // Adaptation not possible
1302 msg << "Cannot connect Corba output port with type: " << type->id() ;
1303 msg << " to Python input port " << inport->getName() << " with type: " << inport->edGetType()->id();
1304 msg << " ("__FILE__ << ":" << __LINE__ << ")";
1305 throw ConversionException(msg.str());
1308 //! Adapt a Python input port to a Xml output port
1310 * \param inport : input port to adapt to Xml type type
1311 * \param type : output port type
1312 * \return an input port of type InputXmlPort
1315 InputPort* RuntimeSALOME::adaptPythonToXml(InputPyPort* inport,
1316 TypeCode * type) throw (ConversionException)
1318 // BEWARE : using the generic check
1319 if(inport->edGetType()->isAdaptable(type))
1322 return new XmlPython(inport);
1324 //non convertible type
1326 msg << "Cannot connect InputPyPort with OutputXmlPort : " ;
1327 msg << "(" <<__FILE__ << ":" <<__LINE__<< ")";
1328 throw ConversionException(msg.str());
1331 //! Adapt a Python input port to an output port with a given implementation
1333 * \param source : input port to adapt to implementation impl and type type
1334 * \param impl : output port implementation (C++, Python or Corba)
1335 * \param type : output port type
1336 * \return adaptated input port
1339 InputPort* RuntimeSALOME::adapt(InputPyPort* source,
1340 const std::string& impl,
1341 TypeCode * type) throw (ConversionException)
1343 if(impl == CppNode::IMPL_NAME)
1345 return adaptPythonToCpp(source,type);
1347 else if(impl == PythonNode::IMPL_NAME)
1349 return adaptPythonToPython(source,type);
1351 else if(impl == CORBANode::IMPL_NAME)
1353 return adaptPythonToCorba(source,type);
1355 else if(impl == Runtime::RUNTIME_ENGINE_INTERACTION_IMPL_NAME)
1357 return adaptPythonToNeutral(source,type);
1359 else if(impl == XmlNode::IMPL_NAME)
1361 return adaptPythonToXml(source,type);
1366 msg << "Cannot connect InputPyPort : unknown implementation " << impl;
1367 msg << " ("<<__FILE__ << ":" << __LINE__<<")";
1368 throw ConversionException(msg.str());
1373 //! Adapt a C++ input port to connect it to a CORBA output port
1375 * \param inport : input port to adapt to CORBA type type
1376 * \param type : type supported by output port
1377 * \return an adaptator port of type InputCorbaPort
1380 InputPort* RuntimeSALOME::adaptCppToCorba(InputCppPort* inport,
1381 TypeCode * type) throw (ConversionException)
1383 DEBTRACE("RuntimeSALOME::adaptCppToCorba(InputCppPort* inport)");
1384 if(isAdaptableCppCorba(type,inport->edGetType()))
1386 //output type is convertible to input type
1387 return new CorbaCpp(inport);
1389 //output type is not convertible
1391 msg << "Cannot connect InputCppPort to Corba output port " ;
1392 msg << type->id() << " != " << inport->edGetType()->id();
1393 msg << " ("__FILE__ << ":" << __LINE__ << ")";
1394 throw ConversionException(msg.str());
1397 //! Adapt a C++ input port to a Python output port
1399 * \param inport : input port to adapt to Python type type
1400 * \param type : output port type
1401 * \return an adaptated input port of type InputPyPort
1403 InputPort* RuntimeSALOME::adaptCppToPython(InputCppPort* inport,
1404 TypeCode * type) throw (ConversionException)
1406 DEBTRACE("RuntimeSALOME::adaptCppToPython(InputCppPort* inport)");
1407 if(isAdaptableCppPyObject(type,inport->edGetType()))
1409 //output type is convertible to input type
1410 return new PyCpp(inport);
1412 //output type is not convertible
1414 msg << "Cannot connect InputCppPort with OutputPythonPort : " ;
1415 msg << __FILE__ << ":" <<__LINE__;
1416 throw ConversionException(msg.str());
1419 //! Adapt a C++ input port to a C++ output port
1421 * \param inport : input port to adapt to C++ type type
1422 * \param type : output port type
1423 * \return an adaptated input port of type InputPyPort
1425 InputPort* RuntimeSALOME::adaptCppToCpp(InputCppPort* inport,
1426 TypeCode * type) throw (ConversionException)
1428 DEBTRACE("RuntimeSALOME::adaptCppToCpp(InputPort* inport" );
1429 DEBTRACE(type->kind() << " " << inport->edGetType()->kind() );
1430 if(type->isAdaptable(inport->edGetType()))
1432 //the output data is convertible to inport type
1433 return new CppCpp(inport);
1435 //non convertible type
1437 msg << "Cannot connect Cpp InputPort to OutputCppPort : " ;
1438 msg << "(" <<__FILE__ << ":" <<__LINE__<< ")";
1439 throw ConversionException(msg.str());
1442 //! Adapt a C++ input port to a Neutral output port
1444 * \param inport : input port to adapt to C++ type type
1445 * \param type : output port type
1446 * \return an adaptated input port of type InputPyPort
1448 InputPort* RuntimeSALOME::adaptCppToNeutral(InputCppPort* inport,
1449 TypeCode * type) throw (ConversionException)
1451 DEBTRACE("RuntimeSALOME::adaptCppToNeutral(InputPort* inport" );
1452 DEBTRACE(type->kind() << " " << inport->edGetType()->kind() );
1453 if(type->isAdaptable(inport->edGetType()))
1455 //the output data is convertible to inport type
1456 return new NeutralCpp(inport);
1458 //non convertible type
1460 msg << "Cannot connect Cpp InputPort to OutputNeutralPort : " ;
1461 msg << "(" <<__FILE__ << ":" <<__LINE__<< ")";
1462 throw ConversionException(msg.str());
1465 InputPort* RuntimeSALOME::adaptCppToXml(InputCppPort* inport,
1466 TypeCode * type) throw (ConversionException)
1468 DEBTRACE("RuntimeSALOME::adaptCppToXml(InputCppPort* inport" );
1469 if(isAdaptableCppXml(type,inport->edGetType()))
1472 return new XmlCpp(inport);
1474 //non convertible type
1476 msg << "Cannot connect InputCppPort with OutputXmlPort : " ;
1477 msg << "(" <<__FILE__ << ":" <<__LINE__<< ")";
1478 throw ConversionException(msg.str());
1481 //! Adapt a C++ input port to connect it to an output port with a given implementation
1483 * \param source : input port to adapt to implementation impl and type type
1484 * \param impl : output port implementation (C++, Python or Corba)
1485 * \param type : output port supported type
1486 * \return the adaptated port
1489 InputPort* RuntimeSALOME::adapt(InputCppPort* source,
1490 const std::string& impl,
1491 TypeCode * type) throw (ConversionException)
1493 DEBTRACE("RuntimeSALOME::adapt(InputCppPort* source)");
1494 if(impl == CORBANode::IMPL_NAME)
1496 return adaptCppToCorba(source,type);
1498 else if(impl == PythonNode::IMPL_NAME)
1500 return adaptCppToPython(source,type);
1502 else if(impl == XmlNode::IMPL_NAME)
1504 return adaptCppToXml(source,type);
1506 else if(impl == CppNode::IMPL_NAME)
1508 return adaptCppToCpp(source, type);
1510 else if(impl == Runtime::RUNTIME_ENGINE_INTERACTION_IMPL_NAME)
1512 return adaptCppToNeutral(source, type);
1517 msg << "Cannot connect InputCppPort to " << impl << " implementation";
1518 msg << " ("__FILE__ << ":" << __LINE__ << ")";
1519 throw ConversionException(msg.str());
1523 // bool RuntimeSALOME::isCompatible(const OutputPort* outputPort,
1524 // const InputPort* inputPort)
1526 // bool result=true;
1530 CORBA::ORB_ptr RuntimeSALOME::getOrb()
1535 PyObject * RuntimeSALOME::getPyOrb()
1540 PyObject * RuntimeSALOME::getBuiltins()
1545 DynamicAny::DynAnyFactory_ptr RuntimeSALOME::getDynFactory()
1550 PyObject * RuntimeSALOME::get_omnipy()
1555 omniORBpyAPI* RuntimeSALOME::getApi()