#include "cReactor.h"
PyObject *
cReactorTime_callLater(PyObject *self, PyObject *args, PyObject *kw)
{
cReactor *reactor;
cDelayedCall *call;
int delay = 0;
PyObject *delay_obj = NULL;
PyObject *req_args = NULL;
PyObject *callable_args = NULL;
PyObject *callable = NULL;
reactor = (cReactor *)self;
req_args = PyTuple_GetSlice(args, 0, 2);
if (!PyArg_ParseTuple(req_args, "OO:callLater", &delay_obj, &callable))
{
Py_DECREF(req_args);
return NULL;
}
Py_DECREF(req_args);
if (delay_obj)
{
delay = cReactorUtil_ConvertDelay(delay_obj);
if (delay < 0)
{
return NULL;
}
}
if (!PyCallable_Check(callable))
{
PyErr_Format(PyExc_TypeError, "callLater() arg 2 expected callable, found %s",
callable->ob_type->tp_name);
return NULL;
}
callable_args = PyTuple_GetSlice(args, 2, PyTuple_Size(args));
call = cReactorUtil_AddDelayedCall(reactor,
delay, callable, callable_args,
kw);
Py_DECREF(callable_args);
return (PyObject *)call;
}
PyObject *
cReactorTime_getDelayedCalls(PyObject *self, PyObject *args)
{
cReactor *reactor;
cDelayedCall *node;
PyObject *calls;
calls = PyList_New(0);
if (!calls) {
return NULL;
}
reactor = (cReactor *)self;
node = reactor->timed_methods;
while(node) {
if (PyList_Append(calls, (PyObject *)node)) {
Py_DECREF(calls);
return NULL;
}
node = node->next;
}
return calls;
}
PyObject *
cReactorTime_cancelCallLater(PyObject *self, PyObject *args)
{
cReactor *reactor;
cDelayedCall *call;
reactor = (cReactor *)self;
if (!PyArg_ParseTuple(args, "O:cancelCallLater", &call))
{
return NULL;
}
if (cReactorUtil_RemoveDelayedCall(reactor, call) < 0)
{
return NULL;
}
Py_INCREF(Py_None);
return Py_None;
}