summaryrefslogtreecommitdiff
path: root/pjsip-apps/src/py_pjsua/py_pjsua.c
blob: 4ca49b827838ebea938a325fd312be706f6b4674 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
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);
}