mirror of
https://gitlab.linphone.org/BC/public/linphone-iphone.git
synced 2026-02-04 04:09:19 +00:00
Improved C# wrapper
This commit is contained in:
parent
0e10e7a5e7
commit
7b00ab9e2f
1 changed files with 26 additions and 23 deletions
|
|
@ -20,20 +20,22 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Collections.Generic;
|
||||
#if __IOS__
|
||||
using ObjCRuntime;
|
||||
#endif
|
||||
|
||||
namespace Linphone
|
||||
{
|
||||
#region Wrapper specifics
|
||||
#region Wrapper specifics
|
||||
/// <summary>
|
||||
/// Only contains the LIB_NAME value that represents the library in which all DllImport are made
|
||||
/// </summary>
|
||||
public class LinphoneWrapper
|
||||
{
|
||||
#if ANDROID
|
||||
public const string LIB_NAME = "linphone"; // With this, it automatically finds liblinphone.so
|
||||
#else
|
||||
#if __IOS__
|
||||
public const string LIB_NAME = "linphone.framework/linphone";
|
||||
#else
|
||||
public const string LIB_NAME = "linphone"; // With this, it automatically finds liblinphone.so
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
@ -58,9 +60,9 @@ namespace Linphone
|
|||
internal IntPtr nativePtr;
|
||||
|
||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||
private delegate void OnLinphoneObjectDataDestroyed(IntPtr data);
|
||||
private delegate void OnLinphoneObjectDataDestroyed(IntPtr data);
|
||||
|
||||
[DllImport(LinphoneWrapper.LIB_NAME)]
|
||||
[DllImport(LinphoneWrapper.LIB_NAME)]
|
||||
static extern int belle_sip_object_data_set(IntPtr ptr, string name, IntPtr data, OnLinphoneObjectDataDestroyed cb);
|
||||
|
||||
[DllImport(LinphoneWrapper.LIB_NAME)]
|
||||
|
|
@ -84,16 +86,18 @@ namespace Linphone
|
|||
[DllImport(LinphoneWrapper.LIB_NAME)]
|
||||
static extern IntPtr bctbx_list_append(IntPtr elem, IntPtr data);
|
||||
|
||||
#if __IOS__
|
||||
[MonoPInvokeCallback(typeof(OnLinphoneObjectDataDestroyed))]
|
||||
private static void onDataDestroyed(IntPtr data)
|
||||
{
|
||||
if (data != IntPtr.Zero)
|
||||
{
|
||||
//Console.WriteLine("Freeing C# handle");
|
||||
GCHandle handle = GCHandle.FromIntPtr(data);
|
||||
handle.Free();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
private static void onDataDestroyed(IntPtr data)
|
||||
{
|
||||
if (data != IntPtr.Zero)
|
||||
{
|
||||
//Console.WriteLine("Freeing C# handle");
|
||||
GCHandle handle = GCHandle.FromIntPtr(data);
|
||||
handle.Free();
|
||||
}
|
||||
}
|
||||
|
||||
~LinphoneObject()
|
||||
{
|
||||
|
|
@ -118,18 +122,15 @@ namespace Linphone
|
|||
//Console.WriteLine("Reffing" + obj.ToString());
|
||||
}
|
||||
obj.nativePtr = ptr;
|
||||
/*objPtr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(T)));
|
||||
Marshal.StructureToPtr(obj, objPtr, false);*/
|
||||
GCHandle handle = GCHandle.Alloc(obj);
|
||||
objPtr = GCHandle.ToIntPtr(handle);
|
||||
GCHandle handle = GCHandle.Alloc(obj, GCHandleType.Weak);
|
||||
objPtr = GCHandle.ToIntPtr(handle);
|
||||
belle_sip_object_data_set(ptr, "cs_obj", objPtr, onDataDestroyed);
|
||||
return obj;
|
||||
}
|
||||
else
|
||||
{
|
||||
//T obj = Marshal.PtrToStructure<T>(objPtr);
|
||||
GCHandle handle = GCHandle.FromIntPtr(objPtr);
|
||||
T obj = (T)handle.Target;
|
||||
T obj = (T)handle.Target;
|
||||
if (takeRef)
|
||||
{
|
||||
obj.nativePtr = belle_sip_object_ref(obj.nativePtr);
|
||||
|
|
@ -272,12 +273,14 @@ namespace Linphone
|
|||
|
||||
public delegate void {{name_public}}({{params_public}});
|
||||
private {{name_public}} {{var_public}};
|
||||
|
||||
|
||||
#if __IOS__
|
||||
[MonoPInvokeCallback(typeof({{name_private}}))]
|
||||
#endif
|
||||
private static void {{cb_name}}({{params_private}})
|
||||
{
|
||||
{{interfaceClassName}} thiz = fromNativePtr<{{interfaceClassName}}>({{first_param}});
|
||||
{{#isSimpleListener}}{{interfaceName}} listener = thiz.Listener;{{/isSimpleListener}}
|
||||
{{#isSimpleListener}}{{interfaceName}} listener = thiz.Listener;{{/isSimpleListener}}
|
||||
{{#isMultiListener}}{{interfaceName}} listener = thiz.CurrentCallbacks;{{/isMultiListener}}
|
||||
listener.{{var_public}}?.Invoke({{{params}}});
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue