2 Unix SMB/CIFS implementation.
3 Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2007-2008
5 ** NOTE! The following LGPL license applies to the tevent
6 ** library. This does NOT imply that all of Samba is released
9 This library is free software; you can redistribute it and/or
10 modify it under the terms of the GNU Lesser General Public
11 License as published by the Free Software Foundation; either
12 version 3 of the License, or (at your option) any later version.
14 This library is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 Lesser General Public License for more details.
19 You should have received a copy of the GNU Lesser General Public
20 License along with this library; if not, see <http://www.gnu.org/licenses/>.
26 #ifndef Py_RETURN_NONE
27 #define Py_RETURN_NONE return Py_INCREF(Py_None), Py_None
32 #include "tevent_util.h"
36 struct tevent_context
*ev_ctx
;
37 } PyTEventContextObject
;
39 PyAPI_DATA(PyTypeObject
) PyTEventContext
;
41 static PyObject
*py_set_default_backend(PyObject
*self
, PyObject
*args
)
45 if (!PyArg_ParseTuple(args
, "s", &name
))
47 tevent_set_default_backend(name
);
51 static PyObject
*py_backend_list(PyObject
*self
)
53 const char **backends
= tevent_backend_list(NULL
);
57 len
= ev_str_list_length(backends
);
58 ret
= PyList_New(len
);
59 for (i
= 0; i
< len
; i
++)
60 PyList_SetItem(ret
, i
, PyString_FromString(backends
[i
]));
61 talloc_free(backends
);
66 static PyMethodDef tevent_methods
[] = {
67 { "set_default_backend", (PyCFunction
)py_set_default_backend
,
68 METH_VARARGS
, "set_default_backend(name) -> None" },
69 { "backend_list", (PyCFunction
)py_backend_list
,
70 METH_NOARGS
, "backend_list() -> list" },
74 static PyObject
*py_event_ctx_new(PyTypeObject
*type
, PyObject
*args
, PyObject
*kwargs
)
76 const char *kwnames
[] = { "name", NULL
};
78 struct tevent_context
*ev_ctx
;
79 PyTEventContextObject
*ret
;
80 if (!PyArg_ParseTupleAndKeywords(args
, kwargs
, "|s",
81 discard_const_p(char *, kwnames
),
86 ev_ctx
= tevent_context_init(NULL
);
88 ev_ctx
= tevent_context_init_byname(NULL
, name
);
90 ret
= (PyTEventContextObject
*)type
->tp_alloc(type
, 0);
92 return (PyObject
*)ret
;
95 static PyObject
*py_event_ctx_loop_once(PyTEventContextObject
*self
)
97 return PyInt_FromLong(tevent_loop_once(self
->ev_ctx
));
100 static PyObject
*py_event_ctx_loop_wait(PyTEventContextObject
*self
)
102 return PyInt_FromLong(tevent_loop_wait(self
->ev_ctx
));
105 static PyMethodDef py_event_ctx_methods
[] = {
106 { "loop_once", (PyCFunction
)py_event_ctx_loop_once
, METH_NOARGS
,
107 "S.loop_once() -> int" },
108 { "loop_wait", (PyCFunction
)py_event_ctx_loop_wait
, METH_NOARGS
,
109 "S.loop_wait() -> int" },
113 static void py_event_ctx_dealloc(PyTEventContextObject
* self
)
115 talloc_free(self
->ev_ctx
);
116 self
->ob_type
->tp_free(self
);
120 PyTypeObject PyTEventContext
= {
121 .tp_name
= "TEventContext",
122 .tp_methods
= py_event_ctx_methods
,
123 .tp_basicsize
= sizeof(PyTEventContextObject
),
124 .tp_dealloc
= (destructor
)py_event_ctx_dealloc
,
125 .tp_flags
= Py_TPFLAGS_DEFAULT
,
126 .tp_new
= py_event_ctx_new
,
129 void inittevent(void)
133 if (PyType_Ready(&PyTEventContext
) < 0)
136 m
= Py_InitModule3("tevent", tevent_methods
, "Event management.");
140 Py_INCREF(&PyTEventContext
);
141 PyModule_AddObject(m
, "TEventContext", (PyObject
*)&PyTEventContext
);