mono: encapsulate internal iwrapper members

Summary: Depends on D10339

Test Plan: meson setup -Dbindings=mono,cxx -Dmono-beta=true

Reviewers: segfaultxavi, Jaehyun_Cho, YOhoho

Reviewed By: YOhoho

Subscribers: cedric, #reviewers, #committers, woohyun

Tags: #efl

Differential Revision: https://phab.enlightenment.org/D10345
This commit is contained in:
Lauro Moura 2019-10-29 11:56:38 -03:00
parent 46ebd2033b
commit 26161e9fbe
2 changed files with 52 additions and 52 deletions

View File

@ -20,7 +20,7 @@ namespace Efl.Eo
{
/// <summary>Observe the ownership state of an Eo wrapper and control its life-cycle.</summary>
public class WrapperSupervisor
internal class WrapperSupervisor
{
private System.WeakReference weakRef;
#pragma warning disable CS0414
@ -30,7 +30,7 @@ public class WrapperSupervisor
/// <summary>Create a new supervisor for the given.</summary>
/// <param name="obj">Efl object to be supervised.</param>
public WrapperSupervisor(Efl.Eo.IWrapper obj)
internal WrapperSupervisor(Efl.Eo.IWrapper obj)
{
weakRef = new WeakReference(obj);
sharedRef = null;
@ -38,7 +38,7 @@ public class WrapperSupervisor
}
/// <summary>Efl object being supervised.</summary>
public Efl.Eo.IWrapper Target
internal Efl.Eo.IWrapper Target
{
get
{
@ -47,7 +47,7 @@ public class WrapperSupervisor
}
/// <summary>Dictionary that holds the events related with the supervised object.</summary>
public EventDictionary EoEvents
internal EventDictionary EoEvents
{
get
{
@ -56,13 +56,13 @@ public class WrapperSupervisor
}
/// <summary>To be called when the object is uniquely owned by C#, removing its strong reference and making it available to garbage collection.</summary>
public void MakeUnique()
internal void MakeUnique()
{
sharedRef = null;
}
/// <summary>To be called when the object is owned in the native library too, adding a strong reference to it and making it unavailable for garbage collection.</summary>
public void MakeShared()
internal void MakeShared()
{
if (this.Target == null)
throw new InvalidOperationException("Tried to make a null reference shared.");

View File

@ -36,7 +36,7 @@ namespace Eo
public static class Globals
{
/// <summary>Represents the type of the native Efl_Class.</summary>
public enum EflClassType
internal enum EflClassType
{
/// <summary>Regular EFL classes.</summary>
Regular = 0,
@ -51,14 +51,14 @@ public static class Globals
}
[return: MarshalAs(UnmanagedType.U1)]
public delegate bool efl_object_init_delegate();
internal delegate bool efl_object_init_delegate();
static readonly FunctionWrapper<efl_object_init_delegate> efl_object_init_ptr =
new FunctionWrapper<efl_object_init_delegate>(efl.Libs.EoModule, "efl_object_init");
public static bool efl_object_init() => efl_object_init_ptr.Value.Delegate();
internal static bool efl_object_init() => efl_object_init_ptr.Value.Delegate();
public delegate void efl_object_shutdown_delegate();
internal delegate void efl_object_shutdown_delegate();
static readonly FunctionWrapper<efl_object_shutdown_delegate> efl_object_shutdown_ptr = new FunctionWrapper<efl_object_shutdown_delegate>(efl.Libs.EoModule, "efl_object_shutdown");
public static void efl_object_shutdown() => efl_object_shutdown_ptr.Value.Delegate();
internal static void efl_object_shutdown() => efl_object_shutdown_ptr.Value.Delegate();
// [DllImport(efl.Libs.Eo)] internal static extern void efl_object_shutdown();
[DllImport(efl.Libs.CustomExports)] internal static extern IntPtr efl_mono_wrapper_supervisor_get(IntPtr eo);
@ -70,19 +70,19 @@ public static class Globals
[DllImport(efl.Libs.Eo)] internal static extern IntPtr
_efl_add_internal_start_bindings([MarshalAs(UnmanagedType.LPStr)] String file, int line, IntPtr klass, IntPtr parent,
byte is_ref, byte is_fallback, IntPtr substitute_ctor, IntPtr data);
public delegate IntPtr
internal delegate IntPtr
_efl_add_end_delegate(IntPtr eo, byte is_ref, byte is_fallback);
[DllImport(efl.Libs.Eo)] internal static extern IntPtr
_efl_add_end(IntPtr eo, byte is_ref, byte is_fallback);
public delegate IntPtr
internal delegate IntPtr
efl_ref_delegate(IntPtr eo);
[DllImport(efl.Libs.Eo)] internal static extern IntPtr
efl_ref(IntPtr eo);
public delegate void
internal delegate void
efl_unref_delegate(IntPtr eo);
[DllImport(efl.Libs.CustomExports)] internal static extern void
efl_unref(IntPtr eo);
public delegate int
internal delegate int
efl_ref_count_delegate(IntPtr eo);
[DllImport(efl.Libs.Eo)] internal static extern int
efl_ref_count(IntPtr eo);
@ -199,11 +199,11 @@ public static class Globals
[DllImport(efl.Libs.Eo)] internal static extern IntPtr
efl_class_new(IntPtr class_description, IntPtr parent, IntPtr extn1, IntPtr extn2, IntPtr extn3, IntPtr extn4, IntPtr extn5, IntPtr extn6, IntPtr extn7, IntPtr extn8, IntPtr extn9, IntPtr extn10, IntPtr extn11, IntPtr extn12, IntPtr extn13, IntPtr extn14, IntPtr extn15, IntPtr extn16, IntPtr extn17, IntPtr extn18, IntPtr extn19, IntPtr extn20, IntPtr extn21, IntPtr extn22, IntPtr extn23, IntPtr extn24, IntPtr extn25, IntPtr extn26, IntPtr extn27, IntPtr extn28, IntPtr extn29, IntPtr extn30, IntPtr extn31, IntPtr extn32, IntPtr extn33, IntPtr extn34, IntPtr extn35, IntPtr extn36, IntPtr extn37, IntPtr extn38, IntPtr extn39, IntPtr extn40, IntPtr extn41, IntPtr extn42, IntPtr extn43, IntPtr extn44, IntPtr extn45, IntPtr extn46, IntPtr extn47, IntPtr extn48, IntPtr term);
public delegate byte efl_class_functions_set_delegate(IntPtr klass_id, IntPtr object_ops, IntPtr class_ops);
internal delegate byte efl_class_functions_set_delegate(IntPtr klass_id, IntPtr object_ops, IntPtr class_ops);
[DllImport(efl.Libs.Eo)] internal static extern byte efl_class_functions_set(IntPtr klass_id, IntPtr object_ops, IntPtr class_ops);
public delegate IntPtr efl_data_scope_get_delegate(IntPtr obj, IntPtr klass);
internal delegate IntPtr efl_data_scope_get_delegate(IntPtr obj, IntPtr klass);
[DllImport(efl.Libs.Eo)] internal static extern IntPtr efl_data_scope_get(IntPtr obj, IntPtr klass);
public delegate IntPtr efl_super_delegate(IntPtr obj, IntPtr klass);
internal delegate IntPtr efl_super_delegate(IntPtr obj, IntPtr klass);
/// <summary>Gets a native pointer to <c>obj</c> that forwards the method call to its parent
/// implementation.
@ -214,13 +214,13 @@ public static class Globals
/// <param name="obj">The native pointer to be prepared.</param>
/// <param name="klass">The current class.</param>
/// <returns>The native pointer to <c>obj</c> prepared to call the parent implementation of <c>klass</c>.</returns>
public static IntPtr Super(IntPtr obj, IntPtr klass)
internal static IntPtr Super(IntPtr obj, IntPtr klass)
{
return efl_super(obj, klass);
}
[DllImport(efl.Libs.Eo)] internal static extern IntPtr efl_super(IntPtr obj, IntPtr klass);
public delegate IntPtr efl_class_get_delegate(IntPtr obj);
internal delegate IntPtr efl_class_get_delegate(IntPtr obj);
[DllImport(efl.Libs.Eo)] internal static extern IntPtr efl_class_get(IntPtr obj);
/// <summary>Gets the native EO class pointer for the given object.
@ -230,13 +230,13 @@ public static class Globals
/// <param name="obj">The native pointer to the <see cref="Efl.Object" /> instance to get the native class
/// from.</param>
/// <returns>The native class pointer or <see cref="IntPtr.Zero" /> if no such class existis.</returns>
public static IntPtr GetClass(IntPtr obj)
internal static IntPtr GetClass(IntPtr obj)
{
return efl_class_get(obj);
}
[DllImport(efl.Libs.Eo)] internal static extern EflClassType efl_class_type_get(IntPtr klass);
public delegate IntPtr dlerror_delegate();
internal delegate IntPtr dlerror_delegate();
[DllImport(efl.Libs.Evil)] internal static extern IntPtr dlerror();
[DllImport(efl.Libs.Eo)] internal static extern IntPtr efl_constructor(IntPtr obj);
@ -261,36 +261,36 @@ public static class Globals
/// <param name="desc">The native event description.</param>
/// <param name="event_info">The native payload of the event.</param>
/// <returns><c>false</c> if one of the callbacks aborted the call. <c>true</c> otherwise.</returns>
public static bool CallEventCallback(IntPtr obj, IntPtr desc, IntPtr event_info)
internal static bool CallEventCallback(IntPtr obj, IntPtr desc, IntPtr event_info)
{
return efl_event_callback_call(obj, desc, event_info);
}
public const int RTLD_NOW = 2;
internal const int RTLD_NOW = 2;
public delegate byte class_initializer(IntPtr klass);
internal delegate byte class_initializer(IntPtr klass);
public static T GetParamHelper<T>(Nullable<T> v) where T : struct
internal static T GetParamHelper<T>(Nullable<T> v) where T : struct
{
return v.Value;
}
public static U GetParamHelper<U>(U v)
internal static U GetParamHelper<U>(U v)
{
return v;
}
public static bool ParamHelperCheck<T>(Nullable<T> v) where T : struct
internal static bool ParamHelperCheck<T>(Nullable<T> v) where T : struct
{
return v.HasValue;
}
public static bool ParamHelperCheck<U>(U v)
internal static bool ParamHelperCheck<U>(U v)
{
return v != null;
}
public static IntPtr register_class(String class_name, IntPtr base_klass, System.Type type)
internal static IntPtr register_class(String class_name, IntPtr base_klass, System.Type type)
{
ClassDescription description;
description.version = 2; // EO_VERSION
@ -329,7 +329,7 @@ public static class Globals
return klass;
}
public static List<IntPtr> get_efl_interfaces(System.Type type)
internal static List<IntPtr> get_efl_interfaces(System.Type type)
{
System.Type base_type = type.BaseType;
@ -369,7 +369,7 @@ public static class Globals
return null;
}
public static System.Collections.Generic.List<string>
internal static System.Collections.Generic.List<string>
GetUserMethods(System.Type type)
{
var r = new System.Collections.Generic.List<string>();
@ -397,7 +397,7 @@ public static class Globals
return r;
}
public static byte class_initializer_call(IntPtr klass, System.Type type)
internal static byte class_initializer_call(IntPtr klass, System.Type type)
{
Eina.Log.Debug($"called with 0x{klass.ToInt64():x} {type}");
var derived = type.BaseType;
@ -446,7 +446,7 @@ public static class Globals
return 1;
}
public static IntPtr call_efl_class_new(IntPtr desc, IntPtr bk, List<IntPtr> il = null)
internal static IntPtr call_efl_class_new(IntPtr desc, IntPtr bk, List<IntPtr> il = null)
{
IntPtr nul = IntPtr.Zero;
int iface_list_count = (il == null ? 0 : il.Count);
@ -505,12 +505,12 @@ public static class Globals
}
}
public static Efl.Eo.WrapperSupervisor WrapperSupervisorPtrToManaged(IntPtr wsPtr)
internal static Efl.Eo.WrapperSupervisor WrapperSupervisorPtrToManaged(IntPtr wsPtr)
{
return (Efl.Eo.WrapperSupervisor) GCHandle.FromIntPtr(wsPtr).Target;
}
public static Efl.Eo.WrapperSupervisor GetWrapperSupervisor(IntPtr eo)
internal static Efl.Eo.WrapperSupervisor GetWrapperSupervisor(IntPtr eo)
{
var wsPtr = Efl.Eo.Globals.efl_mono_wrapper_supervisor_get(eo);
if (wsPtr == IntPtr.Zero)
@ -521,13 +521,13 @@ public static class Globals
return WrapperSupervisorPtrToManaged(wsPtr);
}
public static void SetWrapperSupervisor(IntPtr eo, Efl.Eo.WrapperSupervisor ws)
internal static void SetWrapperSupervisor(IntPtr eo, Efl.Eo.WrapperSupervisor ws)
{
GCHandle gch = GCHandle.Alloc(ws);
Efl.Eo.Globals.efl_mono_wrapper_supervisor_set(eo, GCHandle.ToIntPtr(gch));
}
public static void free_dict_values(Dictionary<String, IntPtr> dict)
internal static void free_dict_values(Dictionary<String, IntPtr> dict)
{
foreach (IntPtr ptr in dict.Values)
{
@ -535,7 +535,7 @@ public static class Globals
}
}
public static void free_stringshare_values(Dictionary<String, IntPtr> dict)
internal static void free_stringshare_values(Dictionary<String, IntPtr> dict)
{
foreach (IntPtr ptr in dict.Values)
{
@ -543,13 +543,13 @@ public static class Globals
}
}
public static void free_gchandle(IntPtr ptr)
internal static void free_gchandle(IntPtr ptr)
{
GCHandle handle = GCHandle.FromIntPtr(ptr);
handle.Free();
}
public static System.Threading.Tasks.Task<Eina.Value> WrapAsync(Eina.Future future, CancellationToken token)
internal static System.Threading.Tasks.Task<Eina.Value> WrapAsync(Eina.Future future, CancellationToken token)
{
// Creates a task that will wait for SetResult for completion.
// TaskCompletionSource is used to create tasks for 'external' Task sources.
@ -621,7 +621,7 @@ public static class Globals
/// <param name="handle">The Eo id to be wrapped.</param>
/// <param name="shouldIncRef">Whether we should increase the refcount of the Eo instance.</param>
/// <returns>The C# wrapper for this instance.</returns>
public static Efl.Eo.IWrapper CreateWrapperFor(System.IntPtr handle, bool shouldIncRef=true)
internal static Efl.Eo.IWrapper CreateWrapperFor(System.IntPtr handle, bool shouldIncRef=true)
{
if (handle == IntPtr.Zero)
@ -695,7 +695,7 @@ public static class Globals
}
private static Efl.FreeWrapperSupervisorCb FreeWrapperSupervisorCallbackDelegate = new Efl.FreeWrapperSupervisorCb(FreeWrapperSupervisorCallback);
public static void FreeWrapperSupervisorCallback(IntPtr eo)
internal static void FreeWrapperSupervisorCallback(IntPtr eo)
{
try
{
@ -733,12 +733,12 @@ public static class Globals
}
}
public static void SetNativeDisposeCallbacks()
internal static void SetNativeDisposeCallbacks()
{
efl_mono_wrapper_supervisor_callbacks_set(FreeWrapperSupervisorCallbackDelegate);
}
public static void ThreadSafeFreeCbExec(EinaFreeCb cbFreeCb, IntPtr cbData)
internal static void ThreadSafeFreeCbExec(EinaFreeCb cbFreeCb, IntPtr cbData)
{
EinaFreeCb cb = (IntPtr gcHandlePtr) => {
cbFreeCb(cbData);
@ -848,9 +848,9 @@ public interface IWrapper
}
}
public static class ClassRegister
internal static class ClassRegister
{
public static System.Type GetManagedType(IntPtr klass)
internal static System.Type GetManagedType(IntPtr klass)
{
System.Type t;
if (Efl.Eo.ClassRegister.typeFromKlass.TryGetValue(klass, out t))
@ -914,7 +914,7 @@ public static class ClassRegister
return t;
}
public static IntPtr GetKlass(System.Type objectType)
internal static IntPtr GetKlass(System.Type objectType)
{
IntPtr klass;
if (klassFromType.TryGetValue(objectType, out klass))
@ -941,7 +941,7 @@ public static class ClassRegister
return RegisterKlass(baseKlass, objectType);
}
public static IntPtr GetInheritKlassOrRegister(IntPtr baseKlass, System.Type objectType)
internal static IntPtr GetInheritKlassOrRegister(IntPtr baseKlass, System.Type objectType)
{
IntPtr klass;
if (klassFromType.TryGetValue(objectType, out klass))
@ -1011,16 +1011,16 @@ public static class ClassRegister
return (IntPtr)(method.Invoke(null, null));
}
public static void AddToKlassTypeBiDictionary(IntPtr klassPtr, System.Type objectType)
internal static void AddToKlassTypeBiDictionary(IntPtr klassPtr, System.Type objectType)
{
klassFromType[objectType] = klassPtr;
typeFromKlass[klassPtr] = objectType;
}
public static readonly System.Collections.Concurrent.ConcurrentDictionary<System.Type, System.IntPtr> klassFromType
internal static readonly System.Collections.Concurrent.ConcurrentDictionary<System.Type, System.IntPtr> klassFromType
= new System.Collections.Concurrent.ConcurrentDictionary<System.Type, System.IntPtr>();
public static readonly System.Collections.Concurrent.ConcurrentDictionary<System.IntPtr, System.Type> typeFromKlass
internal static readonly System.Collections.Concurrent.ConcurrentDictionary<System.IntPtr, System.Type> typeFromKlass
= new System.Collections.Concurrent.ConcurrentDictionary<System.IntPtr, System.Type>();
private static readonly object klassAllocLock = new object();