22 #include "GaudiKernel/IInterface.h"
23 #include "GaudiKernel/INamedInterface.h"
24 #include "GaudiKernel/StatusCode.h"
28 #include "CPyCppyy/PyException.h"
34 #include "TClassRef.h"
53 unsigned long& minor )
59 const_cast<char*
>(
"interfaceID"),
60 const_cast<char*
>(
"") );
64 return StatusCode::FAILURE;
67 PyObject* pyId = PyObject_CallMethod( idObj,
68 const_cast<char*
>(
"id"),
69 const_cast<char*
>(
"") );
73 return StatusCode::FAILURE;
75 id = PyLong_AsUnsignedLong(pyId);
78 PyObject* pyMajor = PyObject_CallMethod( idObj,
79 const_cast<char*
>(
"majorVersion"),
80 const_cast<char*
>(
"") );
84 return StatusCode::FAILURE;
86 major = PyLong_AsUnsignedLong(pyMajor);
89 PyObject* pyMinor = PyObject_CallMethod( idObj,
90 const_cast<char*
>(
"minorVersion"),
91 const_cast<char*
>(
"") );
95 return StatusCode::FAILURE;
97 minor = PyLong_AsUnsignedLong(pyMinor);
101 return StatusCode::SUCCESS;
110 PyObject* py_repr = PyObject_Repr( o );
113 Py_DECREF( py_repr );
125 PyObject* py_str = PyObject_Str( o );
140 PyObject* pytype = 0, *pyvalue = 0, *pytrace = 0;
141 PyErr_Fetch (&pytype, &pyvalue, &pytrace);
143 Py_XINCREF (pyvalue);
144 Py_XINCREF (pytrace);
146 PyErr_Restore (pytype, pyvalue, pytrace);
152 PyObject*
f = PySys_GetObject (
const_cast<char*
>(
"stderr"));
153 PyObject* fstr = PyUnicode_FromString (
"flush");
154 PyObject*
x = PyObject_CallMethodObjArgs (
f, fstr, NULL);
165 const char* methodName,
169 char*
method =
const_cast<char*
>(methodName);
172 if ( 0 ==
self || 0 ==
method ) {
return StatusCode::FAILURE; }
178 r = PyObject_CallMethod(
self,
method,
const_cast<char*
>(
"O"),
arg );
180 r = PyObject_CallMethod(
self,
method,
const_cast<char*
>(
"") );
186 if ( PyLong_Check(
r ) ) {
195 if ( PyObject_HasAttrString (
r, (
char*)
"getCode") ) {
196 c = PyObject_CallMethod(
r,
197 const_cast<char*
>(
"getCode"),
198 const_cast<char*
>(
"") );
203 std::ostringstream
msg;
204 msg <<
"unexpected returned type from (python) function '"
208 PyErr_SetString (PyExc_TypeError,
msg.str().c_str());
218 if ( PyLong_Check (
c) ) {
225 std::ostringstream
msg;
226 msg <<
"unexpected returned type from (python) function '"
227 <<
method <<
"().getCode()' [got "
230 PyErr_SetString (PyExc_TypeError,
msg.str().c_str());
234 return StatusCode::FAILURE;
239 const InterfaceID& riid,
240 void** ppvInterface )
246 <<
"==============[ " <<
PyAthena::repr(
self) <<
" ]=============="
252 const_cast<char*
>(
"__class__") );
259 bases = PyObject_CallMethod(
type,
260 const_cast<char*
>(
"mro"),
261 const_cast<char*
>(
"") );
262 if ( !bases || !PySequence_Check( bases ) ) {
268 const int nBases = PySequence_Size( bases );
269 if ( -1 == nBases ) {
275 for (
int i = 0;
i < nBases; ++
i ) {
281 unsigned long id = 0;
282 unsigned long major = 0;
283 unsigned long minor = 0;
284 if ( !fetchInterfaceId(
base,
id, major, minor ).isSuccess() ) {
289 InterfaceID pyID(
id, major, minor );
290 if ( !pyID.versionMatch( riid ) ) {
296 pyname = PyObject_GetAttrString(
base,
297 const_cast<char*
>(
"__name__") );
305 const std::string cppName =
reinterpret_cast<MyObjProxy*
>(
self)->m_class->GetName();
307 std::cout <<
"::: would like to do: *ppvInterface = static_cast<"
308 << cppBaseName <<
"*>( "
309 << cppName <<
"|m_self );"
313 const RootType toType( cppBaseName );
314 void* objProxy = TPython::CPPInstance_AsVoidPtr(
self);
315 *ppvInterface = objProxy;
317 *ppvInterface = fromType.
Class()->DynamicCast (toType.
Class(), objProxy);
318 std::cout <<
"::: [" << cppName <<
"]: "
319 << ( (
bool)fromType ?
" OK" :
"ERR" )
322 <<
"::: [" << cppBaseName <<
"]: "
323 << ( (
bool)toType ?
" OK" :
"ERR" )
324 <<
" " << *ppvInterface
326 std::cout <<
"::: *ppvInterface: " << *ppvInterface << std::endl;
327 if ( *ppvInterface ) {
329 const_cast<char*
>(
"addRef"),
330 const_cast<char*
>(
"") );
331 if (
c && PyLong_Check(
c) ) {
332 sc = StatusCode::SUCCESS;
337 if (
sc.isSuccess() ) {
352 const char* component )
357 (
char*)
"ss",
evt, component);
371 const char* component,
375 PyObject* pySc = TPython::CPPInstance_FromVoidPtr((
void*)&
sc,
383 (
char*)
"ssO",
evt, component, pySc);