mirror of
https://gitlab.linphone.org/BC/public/linphone-iphone.git
synced 2026-05-07 05:53:06 +00:00
Fix C# wrapper for UWP
This commit is contained in:
parent
6df37d30f9
commit
a399cb0579
2 changed files with 91 additions and 25 deletions
|
|
@ -1,17 +1,17 @@
|
|||
#!/usr/bin/python
|
||||
|
||||
# Copyright (C) 2017 Belledonne Communications SARL
|
||||
#
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
|
@ -58,7 +58,7 @@ class CsharpTranslator(object):
|
|||
|
||||
def translate_method_name(self, name, recursive=False, topAncestor=None):
|
||||
translatedName = name.to_camel_case(lower=True)
|
||||
|
||||
|
||||
if name.prev is None or not recursive or name.prev is topAncestor:
|
||||
return translatedName
|
||||
|
||||
|
|
@ -129,7 +129,7 @@ class CsharpTranslator(object):
|
|||
return False if dllImport else True
|
||||
elif type(_type) is AbsApi.EnumType:
|
||||
return False if dllImport else True
|
||||
|
||||
|
||||
def translate_type(self, _type, isArg, dllImport=True):
|
||||
if type(_type) is AbsApi.EnumType:
|
||||
if dllImport and isArg:
|
||||
|
|
@ -156,10 +156,10 @@ class CsharpTranslator(object):
|
|||
raise AbsApi.Error('translation of bctbx_list_t of enums')
|
||||
else:
|
||||
raise AbsApi.Error('translation of bctbx_list_t of unknow type !')
|
||||
|
||||
|
||||
def translate_argument(self, arg, dllImport=True):
|
||||
return '{0} {1}'.format(self.translate_type(arg.type, True, dllImport), self.translate_argument_name(arg.name))
|
||||
|
||||
|
||||
def throws_exception(self, return_type):
|
||||
if type(return_type) is AbsApi.BaseType:
|
||||
if return_type.name == 'status':
|
||||
|
|
@ -178,7 +178,7 @@ class CsharpTranslator(object):
|
|||
if arg is not method.args[0] or not static:
|
||||
methodElems['params'] += ', '
|
||||
methodElems['params'] += self.translate_argument(arg)
|
||||
|
||||
|
||||
methodDict = {}
|
||||
methodDict['prototype'] = "static extern {return} {name}({params});".format(**methodElems)
|
||||
|
||||
|
|
@ -235,7 +235,7 @@ class CsharpTranslator(object):
|
|||
methodDict['impl']['args'] += self.translate_argument(arg, False)
|
||||
|
||||
return methodDict
|
||||
|
||||
|
||||
###########################################################################################################################################
|
||||
|
||||
def translate_property_getter(self, prop, name, static=False):
|
||||
|
|
@ -311,7 +311,7 @@ class CsharpTranslator(object):
|
|||
methodDict['setter_c_name'] = methodDictSet['setter_c_name']
|
||||
|
||||
return methodDict
|
||||
|
||||
|
||||
def translate_property(self, prop):
|
||||
res = []
|
||||
name = prop.name.to_camel_case()
|
||||
|
|
@ -323,7 +323,7 @@ class CsharpTranslator(object):
|
|||
elif prop.setter is not None:
|
||||
res.append(self.translate_property_setter(prop.setter, name))
|
||||
return res
|
||||
|
||||
|
||||
###########################################################################################################################################
|
||||
|
||||
def translate_listener(self, _class, method):
|
||||
|
|
@ -350,7 +350,7 @@ class CsharpTranslator(object):
|
|||
listenerDict['delegate']['interfaceClassName'] = listenedClass.name.to_camel_case()
|
||||
listenerDict['delegate']['isSimpleListener'] = not listenedClass.multilistener
|
||||
listenerDict['delegate']['isMultiListener'] = listenedClass.multilistener
|
||||
|
||||
|
||||
listenerDict['delegate']['params_public'] = ""
|
||||
listenerDict['delegate']['params_private'] = ""
|
||||
listenerDict['delegate']['params'] = ""
|
||||
|
|
@ -378,7 +378,7 @@ class CsharpTranslator(object):
|
|||
else:
|
||||
listenerDict['delegate']['first_param'] = argName
|
||||
listenerDict['delegate']['params'] = 'thiz'
|
||||
|
||||
|
||||
listenerDict['delegate']['params_public'] += normalType + " " + argName
|
||||
listenerDict['delegate']['params_private'] += dllImportType + " " + argName
|
||||
|
||||
|
|
@ -434,7 +434,7 @@ class CsharpTranslator(object):
|
|||
methodDict['is_generic'] = True
|
||||
|
||||
return methodDict
|
||||
|
||||
|
||||
###########################################################################################################################################
|
||||
|
||||
def translate_enum(self, enum):
|
||||
|
|
@ -470,6 +470,8 @@ class CsharpTranslator(object):
|
|||
classDict = {}
|
||||
classDict['className'] = _class.name.to_camel_case()
|
||||
classDict['isLinphoneFactory'] = _class.name.to_camel_case() == "Factory"
|
||||
classDict['isLinphoneCall'] = _class.name.to_camel_case() == "Call"
|
||||
classDict['isLinphoneCore'] = _class.name.to_camel_case() == "Core"
|
||||
classDict['doc'] = self.docTranslator.translate(_class.briefDescription)
|
||||
classDict['dllImports'] = []
|
||||
|
||||
|
|
@ -482,12 +484,12 @@ class CsharpTranslator(object):
|
|||
else:
|
||||
classDict['dllImports'].append(self.generate_add_for_listener_callbacks(_class, listenerName))
|
||||
classDict['dllImports'].append(self.generate_remove_for_listener_callbacks(_class, listenerName))
|
||||
|
||||
|
||||
for method in _class.classMethods:
|
||||
try:
|
||||
if 'get' in method.name.to_word_list():
|
||||
methodDict = self.translate_property_getter(method, method.name.to_camel_case(), True)
|
||||
#The following doesn't work because there a at least one method that has both getter and setter,
|
||||
#The following doesn't work because there a at least one method that has both getter and setter,
|
||||
#and because it doesn't do both of them at once, property is declared twice
|
||||
#elif 'set' in method.name.to_word_list():
|
||||
# methodDict = self.translate_property_setter(method, method.name.to_camel_case(), True)
|
||||
|
|
@ -521,7 +523,7 @@ class CsharpTranslator(object):
|
|||
interfaceDict['methods'] = []
|
||||
for method in interface.methods:
|
||||
interfaceDict['methods'].append(self.translate_listener(interface, method))
|
||||
|
||||
|
||||
return interfaceDict
|
||||
|
||||
###########################################################################################################################################
|
||||
|
|
@ -549,7 +551,7 @@ class WrapperImpl(object):
|
|||
self.enums = enums
|
||||
self.interfaces = interfaces
|
||||
self.classes = classes
|
||||
|
||||
|
||||
###########################################################################################################################################
|
||||
|
||||
def render(renderer, item, path):
|
||||
|
|
@ -569,21 +571,29 @@ def main():
|
|||
argparser.add_argument('-o --output', type=str, help='the directory where to generate the source files', dest='outputdir', default='.')
|
||||
argparser.add_argument('-n --name', type=str, help='the name of the genarated source file', dest='outputfile', default='LinphoneWrapper.cs')
|
||||
args = argparser.parse_args()
|
||||
|
||||
|
||||
entries = os.listdir(args.outputdir)
|
||||
|
||||
|
||||
project = CApi.Project()
|
||||
project.initFromDir(args.xmldir)
|
||||
project.check()
|
||||
|
||||
|
||||
parser = AbsApi.CParser(project)
|
||||
parser.functionBl = ['linphone_vcard_get_belcard', 'linphone_core_get_current_vtable']
|
||||
parser.functionBl = \
|
||||
['linphone_vcard_get_belcard',\
|
||||
'linphone_core_get_current_vtable',\
|
||||
'linphone_call_set_native_video_window_id',\
|
||||
'linphone_call_get_native_video_window_id',\
|
||||
'linphone_core_get_native_preview_window_id',\
|
||||
'linphone_core_set_native_preview_window_id',\
|
||||
'linphone_core_set_native_video_window_id',\
|
||||
'linphone_core_get_native_video_window_id']
|
||||
parser.classBl += 'LinphoneCoreVTable'
|
||||
parser.methodBl.remove('getCurrentCallbacks')
|
||||
parser.parse_all()
|
||||
translator = CsharpTranslator()
|
||||
renderer = pystache.Renderer()
|
||||
|
||||
|
||||
enums = []
|
||||
for item in parser.enumsIndex.items():
|
||||
if item[1] is not None:
|
||||
|
|
@ -610,4 +620,4 @@ def main():
|
|||
render(renderer, wrapper, args.outputdir + "/" + args.outputfile)
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
main()
|
||||
|
|
|
|||
|
|
@ -376,6 +376,62 @@ namespace Linphone
|
|||
return fromNativePtr<CoreListener>(coreCbsPtr, false);
|
||||
}
|
||||
{{/isLinphoneFactory}}
|
||||
{{#isLinphoneCall}}
|
||||
[DllImport(LinphoneWrapper.LIB_NAME)]
|
||||
static extern IntPtr linphone_call_get_native_video_window_id(IntPtr thiz);
|
||||
[DllImport(LinphoneWrapper.LIB_NAME)]
|
||||
static extern void linphone_call_set_native_video_window_id(IntPtr thiz, IntPtr id);
|
||||
|
||||
/// Get the native window handle of the video window, casted as an unsigned long.
|
||||
public string NativeVideoWindowId
|
||||
{
|
||||
get
|
||||
{
|
||||
return Marshal.PtrToStringUni(linphone_call_get_native_video_window_id(nativePtr));
|
||||
}
|
||||
set
|
||||
{
|
||||
linphone_call_set_native_video_window_id(nativePtr, Marshal.StringToHGlobalUni(value));
|
||||
}
|
||||
}
|
||||
{{/isLinphoneCall}}
|
||||
{{#isLinphoneCore}}
|
||||
[DllImport(LinphoneWrapper.LIB_NAME)]
|
||||
static extern IntPtr linphone_core_get_native_video_window_id(IntPtr thiz);
|
||||
[DllImport(LinphoneWrapper.LIB_NAME)]
|
||||
static extern void linphone_core_set_native_video_window_id(IntPtr thiz, IntPtr id);
|
||||
|
||||
/// Get the native window handle of the video window.
|
||||
public string NativeVideoWindowId
|
||||
{
|
||||
get
|
||||
{
|
||||
return Marshal.PtrToStringUni(linphone_core_get_native_video_window_id(nativePtr));
|
||||
}
|
||||
set
|
||||
{
|
||||
linphone_core_set_native_video_window_id(nativePtr, Marshal.StringToHGlobalUni(value));
|
||||
}
|
||||
}
|
||||
|
||||
[DllImport(LinphoneWrapper.LIB_NAME)]
|
||||
static extern IntPtr linphone_core_get_native_preview_window_id(IntPtr thiz);
|
||||
[DllImport(LinphoneWrapper.LIB_NAME)]
|
||||
static extern void linphone_core_set_native_preview_window_id(IntPtr thiz, IntPtr id);
|
||||
|
||||
/// Get the native window handle of the video preview window.
|
||||
public string NativePreviewWindowId
|
||||
{
|
||||
get
|
||||
{
|
||||
return Marshal.PtrToStringUni(linphone_core_get_native_preview_window_id(nativePtr));
|
||||
}
|
||||
set
|
||||
{
|
||||
linphone_core_set_native_preview_window_id(nativePtr, Marshal.StringToHGlobalUni(value));
|
||||
}
|
||||
}
|
||||
{{/isLinphoneCore}}
|
||||
{{#dllImports}}
|
||||
[DllImport(LinphoneWrapper.LIB_NAME)]
|
||||
{{{prototype}}}
|
||||
|
|
@ -400,7 +456,7 @@ namespace Linphone
|
|||
return Marshal.PtrToStringAnsi(stringPtr);
|
||||
{{/is_string}}
|
||||
{{#is_bool}}
|
||||
return {{getter_c_name}}({{getter_nativePtr}}) == 1;
|
||||
return {{getter_c_name}}({{getter_nativePtr}}) != 0;
|
||||
{{/is_bool}}
|
||||
{{#is_class}}
|
||||
IntPtr ptr = {{getter_c_name}}({{getter_nativePtr}});
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue