Benny Prijono | 8b8b997 | 2006-11-16 11:18:03 +0000 | [diff] [blame^] | 1 | #include <Python.h> |
| 2 | #include <pjsua-lib/pjsua.h> |
| 3 | |
| 4 | |
| 5 | static PyObject *py_pjsua_perror(PyObject *pSelf, PyObject *pArgs) { |
| 6 | const char *sender; |
| 7 | const char *title; |
| 8 | pj_status_t status; |
| 9 | if (!PyArg_ParseTuple(pArgs, "ssi", &sender, &title, &status)) { |
| 10 | return NULL; |
| 11 | } |
| 12 | pjsua_perror(sender, title, status); |
| 13 | Py_INCREF(Py_None); |
| 14 | return Py_None; |
| 15 | } |
| 16 | static PyObject *py_pjsua_create(PyObject *pSelf, PyObject *pArgs) { |
| 17 | pj_status_t status; |
| 18 | if (!PyArg_ParseTuple(pArgs, "")) { |
| 19 | return NULL; |
| 20 | } |
| 21 | status = pjsua_create(); |
| 22 | printf("status %d\n",status); |
| 23 | return Py_BuildValue("i",status); |
| 24 | } |
| 25 | static PyObject *py_pjsua_start(PyObject *pSelf, PyObject *pArgs) { |
| 26 | pj_status_t status; |
| 27 | if (!PyArg_ParseTuple(pArgs, "")) { |
| 28 | return NULL; |
| 29 | } |
| 30 | status = pjsua_start(); |
| 31 | printf("status %d\n",status); |
| 32 | return Py_BuildValue("i",status); |
| 33 | } |
| 34 | |
| 35 | static PyObject *py_pjsua_destroy(PyObject *pSelf, PyObject *pArgs) { |
| 36 | pj_status_t status; |
| 37 | if (!PyArg_ParseTuple(pArgs, "")) { |
| 38 | return NULL; |
| 39 | } |
| 40 | status = pjsua_destroy(); |
| 41 | printf("status %d\n",status); |
| 42 | return Py_BuildValue("i",status); |
| 43 | } |
| 44 | static PyObject *py_pjsua_handle_events(PyObject *pSelf, PyObject *pArgs) { |
| 45 | int ret; |
| 46 | unsigned msec; |
| 47 | if (!PyArg_ParseTuple(pArgs, "i", &msec)) { |
| 48 | return NULL; |
| 49 | } |
| 50 | ret = pjsua_handle_events(msec); |
| 51 | printf("return %d\n",ret); |
| 52 | return Py_BuildValue("i",ret); |
| 53 | } |
| 54 | static PyObject *py_pjsua_verify_sip_url(PyObject *pSelf, PyObject *pArgs) { |
| 55 | pj_status_t status; |
| 56 | const char *url; |
| 57 | if (!PyArg_ParseTuple(pArgs, "s", &url)) { |
| 58 | return NULL; |
| 59 | } |
| 60 | status = pjsua_verify_sip_url(url); |
| 61 | printf("status %d\n",status); |
| 62 | return Py_BuildValue("i",status); |
| 63 | } |
| 64 | /* doc string */ |
| 65 | static char pjsua_perror_doc[] = "Display error message for the specified error code"; |
| 66 | static char pjsua_create_doc[] = "Instantiate pjsua application"; |
| 67 | static char pjsua_start_doc[] = "Application is recommended to call this function after all initialization is done, so that the library can do additional checking set up additional"; |
| 68 | static char pjsua_destroy_doc[] = "Destroy pjsua"; |
| 69 | static char pjsua_handle_events_doc[] = "Poll pjsua for events, and if necessary block the caller thread for the specified maximum interval (in miliseconds)"; |
| 70 | static char pjsua_verify_sip_url_doc[] = "Verify that valid SIP url is given"; |
| 71 | |
| 72 | /* Map of function names to functions */ |
| 73 | static PyMethodDef py_pjsua_methods[] = { |
| 74 | {"perror", py_pjsua_perror, METH_VARARGS, pjsua_perror_doc}, |
| 75 | {"create", py_pjsua_create, METH_VARARGS, pjsua_create_doc}, |
| 76 | {"start", py_pjsua_start, METH_VARARGS, pjsua_start_doc}, |
| 77 | {"destroy", py_pjsua_destroy, METH_VARARGS, pjsua_destroy_doc}, |
| 78 | {"handle_events", py_pjsua_handle_events, METH_VARARGS, pjsua_handle_events_doc}, |
| 79 | {"verify_sip_url", py_pjsua_verify_sip_url, METH_VARARGS, pjsua_verify_sip_url_doc}, |
| 80 | {NULL, NULL} /* End of functions */ |
| 81 | }; |
| 82 | |
| 83 | |
| 84 | PyMODINIT_FUNC |
| 85 | initpy_pjsua(void) |
| 86 | { |
| 87 | Py_InitModule("py_pjsua", py_pjsua_methods); |
| 88 | } |