1 // SUPERV GraphExecutor : contains classes that permit execution of graphs and particularly the execution automaton
3 // Copyright (C) 2003 CEA/DEN, EDF R&D
7 // File : DataFlowExecutor_PyDynInvoke.cxx
8 // Author : Jean Rahuel, CEA
17 #include "DataFlowExecutor_InNode.hxx"
18 #include "DataFlowExecutor_OutNode.hxx"
20 using namespace CORBA ;
22 extern GraphExecutor::FiniteStateMachine * theAutomaton ;
24 //static PyObject * MyPyObjSignal = NULL ;
25 static PyObject * MyPyObjRef = NULL ;
26 static PyObject * MyPyObjIor = NULL ;
27 static PyObject * MyPyRunMethod = NULL ;
29 static PyMethodDef MethodPyRunMethod[] = {
30 { "RunMethod", PyRunMethod, METH_VARARGS },
34 bool GraphExecutor::InNode::InitPython() {
35 cdebug_in << "InitPython" << endl ;
37 Automaton()->PyLock() ;
38 // PyObject * Module = Py_InitModule( "InitPyRunMethod" , MethodPyRunMethod ) ;
39 if ( !Automaton()->PyInitModule() ) {
40 Py_InitModule( "InitPyRunMethod" , MethodPyRunMethod ) ;
41 // asv : 20.01.05 : changes involved with switching to old (HEAD) KERNEL
42 //_OutNode->SuperVisionContainer()->ActivatePythonExecution( "InitPyRunMethod" , MethodPyRunMethod ) ;
44 // PyObject * Dictionnary = PyModule_GetDict( Module ) ;
45 // InitPyDynInvokeError = PyErr_NewException( "InitPyDynInvokeError" , NULL , NULL ) ;
46 // PyDict_SetItemString( Dictionnary , InitPyDynInvokeError ) ;
47 cdebug << ThreadNo() << "Py_Initialized() " << endl ;
50 //JR : Python documentation says that there is no sense to set a handler of synchronous
51 // signals as SIGSEGV and SIGFPE !!!
52 if ( Automaton()->PyFunction( "PyObjSignal" ) == NULL ) {
54 aPyFunc = "import signal\n" ;
55 aPyFunc += "import InitPyRunMethod\n" ;
56 aPyFunc += "import sys\n" ;
57 aPyFunc += "import CORBA\n" ;
58 aPyFunc += "import omniORB\n" ;
59 aPyFunc += "def PySignalHandler( aSignal , aStackFrame ) :\n" ;
60 aPyFunc += " print 'PySignalHandler(aSignal =',aSignal,',aStackFrame= ',aStackFrame,')'\n" ;
61 aPyFunc += "InitPyRunMethod.RunMethod( PySignalHandler )\n" ;
62 aPyFunc += "PrevHandler = signal.signal( signal.SIGSEGV , PySignalHandler )\n" ;
63 aPyFunc += "print 'PyObjSignal PrevHandler of SIGSEGV :', PrevHandler\n" ;
64 aPyFunc += "print 'PyObjSignal actual handler of SIGSEGV :', signal.getsignal( signal.SIGSEGV )\n" ;
65 // if ( PyRun_SimpleString( (char *) aPyFunc.c_str() ) ) {
66 if ( PyRunSimpleString( (char *) aPyFunc.c_str() ) ) {
67 cdebug << ThreadNo() << " " << Name() << " PyRun_SimpleString ERROR " << endl << aPyFunc << endl ;
68 Automaton()->PyUnLock() ;
71 MyPyObjSignal = MyPyRunMethod ;
72 Automaton()->PyFunction( "PyObjSignal" , MyPyObjSignal ) ;
75 MyPyObjSignal = Automaton()->PyFunction( "PyObjSignal" ) ;
79 // PyObjRef convert an IOR (string) to an Python ObjectReference
80 if ( Automaton()->PyFunction( "PyObjRef" ) == NULL ) {
82 aPyFunc = "import InitPyRunMethod\n" ;
83 aPyFunc += "import sys\n" ;
84 aPyFunc += "import CORBA\n" ;
85 aPyFunc += "import omniORB\n" ;
86 aPyFunc += "def PyObjRef( IORObjStr ) :\n" ;
87 aPyFunc += " orb = CORBA.ORB_init( sys.argv , CORBA.ORB_ID )\n" ;
88 aPyFunc += " objref = orb.string_to_object( IORObjStr )\n" ;
89 aPyFunc += " return objref\n" ;
90 aPyFunc += "InitPyRunMethod.RunMethod( PyObjRef )\n" ;
91 if ( PyRun_SimpleString( (char *) aPyFunc.c_str() ) ) {
92 // asv : 20.01.05 : changes involved with switching to old (HEAD) KERNEL
93 //if ( PyRunSimpleString( (char *) aPyFunc.c_str() ) ) {
94 cdebug << ThreadNo() << " " << Name() << " PyRun_SimpleString ERROR " << endl << aPyFunc << endl ;
95 Automaton()->PyUnLock() ;
98 MyPyObjRef = MyPyRunMethod ;
99 Automaton()->PyFunction( "PyObjRef" , MyPyObjRef ) ;
102 MyPyObjRef = Automaton()->PyFunction( "PyObjRef" ) ;
105 // PyObjRef convert an Python ObjectReference to an IOR (string)
106 if ( Automaton()->PyFunction( "PyObjIor" ) == NULL ) {
108 aPyFunc = "import InitPyRunMethod\n" ;
109 aPyFunc += "import sys\n" ;
110 aPyFunc += "import CORBA\n" ;
111 aPyFunc += "import omniORB\n" ;
112 aPyFunc += "def PyObjIor( ObjRef ) :\n" ;
113 aPyFunc += " orb = CORBA.ORB_init( sys.argv , CORBA.ORB_ID )\n" ;
114 aPyFunc += " objIor = orb.object_to_string( ObjRef )\n" ;
115 aPyFunc += " return objIor\n" ;
116 aPyFunc += "InitPyRunMethod.RunMethod( PyObjIor )\n" ;
117 if ( PyRun_SimpleString( (char *) aPyFunc.c_str() ) ) {
118 // asv : 20.01.05 : changes involved with switching to old (HEAD) KERNEL
119 //if ( PyRunSimpleString( (char *) aPyFunc.c_str() ) ) {
120 cdebug << ThreadNo() << " " << Name() << " PyRun_SimpleString ERROR " << endl << aPyFunc << endl ;
121 Automaton()->PyUnLock() ;
124 MyPyObjIor = MyPyRunMethod ;
125 Automaton()->PyFunction( "PyObjIor" , MyPyObjIor ) ;
128 MyPyObjIor = Automaton()->PyFunction( "PyObjIor" ) ;
130 Automaton()->PyUnLock() ;
132 cdebug_out << "InitPython" << endl ;
137 void GraphExecutor::InNode::RemovePyDynInvoke( char * PyFuncName ) {
138 // Automaton()->PyLock() ; // Already done ...
139 if ( Automaton()->ErasePyFunction( PyFuncName ) ) {
140 cdebug << "InNode::RemovePyDynInvoke( " << PyFuncName << " ) success" << endl ;
143 cdebug << "InNode::RemovePyDynInvoke( " << PyFuncName << " ) ERROR failed" << endl ;
145 // Automaton()->PyUnLock() ;
148 PyObject * GraphExecutor::InNode::InitPyDynInvoke( char * PyFuncName ,
149 const SUPERV::ListOfStrings * aPythonFunction ,
154 PyObject * thePyRunMethod = NULL ;
156 cdebug_in << "InitPyDynInvoke '" << PyFuncName << "' length " << (*aPythonFunction).length() << endl ;
158 if ( strlen( PyFuncName ) ) {
159 Automaton()->PyLock() ;
160 thePyRunMethod = Automaton()->PyFunction( PyFuncName ) ;
161 if ( (*aPythonFunction).length() ) {
162 if ( thePyRunMethod == NULL ) {
164 aPyFunc += "import InitPyRunMethod\n" ;
165 for ( i = 0 ; i < (*aPythonFunction).length() ; i++ ) {
166 aPyFunc += (*aPythonFunction)[ i ] ;
169 aPyFunc += "InitPyRunMethod.RunMethod( " ;
170 aPyFunc += PyFuncName ;
172 /*cdebug *///cout<< "InitPyDynInvoke PyRun_SimpleString " << endl << aPyFunc << endl ;
173 // if ( PyRun_SimpleString( (char *) aPyFunc.c_str() ) ) {
174 if ( PyRunSimpleString( (char *) aPyFunc.c_str() ) ) {
175 cdebug << ThreadNo() << " " << Name() << " PyRunSimpleString ERROR " << endl << aPyFunc << endl ;
176 PyFuncRunned( false ) ;
181 PyFuncRunned( true ) ;
182 thePyRunMethod = MyPyRunMethod ;
184 Automaton()->PyFunction( PyFuncName , thePyRunMethod ) ;
185 cdebug << ThreadNo() << "PyRunSimpleString( " << (*aPythonFunction)[ 0 ] << " ) " << endl ;
189 Automaton()->PyUnLock() ;
190 cdebug_out << "InitPyDynInvoke '" << PyFuncName << "' thePyRunMethod " << thePyRunMethod << " "
191 << thePyRunMethod->ob_refcnt << endl ;
192 return thePyRunMethod ;
195 else if ( thePyRunMethod ) {
196 Automaton()->PyUnLock() ;
197 cdebug_out << "InitPyDynInvoke '" << PyFuncName << "' thePyRunMethod " << thePyRunMethod << " "
198 << thePyRunMethod->ob_refcnt << endl ;
199 return thePyRunMethod ;
201 Automaton()->PyUnLock() ;
204 cdebug_out << "InitPyDynInvoke '" << PyFuncName << "' thePyRunMethod Null Err " << Err << endl ;
209 extern "C" PyObject * PyRunMethod( PyObject * dummy , PyObject * Args ) {
210 PyObject * Result = NULL ;
211 PyObject * Temp = NULL ;
212 if ( PyArg_ParseTuple( Args , "O:set_callback" , & Temp ) ) {
213 // cout << "PyArg_ParsedTuple" << endl ;
214 if ( !PyCallable_Check( Temp ) ) {
215 // PyErr_SetString( PyExc_TypeError , "PyRunMethod must be callable" ) ;
216 // cout << "PyRunMethod must be callable" << endl ;
220 Py_XDECREF( MyPyRunMethod ) ;
221 MyPyRunMethod = Temp ;
222 Py_INCREF( Py_None ) ;
228 #define PyDynInvokeTrace 1
229 bool GraphExecutor::InNode::PyDynInvoke( PyObject * MyPyRunMethod ,
231 ServicesAnyData * InParametersList , int nInParams ,
232 ServicesAnyData * OutParametersList , int nOutParams ) {
240 cdebug_in << ThreadNo() << "GraphExecutor::InNode::PyDynInvoke Node " << Name()
241 << " method " << method
242 << " InParametersList " << InParametersList
243 << " OutParametersList " << OutParametersList
244 << " " << nInParams << " InArgs " << nOutParams
245 << " OutArgs MyPyRunMethod " ;
247 if ( MyPyRunMethod ) {
249 cdebug << MyPyRunMethod << " " << MyPyRunMethod->ob_refcnt << endl ;
254 cdebug << " NULL" << endl ;
261 PyObject * ArgsList = NULL ;
262 PyObject * ArgValue = NULL ;
263 PyObject * Result = NULL ;
264 PyObject * MyPyObjRefList = NULL ;
265 PyObject * ResultObj = NULL ;
266 PyObject * MyPyObjIorList = NULL ;
267 PyObject * ResultIor = NULL ;
269 CORBA::Object_ptr ObjRef ;
273 if ( !PyCallable_Check( MyPyRunMethod ) ) {
278 ArgsList = PyTuple_New( nInParams ) ;
280 for ( i = 0 ; i < nInParams ; i++ ) {
281 data = InParametersList[i].Value ;
282 sname = InParametersList[i].Name.c_str() ;
283 switch ( data.type()->kind() ) {
284 case CORBA::tk_string : {
287 PyObject * ArgValue = Py_BuildValue( "s" , t ) ;
288 PyTuple_SetItem( ArgsList , i , ArgValue ) ;
290 cdebug << "ArgIn" << i << " : " << sname << " " << method << " Value " << t << " (string) "
291 << " ArgsList->ob_refcnt" << ArgsList->ob_refcnt << " ArgValue->ob_refcnt"
292 << ArgValue->ob_refcnt << endl ;
296 case CORBA::tk_boolean : {
298 data >>= (CORBA::Any::to_boolean ) b ;
299 PyObject * ArgValue = Py_BuildValue( "b" , b ) ;
300 PyTuple_SetItem( ArgsList , i , ArgValue ) ;
302 cdebug << "ArgIn" << i << " : " << sname << " " << method << " Value " << b
303 << " (boolean) ArgsList->ob_refcnt" << ArgsList->ob_refcnt << " ArgValue->ob_refcnt"
304 << ArgValue->ob_refcnt << endl ;
308 case CORBA::tk_char : {
310 data >>= (CORBA::Any::to_char ) c ;
311 PyObject * ArgValue = Py_BuildValue( "c" , c ) ;
312 PyTuple_SetItem( ArgsList , i , ArgValue ) ;
314 cdebug << "ArgIn" << i << " : " << sname << " " << method << " Value " << c
315 << " (char) ArgsList->ob_refcnt" << ArgsList->ob_refcnt << " ArgValue->ob_refcnt"
316 << ArgValue->ob_refcnt << endl ;
320 case CORBA::tk_short : {
323 PyObject * ArgValue = Py_BuildValue( "h" , s ) ;
324 PyTuple_SetItem( ArgsList , i , ArgValue ) ;
326 cdebug << "ArgIn" << i << " : " << sname << " " << method << " Value " << s
327 << " (short) ArgsList->ob_refcnt" << ArgsList->ob_refcnt << " ArgValue->ob_refcnt"
328 << ArgValue->ob_refcnt << endl ;
332 case CORBA::tk_long : {
335 PyObject * ArgValue = Py_BuildValue( "l" , l ) ;
337 cdebug << "ArgIn" << i << " : " << sname << " " << method << " Value " << l
338 << " ArgValue->ob_refcnt" << ArgValue->ob_refcnt << endl ;
340 PyTuple_SetItem( ArgsList , i , ArgValue ) ;
342 cdebug << "ArgIn" << i << " : " << sname << " " << method << " Value " << l
343 << " (long) ArgsList->ob_refcnt" << ArgsList->ob_refcnt << " ArgValue->ob_refcnt"
344 << ArgValue->ob_refcnt << endl ;
348 case CORBA::tk_float : {
351 PyObject * ArgValue = Py_BuildValue( "f" , f ) ;
352 PyTuple_SetItem( ArgsList , i , ArgValue ) ;
354 cdebug << "ArgIn" << i << " : " << sname << " " << method << " Value " << f
355 << " (float) ArgsList->ob_refcnt" << ArgsList->ob_refcnt << " ArgValue->ob_refcnt"
356 << ArgValue->ob_refcnt << endl ;
360 case CORBA::tk_double : {
363 PyObject * ArgValue = Py_BuildValue( "d" , d ) ;
364 PyTuple_SetItem( ArgsList , i , ArgValue ) ;
366 cdebug << "ArgIn" << i << " : " << sname << " " << method << " Value " << d
367 << " (double) ArgsList->ob_refcnt" << ArgsList->ob_refcnt << " ArgValue->ob_refcnt"
368 << ArgValue->ob_refcnt << endl ;
372 case CORBA::tk_objref : {
373 MyPyObjRefList = PyTuple_New( 1 ) ;
374 PyObject * ObjValue ;
375 #if OMNIORB_VERSION >= 4
376 data >>= (CORBA::Any::to_object ) ObjRef ;
380 IORObjRef = ObjectToString( ObjRef ) ;
381 ObjValue = Py_BuildValue( "s" , IORObjRef ) ;
382 PyTuple_SetItem( MyPyObjRefList , 0 , ObjValue ) ;
384 cdebug << "ArgIn" << i << " : " << sname << " " << method << " " << " Value " << IORObjRef << " (objref) "
385 << MyPyObjRef->ob_refcnt << "/" << MyPyObjRefList->ob_refcnt << endl ;
387 // ResultObj = PyEval_CallObject( MyPyObjRef , MyPyObjRefList ) ;
388 ResultObj = PyEvalCallObject( "PyObjRef" , MyPyObjRef , MyPyObjRefList ) ;
390 cdebug << "ObjValue->ob_refcnt" << ObjValue->ob_refcnt << endl ;
392 ArgValue = Py_BuildValue( "O" , ResultObj ) ;
393 PyTuple_SetItem( ArgsList , i , ArgValue ) ;
395 cdebug << "ArgIn" << i << " : " << sname << " " << method << " Value (objref) ArgsList->ob_refcnt"
396 << ArgsList->ob_refcnt << " ArgValue->ob_refcnt" << ArgValue->ob_refcnt << endl ;
397 cdebug << "MyPyObjRefList->ob_refcnt " << MyPyObjRefList->ob_refcnt-1 << endl ;
399 Py_DECREF( MyPyObjRefList ) ;
400 if ( CORBA::is_nil( ObjRef ) ) {
405 cdebug << "ResultObj->ob_refcnt " << ResultObj->ob_refcnt-1 << endl ;
407 Py_DECREF( ResultObj ) ;
412 cdebug << "ArgIn" << i << " : " << sname << " Value " << "(other ERROR)" << endl ;
417 // Result = PyEval_CallObject( MyPyRunMethod , ArgsList ) ;
418 Result = PyEvalCallObject( method , MyPyRunMethod , ArgsList ) ;
421 cdebug << "ArgsList->ob_refcnt" << ArgsList->ob_refcnt << endl ;
424 if ( Result == NULL ) {
425 cdebug_out << "GraphExecutor::InNode::PyDynInvoke Node " << Name() << " " << method << " Error Result == NULL"
430 for ( i = 0 ; i < nOutParams ; i++ ) {
431 data = OutParametersList[i].Value ;
432 sname = OutParametersList[i].Name.c_str() ;
433 switch ( data.type()->kind() ) {
434 case CORBA::tk_string : {
436 PyObject * ArgValue ;
437 if ( PyTuple_Check( Result ) ) {
438 ArgValue = PyTuple_GetItem( Result , i ) ;
443 if ( !PyString_Check( ArgValue ) ) {
444 cdebug << "ArgOut" << i << " : " << sname << " " << method << " ERROR (string)" << endl ;
448 t = PyString_AsString( ArgValue ) ;
452 cdebug << "ArgOut" << i << " : " << sname << " " << method << " Value " << t << " (string)"
453 << " Result->ob_refcnt" << Result->ob_refcnt << " ArgValue->ob_refcnt"
454 << ArgValue->ob_refcnt << endl ;
458 case CORBA::tk_boolean : {
460 PyObject * ArgValue ;
461 if ( PyTuple_Check( Result ) ) {
462 ArgValue = PyTuple_GetItem( Result , i ) ;
467 if ( !PyInt_Check( ArgValue ) ) {
468 cdebug << "ArgOut" << i << " : " << sname << " " << method << " ERROR (boolean)" << endl ;
472 b = PyInt_AsLong( ArgValue ) ;
474 data <<= (CORBA::Any::from_boolean ) b ;
476 cdebug << "ArgOut" << i << " : " << sname << " " << method << " Value " << b << " (boolean)"
477 << " Result->ob_refcnt" << Result->ob_refcnt << " ArgValue->ob_refcnt"
478 << ArgValue->ob_refcnt << endl ;
482 case CORBA::tk_char : {
483 unsigned char c = 0 ;
484 PyObject * ArgValue ;
485 if ( PyTuple_Check( Result ) ) {
486 ArgValue = PyTuple_GetItem( Result , i ) ;
491 //JR 04.04.2005 Debug if ( !PyInt_Check( ArgValue ) ) {
492 //Difficult to understand that behavior ... Python char type is a string of length 1 !
493 // or type is int ...
494 if ( !PyString_Check( ArgValue ) && !PyInt_Check( ArgValue ) ) {
495 cdebug << "ArgOut" << i << " : " << sname << " " << method << " ERROR (char)" << endl ;
499 c = PyInt_AsLong( ArgValue ) ;
501 data <<= (CORBA::Any::from_char ) c ;
503 cdebug << "ArgOut" << i << " : " << sname << " " << method << " Value " << c << " (char)"
504 << " Result->ob_refcnt" << Result->ob_refcnt << " ArgValue->ob_refcnt"
505 << ArgValue->ob_refcnt << endl ;
509 case CORBA::tk_short : {
511 PyObject * ArgValue ;
512 if ( PyTuple_Check( Result ) ) {
513 ArgValue = PyTuple_GetItem( Result , i ) ;
518 if ( !PyInt_Check( ArgValue ) ) {
519 cdebug << "ArgOut" << i << " : " << sname << " " << method << " ERROR (short)" << endl ;
523 s = PyInt_AsLong( ArgValue ) ;
527 cdebug << "ArgOut" << i << " : " << sname << " " << method << " Value " << s << " (short)"
528 << " Result->ob_refcnt" << Result->ob_refcnt << " ArgValue->ob_refcnt"
529 << ArgValue->ob_refcnt << endl ;
533 case CORBA::tk_long : {
535 PyObject * ArgValue ;
536 if ( PyTuple_Check( Result ) ) {
537 ArgValue = PyTuple_GetItem( Result , i ) ;
542 if ( PyLong_Check( ArgValue ) ) {
543 l = PyLong_AsLong( ArgValue ) ;
545 else if ( PyInt_Check( ArgValue ) ) {
546 l = PyInt_AsLong( ArgValue ) ;
549 cdebug << "ArgOut" << i << " : " << sname << " " << method << " ERROR (CORBA::tk_long)" << endl ;
554 cdebug << "ArgOut" << i << " : " << sname << " " << method << " Value " << l << " (long)"
555 << " Result->ob_refcnt" << Result->ob_refcnt << " ArgValue->ob_refcnt"
556 << ArgValue->ob_refcnt << endl ;
560 case CORBA::tk_float : {
562 PyObject * ArgValue ;
563 if ( PyTuple_Check( Result ) ) {
564 ArgValue = PyTuple_GetItem( Result , i ) ;
569 if ( !PyFloat_Check( ArgValue ) ) {
570 cdebug << "ArgOut" << i << " : " << sname << " " << method << " ERROR (float)" << endl ;
574 f = PyFloat_AsDouble( ArgValue ) ;
578 cdebug << "ArgOut" << i << " : " << sname << " " << method << " Value " << f << " (float)"
579 << " Result->ob_refcnt" << Result->ob_refcnt << " ArgValue->ob_refcnt"
580 << ArgValue->ob_refcnt << endl ;
584 case CORBA::tk_double : {
586 PyObject * ArgValue ;
587 if ( PyTuple_Check( Result ) ) {
588 ArgValue = PyTuple_GetItem( Result , i ) ;
593 if ( !PyFloat_Check( ArgValue ) ) {
594 cdebug << "ArgOut" << i << " : " << sname << " " << method << " ERROR (double)" << endl ;
598 d = PyFloat_AsDouble( ArgValue ) ;
602 cdebug << "ArgOut" << i << " : " << sname << " " << method << " Value " << d << " (double)"
603 << " Result->ob_refcnt" << Result->ob_refcnt << " ArgValue->ob_refcnt"
604 << ArgValue->ob_refcnt << endl ;
608 case CORBA::tk_objref : {
610 MyPyObjIorList = PyTuple_New( 1 ) ;
611 if ( PyTuple_Check( Result ) ) {
612 ObjIor = PyTuple_GetItem( Result , i ) ;
618 cdebug << "ArgOut" << i << " : " << sname << " " << method << " Value " << "(object reference) "
619 << " Result->ob_refcnt" << Result->ob_refcnt << " ObjIor->ob_refcnt"
620 << ObjIor->ob_refcnt << endl ;
622 Py_INCREF( ObjIor ) ;
623 // PyObject_Print( ObjIor , stdout , 0 ) ;
624 PyTuple_SetItem( MyPyObjIorList , 0 , ObjIor ) ;
625 // ResultIor = PyEval_CallObject( MyPyObjIor , MyPyObjIorList ) ;
626 ResultIor = PyEvalCallObject( "PyObjIor" , MyPyObjIor , MyPyObjIorList ) ;
628 cdebug << "ObjIor->ob_refcnt " << ObjIor->ob_refcnt-1 << endl ;
630 Py_DECREF( ObjIor ) ;
632 cdebug << "MyPyObjIorList->ob_refcnt " << MyPyObjIorList->ob_refcnt-1 << endl ;
634 Py_DECREF( MyPyObjIorList ) ;
636 cdebug << "MyPyObjIor->ob_refcnt " << MyPyObjIor->ob_refcnt << endl ;
640 IOR = PyString_AsString( ResultIor ) ;
641 ObjRef = StringToObject( IOR ) ;
642 //JR 05.08.2005 BUG OMNIORB4 ? : that line does run with SALOME_3 (OMNIOrb4) for
643 // object references ... (It's Ok with OMNIOrb3)
644 // IOR and ObjRef and IORObjRef are Ok
645 // BUT data contains a nil reference !!!
649 SUPERV::SuperG_var mySuperVisionComponent ;
650 mySuperVisionComponent = theAutomaton->SuperVisionComponent() ;
651 if ( CORBA::is_nil( mySuperVisionComponent ) ) {
652 Engines::Container_var myContainer ;
653 Engines::Component_var myObjComponent ;
654 _OutNode->Graph()->StartComponent( ThreadNo() , "SuperVisionContainer" ,
656 myContainer , myObjComponent ) ;
657 mySuperVisionComponent = SUPERV::SuperG::_narrow( myObjComponent ) ;
658 theAutomaton->SuperVisionComponent( mySuperVisionComponent ) ;
660 //JR 24.08.2005 BUG OMNIORB4 ? : That does not run also ==> Comments
661 // CORBA::Object_ptr ObjRef1 ;
662 // ObjRef1 = mySuperVisionComponent->ToObject( ObjRef ) ;
663 // data <<= ObjRef1 ;
664 //JR 24.08.2005 BUG OMNIORB4 ? : BUT THAT RUNS WITH THE "IDENTITY METHOD ToObject of SUPERV.idl :
665 // Object ToObject( in Object anObject ) ;
666 //CODE of that method !!! :
667 //CORBA::Object_ptr SuperV_Impl::ToObject( CORBA::Object_ptr anObjectRef ) {
668 // beginService( "SuperV_Impl::ToObject" );
669 // CORBA::Object_ptr anObject ;
670 // anObject = CORBA::Object::_duplicate( anObjectRef ) ;
671 // endService( "SuperV_Impl::ToObject" );
674 //BUT THAT RUNS ONLY IF WE USE Dynamic invocation of CORBA (DynInvoke)
675 ServicesAnyData anInParametersList ;
676 anInParametersList.Name = "anObjRef" ;
677 anInParametersList.Value <<= ObjRef ;
678 DynInvoke( mySuperVisionComponent , "ToObject" ,
679 &anInParametersList , 1 , &OutParametersList[i] , 1 ) ;
680 data = OutParametersList[i].Value ;
682 IORObjRef = ObjectToString( ObjRef ) ;
684 cdebug << "ArgOut" << i << " : " << sname << " " << method << " Value IORPy "
685 << IOR << " IORObjRef " << IORObjRef << " (objref) " << endl ;
687 if ( CORBA::is_nil( ObjRef ) ) {
689 cdebug << "ObjRef ERROR(nil reference) ResultIor->ob_refcnt "
690 << ResultIor->ob_refcnt-1 << endl ;
696 cdebug << "ObjRef NOT(nil reference)ResultIor->ob_refcnt "
697 << ResultIor->ob_refcnt-1 << endl ;
699 Py_DECREF( ResultIor ) ;
703 cdebug_out << "GraphExecutor::InNode::PyDynInvoke Error ResultIor == NULL Node "
704 << Name() << " method " << method << " " << endl ;
710 cdebug << "ArgOut" << i << " : " << sname << " " << method << " Value " << "(other ERROR)" << endl ;
714 //JR 05.08.2005 BUG OMNIORB4 ? : that line does run with SALOME_3 (OMNIOrb4) for
715 // object references ...
716 OutParametersList[i].Value = data ;
717 // if ( data.type()->kind() == CORBA::tk_objref ) {
718 // IORObjRef = ObjectToString( ObjRef ) ;
719 //#if PyDynInvokeTrace
720 // cdebug << ThreadNo() << "GraphExecutor::InNode::PyDynInvoke Node " << Name()
721 // << "ArgOut" << i << " : " << sname << " " << method << " ObjRef "
722 // << IORObjRef << " (objref) " << endl ;
723 // Engines::Component_var theObjComponent ;
724 // theObjComponent = Engines::Component::_narrow( ObjRef ) ;
725 // DynInvoke( theObjComponent , "ping" , NULL , 0 , NULL , 0 ) ;
727 // Engines::Container_var myContainer ;
728 // Engines::Component_var myObjComponent ;
729 // _OutNode->Graph()->StartComponent( ThreadNo() , "SuperVisionContainer" ,
731 // myContainer , myObjComponent ) ;
732 // SUPERV::SuperG_var mySuperVisionComponent ;
733 // mySuperVisionComponent = SUPERV::SuperG::_narrow( myObjComponent ) ;
734 // CORBA::Object_ptr ObjRef1 ;
735 // ObjRef1 = mySuperVisionComponent->ToObject( IORObjRef ) ;
736 //#if PyDynInvokeTrace
737 // IORObjRef = ObjectToString( ObjRef1 ) ;
738 // cdebug << ThreadNo() << "GraphExecutor::InNode::PyDynInvoke Node " << Name()
739 // << "ArgOut" << i << " : " << sname << " " << method << " ToObject "
740 // << IORObjRef << " (objref) " << endl ;
743 // ServicesAnyData anInParametersList ;
744 // anInParametersList.Name = "anIORObjRef" ;
745 // anInParametersList.Value <<= IORObjRef ;
746 // DynInvoke( mySuperVisionComponent , "ToObject" ,
747 // &anInParametersList , 1 , &OutParametersList[i] , 1 ) ;
748 //#if PyDynInvokeTrace
749 // OutParametersList[i].Value >>= ObjRef1 ;
750 // IORObjRef = ObjectToString( ObjRef1 ) ;
751 // cdebug << ThreadNo() << "GraphExecutor::InNode::PyDynInvoke Node " << Name()
752 // << "ArgOut" << i << " : " << sname << " " << method
753 // << " DynInvoke(ToObject) " << IORObjRef << " (objref) " << endl ;
759 cdebug << "InNode::PyDynInvoke Result->ob_refcnt " << Result->ob_refcnt-1 << endl ;
761 Py_DECREF( Result ) ;
765 cdebug << "InNode::PyDynInvoke ArgsList->ob_refcnt " << ArgsList->ob_refcnt-1 << endl ;
767 Py_DECREF( ArgsList ) ;
773 for ( i = 0 ; i < nInParams ; i++ ) { // Without Gates
774 cdebug << "InParametersList[" << i << "] : "
775 << InParametersList[i].Name << " "
776 << AnyValue( InParametersList[i].Value ) << endl ;
778 for ( i = 0 ; i < nOutParams ; i++ ) { // Without Gates
779 cdebug << "OutParametersList[" << i << "] : "
780 << OutParametersList[i].Name << " "
781 << AnyValue( OutParametersList[i].Value ) << endl ;
787 cdebug_out << "GraphExecutor::InNode::PyDynInvoke Node " << Name() << " method " << method << " " << RetVal
795 bool GraphExecutor::InNode::PyRunSimpleString( char* thePyString )
797 const bool ErrorValue = true;
801 MESSAGE( pthread_self() << "Python method beginning : " << thePyString );
802 cdebug_in << pthread_self() << "Python method beginning : " << thePyString << endl ;
804 aRet = PyRun_SimpleString( thePyString );
805 // asv : 20.01.05 : changes involved with switching to old (HEAD) KERNEL
806 //aRet = _OutNode->SuperVisionContainer()->ActivatePythonExecution( thePyString ) ;
808 MESSAGE( pthread_self() << "Python method finished." );
809 cdebug_out << pthread_self() << "Python method finished." << endl ;
812 MESSAGE( pthread_self() << "ERROR: Exception caught running Python method." );
813 cdebug_out << pthread_self() << "ERROR: Exception caught running Python method."
815 MESSAGE( " Python was reinitialized. Previous Python definitions are lost" );
816 // asv : 20.01.05 : changes involved with switching to old (HEAD) KERNEL
819 Py_InitModule( "InitPyRunMethod" , MethodPyRunMethod );
820 _OutNode->PyInitialized( false );
826 PyObject * GraphExecutor::InNode::PyEvalCallObject( const char *method ,
827 PyObject * MyPyRunMethod ,
828 PyObject * ArgsList ) {
829 // cdebug_in << "Executor::InNode::PyEvalCallObject " << Name() << endl ;
830 PyObject * Result = NULL ;
832 // MESSAGE( pthread_self() << "PyEval_CallObject " << Name() << " method beginning : " << method );
833 // cdebug << pthread_self() << "PyEval_CallObject " << Name() << " method beginning : " << method << endl ;
834 Result = PyEval_CallObject( MyPyRunMethod , ArgsList ) ;
835 // asv : 20.01.05 : changes involved with switching to old (HEAD) KERNEL
836 //Result = _OutNode->SuperVisionContainer()->ActivatePythonExecution( MyPyRunMethod , ArgsList ) ;
837 // MESSAGE( pthread_self() << "PyEval_CallObject method finished. Result " << Result );
838 // cdebug << pthread_self() << "PyEval_CallObject method finished. Result " << Result << endl ;
839 // cdebug_out << "Executor::InNode::PyEvalCallObject " << Name() << endl ;
841 MESSAGE( pthread_self() << "ERROR: Exception caught PyEval_CallObject " << Name()
842 << " Python method " << method << ". Result " << Result );
843 cdebug << pthread_self() << "ERROR: Exception caught PyEval_CallObject " << Name()
844 << " Python method " << method << ". Result " << Result << endl ;
845 MESSAGE( " Python was reinitialized. Previous Python definitions are lost Py_IsInitialized " << Py_IsInitialized() );
846 //JR ===> fatal error in python : no current thread
847 // asv : 20.01.05 : changes involved with switching to old (HEAD) KERNEL
850 Automaton()->PyInitModule( false ) ;
851 Py_InitModule( "InitPyRunMethod" , MethodPyRunMethod );
852 _OutNode->PyInitialized( false );
854 if ( Result == NULL ) {
855 Kill() ; // Reset of _ThreadId
857 // cdebug << "Executor::InNode::PyEvalCallObject ERROR catched " << Name()
858 // << " Py_IsInitialized " << Py_IsInitialized() << endl ;
860 // cdebug_out << "Executor::InNode::PyEvalCallObject " << Name() << endl ;