forked from enlightenment/efl
mono: encapsulate internal FunctionWrapper
Summary: Depends on D10340 Test Plan: meson setup -Dbindings=mono,cxx -Dmono-beta=true Reviewers: lauromoura, segfaultxavi, Jaehyun_Cho Reviewed By: lauromoura Subscribers: cedric, #reviewers, woohyun, #committers Tags: #efl Differential Revision: https://phab.enlightenment.org/D10342
This commit is contained in:
parent
72da16f679
commit
1db12b5fb4
|
@ -24,13 +24,13 @@ namespace Efl.Eo
|
||||||
///This class has a platform-dependent implementation on whether it
|
///This class has a platform-dependent implementation on whether it
|
||||||
///is compiled for Windows (using LoadLibrary/GetProcAddress) or Unix
|
///is compiled for Windows (using LoadLibrary/GetProcAddress) or Unix
|
||||||
///(dlopen/dlsym).</summary>
|
///(dlopen/dlsym).</summary>
|
||||||
public static partial class FunctionInterop
|
internal static partial class FunctionInterop
|
||||||
{
|
{
|
||||||
///<summary>Loads a function pointer from the given module.</summary>
|
///<summary>Loads a function pointer from the given module.</summary>
|
||||||
///<param name="moduleName">The name of the module containing the function.</param>
|
///<param name="moduleName">The name of the module containing the function.</param>
|
||||||
///<param name="functionName">The name of the function to search for.</param>
|
///<param name="functionName">The name of the function to search for.</param>
|
||||||
///<returns>A function pointer that can be used with delegates.</returns>
|
///<returns>A function pointer that can be used with delegates.</returns>
|
||||||
public static IntPtr LoadFunctionPointer(string moduleName, string functionName)
|
internal static IntPtr LoadFunctionPointer(string moduleName, string functionName)
|
||||||
{
|
{
|
||||||
IntPtr module = NativeModule.LoadLibrary(moduleName);
|
IntPtr module = NativeModule.LoadLibrary(moduleName);
|
||||||
Eina.Log.Debug($"searching {module} for {functionName}");
|
Eina.Log.Debug($"searching {module} for {functionName}");
|
||||||
|
@ -42,7 +42,7 @@ public static partial class FunctionInterop
|
||||||
///<summary>Loads a function pointer from the default module.</summary>
|
///<summary>Loads a function pointer from the default module.</summary>
|
||||||
///<param name="functionName">The name of the function to search for.</param>
|
///<param name="functionName">The name of the function to search for.</param>
|
||||||
///<returns>A function pointer that can be used with delegates.</returns>
|
///<returns>A function pointer that can be used with delegates.</returns>
|
||||||
public static IntPtr LoadFunctionPointer(string functionName)
|
internal static IntPtr LoadFunctionPointer(string functionName)
|
||||||
{
|
{
|
||||||
Eina.Log.Debug($"searching {null} for {functionName}");
|
Eina.Log.Debug($"searching {null} for {functionName}");
|
||||||
var s = FunctionInterop.dlsym(IntPtr.Zero, functionName);
|
var s = FunctionInterop.dlsym(IntPtr.Zero, functionName);
|
||||||
|
@ -57,7 +57,7 @@ public static partial class FunctionInterop
|
||||||
///
|
///
|
||||||
///The parameter T must be a delegate.
|
///The parameter T must be a delegate.
|
||||||
///</summary>
|
///</summary>
|
||||||
public class FunctionWrapper<T> // NOTE: When supporting C# >=7.3, add a where T: System.Delegate?
|
class FunctionWrapper<T> // NOTE: When supporting C# >=7.3, add a where T: System.Delegate?
|
||||||
{
|
{
|
||||||
private Lazy<FunctionLoadResult<T>> loadResult;
|
private Lazy<FunctionLoadResult<T>> loadResult;
|
||||||
#pragma warning disable 0414
|
#pragma warning disable 0414
|
||||||
|
@ -87,7 +87,7 @@ public class FunctionWrapper<T> // NOTE: When supporting C# >=7.3, add a where T
|
||||||
///<summary>Creates a wrapper for the given function of the given module.</summary>
|
///<summary>Creates a wrapper for the given function of the given module.</summary>
|
||||||
///<param name="moduleName">The name of the module containing the function.</param>
|
///<param name="moduleName">The name of the module containing the function.</param>
|
||||||
///<param name="functionName">The name of the function to search for.</param>
|
///<param name="functionName">The name of the function to search for.</param>
|
||||||
public FunctionWrapper(string moduleName, string functionName)
|
internal FunctionWrapper(string moduleName, string functionName)
|
||||||
: this(new NativeModule(moduleName), functionName)
|
: this(new NativeModule(moduleName), functionName)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -95,7 +95,7 @@ public class FunctionWrapper<T> // NOTE: When supporting C# >=7.3, add a where T
|
||||||
///<summary>Creates a wrapper for the given function of the given module.</summary>
|
///<summary>Creates a wrapper for the given function of the given module.</summary>
|
||||||
///<param name="module">The module wrapper containing the function.</param>
|
///<param name="module">The module wrapper containing the function.</param>
|
||||||
///<param name="functionName">The name of the function to search for.</param>
|
///<param name="functionName">The name of the function to search for.</param>
|
||||||
public FunctionWrapper(NativeModule module, string functionName)
|
internal FunctionWrapper(NativeModule module, string functionName)
|
||||||
{
|
{
|
||||||
this.module = module;
|
this.module = module;
|
||||||
loadResult = new Lazy<FunctionLoadResult<T>>
|
loadResult = new Lazy<FunctionLoadResult<T>>
|
||||||
|
@ -107,7 +107,7 @@ public class FunctionWrapper<T> // NOTE: When supporting C# >=7.3, add a where T
|
||||||
|
|
||||||
///<summary>Retrieves the result of function load.</summary>
|
///<summary>Retrieves the result of function load.</summary>
|
||||||
///<returns>The load result.</returns>
|
///<returns>The load result.</returns>
|
||||||
public FunctionLoadResult<T> Value
|
internal FunctionLoadResult<T> Value
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
|
@ -117,7 +117,7 @@ public class FunctionWrapper<T> // NOTE: When supporting C# >=7.3, add a where T
|
||||||
}
|
}
|
||||||
|
|
||||||
///<summary>The outcome of the function load process.</summary>
|
///<summary>The outcome of the function load process.</summary>
|
||||||
public enum FunctionLoadResultKind
|
enum FunctionLoadResultKind
|
||||||
{
|
{
|
||||||
///<summary>Function was loaded successfully.</summary>
|
///<summary>Function was loaded successfully.</summary>
|
||||||
Success,
|
Success,
|
||||||
|
@ -128,16 +128,16 @@ public enum FunctionLoadResultKind
|
||||||
}
|
}
|
||||||
|
|
||||||
///<summary>Represents the result of loading a function pointer.</summary>
|
///<summary>Represents the result of loading a function pointer.</summary>
|
||||||
public class FunctionLoadResult<T>
|
class FunctionLoadResult<T>
|
||||||
{
|
{
|
||||||
///<summary>The status of the load.</summary>
|
///<summary>The status of the load.</summary>
|
||||||
public FunctionLoadResultKind Kind;
|
FunctionLoadResultKind Kind;
|
||||||
private T _Delegate;
|
private T _Delegate;
|
||||||
|
|
||||||
///<summary>The delegate wrapping the loaded function pointer.
|
///<summary>The delegate wrapping the loaded function pointer.
|
||||||
///
|
///
|
||||||
///Throws InvalidOperationException if trying to access while not loaded.</summary>
|
///Throws InvalidOperationException if trying to access while not loaded.</summary>
|
||||||
public T Delegate
|
internal T Delegate
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
|
@ -152,14 +152,14 @@ public class FunctionLoadResult<T>
|
||||||
|
|
||||||
///<summary>Creates a new load result of the given kind.</summary>
|
///<summary>Creates a new load result of the given kind.</summary>
|
||||||
///<param name="kind">The outcome of the load process.</param>
|
///<param name="kind">The outcome of the load process.</param>
|
||||||
public FunctionLoadResult(FunctionLoadResultKind kind)
|
internal FunctionLoadResult(FunctionLoadResultKind kind)
|
||||||
{
|
{
|
||||||
this.Kind = kind;
|
this.Kind = kind;
|
||||||
}
|
}
|
||||||
|
|
||||||
///<summary>Creates a new load result with the given delegate.</summary>
|
///<summary>Creates a new load result with the given delegate.</summary>
|
||||||
///<param name="Delegate">The delegate wrapping the native function.</param>
|
///<param name="Delegate">The delegate wrapping the native function.</param>
|
||||||
public FunctionLoadResult(T Delegate)
|
internal FunctionLoadResult(T Delegate)
|
||||||
{
|
{
|
||||||
this._Delegate = Delegate;
|
this._Delegate = Delegate;
|
||||||
this.Kind = FunctionLoadResultKind.Success;
|
this.Kind = FunctionLoadResultKind.Success;
|
||||||
|
|
|
@ -19,7 +19,7 @@ using System.Runtime.InteropServices;
|
||||||
namespace Efl.Eo
|
namespace Efl.Eo
|
||||||
{
|
{
|
||||||
|
|
||||||
public static partial class FunctionInterop
|
internal static partial class FunctionInterop
|
||||||
{
|
{
|
||||||
[DllImport(efl.Libs.Libdl)]
|
[DllImport(efl.Libs.Libdl)]
|
||||||
private static extern IntPtr dlsym(IntPtr handle, string symbol);
|
private static extern IntPtr dlsym(IntPtr handle, string symbol);
|
||||||
|
@ -28,7 +28,7 @@ public static partial class FunctionInterop
|
||||||
///<param name="nativeLibraryHandle">The module containing the function.</param>
|
///<param name="nativeLibraryHandle">The module containing the function.</param>
|
||||||
///<param name="functionName">The name of the function to search for.</param>
|
///<param name="functionName">The name of the function to search for.</param>
|
||||||
///<returns>A function pointer that can be used with delegates.</returns>
|
///<returns>A function pointer that can be used with delegates.</returns>
|
||||||
public static IntPtr LoadFunctionPointer(IntPtr nativeLibraryHandle, string functionName)
|
internal static IntPtr LoadFunctionPointer(IntPtr nativeLibraryHandle, string functionName)
|
||||||
{
|
{
|
||||||
Eina.Log.Debug($"searching {nativeLibraryHandle} for {functionName}");
|
Eina.Log.Debug($"searching {nativeLibraryHandle} for {functionName}");
|
||||||
var s = FunctionInterop.dlsym(nativeLibraryHandle, functionName);
|
var s = FunctionInterop.dlsym(nativeLibraryHandle, functionName);
|
||||||
|
|
|
@ -19,10 +19,10 @@ using System.Runtime.InteropServices;
|
||||||
namespace Efl.Eo
|
namespace Efl.Eo
|
||||||
{
|
{
|
||||||
|
|
||||||
public static partial class FunctionInterop
|
static partial class FunctionInterop
|
||||||
{
|
{
|
||||||
[DllImport(efl.Libs.Libdl)]
|
[DllImport(efl.Libs.Libdl)]
|
||||||
public static extern IntPtr GetProcAddress(IntPtr handle, string symbol);
|
internal static extern IntPtr GetProcAddress(IntPtr handle, string symbol);
|
||||||
|
|
||||||
private static IntPtr LoadFunctionPointer(IntPtr nativeLibraryHandle, string functionName)
|
private static IntPtr LoadFunctionPointer(IntPtr nativeLibraryHandle, string functionName)
|
||||||
=> FunctionInterop.GetProcAddress(nativeLibraryHandle, functionName);
|
=> FunctionInterop.GetProcAddress(nativeLibraryHandle, functionName);
|
||||||
|
|
|
@ -52,12 +52,12 @@ public static class Globals
|
||||||
|
|
||||||
[return: MarshalAs(UnmanagedType.U1)]
|
[return: MarshalAs(UnmanagedType.U1)]
|
||||||
public delegate bool efl_object_init_delegate();
|
public delegate bool efl_object_init_delegate();
|
||||||
public static readonly FunctionWrapper<efl_object_init_delegate> efl_object_init_ptr =
|
static readonly FunctionWrapper<efl_object_init_delegate> efl_object_init_ptr =
|
||||||
new FunctionWrapper<efl_object_init_delegate>(efl.Libs.EoModule, "efl_object_init");
|
new FunctionWrapper<efl_object_init_delegate>(efl.Libs.EoModule, "efl_object_init");
|
||||||
public static bool efl_object_init() => efl_object_init_ptr.Value.Delegate();
|
public static bool efl_object_init() => efl_object_init_ptr.Value.Delegate();
|
||||||
|
|
||||||
public delegate void efl_object_shutdown_delegate();
|
public delegate void efl_object_shutdown_delegate();
|
||||||
public static readonly FunctionWrapper<efl_object_shutdown_delegate> efl_object_shutdown_ptr = new FunctionWrapper<efl_object_shutdown_delegate>(efl.Libs.EoModule, "efl_object_shutdown");
|
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();
|
public 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.Eo)] internal static extern void efl_object_shutdown();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue