Commit 7557a041 authored by Sylvain Berfini's avatar Sylvain Berfini 🎩

Fixed C# multi listeners, had to rework how to use them

parent 0bcd9630
......@@ -569,6 +569,7 @@ LINPHONE_PUBLIC LinphoneProxyConfig * linphone_account_creator_create_proxy_conf
* Configure an account (create a proxy config and authentication info for it).
* @param[in] creator #LinphoneAccountCreator object
* @return A #LinphoneProxyConfig object if successful, NULL otherwise
* @deprecated
**/
LINPHONE_DEPRECATED LINPHONE_PUBLIC LinphoneProxyConfig * linphone_account_creator_configure(const LinphoneAccountCreator *creator);
......
......@@ -21,17 +21,20 @@
############################################################################
add_custom_command(OUTPUT LinphoneWrapper.cs
COMMAND ${CMAKE_COMMAND} -E remove_directory "${CMAKE_INSTALL_DATADIR}/linphonecs/"
COMMAND ${PYTHON_EXECUTABLE} "${CMAKE_CURRENT_SOURCE_DIR}/genwrapper.py" "${PROJECT_BINARY_DIR}/coreapi/help/doc/doxygen/xml"
DEPENDS ${PROJECT_SOURCE_DIR}/tools/genapixml.py
${LINPHONE_HEADER_FILES}
${PROJECT_SOURCE_DIR}/tools/metadoc.py
${PROJECT_SOURCE_DIR}/tools/abstractapi.py
genwrapper.py
wrapper_impl.mustache
${PROJECT_BINARY_DIR}/coreapi/help/doc/doxygen/xml/index.xml
linphone-doc
)
add_custom_target(linphonecs ALL DEPENDS LinphoneWrapper.cs)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/LinphoneWrapper.cs
DESTINATION ${CMAKE_INSTALL_DATADIR}/linphonecs
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/LinphoneWrapper.cs"
DESTINATION "${CMAKE_INSTALL_DATADIR}/linphonecs/"
)
......@@ -253,7 +253,6 @@ class CsharpTranslator(object):
listenerDict['delegate']['name'] = method.name.translate(self.nameTranslator)
listenerDict['delegate']['interfaceClassName'] = listenedClass.name.translate(self.nameTranslator)
listenerDict['delegate']['isSimpleListener'] = listenedClass.singlelistener
listenerDict['delegate']['isMultiListener'] = listenedClass.multilistener
listenerDict['delegate']['params_public'] = ""
......@@ -296,61 +295,6 @@ class CsharpTranslator(object):
listenerDict['delegate']["c_name_setter"] = c_name_setter
return listenerDict
def generate_getter_for_listener_callbacks(self, _class, classname):
methodDict = self.init_method_dict()
c_name = _class.name.to_snake_case(fullName=True) + '_get_callbacks'
methodDict['prototype'] = "static extern IntPtr {c_name}(IntPtr thiz);".format(classname = classname, c_name = c_name)
methodDict['has_impl'] = False
methodDict['has_property'] = True
methodDict['property_static'] = ''
methodDict['property_return'] = classname
methodDict['property_name'] = 'Listener'
methodDict['has_getter'] = True
methodDict['return'] = classname
methodDict['getter_nativePtr'] = 'nativePtr'
methodDict['getter_c_name'] = c_name
methodDict['is_class'] = True
methodDict['addListener'] = True
return methodDict
def generate_add_for_listener_callbacks(self, _class, classname):
methodDict = self.init_method_dict()
c_name = _class.name.to_snake_case(fullName=True) + '_add_callbacks'
methodDict['prototype'] = "static extern void {c_name}(IntPtr thiz, IntPtr cbs);".format(classname = classname, c_name = c_name)
methodDict['impl']['static'] = ''
methodDict['impl']['type'] = 'void'
methodDict['impl']['name'] = 'AddListener'
methodDict['impl']['return'] = ''
methodDict['impl']['c_name'] = c_name
methodDict['impl']['nativePtr'] = 'nativePtr, '
methodDict['impl']['args'] = classname + ' cbs'
methodDict['impl']['c_args'] = 'cbs != null ? cbs.nativePtr : IntPtr.Zero'
methodDict['is_generic'] = True
methodDict['impl']['addListener'] = True
methodDict['impl']['removeListener'] = False
return methodDict
def generate_remove_for_listener_callbacks(self, _class, classname):
methodDict = self.init_method_dict()
c_name = _class.name.to_snake_case(fullName=True) + '_remove_callbacks'
methodDict['prototype'] = "static extern void {c_name}(IntPtr thiz, IntPtr cbs);".format(classname = classname, c_name = c_name)
methodDict['impl']['static'] = ''
methodDict['impl']['type'] = 'void'
methodDict['impl']['name'] = 'RemoveListener'
methodDict['impl']['return'] = ''
methodDict['impl']['c_name'] = c_name
methodDict['impl']['nativePtr'] = 'nativePtr, '
methodDict['impl']['args'] = classname + ' cbs'
methodDict['impl']['c_args'] = 'cbs != null ? cbs.nativePtr : IntPtr.Zero'
methodDict['is_generic'] = True
methodDict['impl']['addListener'] = False
methodDict['impl']['removeListener'] = True
return methodDict
###########################################################################################################################################
def translate_enum(self, enum):
......@@ -396,11 +340,9 @@ class CsharpTranslator(object):
islistenable = _class.listenerInterface is not None
if islistenable:
listenerName = _class.listenerInterface.name.translate(self.nameTranslator)
if _class.singlelistener:
classDict['dllImports'].append(self.generate_getter_for_listener_callbacks(_class, listenerName))
if _class.multilistener:
classDict['dllImports'].append(self.generate_add_for_listener_callbacks(_class, listenerName))
classDict['dllImports'].append(self.generate_remove_for_listener_callbacks(_class, listenerName))
classDict['listener'] = {}
classDict['listener']['listener_constructor'] = _class.name.to_snake_case()
classDict['listener']['interfaceName'] = listenerName
for method in _class.classMethods:
try:
......
......@@ -336,6 +336,11 @@ namespace Linphone
[StructLayout(LayoutKind.Sequential)]
public class {{interfaceName}} : LinphoneObject
{
~{{interfaceName}}()
{
unregister();
}
[DllImport(LinphoneWrapper.LIB_NAME, CallingConvention = CallingConvention.Cdecl)]
static extern void {{set_user_data_name}}(IntPtr thiz, IntPtr listener);
......@@ -366,11 +371,11 @@ namespace Linphone
private static void {{cb_name}}({{params_private}})
{
{{interfaceClassName}} thiz = fromNativePtr<{{interfaceClassName}}>({{first_param}});
{{#isSimpleListener}}{{interfaceName}} single_listener = thiz.Listener;
single_listener.{{var_public}}?.Invoke({{{params}}});
{{/isSimpleListener}}
{{#isMultiListener}}{{interfaceName}} multi_listener = thiz.CurrentCallbacks;
multi_listener.{{var_public}}?.Invoke({{{params}}});{{/isMultiListener}}
{{interfaceName}} current_listener = thiz.CurrentCallbacks;
if (current_listener != null)
{
current_listener.{{var_public}}?.Invoke({{{params}}});
}
}
public {{name_public}} {{name}}
......@@ -442,18 +447,7 @@ namespace Linphone
[StructLayout(LayoutKind.Sequential)]
public class {{className}} : LinphoneObject
{
{{#isLinphoneFactory}}
[DllImport(LinphoneWrapper.LIB_NAME, CallingConvention = CallingConvention.Cdecl)]
static extern IntPtr linphone_factory_create_core_cbs(IntPtr factory);
public CoreListener CreateCoreListener()
{
IntPtr coreCbsPtr = linphone_factory_create_core_cbs(nativePtr);
return fromNativePtr<CoreListener>(coreCbsPtr, false);
}
{{/isLinphoneFactory}}
{{#isLinphoneCall}}
/// Get the native window handle of the video window, casted as an unsigned long.
public string NativeVideoWindowIdString
{
......@@ -468,7 +462,6 @@ namespace Linphone
}
{{/isLinphoneCall}}
{{#isLinphoneCore}}
[DllImport(LinphoneWrapper.LIB_NAME, CallingConvention = CallingConvention.Cdecl)]
static extern IntPtr linphone_core_get_ms_factory(IntPtr thiz);
......@@ -508,6 +501,42 @@ namespace Linphone
}
}
{{/isLinphoneCore}}
{{#listener}}
[DllImport(LinphoneWrapper.LIB_NAME, CallingConvention = CallingConvention.Cdecl)]
static extern IntPtr linphone_factory_create_{{listener_constructor}}_cbs(IntPtr factory);
[DllImport(LinphoneWrapper.LIB_NAME, CallingConvention = CallingConvention.Cdecl)]
static extern IntPtr linphone_{{listener_constructor}}_add_callbacks(IntPtr thiz, IntPtr cbs);
[DllImport(LinphoneWrapper.LIB_NAME, CallingConvention = CallingConvention.Cdecl)]
static extern IntPtr linphone_{{listener_constructor}}_remove_callbacks(IntPtr thiz, IntPtr cbs);
~{{className}}()
{
if (listener != null)
{
linphone_{{listener_constructor}}_remove_callbacks(nativePtr, listener.nativePtr);
}
}
private {{interfaceName}} listener;
public {{interfaceName}} Listener
{
get {
if (listener == null)
{
IntPtr nativeListener = linphone_factory_create_{{listener_constructor}}_cbs(IntPtr.Zero);
listener = fromNativePtr<{{interfaceName}}>(nativeListener, false);
linphone_{{listener_constructor}}_add_callbacks(nativePtr, nativeListener);
listener.register();
}
return listener;
}
}
{{/listener}}
{{#dllImports}}
[DllImport(LinphoneWrapper.LIB_NAME, CallingConvention = CallingConvention.Cdecl)]
{{{prototype}}}
......@@ -537,9 +566,6 @@ namespace Linphone
{{#is_class}}
IntPtr ptr = {{getter_c_name}}({{getter_nativePtr}});
{{{property_return}}} obj = fromNativePtr<{{return}}>(ptr, {{takeRef}});
{{#addListener}}
obj.register();
{{/addListener}}
return obj;
{{/is_class}}
{{#is_enum}}
......@@ -600,12 +626,6 @@ namespace Linphone
{{/doc}}
public {{static}}{{override}}{{{type}}} {{name}}({{{args}}})
{
{{#addListener}}
cbs.register();
{{/addListener}}
{{#removeListener}}
cbs.unregister();
{{/removeListener}}
{{#is_string}}
IntPtr stringPtr = {{c_name}}({{nativePtr}}{{{c_args}}});
return Marshal.PtrToStringAnsi(stringPtr);
......
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