From 2915732e029985e05e96f5b56fcbe9144801add2 Mon Sep 17 00:00:00 2001 From: Sylvain Berfini Date: Thu, 20 Apr 2017 17:58:45 +0200 Subject: [PATCH] Finished C# wrapper by adding methods having lists in params --- wrappers/csharp/genwrapper.py | 10 +++++--- wrappers/csharp/wrapper_impl.mustache | 36 ++++++++++++++++++++++++++- 2 files changed, 42 insertions(+), 4 deletions(-) diff --git a/wrappers/csharp/genwrapper.py b/wrappers/csharp/genwrapper.py index 4221bb202..d9d17727a 100644 --- a/wrappers/csharp/genwrapper.py +++ b/wrappers/csharp/genwrapper.py @@ -138,9 +138,7 @@ class CsharpTranslator(object): elif type(_type) is AbsApi.BaseType: return self.translate_base_type(_type, isArg, dllImport) elif type(_type) is AbsApi.ListType: - if isArg: - raise AbsApi.Error('Lists as params are not supported yet') - elif dllImport: + if dllImport: return 'IntPtr' else: if type(_type.containedTypeDesc) is AbsApi.BaseType: @@ -222,6 +220,12 @@ class CsharpTranslator(object): methodDict['impl']['c_args'] += '(int)' + self.translate_argument_name(arg.name) elif self.translate_type(arg.type, False, False) == "bool": methodDict['impl']['c_args'] += self.translate_argument_name(arg.name) + " ? 1 : 0" + elif self.get_class_array_type(self.translate_type(arg.type, False, False)) is not None: + listtype = self.get_class_array_type(self.translate_type(arg.type, False, False)) + if listtype == 'string': + methodDict['impl']['c_args'] += "StringArrayToBctbxList(" + self.translate_argument_name(arg.name) + ")" + else: + methodDict['impl']['c_args'] += "ObjectArrayToBctbxList<" + listtype + ">(" + self.translate_argument_name(arg.name) + ")" else: methodDict['impl']['c_args'] += self.translate_argument_name(arg.name) methodDict['impl']['args'] += self.translate_argument(arg, False) diff --git a/wrappers/csharp/wrapper_impl.mustache b/wrappers/csharp/wrapper_impl.mustache index 5c5ec950d..fd5ce5b9c 100644 --- a/wrappers/csharp/wrapper_impl.mustache +++ b/wrappers/csharp/wrapper_impl.mustache @@ -60,6 +60,12 @@ namespace Linphone [DllImport(LinphoneWrapper.LIB_NAME)] static extern IntPtr bctbx_list_get_data(IntPtr ptr); + + [DllImport(LinphoneWrapper.LIB_NAME)] + static extern IntPtr bctbx_list_append(IntPtr elem, string data); + + [DllImport(LinphoneWrapper.LIB_NAME)] + static extern IntPtr bctbx_list_append(IntPtr elem, IntPtr data); ~LinphoneObject() { @@ -134,6 +140,26 @@ namespace Linphone } } } + + internal static IntPtr StringArrayToBctbxList(IEnumerable stringlist) + { + IntPtr bctbx_list = IntPtr.Zero; + foreach (string s in stringlist) + { + bctbx_list = bctbx_list_append(bctbx_list, s); + } + return bctbx_list; + } + + internal static IntPtr ObjectArrayToBctbxList(IEnumerable objlist) where T : LinphoneObject, new() + { + IntPtr bctbx_list = IntPtr.Zero; + foreach (T ptr in objlist) + { + bctbx_list = bctbx_list_append(bctbx_list, ptr.nativePtr); + } + return bctbx_list; + } } public class LinphoneAndroid @@ -294,13 +320,21 @@ namespace Linphone {{#exception}}int exception_result = {{/exception}}{{setter_c_name}}({{setter_nativePtr}}value); {{#exception}}if (exception_result != 0) throw new LinphoneException("{{property_name}} setter returned value " + exception_result);{{/exception}} {{/is_generic}} + {{#is_string_list}} + {{#exception}}int exception_result = {{/exception}}{{setter_c_name}}({{setter_nativePtr}}StringArrayToBctbxList(value)); + {{#exception}}if (exception_result != 0) throw new LinphoneException("{{property_name}} setter returned value " + exception_result);{{/exception}} + {{/is_string_list}} + {{#is_class_list}} + {{#exception}}int exception_result = {{/exception}}{{setter_c_name}}({{setter_nativePtr}}ObjectArrayToBctbxList<{{{list_type}}}>(value)); + {{#exception}}if (exception_result != 0) throw new LinphoneException("{{property_name}} setter returned value " + exception_result);{{/exception}} + {{/is_class_list}} } {{/has_setter}} } {{/has_property}} {{#has_impl}} {{#impl}} - public {{static}}{{override}}{{{type}}} {{name}}({{args}}) + public {{static}}{{override}}{{{type}}} {{name}}({{{args}}}) { {{#is_string}} IntPtr stringPtr = {{c_name}}({{nativePtr}}{{c_args}});