1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
11 struct PythonCallbackData {
17 Calls a python callback for the TimeoutHandler function type
19 static void PythonCallback(PythonCallbackData *calldata) {
20 PyObject *arglist, *result;
22 arglist = Py_BuildValue("(O)", calldata->data);
25 result = PyEval_CallObject((PyObject*)calldata->pyfunc, arglist);
26 if (!result || PyErr_Occurred()) {
27 // an exception occured in the script, display it
36 // Grab a Python function object as a Python object.
37 %typemap(python,in) PyObject *func {
38 if (!PyCallable_Check($input)) {
39 PyErr_SetString(PyExc_TypeError, "Excepting a callable object.");
47 %ignore Timer::Timer(long, TimeoutHandler, void*);
48 %ignore Timer::operator delete(void*);
49 %ignore Timer::initialize();
50 %ignore Timer::destroy();
51 %ignore Timer::dispatchTimers(bool);
52 %ignore Timer::nearestTimeout(struct timeval&);
55 Timer(long, PyObject*, PyObject*);
57 // if you don't call stop() before the object disappears, the timer will
58 // keep firing forever
67 static otk::Timer *new_otk_Timer(long delay,
68 PyObject *func, PyObject *data) {
69 PythonCallbackData *d = new PythonCallbackData;
72 return new otk::Timer(delay,
73 (otk::Timer::TimeoutHandler)&PythonCallback, d);
74 // the PythonCallbackData is leaked.. XXX