summaryrefslogtreecommitdiff
path: root/pjsip-apps/src/py_pjsua
diff options
context:
space:
mode:
authorBenny Prijono <bennylp@teluu.com>2006-11-16 11:18:03 +0000
committerBenny Prijono <bennylp@teluu.com>2006-11-16 11:18:03 +0000
commit2260882aabe327526103f31840cc218ed9552078 (patch)
tree04c0bc7ffa9fe5f9914bddbadfcc2e0a4cd782dc /pjsip-apps/src/py_pjsua
parenta66ebf5d8f421cab171f591799fc94edf76e2d3f (diff)
Added initial Python module
git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@803 74dad513-b988-da41-8d7b-12977e46ad98
Diffstat (limited to 'pjsip-apps/src/py_pjsua')
-rw-r--r--pjsip-apps/src/py_pjsua/pjsua.py17
-rw-r--r--pjsip-apps/src/py_pjsua/py_pjsua.c88
-rw-r--r--pjsip-apps/src/py_pjsua/py_pjsua.def2
-rw-r--r--pjsip-apps/src/py_pjsua/setup.py7
4 files changed, 114 insertions, 0 deletions
diff --git a/pjsip-apps/src/py_pjsua/pjsua.py b/pjsip-apps/src/py_pjsua/pjsua.py
new file mode 100644
index 00000000..cae3480f
--- /dev/null
+++ b/pjsip-apps/src/py_pjsua/pjsua.py
@@ -0,0 +1,17 @@
+# import module py_pjsua
+import py_pjsua
+
+print '''Testing py_pjsua.create : '''
+status = py_pjsua.create()
+print "py status " + `status`
+
+# perror
+print '''Testing error code 70006 : '''
+py_pjsua.perror("py_pjsua","hello",70006)
+
+# test py_pjsua.destroy
+print '''Testing py_pjsua.destroy : '''
+status = py_pjsua.destroy()
+print "py status " + `status`
+
+print '''End Of py_pjsua'''
diff --git a/pjsip-apps/src/py_pjsua/py_pjsua.c b/pjsip-apps/src/py_pjsua/py_pjsua.c
new file mode 100644
index 00000000..4ca49b82
--- /dev/null
+++ b/pjsip-apps/src/py_pjsua/py_pjsua.c
@@ -0,0 +1,88 @@
+#include <Python.h>
+#include <pjsua-lib/pjsua.h>
+
+
+static PyObject *py_pjsua_perror(PyObject *pSelf, PyObject *pArgs) {
+ const char *sender;
+ const char *title;
+ pj_status_t status;
+ if (!PyArg_ParseTuple(pArgs, "ssi", &sender, &title, &status)) {
+ return NULL;
+ }
+ pjsua_perror(sender, title, status);
+ Py_INCREF(Py_None);
+ return Py_None;
+}
+static PyObject *py_pjsua_create(PyObject *pSelf, PyObject *pArgs) {
+ pj_status_t status;
+ if (!PyArg_ParseTuple(pArgs, "")) {
+ return NULL;
+ }
+ status = pjsua_create();
+ printf("status %d\n",status);
+ return Py_BuildValue("i",status);
+}
+static PyObject *py_pjsua_start(PyObject *pSelf, PyObject *pArgs) {
+ pj_status_t status;
+ if (!PyArg_ParseTuple(pArgs, "")) {
+ return NULL;
+ }
+ status = pjsua_start();
+ printf("status %d\n",status);
+ return Py_BuildValue("i",status);
+}
+
+static PyObject *py_pjsua_destroy(PyObject *pSelf, PyObject *pArgs) {
+ pj_status_t status;
+ if (!PyArg_ParseTuple(pArgs, "")) {
+ return NULL;
+ }
+ status = pjsua_destroy();
+ printf("status %d\n",status);
+ return Py_BuildValue("i",status);
+}
+static PyObject *py_pjsua_handle_events(PyObject *pSelf, PyObject *pArgs) {
+ int ret;
+ unsigned msec;
+ if (!PyArg_ParseTuple(pArgs, "i", &msec)) {
+ return NULL;
+ }
+ ret = pjsua_handle_events(msec);
+ printf("return %d\n",ret);
+ return Py_BuildValue("i",ret);
+}
+static PyObject *py_pjsua_verify_sip_url(PyObject *pSelf, PyObject *pArgs) {
+ pj_status_t status;
+ const char *url;
+ if (!PyArg_ParseTuple(pArgs, "s", &url)) {
+ return NULL;
+ }
+ status = pjsua_verify_sip_url(url);
+ printf("status %d\n",status);
+ return Py_BuildValue("i",status);
+}
+/* doc string */
+static char pjsua_perror_doc[] = "Display error message for the specified error code";
+static char pjsua_create_doc[] = "Instantiate pjsua application";
+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";
+static char pjsua_destroy_doc[] = "Destroy pjsua";
+static char pjsua_handle_events_doc[] = "Poll pjsua for events, and if necessary block the caller thread for the specified maximum interval (in miliseconds)";
+static char pjsua_verify_sip_url_doc[] = "Verify that valid SIP url is given";
+
+/* Map of function names to functions */
+static PyMethodDef py_pjsua_methods[] = {
+ {"perror", py_pjsua_perror, METH_VARARGS, pjsua_perror_doc},
+ {"create", py_pjsua_create, METH_VARARGS, pjsua_create_doc},
+ {"start", py_pjsua_start, METH_VARARGS, pjsua_start_doc},
+ {"destroy", py_pjsua_destroy, METH_VARARGS, pjsua_destroy_doc},
+ {"handle_events", py_pjsua_handle_events, METH_VARARGS, pjsua_handle_events_doc},
+ {"verify_sip_url", py_pjsua_verify_sip_url, METH_VARARGS, pjsua_verify_sip_url_doc},
+ {NULL, NULL} /* End of functions */
+};
+
+
+PyMODINIT_FUNC
+initpy_pjsua(void)
+{
+ Py_InitModule("py_pjsua", py_pjsua_methods);
+}
diff --git a/pjsip-apps/src/py_pjsua/py_pjsua.def b/pjsip-apps/src/py_pjsua/py_pjsua.def
new file mode 100644
index 00000000..a8dd2f30
--- /dev/null
+++ b/pjsip-apps/src/py_pjsua/py_pjsua.def
@@ -0,0 +1,2 @@
+EXPORTS
+ initpy_pjsua
diff --git a/pjsip-apps/src/py_pjsua/setup.py b/pjsip-apps/src/py_pjsua/setup.py
new file mode 100644
index 00000000..2ad07d64
--- /dev/null
+++ b/pjsip-apps/src/py_pjsua/setup.py
@@ -0,0 +1,7 @@
+from distutils.core import setup, Extension
+pjproject = "../../../"
+setup(name="py_pjsua", version="0.1",
+ ext_modules = [
+ Extension("py_pjsua", ["py_pjsua.c"], include_dirs=[pjproject + "pjsip/include", pjproject + "pjlib/include", pjproject + "pjlib-util/include", pjproject + "pjmedia/include"], library_dirs=[pjproject + "pjsip/lib", pjproject + "pjlib/lib", pjproject + "pjmedia/lib", pjproject + "pjlib-util/lib"], libraries=["pjsua-i686-pc-linux-gnu", "pjsip-ua-i686-pc-linux-gnu", "pjsip-simple-i686-pc-linux-gnu", "pjsip-i686-pc-linux-gnu", "pjmedia-codec-i686-pc-linux-gnu", "pjmedia-i686-pc-linux-gnu", "pjmedia-codec-i686-pc-linux-gnu", "pjlib-util-i686-pc-linux-gnu", "pj-i686-pc-linux-gnu"]),
+
+ ])