diff --git a/tools/python/apixml2python/handwritten_definitions.mustache b/tools/python/apixml2python/handwritten_definitions.mustache index dd19be207..73baddea6 100644 --- a/tools/python/apixml2python/handwritten_definitions.mustache +++ b/tools/python/apixml2python/handwritten_definitions.mustache @@ -197,9 +197,11 @@ static PyObject * pylinphone_Core_class_method_new_with_config(PyObject *cls, Py static void pylinphone_ChatRoom_callback_chat_message_state_changed(LinphoneChatMessage *msg, LinphoneChatMessageState state, void *ud) { PyGILState_STATE pygil_state; - PyObject * pycm = NULL; - PyObject * func = NULL; - pylinphone_ChatRoomObject *pycr = (pylinphone_ChatRoomObject *)ud; + PyObject *pycm = NULL; + PyObject *func = NULL; + PyObject *_dict = (PyObject *)ud; + PyObject *_cb = PyDict_GetItemString(_dict, "callback"); + PyObject *_ud = PyDict_GetItemString(_dict, "user_data"); pygil_state = PyGILState_Ensure(); pycm = linphone_chat_message_get_user_data(msg); @@ -207,8 +209,8 @@ static void pylinphone_ChatRoom_callback_chat_message_state_changed(LinphoneChat pycm = pylinphone_ChatMessage_new_from_native_ptr(&pylinphone_ChatMessageType, msg); } pylinphone_trace(1, "[PYLINPHONE] >>> %s(%p, %p [%p], %d, %p)", __FUNCTION__, pycm, msg, state, ud); - if ((pycr->send_message_cb != NULL) && PyCallable_Check(pycr->send_message_cb)) { - if (PyEval_CallObject(pycr->send_message_cb, Py_BuildValue("OiO", pycm, state, pycr->send_message_ud)) == NULL) { + if ((_cb != NULL) && PyCallable_Check(_cb)) { + if (PyEval_CallObject(_cb, Py_BuildValue("OiO", pycm, state, _ud)) == NULL) { PyErr_Print(); } } @@ -218,6 +220,7 @@ static void pylinphone_ChatRoom_callback_chat_message_state_changed(LinphoneChat static PyObject * pylinphone_ChatRoom_instance_method_send_message2(PyObject *self, PyObject *args) { PyObject *_chat_message; + PyObject *_dict; PyObject *_cb; PyObject *_ud; LinphoneChatMessage * _chat_message_native_ptr; @@ -234,18 +237,19 @@ static PyObject * pylinphone_ChatRoom_instance_method_send_message2(PyObject *se PyErr_SetString(PyExc_TypeError, "The msg argument must be a linphone.ChatMessage"); return NULL; } - if (!PyCallable_Check(_cb)) { + if ((_cb != Py_None) && !PyCallable_Check(_cb)) { PyErr_SetString(PyExc_TypeError, "The status_cb argument must be a callable"); return NULL; } if ((_chat_message_native_ptr = pylinphone_ChatMessage_get_native_ptr(_chat_message)) == NULL) { return NULL; } + _dict = PyDict_New(); + PyDict_SetItemString(_dict, "callback", _cb); + PyDict_SetItemString(_dict, "user_data", _ud); pylinphone_trace(1, "[PYLINPHONE] >>> %s(%p [%p], %p [%p], %p, %p)", __FUNCTION__, self, native_ptr, _chat_message, _chat_message_native_ptr, _cb, _ud); - ((pylinphone_ChatRoomObject *)self)->send_message_cb = _cb; - ((pylinphone_ChatRoomObject *)self)->send_message_ud = _ud; - linphone_chat_room_send_message2(native_ptr, _chat_message_native_ptr, pylinphone_ChatRoom_callback_chat_message_state_changed, self); + linphone_chat_room_send_message2(native_ptr, _chat_message_native_ptr, pylinphone_ChatRoom_callback_chat_message_state_changed, _dict); pylinphone_dispatch_messages(); pylinphone_trace(-1, "[PYLINPHONE] <<< %s -> None", __FUNCTION__);