2 Unix SMB/CIFS implementation.
3 Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2007-2008
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #include <../talloc/pytalloc.h>
23 #include <tevent_util.h>
25 PyAPI_DATA(PyTypeObject) PyEventContext;
27 static PyObject *py_set_default_backend(PyObject *self, PyObject *args)
31 if (!PyArg_ParseTuple(args, "s", &name))
33 event_set_default_backend(name);
37 static PyObject *py_backend_list(PyObject *self)
39 const char **backends = event_backend_list(NULL);
43 len = ev_str_list_length(backends);
44 ret = PyList_New(len);
45 for (i = 0; i < len; i++)
46 PyList_SetItem(ret, i, PyString_FromString(backends[i]));
47 talloc_free(backends);
52 static PyMethodDef tevent_methods[] = {
53 { "set_default_backend", (PyCFunction)py_set_default_backend,
54 METH_VARARGS, "set_default_backend(name) -> None" },
55 { "backend_list", (PyCFunction)py_backend_list,
56 METH_NOARGS, "backend_list() -> list" },
60 static PyObject *py_event_ctx_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
62 const char *kwnames[] = { "name", NULL };
64 struct event_context *ev_ctx;
65 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|s", (char **)kwnames, &name))
69 ev_ctx = event_context_init(NULL);
71 ev_ctx = event_context_init_byname(NULL, name);
73 return py_talloc_import(&PyEventContext, ev_ctx);
76 static PyObject *py_event_ctx_loop_once(py_talloc_Object *self)
78 return PyInt_FromLong(event_loop_once(self->ptr));
81 static PyObject *py_event_ctx_loop_wait(py_talloc_Object *self)
83 return PyInt_FromLong(event_loop_wait(self->ptr));
86 static PyMethodDef py_event_ctx_methods[] = {
87 { "loop_once", (PyCFunction)py_event_ctx_loop_once, METH_NOARGS,
88 "S.loop_once() -> int" },
89 { "loop_wait", (PyCFunction)py_event_ctx_loop_wait, METH_NOARGS,
90 "S.loop_wait() -> int" },
94 PyTypeObject PyEventContext = {
95 .tp_name = "EventContext",
96 .tp_methods = py_event_ctx_methods,
97 .tp_basicsize = sizeof(py_talloc_Object),
98 .tp_dealloc = py_talloc_dealloc,
99 .tp_new = py_event_ctx_new,
102 void inittevent(void)
106 m = Py_InitModule3("tevent", tevent_methods, "Event management.");