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 <tevent_util.h>
26 struct event_context *ev_ctx;
27 } PyEventContextObject;
29 PyAPI_DATA(PyTypeObject) PyEventContext;
31 static PyObject *py_set_default_backend(PyObject *self, PyObject *args)
35 if (!PyArg_ParseTuple(args, "s", &name))
37 event_set_default_backend(name);
41 static PyObject *py_backend_list(PyObject *self)
43 const char **backends = event_backend_list(NULL);
47 len = ev_str_list_length(backends);
48 ret = PyList_New(len);
49 for (i = 0; i < len; i++)
50 PyList_SetItem(ret, i, PyString_FromString(backends[i]));
51 talloc_free(backends);
56 static PyMethodDef tevent_methods[] = {
57 { "set_default_backend", (PyCFunction)py_set_default_backend,
58 METH_VARARGS, "set_default_backend(name) -> None" },
59 { "backend_list", (PyCFunction)py_backend_list,
60 METH_NOARGS, "backend_list() -> list" },
64 static PyObject *py_event_ctx_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
66 const char *kwnames[] = { "name", NULL };
68 struct event_context *ev_ctx;
69 PyEventContextObject *ret;
70 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|s", (char **)kwnames, &name))
74 ev_ctx = event_context_init(NULL);
76 ev_ctx = event_context_init_byname(NULL, name);
78 ret = (PyEventContextObject *)type->tp_alloc(type, 0);
80 return (PyObject *)ret;
83 static PyObject *py_event_ctx_loop_once(PyEventContextObject *self)
85 return PyInt_FromLong(event_loop_once(self->ev_ctx));
88 static PyObject *py_event_ctx_loop_wait(PyEventContextObject *self)
90 return PyInt_FromLong(event_loop_wait(self->ev_ctx));
93 static PyMethodDef py_event_ctx_methods[] = {
94 { "loop_once", (PyCFunction)py_event_ctx_loop_once, METH_NOARGS,
95 "S.loop_once() -> int" },
96 { "loop_wait", (PyCFunction)py_event_ctx_loop_wait, METH_NOARGS,
97 "S.loop_wait() -> int" },
101 static void py_event_ctx_dealloc(PyEventContextObject * self)
103 talloc_free(self->ev_ctx);
104 self->ob_type->tp_free(self);
107 PyTypeObject PyEventContext = {
108 .tp_name = "EventContext",
109 .tp_methods = py_event_ctx_methods,
110 .tp_basicsize = sizeof(PyEventContextObject),
111 .tp_dealloc = (destructor)py_event_ctx_dealloc,
112 .tp_flags = Py_TPFLAGS_DEFAULT,
113 .tp_new = py_event_ctx_new,
116 void inittevent(void)
120 if (PyType_Ready(&PyEventContext) < 0)
123 m = Py_InitModule3("tevent", tevent_methods, "Event management.");
127 Py_INCREF(&PyEventContext);
128 PyModule_AddObject(m, "EventContext", (PyObject *)&PyEventContext);