The Gaudi Framework  v32r2 (46d42edc)
CallbackStreamBuf.cpp
Go to the documentation of this file.
1 // ============================================================================
2 #include "GaudiPython/CallbackStreamBuf.h" // this one first, so Python.h is first
3 // ============================================================================
5 // ============================================================================
6 #include <algorithm>
7 // ============================================================================
8 
9 // ============================================================================
11 // ============================================================================
12 int GaudiPython::call_python_method( PyObject* self, const char* method, char* buf ) {
13  if ( !self || !method ) { return 1; }
14  PyObject* r = PyObject_CallMethod( self, const_cast<char*>( method ), const_cast<char*>( "s" ), buf );
15  if ( !r ) {
16  std::string err( "Unsuccessful call to bound Python method" );
17  err += method;
18  PyErr_SetString( PyExc_TypeError, err.c_str() );
19  PyErr_Print();
20  return 1;
21  }
22  Py_DECREF( r );
23  return 0;
24 }
25 
26 // ============================================================================
28 // ============================================================================
30 
31 // ============================================================================
33 // ============================================================================
35  size_t length;
36  char* x;
37  for ( length = 0, x = pbase(); x < epptr(); ++x, ++length )
38  ;
39  // getting in a null terminated buffer the characters
40  memcpy( m_callbackBuff.data(), pbase(), std::min( length, m_callbackBuff.size() ) );
41  m_callbackBuff[std::min( length, m_callbackBuff.size() )] = '\0';
42  // calling the python method
43  GaudiPython::call_python_method( m_self.get(), "_sync", m_callbackBuff.data() );
44  // reseting in/out buffer pointers
45  setp( pbase(), pbase() );
46  setg( eback(), eback(), eback() );
47  return 0;
48 }
int sync() override
reimplementation of stringbuf::sync()
STL class.
T min(T... args)
T c_str(T... args)
CallbackStreamBuf(PyObject *self)
CallbackStreamBuf constructor.
GAUDI_API StatusCode call_python_method(PyObject *self, const char *method)
call the python method
Definition: Algorithm.cpp:38