Commit 2915732e authored by Sylvain Berfini's avatar Sylvain Berfini 🎩
Browse files

Finished C# wrapper by adding methods having lists in params

parent 578bfd5f
......@@ -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)
......
......@@ -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<string> 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<T>(IEnumerable<T> 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}});
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment