diff --git a/src/bindings/mono/efl_mono/efl_all.cs b/src/bindings/mono/efl_mono/efl_all.cs index d8c08d3890..bf78df1d3d 100644 --- a/src/bindings/mono/efl_mono/efl_all.cs +++ b/src/bindings/mono/efl_mono/efl_all.cs @@ -36,22 +36,17 @@ static class UnsafeNativeMethods { } } -public enum Components { - Basic, - Ui -} - public static class All { private static bool InitializedUi = false; - public static void Init(Efl.Components components=Components.Basic) { + public static void Init(Efl.Csharp.Components components=Efl.Csharp.Components.Basic) { Eina.Config.Init(); Efl.Eo.Config.Init(); ecore_init(); evas_init(); eldbus.Config.Init(); - if (components == Components.Ui) { + if (components == Efl.Csharp.Components.Ui) { Efl.Ui.Config.Init(); InitializedUi = true; } diff --git a/src/bindings/mono/efl_mono/efl_csharp_application.cs b/src/bindings/mono/efl_mono/efl_csharp_application.cs index b487cf6289..f067b288ec 100644 --- a/src/bindings/mono/efl_mono/efl_csharp_application.cs +++ b/src/bindings/mono/efl_mono/efl_csharp_application.cs @@ -14,8 +14,11 @@ static class UnsafeNativeMethods { namespace Efl { namespace Csharp { + ///The components to be initialized. public enum Components { + ///Basic components: Eina, Eo, Ecore, Evas and DBus. Basic, + ///The same components of and the Elementary widget toolkit. Ui, } /// diff --git a/src/bindings/mono/eina_mono/eina_accessor.cs b/src/bindings/mono/eina_mono/eina_accessor.cs index c3c09c4966..3f2f71b2b3 100644 --- a/src/bindings/mono/eina_mono/eina_accessor.cs +++ b/src/bindings/mono/eina_mono/eina_accessor.cs @@ -27,6 +27,7 @@ public class Accessor : IEnumerable, IDisposable private Ownership Ownership { get; set; } // FIXME Part of the implicit EFL Container interface. Need to make it explicit. + ///Whether this wrapper owns the native accessor. public bool Own { get @@ -40,12 +41,18 @@ public class Accessor : IEnumerable, IDisposable } /// Create a new accessor wrapping the given pointer. + /// The native handle to be wrapped. + /// Whether this wrapper owns the native accessor. public Accessor(IntPtr handle, Ownership owner=Ownership.Managed) { Handle = handle; Ownership = owner; } + /// Create a new accessor wrapping the given pointer. + /// The native handle to be wrapped. + /// Whether this wrapper owns the native accessor. + /// For compatibility with other EFL# containers. Ignored in acessors. public Accessor(IntPtr handle, bool own, bool ownContent=false) : this(handle, own ? Ownership.Managed : Ownership.Unmanaged) { @@ -57,6 +64,9 @@ public class Accessor : IEnumerable, IDisposable Dispose(true); } + /// Disposes of this wrapper, releasing the native accessor if owned. + /// True if this was called from public method. False if + /// called from the C# finalizer. protected virtual void Dispose(bool disposing) { if (Ownership == Ownership.Managed && Handle != IntPtr.Zero) @@ -66,17 +76,23 @@ public class Accessor : IEnumerable, IDisposable } } + /// Finalizer to be called from the Garbage Collector. ~Accessor() { Dispose(false); } - public virtual T Convert(IntPtr data) + /// Convert the native data into managed. This is used when returning the data through a + /// . + /// The data to be converted + /// The managed data representing data. + protected virtual T Convert(IntPtr data) { return NativeToManaged(data); } /// Returns an enumerator that iterates throught this accessor. + /// An enumerator to walk through the acessor items. public IEnumerator GetEnumerator() { if (Handle == IntPtr.Zero) @@ -105,19 +121,38 @@ public class Accessor : IEnumerable, IDisposable } } +///Accessor for Inlists. public class AccessorInList : Accessor { + + /// Create a new accessor wrapping the given pointer. + /// The native handle to be wrapped. + /// Whether this wrapper owns the native accessor. public AccessorInList(IntPtr handle, Ownership own): base(handle, own) {} - public override T Convert(IntPtr data) + + /// Convert the native data into managed. This is used when returning the data through a + /// . + /// The data to be converted + /// The managed data representing data. + protected override T Convert(IntPtr data) { return NativeToManagedInlistNode(data); } } +///Accessor for Inarrays. public class AccessorInArray : Accessor { + /// Create a new accessor wrapping the given pointer. + /// The native handle to be wrapped. + /// Whether this wrapper owns the native accessor. public AccessorInArray(IntPtr handle, Ownership own): base(handle, own) {} - public override T Convert(IntPtr data) + + /// Convert the native data into managed. This is used when returning the data through a + /// . + /// The data to be converted + /// The managed data representing data. + protected override T Convert(IntPtr data) { return NativeToManagedInplace(data); } diff --git a/src/bindings/mono/eina_mono/eina_promises.cs b/src/bindings/mono/eina_mono/eina_promises.cs index 8be5f9d6cb..176a8835ae 100644 --- a/src/bindings/mono/eina_mono/eina_promises.cs +++ b/src/bindings/mono/eina_mono/eina_promises.cs @@ -129,6 +129,9 @@ public class Promise : IDisposable Dispose(false); } + /// Disposes of this wrapper, rejecting the native promise with + /// True if this was called from public method. False if + /// called from the C# finalizer. protected virtual void Dispose(bool disposing) { if (Handle != IntPtr.Zero) @@ -190,7 +193,7 @@ public class Future /// public delegate Eina.Value ResolvedCb(Eina.Value value); - public IntPtr Handle { get; internal set; } + internal IntPtr Handle; /// /// Creates a Future from a native pointer. @@ -317,14 +320,23 @@ public class Future } } +/// Custom marshaler to convert between managed and native . +/// Internal usage in generated code. public class FutureMarshaler : ICustomMarshaler { + ///Wrap the native future with a managed wrapper. + ///Handle to the native future. + ///An wrapping the native future. public object MarshalNativeToManaged(IntPtr pNativeData) { return new Future(pNativeData); } + ///Extracts the native future from a managed wrapper. + ///The managed wrapper. If it is not an , the value returned + ///is . + ///A pointing to the native future. public IntPtr MarshalManagedToNative(object managedObj) { Future f = managedObj as Future; @@ -333,20 +345,27 @@ public class FutureMarshaler : ICustomMarshaler return f.Handle; } + ///Not implemented. The code receiving the native data is in charge of releasing it. + ///The native pointer to be released. public void CleanUpNativeData(IntPtr pNativeData) { } + ///Not implemented. The runtime takes care of releasing it. + ///The managed object to be cleaned. public void CleanUpManagedData(object managedObj) { } + ///Size of the native data size returned + ///The size of the data. public int GetNativeDataSize() { return -1; } + ///Gets an instance of this marshaller. + ///A name that could be used to customize the returned marshaller. Currently not used. + ///The instance that will marshall the data. public static ICustomMarshaler GetInstance(string cookie) { if (marshaler == null) - { marshaler = new FutureMarshaler(); - } return marshaler; } diff --git a/src/bindings/mono/eo_mono/FunctionWrapper.cs b/src/bindings/mono/eo_mono/FunctionWrapper.cs index 03e81383bb..5aa4030a2f 100644 --- a/src/bindings/mono/eo_mono/FunctionWrapper.cs +++ b/src/bindings/mono/eo_mono/FunctionWrapper.cs @@ -3,8 +3,17 @@ using System.Runtime.InteropServices; namespace Efl { namespace Eo { +///Class to load functions pointers from a native module. +/// +///This class has a platform-dependent implementation on whether it +///is compiled for Windows (using LoadLibrary/GetProcAddress) or Unix +///(dlopen/dlsym). public partial class FunctionInterop { + ///Loads a function pointer from the given module. + ///The name of the module containing the function. + ///The name of the function to search for. + ///A function pointer that can be used with delegates. public static IntPtr LoadFunctionPointer(string moduleName, string functionName) { NativeModule module = new NativeModule(moduleName); @@ -13,6 +22,10 @@ public partial class FunctionInterop Eina.Log.Debug($"searching {module.Module} for{functionName}, result {s}"); return s; } + + ///Loads a function pointer from the default module. + ///The name of the function to search for. + ///A function pointer that can be used with delegates. public static IntPtr LoadFunctionPointer(string functionName) { Eina.Log.Debug($"searching {null} for {functionName}"); @@ -21,8 +34,14 @@ public partial class FunctionInterop return s; } } - -public class FunctionWrapper + +///Wraps a native function in a portable manner. +/// +///This is intended as a workaround DllImport limitations when switching between mono and dotnet. +/// +///The parameter T must be a delegate. +/// +public class FunctionWrapper // NOTE: When supporting C# >=7.3, add a where T: System.Delegate? { private Lazy> loadResult; #pragma warning disable 0414 @@ -42,12 +61,18 @@ public class FunctionWrapper return new FunctionLoadResult(Marshal.GetDelegateForFunctionPointer(funcptr)); } } - + + ///Creates a wrapper for the given function of the given module. + ///The name of the module containing the function. + ///The name of the function to search for. public FunctionWrapper(string moduleName, string functionName) : this (new NativeModule(moduleName), functionName) { } - + + ///Creates a wrapper for the given function of the given module. + ///The module wrapper containing the function. + ///The name of the function to search for. public FunctionWrapper(NativeModule module, string functionName) { this.module = module; @@ -58,6 +83,8 @@ public class FunctionWrapper }); } + ///Retrieves the result of function load. + ///The load result. public FunctionLoadResult Value { get @@ -67,12 +94,26 @@ public class FunctionWrapper } } -public enum FunctionLoadResultKind { Success, LibraryNotFound, FunctionNotFound } - +///The outcome of the function load process. +public enum FunctionLoadResultKind { + ///Function was loaded successfully. + Success, + ///Library was not found. + LibraryNotFound, + ///Function symbol was not found in the given module. + FunctionNotFound +} + +///Represents the result of loading a function pointer. public class FunctionLoadResult { + ///The status of the load. public FunctionLoadResultKind Kind; - public T _Delegate; + private T _Delegate; + + ///The delegate wrapping the loaded function pointer. + /// + ///Throws InvalidOperationException if trying to access while not loaded. public T Delegate { get { @@ -82,10 +123,15 @@ public class FunctionLoadResult } } + ///Creates a new load result of the given kind. + ///The outcome of the load process. public FunctionLoadResult(FunctionLoadResultKind kind) { this.Kind = kind; } + + ///Creates a new load result with the given delegate. + ///The delegate wrapping the native function. public FunctionLoadResult(T Delegate) { this._Delegate = Delegate; @@ -93,5 +139,4 @@ public class FunctionLoadResult } } - } } diff --git a/src/bindings/mono/eo_mono/FunctionWrapper_Unix.cs b/src/bindings/mono/eo_mono/FunctionWrapper_Unix.cs index 76ee4892ef..845f8239e0 100644 --- a/src/bindings/mono/eo_mono/FunctionWrapper_Unix.cs +++ b/src/bindings/mono/eo_mono/FunctionWrapper_Unix.cs @@ -6,8 +6,12 @@ namespace Efl { namespace Eo { public partial class FunctionInterop { [DllImport(efl.Libs.Libdl)] - public static extern IntPtr dlsym(IntPtr handle, string symbol); - + private static extern IntPtr dlsym(IntPtr handle, string symbol); + + ///Loads a function pointer from the given module. + ///The module containing the function. + ///The name of the function to search for. + ///A function pointer that can be used with delegates. public static IntPtr LoadFunctionPointer(IntPtr nativeLibraryHandle, string functionName) { Eina.Log.Debug("searching {nativeLibraryHandle} for {functionName}"); @@ -17,5 +21,4 @@ public partial class FunctionInterop } } - } } diff --git a/src/bindings/mono/eo_mono/NativeModule.cs b/src/bindings/mono/eo_mono/NativeModule.cs index 324a933b65..400f24fb87 100644 --- a/src/bindings/mono/eo_mono/NativeModule.cs +++ b/src/bindings/mono/eo_mono/NativeModule.cs @@ -2,10 +2,13 @@ using System; namespace Efl { namespace Eo { +///Wraps a native module that was opened with dlopen/LoadLibrary. public partial class NativeModule : IDisposable { private Lazy module; + ///Lazily tries to load the module with the given name. + ///The name of the module to load. public NativeModule(string libName) { module = new Lazy @@ -15,6 +18,7 @@ public partial class NativeModule : IDisposable }); } + ///The module that was loaded. public IntPtr Module { get @@ -23,6 +27,7 @@ public partial class NativeModule : IDisposable } } + ///Unload and released the handle to the wrapped module. public void Dispose() { UnloadLibrary(module.Value); diff --git a/src/bindings/mono/eo_mono/NativeModule_Unix.cs b/src/bindings/mono/eo_mono/NativeModule_Unix.cs index 6f6939546c..8783895b14 100644 --- a/src/bindings/mono/eo_mono/NativeModule_Unix.cs +++ b/src/bindings/mono/eo_mono/NativeModule_Unix.cs @@ -5,21 +5,45 @@ namespace Efl { namespace Eo { public partial class NativeModule { - public const int RTLD_NOW = 0x002; + private const int RTLD_NOW = 0x002; // Currently we are using GLOBAL due to issues // with the way evas modules are built. - public const int RTLD_GLOBAL = 0x100; + private const int RTLD_GLOBAL = 0x100; [DllImport(efl.Libs.Libdl)] - public static extern IntPtr dlopen(string fileName, int flag); + private static extern IntPtr dlopen(string fileName, int flag); [DllImport(efl.Libs.Libdl)] - public static extern int dlclose(IntPtr handle); + private static extern int dlclose(IntPtr handle); + ///Closes the library handle. + ///The handle to the library. public static void UnloadLibrary(IntPtr handle) { dlclose(handle); } + ///Loads the given library. + /// + ///It attempts to load using the following list of names based on the filename + ///parameter: + /// + /// + /// + ///filename + /// + /// + ///libfilename + /// + /// + ///filename.so + /// + /// + ///libfilename.so + /// + /// + /// + ///The name to search for. + ///The loaded library handle or on failure. public static IntPtr LoadLibrary(string filename) { Eina.Log.Debug($"Loading library {filename}"); diff --git a/src/bindings/mono/meson.build b/src/bindings/mono/meson.build index 3d844e7dac..67c77a647d 100644 --- a/src/bindings/mono/meson.build +++ b/src/bindings/mono/meson.build @@ -62,7 +62,6 @@ blacklisted_files = [ 'efl_vg_root_node.eo', 'efl_vg_shape.eo.cs', 'efl_io_buffer.eo', - 'efl_io_positioner.eo', 'efl_io_queue.eo', 'efl_io_sizer.eo', 'efl_io_closer_fd.eo',