47 arguments = args == Py_None ? NULL : args;
48 Py_XINCREF (
function);
49 Py_XINCREF (arguments);
55 Py_XDECREF (
function);
56 Py_XDECREF (arguments);
62 PyObject *py_arg = arguments ? Py_BuildValue (
"(O)",arguments) : NULL;
63 PyObject* val = make_call (py_arg);
72 PyObject *py_arg = arguments ? Py_BuildValue (
"(O)",arguments) : NULL;
73 PyObject* val = make_call (py_arg);
75 if (val) retval = PyInt_AsLong (val);
86 if (arguments) py_arg = Py_BuildValue (
"(i,O)", arg, arguments);
87 else py_arg = Py_BuildValue (
"(i)", arg);
89 PyObject * val = make_call (py_arg);
96 std::string name =
"";
100 PyObject *p_name = PyObject_GetAttrString (
function,
"__name__");
101 if (PyString_Check (p_name)) name = python::as_string (p_name);
102 else fprintf (stderr,
"*** error: py_callback::put_state: Failed to retrieve callback name!");
111 if (arguments != NULL)
134 fprintf (stderr,
"*** error: py_callback::get_state: Invalid instance!\n");
140 function = PyObject_GetAttrString (
instance, (
char *) name.c_str ());
143 if (!PyCallable_Check (
function))
145 fprintf (stderr,
"*** error: py_callback::get_state: Setting callback '%s' failed!\n", name.c_str ());
153 PyObject *py_callback::make_call (PyObject *args)
155 if (
function == NULL)
return NULL;
157 PyObject * val = PyObject_CallObject (
function, args);
void callback_func1(int arg)
Calls the python function with an integer.
Class to write data from a Gzip compressed file.
Class to read data from a Gzip compressed file.
Declares the py_callback class.
static void put_tuple(PyObject *tuple, ogzstream &file)
Save a Python tuple into a file.
static PyObject * instance
When restoring a callback from file, instance has to point to the python instance (module or class) c...
bool callback_func0ret()
Calls the python function and returns bool.
static void show_traceback(void)
Dumps any error information to stderr.
bool get_state(igzstream &in)
Restores the callback from a file.
static PyObject * get_tuple(igzstream &file)
Loads a Python tuple previously saved with put_tuple ().
~py_callback()
Destructor.
void put_state(ogzstream &out) const
Saves the callback and it's arguments to file.
Defines the python class. This file is named this way so it doesn't conflicts with Python...
void callback_func0()
Calls the python function without arguments.
py_callback()
Default ctor,.