commit 3d8e0dabc079f5cd74dd6c6235fcc1f39f02a96c
parent 0c0a9371bdd0e27d12e90a6d9428b0c87e313f76
Author: Joris Vink <joris@coders.se>
Date: Wed, 1 Feb 2017 17:12:52 +0100
expose kore_server_bind() and fatal() to python
Diffstat:
2 files changed, 42 insertions(+), 3 deletions(-)
diff --git 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
@@ -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;
@@ -528,6 +528,41 @@ python_exported_log(PyObject *self, PyObject *args)
}
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)
{
PyObject *module;