Skip to content

Commit

Permalink
More ticket #982: added MWI support for Python
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.pjsip.org/repos/pjproject/trunk@2976 74dad513-b988-da41-8d7b-12977e46ad98
  • Loading branch information
bennylp committed Oct 29, 2009
1 parent 53add07 commit 6a46488
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 0 deletions.
28 changes: 28 additions & 0 deletions pjsip-apps/src/python/_pjsua.c
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,33 @@ static void cb_on_typing(pjsua_call_id call_id, const pj_str_t *from,
}


/*
* on_mwi_info
*/
static void cb_on_mwi_info(pjsua_acc_id acc_id, pjsua_mwi_info *mwi_info)
{
if (PyCallable_Check(g_obj_callback->on_mwi_info)) {
PyObject *param_acc_id, *param_body;
pj_str_t body;

ENTER_PYTHON();

body.ptr = mwi_info->rdata->msg_info.msg->body->data;
body.slen = mwi_info->rdata->msg_info.msg->body->len;

PyObject_CallFunctionObjArgs(
g_obj_callback->on_mwi_info,
param_acc_id = Py_BuildValue("i",acc_id),
param_body = PyString_FromPJ(&body),
NULL
);

Py_DECREF(param_acc_id);
Py_DECREF(param_body);

LEAVE_PYTHON();
}
}

/*
* translate_hdr
Expand Down Expand Up @@ -901,6 +928,7 @@ static PyObject *py_pjsua_init(PyObject *pSelf, PyObject *pArgs)
cfg_ua.cb.on_pager2 = &cb_on_pager;
cfg_ua.cb.on_pager_status2 = &cb_on_pager_status;
cfg_ua.cb.on_typing2 = &cb_on_typing;
cfg_ua.cb.on_mwi_info = &cb_on_mwi_info;

p_cfg_ua = &cfg_ua;

Expand Down
16 changes: 16 additions & 0 deletions pjsip-apps/src/python/_pjsua.h
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ typedef struct PyObj_pjsua_callback
PyObject * on_pager;
PyObject * on_pager_status;
PyObject * on_typing;
PyObject * on_mwi_info;
} PyObj_pjsua_callback;


Expand All @@ -258,6 +259,7 @@ static void PyObj_pjsua_callback_delete(PyObj_pjsua_callback* self)
Py_XDECREF(self->on_pager);
Py_XDECREF(self->on_pager_status);
Py_XDECREF(self->on_typing);
Py_XDECREF(self->on_mwi_info);
self->ob_type->tp_free((PyObject*)self);
}

Expand Down Expand Up @@ -291,6 +293,7 @@ static PyObject * PyObj_pjsua_callback_new(PyTypeObject *type,
self->on_pager = Py_BuildValue("");
self->on_pager_status = Py_BuildValue("");
self->on_typing = Py_BuildValue("");
self->on_mwi_info = Py_BuildValue("");
}

return (PyObject *)self;
Expand Down Expand Up @@ -394,6 +397,11 @@ static PyMemberDef PyObj_pjsua_callback_members[] =
offsetof(PyObj_pjsua_callback, on_typing), 0,
"Notify application about typing indication."
},
{
"on_mwi_info", T_OBJECT_EX,
offsetof(PyObj_pjsua_callback, on_mwi_info), 0,
"Notify application about MWI indication."
},
{NULL} /* Sentinel */
};

Expand Down Expand Up @@ -1645,6 +1653,7 @@ typedef struct
PyObject *id;
PyObject *reg_uri;
int publish_enabled;
int mwi_enabled;
PyObject *force_contact;
PyListObject *proxy;
unsigned reg_timeout;
Expand Down Expand Up @@ -1698,6 +1707,7 @@ static void PyObj_pjsua_acc_config_import(PyObj_pjsua_acc_config *obj,
Py_XDECREF(obj->reg_uri);
obj->reg_uri = PyString_FromPJ(&cfg->reg_uri);
obj->publish_enabled = cfg->publish_enabled;
obj->mwi_enabled = cfg->mwi_enabled;
Py_XDECREF(obj->force_contact);
obj->force_contact = PyString_FromPJ(&cfg->force_contact);
Py_XDECREF(obj->proxy);
Expand Down Expand Up @@ -1753,6 +1763,7 @@ static void PyObj_pjsua_acc_config_export(pjsua_acc_config *cfg,
cfg->id = PyString_ToPJ(obj->id);
cfg->reg_uri = PyString_ToPJ(obj->reg_uri);
cfg->publish_enabled = obj->publish_enabled;
cfg->mwi_enabled = obj->mwi_enabled;
cfg->force_contact = PyString_ToPJ(obj->force_contact);

cfg->proxy_cnt = PyList_Size((PyObject*)obj->proxy);
Expand Down Expand Up @@ -1857,6 +1868,11 @@ static PyMemberDef PyObj_pjsua_acc_config_members[] =
offsetof(PyObj_pjsua_acc_config, publish_enabled), 0,
"Publish presence? "
},
{
"mwi_enabled", T_INT,
offsetof(PyObj_pjsua_acc_config, mwi_enabled), 0,
"Enable MWI subscription "
},
{
"force_contact", T_OBJECT_EX,
offsetof(PyObj_pjsua_acc_config, force_contact), 0,
Expand Down
21 changes: 21 additions & 0 deletions pjsip-apps/src/python/pjsua.py
Original file line number Diff line number Diff line change
Expand Up @@ -993,6 +993,19 @@ def on_typing(self, from_uri, contact, is_typing):
"""
pass

def on_mwi_info(self, body):
"""
Notification about change in Message Summary / Message Waiting
Indication (RFC 3842) status. MWI subscription must be enabled
in the account config to receive this notification.
Keyword arguments:
body -- String containing message body as received in the
NOTIFY request.
"""
pass



class Account:
Expand Down Expand Up @@ -2113,6 +2126,7 @@ def init(self, ua_cfg=None, log_cfg=None, media_cfg=None):
py_ua_cfg.cb.on_pager = _cb_on_pager
py_ua_cfg.cb.on_pager_status = _cb_on_pager_status
py_ua_cfg.cb.on_typing = _cb_on_typing
py_ua_cfg.cb.on_mwi_info = _cb_on_mwi_info;

err = _pjsua.init(py_ua_cfg, log_cfg._cvt_to_pjsua(),
media_cfg._cvt_to_pjsua())
Expand Down Expand Up @@ -2763,6 +2777,11 @@ def _cb_on_typing(self, call_id, from_uri, to_uri, contact, is_typing,
else:
acc._cb.on_typing(from_uri, contact, is_typing)

def _cb_on_mwi_info(self, acc_id, body):
acc = self._lookup_account(acc_id)
if acc:
return acc._cb.on_mwi_info(body)

def _cb_on_buddy_state(self, buddy_id):
buddy = self._lookup_buddy(buddy_id)
if buddy:
Expand Down Expand Up @@ -2816,6 +2835,8 @@ def _cb_on_pager_status(call_id, to, body, user_data, status, reason, acc_id):
def _cb_on_typing(call_id, from_uri, to, contact, is_typing, acc_id):
_lib._cb_on_typing(call_id, from_uri, to, contact, is_typing, acc_id)

def _cb_on_mwi_info(acc_id, body):
_lib._cb_on_mwi_info(acc_id, body)

# Worker thread
def _worker_thread_main(arg):
Expand Down

0 comments on commit 6a46488

Please sign in to comment.