From 3d8e0dabc079f5cd74dd6c6235fcc1f39f02a96c Mon Sep 17 00:00:00 2001 From: Joris Vink Date: Wed, 1 Feb 2017 17:12:52 +0100 Subject: [PATCH] expose kore_server_bind() and fatal() to python --- includes/python_methods.h | 8 ++++++-- src/python.c | 37 ++++++++++++++++++++++++++++++++++++- 2 files changed, 42 insertions(+), 3 deletions(-) diff --git a/includes/python_methods.h b/includes/python_methods.h index 8ba16bb..c3be018 100644 --- a/includes/python_methods.h +++ b/includes/python_methods.h @@ -14,7 +14,9 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -static PyObject *python_exported_log(PyObject *, PyObject *); +static PyObject *python_kore_log(PyObject *, PyObject *); +static PyObject *python_kore_fatal(PyObject *, PyObject *); +static PyObject *python_kore_listen(PyObject *, PyObject *); static PyObject *python_websocket_send(PyObject *, PyObject *); static PyObject *python_websocket_broadcast(PyObject *, PyObject *); @@ -24,7 +26,9 @@ static PyObject *python_websocket_broadcast(PyObject *, PyObject *); #define GETSET(n, g, s) { n, (getter)g, (setter)s, NULL, NULL } static struct PyMethodDef pykore_methods[] = { - METHOD("log", python_exported_log, METH_VARARGS), + METHOD("log", python_kore_log, METH_VARARGS), + METHOD("fatal", python_kore_fatal, METH_VARARGS), + METHOD("listen", python_kore_listen, METH_VARARGS), METHOD("websocket_send", python_websocket_send, METH_VARARGS), METHOD("websocket_broadcast", python_websocket_broadcast, METH_VARARGS), { NULL, NULL, 0, NULL } diff --git a/src/python.c b/src/python.c index 4b54359..5360cf6 100644 --- a/src/python.c +++ b/src/python.c @@ -512,7 +512,7 @@ python_push_integer(PyObject *module, const char *name, long value) } static PyObject * -python_exported_log(PyObject *self, PyObject *args) +python_kore_log(PyObject *self, PyObject *args) { int prio; const char *message; @@ -527,6 +527,41 @@ python_exported_log(PyObject *self, PyObject *args) Py_RETURN_TRUE; } +static PyObject * +python_kore_listen(PyObject *self, PyObject *args) +{ + const char *ip, *port, *ccb; + + if (!PyArg_ParseTuple(args, "sss", &ip, &port, &ccb)) { + PyErr_SetString(PyExc_TypeError, "invalid parameters"); + return (NULL); + } + + if (!strcmp(ccb, "")) + ccb = NULL; + + if (!kore_server_bind(ip, port, ccb)) { + PyErr_SetString(PyExc_RuntimeError, "failed to listen"); + return (NULL); + } + + Py_RETURN_TRUE; +} + +static PyObject * +python_kore_fatal(PyObject *self, PyObject *args) +{ + const char *reason; + + if (!PyArg_ParseTuple(args, "s", &reason)) + reason = "python_kore_fatal: PyArg_ParseTuple failed"; + + fatal("%s", reason); + + /* not reached */ + Py_RETURN_TRUE; +} + static PyObject * python_import(const char *path) {