mirror of https://git.kore.io/kore.git
expose kore_server_bind() and fatal() to python
This commit is contained in:
parent
0c0a9371bd
commit
3d8e0dabc0
|
@ -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 }
|
||||
|
|
37
src/python.c
37
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)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue