+// SUPERV GraphExecutor : contains classes that permit execution of graphs and particularly the execution automaton
+//
+// Copyright (C) 2003 CEA/DEN, EDF R&D
+//
+//
+//
+// File : DataFlowExecutor_PyDynInvoke.cxx
+// Author : Jean Rahuel, CEA
+// Module : SUPERV
+// $Header:
+
using namespace std;
-//=============================================================================
-// File : DataFlowExecutor_PyDynInvoke.cxx
-// Created : 2003
-// Author : Jean Rahuel, CEA
-// Project : SALOME
-// $Header:
-//=============================================================================
#include <stdarg.h>
#include <map>
bool GraphExecutor::InNode::InitPython() {
cdebug_in << "InitPython" << endl ;
-
- PyObject * Module = Py_InitModule( "InitPyRunMethod" , MethodPyRunMethod ) ;
- PyObject * Dictionnary = PyModule_GetDict( Module ) ;
+
+ Automaton()->PyLock() ;
+// PyObject * Module = Py_InitModule( "InitPyRunMethod" , MethodPyRunMethod ) ;
+ if ( !Automaton()->PyInitModule() ) {
+ Py_InitModule( "InitPyRunMethod" , MethodPyRunMethod ) ;
+ }
+// PyObject * Dictionnary = PyModule_GetDict( Module ) ;
// InitPyDynInvokeError = PyErr_NewException( "InitPyDynInvokeError" , NULL , NULL ) ;
// PyDict_SetItemString( Dictionnary , InitPyDynInvokeError ) ;
cdebug << ThreadNo() << "Py_Initialized() " << endl ;
- string aPyFunc ;
- aPyFunc = "print 'InitPyRunMethod'\n" ;
- aPyFunc += "import InitPyRunMethod\n" ;
- aPyFunc += "print 'sys'\n" ;
- aPyFunc += "import sys\n" ;
- aPyFunc += "print 'CORBA'\n" ;
- aPyFunc += "import CORBA\n" ;
- aPyFunc += "print 'omniORB'\n" ;
- aPyFunc += "import omniORB\n" ;
- aPyFunc += "print 'PyObjRef'\n" ;
- aPyFunc += "def PyObjRef( IORObjStr ) :\n" ;
-// aPyFunc += " print 'PyObjRef',IORObjStr\n" ;
- aPyFunc += " orb = CORBA.ORB_init( sys.argv , CORBA.ORB_ID )\n" ;
- aPyFunc += " objref = orb.string_to_object( IORObjStr )\n" ;
-// aPyFunc += " print IORObjStr,objref\n" ;
-// aPyFunc += " return objref,objref\n" ;
- aPyFunc += " return objref\n" ;
- aPyFunc += "InitPyRunMethod.RunMethod( PyObjRef )\n" ;
- if ( PyRun_SimpleString( (char *) aPyFunc.c_str() ) ) {
- cdebug << ThreadNo() << " PyRun_SimpleString ERROR " << endl << aPyFunc << endl ;
- return false ;
+ if ( Automaton()->PyFunction( "PyObjRef" ) == NULL ) {
+ string aPyFunc ;
+// aPyFunc = "print 'InitPyRunMethod'\n" ;
+ aPyFunc = "import InitPyRunMethod\n" ;
+// aPyFunc += "print 'sys'\n" ;
+ aPyFunc += "import sys\n" ;
+// aPyFunc += "print 'CORBA'\n" ;
+ aPyFunc += "import CORBA\n" ;
+// aPyFunc += "print 'omniORB'\n" ;
+ aPyFunc += "import omniORB\n" ;
+// aPyFunc += "print 'PyObjRef'\n" ;
+ aPyFunc += "def PyObjRef( IORObjStr ) :\n" ;
+// aPyFunc += " print 'PyObjRef',IORObjStr\n" ;
+ aPyFunc += " orb = CORBA.ORB_init( sys.argv , CORBA.ORB_ID )\n" ;
+// aPyFunc += " print 'PyObjRef orb',orb\n" ;
+ aPyFunc += " objref = orb.string_to_object( IORObjStr )\n" ;
+// aPyFunc += " print 'PyObjRef IORObjStr objref',IORObjStr,objref\n" ;
+ aPyFunc += " return objref\n" ;
+ aPyFunc += "InitPyRunMethod.RunMethod( PyObjRef )\n" ;
+ if ( PyRun_SimpleString( (char *) aPyFunc.c_str() ) ) {
+ cdebug << ThreadNo() << " " << Name() << " PyRun_SimpleString ERROR " << endl << aPyFunc << endl ;
+ Automaton()->PyUnLock() ;
+ return false ;
+ }
+ MyPyObjRef = MyPyRunMethod ;
+ Automaton()->PyFunction( "PyObjRef" , MyPyObjRef ) ;
}
- MyPyObjRef = MyPyRunMethod ;
-
- aPyFunc = "import InitPyRunMethod\n" ;
- aPyFunc += "import sys\n" ;
- aPyFunc += "import CORBA\n" ;
- aPyFunc += "import omniORB\n" ;
- aPyFunc += "def PyObjIor( ObjRef ) :\n" ;
-// aPyFunc += " print 'PyObjIor',ObjRef\n" ;
- aPyFunc += " orb = CORBA.ORB_init( sys.argv , CORBA.ORB_ID )\n" ;
-// aPyFunc += " print 'PyObjIor',orb\n" ;
- aPyFunc += " objIor = orb.object_to_string( ObjRef )\n" ;
-// aPyFunc += " print 'PyObjIor',ObjRef,objIor\n" ;
- aPyFunc += " return objIor\n" ;
- aPyFunc += "InitPyRunMethod.RunMethod( PyObjIor )\n" ;
- if ( PyRun_SimpleString( (char *) aPyFunc.c_str() ) ) {
- cdebug << ThreadNo() << " PyRun_SimpleString ERROR " << endl << aPyFunc << endl ;
- return false ;
+ else {
+ MyPyObjRef = Automaton()->PyFunction( "PyObjRef" ) ;
+ }
+
+ if ( Automaton()->PyFunction( "PyObjIor" ) == NULL ) {
+ string aPyFunc ;
+ aPyFunc = "import InitPyRunMethod\n" ;
+ aPyFunc += "import sys\n" ;
+ aPyFunc += "import CORBA\n" ;
+ aPyFunc += "import omniORB\n" ;
+ aPyFunc += "def PyObjIor( ObjRef ) :\n" ;
+// aPyFunc += " print 'PyObjIor',ObjRef\n" ;
+ aPyFunc += " orb = CORBA.ORB_init( sys.argv , CORBA.ORB_ID )\n" ;
+// aPyFunc += " print 'PyObjIor orb',orb\n" ;
+ aPyFunc += " objIor = orb.object_to_string( ObjRef )\n" ;
+// aPyFunc += " print 'PyObjIor ObjRef objIor',ObjRef,objIor\n" ;
+ aPyFunc += " return objIor\n" ;
+ aPyFunc += "InitPyRunMethod.RunMethod( PyObjIor )\n" ;
+ if ( PyRun_SimpleString( (char *) aPyFunc.c_str() ) ) {
+ cdebug << ThreadNo() << " " << Name() << " PyRun_SimpleString ERROR " << endl << aPyFunc << endl ;
+ Automaton()->PyUnLock() ;
+ return false ;
+ }
+ MyPyObjIor = MyPyRunMethod ;
+ Automaton()->PyFunction( "PyObjIor" , MyPyObjIor ) ;
+ }
+ else {
+ MyPyObjIor = Automaton()->PyFunction( "PyObjIor" ) ;
}
- MyPyObjIor = MyPyRunMethod ;
+ Automaton()->PyUnLock() ;
cdebug_out << "InitPython" << endl ;
+
return true ;
}
-PyObject * GraphExecutor::InNode::InitPyDynInvoke(
- char * PyFuncName ,
- const SUPERV::ListOfStrings * aPythonFunction ) {
+PyObject * GraphExecutor::InNode::InitPyDynInvoke( char * PyFuncName ,
+ const SUPERV::ListOfStrings * aPythonFunction ) {
bool RetVal = true ;
string aPyFunc ;
+ PyObject * thePyRunMethod = NULL ;
- cdebug_in << "InitPyDynInvoke '" << PyFuncName << "' length "
- << (*aPythonFunction).length() << endl ;
+ cdebug_in << "InitPyDynInvoke '" << PyFuncName << "' length " << (*aPythonFunction).length() << endl ;
- if ( (*aPythonFunction).length() ) {
- int i ;
- aPyFunc += "import InitPyRunMethod\n" ;
- for ( i = 0 ; i < (*aPythonFunction).length() ; i++ ) {
- aPyFunc += (*aPythonFunction)[ i ] ;
- aPyFunc += "\n" ;
- }
- aPyFunc += "InitPyRunMethod.RunMethod( " ;
- aPyFunc += PyFuncName ;
- aPyFunc += " )\n" ;
- cdebug << "InitPyDynInvoke PyRun_SimpleString " << endl << aPyFunc << endl ;
- if ( PyRun_SimpleString( (char *) aPyFunc.c_str() ) ) {
- cdebug << ThreadNo() << " PyRun_SimpleString ERROR " << endl << aPyFunc << endl ;
- RetVal = false ;
- }
- else {
- PyFuncRunned( true ) ;
-// _MyPyRunMethod = MyPyRunMethod ; // To mutex
- cdebug << ThreadNo() << "PyRun_SimpleString( " << (*aPythonFunction)[ 0 ]
- << " )" << endl ;
+ if ( strlen( PyFuncName ) ) {
+ Automaton()->PyLock() ;
+ thePyRunMethod = Automaton()->PyFunction( PyFuncName ) ;
+ if ( (*aPythonFunction).length() ) {
+ if ( thePyRunMethod == NULL ) {
+ unsigned int i ;
+ aPyFunc += "import InitPyRunMethod\n" ;
+ for ( i = 0 ; i < (*aPythonFunction).length() ; i++ ) {
+ aPyFunc += (*aPythonFunction)[ i ] ;
+ aPyFunc += "\n" ;
+ }
+ aPyFunc += "InitPyRunMethod.RunMethod( " ;
+ aPyFunc += PyFuncName ;
+ aPyFunc += " )\n" ;
+ /*cdebug *///cout<< "InitPyDynInvoke PyRun_SimpleString " << endl << aPyFunc << endl ;
+ if ( PyRun_SimpleString( (char *) aPyFunc.c_str() ) ) {
+ cdebug << ThreadNo() << " " << Name() << " PyRun_SimpleString ERROR " << endl << aPyFunc << endl ;
+ RetVal = false ;
+ }
+ else {
+ PyFuncRunned( true ) ;
+ thePyRunMethod = MyPyRunMethod ;
+
+ Automaton()->PyFunction( PyFuncName , thePyRunMethod ) ;
+ cdebug << ThreadNo() << "PyRun_SimpleString( " << (*aPythonFunction)[ 0 ] << " ) " << endl ;
+ }
+ }
+ if ( RetVal ) {
+ Automaton()->PyUnLock() ;
+ cdebug_out << "InitPyDynInvoke '" << PyFuncName << "' thePyRunMethod " << thePyRunMethod << " "
+ << thePyRunMethod->ob_refcnt << endl ;
+ return thePyRunMethod ;
+ }
}
- cdebug_out << "InitPyDynInvoke" << endl ;
- if ( RetVal ) {
- return MyPyRunMethod ;
+ else if ( thePyRunMethod ) {
+ Automaton()->PyUnLock() ;
+ cdebug_out << "InitPyDynInvoke '" << PyFuncName << "' thePyRunMethod " << thePyRunMethod << " "
+ << thePyRunMethod->ob_refcnt << endl ;
+ return thePyRunMethod ;
}
+ Automaton()->PyUnLock() ;
}
+ cdebug_out << "InitPyDynInvoke '" << PyFuncName << "' thePyRunMethod Null" << endl ;
+
return NULL ;
}
extern "C" PyObject * PyRunMethod( PyObject * dummy , PyObject * Args ) {
-// cout << "PyRunMethod -->" << endl ;
PyObject * Result = NULL ;
PyObject * Temp = NULL ;
if ( PyArg_ParseTuple( Args , "O:set_callback" , & Temp ) ) {
Py_INCREF( Py_None ) ;
Result = Py_None ;
}
-// cout << "<-- PyRunMethod" << endl ;
return Result ;
}
int n_out = nOutParams ;
const char * sname;
- cdebug_in << "GraphExecutor::InNode::PyDynInvoke " << method << endl ;
+ cdebug_in << ThreadNo() << "GraphExecutor::InNode::PyDynInvoke Node " << Name() << " method " << method
+ << " " << n_in << " InArgs " << n_out << " OutArgs MyPyRunMethod " ;
+ if ( MyPyRunMethod ) {
+ cdebug << MyPyRunMethod << " " << MyPyRunMethod->ob_refcnt << endl ;
+ }
+ else {
+ cdebug << " NULL" << endl ;
+ return false ;
+ }
CORBA::Any data ;
PyObject * ArgsList = NULL ;
- PyObject * ArgValue ;
- PyObject * ArgResult ;
- PyObject * Result ;
+ PyObject * ArgValue = NULL ;
+ PyObject * Result = NULL ;
PyObject * MyPyObjRefList = NULL ;
PyObject * ResultObj = NULL ;
PyObject * MyPyObjIorList = NULL ;
PyObject * ResultIor = NULL ;
- ArgsList = PyTuple_New( n_in ) ;
CORBA::Object_ptr ObjRef ;
char * IORObjRef ;
- for ( i = 0 ; i < n_in ; i++ ) {
- data = inParams[i].Value ;
- sname = inParams[i].Name.c_str() ;
- switch ( data.type()->kind() ) {
- case CORBA::tk_string : {
- char * t ;
- data >>= t ;
- ArgValue = Py_BuildValue( "s" , t ) ;
- PyTuple_SetItem( ArgsList , i , ArgValue ) ;
- cdebug << "ArgIn" << i << " : " << sname << " Value " << t << " (string) "
- << ArgsList->ob_refcnt << endl ;
- break ;
- }
- case CORBA::tk_double : {
- double d ;
- data >>= d ;
- ArgValue = Py_BuildValue( "d" , d ) ;
- PyTuple_SetItem( ArgsList , i , ArgValue ) ;
- cdebug << "ArgIn" << i << " : " << sname << " Value " << d << " (double) "
- << ArgsList->ob_refcnt << endl ;
- break ;
- }
- case CORBA::tk_long : {
- long l ;
- data >>= l ;
- ArgValue = Py_BuildValue( "l" , l ) ;
- PyTuple_SetItem( ArgsList , i , ArgValue ) ;
- cdebug << "ArgIn" << i << " : " << sname << " Value " << l
- << " (long) ArgsList->ob_refcnt" << ArgsList->ob_refcnt << endl ;
- break ;
- }
- case CORBA::tk_objref : {
- MyPyObjRefList = PyTuple_New( 1 ) ;
- PyObject * ObjValue ;
- data >>= ObjRef ;
- IORObjRef = ObjectToString( ObjRef ) ;
- ObjValue = Py_BuildValue( "s" , IORObjRef ) ;
- PyTuple_SetItem( MyPyObjRefList , 0 , ObjValue ) ;
- cdebug << "ArgIn" << i << " : " << sname << " Value " << IORObjRef << " (objref) "
- << MyPyObjRefList->ob_refcnt << endl ;
- ResultObj = PyEval_CallObject( MyPyObjRef , MyPyObjRefList ) ;
- cdebug << "MyPyObjRefList->ob_refcnt" << MyPyObjRefList->ob_refcnt << " "
- << "ResultObj->ob_refcnt" << ResultObj->ob_refcnt << endl ;
- PyObject_Print( ResultObj , stdout , 0 ) ;
- PyTuple_SetItem( ArgsList , i , ResultObj ) ;
- cdebug << "ArgIn" << i << " : " << sname << " Value (objref) ArgsList->ob_refcnt"
- << ArgsList->ob_refcnt << " ResultObj->ob_refcnt" << ResultObj->ob_refcnt
- << endl ;
- break ;
- }
- default : {
- cdebug << "ArgIn" << i << " : " << sname << " Value " << "(other ERROR)" << endl ;
- }
- }
- }
-
- Result = PyEval_CallObject( MyPyRunMethod , ArgsList ) ;
- cdebug << "ArgsList->ob_refcnt" << ArgsList->ob_refcnt << endl ;
-
- if ( Result == NULL ) {
- cdebug_out << "GraphExecutor::InNode::PyDynInvoke Error Result == NULL" << endl ;
+ if ( !PyCallable_Check( MyPyRunMethod ) ) {
+ Result = NULL ;
RetVal = false ;
}
else {
- for ( i = 0 ; i < n_out ; i++ ) {
- data = outParams[i].Value ;
- sname = outParams[i].Name.c_str() ;
+ ArgsList = PyTuple_New( n_in ) ;
+
+ for ( i = 0 ; i < n_in ; i++ ) {
+ data = inParams[i].Value ;
+ sname = inParams[i].Name.c_str() ;
switch ( data.type()->kind() ) {
case CORBA::tk_string : {
char * t ;
- ArgValue = PyTuple_GetItem( Result , i ) ;
- if ( ArgValue == NULL ) {
- ArgValue = Result ;
- }
- t = PyString_AsString( ArgValue ) ;
- data <<= t ;
- cdebug << "ArgOut" << i << " : " << sname << " Value " << t << " (string)"
- << endl ;
+ data >>= t ;
+ ArgValue = Py_BuildValue( "s" , t ) ;
+ PyTuple_SetItem( ArgsList , i , ArgValue ) ;
+ cdebug << "ArgIn" << i << " : " << sname << " " << method << " Value " << t << " (string) "
+ << " ArgsList->ob_refcnt" << ArgsList->ob_refcnt << " ArgValue->ob_refcnt"
+ << ArgValue->ob_refcnt << endl ;
break ;
}
- case CORBA::tk_double : {
- double d ;
- ArgValue = PyTuple_GetItem( Result , i ) ;
- if ( ArgValue == NULL ) {
- ArgValue = Result ;
- }
- d = PyFloat_AsDouble( ArgValue ) ;
- data <<= d ;
- cdebug << "ArgOut" << i << " : " << sname << " Value " << d << " (double)"
- << endl ;
+ case CORBA::tk_boolean : {
+ bool b ;
+ data >>= (CORBA::Any::to_boolean ) b ;
+ ArgValue = Py_BuildValue( "b" , b ) ;
+ PyTuple_SetItem( ArgsList , i , ArgValue ) ;
+ cdebug << "ArgIn" << i << " : " << sname << " " << method << " Value " << b
+ << " (boolean) ArgsList->ob_refcnt" << ArgsList->ob_refcnt << " ArgValue->ob_refcnt"
+ << ArgValue->ob_refcnt << endl ;
+ break ;
+ }
+ case CORBA::tk_char : {
+ unsigned char c ;
+ data >>= (CORBA::Any::to_char ) c ;
+ ArgValue = Py_BuildValue( "c" , c ) ;
+ PyTuple_SetItem( ArgsList , i , ArgValue ) ;
+ cdebug << "ArgIn" << i << " : " << sname << " " << method << " Value " << c
+ << " (char) ArgsList->ob_refcnt" << ArgsList->ob_refcnt << " ArgValue->ob_refcnt"
+ << ArgValue->ob_refcnt << endl ;
+ break ;
+ }
+ case CORBA::tk_short : {
+ short s ;
+ data >>= s ;
+ ArgValue = Py_BuildValue( "h" , s ) ;
+ PyTuple_SetItem( ArgsList , i , ArgValue ) ;
+ cdebug << "ArgIn" << i << " : " << sname << " " << method << " Value " << s
+ << " (short) ArgsList->ob_refcnt" << ArgsList->ob_refcnt << " ArgValue->ob_refcnt"
+ << ArgValue->ob_refcnt << endl ;
break ;
}
case CORBA::tk_long : {
long l ;
- ArgValue = PyTuple_GetItem( Result , i ) ;
- if ( ArgValue == NULL ) {
- ArgValue = Result ;
- }
- l = PyInt_AsLong( ArgValue ) ;
- data <<= l ;
- cdebug << "ArgOut" << i << " : " << sname << " Value " << l << " (long)" << endl ;
+ data >>= l ;
+ ArgValue = Py_BuildValue( "l" , l ) ;
+ PyTuple_SetItem( ArgsList , i , ArgValue ) ;
+ cdebug << "ArgIn" << i << " : " << sname << " " << method << " Value " << l
+ << " (long) ArgsList->ob_refcnt" << ArgsList->ob_refcnt << " ArgValue->ob_refcnt"
+ << ArgValue->ob_refcnt << endl ;
+ break ;
+ }
+ case CORBA::tk_float : {
+ float f ;
+ data >>= f ;
+ ArgValue = Py_BuildValue( "f" , f ) ;
+ PyTuple_SetItem( ArgsList , i , ArgValue ) ;
+ cdebug << "ArgIn" << i << " : " << sname << " " << method << " Value " << f
+ << " (float) ArgsList->ob_refcnt" << ArgsList->ob_refcnt << " ArgValue->ob_refcnt"
+ << ArgValue->ob_refcnt << endl ;
+ break ;
+ }
+ case CORBA::tk_double : {
+ double d ;
+ data >>= d ;
+ ArgValue = Py_BuildValue( "d" , d ) ;
+ PyTuple_SetItem( ArgsList , i , ArgValue ) ;
+ cdebug << "ArgIn" << i << " : " << sname << " " << method << " Value " << d
+ << " (double) ArgsList->ob_refcnt" << ArgsList->ob_refcnt << " ArgValue->ob_refcnt"
+ << ArgValue->ob_refcnt << endl ;
break ;
}
case CORBA::tk_objref : {
- MyPyObjIorList = PyTuple_New( 1 ) ;
- PyObject * ObjIor = PyTuple_GetItem( Result , i ) ;
- if ( ObjIor == NULL ) {
- ObjIor = Result ;
- }
- Py_INCREF( ObjIor ) ;
- PyObject_Print( ObjIor , stdout , 0 ) ;
- PyTuple_SetItem( MyPyObjIorList , 0 , ObjIor ) ;
- Py_DECREF( ObjIor ) ;
- ResultIor = PyEval_CallObject( MyPyObjIor , MyPyObjIorList ) ;
-// ObjRef = PyCObject_AsVoidPtr( ArgValue ) ;
-// ObjRef = (CORBA::Object_ptr ) PyLong_AsVoidPtr( ArgValue ) ;
- char * IOR = NULL ;
-// ArgValue = PyTuple_GetItem( Result , i ) ;
- if ( ResultIor ) {
- IOR = PyString_AsString( ResultIor ) ;
- ObjRef = StringToObject( IOR ) ;
- data <<= ObjRef ;
- IORObjRef = ObjectToString( ObjRef ) ;
- cdebug << "ArgOut" << i << " : " << sname << " Value " << "(object reference) "
- << IORObjRef << endl ;
- }
+ MyPyObjRefList = PyTuple_New( 1 ) ;
+ PyObject * ObjValue ;
+ data >>= ObjRef ;
+ IORObjRef = ObjectToString( ObjRef ) ;
+ ObjValue = Py_BuildValue( "s" , IORObjRef ) ;
+ PyTuple_SetItem( MyPyObjRefList , 0 , ObjValue ) ;
+ cdebug << "ArgIn" << i << " : " << sname << " " << method << " " << " Value " << IORObjRef << " (objref) "
+ << MyPyObjRef->ob_refcnt << "/" << MyPyObjRefList->ob_refcnt << endl ;
+ ResultObj = PyEval_CallObject( MyPyObjRef , MyPyObjRefList ) ;
+ cdebug << "ObjValue->ob_refcnt" << ObjValue->ob_refcnt << endl ;
+ ArgValue = Py_BuildValue( "O" , ResultObj ) ;
+ PyTuple_SetItem( ArgsList , i , ArgValue ) ;
+ cdebug << "ArgIn" << i << " : " << sname << " " << method << " Value (objref) ArgsList->ob_refcnt"
+ << ArgsList->ob_refcnt << " ArgValue->ob_refcnt" << ArgValue->ob_refcnt << endl ;
+ cdebug << "MyPyObjRefList->ob_refcnt " << MyPyObjRefList->ob_refcnt-1 << endl ;
+ Py_DECREF( MyPyObjRefList ) ;
+ if ( CORBA::is_nil( ObjRef ) ) {
+ ResultObj = NULL ;
+ }
else {
- cdebug_out << "GraphExecutor::InNode::PyDynInvoke Error ResultIor == NULL"
- << endl ;
- RetVal = false ;
- }
+ cdebug << "ResultObj->ob_refcnt " << ResultObj->ob_refcnt-1 << endl ;
+ Py_DECREF( ResultObj ) ;
+ }
break ;
}
default : {
- cdebug << "ArgOut" << i << " : " << sname << " Value " << "(other ERROR)" << endl ;
+ cdebug << "ArgIn" << i << " : " << sname << " Value " << "(other ERROR)" << endl ;
}
}
- outParams[i].Value = data ;
}
- if ( MyPyObjIorList ) {
- int cnt = MyPyObjIorList->ob_refcnt ;
- while ( cnt ) {
- cnt = MyPyObjIorList->ob_refcnt - 1 ;
- Py_DECREF( MyPyObjIorList ) ;
- Py_DECREF( ResultIor ) ;
- cdebug << "MyPyObjIorList->ob_refcnt" << MyPyObjIorList->ob_refcnt << " "
- << "ResultIor->ob_refcnt" << ResultIor->ob_refcnt << endl ;
- }
+ Result = PyEval_CallObject( MyPyRunMethod , ArgsList ) ;
+
+ cdebug << "ArgsList->ob_refcnt" << ArgsList->ob_refcnt << endl ;
+
+ if ( Result == NULL ) {
+ cdebug_out << "GraphExecutor::InNode::PyDynInvoke Node " << Name() << " " << method << " Error Result == NULL"
+ << endl ;
+ RetVal = false ;
}
- Py_DECREF( Result ) ;
- }
+ else {
+ for ( i = 0 ; i < n_out ; i++ ) {
+ data = outParams[i].Value ;
+ sname = outParams[i].Name.c_str() ;
+ switch ( data.type()->kind() ) {
+ case CORBA::tk_string : {
+ char * t = "" ;
+ if ( PyTuple_Check( Result ) ) {
+ ArgValue = PyTuple_GetItem( Result , i ) ;
+ }
+ else {
+ ArgValue = Result ;
+ }
+ if ( !PyString_Check( ArgValue ) ) {
+ cdebug << "ArgOut" << i << " : " << sname << " " << method << " ERROR (string)" << endl ;
+ }
+ else {
+ t = PyString_AsString( ArgValue ) ;
+ }
+ data <<= t ;
+ cdebug << "ArgOut" << i << " : " << sname << " " << method << " Value " << t << " (string)"
+ << " ArgsList->ob_refcnt" << ArgsList->ob_refcnt << " ArgValue->ob_refcnt"
+ << ArgValue->ob_refcnt << endl ;
+ break ;
+ }
+ case CORBA::tk_boolean : {
+ bool b = false ;
+ if ( PyTuple_Check( Result ) ) {
+ ArgValue = PyTuple_GetItem( Result , i ) ;
+ }
+ else {
+ ArgValue = Result ;
+ }
+ if ( !PyInt_Check( ArgValue ) ) {
+ cdebug << "ArgOut" << i << " : " << sname << " " << method << " ERROR (boolean)" << endl ;
+ }
+ else {
+ b = PyInt_AsLong( ArgValue ) ;
+ }
+ data <<= (CORBA::Any::from_boolean ) b ;
+ cdebug << "ArgOut" << i << " : " << sname << " " << method << " Value " << b << " (boolean)"
+ << " ArgsList->ob_refcnt" << ArgsList->ob_refcnt << " ArgValue->ob_refcnt"
+ << ArgValue->ob_refcnt << endl ;
+ break ;
+ }
+ case CORBA::tk_char : {
+ unsigned char c = 0 ;
+ if ( PyTuple_Check( Result ) ) {
+ ArgValue = PyTuple_GetItem( Result , i ) ;
+ }
+ else {
+ ArgValue = Result ;
+ }
+ if ( !PyInt_Check( ArgValue ) ) {
+ cdebug << "ArgOut" << i << " : " << sname << " " << method << " ERROR (char)" << endl ;
+ }
+ else {
+ c = PyInt_AsLong( ArgValue ) ;
+ }
+ data <<= (CORBA::Any::from_char ) c ;
+ cdebug << "ArgOut" << i << " : " << sname << " " << method << " Value " << c << " (char)"
+ << " ArgsList->ob_refcnt" << ArgsList->ob_refcnt << " ArgValue->ob_refcnt"
+ << ArgValue->ob_refcnt << endl ;
+ break ;
+ }
+ case CORBA::tk_short : {
+ short s = 0 ;
+ if ( PyTuple_Check( Result ) ) {
+ ArgValue = PyTuple_GetItem( Result , i ) ;
+ }
+ else {
+ ArgValue = Result ;
+ }
+ if ( !PyInt_Check( ArgValue ) ) {
+ cdebug << "ArgOut" << i << " : " << sname << " " << method << " ERROR (short)" << endl ;
+ }
+ else {
+ s = PyInt_AsLong( ArgValue ) ;
+ }
+ data <<= s ;
+ cdebug << "ArgOut" << i << " : " << sname << " " << method << " Value " << s << " (short)"
+ << " ArgsList->ob_refcnt" << ArgsList->ob_refcnt << " ArgValue->ob_refcnt"
+ << ArgValue->ob_refcnt << endl ;
+ break ;
+ }
+ case CORBA::tk_long : {
+ long l = 0 ;
+ if ( PyTuple_Check( Result ) ) {
+ ArgValue = PyTuple_GetItem( Result , i ) ;
+ }
+ else {
+ ArgValue = Result ;
+ }
+ if ( PyLong_Check( ArgValue ) ) {
+ l = PyLong_AsLong( ArgValue ) ;
+ }
+ else if ( PyInt_Check( ArgValue ) ) {
+ l = PyInt_AsLong( ArgValue ) ;
+ }
+ else {
+ cdebug << "ArgOut" << i << " : " << sname << " " << method << " ERROR (CORBA::tk_long)" << endl ;
+ }
+ data <<= l ;
+ cdebug << "ArgOut" << i << " : " << sname << " " << method << " Value " << l << " (long)"
+ << " ArgsList->ob_refcnt" << ArgsList->ob_refcnt << " ArgValue->ob_refcnt"
+ << ArgValue->ob_refcnt << endl ;
+ break ;
+ }
+ case CORBA::tk_float : {
+ float f = 0 ;
+ if ( PyTuple_Check( Result ) ) {
+ ArgValue = PyTuple_GetItem( Result , i ) ;
+ }
+ else {
+ ArgValue = Result ;
+ }
+ if ( !PyFloat_Check( ArgValue ) ) {
+ cdebug << "ArgOut" << i << " : " << sname << " " << method << " ERROR (float)" << endl ;
+ }
+ else {
+ f = PyFloat_AsDouble( ArgValue ) ;
+ }
+ data <<= f ;
+ cdebug << "ArgOut" << i << " : " << sname << " " << method << " Value " << f << " (float)"
+ << " ArgsList->ob_refcnt" << ArgsList->ob_refcnt << " ArgValue->ob_refcnt"
+ << ArgValue->ob_refcnt << endl ;
+ break ;
+ }
+ case CORBA::tk_double : {
+ double d = 0 ;
+ if ( PyTuple_Check( Result ) ) {
+ ArgValue = PyTuple_GetItem( Result , i ) ;
+ }
+ else {
+ ArgValue = Result ;
+ }
+ if ( !PyFloat_Check( ArgValue ) ) {
+ cdebug << "ArgOut" << i << " : " << sname << " " << method << " ERROR (double)" << endl ;
+ }
+ else {
+ d = PyFloat_AsDouble( ArgValue ) ;
+ }
+ data <<= d ;
+ cdebug << "ArgOut" << i << " : " << sname << " " << method << " Value " << d << " (double)"
+ << " ArgsList->ob_refcnt" << ArgsList->ob_refcnt << " ArgValue->ob_refcnt"
+ << ArgValue->ob_refcnt << endl ;
+ break ;
+ }
+ case CORBA::tk_objref : {
+ PyObject * ObjIor ;
+ MyPyObjIorList = PyTuple_New( 1 ) ;
+ if ( PyTuple_Check( Result ) ) {
+ ObjIor = PyTuple_GetItem( Result , i ) ;
+ }
+ else {
+ ObjIor = Result ;
+ }
+ cdebug << "ArgOut" << i << " : " << sname << " " << method << " Value " << "(object reference) "
+ << " ArgsList->ob_refcnt" << ArgsList->ob_refcnt << " ObjIor->ob_refcnt"
+ << ObjIor->ob_refcnt << endl ;
+ Py_INCREF( ObjIor ) ;
+// PyObject_Print( ObjIor , stdout , 0 ) ;
+ PyTuple_SetItem( MyPyObjIorList , 0 , ObjIor ) ;
+ ResultIor = PyEval_CallObject( MyPyObjIor , MyPyObjIorList ) ;
+ cdebug << "ObjIor->ob_refcnt " << ObjIor->ob_refcnt-1 << endl ;
+ Py_DECREF( ObjIor ) ;
+ cdebug << "MyPyObjIorList->ob_refcnt " << MyPyObjIorList->ob_refcnt-1 << endl ;
+ Py_DECREF( MyPyObjIorList ) ;
+ cdebug << "MyPyObjIor->ob_refcnt " << MyPyObjIor->ob_refcnt << endl ;
+ if ( ResultIor ) {
+ char * IOR = NULL ;
+ IOR = PyString_AsString( ResultIor ) ;
+ ObjRef = StringToObject( IOR ) ;
+ data <<= ObjRef ;
+ IORObjRef = ObjectToString( ObjRef ) ;
+ cdebug << "ArgOut" << i << " : " << sname << " " << method << " Value " << IORObjRef << " (objref) "
+ << endl ;
+ if ( CORBA::is_nil( ObjRef ) ) {
+ ResultIor = NULL ;
+ }
+ else {
+ cdebug << "ResultIor->ob_refcnt " << ResultIor->ob_refcnt-1 << endl ;
+ Py_DECREF( ResultIor ) ;
+ }
+ }
+ else {
+ cdebug_out << "GraphExecutor::InNode::PyDynInvoke Error ResultIor == NULL Node "
+ << Name() << " method " << method << " " << endl ;
+ RetVal = false ;
+ }
+ break ;
+ }
+ default : {
+ cdebug << "ArgOut" << i << " : " << sname << " " << method << " Value " << "(other ERROR)" << endl ;
+ }
+ }
+ outParams[i].Value = data ;
+ }
- Py_DECREF( ArgsList ) ;
- if ( MyPyObjRefList ) {
- int cnt = MyPyObjRefList->ob_refcnt ;
- while ( cnt ) {
- cnt = MyPyObjRefList->ob_refcnt - 1 ;
- Py_DECREF( MyPyObjRefList ) ;
- Py_DECREF( ResultObj ) ;
- cdebug << "MyPyObjRefList->ob_refcnt" << MyPyObjRefList->ob_refcnt << " "
- << "ResultObj->ob_refcnt" << ResultObj->ob_refcnt << endl ;
+ cdebug << "Result->ob_refcnt" << Result->ob_refcnt-1 << endl ;
+ Py_DECREF( Result ) ;
}
+
+ cdebug << "GraphExecutor::InNode::PyDynInvoke ArgsList->ob_refcnt"
+ << ArgsList->ob_refcnt-1 << endl ;
+ Py_DECREF( ArgsList ) ;
}
- cdebug_out << "GraphExecutor::InNode::PyDynInvoke " << method << endl ;
+ cdebug_out << "GraphExecutor::InNode::PyDynInvoke Node " << Name() << " method " << method << " " << RetVal
+ << endl ;
return RetVal ;