From 102cab7620cca5afec2468fe569beabe6340a98b Mon Sep 17 00:00:00 2001 From: Ghislain MARY Date: Fri, 8 Aug 2014 16:24:13 +0200 Subject: [PATCH] Hand-written version of linphone_core_iterate() in the Python wrapper. It adds a loop to peek Windows messages to prevent a deadlock in the MoveWindow function. --- tools/python/apixml2python.py | 1 + .../python/apixml2python/handwritten.mustache | 23 +++++++++++++++++++ tools/python/apixml2python/linphone.py | 11 +++++---- .../apixml2python/linphone_module.mustache | 9 ++++++++ 4 files changed, 40 insertions(+), 4 deletions(-) diff --git a/tools/python/apixml2python.py b/tools/python/apixml2python.py index c93b21eb1..5d8e18d57 100755 --- a/tools/python/apixml2python.py +++ b/tools/python/apixml2python.py @@ -115,6 +115,7 @@ blacklisted_functions = [ 'lp_config_section_to_dict' ] hand_written_functions = [ + 'linphone_core_iterate', 'linphone_core_new', 'linphone_core_new_with_config' ] diff --git a/tools/python/apixml2python/handwritten.mustache b/tools/python/apixml2python/handwritten.mustache index 101cabe8c..2033799e7 100644 --- a/tools/python/apixml2python/handwritten.mustache +++ b/tools/python/apixml2python/handwritten.mustache @@ -177,3 +177,26 @@ static PyObject * pylinphone_Core_class_method_new_with_config(PyObject *cls, Py Py_DECREF(self); return pyret; } + +static PyObject * pylinphone_Core_instance_method_iterate(PyObject *self, PyObject *args) { + LinphoneCore *native_ptr = pylinphone_Core_get_native_ptr(self); + if (native_ptr == NULL) { + PyErr_SetString(PyExc_TypeError, "Invalid linphone.Core instance"); + return NULL; + } + + pylinphone_trace(1, "[PYLINPHONE] >>> %s(%p [%p])", __FUNCTION__, self, native_ptr); + linphone_core_iterate(native_ptr); +#ifdef WIN32 + { + MSG msg; + while (PeekMessage(&msg, NULL, 0, 0, 1)) { + TranslateMessage(&msg); + DispatchMessage(&msg); + } + } +#endif + + pylinphone_trace(-1, "[PYLINPHONE] <<< %s -> None", __FUNCTION__); + Py_RETURN_NONE; +} diff --git a/tools/python/apixml2python/linphone.py b/tools/python/apixml2python/linphone.py index 0a8c1f550..5e7a0873d 100644 --- a/tools/python/apixml2python/linphone.py +++ b/tools/python/apixml2python/linphone.py @@ -701,6 +701,7 @@ class LinphoneModule(object): c['class_has_user_data'] = False c['class_type_methods'] = [] c['class_type_hand_written_methods'] = [] + c['class_instance_hand_written_methods'] = [] c['class_object_members'] = '' if c['class_name'] == 'Core': c['class_object_members'] = "\tPyObject *vtable_dict;" @@ -738,13 +739,15 @@ class LinphoneModule(object): method_name = xml_instance_method.get('name') if method_name in blacklisted_functions: continue - method_name = method_name.replace(c['class_c_function_prefix'], '') if method_name in self.internal_instance_method_names: continue m = {} - m['method_name'] = method_name - m['method_xml_node'] = xml_instance_method - c['class_instance_methods'].append(m) + m['method_name'] = method_name.replace(c['class_c_function_prefix'], '') + if method_name in hand_written_functions: + c['class_instance_hand_written_methods'].append(m) + else: + m['method_xml_node'] = xml_instance_method + c['class_instance_methods'].append(m) c['class_properties'] = [] xml_properties = xml_class.findall("./properties/property") for xml_property in xml_properties: diff --git a/tools/python/apixml2python/linphone_module.mustache b/tools/python/apixml2python/linphone_module.mustache index b85253611..2a9c903b0 100644 --- a/tools/python/apixml2python/linphone_module.mustache +++ b/tools/python/apixml2python/linphone_module.mustache @@ -22,6 +22,9 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include #include +#ifdef WIN32 +#include +#endif #ifdef _MSC_VER #define PYLINPHONE_INLINE __inline @@ -53,6 +56,9 @@ static PyObject * pylinphone_{{class_name}}_new_from_native_ptr(PyTypeObject *ty {{#class_type_hand_written_methods}} static PyObject * pylinphone_{{class_name}}_class_method_{{method_name}}(PyObject *cls, PyObject *args); {{/class_type_hand_written_methods}} +{{#class_instance_hand_written_methods}} +static PyObject * pylinphone_{{class_name}}_instance_method_{{method_name}}(PyObject *self, PyObject *args); +{{/class_instance_hand_written_methods}} {{/classes}} {{#events}} @@ -103,6 +109,9 @@ static PyMethodDef pylinphone_{{class_name}}_instance_methods[] = { { "{{method_name}}", pylinphone_{{class_name}}_class_method_{{method_name}}, METH_VARARGS | METH_CLASS, "" }, {{/class_type_methods}} /* Instance methods */ +{{#class_instance_hand_written_methods}} + { "{{method_name}}", pylinphone_{{class_name}}_instance_method_{{method_name}}, METH_VARARGS, "" }, +{{/class_instance_hand_written_methods}} {{#class_instance_methods}} { "{{method_name}}", pylinphone_{{class_name}}_instance_method_{{method_name}}, METH_VARARGS, "" }, {{/class_instance_methods}}