diff --git a/src/bindings/mono/efl_mono/efl_all.cs b/src/bindings/mono/efl_mono/efl_all.cs index bf78df1d3d..70b9825b9d 100644 --- a/src/bindings/mono/efl_mono/efl_all.cs +++ b/src/bindings/mono/efl_mono/efl_all.cs @@ -6,10 +6,11 @@ using System.Threading; using static Efl.UnsafeNativeMethods; -namespace Efl { - -static class UnsafeNativeMethods { +namespace Efl +{ +static class UnsafeNativeMethods +{ private delegate void init_func_delegate(); [DllImport(efl.Libs.Ecore)] public static extern void ecore_init(); [DllImport(efl.Libs.Ecore)] public static extern void ecore_shutdown(); @@ -27,39 +28,48 @@ static class UnsafeNativeMethods { [DllImport(efl.Libs.Elementary)] public static extern void elm_run(); [DllImport(efl.Libs.Elementary)] public static extern void elm_exit(); - static UnsafeNativeMethods() { + static UnsafeNativeMethods() + { _evas_init = new Efl.Eo.FunctionWrapper("evas", "evas_init"); } + public static void evas_init() { _evas_init.Value.Delegate(); } } -public static class All { +public static class All +{ private static bool InitializedUi = false; - public static void Init(Efl.Csharp.Components components=Efl.Csharp.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 == Efl.Csharp.Components.Ui) { + if (components == Efl.Csharp.Components.Ui) + { Efl.Ui.Config.Init(); InitializedUi = true; } } /// Shutdowns all EFL subsystems. - public static void Shutdown() { + public static void Shutdown() + { // Try to cleanup everything before actually shutting down. System.GC.Collect(); System.GC.WaitForPendingFinalizers(); if (InitializedUi) + { Efl.Ui.Config.Shutdown(); + } + eldbus.Config.Shutdown(); evas_shutdown(); ecore_shutdown(); @@ -69,29 +79,38 @@ public static class All { } // Placeholder. Will move to elm_config.cs later -namespace Ui { +namespace Ui +{ -public static class Config { - public static void Init() { +public static class Config +{ + public static void Init() + { // TODO Support elm command line arguments #if WIN32 // Not a native define, we define it in our build system // Ecore_Win32 uses OleInitialize, which requires single thread apartments if (System.Threading.Thread.CurrentThread.GetApartmentState() != ApartmentState.STA) + { throw new InvalidOperationException("UI Applications require STAThreadAttribute in Main()"); + } #endif elm_init(0, IntPtr.Zero); elm_policy_set((int)Elm.Policy.Quit, (int)Elm.PolicyQuit.LastWindowHidden); } - public static void Shutdown() { + + public static void Shutdown() + { elm_shutdown(); } - public static void Run() { + public static void Run() + { elm_run(); } - public static void Exit() { + public static void Exit() + { elm_exit(); } } diff --git a/src/bindings/mono/efl_mono/efl_csharp_application.cs b/src/bindings/mono/efl_mono/efl_csharp_application.cs index 3bac96170d..1e63d62c4a 100644 --- a/src/bindings/mono/efl_mono/efl_csharp_application.cs +++ b/src/bindings/mono/efl_mono/efl_csharp_application.cs @@ -3,99 +3,131 @@ using System.Runtime.InteropServices; using System.Threading; using static Efl.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, - } - /// - /// This represents the entry point for the EFL framework - /// You can use this class to implement the 4 abstract methods which will then be called accordingly - /// All subsystems of efl are booted up correctly when the abstract methods of this class are called. - /// - /// - /// Calls to efl outside those efl-callbacks or outside the mainloop are not allowed and will lead to issues - /// - /// - /// UserApp is the class that implements the Application abstract - /// - /// public static void Main() { - /// UserApp editor = new UserApp(); - /// editor.Launch(editor); - /// } - /// - /// - public abstract class Application { - //the initializied components - private static Components initComponent; - //what follows are 3 private functions to boot up the internals of efl - private static void Init(Efl.Csharp.Components component) { +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, +} + +/// +/// This represents the entry point for the EFL framework +/// You can use this class to implement the 4 abstract methods which will then be called accordingly +/// All subsystems of efl are booted up correctly when the abstract methods of this class are called. +/// +/// +/// Calls to efl outside those efl-callbacks or outside the mainloop are not allowed and will lead to issues +/// +/// +/// UserApp is the class that implements the Application abstract +/// +/// public static void Main() +/// { +/// UserApp editor = new UserApp(); +/// editor.Launch(editor); +/// } +/// +/// +public abstract class Application +{ + //the initializied components + private static Components initComponent; + //what follows are 3 private functions to boot up the internals of efl + private static void Init(Efl.Csharp.Components component) + { Eina.Config.Init(); Efl.Eo.Config.Init(); ecore_init(); evas_init(); eldbus.Config.Init(); - if (component == Components.Ui) { - // TODO Support elm command line arguments -#if WIN32 // Not a native define, we define it in our build system - // Ecore_Win32 uses OleInitialize, which requires single thread apartments - if (System.Threading.Thread.CurrentThread.GetApartmentState() != ApartmentState.STA) - throw new InvalidOperationException("UI Applications require STAThreadAttribute in Main()"); + if (component == Components.Ui) + { + // TODO Support elm command line arguments +#if WIN32 // Not a native define, we define it in our build system + // Ecore_Win32 uses OleInitialize, which requires single thread apartments + if (System.Threading.Thread.CurrentThread.GetApartmentState() != ApartmentState.STA) + { + throw new InvalidOperationException("UI Applications require STAThreadAttribute in Main()"); + } #endif - elm_init(0, IntPtr.Zero); + elm_init(0, IntPtr.Zero); - elm_policy_set((int)Elm.Policy.Quit, (int)Elm.PolicyQuit.LastWindowHidden); + elm_policy_set((int)Elm.Policy.Quit, (int)Elm.PolicyQuit.LastWindowHidden); } + initComponent = component; - } - private static void Shutdown() { + } + + private static void Shutdown() + { // Try to cleanup everything before actually shutting down. System.GC.Collect(); System.GC.WaitForPendingFinalizers(); - if (initComponent == Components.Ui) { - elm_shutdown(); + if (initComponent == Components.Ui) + { + elm_shutdown(); } + eldbus.Config.Shutdown(); evas_shutdown(); ecore_shutdown(); Efl.Eo.Config.Shutdown(); Eina.Config.Shutdown(); - } - /// - /// Called when the application is started. Arguments from the command line are passed here. - /// - protected abstract void OnInitialize(Eina.Array args); - /// - /// Arguments are passed here, Additional calls to this function may occure, - /// but then the initialization flag is set to false. - /// - /// - /// When Initialize is true then OnInitialize is also called - /// - protected virtual void OnArguments(Efl.LoopArguments args) { } - /// - /// Called when the application is not going to be displayed, or is not used by a user for some time. - /// - protected virtual void OnPause() { } - /// - /// Called before an application is used again after a call to OnPause(). - /// - protected virtual void OnResume() { } - /// - /// Called before starting the shutdown of the application. - /// - protected virtual void OnTerminate() { } - /// - /// This function initializices everything in EFL and runs your application. - /// This call will result in a call to OnInitialize(), which you application should override. - /// - public void Launch(Efl.Csharp.Components components=Components.Ui) { + } + + /// + /// Called when the application is started. Arguments from the command line are passed here. + /// + protected abstract void OnInitialize(Eina.Array args); + + /// + /// Arguments are passed here, Additional calls to this function may occure, + /// but then the initialization flag is set to false. + /// + /// + /// When Initialize is true then OnInitialize is also called + /// + protected virtual void OnArguments(Efl.LoopArguments args) + { + } + + /// + /// Called when the application is not going to be displayed, or is not used by a user for some time. + /// + protected virtual void OnPause() + { + } + + /// + /// Called before an application is used again after a call to OnPause(). + /// + protected virtual void OnResume() + { + } + + /// + /// Called before starting the shutdown of the application. + /// + protected virtual void OnTerminate() + { + } + + /// + /// This function initializices everything in EFL and runs your application. + /// This call will result in a call to OnInitialize(), which you application should override. + /// + public void Launch(Efl.Csharp.Components components = Components.Ui) + { Init(components); Efl.App app = Efl.App.AppMain; Eina.Array command_line = new Eina.Array(); @@ -103,26 +135,32 @@ namespace Efl { #if EFL_BETA app.SetCommandArray(command_line); #endif - app.ArgumentsEvt += (object sender, LoopArgumentsEvt_Args evt) => { - if (evt.arg.Initialization) { - OnInitialize(evt.arg.Argv); - } - OnArguments(evt.arg); + app.ArgumentsEvt += (object sender, LoopArgumentsEvt_Args evt) => + { + if (evt.arg.Initialization) + { + OnInitialize(evt.arg.Argv); + } + + OnArguments(evt.arg); }; - app.PauseEvt += (object sender, EventArgs e) => { - OnPause(); + app.PauseEvt += (object sender, EventArgs e) => + { + OnPause(); }; - app.ResumeEvt += (object sender, EventArgs e) => { - OnResume(); + app.ResumeEvt += (object sender, EventArgs e) => + { + OnResume(); }; - app.TerminateEvt += (object sender, EventArgs e) => { - OnTerminate(); + app.TerminateEvt += (object sender, EventArgs e) => + { + OnTerminate(); }; app.Begin(); Shutdown(); - } } - } } +} +} diff --git a/src/bindings/mono/eina_mono/eina_accessor.cs b/src/bindings/mono/eina_mono/eina_accessor.cs index 3f2f71b2b3..31574d552f 100644 --- a/src/bindings/mono/eina_mono/eina_accessor.cs +++ b/src/bindings/mono/eina_mono/eina_accessor.cs @@ -7,7 +7,8 @@ using static Eina.TraitFunctions; using static Eina.AccessorNativeFunctions; -namespace Eina { +namespace Eina +{ internal class AccessorNativeFunctions { @@ -43,7 +44,7 @@ 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) + public Accessor(IntPtr handle, Ownership owner = Ownership.Managed) { Handle = handle; Ownership = owner; @@ -53,7 +54,7 @@ public class Accessor : IEnumerable, IDisposable /// 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) + public Accessor(IntPtr handle, bool own, bool ownContent = false) : this(handle, own ? Ownership.Managed : Ownership.Unmanaged) { } @@ -96,13 +97,16 @@ public class Accessor : IEnumerable, IDisposable public IEnumerator GetEnumerator() { if (Handle == IntPtr.Zero) + { throw new ObjectDisposedException(base.GetType().Name); + } + IntPtr tmp = MemoryNative.Alloc(Marshal.SizeOf(typeof(IntPtr))); uint position = 0; try { - while(eina_accessor_data_get(Handle, position, tmp)) + while (eina_accessor_data_get(Handle, position, tmp)) { IntPtr data = (IntPtr)Marshal.PtrToStructure(tmp, typeof(IntPtr)); yield return Convert(data); @@ -124,11 +128,12 @@ 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 AccessorInList(IntPtr handle, Ownership own) : base(handle, own) + { + } /// Convert the native data into managed. This is used when returning the data through a /// . @@ -146,7 +151,9 @@ 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 AccessorInArray(IntPtr handle, Ownership own) : base(handle, own) + { + } /// Convert the native data into managed. This is used when returning the data through a /// . diff --git a/src/bindings/mono/eina_mono/eina_array.cs b/src/bindings/mono/eina_mono/eina_array.cs index b2cdede565..106af08226 100644 --- a/src/bindings/mono/eina_mono/eina_array.cs +++ b/src/bindings/mono/eina_mono/eina_array.cs @@ -7,7 +7,8 @@ using System.Collections.Generic; using static Eina.TraitFunctions; using static Eina.ArrayNativeFunctions; -namespace Eina { +namespace Eina +{ public static class ArrayNativeFunctions { @@ -64,7 +65,9 @@ public class Array : IEnumerable, IDisposable Own = true; OwnContent = true; if (Handle == IntPtr.Zero) + { throw new SEHException("Could not alloc array"); + } } internal bool InternalPush(IntPtr ele) @@ -131,19 +134,23 @@ public class Array : IEnumerable, IDisposable IntPtr h = Handle; Handle = IntPtr.Zero; if (h == IntPtr.Zero) + { return; + } if (OwnContent) { int len = (int)eina_array_count_custom_export_mono(h); - for(int i = 0; i < len; ++i) + for (int i = 0; i < len; ++i) { NativeFree(eina_array_data_get_custom_export_mono(h, (uint)i)); } } if (Own) + { eina_array_free(h); + } } public void Dispose() @@ -169,7 +176,7 @@ public class Array : IEnumerable, IDisposable if (OwnContent) { int len = Length; - for(int i = 0; i < len; ++i) + for (int i = 0; i < len; ++i) { NativeFree(InternalDataGet(i)); } @@ -190,7 +197,7 @@ public class Array : IEnumerable, IDisposable public int Count() { - return (int) eina_array_count_custom_export_mono(Handle); + return (int)eina_array_count_custom_export_mono(Handle); } public void SetOwnership(bool ownAll) @@ -210,7 +217,10 @@ public class Array : IEnumerable, IDisposable IntPtr ele = ManagedToNativeAlloc(val); var r = InternalPush(ele); if (!r) + { NativeFree(ele); + } + return r; } @@ -218,7 +228,9 @@ public class Array : IEnumerable, IDisposable // public void Add(T val) // { // if (!Push(val)) -// throw; +// { +// throw; +// } // } public T Pop() @@ -226,7 +238,10 @@ public class Array : IEnumerable, IDisposable IntPtr ele = InternalPop(); var r = NativeToManaged(ele); if (OwnContent && ele != IntPtr.Zero) + { NativeFree(ele); + } + return r; } @@ -245,7 +260,10 @@ public class Array : IEnumerable, IDisposable { IntPtr ele = InternalDataGet(idx); // TODO: check bondaries ?? if (OwnContent && ele != IntPtr.Zero) + { NativeFree(ele); + } + ele = ManagedToNativeAlloc(val); InternalDataSet(idx, ele); } @@ -266,18 +284,24 @@ public class Array : IEnumerable, IDisposable { int len = Length; var managed = new T[len]; - for(int i = 0; i < len; ++i) + for (int i = 0; i < len; ++i) { managed[i] = DataGet(i); } + return managed; } public bool Append(T[] values) { - foreach(T v in values) + foreach (T v in values) + { if (!Push(v)) + { return false; + } + } + return true; } @@ -290,7 +314,7 @@ public class Array : IEnumerable, IDisposable public IEnumerator GetEnumerator() { int len = Length; - for(int i = 0; i < len; ++i) + for (int i = 0; i < len; ++i) { yield return DataGet(i); } diff --git a/src/bindings/mono/eina_mono/eina_binbuf.cs b/src/bindings/mono/eina_mono/eina_binbuf.cs index 20a4c2d0ce..24fdaee5b1 100644 --- a/src/bindings/mono/eina_mono/eina_binbuf.cs +++ b/src/bindings/mono/eina_mono/eina_binbuf.cs @@ -3,7 +3,8 @@ using System; using System.Runtime.InteropServices; -namespace Eina { +namespace Eina +{ public class Binbuf : IDisposable { @@ -43,7 +44,7 @@ public class Binbuf : IDisposable public int Length { - get { return (int) GetLength(); } + get { return (int)GetLength(); } } private void InitNew() @@ -51,7 +52,9 @@ public class Binbuf : IDisposable Handle = eina_binbuf_new(); Own = true; if (Handle == IntPtr.Zero) + { throw new SEHException("Could not alloc binbuf"); + } } public Binbuf() @@ -98,7 +101,8 @@ public class Binbuf : IDisposable { IntPtr h = Handle; Handle = IntPtr.Zero; - if (Own && h != IntPtr.Zero) { + if (Own && h != IntPtr.Zero) + { eina_binbuf_free(Handle); } } @@ -180,7 +184,9 @@ public class Binbuf : IDisposable { var ptr = eina_binbuf_string_get(Handle); if (ptr == IntPtr.Zero) + { return null; + } var size = (int)(this.GetLength()); byte[] mArray = new byte[size]; diff --git a/src/bindings/mono/eina_mono/eina_common.cs b/src/bindings/mono/eina_mono/eina_common.cs index c9c10de160..199b92bc06 100644 --- a/src/bindings/mono/eina_mono/eina_common.cs +++ b/src/bindings/mono/eina_mono/eina_common.cs @@ -6,6 +6,7 @@ using System.Runtime.InteropServices; namespace Eina { + namespace Callbacks { @@ -41,7 +42,8 @@ internal static class NativeCustomExportFunctions } /// Wrapper around native memory DllImport'd functions -public static class MemoryNative { +public static class MemoryNative +{ public static void Free(IntPtr ptr) { NativeCustomExportFunctions.efl_mono_native_free(ptr); @@ -122,7 +124,9 @@ public static class StringConversion public static IntPtr ManagedStringToNativeUtf8Alloc(string managedString) { if (managedString == null) + { return IntPtr.Zero; + } byte[] strbuf = Encoding.UTF8.GetBytes(managedString); IntPtr native = MemoryNative.Alloc(strbuf.Length + 1); @@ -134,11 +138,15 @@ public static class StringConversion public static string NativeUtf8ToManagedString(IntPtr pNativeData) { if (pNativeData == IntPtr.Zero) + { return null; + } int len = 0; while (Marshal.ReadByte(pNativeData, len) != 0) + { ++len; + } byte[] strbuf = new byte[len]; Marshal.Copy(pNativeData, strbuf, 0, strbuf.Length); @@ -147,7 +155,8 @@ public static class StringConversion } /// Enum to handle resource ownership between managed and unmanaged code. -public enum Ownership { +public enum Ownership +{ /// The resource is owned by the managed code. It should free the handle on disposal. Managed, /// The resource is owned by the unmanaged code. It won't be freed on disposal. diff --git a/src/bindings/mono/eina_mono/eina_config.cs b/src/bindings/mono/eina_mono/eina_config.cs index ee0bb5bd0e..9f3028f62d 100644 --- a/src/bindings/mono/eina_mono/eina_config.cs +++ b/src/bindings/mono/eina_mono/eina_config.cs @@ -3,18 +3,24 @@ using System; using System.Runtime.InteropServices; -namespace Eina { +namespace Eina +{ -public class Config { +public class Config +{ [DllImport(efl.Libs.Eina)] private static extern int eina_init(); [DllImport(efl.Libs.Eina)] private static extern int eina_shutdown(); - public static void Init() { + public static void Init() + { if (eina_init() == 0) + { throw (new Efl.EflException("Failed to initialize Eina")); + } } - public static int Shutdown() { + public static int Shutdown() + { return eina_shutdown(); } @@ -24,15 +30,15 @@ public class Config { /// Wrapper class for pointers that need some cleanup afterwards /// like strings. /// -public class DisposableIntPtr : IDisposable { - +public class DisposableIntPtr : IDisposable +{ public IntPtr Handle { get; set; } private bool ShouldFree; private bool Disposed; /// Wraps a new ptr what will be freed based on the /// value of shouldFree - public DisposableIntPtr(IntPtr ptr, bool shouldFree=false) + public DisposableIntPtr(IntPtr ptr, bool shouldFree = false) { Handle = ptr; ShouldFree = shouldFree; @@ -46,9 +52,11 @@ public class DisposableIntPtr : IDisposable { protected virtual void Dispose(bool disposing) { - if (!Disposed && ShouldFree) { + if (!Disposed && ShouldFree) + { MemoryNative.Free(this.Handle); } + Disposed = true; } @@ -57,4 +65,5 @@ public class DisposableIntPtr : IDisposable { Dispose(false); } } + } diff --git a/src/bindings/mono/eina_mono/eina_container_common.cs b/src/bindings/mono/eina_mono/eina_container_common.cs index 3eddb2aa31..73a3a0f46a 100644 --- a/src/bindings/mono/eina_mono/eina_container_common.cs +++ b/src/bindings/mono/eina_mono/eina_container_common.cs @@ -11,9 +11,15 @@ using static Eina.InarrayNativeFunctions; using static Eina.InlistNativeFunctions; using static Eina.NativeCustomExportFunctions; -namespace Eina { +namespace Eina +{ -public enum ElementType { NumericType, StringType, ObjectType }; +public enum ElementType +{ + NumericType, + StringType, + ObjectType +}; [StructLayout(LayoutKind.Sequential)] public struct InlistMem @@ -82,13 +88,18 @@ public class StringElementTraits : IBaseElementTraits public void NativeFree(IntPtr nat) { if (nat != IntPtr.Zero) + { MemoryNative.Free(nat); + } } public void NativeFreeInlistNodeElement(IntPtr nat) { if (nat == IntPtr.Zero) + { return; + } + var val = Marshal.PtrToStructure (nat + Marshal.SizeOf()); NativeFree(val); @@ -97,9 +108,15 @@ public class StringElementTraits : IBaseElementTraits public void NativeFreeInlistNode(IntPtr nat, bool freeElement) { if (nat == IntPtr.Zero) + { return; + } + if (freeElement) + { NativeFreeInlistNodeElement(nat); + } + MemoryNative.Free(nat); } @@ -115,7 +132,10 @@ public class StringElementTraits : IBaseElementTraits public string NativeToManaged(IntPtr nat) { if (nat == IntPtr.Zero) + { return default(string); + } + return StringConversion.NativeUtf8ToManagedString(nat); } @@ -126,6 +146,7 @@ public class StringElementTraits : IBaseElementTraits Eina.Log.Error("Null pointer for Inlist node."); return default(string); } + IntPtr ptr_location = nat + Marshal.SizeOf(); return NativeToManaged(Marshal.ReadIntPtr(ptr_location)); } @@ -134,10 +155,16 @@ public class StringElementTraits : IBaseElementTraits public string NativeToManagedInplace(IntPtr nat) { if (nat == IntPtr.Zero) + { return default(string); + } + nat = Marshal.ReadIntPtr(nat); if (nat == IntPtr.Zero) + { return default(string); + } + return NativeToManaged(nat); } @@ -180,7 +207,10 @@ public class EflObjectElementTraits : IBaseElementTraits { IntPtr h = ((Efl.Eo.IWrapper)man).NativeHandle; if (h == IntPtr.Zero) + { return h; + } + return Efl.Eo.Globals.efl_ref(h); } @@ -204,19 +234,26 @@ public class EflObjectElementTraits : IBaseElementTraits public void NativeFree(IntPtr nat) { if (nat != IntPtr.Zero) + { Efl.Eo.Globals.efl_unref(nat); + } } public void NativeFreeRef(IntPtr nat, bool unrefs) { if (unrefs) + { NativeFree(nat); + } } public void NativeFreeInlistNodeElement(IntPtr nat) { if (nat == IntPtr.Zero) + { return; + } + var val = Marshal.PtrToStructure (nat + Marshal.SizeOf()); NativeFree(val); @@ -225,9 +262,15 @@ public class EflObjectElementTraits : IBaseElementTraits public void NativeFreeInlistNode(IntPtr nat, bool freeElement) { if (nat == IntPtr.Zero) + { return; + } + if (freeElement) + { NativeFreeInlistNodeElement(nat); + } + MemoryNative.Free(nat); } @@ -243,14 +286,20 @@ public class EflObjectElementTraits : IBaseElementTraits public T NativeToManaged(IntPtr nat) { if (nat == IntPtr.Zero) + { return default(T); - return (T) Activator.CreateInstance(concreteType, Efl.Eo.Globals.efl_ref(nat)); + } + + return (T)Activator.CreateInstance(concreteType, Efl.Eo.Globals.efl_ref(nat)); } public T NativeToManagedRef(IntPtr nat) { if (nat == IntPtr.Zero) + { return default(T); + } + return NativeToManaged(nat); } @@ -261,6 +310,7 @@ public class EflObjectElementTraits : IBaseElementTraits Eina.Log.Error("Null pointer for Inlist node."); return default(T); } + IntPtr ptr_location = nat + Marshal.SizeOf(); return NativeToManaged(Marshal.ReadIntPtr(ptr_location)); } @@ -269,10 +319,16 @@ public class EflObjectElementTraits : IBaseElementTraits public T NativeToManagedInplace(IntPtr nat) { if (nat == IntPtr.Zero) + { return default(T); + } + nat = Marshal.ReadIntPtr(nat); if (nat == IntPtr.Zero) + { return default(T); + } + return NativeToManaged(nat); } @@ -355,6 +411,7 @@ public abstract class PrimitiveElementTraits Eina.Log.Error("Null pointer on primitive/struct container."); return default(T); } + return PrimitiveConversion.PointerToManaged(nat); } @@ -371,7 +428,7 @@ public abstract class PrimitiveElementTraits private int PrimitiveCompareCb(IntPtr ptr1, IntPtr ptr2) { - var m1 = (IComparable) NativeToManaged(ptr1); + var m1 = (IComparable)NativeToManaged(ptr1); var m2 = NativeToManaged(ptr2); return m1.CompareTo(m2); } @@ -379,7 +436,10 @@ public abstract class PrimitiveElementTraits public IntPtr EinaCompareCb() { if (dlgt == null) + { dlgt = new Eina_Compare_Cb(PrimitiveCompareCb); + } + return Marshal.GetFunctionPointerForDelegate(dlgt); } @@ -406,10 +466,16 @@ abstract public class Primitive32ElementTraits : PrimitiveElementTraits, I public Primitive32ElementTraits() { if (int32Traits == null) + { if (typeof(T) == typeof(Int32)) // avoid infinite recursion + { int32Traits = (IBaseElementTraits)this; + } else + { int32Traits = TraitFunctions.GetTypeTraits(); + } + } } public abstract void ManagedToNativeCopyTo(T man, IntPtr mem); @@ -438,10 +504,16 @@ abstract public class Primitive64ElementTraits : PrimitiveElementTraits, I public Primitive64ElementTraits() { if (int64Traits == null) + { if (typeof(T) == typeof(Int64)) // avoid infinite recursion + { int64Traits = (IBaseElementTraits)this; + } else + { int64Traits = TraitFunctions.GetTypeTraits(); + } + } } public abstract void ManagedToNativeCopyTo(T man, IntPtr mem); @@ -471,6 +543,7 @@ public class IntElementTraits : Primitive32ElementTraits, IBaseElementTrait arr[0] = man; Marshal.Copy(arr, 0, mem, 1); } + override public int NativeToManagedInlistNode(IntPtr nat) { if (nat == IntPtr.Zero) @@ -478,6 +551,7 @@ public class IntElementTraits : Primitive32ElementTraits, IBaseElementTrait Eina.Log.Error("Null pointer for Inlist node."); return default(int); } + IntPtr loc = nat + Marshal.SizeOf(); var v = new int[1]; Marshal.Copy(loc, v, 0, 1); @@ -493,6 +567,7 @@ public class CharElementTraits : Primitive32ElementTraits, IBaseElementTra arr[0] = man; Marshal.Copy(arr, 0, mem, 1); } + override public char NativeToManagedInlistNode(IntPtr nat) { if (nat == IntPtr.Zero) @@ -500,12 +575,14 @@ public class CharElementTraits : Primitive32ElementTraits, IBaseElementTra Eina.Log.Error("Null pointer for Inlist node."); return default(char); } + IntPtr loc = nat + Marshal.SizeOf(); var v = new char[1]; Marshal.Copy(loc, v, 0, 1); return v[0]; } } + public class LongElementTraits : Primitive64ElementTraits, IBaseElementTraits { override public void ManagedToNativeCopyTo(long man, IntPtr mem) @@ -514,6 +591,7 @@ public class LongElementTraits : Primitive64ElementTraits, IBaseElementTra arr[0] = man; Marshal.Copy(arr, 0, mem, 1); } + override public long NativeToManagedInlistNode(IntPtr nat) { if (nat == IntPtr.Zero) @@ -521,6 +599,7 @@ public class LongElementTraits : Primitive64ElementTraits, IBaseElementTra Eina.Log.Error("Null pointer for Inlist node."); return default(long); } + IntPtr loc = nat + Marshal.SizeOf(); var v = new long[1]; Marshal.Copy(loc, v, 0, 1); @@ -536,6 +615,7 @@ public class ShortElementTraits : Primitive32ElementTraits, IBaseElementT arr[0] = man; Marshal.Copy(arr, 0, mem, 1); } + override public short NativeToManagedInlistNode(IntPtr nat) { if (nat == IntPtr.Zero) @@ -543,6 +623,7 @@ public class ShortElementTraits : Primitive32ElementTraits, IBaseElementT Eina.Log.Error("Null pointer for Inlist node."); return default(short); } + IntPtr loc = nat + Marshal.SizeOf(); var v = new short[1]; Marshal.Copy(loc, v, 0, 1); @@ -558,6 +639,7 @@ public class FloatElementTraits : Primitive32ElementTraits, IBaseElementT arr[0] = man; Marshal.Copy(arr, 0, mem, 1); } + override public float NativeToManagedInlistNode(IntPtr nat) { if (nat == IntPtr.Zero) @@ -565,6 +647,7 @@ public class FloatElementTraits : Primitive32ElementTraits, IBaseElementT Eina.Log.Error("Null pointer for Inlist node."); return default(float); } + IntPtr loc = nat + Marshal.SizeOf(); var v = new float[1]; Marshal.Copy(loc, v, 0, 1); @@ -580,6 +663,7 @@ public class DoubleElementTraits : Primitive64ElementTraits, IBaseElemen arr[0] = man; Marshal.Copy(arr, 0, mem, 1); } + override public double NativeToManagedInlistNode(IntPtr nat) { if (nat == IntPtr.Zero) @@ -587,6 +671,7 @@ public class DoubleElementTraits : Primitive64ElementTraits, IBaseElemen Eina.Log.Error("Null pointer for Inlist node."); return default(double); } + IntPtr loc = nat + Marshal.SizeOf(); var v = new double[1]; Marshal.Copy(loc, v, 0, 1); @@ -602,6 +687,7 @@ public class ByteElementTraits : Primitive32ElementTraits, IBaseElementTra arr[0] = man; Marshal.Copy(arr, 0, mem, 1); } + override public byte NativeToManagedInlistNode(IntPtr nat) { if (nat == IntPtr.Zero) @@ -609,6 +695,7 @@ public class ByteElementTraits : Primitive32ElementTraits, IBaseElementTra Eina.Log.Error("Null pointer for Inlist node."); return default(byte); } + IntPtr loc = nat + Marshal.SizeOf(); var v = new byte[1]; Marshal.Copy(loc, v, 0, 1); @@ -631,11 +718,17 @@ public static class TraitFunctions public static Eina.ElementType GetElementTypeCode(System.Type type) { if (IsEflObject(type)) + { return ElementType.ObjectType; + } else if (IsString(type)) + { return ElementType.StringType; + } else + { return ElementType.NumericType; + } } private static IDictionary register = new Dictionary(); @@ -643,7 +736,9 @@ public static class TraitFunctions private static System.Type AsEflInstantiableType(System.Type type) { if (!IsEflObject(type)) + { return null; + } if (type.IsInterface) { @@ -663,32 +758,55 @@ public static class TraitFunctions { System.Type concrete = AsEflInstantiableType(type); if (concrete == null || !type.IsAssignableFrom(concrete)) + { throw new Exception("Failed to get a suitable concrete class for this type."); + } + traits = new EflObjectElementTraits(concrete); } else if (IsString(type)) + { traits = new StringElementTraits(); + } else if (type.IsValueType) { if (type == typeof(int)) + { traits = new IntElementTraits(); + } else if (type == typeof(char)) + { traits = new CharElementTraits(); + } else if (type == typeof(long)) + { traits = new LongElementTraits(); + } else if (type == typeof(short)) + { traits = new ShortElementTraits(); + } else if (type == typeof(float)) + { traits = new FloatElementTraits(); + } else if (type == typeof(double)) + { traits = new DoubleElementTraits(); + } else if (type == typeof(byte)) + { traits = new ByteElementTraits(); + } else + { throw new Exception("No traits registered for this type"); + } } else + { throw new Exception("No traits registered for this type"); + } register[type] = traits; return traits; @@ -704,8 +822,11 @@ public static class TraitFunctions { object traits; if (!register.TryGetValue(typeof(T), out traits)) + { traits = RegisterTypeTraits(); - return (IBaseElementTraits) traits; + } + + return (IBaseElementTraits)traits; } // // diff --git a/src/bindings/mono/eina_mono/eina_error.cs b/src/bindings/mono/eina_mono/eina_error.cs index 07760fd395..0247cb64db 100644 --- a/src/bindings/mono/eina_mono/eina_error.cs +++ b/src/bindings/mono/eina_mono/eina_error.cs @@ -3,7 +3,8 @@ using System; using System.Runtime.InteropServices; -namespace Eina { +namespace Eina +{ public struct Error : IComparable { @@ -21,19 +22,26 @@ public struct Error : IComparable public static Error ENOENT = new Error(2); public static Error ECANCELED = new Error(125); - public Error(int value) { code = value; } + public Error(int value) + { + code = value; + } + static public implicit operator Error(int val) { return new Error(val); } + static public implicit operator int(Error error) { return error.code; } + public int CompareTo(Error err) { return code.CompareTo(err.code); } + public override string ToString() { return "Eina.Error(" + code + ")"; @@ -80,7 +88,9 @@ public struct Error : IComparable public static void Raise(Error e) { if (e != 0) + { throw (new Efl.EflException(MsgGet(e))); + } } public static void Clear() @@ -93,4 +103,5 @@ public struct Error : IComparable return eina_error_msg_register(msg); } } + } diff --git a/src/bindings/mono/eina_mono/eina_hash.cs b/src/bindings/mono/eina_mono/eina_hash.cs index 95de7c5cb2..9659a809fd 100644 --- a/src/bindings/mono/eina_mono/eina_hash.cs +++ b/src/bindings/mono/eina_mono/eina_hash.cs @@ -137,8 +137,10 @@ public class Hash : IEnumerable>, IDi public bool OwnKey {get; set;} public bool OwnValue {get; set;} - public int Count { - get { + public int Count + { + get + { return Population(); } } @@ -179,10 +181,14 @@ public class Hash : IEnumerable>, IDi IntPtr h = Handle; Handle = IntPtr.Zero; if (h == IntPtr.Zero) + { return; + } if (Own) + { eina_hash_free(h); + } } public void Dispose() @@ -218,7 +224,9 @@ public class Hash : IEnumerable>, IDi OwnValue = ownValue; if (ownValue) + { eina_hash_free_cb_set(Handle, EinaFreeCb()); + } } public void SetOwnership(bool ownAll) @@ -289,7 +297,9 @@ public class Hash : IEnumerable>, IDi //NativeFreeRef(nk); FreeNativeIndirection(gchnk, ForceRefKey()); if (found == IntPtr.Zero) + { throw new KeyNotFoundException(); + } return NativeToManaged(IndirectNative(found, false)); } @@ -305,6 +315,7 @@ public class Hash : IEnumerable>, IDi val = default(TValue); return false; } + val = NativeToManaged(IndirectNative(found, false)); return true; } @@ -334,8 +345,12 @@ public class Hash : IEnumerable>, IDi NativeFree(nv); return false; } + if (OwnValue) + { NativeFree(old); + } + return true; } @@ -355,7 +370,7 @@ public class Hash : IEnumerable>, IDi return GCHandle.ToIntPtr(gch); } - else if(IsEflObject(typeof(T)) && forceRef) + else if (IsEflObject(typeof(T)) && forceRef) { GCHandle gch = GCHandle.Alloc(new byte[Marshal.SizeOf()], GCHandleType.Pinned); IntPtr pin = gch.AddrOfPinnedObject(); @@ -369,6 +384,7 @@ public class Hash : IEnumerable>, IDi return ManagedToNativeAlloc(value); } } + private static IntPtr GetNativePtr(IntPtr gchptr, bool forceRef) { if (forceRef) @@ -383,6 +399,7 @@ public class Hash : IEnumerable>, IDi return gchptr; } } + private static void FreeNativeIndirection(IntPtr gchptr, bool forceRef) { if (forceRef) @@ -416,7 +433,9 @@ public class Hash : IEnumerable>, IDi FreeNativeIndirection(gchnk, ForceRefKey()); FreeNativeIndirection(gchnv, false); if (OwnValue || old != IntPtr.Zero) + { NativeFree(old); + } } public TValue this[TKey key] @@ -494,4 +513,3 @@ public class Hash : IEnumerable>, IDi } } - diff --git a/src/bindings/mono/eina_mono/eina_inarray.cs b/src/bindings/mono/eina_mono/eina_inarray.cs index a99acc8371..987b46600f 100644 --- a/src/bindings/mono/eina_mono/eina_inarray.cs +++ b/src/bindings/mono/eina_mono/eina_inarray.cs @@ -7,7 +7,8 @@ using System.Collections.Generic; using static Eina.TraitFunctions; using static Eina.InarrayNativeFunctions; -namespace Eina { +namespace Eina +{ public static class InarrayNativeFunctions { @@ -86,7 +87,9 @@ public class Inarray : IEnumerable, IDisposable Own = true; OwnContent = true; if (Handle == IntPtr.Zero) + { throw new SEHException("Could not alloc inarray"); + } } public Inarray() @@ -123,19 +126,23 @@ public class Inarray : IEnumerable, IDisposable IntPtr h = Handle; Handle = IntPtr.Zero; if (h == IntPtr.Zero) + { return; + } if (OwnContent) { uint len = eina_inarray_count(h); - for(uint i = 0; i < len; ++i) + for (uint i = 0; i < len; ++i) { NativeFreeInplace(eina_inarray_nth(h, i)); } } if (Own) + { eina_inarray_free(h); + } } public void Dispose() @@ -176,7 +183,7 @@ public class Inarray : IEnumerable, IDisposable public int Count() { - return (int) eina_inarray_count(Handle); + return (int)eina_inarray_count(Handle); } public void SetOwnership(bool ownAll) @@ -201,7 +208,10 @@ public class Inarray : IEnumerable, IDisposable var r = eina_inarray_push(Handle, ind); if (r == -1) + { NativeFreeInplace(ele); + } + ResidueFreeInplace(ele); gch.Free(); return r; @@ -211,7 +221,9 @@ public class Inarray : IEnumerable, IDisposable // public void Add(T val) // { // if (!Push(val)) -// throw; +// { +// throw; +// } // } public T Pop() @@ -219,7 +231,10 @@ public class Inarray : IEnumerable, IDisposable IntPtr ele = eina_inarray_pop(Handle); var r = NativeToManagedInplace(ele); if (OwnContent && ele != IntPtr.Zero) + { NativeFreeInplace(ele); + } + return r; } @@ -244,7 +259,10 @@ public class Inarray : IEnumerable, IDisposable var r = eina_inarray_insert_at(Handle, idx, ind); if (!r) + { NativeFreeInplace(ele); + } + ResidueFreeInplace(ele); return r; } @@ -253,9 +271,15 @@ public class Inarray : IEnumerable, IDisposable { var old = eina_inarray_nth(Handle, idx); if (old == IntPtr.Zero) + { return false; + } + if (OwnContent) + { NativeFreeInplace(old); + } + var ele = IntPtr.Zero; GCHandle gch = GCHandle.Alloc(ele, GCHandleType.Pinned); IntPtr ind = gch.AddrOfPinnedObject(); @@ -283,9 +307,14 @@ public class Inarray : IEnumerable, IDisposable { IntPtr ele = eina_inarray_nth(Handle, idx); if (ele == IntPtr.Zero) + { return false; + } + if (OwnContent) + { NativeFreeInplace(ele); + } return eina_inarray_remove_at(Handle, idx); } @@ -299,18 +328,24 @@ public class Inarray : IEnumerable, IDisposable { int len = Length; var managed = new T[len]; - for(int i = 0; i < len; ++i) + for (int i = 0; i < len; ++i) { managed[i] = At(i); } + return managed; } public bool Append(T[] values) { - foreach(T v in values) + foreach (T v in values) + { if (Push(v) == -1) + { return false; + } + } + return true; } @@ -327,7 +362,7 @@ public class Inarray : IEnumerable, IDisposable public IEnumerator GetEnumerator() { int len = Length; - for(int i = 0; i < len; ++i) + for (int i = 0; i < len; ++i) { yield return At(i); } diff --git a/src/bindings/mono/eina_mono/eina_inlist.cs b/src/bindings/mono/eina_mono/eina_inlist.cs index 0bf09d0b85..0cc9bae6a0 100644 --- a/src/bindings/mono/eina_mono/eina_inlist.cs +++ b/src/bindings/mono/eina_mono/eina_inlist.cs @@ -8,7 +8,8 @@ using static Eina.TraitFunctions; using static Eina.InlistNativeFunctions; using Eina.Callbacks; -namespace Eina { +namespace Eina +{ public static class InlistNativeFunctions { @@ -111,11 +112,16 @@ public class Inlist : IEnumerable, IDisposable private IntPtr InternalAt(int idx) { if (idx < 0) + { return IntPtr.Zero; + } IntPtr curr = Handle; for (int n = 0; n != idx && curr != IntPtr.Zero; ++n) + { curr = InternalNext(curr); + } + return curr; } @@ -159,11 +165,13 @@ public class Inlist : IEnumerable, IDisposable IntPtr h = Handle; Handle = IntPtr.Zero; if (h == IntPtr.Zero) + { return; + } if (OwnContent) { - for(IntPtr curr = h; curr != IntPtr.Zero; curr = InternalNext(curr)) + for (IntPtr curr = h; curr != IntPtr.Zero; curr = InternalNext(curr)) { NativeFreeInlistNodeElement(curr); } @@ -212,7 +220,7 @@ public class Inlist : IEnumerable, IDisposable public int Count() { - return (int) eina_inlist_count(Handle); + return (int)eina_inlist_count(Handle); } public void Clean() @@ -248,7 +256,10 @@ public class Inlist : IEnumerable, IDisposable { IntPtr node = InternalAt(idx); if (node == IntPtr.Zero) + { throw new IndexOutOfRangeException(); + } + return NativeToManagedInlistNode(node); } @@ -256,7 +267,9 @@ public class Inlist : IEnumerable, IDisposable { IntPtr old = InternalAt(idx); if (old == IntPtr.Zero) + { throw new IndexOutOfRangeException(); + } IntPtr new_node = ManagedToNativeAllocInlistNode(val); @@ -282,17 +295,20 @@ public class Inlist : IEnumerable, IDisposable { var managed = new T[Count()]; int i = 0; - for(IntPtr curr = Handle; curr != IntPtr.Zero; ++i, curr = InternalNext(curr)) + for (IntPtr curr = Handle; curr != IntPtr.Zero; ++i, curr = InternalNext(curr)) { managed[i] = NativeToManagedInlistNode(curr); } + return managed; } public void AppendArray(T[] values) { foreach (T v in values) + { Append(v); + } } @@ -303,7 +319,7 @@ public class Inlist : IEnumerable, IDisposable public IEnumerator GetEnumerator() { - for(IntPtr curr = Handle; curr != IntPtr.Zero; curr = InternalNext(curr)) + for (IntPtr curr = Handle; curr != IntPtr.Zero; curr = InternalNext(curr)) { yield return NativeToManagedInlistNode(curr); } diff --git a/src/bindings/mono/eina_mono/eina_iterator.cs b/src/bindings/mono/eina_mono/eina_iterator.cs index 56ebab3f0c..c8f61410ce 100644 --- a/src/bindings/mono/eina_mono/eina_iterator.cs +++ b/src/bindings/mono/eina_mono/eina_iterator.cs @@ -7,7 +7,8 @@ using System.Collections.Generic; using static Eina.TraitFunctions; using static Eina.IteratorNativeFunctions; -namespace Eina { +namespace Eina +{ public static class IteratorNativeFunctions { @@ -58,18 +59,22 @@ public class Iterator : IEnumerable, IDisposable var h = Handle; Handle = IntPtr.Zero; if (h == IntPtr.Zero) + { return; + } if (OwnContent) { - for(IntPtr data; eina_iterator_next(h, out data);) + for (IntPtr data; eina_iterator_next(h, out data);) { NativeFree(data); } } if (Own) + { eina_iterator_free(h); + } } public void Dispose() @@ -114,7 +119,9 @@ public class Iterator : IEnumerable, IDisposable res = NativeToManaged(data); if (OwnContent) + { NativeFree(data); + } return true; } @@ -131,7 +138,7 @@ public class Iterator : IEnumerable, IDisposable public IEnumerator GetEnumerator() { - for(T curr; Next(out curr);) + for (T curr; Next(out curr);) { yield return curr; } diff --git a/src/bindings/mono/eina_mono/eina_list.cs b/src/bindings/mono/eina_mono/eina_list.cs index 8ad4a2f6cf..fe956508b8 100644 --- a/src/bindings/mono/eina_mono/eina_list.cs +++ b/src/bindings/mono/eina_mono/eina_list.cs @@ -8,7 +8,8 @@ using static Eina.TraitFunctions; using static Eina.ListNativeFunctions; using Eina.Callbacks; -namespace Eina { +namespace Eina +{ public static class ListNativeFunctions { @@ -175,18 +176,22 @@ public class List : IEnumerable, IDisposable IntPtr h = Handle; Handle = IntPtr.Zero; if (h == IntPtr.Zero) + { return; + } if (OwnContent) { - for(IntPtr curr = h; curr != IntPtr.Zero; curr = InternalNext(curr)) + for (IntPtr curr = h; curr != IntPtr.Zero; curr = InternalNext(curr)) { NativeFree(InternalDataGet(curr)); } } if (Own) + { eina_list_free(h); + } } public void Dispose() @@ -221,7 +226,7 @@ public class List : IEnumerable, IDisposable public int Count() { - return (int) eina_list_count_custom_export_mono(Handle); + return (int)eina_list_count_custom_export_mono(Handle); } public void Append(T val) @@ -274,9 +279,15 @@ public class List : IEnumerable, IDisposable { IntPtr pos = eina_list_nth_list(Handle, (uint)idx); if (pos == IntPtr.Zero) + { throw new IndexOutOfRangeException(); + } + if (OwnContent) + { NativeFree(InternalDataGet(pos)); + } + IntPtr ele = ManagedToNativeAlloc(val); InternalDataSet(pos, ele); } @@ -314,17 +325,20 @@ public class List : IEnumerable, IDisposable { var managed = new T[Count()]; int i = 0; - for(IntPtr curr = Handle; curr != IntPtr.Zero; curr = InternalNext(curr), ++i) + for (IntPtr curr = Handle; curr != IntPtr.Zero; curr = InternalNext(curr), ++i) { managed[i] = NativeToManaged(InternalDataGet(curr)); } + return managed; } public void AppendArray(T[] values) { foreach (T v in values) + { Append(v); + } } @@ -340,7 +354,7 @@ public class List : IEnumerable, IDisposable public IEnumerator GetEnumerator() { - for(IntPtr curr = Handle; curr != IntPtr.Zero; curr = InternalNext(curr)) + for (IntPtr curr = Handle; curr != IntPtr.Zero; curr = InternalNext(curr)) { yield return NativeToManaged(InternalDataGet(curr)); } diff --git a/src/bindings/mono/eina_mono/eina_log.cs b/src/bindings/mono/eina_mono/eina_log.cs index c17f02b8e5..56882b9000 100644 --- a/src/bindings/mono/eina_mono/eina_log.cs +++ b/src/bindings/mono/eina_mono/eina_log.cs @@ -5,7 +5,9 @@ using System.Runtime.InteropServices; using System.Runtime.CompilerServices; using System.Diagnostics.Contracts; -namespace Eina { // Manual wrappers around eina functions +namespace Eina +{ +// Manual wrappers around eina functions public class Log { @@ -55,44 +57,54 @@ public class Log static Log() { - const String name="mono"; - const String color="\033[32;1m"; + const String name = "mono"; + const String color = "\033[32;1m"; // Maybe move this check outside when other eina stuff get support? domain = eina_log_domain_register(name, color); if (domain < 0) - Console.WriteLine("Error: Couldn't register Eina log domain for name {0}.", name); + { + Console.WriteLine("Error: Couldn't register Eina log domain for name {0}.", name); + } else - Info($"Registered mono domain with number {domain}"); + { + Info($"Registered mono domain with number {domain}"); + } } private static void EnsureDomainRegistered() { if (domain < 0) - throw new InvalidOperationException("Log domain is not registered."); + { + throw new InvalidOperationException("Log domain is not registered."); + } } - public static void Critical(String message, [CallerLineNumber] int line=0, [CallerFilePath] string file=null, [CallerMemberName] string member = null) + public static void Critical(String message, [CallerLineNumber] int line = 0, [CallerFilePath] string file = null, [CallerMemberName] string member = null) { EnsureDomainRegistered(); eina_log_print(domain, Level.Critical, file, member, line, message); } - public static void Error(String message, [CallerLineNumber] int line=0, [CallerFilePath] string file=null, [CallerMemberName] string member = null) + + public static void Error(String message, [CallerLineNumber] int line = 0, [CallerFilePath] string file = null, [CallerMemberName] string member = null) { EnsureDomainRegistered(); eina_log_print(domain, Level.Error, file, member, line, message); } - public static void Warning(String message, [CallerLineNumber] int line=0, [CallerFilePath] string file=null, [CallerMemberName] string member = null) + + public static void Warning(String message, [CallerLineNumber] int line = 0, [CallerFilePath] string file = null, [CallerMemberName] string member = null) { EnsureDomainRegistered(); eina_log_print(domain, Level.Warning, file, member, line, message); } - public static void Info(String message, [CallerLineNumber] int line=0, [CallerFilePath] string file=null, [CallerMemberName] string member = null) + + public static void Info(String message, [CallerLineNumber] int line = 0, [CallerFilePath] string file = null, [CallerMemberName] string member = null) { EnsureDomainRegistered(); eina_log_print(domain, Level.Info, file, member, line, message); } - public static void Debug(String message, [CallerLineNumber] int line=0, [CallerFilePath] string file=null, [CallerMemberName] string member = null) + + public static void Debug(String message, [CallerLineNumber] int line = 0, [CallerFilePath] string file = null, [CallerMemberName] string member = null) { EnsureDomainRegistered(); eina_log_print(domain, Level.Debug, file, member, line, message); @@ -108,4 +120,5 @@ public class Log return eina_log_level_get(); } } + } diff --git a/src/bindings/mono/eina_mono/eina_promises.cs b/src/bindings/mono/eina_mono/eina_promises.cs index 176a8835ae..c7b68fe7a9 100644 --- a/src/bindings/mono/eina_mono/eina_promises.cs +++ b/src/bindings/mono/eina_mono/eina_promises.cs @@ -6,9 +6,11 @@ using System.Linq; using static Eina.EinaNative.PromiseNativeMethods; -namespace Eina { +namespace Eina +{ -namespace EinaNative { +namespace EinaNative +{ static internal class PromiseNativeMethods { @@ -80,7 +82,7 @@ public class Promise : IDisposable /// Currently, creating a promise directly uses the Main Loop scheduler the source of notifications (i.e. the /// future callbacks will be called mainly from a loop iteration). /// - public Promise(CancelCb cancelCb=null) + public Promise(CancelCb cancelCb = null) { Efl.Loop loop = Efl.App.AppMain; @@ -90,10 +92,13 @@ public class Promise : IDisposable IntPtr cb_data = IntPtr.Zero; // A safety clean callback to mark this wrapper as invalid - CancelCb safetyCb = () => { + CancelCb safetyCb = () => + { Handle = IntPtr.Zero; if (cancelCb != null) + { cancelCb(); + } }; CleanupHandle = GCHandle.Alloc(safetyCb); @@ -105,14 +110,21 @@ public class Promise : IDisposable private static void NativeCancelCb(IntPtr data, IntPtr dead) { if (data == IntPtr.Zero) + { return; + } GCHandle handle = GCHandle.FromIntPtr(data); CancelCb cb = handle.Target as CancelCb; if (cb != null) + { cb(); + } else + { Eina.Log.Info("Null promise CancelCb found"); + } + handle.Free(); } @@ -144,7 +156,9 @@ public class Promise : IDisposable private void SanityChecks() { if (this.Handle == IntPtr.Zero) + { throw new ObjectDisposedException(GetType().Name); + } } /// @@ -200,7 +214,8 @@ public class Future /// public Future(IntPtr handle) { - Handle = ThenRaw(handle, (Eina.Value value) => { + Handle = ThenRaw(handle, (Eina.Value value) => + { Handle = IntPtr.Zero; return value; }); @@ -212,12 +227,16 @@ public class Future /// Optionally a resolved callback may be provided. If so, it will be chained /// before the returned future. /// - public Future(Promise promise, ResolvedCb cb=null) + public Future(Promise promise, ResolvedCb cb = null) { IntPtr intermediate = eina_future_new(promise.Handle); - Handle = ThenRaw(intermediate, (Eina.Value value) => { + Handle = ThenRaw(intermediate, (Eina.Value value) => + { if (cb != null) + { value = cb(value); + } + Handle = IntPtr.Zero; return value; }); @@ -226,7 +245,9 @@ public class Future private void SanityChecks() { if (this.Handle == IntPtr.Zero) + { throw new ObjectDisposedException(GetType().Name); + } } /// @@ -266,14 +287,20 @@ public class Future desc.data = GCHandle.ToIntPtr(handle); return eina_future_then_from_desc(previous, desc); } + private static Eina.ValueNative NativeResolvedCb(IntPtr data, Eina.ValueNative value, IntPtr dead_future) { GCHandle handle = GCHandle.FromIntPtr(data); ResolvedCb cb = handle.Target as ResolvedCb; if (cb != null) + { value = cb(value); + } else + { Eina.Log.Warning("Failed to get future callback."); + } + handle.Free(); return value; } @@ -308,14 +335,18 @@ public class Future for (int j = 0; j <= i; j++) { if (descs[i].data == IntPtr.Zero) + { continue; + } GCHandle handle = GCHandle.FromIntPtr(descs[i].data); handle.Free(); } + Eina.Log.Error($"Failed to create native future description for callbacks. Error: {e.ToString()}"); return null; } + return new Future(eina_future_chain_array(Handle, descs)); } } @@ -341,17 +372,24 @@ public class FutureMarshaler : ICustomMarshaler { Future f = managedObj as Future; if (f == null) + { return IntPtr.Zero; + } + 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) { } + 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) { } + public void CleanUpManagedData(object managedObj) + { + } ///Size of the native data size returned ///The size of the data. @@ -363,9 +401,13 @@ public class FutureMarshaler : ICustomMarshaler ///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) { + public static ICustomMarshaler GetInstance(string cookie) + { if (marshaler == null) + { marshaler = new FutureMarshaler(); + } + return marshaler; } diff --git a/src/bindings/mono/eina_mono/eina_slice.cs b/src/bindings/mono/eina_mono/eina_slice.cs index 649ffc5d98..cb6249c019 100644 --- a/src/bindings/mono/eina_mono/eina_slice.cs +++ b/src/bindings/mono/eina_mono/eina_slice.cs @@ -3,7 +3,8 @@ using System; using System.Runtime.InteropServices; -namespace Eina { +namespace Eina +{ public interface ISliceBase { @@ -21,8 +22,8 @@ public struct Slice : ISliceBase public int Length { - get { return (int) Len; } - set { Len = (UIntPtr) value; } + get { return (int)Len; } + set { Len = (UIntPtr)value; } } public Slice(IntPtr mem, UIntPtr len) @@ -47,8 +48,8 @@ public struct RwSlice : ISliceBase public int Length { - get { return (int) Len; } - set { Len = (UIntPtr) value; } + get { return (int)Len; } + set { Len = (UIntPtr)value; } } public RwSlice(IntPtr mem, UIntPtr len) diff --git a/src/bindings/mono/eina_mono/eina_strbuf.cs b/src/bindings/mono/eina_mono/eina_strbuf.cs index 9d7a982abb..5b25ff15de 100644 --- a/src/bindings/mono/eina_mono/eina_strbuf.cs +++ b/src/bindings/mono/eina_mono/eina_strbuf.cs @@ -5,8 +5,10 @@ using static Eina.EinaNative.StrbufNativeMethods; namespace Eina { + namespace EinaNative { + static internal class StrbufNativeMethods { [DllImport(efl.Libs.Eina)] @@ -48,7 +50,7 @@ public class Strbuf : IDisposable private bool Disposed; ///Creates a new Strbuf. By default its lifetime is managed. - public Strbuf(Ownership ownership=Ownership.Managed) + public Strbuf(Ownership ownership = Ownership.Managed) { this.Handle = eina_strbuf_new(); this.Ownership = ownership; @@ -89,9 +91,11 @@ public class Strbuf : IDisposable return; } - if (!Disposed && (Handle != IntPtr.Zero)) { + if (!Disposed && (Handle != IntPtr.Zero)) + { eina_strbuf_free(Handle); } + Disposed = true; } @@ -115,7 +119,10 @@ public class Strbuf : IDisposable public void Reset() { if (Disposed) + { throw new ObjectDisposedException(base.GetType().Name); + } + eina_strbuf_reset(Handle); } @@ -123,7 +130,10 @@ public class Strbuf : IDisposable public bool Append(string text) { if (Disposed) + { throw new ObjectDisposedException(base.GetType().Name); + } + return eina_strbuf_append(Handle, text); } @@ -131,7 +141,10 @@ public class Strbuf : IDisposable public bool AppendEscaped(string text) { if (Disposed) + { throw new ObjectDisposedException(base.GetType().Name); + } + return eina_strbuf_append_escaped(Handle, text); } @@ -139,7 +152,10 @@ public class Strbuf : IDisposable public bool Append(char c) { if (Disposed) + { throw new ObjectDisposedException(base.GetType().Name); + } + return eina_strbuf_append_char(Handle, c); } @@ -147,10 +163,12 @@ public class Strbuf : IDisposable public string Steal() { if (Disposed) + { throw new ObjectDisposedException(base.GetType().Name); + } + return eina_strbuf_string_steal(Handle); } } } // namespace eina - diff --git a/src/bindings/mono/eina_mono/eina_stringshare.cs b/src/bindings/mono/eina_mono/eina_stringshare.cs index 83ea31ee6d..3b41bfbe3f 100644 --- a/src/bindings/mono/eina_mono/eina_stringshare.cs +++ b/src/bindings/mono/eina_mono/eina_stringshare.cs @@ -4,9 +4,11 @@ using System; using System.Runtime.InteropServices; -namespace Eina { +namespace Eina +{ -public class Stringshare { +public class Stringshare +{ [DllImport(efl.Libs.Eina)] public static extern System.IntPtr eina_stringshare_add_length(string str, System.UInt32 slen); [DllImport(efl.Libs.Eina)] public static extern System.IntPtr @@ -16,4 +18,3 @@ public class Stringshare { } } - diff --git a/src/bindings/mono/eina_mono/eina_value.cs b/src/bindings/mono/eina_mono/eina_value.cs index eedf478f8b..742dc4d366 100644 --- a/src/bindings/mono/eina_mono/eina_value.cs +++ b/src/bindings/mono/eina_mono/eina_value.cs @@ -14,9 +14,11 @@ using static Eina.EinaNative.UnsafeNativeMethods; using static Eina.TraitFunctions; -namespace Eina { +namespace Eina +{ -namespace EinaNative { +namespace EinaNative +{ // Structs to be passed from/to C when dealing with containers and // optional values. @@ -36,8 +38,8 @@ struct Value_List } [SuppressUnmanagedCodeSecurityAttribute] -static internal class UnsafeNativeMethods { - +static internal class UnsafeNativeMethods +{ [DllImport(efl.Libs.Eina)] internal static extern IntPtr eina_value_new(IntPtr type); @@ -526,13 +528,24 @@ public struct ValueNative public class SetItemFailedException : Exception { /// Default constructor. - public SetItemFailedException() : base () { } + public SetItemFailedException() : base() + { + } + /// Most commonly used contructor. - public SetItemFailedException(string msg) : base(msg) { } + public SetItemFailedException(string msg) : base(msg) + { + } + /// Wraps an inner exception. - public SetItemFailedException(string msg, Exception inner) : base(msg, inner) { } + public SetItemFailedException(string msg, Exception inner) : base(msg, inner) + { + } + /// Serializable constructor. - protected SetItemFailedException(SerializationInfo info, StreamingContext context) : base(info, context) { } + protected SetItemFailedException(SerializationInfo info, StreamingContext context) : base(info, context) + { + } } /// Exception for methods that must have been called on a container. @@ -540,18 +553,30 @@ public class SetItemFailedException : Exception public class InvalidValueTypeException: Exception { /// Default constructor. - public InvalidValueTypeException() : base () { } + public InvalidValueTypeException() : base() + { + } + /// Most commonly used contructor. - public InvalidValueTypeException(string msg) : base(msg) { } + public InvalidValueTypeException(string msg) : base(msg) + { + } + /// Wraps an inner exception. - public InvalidValueTypeException(string msg, Exception inner) : base(msg, inner) { } + public InvalidValueTypeException(string msg, Exception inner) : base(msg, inner) + { + } + /// Serializable constructor. - protected InvalidValueTypeException(SerializationInfo info, StreamingContext context) : base(info, context) { } + protected InvalidValueTypeException(SerializationInfo info, StreamingContext context) : base(info, context) + { + } } /// Managed-side Enum to represent Eina_Value_Type constants -public enum ValueType { +public enum ValueType +{ /// Signed 8 bit integer. Same as 'sbyte' SByte, /// Unsigned 8 bit integer. Same as 'byte' @@ -592,10 +617,12 @@ public enum ValueType { Empty, } -static class ValueTypeMethods { +static class ValueTypeMethods +{ public static bool IsNumeric(this ValueType val) { - switch (val) { + switch (val) + { case ValueType.SByte: case ValueType.Byte: case ValueType.Short: @@ -616,7 +643,8 @@ static class ValueTypeMethods { public static bool IsString(this ValueType val) { - switch(val) { + switch (val) + { case ValueType.String: return true; default: @@ -626,7 +654,8 @@ static class ValueTypeMethods { public static bool IsContainer(this ValueType val) { - switch(val) { + switch (val) + { case ValueType.Array: case ValueType.List: case ValueType.Hash: @@ -649,7 +678,8 @@ static class ValueTypeMethods { /// Returns the Marshal.SizeOf for the given ValueType native structure. public static int MarshalSizeOf(this ValueType val) { - switch (val) { + switch (val) + { case ValueType.Array: return Marshal.SizeOf(typeof(EinaNative.Value_Array)); case ValueType.List: @@ -659,6 +689,7 @@ static class ValueTypeMethods { } } } + static class ValueTypeBridge { private static Dictionary ManagedToNative = new Dictionary(); @@ -668,7 +699,9 @@ static class ValueTypeBridge public static ValueType GetManaged(IntPtr native) { if (!TypesLoaded) + { LoadTypes(); + } return NativeToManaged[native]; } @@ -676,7 +709,9 @@ static class ValueTypeBridge public static IntPtr GetNative(ValueType valueType) { if (!TypesLoaded) + { LoadTypes(); + } return ManagedToNative[valueType]; } @@ -779,14 +814,20 @@ public class Value : IDisposable, IComparable, IEquatable internal IntPtr Handle { get; set;} + /// Whether this wrapper owns (can free) the native value. public Ownership Ownership { get; protected set;} + private bool Disposed; + /// Whether this is an Optional value (meaning it can have a value or not). - public bool Optional { - get { + public bool Optional + { + get + { return GetValueType() == Eina.ValueType.Optional; } + /* protected set { // Should we expose this? // Something like { @@ -795,23 +836,32 @@ public class Value : IDisposable, IComparable, IEquatable // } } */ } + /// Whether this wrapper is actually empty/uninitialized (zeroed). This is different from an empty optional value. - public bool Empty { - get { + public bool Empty + { + get + { SanityChecks(); return GetValueType() == Eina.ValueType.Empty; } } /// Whether this optional value is empty. - public bool OptionalEmpty { - get { + public bool OptionalEmpty + { + get + { OptionalSanityChecks(); bool empty; if (!eina_value_optional_empty_is_wrapper(this.Handle, out empty)) + { throw new System.InvalidOperationException("Couldn't get the empty information"); + } else + { return empty; + } } } @@ -826,12 +876,14 @@ public class Value : IDisposable, IComparable, IEquatable } // Constructor to be used by the "FromContainerDesc" methods. - private Value() { + private Value() + { this.Handle = Alloc(); this.Ownership = Ownership.Managed; } - public Value(IntPtr handle, Ownership ownership=Ownership.Managed) { + public Value(IntPtr handle, Ownership ownership = Ownership.Managed) + { this.Handle = handle; this.Ownership = ownership; } @@ -840,11 +892,15 @@ public class Value : IDisposable, IComparable, IEquatable public Value(ValueType type) { if (type.IsContainer()) + { throw new ArgumentException("To use container types you must provide a subtype"); + } this.Handle = Alloc(); if (this.Handle == IntPtr.Zero) + { throw new OutOfMemoryException("Failed to allocate memory for Eina.Value"); + } // Initialize to EINA_VALUE_EMPTY before performing any other operation on this value. MemoryNative.Memset(this.Handle, 0, eina_value_sizeof()); @@ -854,10 +910,12 @@ public class Value : IDisposable, IComparable, IEquatable } /// Constructor for container values, like Array, Hash. - public Value(ValueType containerType, ValueType subtype, uint step=0) + public Value(ValueType containerType, ValueType subtype, uint step = 0) { if (!containerType.IsContainer()) + { throw new ArgumentException("First type must be a container type."); + } this.Handle = Alloc(); this.Ownership = Ownership.Managed; @@ -870,7 +928,9 @@ public class Value : IDisposable, IComparable, IEquatable { Handle = Alloc(); if (!eina_value_copy(v.Handle, this.Handle)) + { throw new System.InvalidOperationException("Failed to copy value to managed memory."); + } Disposed = false; Ownership = Ownership.Managed; @@ -880,10 +940,13 @@ public class Value : IDisposable, IComparable, IEquatable public Value(ValueNative value) { IntPtr tmp = IntPtr.Zero; - try { + try + { this.Handle = Alloc(); if (value.Type == IntPtr.Zero) // Got an EINA_VALUE_EMPTY by value. + { MemoryNative.Memset(this.Handle, 0, Marshal.SizeOf(typeof(ValueNative))); + } else { // We allocate this intermediate ValueNative using malloc to allow freeing with @@ -895,14 +958,22 @@ public class Value : IDisposable, IComparable, IEquatable // Copy is used to deep copy the pointed payload (e.g. strings) inside this struct, so we can own this value. if (!eina_value_copy(tmp, this.Handle)) + { throw new System.InvalidOperationException("Failed to copy value to managed memory."); + } } - } catch { + } + catch + { Free(this.Handle); throw; - } finally { + } + finally + { if (tmp != IntPtr.Zero) + { MemoryNative.Free(tmp); + } } this.Ownership = Ownership.Managed; @@ -912,77 +983,99 @@ public class Value : IDisposable, IComparable, IEquatable public Value(byte x) : this(ValueType.Byte) { if (!Set(x)) + { throw new InvalidOperationException("Couldn't set value."); + } } /// Type-specific constructor, for convenience. public Value(sbyte x) : this(ValueType.SByte) { if (!Set(x)) + { throw new InvalidOperationException("Couldn't set value."); + } } /// Type-specific constructor, for convenience. public Value(short x) : this(ValueType.Short) { if (!Set(x)) + { throw new InvalidOperationException("Couldn't set value."); + } } /// Type-specific constructor, for convenience. public Value(ushort x) : this(ValueType.UShort) { if (!Set(x)) + { throw new InvalidOperationException("Couldn't set value."); + } } /// Type-specific constructor, for convenience. public Value(int x) : this(ValueType.Int32) { if (!Set(x)) + { throw new InvalidOperationException("Couldn't set value."); + } } /// Type-specific constructor, for convenience. public Value(uint x) : this(ValueType.UInt32) { if (!Set(x)) + { throw new InvalidOperationException("Couldn't set value."); + } } /// Type-specific constructor, for convenience. public Value(long x) : this(ValueType.Long) { if (!Set(x)) + { throw new InvalidOperationException("Couldn't set value."); + } } /// Type-specific constructor, for convenience. public Value(ulong x) : this(ValueType.ULong) { if (!Set(x)) + { throw new InvalidOperationException("Couldn't set value."); + } } /// Type-specific constructor, for convenience. public Value(float x) : this(ValueType.Float) { if (!Set(x)) + { throw new InvalidOperationException("Couldn't set value."); + } } /// Type-specific constructor, for convenience. public Value(double x) : this(ValueType.Double) { if (!Set(x)) + { throw new InvalidOperationException("Couldn't set value."); + } } /// Type-specific constructor, for convenience. public Value(string x) : this(ValueType.String) { if (!Set(x)) + { throw new InvalidOperationException("Couldn't set value."); + } } /// Implicit conversion from managed value to native struct representation. @@ -1002,7 +1095,10 @@ public class Value : IDisposable, IComparable, IEquatable { var v = new Eina.Value(ValueType.Byte); if (!v.Set(x)) + { throw new InvalidOperationException("Couldn't set value."); + } + return v; } @@ -1011,7 +1107,10 @@ public class Value : IDisposable, IComparable, IEquatable { byte b; if (!v.Get(out b)) + { throw new InvalidOperationException("Couldn't get value."); + } + return b; } @@ -1020,7 +1119,10 @@ public class Value : IDisposable, IComparable, IEquatable { var v = new Eina.Value(ValueType.SByte); if (!v.Set(x)) + { throw new InvalidOperationException("Couldn't set value."); + } + return v; } @@ -1029,7 +1131,10 @@ public class Value : IDisposable, IComparable, IEquatable { sbyte b; if (!v.Get(out b)) + { throw new InvalidOperationException("Couldn't get value."); + } + return b; } @@ -1038,7 +1143,10 @@ public class Value : IDisposable, IComparable, IEquatable { var v = new Eina.Value(ValueType.Short); if (!v.Set(x)) + { throw new InvalidOperationException("Couldn't set value."); + } + return v; } @@ -1047,7 +1155,10 @@ public class Value : IDisposable, IComparable, IEquatable { short b; if (!v.Get(out b)) + { throw new InvalidOperationException("Couldn't get value."); + } + return b; } @@ -1056,7 +1167,10 @@ public class Value : IDisposable, IComparable, IEquatable { var v = new Eina.Value(ValueType.UShort); if (!v.Set(x)) + { throw new InvalidOperationException("Couldn't set value."); + } + return v; } @@ -1065,7 +1179,10 @@ public class Value : IDisposable, IComparable, IEquatable { ushort b; if (!v.Get(out b)) + { throw new InvalidOperationException("Couldn't get value."); + } + return b; } @@ -1074,7 +1191,10 @@ public class Value : IDisposable, IComparable, IEquatable { var v = new Eina.Value(ValueType.Int32); if (!v.Set(x)) + { throw new InvalidOperationException("Couldn't set value."); + } + return v; } @@ -1083,7 +1203,10 @@ public class Value : IDisposable, IComparable, IEquatable { int b; if (!v.Get(out b)) + { throw new InvalidOperationException("Couldn't get value."); + } + return b; } @@ -1092,7 +1215,10 @@ public class Value : IDisposable, IComparable, IEquatable { var v = new Eina.Value(ValueType.UInt32); if (!v.Set(x)) + { throw new InvalidOperationException("Couldn't set value."); + } + return v; } @@ -1101,7 +1227,10 @@ public class Value : IDisposable, IComparable, IEquatable { uint b; if (!v.Get(out b)) + { throw new InvalidOperationException("Couldn't get value."); + } + return b; } @@ -1110,7 +1239,10 @@ public class Value : IDisposable, IComparable, IEquatable { var v = new Eina.Value(ValueType.Long); if (!v.Set(x)) + { throw new InvalidOperationException("Couldn't set value."); + } + return v; } @@ -1119,7 +1251,10 @@ public class Value : IDisposable, IComparable, IEquatable { long b; if (!v.Get(out b)) + { throw new InvalidOperationException("Couldn't get value."); + } + return b; } @@ -1128,7 +1263,10 @@ public class Value : IDisposable, IComparable, IEquatable { var v = new Eina.Value(ValueType.ULong); if (!v.Set(x)) + { throw new InvalidOperationException("Couldn't set value."); + } + return v; } @@ -1137,7 +1275,10 @@ public class Value : IDisposable, IComparable, IEquatable { ulong b; if (!v.Get(out b)) + { throw new InvalidOperationException("Couldn't get value."); + } + return b; } @@ -1146,7 +1287,10 @@ public class Value : IDisposable, IComparable, IEquatable { var v = new Eina.Value(ValueType.Float); if (!v.Set(x)) + { throw new InvalidOperationException("Couldn't set value."); + } + return v; } @@ -1155,7 +1299,10 @@ public class Value : IDisposable, IComparable, IEquatable { float b; if (!v.Get(out b)) + { throw new InvalidOperationException("Couldn't get value."); + } + return b; } @@ -1164,7 +1311,10 @@ public class Value : IDisposable, IComparable, IEquatable { var v = new Eina.Value(ValueType.Double); if (!v.Set(x)) + { throw new InvalidOperationException("Couldn't set value."); + } + return v; } @@ -1173,7 +1323,10 @@ public class Value : IDisposable, IComparable, IEquatable { double b; if (!v.Get(out b)) + { throw new InvalidOperationException("Couldn't get value."); + } + return b; } @@ -1182,7 +1335,10 @@ public class Value : IDisposable, IComparable, IEquatable { var v = new Eina.Value(ValueType.String); if (!v.Set(x)) + { throw new InvalidOperationException("Couldn't set value."); + } + return v; } @@ -1191,7 +1347,10 @@ public class Value : IDisposable, IComparable, IEquatable { string b; if (!v.Get(out b)) + { throw new InvalidOperationException("Couldn't get value."); + } + return b; } @@ -1237,15 +1396,18 @@ public class Value : IDisposable, IComparable, IEquatable /// Actually free the wrapped eina value. Can be called from Dispose() or through the GC. protected virtual void Dispose(bool disposing) { - if (this.Ownership == Ownership.Unmanaged) { + if (this.Ownership == Ownership.Unmanaged) + { Disposed = true; return; } - if (!Disposed && (Handle != IntPtr.Zero)) { + if (!Disposed && (Handle != IntPtr.Zero)) + { // No need to call flush as eina_value_free already calls it for us. Free(this.Handle); } + Disposed = true; } @@ -1256,10 +1418,15 @@ public class Value : IDisposable, IComparable, IEquatable } /// Returns the native handle wrapped by this object. - public IntPtr NativeHandle { - get { + public IntPtr NativeHandle + { + get + { if (Disposed) + { throw new ObjectDisposedException(base.GetType().Name); + } + return this.Handle; } } @@ -1268,14 +1435,18 @@ public class Value : IDisposable, IComparable, IEquatable public bool Setup(ValueType type) { if (Disposed) + { throw new ObjectDisposedException(base.GetType().Name); + } // Can't call setup with Empty value type (would give an eina error) if (type == Eina.ValueType.Empty) { // Need to cleanup as it may point to payload outside the underlying Eina_Value (like arrays and strings). if (!Empty) + { eina_value_flush_wrapper(this.Handle); + } MemoryNative.Memset(this.Handle, 0, eina_value_sizeof()); @@ -1283,15 +1454,19 @@ public class Value : IDisposable, IComparable, IEquatable } if (type.IsContainer()) + { throw new ArgumentException("To setup a container you must provide a subtype."); + } return eina_value_setup_wrapper(this.Handle, ValueTypeBridge.GetNative(type)); } - public bool Setup(ValueType containerType, ValueType subtype, uint step=0) { + public bool Setup(ValueType containerType, ValueType subtype, uint step = 0) + { IntPtr native_subtype = ValueTypeBridge.GetNative(subtype); bool ret = false; - switch (containerType) { + switch (containerType) + { case ValueType.Array: ret = eina_value_array_setup_wrapper(this.Handle, native_subtype, step); break; @@ -1306,22 +1481,29 @@ public class Value : IDisposable, IComparable, IEquatable private void SanityChecks() { if (Disposed) + { throw new ObjectDisposedException(GetType().Name); + } } - private void ContainerSanityChecks(int targetIndex=-1) + private void ContainerSanityChecks(int targetIndex = -1) { SanityChecks(); uint size = 0; ValueType type = GetValueType(); if (!type.IsContainer()) + { throw new InvalidValueTypeException("Value type must be a container"); + } if (targetIndex == -1) // Some methods (e.g. append) don't care about size + { return; + } - switch (type) { + switch (type) + { case ValueType.Array: size = eina_value_array_count_wrapper(this.Handle); break; @@ -1331,8 +1513,10 @@ public class Value : IDisposable, IComparable, IEquatable } if (targetIndex >= size) + { throw new System.ArgumentOutOfRangeException( $"Index {targetIndex} is larger than max array index {size-1}"); + } } private void OptionalSanityChecks() @@ -1341,7 +1525,9 @@ public class Value : IDisposable, IComparable, IEquatable ValueType type = GetValueType(); if (!type.IsOptional()) + { throw new InvalidValueTypeException("Value is not an Optional one"); + } } /// Get a ValueNative struct with the *value* pointed by this Eina.Value. @@ -1356,13 +1542,18 @@ public class Value : IDisposable, IComparable, IEquatable SanityChecks(); if (this.Optional) + { return eina_value_optional_pset(this.Handle, ValueTypeBridge.GetNative(ValueType.Byte), ref value); + } if (!GetValueType().IsNumeric()) + { throw (new ArgumentException( "Trying to set numeric value on a non-numeric Eina.Value")); + } + return eina_value_set_wrapper_uchar(this.Handle, value); } @@ -1371,13 +1562,18 @@ public class Value : IDisposable, IComparable, IEquatable SanityChecks(); if (this.Optional) + { return eina_value_optional_pset(this.Handle, ValueTypeBridge.GetNative(ValueType.SByte), ref value); + } if (!GetValueType().IsNumeric()) + { throw (new ArgumentException( "Trying to set numeric value on a non-numeric Eina.Value")); + } + return eina_value_set_wrapper_char(this.Handle, value); } @@ -1386,13 +1582,18 @@ public class Value : IDisposable, IComparable, IEquatable SanityChecks(); if (this.Optional) + { return eina_value_optional_pset(this.Handle, ValueTypeBridge.GetNative(ValueType.Short), ref value); + } if (!GetValueType().IsNumeric()) + { throw (new ArgumentException( "Trying to set numeric value on a non-numeric Eina.Value")); + } + return eina_value_set_wrapper_short(this.Handle, value); } @@ -1401,13 +1602,18 @@ public class Value : IDisposable, IComparable, IEquatable SanityChecks(); if (this.Optional) + { return eina_value_optional_pset(this.Handle, ValueTypeBridge.GetNative(ValueType.UShort), ref value); + } if (!GetValueType().IsNumeric()) + { throw (new ArgumentException( "Trying to set numeric value on a non-numeric Eina.Value")); + } + return eina_value_set_wrapper_ushort(this.Handle, value); } @@ -1417,13 +1623,18 @@ public class Value : IDisposable, IComparable, IEquatable SanityChecks(); if (this.Optional) + { return eina_value_optional_pset(this.Handle, ValueTypeBridge.GetNative(ValueType.UInt32), ref value); + } if (!GetValueType().IsNumeric()) + { throw (new ArgumentException( "Trying to set numeric value on a non-numeric Eina.Value")); + } + return eina_value_set_wrapper_uint(this.Handle, value); } @@ -1433,13 +1644,18 @@ public class Value : IDisposable, IComparable, IEquatable SanityChecks(); if (this.Optional) + { return eina_value_optional_pset(this.Handle, ValueTypeBridge.GetNative(ValueType.Int32), ref value); + } if (!GetValueType().IsNumeric()) + { throw (new ArgumentException( "Trying to set numeric value on a non-numeric Eina.Value")); + } + return eina_value_set_wrapper_int(this.Handle, value); } @@ -1449,13 +1665,18 @@ public class Value : IDisposable, IComparable, IEquatable SanityChecks(); if (this.Optional) + { return eina_value_optional_pset(this.Handle, ValueTypeBridge.GetNative(ValueType.ULong), ref value); + } if (!GetValueType().IsNumeric()) + { throw (new ArgumentException( "Trying to set numeric value on a non-numeric Eina.Value")); + } + return eina_value_set_wrapper_ulong(this.Handle, value); } @@ -1465,13 +1686,18 @@ public class Value : IDisposable, IComparable, IEquatable SanityChecks(); if (this.Optional) + { return eina_value_optional_pset(this.Handle, ValueTypeBridge.GetNative(ValueType.Long), ref value); + } if (!GetValueType().IsNumeric()) + { throw (new ArgumentException( "Trying to set numeric value on a non-numeric Eina.Value")); + } + return eina_value_set_wrapper_long(this.Handle, value); } @@ -1481,13 +1707,17 @@ public class Value : IDisposable, IComparable, IEquatable SanityChecks(); if (this.Optional) + { return eina_value_optional_pset(this.Handle, ValueTypeBridge.GetNative(ValueType.Float), ref value); + } if (!GetValueType().IsNumeric()) + { throw (new ArgumentException( "Trying to set numeric value on a non-numeric Eina.Value")); + } return eina_value_set_wrapper_float(this.Handle, value); } @@ -1498,13 +1728,18 @@ public class Value : IDisposable, IComparable, IEquatable SanityChecks(); if (this.Optional) + { return eina_value_optional_pset(this.Handle, ValueTypeBridge.GetNative(ValueType.Double), ref value); + } if (!GetValueType().IsNumeric()) + { throw (new ArgumentException( "Trying to set numeric value on a non-numeric Eina.Value")); + } + return eina_value_set_wrapper_double(this.Handle, value); } @@ -1514,13 +1749,18 @@ public class Value : IDisposable, IComparable, IEquatable SanityChecks(); if (this.Optional) + { return eina_value_optional_pset(this.Handle, ValueTypeBridge.GetNative(ValueType.String), ref value); + } if (!GetValueType().IsString()) + { throw (new ArgumentException( "Trying to set non-string value on a string Eina.Value")); + } + // No need to worry about ownership as eina_value_set will copy the passed string. return eina_value_set_wrapper_string(this.Handle, value); } @@ -1533,9 +1773,11 @@ public class Value : IDisposable, IComparable, IEquatable int error_code = value; if (this.Optional) + { return eina_value_optional_pset(this.Handle, ValueTypeBridge.GetNative(ValueType.Error), ref error_code); + } return eina_value_set_wrapper_int(this.Handle, error_code); } @@ -1549,20 +1791,28 @@ public class Value : IDisposable, IComparable, IEquatable IntPtr ptr_val = MemoryNative.Alloc(subtype.MarshalSizeOf()); IntPtr native_type = ValueTypeBridge.GetNative(subtype); - try { - switch (subtype) { + try + { + switch (subtype) + { // PSet on Container types require an Eina_Value_, which is the structure // that contains subtype, etc. case ValueType.Array: EinaNative.Value_Array value_array; if (!eina_value_get_wrapper(value.Handle, out value_array)) + { return false; + } + Marshal.StructureToPtr(value_array, ptr_val, false); break; case ValueType.List: EinaNative.Value_List value_list; if (!eina_value_get_wrapper(value.Handle, out value_list)) + { return false; + } + Marshal.StructureToPtr(value_list, ptr_val, false); break; default: @@ -1570,7 +1820,9 @@ public class Value : IDisposable, IComparable, IEquatable } return eina_value_optional_pset(this.Handle, native_type, ptr_val); - } finally { + } + finally + { MemoryNative.Free(ptr_val); } } @@ -1580,9 +1832,13 @@ public class Value : IDisposable, IComparable, IEquatable { SanityChecks(); if (this.Optional) + { return eina_value_optional_pget(this.Handle, out value); + } else + { return eina_value_get_wrapper(this.Handle, out value); + } } /// Gets the currently stored value as a sbyte. @@ -1590,9 +1846,13 @@ public class Value : IDisposable, IComparable, IEquatable { SanityChecks(); if (this.Optional) + { return eina_value_optional_pget(this.Handle, out value); + } else + { return eina_value_get_wrapper(this.Handle, out value); + } } /// Gets the currently stored value as a short. @@ -1600,9 +1860,13 @@ public class Value : IDisposable, IComparable, IEquatable { SanityChecks(); if (this.Optional) + { return eina_value_optional_pget(this.Handle, out value); + } else + { return eina_value_get_wrapper(this.Handle, out value); + } } /// Gets the currently stored value as an ushort. @@ -1610,9 +1874,13 @@ public class Value : IDisposable, IComparable, IEquatable { SanityChecks(); if (this.Optional) + { return eina_value_optional_pget(this.Handle, out value); + } else + { return eina_value_get_wrapper(this.Handle, out value); + } } /// Gets the currently stored value as an int. @@ -1620,9 +1888,13 @@ public class Value : IDisposable, IComparable, IEquatable { SanityChecks(); if (this.Optional) + { return eina_value_optional_pget(this.Handle, out value); + } else + { return eina_value_get_wrapper(this.Handle, out value); + } } /// Gets the currently stored value as an uint. @@ -1630,9 +1902,13 @@ public class Value : IDisposable, IComparable, IEquatable { SanityChecks(); if (this.Optional) + { return eina_value_optional_pget(this.Handle, out value); + } else + { return eina_value_get_wrapper(this.Handle, out value); + } } /// Gets the currently stored value as a long. @@ -1640,9 +1916,13 @@ public class Value : IDisposable, IComparable, IEquatable { SanityChecks(); if (this.Optional) + { return eina_value_optional_pget(this.Handle, out value); + } else + { return eina_value_get_wrapper(this.Handle, out value); + } } /// Gets the currently stored value as an ulong. @@ -1650,9 +1930,13 @@ public class Value : IDisposable, IComparable, IEquatable { SanityChecks(); if (this.Optional) + { return eina_value_optional_pget(this.Handle, out value); + } else + { return eina_value_get_wrapper(this.Handle, out value); + } } /// Gets the currently stored value as a float. @@ -1660,9 +1944,13 @@ public class Value : IDisposable, IComparable, IEquatable { SanityChecks(); if (this.Optional) + { return eina_value_optional_pget(this.Handle, out value); + } else + { return eina_value_get_wrapper(this.Handle, out value); + } } /// Gets the currently stored value as a double. @@ -1670,9 +1958,13 @@ public class Value : IDisposable, IComparable, IEquatable { SanityChecks(); if (this.Optional) + { return eina_value_optional_pget(this.Handle, out value); + } else + { return eina_value_get_wrapper(this.Handle, out value); + } } /// Gets the currently stored value as a string. @@ -1680,15 +1972,20 @@ public class Value : IDisposable, IComparable, IEquatable { SanityChecks(); IntPtr output = IntPtr.Zero; - if (this.Optional) { - if (!eina_value_optional_pget(this.Handle, out output)) { + if (this.Optional) + { + if (!eina_value_optional_pget(this.Handle, out output)) + { value = String.Empty; return false; } - } else if (!eina_value_get_wrapper(this.Handle, out output)) { + } + else if (!eina_value_get_wrapper(this.Handle, out output)) + { value = String.Empty; return false; } + value = StringConversion.NativeUtf8ToManagedString(output); return true; } @@ -1700,9 +1997,13 @@ public class Value : IDisposable, IComparable, IEquatable bool ret; int intermediate; // It seems out doesn't play well with implicit operators... if (this.Optional) + { ret = eina_value_optional_pget(this.Handle, out intermediate); + } else + { ret = eina_value_get_wrapper(this.Handle, out intermediate); + } value = intermediate; @@ -1716,24 +2017,33 @@ public class Value : IDisposable, IComparable, IEquatable value = null; if (!this.Optional) + { throw new InvalidValueTypeException("Values can only be retreived"); + } IntPtr nativeType = eina_value_optional_type_get_wrapper(this.Handle); ValueType managedType = ValueTypeBridge.GetManaged(nativeType); - switch (managedType) { + switch (managedType) + { case ValueType.Array: Eina.EinaNative.Value_Array array_desc; if (!eina_value_optional_pget(this.Handle, out array_desc)) + { return false; + } + value = Value.FromArrayDesc(array_desc); break; case ValueType.List: Eina.EinaNative.Value_List list_desc; if (!eina_value_optional_pget(this.Handle, out list_desc)) + { return false; + } + value = Value.FromListDesc(list_desc); break; } @@ -1745,7 +2055,10 @@ public class Value : IDisposable, IComparable, IEquatable public ValueType GetValueType() { if (Disposed) + { throw new ObjectDisposedException(base.GetType().Name); + } + IntPtr native_type = eina_value_type_get_wrapper(this.Handle); return ValueTypeBridge.GetManaged(native_type); } @@ -1755,7 +2068,9 @@ public class Value : IDisposable, IComparable, IEquatable public bool ConvertTo(Value target) { if (target == null) + { return false; + } SanityChecks(); @@ -1766,7 +2081,10 @@ public class Value : IDisposable, IComparable, IEquatable public int CompareTo(Value other) { if (other == null) + { return 1; + } + SanityChecks(); other.SanityChecks(); return eina_value_compare_wrapper(this.Handle, other.Handle); @@ -1780,20 +2098,27 @@ public class Value : IDisposable, IComparable, IEquatable public override bool Equals(object obj) { if (obj == null) + { return false; + } Value v = obj as Value; if (v == null) + { return false; + } return this.Equals(v); } public bool Equals(Value other) { - try { + try + { return this.CompareTo(other) == 0; - } catch (ObjectDisposedException) { + } + catch (ObjectDisposedException) + { return false; } } @@ -1806,7 +2131,9 @@ public class Value : IDisposable, IComparable, IEquatable public static bool operator==(Value x, Value y) { if (object.ReferenceEquals(x, null)) + { return object.ReferenceEquals(y, null); + } return x.Equals(y); } @@ -1814,21 +2141,30 @@ public class Value : IDisposable, IComparable, IEquatable public static bool operator!=(Value x, Value y) { if (object.ReferenceEquals(x, null)) + { return !object.ReferenceEquals(y, null); + } + return !x.Equals(y); } public static bool operator>(Value x, Value y) { if (object.ReferenceEquals(x, null) || object.ReferenceEquals(y, null)) + { return false; + } + return x.CompareTo(y) > 0; } public static bool operator<(Value x, Value y) { if (object.ReferenceEquals(x, null) || object.ReferenceEquals(y, null)) + { return false; + } + return x.CompareTo(y) < 0; } @@ -1851,25 +2187,32 @@ public class Value : IDisposable, IComparable, IEquatable } // Container methods methods - public int Count() { + public int Count() + { ContainerSanityChecks(); - switch(GetValueType()) { + switch (GetValueType()) + { case ValueType.Array: return (int)eina_value_array_count_wrapper(this.Handle); case ValueType.List: return (int)eina_value_list_count_wrapper(this.Handle); } + return -1; } - public bool Append(object o) { + + public bool Append(object o) + { ContainerSanityChecks(); - switch (GetValueSubType()) { + switch (GetValueSubType()) + { case ValueType.SByte: { sbyte b = Convert.ToSByte(o); return eina_value_container_append_wrapper_char(this.Handle, b); } + case ValueType.Byte: { byte b = Convert.ToByte(o); @@ -1881,6 +2224,7 @@ public class Value : IDisposable, IComparable, IEquatable short b = Convert.ToInt16(o); return eina_value_container_append_wrapper_short(this.Handle, b); } + case ValueType.UShort: { ushort b = Convert.ToUInt16(o); @@ -1892,6 +2236,7 @@ public class Value : IDisposable, IComparable, IEquatable int x = Convert.ToInt32(o); return eina_value_container_append_wrapper_int(this.Handle, x); } + case ValueType.UInt32: { uint x = Convert.ToUInt32(o); @@ -1904,6 +2249,7 @@ public class Value : IDisposable, IComparable, IEquatable long x = Convert.ToInt64(o); return eina_value_container_append_wrapper_long(this.Handle, x); } + case ValueType.ULong: case ValueType.UInt64: { @@ -1916,6 +2262,7 @@ public class Value : IDisposable, IComparable, IEquatable float x = Convert.ToSingle(o); return eina_value_container_append_wrapper_float(this.Handle, x); } + case ValueType.Double: { double x = Convert.ToDouble(o); @@ -1928,21 +2275,25 @@ public class Value : IDisposable, IComparable, IEquatable return eina_value_container_append_wrapper_string(this.Handle, x); } } + return false; } public object this[int i] { - get { + get + { ContainerSanityChecks(i); - switch (GetValueSubType()) { + switch (GetValueSubType()) + { case ValueType.SByte: { sbyte ret = default(sbyte); eina_value_container_get_wrapper(this.Handle, i, out ret); return ret; } + case ValueType.Byte: { byte ret = default(byte); @@ -1956,6 +2307,7 @@ public class Value : IDisposable, IComparable, IEquatable eina_value_container_get_wrapper(this.Handle, i, out ret); return ret; } + case ValueType.UShort: { ushort ret = default(ushort); @@ -1969,6 +2321,7 @@ public class Value : IDisposable, IComparable, IEquatable eina_value_container_get_wrapper(this.Handle, i, out ret); return ret; } + case ValueType.UInt32: { uint ret = default(uint); @@ -1983,6 +2336,7 @@ public class Value : IDisposable, IComparable, IEquatable eina_value_container_get_wrapper(this.Handle, i, out ret); return ret; } + case ValueType.ULong: case ValueType.UInt64: { @@ -1997,6 +2351,7 @@ public class Value : IDisposable, IComparable, IEquatable eina_value_container_get_wrapper(this.Handle, i, out ret); return ret; } + case ValueType.Double: { double ret = default(double); @@ -2012,87 +2367,95 @@ public class Value : IDisposable, IComparable, IEquatable eina_value_container_get_wrapper(this.Handle, i, out ptr); return Eina.StringConversion.NativeUtf8ToManagedString(ptr); } + default: throw new InvalidOperationException("Subtype not supported."); } } - set { + set + { ContainerSanityChecks(i); - switch (GetValueSubType()) { + switch (GetValueSubType()) + { case ValueType.SByte: { sbyte v = Convert.ToSByte(value); eina_value_container_set_wrapper_char(this.Handle, i, v); + break; } - break; + case ValueType.Byte: { byte v = Convert.ToByte(value); eina_value_container_set_wrapper_uchar(this.Handle, i, v); + break; } - break; case ValueType.Short: { short x = Convert.ToInt16(value); eina_value_container_set_wrapper_short(this.Handle, i, x); + break; } - break; + case ValueType.UShort: { ushort x = Convert.ToUInt16(value); eina_value_container_set_wrapper_ushort(this.Handle, i, x); + break; } - break; case ValueType.Int32: { int x = Convert.ToInt32(value); eina_value_container_set_wrapper_int(this.Handle, i, x); + break; } - break; + case ValueType.UInt32: { uint x = Convert.ToUInt32(value); eina_value_container_set_wrapper_uint(this.Handle, i, x); + break; } - break; case ValueType.Long: case ValueType.Int64: { long x = Convert.ToInt64(value); eina_value_container_set_wrapper_long(this.Handle, i, x); + break; } - break; + case ValueType.ULong: case ValueType.UInt64: { ulong x = Convert.ToUInt64(value); eina_value_container_set_wrapper_ulong(this.Handle, i, x); + break; } - break; case ValueType.Float: { float x = Convert.ToSingle(value); eina_value_container_set_wrapper_float(this.Handle, i, x); + break; } - break; + case ValueType.Double: { double x = Convert.ToDouble(value); eina_value_container_set_wrapper_double(this.Handle, i, x); + break; } - break; case ValueType.String: { string x = Convert.ToString(value); eina_value_container_set_wrapper_string(this.Handle, i, x); + break; } - break; } } } @@ -2103,7 +2466,8 @@ public class Value : IDisposable, IComparable, IEquatable IntPtr native_subtype = IntPtr.Zero; - switch (GetValueType()) { + switch (GetValueType()) + { case ValueType.Array: native_subtype = eina_value_array_subtype_get_wrapper(this.Handle); break; @@ -2111,86 +2475,113 @@ public class Value : IDisposable, IComparable, IEquatable native_subtype = eina_value_list_subtype_get_wrapper(this.Handle); break; } + return ValueTypeBridge.GetManaged(native_subtype); } } /// Custom marshaler to convert value pointers to managed values and back, /// without changing ownership. -public class ValueMarshaler : ICustomMarshaler { - +public class ValueMarshaler : ICustomMarshaler +{ /// Creates a managed value from a C pointer, whitout taking ownership of it. - public object MarshalNativeToManaged(IntPtr pNativeData) { + public object MarshalNativeToManaged(IntPtr pNativeData) + { return new Value(pNativeData, Ownership.Unmanaged); } /// Retrieves the C pointer from a given managed value, /// keeping the managed ownership. - public IntPtr MarshalManagedToNative(object managedObj) { - try { + public IntPtr MarshalManagedToNative(object managedObj) + { + try + { Value v = (Value)managedObj; return v.Handle; - } catch (InvalidCastException) { + } + catch (InvalidCastException) + { return IntPtr.Zero; } } - public void CleanUpNativeData(IntPtr pNativeData) { + public void CleanUpNativeData(IntPtr pNativeData) + { } - public void CleanUpManagedData(object managedObj) { + public void CleanUpManagedData(object managedObj) + { } - public int GetNativeDataSize() { + public int GetNativeDataSize() + { return -1; } - public static ICustomMarshaler GetInstance(string cookie) { - if (marshaler == null) { + public static ICustomMarshaler GetInstance(string cookie) + { + if (marshaler == null) + { marshaler = new ValueMarshaler(); } + return marshaler; } + static private ValueMarshaler marshaler; } /// Custom marshaler to convert value pointers to managed values and back, /// also transferring the ownership to the other side. -public class ValueMarshalerOwn : ICustomMarshaler { +public class ValueMarshalerOwn : ICustomMarshaler +{ /// Creates a managed value from a C pointer, taking the ownership. - public object MarshalNativeToManaged(IntPtr pNativeData) { + public object MarshalNativeToManaged(IntPtr pNativeData) + { return new Value(pNativeData, Ownership.Managed); } /// Retrieves the C pointer from a given managed value, /// transferring the ownership to the unmanaged side, which should release it /// when not needed. - public IntPtr MarshalManagedToNative(object managedObj) { - try { + public IntPtr MarshalManagedToNative(object managedObj) + { + try + { Value v = (Value)managedObj; v.ReleaseOwnership(); return v.Handle; - } catch (InvalidCastException) { + } + catch (InvalidCastException) + { return IntPtr.Zero; } } - public void CleanUpNativeData(IntPtr pNativeData) { + public void CleanUpNativeData(IntPtr pNativeData) + { } - public void CleanUpManagedData(object managedObj) { + public void CleanUpManagedData(object managedObj) + { } - public int GetNativeDataSize() { + public int GetNativeDataSize() + { return -1; } - public static ICustomMarshaler GetInstance(string cookie) { - if (marshaler == null) { + public static ICustomMarshaler GetInstance(string cookie) + { + if (marshaler == null) + { marshaler = new ValueMarshalerOwn(); } + return marshaler; } + static private ValueMarshalerOwn marshaler; } + } diff --git a/src/bindings/mono/eldbus_mono/eldbus_common.cs b/src/bindings/mono/eldbus_mono/eldbus_common.cs index 30e3b0be8e..39c2d039d6 100644 --- a/src/bindings/mono/eldbus_mono/eldbus_common.cs +++ b/src/bindings/mono/eldbus_mono/eldbus_common.cs @@ -5,7 +5,8 @@ using System.Runtime.InteropServices; using static eldbus.EldbusMessageNativeFunctions; -namespace eldbus { +namespace eldbus +{ public static class Timeout { @@ -26,6 +27,7 @@ public struct ObjectPath { return new ObjectPath(str); } + public static implicit operator string(ObjectPath path) { return path.value; @@ -46,6 +48,7 @@ public struct SignatureString { return new SignatureString(str); } + public static implicit operator string(SignatureString sig) { return sig.value; @@ -66,6 +69,7 @@ public struct UnixFd { return new UnixFd(fd); } + public static implicit operator Int32(UnixFd unix_fd) { return unix_fd.value; @@ -75,23 +79,107 @@ public struct UnixFd public static class Argument { - public class ByteType { public const char Code = 'y'; public const string Signature = "y"; } - public class BooleanType { public const char Code = 'b'; public const string Signature = "b"; } - public class Int16Type { public const char Code = 'n'; public const string Signature = "n"; } - public class UInt16Type { public const char Code = 'q'; public const string Signature = "q"; } - public class Int32Type { public const char Code = 'i'; public const string Signature = "i"; } - public class UInt32Type { public const char Code = 'u'; public const string Signature = "u"; } - public class Int64Type { public const char Code = 'x'; public const string Signature = "x"; } - public class UInt64Type { public const char Code = 't'; public const string Signature = "t"; } - public class DoubleType { public const char Code = 'd'; public const string Signature = "d"; } - public class StringType { public const char Code = 's'; public const string Signature = "s"; } - public class ObjectPathType { public const char Code = 'o'; public const string Signature = "o"; } - public class SignatureType { public const char Code = 'g'; public const string Signature = "g"; } - public class ArrayType { public const char Code = 'a'; public const string Signature = "a"; } - public class StructType { public const char Code = 'r'; public const string Signature = "r"; } - public class VariantType { public const char Code = 'v'; public const string Signature = "v"; } - public class DictEntryType { public const char Code = 'e'; public const string Signature = "e"; } - public class UnixFdType { public const char Code = 'h'; public const string Signature = "h"; } + public class ByteType + { + public const char Code = 'y'; + public const string Signature = "y"; + } + + public class BooleanType + { + public const char Code = 'b'; + public const string Signature = "b"; + } + + public class Int16Type + { + public const char Code = 'n'; + public const string Signature = "n"; + } + + public class UInt16Type + { + public const char Code = 'q'; + public const string Signature = "q"; + } + + public class Int32Type + { + public const char Code = 'i'; + public const string Signature = "i"; + } + + public class UInt32Type + { + public const char Code = 'u'; + public const string Signature = "u"; + } + + public class Int64Type + { + public const char Code = 'x'; + public const string Signature = "x"; + } + + public class UInt64Type + { + public const char Code = 't'; + public const string Signature = "t"; + } + + public class DoubleType + { + public const char Code = 'd'; + public const string Signature = "d"; + } + + public class StringType + { + public const char Code = 's'; + public const string Signature = "s"; + } + + public class ObjectPathType + { + public const char Code = 'o'; + public const string Signature = "o"; + } + + public class SignatureType + { + public const char Code = 'g'; + public const string Signature = "g"; + } + + public class ArrayType + { + public const char Code = 'a'; + public const string Signature = "a"; + } + + public class StructType + { + public const char Code = 'r'; + public const string Signature = "r"; + } + + public class VariantType + { + public const char Code = 'v'; + public const string Signature = "v"; + } + + public class DictEntryType + { + public const char Code = 'e'; + public const string Signature = "e"; + } + + public class UnixFdType + { + public const char Code = 'h'; + public const string Signature = "h"; + } // public static readonly ByteType ByteT = new ByteType(); // public static readonly BooleanType BooleanT = new BooleanType(); @@ -135,13 +223,17 @@ public abstract class BasicMessageArgument public void AppendTo(eldbus.Message msg) { if (!InternalAppendTo(msg)) + { throw new SEHException("Eldbus: could not append basic type to eldbus.Message"); + } } public void AppendTo(eldbus.MessageIterator iter) { if (!InternalAppendTo(iter)) + { throw new SEHException("Eldbus: could not append basic type to eldbus.MessageIterator"); + } } public abstract char TypeCode {get;} @@ -219,8 +311,15 @@ public class ByteMessageArgument : BasicMessageArgument value = arg; } - public override char TypeCode { get { return Argument.ByteType.Code; } } - public override string Signature { get { return Argument.ByteType.Signature; } } + public override char TypeCode + { + get { return Argument.ByteType.Code; } + } + + public override string Signature + { + get { return Argument.ByteType.Signature; } + } protected override bool InternalAppendTo(eldbus.Message msg) { @@ -242,8 +341,15 @@ public class BoolMessageArgument : BasicMessageArgument value = Convert.ToInt32(arg); } - public override char TypeCode { get { return Argument.BooleanType.Code; } } - public override string Signature { get { return Argument.ByteType.Signature; } } + public override char TypeCode + { + get { return Argument.BooleanType.Code; } + } + + public override string Signature + { + get { return Argument.ByteType.Signature; } + } protected override bool InternalAppendTo(eldbus.Message msg) { @@ -265,8 +371,15 @@ public class Int16MessageArgument : BasicMessageArgument value = arg; } - public override char TypeCode { get { return Argument.Int16Type.Code; } } - public override string Signature { get { return Argument.ByteType.Signature; } } + public override char TypeCode + { + get { return Argument.Int16Type.Code; } + } + + public override string Signature + { + get { return Argument.ByteType.Signature; } + } protected override bool InternalAppendTo(eldbus.Message msg) { @@ -288,8 +401,15 @@ public class UInt16MessageArgument : BasicMessageArgument value = arg; } - public override char TypeCode { get { return Argument.UInt16Type.Code; } } - public override string Signature { get { return Argument.ByteType.Signature; } } + public override char TypeCode + { + get { return Argument.UInt16Type.Code; } + } + + public override string Signature + { + get { return Argument.ByteType.Signature; } + } protected override bool InternalAppendTo(eldbus.Message msg) { @@ -311,8 +431,15 @@ public class Int32MessageArgument : BasicMessageArgument value = arg; } - public override char TypeCode { get { return Argument.Int32Type.Code; } } - public override string Signature { get { return Argument.ByteType.Signature; } } + public override char TypeCode + { + get { return Argument.Int32Type.Code; } + } + + public override string Signature + { + get { return Argument.ByteType.Signature; } + } protected override bool InternalAppendTo(eldbus.Message msg) { @@ -334,8 +461,15 @@ public class UInt32MessageArgument : BasicMessageArgument value = arg; } - public override char TypeCode { get { return Argument.UInt32Type.Code; } } - public override string Signature { get { return Argument.ByteType.Signature; } } + public override char TypeCode + { + get { return Argument.UInt32Type.Code; } + } + + public override string Signature + { + get { return Argument.ByteType.Signature; } + } protected override bool InternalAppendTo(eldbus.Message msg) { @@ -357,8 +491,15 @@ public class Int64MessageArgument : BasicMessageArgument value = arg; } - public override char TypeCode { get { return Argument.Int64Type.Code; } } - public override string Signature { get { return Argument.ByteType.Signature; } } + public override char TypeCode + { + get { return Argument.Int64Type.Code; } + } + + public override string Signature + { + get { return Argument.ByteType.Signature; } + } protected override bool InternalAppendTo(eldbus.Message msg) { @@ -380,8 +521,15 @@ public class UInt64MessageArgument : BasicMessageArgument value = arg; } - public override char TypeCode { get { return Argument.UInt64Type.Code; } } - public override string Signature { get { return Argument.ByteType.Signature; } } + public override char TypeCode + { + get { return Argument.UInt64Type.Code; } + } + + public override string Signature + { + get { return Argument.ByteType.Signature; } + } protected override bool InternalAppendTo(eldbus.Message msg) { @@ -403,8 +551,15 @@ public class DoubleMessageArgument : BasicMessageArgument value = arg; } - public override char TypeCode { get { return Argument.DoubleType.Code; } } - public override string Signature { get { return Argument.ByteType.Signature; } } + public override char TypeCode + { + get { return Argument.DoubleType.Code; } + } + + public override string Signature + { + get { return Argument.ByteType.Signature; } + } protected override bool InternalAppendTo(eldbus.Message msg) { @@ -439,32 +594,53 @@ public abstract class StringLikeMessageArgument : BasicMessageArgument public class StringMessageArgument : StringLikeMessageArgument { - public StringMessageArgument(string arg) - : base(arg) - {} + public StringMessageArgument(string arg) : base(arg) + { + } - public override char TypeCode { get { return Argument.StringType.Code; } } - public override string Signature { get { return Argument.ByteType.Signature; } } + public override char TypeCode + { + get { return Argument.StringType.Code; } + } + + public override string Signature + { + get { return Argument.ByteType.Signature; } + } } public class ObjectPathMessageArgument : StringLikeMessageArgument { - public ObjectPathMessageArgument(ObjectPath arg) - : base(arg.value) - {} + public ObjectPathMessageArgument(ObjectPath arg) : base(arg.value) + { + } - public override char TypeCode { get { return Argument.ObjectPathType.Code; } } - public override string Signature { get { return Argument.ByteType.Signature; } } + public override char TypeCode + { + get { return Argument.ObjectPathType.Code; } + } + + public override string Signature + { + get { return Argument.ByteType.Signature; } + } } public class SignatureMessageArgument : StringLikeMessageArgument { - public SignatureMessageArgument(SignatureString arg) - : base(arg.value) - {} + public SignatureMessageArgument(SignatureString arg) : base(arg.value) + { + } - public override char TypeCode { get { return Argument.SignatureType.Code; } } - public override string Signature { get { return Argument.ByteType.Signature; } } + public override char TypeCode + { + get { return Argument.SignatureType.Code; } + } + + public override string Signature + { + get { return Argument.ByteType.Signature; } + } } public class UnixFdMessageArgument : BasicMessageArgument @@ -476,8 +652,15 @@ public class UnixFdMessageArgument : BasicMessageArgument value = arg.value; } - public override char TypeCode { get { return Argument.UnixFdType.Code; } } - public override string Signature { get { return Argument.ByteType.Signature; } } + public override char TypeCode + { + get { return Argument.UnixFdType.Code; } + } + + public override string Signature + { + get { return Argument.ByteType.Signature; } + } protected override bool InternalAppendTo(eldbus.Message msg) { @@ -497,7 +680,10 @@ public static class Common public static void RaiseNullHandle() { if (NullHandleError == 0) + { NullHandleError = Eina.Error.Register("Eldbus: null handle"); + } + Eina.Error.Raise(NullHandleError); } @@ -511,7 +697,10 @@ public static class Common public static Eldbus_Message_Cb GetMessageCbWrapper() { if (message_cb_wrapper == null) + { message_cb_wrapper = new Eldbus_Message_Cb(MessageCbWrapper); + } + return message_cb_wrapper; } @@ -532,7 +721,7 @@ public static class Common msg = new eldbus.Message(msg_hdl, false); pending = new eldbus.Pending(pending_hdl, false); } - catch(Exception e) + catch (Exception e) { Eina.Log.Error("Eldbus: could not convert Eldbus_Message_Cb parameters. Exception: " + e.ToString()); return; @@ -542,7 +731,7 @@ public static class Common { dlgt(msg, pending); } - catch(Exception e) + catch (Exception e) { Eina.Log.Error("Eldbus: Eldbus_Message_Cb delegate error. Exception: " + e.ToString()); } @@ -553,5 +742,3 @@ public static class Common } } - - diff --git a/src/bindings/mono/eldbus_mono/eldbus_config.cs b/src/bindings/mono/eldbus_mono/eldbus_config.cs index c5bae0767b..08d2386f9b 100644 --- a/src/bindings/mono/eldbus_mono/eldbus_config.cs +++ b/src/bindings/mono/eldbus_mono/eldbus_config.cs @@ -3,7 +3,8 @@ using System; using System.Runtime.InteropServices; -namespace eldbus { +namespace eldbus +{ public static class Config { @@ -13,7 +14,9 @@ public static class Config public static void Init() { if (eldbus_init() == 0) + { throw new Efl.EflException("Failed to initialize Eldbus"); + } } public static void Shutdown() diff --git a/src/bindings/mono/eldbus_mono/eldbus_connection.cs b/src/bindings/mono/eldbus_mono/eldbus_connection.cs index bef7f29acb..24a1ad9aff 100644 --- a/src/bindings/mono/eldbus_mono/eldbus_connection.cs +++ b/src/bindings/mono/eldbus_mono/eldbus_connection.cs @@ -5,8 +5,8 @@ using System.Runtime.InteropServices; using static eldbus.EldbusConnectionNativeFunctions; -namespace eldbus { - +namespace eldbus +{ public static class EldbusConnectionNativeFunctions { @@ -155,10 +155,14 @@ public class Connection : IDisposable IntPtr h = Handle; Handle = IntPtr.Zero; if (h == IntPtr.Zero) + { return; + } if (Own) + { eldbus_connection_unref(h); + } } public void Dispose() @@ -184,15 +188,19 @@ public class Connection : IDisposable CheckHandle(); if (msg == null) + { throw new ArgumentNullException("msg"); + } IntPtr cb_wrapper = (dlgt == null ? IntPtr.Zero : eldbus.Common.GetMessageCbWrapperPtr()); IntPtr cb_data = (dlgt == null ? IntPtr.Zero : Marshal.GetFunctionPointerForDelegate(dlgt)); var pending_hdl = eldbus_connection_send(Handle, msg.Handle, cb_wrapper, cb_data, timeout); - if(pending_hdl == IntPtr.Zero) + if (pending_hdl == IntPtr.Zero) + { throw new SEHException("Eldbus: could not get `Pending' object from eldbus_connection_send"); + } msg.Ref(); @@ -204,7 +212,10 @@ public class Connection : IDisposable CheckHandle(); var ptr = eldbus_connection_unique_name_get(Handle); if (ptr == IntPtr.Zero) + { return null; + } + return Eina.StringConversion.NativeUtf8ToManagedString(ptr); } @@ -213,15 +224,19 @@ public class Connection : IDisposable CheckHandle(); if (bus == null) + { throw new ArgumentNullException("bus"); + } IntPtr cb_wrapper = (dlgt == null ? IntPtr.Zero : eldbus.Common.GetMessageCbWrapperPtr()); IntPtr cb_data = (dlgt == null ? IntPtr.Zero : Marshal.GetFunctionPointerForDelegate(dlgt)); var pending_hdl = eldbus_name_request(Handle, bus, flags, cb_wrapper, cb_data); - if(pending_hdl == IntPtr.Zero) + if (pending_hdl == IntPtr.Zero) + { throw new SEHException("Eldbus: could not get `Pending' object from eldbus_name_request"); + } return new eldbus.Pending(pending_hdl, false); } @@ -231,15 +246,19 @@ public class Connection : IDisposable CheckHandle(); if (bus == null) + { throw new ArgumentNullException("bus"); + } IntPtr cb_wrapper = (dlgt == null ? IntPtr.Zero : eldbus.Common.GetMessageCbWrapperPtr()); IntPtr cb_data = (dlgt == null ? IntPtr.Zero : Marshal.GetFunctionPointerForDelegate(dlgt)); var pending_hdl = eldbus_name_release(Handle, bus, cb_wrapper, cb_data); - if(pending_hdl == IntPtr.Zero) + if (pending_hdl == IntPtr.Zero) + { throw new SEHException("Eldbus: could not get `Pending' object from eldbus_name_release"); + } return new eldbus.Pending(pending_hdl, false); } @@ -249,15 +268,19 @@ public class Connection : IDisposable CheckHandle(); if (bus == null) + { throw new ArgumentNullException("bus"); + } IntPtr cb_wrapper = (dlgt == null ? IntPtr.Zero : eldbus.Common.GetMessageCbWrapperPtr()); IntPtr cb_data = (dlgt == null ? IntPtr.Zero : Marshal.GetFunctionPointerForDelegate(dlgt)); var pending_hdl = eldbus_name_owner_get(Handle, bus, cb_wrapper, cb_data); - if(pending_hdl == IntPtr.Zero) + if (pending_hdl == IntPtr.Zero) + { throw new SEHException("Eldbus: could not get `Pending' object from eldbus_name_owner_get"); + } return new eldbus.Pending(pending_hdl, false); } @@ -267,15 +290,19 @@ public class Connection : IDisposable CheckHandle(); if (bus == null) + { throw new ArgumentNullException("bus"); + } IntPtr cb_wrapper = (dlgt == null ? IntPtr.Zero : eldbus.Common.GetMessageCbWrapperPtr()); IntPtr cb_data = (dlgt == null ? IntPtr.Zero : Marshal.GetFunctionPointerForDelegate(dlgt)); var pending_hdl = eldbus_name_owner_has(Handle, bus, cb_wrapper, cb_data); - if(pending_hdl == IntPtr.Zero) + if (pending_hdl == IntPtr.Zero) + { throw new SEHException("Eldbus: could not get `Pending' object from eldbus_name_owner_has"); + } return new eldbus.Pending(pending_hdl, false); } @@ -289,8 +316,10 @@ public class Connection : IDisposable var pending_hdl = eldbus_names_list(Handle, cb_wrapper, cb_data); - if(pending_hdl == IntPtr.Zero) + if (pending_hdl == IntPtr.Zero) + { throw new SEHException("Eldbus: could not get `Pending' object from eldbus_names_list"); + } return new eldbus.Pending(pending_hdl, false); } @@ -304,8 +333,10 @@ public class Connection : IDisposable var pending_hdl = eldbus_names_activatable_list(Handle, cb_wrapper, cb_data); - if(pending_hdl == IntPtr.Zero) + if (pending_hdl == IntPtr.Zero) + { throw new SEHException("Eldbus: could not get `Pending' object from eldbus_names_activatable_list"); + } return new eldbus.Pending(pending_hdl, false); } @@ -319,8 +350,10 @@ public class Connection : IDisposable var pending_hdl = eldbus_hello(Handle, cb_wrapper, cb_data); - if(pending_hdl == IntPtr.Zero) + if (pending_hdl == IntPtr.Zero) + { throw new SEHException("Eldbus: could not get `Pending' object from eldbus_hello"); + } return new eldbus.Pending(pending_hdl, false); } @@ -330,15 +363,19 @@ public class Connection : IDisposable CheckHandle(); if (bus == null) + { throw new ArgumentNullException("bus"); + } IntPtr cb_wrapper = (dlgt == null ? IntPtr.Zero : eldbus.Common.GetMessageCbWrapperPtr()); IntPtr cb_data = (dlgt == null ? IntPtr.Zero : Marshal.GetFunctionPointerForDelegate(dlgt)); var pending_hdl = eldbus_name_start(Handle, bus, flags, cb_wrapper, cb_data); - if(pending_hdl == IntPtr.Zero) + if (pending_hdl == IntPtr.Zero) + { throw new SEHException("Eldbus: could not get `Pending' object from eldbus_name_start"); + } return new eldbus.Pending(pending_hdl, false); } diff --git a/src/bindings/mono/eldbus_mono/eldbus_message.cs b/src/bindings/mono/eldbus_mono/eldbus_message.cs index a8c96ffe7a..4e2c154e6a 100644 --- a/src/bindings/mono/eldbus_mono/eldbus_message.cs +++ b/src/bindings/mono/eldbus_mono/eldbus_message.cs @@ -5,7 +5,8 @@ using System.Runtime.InteropServices; using static eldbus.EldbusMessageNativeFunctions; -namespace eldbus { +namespace eldbus +{ public static class EldbusMessageNativeFunctions { @@ -223,10 +224,14 @@ public class Message : IDisposable IntPtr h = Handle; Handle = IntPtr.Zero; if (h == IntPtr.Zero) + { return; + } if (Own) + { eldbus_message_unref(h); + } } public void Dispose() @@ -251,7 +256,10 @@ public class Message : IDisposable { var ptr = eldbus_message_method_call_new(dest, path, iface, method); if (ptr == IntPtr.Zero) + { throw new SEHException("Eldbus: could not get `Message' object from eldbus_message_method_call_new"); + } + return new eldbus.Message(ptr, true); } @@ -259,7 +267,10 @@ public class Message : IDisposable { var ptr = eldbus_message_signal_new(path, _interface, name); if (ptr == IntPtr.Zero) + { throw new SEHException("Eldbus: could not get `Message' object from eldbus_message_signal_new"); + } + return new eldbus.Message(ptr, true); } @@ -322,7 +333,10 @@ public class Message : IDisposable CheckHandle(); var ptr = eldbus_message_error_new(Handle, error_name, error_msg); if (ptr == IntPtr.Zero) + { throw new SEHException("Eldbus: could not get `Message' object from eldbus_message_error_new"); + } + return new eldbus.Message(ptr, false); } @@ -331,7 +345,10 @@ public class Message : IDisposable CheckHandle(); var ptr = eldbus_message_method_return_new(Handle); if (ptr == IntPtr.Zero) + { throw new SEHException("Eldbus: could not get `Message' object from eldbus_message_method_return_new"); + } + return new eldbus.Message(ptr, false); } @@ -459,7 +476,10 @@ public class Message : IDisposable CheckHandle(); var ptr = eldbus_message_iter_get(Handle); if (ptr == IntPtr.Zero) + { throw new SEHException("Eldbus: could not get `MessageIterator' object from eldbus_message_iter_get"); + } + return new eldbus.MessageIterator(ptr, IntPtr.Zero); } } @@ -514,12 +534,18 @@ public class MessageIterator IntPtr new_iter = IntPtr.Zero; if (signature[0] == 'v') + { new_iter = eldbus_message_iter_container_new(Handle, 'v', signature.Substring(1)); + } else if (!eldbus_message_iter_arguments_append(Handle, signature, out new_iter)) + { throw new SEHException("Eldbus: could not append container type"); + } if (new_iter == IntPtr.Zero) + { throw new SEHException("Eldbus: could not get `MessageIterator' object from eldbus_message_iter_arguments_append"); + } return new eldbus.MessageIterator(new_iter, Handle); } @@ -531,7 +557,9 @@ public class MessageIterator IntPtr new_iter = eldbus_message_iter_container_new(Handle, type, contained_signature); if (new_iter == IntPtr.Zero) + { throw new SEHException("Eldbus: could not get `MessageIterator' object from eldbus_message_iter_container_new"); + } return new eldbus.MessageIterator(new_iter, Handle); } @@ -541,10 +569,14 @@ public class MessageIterator CheckHandle(); if (Parent == IntPtr.Zero) + { throw new SEHException("Eldbus: can not close MessageIterator open container without a parent"); + } if (!eldbus_message_iter_container_close(Parent, Handle)) + { throw new SEHException("Eldbus: could not close MessageIterator"); + } Handle = IntPtr.Zero; Parent = IntPtr.Zero; @@ -654,7 +686,10 @@ public class MessageIterator IntPtr hdl = IntPtr.Zero; bool r = eldbus_message_iter_get_and_next(Handle, typecode, out hdl); if (hdl == IntPtr.Zero) + { throw new SEHException("Eldbus: could not get argument"); + } + iter = new eldbus.MessageIterator(hdl, Handle); return r; @@ -665,7 +700,10 @@ public class MessageIterator CheckHandle(); IntPtr hdl = IntPtr.Zero; if (!eldbus_message_iter_arguments_get(Handle, signatue, out hdl) || hdl == IntPtr.Zero) + { throw new SEHException("Eldbus: could not get argument"); + } + iter = new eldbus.MessageIterator(hdl, Handle); return Next(); @@ -764,7 +802,10 @@ public class MessageIterator CheckHandle(); IntPtr hdl = IntPtr.Zero; if (!eldbus_message_iter_arguments_get(Handle, signatue, out hdl) || hdl == IntPtr.Zero) + { throw new SEHException("Eldbus: could not get argument"); + } + iter = new eldbus.MessageIterator(hdl, Handle); } @@ -789,7 +830,9 @@ public class MessageIterator CheckHandle(); if (!eldbus_message_iter_fixed_array_get(Handle, type_code, out value, out n_elements)) + { throw new SEHException("Eldbus: could not get fixed array"); + } } public void GetFixedArray(out byte[] array) @@ -880,4 +923,3 @@ public class MessageIterator } } - diff --git a/src/bindings/mono/eldbus_mono/eldbus_object.cs b/src/bindings/mono/eldbus_mono/eldbus_object.cs index 7b48743dd3..1e9af69709 100644 --- a/src/bindings/mono/eldbus_mono/eldbus_object.cs +++ b/src/bindings/mono/eldbus_mono/eldbus_object.cs @@ -7,8 +7,8 @@ using static eldbus.EldbusObjectNativeFunctions; using IntPtr = System.IntPtr; -namespace eldbus { - +namespace eldbus +{ public static class EldbusObjectNativeFunctions { @@ -112,16 +112,26 @@ public class Object : System.IDisposable public Object(eldbus.Connection conn, string bus, string path) { if (conn == null) + { throw new System.ArgumentNullException("conn"); + } + if (bus == null) + { throw new System.ArgumentNullException("bus"); + } + if (path == null) + { throw new System.ArgumentNullException("path"); + } var handle = eldbus_object_get(conn.Handle, bus, path); if (handle == IntPtr.Zero) + { throw new SEHException("Eldbus: could not get `Object' object from eldbus_object_get"); + } InitNew(handle, true); } @@ -136,10 +146,14 @@ public class Object : System.IDisposable IntPtr h = Handle; Handle = IntPtr.Zero; if (h == IntPtr.Zero) + { return; + } if (Own) + { eldbus_object_unref(h); + } } public void Dispose() @@ -166,7 +180,9 @@ public class Object : System.IDisposable var conn = eldbus_object_connection_get(Handle); if (conn == IntPtr.Zero) + { throw new SEHException("Eldbus: could not get `Connection' object from eldbus_object_connection_get"); + } return new eldbus.Connection(conn, false); } @@ -202,7 +218,9 @@ public class Object : System.IDisposable CheckHandle(); if (msg == null) + { throw new System.ArgumentNullException("msg"); + } IntPtr cb_wrapper = dlgt == null ? IntPtr.Zero : eldbus.Common.GetMessageCbWrapperPtr(); IntPtr cb_data = dlgt == null ? IntPtr.Zero : Marshal.GetFunctionPointerForDelegate(dlgt); @@ -210,7 +228,9 @@ public class Object : System.IDisposable var pending_hdl = eldbus_object_send(Handle, msg.Handle, cb_wrapper, cb_data, timeout); if (pending_hdl == IntPtr.Zero) + { throw new SEHException("Eldbus: could not get `Pending' object from eldbus_object_send"); + } return new eldbus.Pending(pending_hdl, false); } @@ -222,7 +242,9 @@ public class Object : System.IDisposable var hdl = eldbus_object_method_call_new(Handle, _interface, member); if (hdl == IntPtr.Zero) + { throw new SEHException("Eldbus: could not get `Message' object from eldbus_object_method_call_new"); + } return new eldbus.Message(hdl, false); } @@ -237,7 +259,9 @@ public class Object : System.IDisposable var pending_hdl = eldbus_object_peer_ping(Handle, cb_wrapper, cb_data); if (pending_hdl == IntPtr.Zero) + { throw new SEHException("Eldbus: could not get `Pending' object from eldbus_object_peer_ping"); + } return new eldbus.Pending(pending_hdl, false); } @@ -252,7 +276,9 @@ public class Object : System.IDisposable var pending_hdl = eldbus_object_peer_machine_id_get(Handle, cb_wrapper, cb_data); if (pending_hdl == IntPtr.Zero) + { throw new SEHException("Eldbus: could not get `Pending' object from eldbus_object_peer_machine_id_get"); + } return new eldbus.Pending(pending_hdl, false); } @@ -267,7 +293,9 @@ public class Object : System.IDisposable var pending_hdl = eldbus_object_introspect(Handle, cb_wrapper, cb_data); if (pending_hdl == IntPtr.Zero) + { throw new SEHException("Eldbus: could not get `Pending' object from eldbus_object_introspect"); + } return new eldbus.Pending(pending_hdl, false); } @@ -282,12 +310,12 @@ public class Object : System.IDisposable var pending_hdl = eldbus_object_managed_objects_get(Handle, cb_wrapper, cb_data); if (pending_hdl == IntPtr.Zero) + { throw new SEHException("Eldbus: could not get `Pending' object from eldbus_object_managed_objects_get"); + } return new eldbus.Pending(pending_hdl, false); } - } - } diff --git a/src/bindings/mono/eldbus_mono/eldbus_pending.cs b/src/bindings/mono/eldbus_mono/eldbus_pending.cs index 906630ecbb..fbd8f35be9 100644 --- a/src/bindings/mono/eldbus_mono/eldbus_pending.cs +++ b/src/bindings/mono/eldbus_mono/eldbus_pending.cs @@ -5,7 +5,8 @@ using System.Runtime.InteropServices; using static eldbus.EldbusPendingNativeFunctions; -namespace eldbus { +namespace eldbus +{ public static class EldbusPendingNativeFunctions { @@ -108,4 +109,3 @@ public class Pending } } - diff --git a/src/bindings/mono/eldbus_mono/eldbus_proxy.cs b/src/bindings/mono/eldbus_mono/eldbus_proxy.cs index ea44ca5db5..0fab5ebcab 100644 --- a/src/bindings/mono/eldbus_mono/eldbus_proxy.cs +++ b/src/bindings/mono/eldbus_mono/eldbus_proxy.cs @@ -5,7 +5,8 @@ using System.Runtime.InteropServices; using static eldbus.EldbusProxyNativeFunctions; -namespace eldbus { +namespace eldbus +{ public static class EldbusProxyNativeFunctions { @@ -104,10 +105,14 @@ public class Proxy : IDisposable IntPtr h = Handle; Handle = IntPtr.Zero; if (h == IntPtr.Zero) + { return; + } if (Own) + { eldbus_proxy_unref(h); + } } public void Dispose() @@ -133,7 +138,10 @@ public class Proxy : IDisposable CheckHandle(); var ptr = eldbus_proxy_object_get(Handle); if (ptr == IntPtr.Zero) + { throw new SEHException("Eldbus: could not get `Object' object from eldbus_proxy_object_get"); + } + return new eldbus.Object(ptr, false); } @@ -149,11 +157,16 @@ public class Proxy : IDisposable CheckHandle(); if (member == null) + { throw new ArgumentNullException("member"); + } var ptr = eldbus_proxy_method_call_new(Handle, member); if (ptr == IntPtr.Zero) + { throw new SEHException("Eldbus: could not get `Message' object from eldbus_proxy_method_call_new"); + } + return new eldbus.Message(ptr, false); } @@ -162,7 +175,9 @@ public class Proxy : IDisposable CheckHandle(); if (msg == null) + { throw new ArgumentNullException("msg"); + } IntPtr cb_wrapper = dlgt == null ? IntPtr.Zero : eldbus.Common.GetMessageCbWrapperPtr(); IntPtr cb_data = dlgt == null ? IntPtr.Zero : Marshal.GetFunctionPointerForDelegate(dlgt); @@ -170,7 +185,9 @@ public class Proxy : IDisposable var pending_hdl = eldbus_proxy_send(Handle, msg.Handle, cb_wrapper, cb_data, timeout); if (pending_hdl == IntPtr.Zero) + { throw new SEHException("Eldbus: could not get `Pending' object from eldbus_proxy_send"); + } return new eldbus.Pending(pending_hdl, false); } @@ -180,7 +197,10 @@ public class Proxy : IDisposable CheckHandle(); var ptr = eldbus_proxy_send_and_block(Handle, msg.Handle, timeout); if (ptr == IntPtr.Zero) + { throw new SEHException("Eldbus: could not get `Message' object from eldbus_proxy_send_and_block"); + } + return new eldbus.Message(ptr, true); } @@ -205,4 +225,3 @@ public class Proxy : IDisposable } } - diff --git a/src/bindings/mono/eldbus_mono/eldbus_service.cs b/src/bindings/mono/eldbus_mono/eldbus_service.cs index 33c3acb194..6e089720e1 100644 --- a/src/bindings/mono/eldbus_mono/eldbus_service.cs +++ b/src/bindings/mono/eldbus_mono/eldbus_service.cs @@ -5,7 +5,8 @@ using System.Runtime.InteropServices; using static eldbus.EldbusServiceNativeFunctions; -namespace eldbus { +namespace eldbus +{ public static class EldbusServiceNativeFunctions { @@ -65,4 +66,3 @@ public static class EldbusServiceNativeFunctions } } - diff --git a/src/bindings/mono/eo_mono/FunctionWrapper.cs b/src/bindings/mono/eo_mono/FunctionWrapper.cs index 5aa4030a2f..bdbca77d93 100644 --- a/src/bindings/mono/eo_mono/FunctionWrapper.cs +++ b/src/bindings/mono/eo_mono/FunctionWrapper.cs @@ -1,7 +1,11 @@ using System; using System.Runtime.InteropServices; -namespace Efl { namespace Eo { +namespace Efl +{ + +namespace Eo +{ ///Class to load functions pointers from a native module. /// @@ -51,14 +55,20 @@ public class FunctionWrapper // NOTE: When supporting C# >=7.3, add a where T private static FunctionLoadResult LazyInitialization(NativeModule module, string functionName) { if (module.Module == IntPtr.Zero) + { return new FunctionLoadResult(FunctionLoadResultKind.LibraryNotFound); + } else { IntPtr funcptr = FunctionInterop.LoadFunctionPointer(module.Module, functionName); if (funcptr == IntPtr.Zero) + { return new FunctionLoadResult(FunctionLoadResultKind.FunctionNotFound); + } else + { return new FunctionLoadResult(Marshal.GetDelegateForFunctionPointer(funcptr)); + } } } @@ -66,7 +76,7 @@ public class FunctionWrapper // NOTE: When supporting C# >=7.3, add a where T ///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) + : this(new NativeModule(moduleName), functionName) { } @@ -95,7 +105,8 @@ public class FunctionWrapper // NOTE: When supporting C# >=7.3, add a where T } ///The outcome of the function load process. -public enum FunctionLoadResultKind { +public enum FunctionLoadResultKind +{ ///Function was loaded successfully. Success, ///Library was not found. @@ -116,9 +127,13 @@ public class FunctionLoadResult ///Throws InvalidOperationException if trying to access while not loaded. public T Delegate { - get { + get + { if (_Delegate == null) + { throw new InvalidOperationException($"Trying to get Delegate while not loaded. Load result: {Kind}"); + } + return _Delegate; } } @@ -139,4 +154,6 @@ public class FunctionLoadResult } } -} } +} + +} diff --git a/src/bindings/mono/eo_mono/FunctionWrapper_Unix.cs b/src/bindings/mono/eo_mono/FunctionWrapper_Unix.cs index 845f8239e0..13a3cac865 100644 --- a/src/bindings/mono/eo_mono/FunctionWrapper_Unix.cs +++ b/src/bindings/mono/eo_mono/FunctionWrapper_Unix.cs @@ -1,7 +1,11 @@ using System; using System.Runtime.InteropServices; -namespace Efl { namespace Eo { +namespace Efl +{ + +namespace Eo +{ public partial class FunctionInterop { @@ -21,4 +25,6 @@ public partial class FunctionInterop } } -} } +} + +} diff --git a/src/bindings/mono/eo_mono/FunctionWrapper_Windows.cs b/src/bindings/mono/eo_mono/FunctionWrapper_Windows.cs index 3cdd80cf2f..dcf2091b71 100644 --- a/src/bindings/mono/eo_mono/FunctionWrapper_Windows.cs +++ b/src/bindings/mono/eo_mono/FunctionWrapper_Windows.cs @@ -1,7 +1,11 @@ using System; using System.Runtime.InteropServices; -namespace Efl { namespace Eo { +namespace Efl +{ + +namespace Eo +{ public partial class FunctionInterop { @@ -12,4 +16,6 @@ public partial class FunctionInterop => FunctionInterop.GetProcAddress(nativeLibraryHandle, functionName); } -} } +} + +} diff --git a/src/bindings/mono/eo_mono/NativeModule.cs b/src/bindings/mono/eo_mono/NativeModule.cs index 400f24fb87..41f663e282 100644 --- a/src/bindings/mono/eo_mono/NativeModule.cs +++ b/src/bindings/mono/eo_mono/NativeModule.cs @@ -1,6 +1,10 @@ using System; -namespace Efl { namespace Eo { +namespace Efl +{ + +namespace Eo +{ ///Wraps a native module that was opened with dlopen/LoadLibrary. public partial class NativeModule : IDisposable @@ -35,4 +39,6 @@ public partial class NativeModule : IDisposable } } -} } +} + +} diff --git a/src/bindings/mono/eo_mono/NativeModule_Unix.cs b/src/bindings/mono/eo_mono/NativeModule_Unix.cs index 8783895b14..e63b9ba111 100644 --- a/src/bindings/mono/eo_mono/NativeModule_Unix.cs +++ b/src/bindings/mono/eo_mono/NativeModule_Unix.cs @@ -1,7 +1,11 @@ using System; using System.Runtime.InteropServices; -namespace Efl { namespace Eo { +namespace Efl +{ + +namespace Eo +{ public partial class NativeModule { @@ -60,11 +64,11 @@ public partial class NativeModule } } } + return r; } } +} - - -} } +} diff --git a/src/bindings/mono/eo_mono/NativeModule_Windows.cs b/src/bindings/mono/eo_mono/NativeModule_Windows.cs index 889adc0949..1db8340cba 100644 --- a/src/bindings/mono/eo_mono/NativeModule_Windows.cs +++ b/src/bindings/mono/eo_mono/NativeModule_Windows.cs @@ -1,7 +1,11 @@ using System; using System.Runtime.InteropServices; -namespace Efl { namespace Eo { +namespace Efl +{ + +namespace Eo +{ public class partial NativeModule { @@ -9,7 +13,6 @@ public class partial NativeModule public static extern IntPtr LoadLibrary(string libFilename); } +} - - -} } +} diff --git a/src/bindings/mono/eo_mono/iwrapper.cs b/src/bindings/mono/eo_mono/iwrapper.cs index 3120dbbbf7..43835aabd7 100644 --- a/src/bindings/mono/eo_mono/iwrapper.cs +++ b/src/bindings/mono/eo_mono/iwrapper.cs @@ -9,12 +9,17 @@ using System.Threading; using static Eina.NativeCustomExportFunctions; using EoG = Efl.Eo.Globals; -namespace Efl { namespace Eo { +namespace Efl +{ -public class Globals { +namespace Eo +{ +public class Globals +{ /// Represents the type of the native Efl_Class. - public enum EflClassType { + public enum EflClassType + { /// Regular EFL classes. Regular = 0, /// Non-instantiable efl classes (i.e. Abstracts). @@ -175,27 +180,27 @@ public class Globals { [DllImport(efl.Libs.Evil)] public static extern IntPtr dlerror(); public delegate bool efl_event_callback_priority_add_delegate( - System.IntPtr obj, - IntPtr desc, - short priority, - Efl.EventCb cb, - System.IntPtr data); + System.IntPtr obj, + IntPtr desc, + short priority, + Efl.EventCb cb, + System.IntPtr data); [DllImport(efl.Libs.Eo)] public static extern bool efl_event_callback_priority_add( - System.IntPtr obj, - IntPtr desc, - short priority, - Efl.EventCb cb, - System.IntPtr data); + System.IntPtr obj, + IntPtr desc, + short priority, + Efl.EventCb cb, + System.IntPtr data); public delegate bool efl_event_callback_del_delegate( - System.IntPtr obj, - IntPtr desc, - Efl.EventCb cb, - System.IntPtr data); + System.IntPtr obj, + IntPtr desc, + Efl.EventCb cb, + System.IntPtr data); [DllImport(efl.Libs.Eo)] public static extern bool efl_event_callback_del( - System.IntPtr obj, - IntPtr desc, - Efl.EventCb cb, - System.IntPtr data); + System.IntPtr obj, + IntPtr desc, + Efl.EventCb cb, + System.IntPtr data); public const int RTLD_NOW = 2; @@ -205,14 +210,17 @@ public class Globals { { return v.Value; } + public static U GetParamHelper(U v) { return v; } + public static bool ParamHelperCheck(Nullable v) where T : struct { return v.HasValue; } + public static bool ParamHelperCheck(U v) { return v != null; @@ -230,9 +238,9 @@ public class Globals { description.class_destructor = IntPtr.Zero; class_initializer init = (IntPtr kls) => - { - return Globals.class_initializer_call(kls, type); - }; + { + return Globals.class_initializer_call(kls, type); + }; description.class_initializer = Marshal.GetFunctionPointerForDelegate(init); @@ -243,12 +251,18 @@ public class Globals { Eina.Log.Debug($"Going to register new class named {class_name}"); IntPtr klass = EoG.call_efl_class_new(description_ptr, base_klass, interface_list); - if(klass == IntPtr.Zero) + if (klass == IntPtr.Zero) + { Eina.Log.Error("klass was not registered"); + } else + { Eina.Log.Debug("Registered class successfully"); + } + return klass; } + public static List get_efl_interfaces(System.Type type) { System.Type base_type = type.BaseType; @@ -260,29 +274,35 @@ public class Globals { { if (!System.Array.Exists(base_ifaces, element => element == iface)) { - var attrs = System.Attribute.GetCustomAttributes(iface); - foreach (var attr in attrs) - { - if (attr is Efl.Eo.NativeClass) { - ifaces_lst.Add(((Efl.Eo.NativeClass)attr).GetEflClass()); - break; - } - } + var attrs = System.Attribute.GetCustomAttributes(iface); + foreach (var attr in attrs) + { + if (attr is Efl.Eo.NativeClass) + { + ifaces_lst.Add(((Efl.Eo.NativeClass)attr).GetEflClass()); + break; + } + } } } + return ifaces_lst; } + private static Efl.Eo.NativeClass get_native_class(System.Type type) { var attrs = System.Attribute.GetCustomAttributes(type); foreach (var attr in attrs) { - if (attr is Efl.Eo.NativeClass) { + if (attr is Efl.Eo.NativeClass) + { return (Efl.Eo.NativeClass)attr; } } + return null; } + public static byte class_initializer_call(IntPtr klass, System.Type type) { Eina.Log.Debug($"called with 0x{klass.ToInt64():x} {type}"); @@ -301,7 +321,7 @@ public class Globals { if (!System.Array.Exists(base_interfaces, element => element == iface)) { var nc = get_native_class(iface); - if(nc != null) + if (nc != null) { var moredescs = nc.GetEoOps(type); Eina.Log.Debug($"adding {moredescs.Count} more descs to registration"); @@ -311,13 +331,14 @@ public class Globals { } } - IntPtr descs_ptr = Marshal.AllocHGlobal(Marshal.SizeOf(descs[0])*count); + IntPtr descs_ptr = Marshal.AllocHGlobal(Marshal.SizeOf(descs[0]) * count); IntPtr ptr = descs_ptr; - for(int i = 0; i != count; ++i) + for (int i = 0; i != count; ++i) { Marshal.StructureToPtr(descs[i], ptr, false); ptr = IntPtr.Add(ptr, Marshal.SizeOf(descs[0])); } + Efl_Object_Ops ops; ops.descs = descs_ptr; ops.count = (UIntPtr)count; @@ -327,74 +348,80 @@ public class Globals { //EoKlass = klass; } else + { Eina.Log.Debug("nativeClass == null"); + } return 1; } + public static IntPtr call_efl_class_new(IntPtr desc, IntPtr bk, List il = null) { IntPtr nul = IntPtr.Zero; int iface_list_count = (il == null ? 0 : il.Count); - switch(iface_list_count) + switch (iface_list_count) { - default: return nul; - case 0: return EoG.efl_class_new(desc, bk, nul); - case 1: return EoG.efl_class_new(desc, bk, il[0], nul); - case 2: return EoG.efl_class_new(desc, bk, il[0], il[1], nul); - case 3: return EoG.efl_class_new(desc, bk, il[0], il[1], il[2], nul); - case 4: return EoG.efl_class_new(desc, bk, il[0], il[1], il[2], il[3], nul); - case 5: return EoG.efl_class_new(desc, bk, il[0], il[1], il[2], il[3], il[4], nul); - case 6: return EoG.efl_class_new(desc, bk, il[0], il[1], il[2], il[3], il[4], il[5], nul); - case 7: return EoG.efl_class_new(desc, bk, il[0], il[1], il[2], il[3], il[4], il[5], il[6], nul); - case 8: return EoG.efl_class_new(desc, bk, il[0], il[1], il[2], il[3], il[4], il[5], il[6], il[7], nul); - case 9: return EoG.efl_class_new(desc, bk, il[0], il[1], il[2], il[3], il[4], il[5], il[6], il[7], il[8], nul); - case 10: return EoG.efl_class_new(desc, bk, il[0], il[1], il[2], il[3], il[4], il[5], il[6], il[7], il[8], il[9], nul); - case 11: return EoG.efl_class_new(desc, bk, il[0], il[1], il[2], il[3], il[4], il[5], il[6], il[7], il[8], il[9], il[10], nul); - case 12: return EoG.efl_class_new(desc, bk, il[0], il[1], il[2], il[3], il[4], il[5], il[6], il[7], il[8], il[9], il[10], il[11], nul); - case 13: return EoG.efl_class_new(desc, bk, il[0], il[1], il[2], il[3], il[4], il[5], il[6], il[7], il[8], il[9], il[10], il[11], il[12], nul); - case 14: return EoG.efl_class_new(desc, bk, il[0], il[1], il[2], il[3], il[4], il[5], il[6], il[7], il[8], il[9], il[10], il[11], il[12], il[13], nul); - case 15: return EoG.efl_class_new(desc, bk, il[0], il[1], il[2], il[3], il[4], il[5], il[6], il[7], il[8], il[9], il[10], il[11], il[12], il[13], il[14], nul); - case 16: return EoG.efl_class_new(desc, bk, il[0], il[1], il[2], il[3], il[4], il[5], il[6], il[7], il[8], il[9], il[10], il[11], il[12], il[13], il[14], il[15], nul); - case 17: return EoG.efl_class_new(desc, bk, il[0], il[1], il[2], il[3], il[4], il[5], il[6], il[7], il[8], il[9], il[10], il[11], il[12], il[13], il[14], il[15], il[16], nul); - case 18: return EoG.efl_class_new(desc, bk, il[0], il[1], il[2], il[3], il[4], il[5], il[6], il[7], il[8], il[9], il[10], il[11], il[12], il[13], il[14], il[15], il[16], il[17], nul); - case 19: return EoG.efl_class_new(desc, bk, il[0], il[1], il[2], il[3], il[4], il[5], il[6], il[7], il[8], il[9], il[10], il[11], il[12], il[13], il[14], il[15], il[16], il[17], il[18], nul); - case 20: return EoG.efl_class_new(desc, bk, il[0], il[1], il[2], il[3], il[4], il[5], il[6], il[7], il[8], il[9], il[10], il[11], il[12], il[13], il[14], il[15], il[16], il[17], il[18], il[19], nul); - case 21: return EoG.efl_class_new(desc, bk, il[0], il[1], il[2], il[3], il[4], il[5], il[6], il[7], il[8], il[9], il[10], il[11], il[12], il[13], il[14], il[15], il[16], il[17], il[18], il[19], il[20], nul); - case 22: return EoG.efl_class_new(desc, bk, il[0], il[1], il[2], il[3], il[4], il[5], il[6], il[7], il[8], il[9], il[10], il[11], il[12], il[13], il[14], il[15], il[16], il[17], il[18], il[19], il[20], il[21], nul); - case 23: return EoG.efl_class_new(desc, bk, il[0], il[1], il[2], il[3], il[4], il[5], il[6], il[7], il[8], il[9], il[10], il[11], il[12], il[13], il[14], il[15], il[16], il[17], il[18], il[19], il[20], il[21], il[22], nul); - case 24: return EoG.efl_class_new(desc, bk, il[0], il[1], il[2], il[3], il[4], il[5], il[6], il[7], il[8], il[9], il[10], il[11], il[12], il[13], il[14], il[15], il[16], il[17], il[18], il[19], il[20], il[21], il[22], il[23], nul); - case 25: return EoG.efl_class_new(desc, bk, il[0], il[1], il[2], il[3], il[4], il[5], il[6], il[7], il[8], il[9], il[10], il[11], il[12], il[13], il[14], il[15], il[16], il[17], il[18], il[19], il[20], il[21], il[22], il[23], il[24], nul); - case 26: return EoG.efl_class_new(desc, bk, il[0], il[1], il[2], il[3], il[4], il[5], il[6], il[7], il[8], il[9], il[10], il[11], il[12], il[13], il[14], il[15], il[16], il[17], il[18], il[19], il[20], il[21], il[22], il[23], il[24], il[25], nul); - case 27: return EoG.efl_class_new(desc, bk, il[0], il[1], il[2], il[3], il[4], il[5], il[6], il[7], il[8], il[9], il[10], il[11], il[12], il[13], il[14], il[15], il[16], il[17], il[18], il[19], il[20], il[21], il[22], il[23], il[24], il[25], il[26], nul); - case 28: return EoG.efl_class_new(desc, bk, il[0], il[1], il[2], il[3], il[4], il[5], il[6], il[7], il[8], il[9], il[10], il[11], il[12], il[13], il[14], il[15], il[16], il[17], il[18], il[19], il[20], il[21], il[22], il[23], il[24], il[25], il[26], il[27], nul); - case 29: return EoG.efl_class_new(desc, bk, il[0], il[1], il[2], il[3], il[4], il[5], il[6], il[7], il[8], il[9], il[10], il[11], il[12], il[13], il[14], il[15], il[16], il[17], il[18], il[19], il[20], il[21], il[22], il[23], il[24], il[25], il[26], il[27], il[28], nul); - case 30: return EoG.efl_class_new(desc, bk, il[0], il[1], il[2], il[3], il[4], il[5], il[6], il[7], il[8], il[9], il[10], il[11], il[12], il[13], il[14], il[15], il[16], il[17], il[18], il[19], il[20], il[21], il[22], il[23], il[24], il[25], il[26], il[27], il[28], il[29], nul); - case 31: return EoG.efl_class_new(desc, bk, il[0], il[1], il[2], il[3], il[4], il[5], il[6], il[7], il[8], il[9], il[10], il[11], il[12], il[13], il[14], il[15], il[16], il[17], il[18], il[19], il[20], il[21], il[22], il[23], il[24], il[25], il[26], il[27], il[28], il[29], il[30], nul); - case 32: return EoG.efl_class_new(desc, bk, il[0], il[1], il[2], il[3], il[4], il[5], il[6], il[7], il[8], il[9], il[10], il[11], il[12], il[13], il[14], il[15], il[16], il[17], il[18], il[19], il[20], il[21], il[22], il[23], il[24], il[25], il[26], il[27], il[28], il[29], il[30], il[31], nul); - case 33: return EoG.efl_class_new(desc, bk, il[0], il[1], il[2], il[3], il[4], il[5], il[6], il[7], il[8], il[9], il[10], il[11], il[12], il[13], il[14], il[15], il[16], il[17], il[18], il[19], il[20], il[21], il[22], il[23], il[24], il[25], il[26], il[27], il[28], il[29], il[30], il[31], il[32], nul); - case 34: return EoG.efl_class_new(desc, bk, il[0], il[1], il[2], il[3], il[4], il[5], il[6], il[7], il[8], il[9], il[10], il[11], il[12], il[13], il[14], il[15], il[16], il[17], il[18], il[19], il[20], il[21], il[22], il[23], il[24], il[25], il[26], il[27], il[28], il[29], il[30], il[31], il[32], il[33], nul); - case 35: return EoG.efl_class_new(desc, bk, il[0], il[1], il[2], il[3], il[4], il[5], il[6], il[7], il[8], il[9], il[10], il[11], il[12], il[13], il[14], il[15], il[16], il[17], il[18], il[19], il[20], il[21], il[22], il[23], il[24], il[25], il[26], il[27], il[28], il[29], il[30], il[31], il[32], il[33], il[34], nul); - case 36: return EoG.efl_class_new(desc, bk, il[0], il[1], il[2], il[3], il[4], il[5], il[6], il[7], il[8], il[9], il[10], il[11], il[12], il[13], il[14], il[15], il[16], il[17], il[18], il[19], il[20], il[21], il[22], il[23], il[24], il[25], il[26], il[27], il[28], il[29], il[30], il[31], il[32], il[33], il[34], il[35], nul); - case 37: return EoG.efl_class_new(desc, bk, il[0], il[1], il[2], il[3], il[4], il[5], il[6], il[7], il[8], il[9], il[10], il[11], il[12], il[13], il[14], il[15], il[16], il[17], il[18], il[19], il[20], il[21], il[22], il[23], il[24], il[25], il[26], il[27], il[28], il[29], il[30], il[31], il[32], il[33], il[34], il[35], il[36], nul); - case 38: return EoG.efl_class_new(desc, bk, il[0], il[1], il[2], il[3], il[4], il[5], il[6], il[7], il[8], il[9], il[10], il[11], il[12], il[13], il[14], il[15], il[16], il[17], il[18], il[19], il[20], il[21], il[22], il[23], il[24], il[25], il[26], il[27], il[28], il[29], il[30], il[31], il[32], il[33], il[34], il[35], il[36], il[37], nul); - case 39: return EoG.efl_class_new(desc, bk, il[0], il[1], il[2], il[3], il[4], il[5], il[6], il[7], il[8], il[9], il[10], il[11], il[12], il[13], il[14], il[15], il[16], il[17], il[18], il[19], il[20], il[21], il[22], il[23], il[24], il[25], il[26], il[27], il[28], il[29], il[30], il[31], il[32], il[33], il[34], il[35], il[36], il[37], il[38], nul); - case 40: return EoG.efl_class_new(desc, bk, il[0], il[1], il[2], il[3], il[4], il[5], il[6], il[7], il[8], il[9], il[10], il[11], il[12], il[13], il[14], il[15], il[16], il[17], il[18], il[19], il[20], il[21], il[22], il[23], il[24], il[25], il[26], il[27], il[28], il[29], il[30], il[31], il[32], il[33], il[34], il[35], il[36], il[37], il[38], il[39], nul); - case 41: return EoG.efl_class_new(desc, bk, il[0], il[1], il[2], il[3], il[4], il[5], il[6], il[7], il[8], il[9], il[10], il[11], il[12], il[13], il[14], il[15], il[16], il[17], il[18], il[19], il[20], il[21], il[22], il[23], il[24], il[25], il[26], il[27], il[28], il[29], il[30], il[31], il[32], il[33], il[34], il[35], il[36], il[37], il[38], il[39], il[40], nul); - case 42: return EoG.efl_class_new(desc, bk, il[0], il[1], il[2], il[3], il[4], il[5], il[6], il[7], il[8], il[9], il[10], il[11], il[12], il[13], il[14], il[15], il[16], il[17], il[18], il[19], il[20], il[21], il[22], il[23], il[24], il[25], il[26], il[27], il[28], il[29], il[30], il[31], il[32], il[33], il[34], il[35], il[36], il[37], il[38], il[39], il[40], il[41], nul); - case 43: return EoG.efl_class_new(desc, bk, il[0], il[1], il[2], il[3], il[4], il[5], il[6], il[7], il[8], il[9], il[10], il[11], il[12], il[13], il[14], il[15], il[16], il[17], il[18], il[19], il[20], il[21], il[22], il[23], il[24], il[25], il[26], il[27], il[28], il[29], il[30], il[31], il[32], il[33], il[34], il[35], il[36], il[37], il[38], il[39], il[40], il[41], il[42], nul); - case 44: return EoG.efl_class_new(desc, bk, il[0], il[1], il[2], il[3], il[4], il[5], il[6], il[7], il[8], il[9], il[10], il[11], il[12], il[13], il[14], il[15], il[16], il[17], il[18], il[19], il[20], il[21], il[22], il[23], il[24], il[25], il[26], il[27], il[28], il[29], il[30], il[31], il[32], il[33], il[34], il[35], il[36], il[37], il[38], il[39], il[40], il[41], il[42], il[43], nul); - case 45: return EoG.efl_class_new(desc, bk, il[0], il[1], il[2], il[3], il[4], il[5], il[6], il[7], il[8], il[9], il[10], il[11], il[12], il[13], il[14], il[15], il[16], il[17], il[18], il[19], il[20], il[21], il[22], il[23], il[24], il[25], il[26], il[27], il[28], il[29], il[30], il[31], il[32], il[33], il[34], il[35], il[36], il[37], il[38], il[39], il[40], il[41], il[42], il[43], il[44], nul); - case 46: return EoG.efl_class_new(desc, bk, il[0], il[1], il[2], il[3], il[4], il[5], il[6], il[7], il[8], il[9], il[10], il[11], il[12], il[13], il[14], il[15], il[16], il[17], il[18], il[19], il[20], il[21], il[22], il[23], il[24], il[25], il[26], il[27], il[28], il[29], il[30], il[31], il[32], il[33], il[34], il[35], il[36], il[37], il[38], il[39], il[40], il[41], il[42], il[43], il[44], il[45], nul); - case 47: return EoG.efl_class_new(desc, bk, il[0], il[1], il[2], il[3], il[4], il[5], il[6], il[7], il[8], il[9], il[10], il[11], il[12], il[13], il[14], il[15], il[16], il[17], il[18], il[19], il[20], il[21], il[22], il[23], il[24], il[25], il[26], il[27], il[28], il[29], il[30], il[31], il[32], il[33], il[34], il[35], il[36], il[37], il[38], il[39], il[40], il[41], il[42], il[43], il[44], il[45], il[46], nul); - case 48: return EoG.efl_class_new(desc, bk, il[0], il[1], il[2], il[3], il[4], il[5], il[6], il[7], il[8], il[9], il[10], il[11], il[12], il[13], il[14], il[15], il[16], il[17], il[18], il[19], il[20], il[21], il[22], il[23], il[24], il[25], il[26], il[27], il[28], il[29], il[30], il[31], il[32], il[33], il[34], il[35], il[36], il[37], il[38], il[39], il[40], il[41], il[42], il[43], il[44], il[45], il[46], il[47], nul); + default: return nul; + case 0: return EoG.efl_class_new(desc, bk, nul); + case 1: return EoG.efl_class_new(desc, bk, il[0], nul); + case 2: return EoG.efl_class_new(desc, bk, il[0], il[1], nul); + case 3: return EoG.efl_class_new(desc, bk, il[0], il[1], il[2], nul); + case 4: return EoG.efl_class_new(desc, bk, il[0], il[1], il[2], il[3], nul); + case 5: return EoG.efl_class_new(desc, bk, il[0], il[1], il[2], il[3], il[4], nul); + case 6: return EoG.efl_class_new(desc, bk, il[0], il[1], il[2], il[3], il[4], il[5], nul); + case 7: return EoG.efl_class_new(desc, bk, il[0], il[1], il[2], il[3], il[4], il[5], il[6], nul); + case 8: return EoG.efl_class_new(desc, bk, il[0], il[1], il[2], il[3], il[4], il[5], il[6], il[7], nul); + case 9: return EoG.efl_class_new(desc, bk, il[0], il[1], il[2], il[3], il[4], il[5], il[6], il[7], il[8], nul); + case 10: return EoG.efl_class_new(desc, bk, il[0], il[1], il[2], il[3], il[4], il[5], il[6], il[7], il[8], il[9], nul); + case 11: return EoG.efl_class_new(desc, bk, il[0], il[1], il[2], il[3], il[4], il[5], il[6], il[7], il[8], il[9], il[10], nul); + case 12: return EoG.efl_class_new(desc, bk, il[0], il[1], il[2], il[3], il[4], il[5], il[6], il[7], il[8], il[9], il[10], il[11], nul); + case 13: return EoG.efl_class_new(desc, bk, il[0], il[1], il[2], il[3], il[4], il[5], il[6], il[7], il[8], il[9], il[10], il[11], il[12], nul); + case 14: return EoG.efl_class_new(desc, bk, il[0], il[1], il[2], il[3], il[4], il[5], il[6], il[7], il[8], il[9], il[10], il[11], il[12], il[13], nul); + case 15: return EoG.efl_class_new(desc, bk, il[0], il[1], il[2], il[3], il[4], il[5], il[6], il[7], il[8], il[9], il[10], il[11], il[12], il[13], il[14], nul); + case 16: return EoG.efl_class_new(desc, bk, il[0], il[1], il[2], il[3], il[4], il[5], il[6], il[7], il[8], il[9], il[10], il[11], il[12], il[13], il[14], il[15], nul); + case 17: return EoG.efl_class_new(desc, bk, il[0], il[1], il[2], il[3], il[4], il[5], il[6], il[7], il[8], il[9], il[10], il[11], il[12], il[13], il[14], il[15], il[16], nul); + case 18: return EoG.efl_class_new(desc, bk, il[0], il[1], il[2], il[3], il[4], il[5], il[6], il[7], il[8], il[9], il[10], il[11], il[12], il[13], il[14], il[15], il[16], il[17], nul); + case 19: return EoG.efl_class_new(desc, bk, il[0], il[1], il[2], il[3], il[4], il[5], il[6], il[7], il[8], il[9], il[10], il[11], il[12], il[13], il[14], il[15], il[16], il[17], il[18], nul); + case 20: return EoG.efl_class_new(desc, bk, il[0], il[1], il[2], il[3], il[4], il[5], il[6], il[7], il[8], il[9], il[10], il[11], il[12], il[13], il[14], il[15], il[16], il[17], il[18], il[19], nul); + case 21: return EoG.efl_class_new(desc, bk, il[0], il[1], il[2], il[3], il[4], il[5], il[6], il[7], il[8], il[9], il[10], il[11], il[12], il[13], il[14], il[15], il[16], il[17], il[18], il[19], il[20], nul); + case 22: return EoG.efl_class_new(desc, bk, il[0], il[1], il[2], il[3], il[4], il[5], il[6], il[7], il[8], il[9], il[10], il[11], il[12], il[13], il[14], il[15], il[16], il[17], il[18], il[19], il[20], il[21], nul); + case 23: return EoG.efl_class_new(desc, bk, il[0], il[1], il[2], il[3], il[4], il[5], il[6], il[7], il[8], il[9], il[10], il[11], il[12], il[13], il[14], il[15], il[16], il[17], il[18], il[19], il[20], il[21], il[22], nul); + case 24: return EoG.efl_class_new(desc, bk, il[0], il[1], il[2], il[3], il[4], il[5], il[6], il[7], il[8], il[9], il[10], il[11], il[12], il[13], il[14], il[15], il[16], il[17], il[18], il[19], il[20], il[21], il[22], il[23], nul); + case 25: return EoG.efl_class_new(desc, bk, il[0], il[1], il[2], il[3], il[4], il[5], il[6], il[7], il[8], il[9], il[10], il[11], il[12], il[13], il[14], il[15], il[16], il[17], il[18], il[19], il[20], il[21], il[22], il[23], il[24], nul); + case 26: return EoG.efl_class_new(desc, bk, il[0], il[1], il[2], il[3], il[4], il[5], il[6], il[7], il[8], il[9], il[10], il[11], il[12], il[13], il[14], il[15], il[16], il[17], il[18], il[19], il[20], il[21], il[22], il[23], il[24], il[25], nul); + case 27: return EoG.efl_class_new(desc, bk, il[0], il[1], il[2], il[3], il[4], il[5], il[6], il[7], il[8], il[9], il[10], il[11], il[12], il[13], il[14], il[15], il[16], il[17], il[18], il[19], il[20], il[21], il[22], il[23], il[24], il[25], il[26], nul); + case 28: return EoG.efl_class_new(desc, bk, il[0], il[1], il[2], il[3], il[4], il[5], il[6], il[7], il[8], il[9], il[10], il[11], il[12], il[13], il[14], il[15], il[16], il[17], il[18], il[19], il[20], il[21], il[22], il[23], il[24], il[25], il[26], il[27], nul); + case 29: return EoG.efl_class_new(desc, bk, il[0], il[1], il[2], il[3], il[4], il[5], il[6], il[7], il[8], il[9], il[10], il[11], il[12], il[13], il[14], il[15], il[16], il[17], il[18], il[19], il[20], il[21], il[22], il[23], il[24], il[25], il[26], il[27], il[28], nul); + case 30: return EoG.efl_class_new(desc, bk, il[0], il[1], il[2], il[3], il[4], il[5], il[6], il[7], il[8], il[9], il[10], il[11], il[12], il[13], il[14], il[15], il[16], il[17], il[18], il[19], il[20], il[21], il[22], il[23], il[24], il[25], il[26], il[27], il[28], il[29], nul); + case 31: return EoG.efl_class_new(desc, bk, il[0], il[1], il[2], il[3], il[4], il[5], il[6], il[7], il[8], il[9], il[10], il[11], il[12], il[13], il[14], il[15], il[16], il[17], il[18], il[19], il[20], il[21], il[22], il[23], il[24], il[25], il[26], il[27], il[28], il[29], il[30], nul); + case 32: return EoG.efl_class_new(desc, bk, il[0], il[1], il[2], il[3], il[4], il[5], il[6], il[7], il[8], il[9], il[10], il[11], il[12], il[13], il[14], il[15], il[16], il[17], il[18], il[19], il[20], il[21], il[22], il[23], il[24], il[25], il[26], il[27], il[28], il[29], il[30], il[31], nul); + case 33: return EoG.efl_class_new(desc, bk, il[0], il[1], il[2], il[3], il[4], il[5], il[6], il[7], il[8], il[9], il[10], il[11], il[12], il[13], il[14], il[15], il[16], il[17], il[18], il[19], il[20], il[21], il[22], il[23], il[24], il[25], il[26], il[27], il[28], il[29], il[30], il[31], il[32], nul); + case 34: return EoG.efl_class_new(desc, bk, il[0], il[1], il[2], il[3], il[4], il[5], il[6], il[7], il[8], il[9], il[10], il[11], il[12], il[13], il[14], il[15], il[16], il[17], il[18], il[19], il[20], il[21], il[22], il[23], il[24], il[25], il[26], il[27], il[28], il[29], il[30], il[31], il[32], il[33], nul); + case 35: return EoG.efl_class_new(desc, bk, il[0], il[1], il[2], il[3], il[4], il[5], il[6], il[7], il[8], il[9], il[10], il[11], il[12], il[13], il[14], il[15], il[16], il[17], il[18], il[19], il[20], il[21], il[22], il[23], il[24], il[25], il[26], il[27], il[28], il[29], il[30], il[31], il[32], il[33], il[34], nul); + case 36: return EoG.efl_class_new(desc, bk, il[0], il[1], il[2], il[3], il[4], il[5], il[6], il[7], il[8], il[9], il[10], il[11], il[12], il[13], il[14], il[15], il[16], il[17], il[18], il[19], il[20], il[21], il[22], il[23], il[24], il[25], il[26], il[27], il[28], il[29], il[30], il[31], il[32], il[33], il[34], il[35], nul); + case 37: return EoG.efl_class_new(desc, bk, il[0], il[1], il[2], il[3], il[4], il[5], il[6], il[7], il[8], il[9], il[10], il[11], il[12], il[13], il[14], il[15], il[16], il[17], il[18], il[19], il[20], il[21], il[22], il[23], il[24], il[25], il[26], il[27], il[28], il[29], il[30], il[31], il[32], il[33], il[34], il[35], il[36], nul); + case 38: return EoG.efl_class_new(desc, bk, il[0], il[1], il[2], il[3], il[4], il[5], il[6], il[7], il[8], il[9], il[10], il[11], il[12], il[13], il[14], il[15], il[16], il[17], il[18], il[19], il[20], il[21], il[22], il[23], il[24], il[25], il[26], il[27], il[28], il[29], il[30], il[31], il[32], il[33], il[34], il[35], il[36], il[37], nul); + case 39: return EoG.efl_class_new(desc, bk, il[0], il[1], il[2], il[3], il[4], il[5], il[6], il[7], il[8], il[9], il[10], il[11], il[12], il[13], il[14], il[15], il[16], il[17], il[18], il[19], il[20], il[21], il[22], il[23], il[24], il[25], il[26], il[27], il[28], il[29], il[30], il[31], il[32], il[33], il[34], il[35], il[36], il[37], il[38], nul); + case 40: return EoG.efl_class_new(desc, bk, il[0], il[1], il[2], il[3], il[4], il[5], il[6], il[7], il[8], il[9], il[10], il[11], il[12], il[13], il[14], il[15], il[16], il[17], il[18], il[19], il[20], il[21], il[22], il[23], il[24], il[25], il[26], il[27], il[28], il[29], il[30], il[31], il[32], il[33], il[34], il[35], il[36], il[37], il[38], il[39], nul); + case 41: return EoG.efl_class_new(desc, bk, il[0], il[1], il[2], il[3], il[4], il[5], il[6], il[7], il[8], il[9], il[10], il[11], il[12], il[13], il[14], il[15], il[16], il[17], il[18], il[19], il[20], il[21], il[22], il[23], il[24], il[25], il[26], il[27], il[28], il[29], il[30], il[31], il[32], il[33], il[34], il[35], il[36], il[37], il[38], il[39], il[40], nul); + case 42: return EoG.efl_class_new(desc, bk, il[0], il[1], il[2], il[3], il[4], il[5], il[6], il[7], il[8], il[9], il[10], il[11], il[12], il[13], il[14], il[15], il[16], il[17], il[18], il[19], il[20], il[21], il[22], il[23], il[24], il[25], il[26], il[27], il[28], il[29], il[30], il[31], il[32], il[33], il[34], il[35], il[36], il[37], il[38], il[39], il[40], il[41], nul); + case 43: return EoG.efl_class_new(desc, bk, il[0], il[1], il[2], il[3], il[4], il[5], il[6], il[7], il[8], il[9], il[10], il[11], il[12], il[13], il[14], il[15], il[16], il[17], il[18], il[19], il[20], il[21], il[22], il[23], il[24], il[25], il[26], il[27], il[28], il[29], il[30], il[31], il[32], il[33], il[34], il[35], il[36], il[37], il[38], il[39], il[40], il[41], il[42], nul); + case 44: return EoG.efl_class_new(desc, bk, il[0], il[1], il[2], il[3], il[4], il[5], il[6], il[7], il[8], il[9], il[10], il[11], il[12], il[13], il[14], il[15], il[16], il[17], il[18], il[19], il[20], il[21], il[22], il[23], il[24], il[25], il[26], il[27], il[28], il[29], il[30], il[31], il[32], il[33], il[34], il[35], il[36], il[37], il[38], il[39], il[40], il[41], il[42], il[43], nul); + case 45: return EoG.efl_class_new(desc, bk, il[0], il[1], il[2], il[3], il[4], il[5], il[6], il[7], il[8], il[9], il[10], il[11], il[12], il[13], il[14], il[15], il[16], il[17], il[18], il[19], il[20], il[21], il[22], il[23], il[24], il[25], il[26], il[27], il[28], il[29], il[30], il[31], il[32], il[33], il[34], il[35], il[36], il[37], il[38], il[39], il[40], il[41], il[42], il[43], il[44], nul); + case 46: return EoG.efl_class_new(desc, bk, il[0], il[1], il[2], il[3], il[4], il[5], il[6], il[7], il[8], il[9], il[10], il[11], il[12], il[13], il[14], il[15], il[16], il[17], il[18], il[19], il[20], il[21], il[22], il[23], il[24], il[25], il[26], il[27], il[28], il[29], il[30], il[31], il[32], il[33], il[34], il[35], il[36], il[37], il[38], il[39], il[40], il[41], il[42], il[43], il[44], il[45], nul); + case 47: return EoG.efl_class_new(desc, bk, il[0], il[1], il[2], il[3], il[4], il[5], il[6], il[7], il[8], il[9], il[10], il[11], il[12], il[13], il[14], il[15], il[16], il[17], il[18], il[19], il[20], il[21], il[22], il[23], il[24], il[25], il[26], il[27], il[28], il[29], il[30], il[31], il[32], il[33], il[34], il[35], il[36], il[37], il[38], il[39], il[40], il[41], il[42], il[43], il[44], il[45], il[46], nul); + case 48: return EoG.efl_class_new(desc, bk, il[0], il[1], il[2], il[3], il[4], il[5], il[6], il[7], il[8], il[9], il[10], il[11], il[12], il[13], il[14], il[15], il[16], il[17], il[18], il[19], il[20], il[21], il[22], il[23], il[24], il[25], il[26], il[27], il[28], il[29], il[30], il[31], il[32], il[33], il[34], il[35], il[36], il[37], il[38], il[39], il[40], il[41], il[42], il[43], il[44], il[45], il[46], il[47], nul); } } + public static IntPtr instantiate_start(IntPtr klass, Efl.Object parent) { Eina.Log.Debug($"Instantiating from klass 0x{klass.ToInt64():x}"); System.IntPtr parent_ptr = System.IntPtr.Zero; - if(parent != null) + if (parent != null) + { parent_ptr = parent.NativeHandle; + } System.IntPtr eo = Efl.Eo.Globals._efl_add_internal_start("file", 0, klass, parent_ptr, 1, 0); if (eo == System.IntPtr.Zero) @@ -407,38 +434,43 @@ public class Globals { return eo; } - public static IntPtr instantiate_end(IntPtr eo) { + public static IntPtr instantiate_end(IntPtr eo) + { Eina.Log.Debug("calling efl_add_internal_end"); eo = Efl.Eo.Globals._efl_add_end(eo, 1, 0); Eina.Log.Debug($"efl_add_end returned eo 0x{eo.ToInt64():x}"); return eo; } + public static void data_set(Efl.Eo.IWrapper obj) { - Eina.Log.Debug($"Calling data_scope_get with obj {obj.NativeHandle.ToInt64():x} and klass {obj.NativeClass.ToInt64():x}"); - IntPtr pd = Efl.Eo.Globals.efl_data_scope_get(obj.NativeHandle, obj.NativeClass); - { - GCHandle gch = GCHandle.Alloc(obj); - EolianPD epd; - epd.pointer = GCHandle.ToIntPtr(gch); - Marshal.StructureToPtr(epd, pd, false); - } + Eina.Log.Debug($"Calling data_scope_get with obj {obj.NativeHandle.ToInt64():x} and klass {obj.NativeClass.ToInt64():x}"); + IntPtr pd = Efl.Eo.Globals.efl_data_scope_get(obj.NativeHandle, obj.NativeClass); + { + GCHandle gch = GCHandle.Alloc(obj); + EolianPD epd; + epd.pointer = GCHandle.ToIntPtr(gch); + Marshal.StructureToPtr(epd, pd, false); + } } + public static Efl.Eo.IWrapper data_get(IntPtr pd) { EolianPD epd = (EolianPD)Marshal.PtrToStructure(pd, typeof(EolianPD)); - if(epd.pointer != IntPtr.Zero) + if (epd.pointer != IntPtr.Zero) { GCHandle gch = GCHandle.FromIntPtr(epd.pointer); return (Efl.Eo.IWrapper)gch.Target; } else + { return null; + } } public static void free_dict_values(Dictionary dict) { - foreach(IntPtr ptr in dict.Values) + foreach (IntPtr ptr in dict.Values) { Eina.MemoryNative.Free(ptr); } @@ -446,7 +478,7 @@ public class Globals { public static void free_stringshare_values(Dictionary dict) { - foreach(IntPtr ptr in dict.Values) + foreach (IntPtr ptr in dict.Values) { Eina.Stringshare.eina_stringshare_del(ptr); } @@ -467,36 +499,45 @@ public class Globals { // Flag to be passed to the cancell callback bool fulfilled = false; - future.Then((Eina.Value received) => { - lock (future) + future.Then((Eina.Value received) => + { + lock (future) + { + // Convert an failed Future to a failed Task. + if (received.GetValueType() == Eina.ValueType.Error) { - // Convert an failed Future to a failed Task. - if (received.GetValueType() == Eina.ValueType.Error) + Eina.Error err; + received.Get(out err); + if (err == Eina.Error.ECANCELED) { - Eina.Error err; - received.Get(out err); - if (err == Eina.Error.ECANCELED) - tcs.SetCanceled(); - else - tcs.TrySetException(new Efl.FutureException(received)); + tcs.SetCanceled(); } else { - // Will mark the returned task below as completed. - tcs.SetResult(received); + tcs.TrySetException(new Efl.FutureException(received)); } - fulfilled = true; - return received; } + else + { + // Will mark the returned task below as completed. + tcs.SetResult(received); + } + + fulfilled = true; + return received; + } }); // Callback to be called when the token is cancelled. - token.Register(() => { - lock (future) + token.Register(() => + { + lock (future) + { + // Will trigger the Then callback above with an Eina.Error + if (!fulfilled) { - // Will trigger the Then callback above with an Eina.Error - if (!fulfilled) - future.Cancel(); + future.Cancel(); } + } }); return tcs.Task; @@ -534,6 +575,7 @@ public interface IWrapper { get; } + /// Pointer to internal Eo class. IntPtr NativeClass { @@ -547,11 +589,14 @@ public static class ClassRegister { System.Type t; if (Efl.Eo.ClassRegister.typeFromKlass.TryGetValue(klass, out t)) + { return t; + } // If it isn't on the dictionary then it is a Native binding class IntPtr namePtr = Efl.Eo.Globals.efl_class_name_get(klass); - if (namePtr == IntPtr.Zero) { + if (namePtr == IntPtr.Zero) + { throw new System.InvalidOperationException($"Could not get Native class name. Handle: {klass}"); } @@ -574,16 +619,23 @@ public static class ClassRegister foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies()) { if (assembly == curr_asm) + { continue; + } t = assembly.GetType(name); if (t != null) + { break; + } } - if (t == null) { + + if (t == null) + { throw new System.InvalidOperationException($"Could not find the C# binding class for the EFL class: {name}"); } } + AddToKlassTypeBiDictionary(klass, t); // Cache it in the dictionary return t; } @@ -592,11 +644,14 @@ public static class ClassRegister { IntPtr klass; if (klassFromType.TryGetValue(objectType, out klass)) + { return klass; + } // Check if it is a Native binding class klass = GetNativeKlassPtr(objectType); - if (klass != IntPtr.Zero) { + if (klass != IntPtr.Zero) + { // Add to the dictionary cache AddToKlassTypeBiDictionary(klass, objectType); return klass; @@ -605,7 +660,10 @@ public static class ClassRegister // Unregistered Inherited class, let's register it IntPtr baseKlass = GetNativeBaseKlassPtr(objectType); if (baseKlass == IntPtr.Zero) + { throw new System.InvalidOperationException($"Could not get base C# binding class for Inherited type: {objectType.FullName}"); + } + return RegisterKlass(baseKlass, objectType); } @@ -613,18 +671,23 @@ public static class ClassRegister { IntPtr klass; if (klassFromType.TryGetValue(objectType, out klass)) + { return klass; + } return RegisterKlass(baseKlass, objectType); } private static IntPtr RegisterKlass(IntPtr baseKlass, System.Type objectType) { - lock (klassAllocLock) { + lock (klassAllocLock) + { IntPtr newKlass = Efl.Eo.Globals.register_class(objectType.FullName, baseKlass, objectType); - if (newKlass == IntPtr.Zero) { + if (newKlass == IntPtr.Zero) + { throw new System.InvalidOperationException($"Failed to register class '{objectType.FullName}'"); } + AddToKlassTypeBiDictionary(newKlass, objectType); return newKlass; } @@ -636,15 +699,20 @@ public static class ClassRegister { var ptr = GetNativeKlassPtr(t); if (ptr != IntPtr.Zero) + { return ptr; + } } + throw new System.InvalidOperationException($"Class '{objectType.FullName}' is not an Efl object"); } private static IntPtr GetNativeKlassPtr(System.Type objectType) { if (objectType == null) + { return IntPtr.Zero; + } if (objectType.IsInterface) { @@ -653,15 +721,20 @@ public static class ClassRegister objectType = assembly.GetType(objectType.FullName + "Concrete"); if (objectType == null) + { return IntPtr.Zero; + } } var method = objectType.GetMethod("GetEflClassStatic", System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic); if (method == null) + { return IntPtr.Zero; - return (IntPtr) (method.Invoke(null, null)); + } + + return (IntPtr)(method.Invoke(null, null)); } public static void AddToKlassTypeBiDictionary(IntPtr klassPtr, System.Type objectType) @@ -699,6 +772,7 @@ public class MarshalTest : ICustomMarshaler Eina.Log.Debug("MarshalTest.GetInstace cookie " + cookie); return new MarshalTest(); } + public void CleanUpManagedData(object ManagedObj) { //Eina.Log.Warning("MarshalTest.CleanUpManagedData not implemented"); @@ -723,7 +797,10 @@ public class MarshalTest : ICustomMarshaler Eina.Log.Debug("MarshalTest.MarshallManagedToNative"); var r = ((IWrapper)ManagedObj).NativeHandle; if (typeof(U) == typeof(OwnTag)) + { Efl.Eo.Globals.efl_ref(r); + } + return r; } @@ -731,9 +808,12 @@ public class MarshalTest : ICustomMarshaler { Eina.Log.Debug("MarshalTest.MarshalNativeToManaged"); if (typeof(U) != typeof(OwnTag)) + { Efl.Eo.Globals.efl_ref(pNativeData); + } + return Activator.CreateInstance(typeof(T), new System.Object[] {pNativeData}); -// return null; + //return null; } } @@ -745,6 +825,7 @@ public class MarshalEflClass : ICustomMarshaler Eina.Log.Debug("MarshalTest.GetInstance cookie " + cookie); return new MarshalEflClass(); } + public void CleanUpManagedData(object ManagedObj) { } @@ -763,8 +844,11 @@ public class MarshalEflClass : ICustomMarshaler { Eina.Log.Debug("MarshalTest.MarshallManagedToNative"); if (ManagedObj == null) + { return IntPtr.Zero; - var t = (System.Type) ManagedObj; + } + + var t = (System.Type)ManagedObj; return Efl.Eo.ClassRegister.GetKlass(t); } @@ -772,194 +856,255 @@ public class MarshalEflClass : ICustomMarshaler { Eina.Log.Debug("MarshalTest.MarshalNativeToManaged"); if (pNativeData == IntPtr.Zero) + { return null; + } + return Efl.Eo.ClassRegister.GetManagedType(pNativeData); } } -public class StringPassOwnershipMarshaler : ICustomMarshaler { - public object MarshalNativeToManaged(IntPtr pNativeData) { +public class StringPassOwnershipMarshaler : ICustomMarshaler +{ + public object MarshalNativeToManaged(IntPtr pNativeData) + { var ret = Eina.StringConversion.NativeUtf8ToManagedString(pNativeData); Eina.MemoryNative.Free(pNativeData); return ret; } - public IntPtr MarshalManagedToNative(object managedObj) { + public IntPtr MarshalManagedToNative(object managedObj) + { return Eina.MemoryNative.StrDup((string)managedObj); } - public void CleanUpNativeData(IntPtr pNativeData) { + public void CleanUpNativeData(IntPtr pNativeData) + { // No need to cleanup. C will take care of it. } - public void CleanUpManagedData(object managedObj) { + public void CleanUpManagedData(object managedObj) + { } - public int GetNativeDataSize() { + public int GetNativeDataSize() + { return -1; } - public static ICustomMarshaler GetInstance(string cookie) { - if (marshaler == null) { + public static ICustomMarshaler GetInstance(string cookie) + { + if (marshaler == null) + { marshaler = new StringPassOwnershipMarshaler(); } + return marshaler; } + static private StringPassOwnershipMarshaler marshaler; } -public class StringKeepOwnershipMarshaler: ICustomMarshaler { - public object MarshalNativeToManaged(IntPtr pNativeData) { +public class StringKeepOwnershipMarshaler: ICustomMarshaler +{ + public object MarshalNativeToManaged(IntPtr pNativeData) + { return Eina.StringConversion.NativeUtf8ToManagedString(pNativeData); } - public IntPtr MarshalManagedToNative(object managedObj) { + public IntPtr MarshalManagedToNative(object managedObj) + { return Eina.StringConversion.ManagedStringToNativeUtf8Alloc((string)managedObj); } - public void CleanUpNativeData(IntPtr pNativeData) { + public void CleanUpNativeData(IntPtr pNativeData) + { // No need to free. The Native side will keep the ownership. } - public void CleanUpManagedData(object managedObj) { + public void CleanUpManagedData(object managedObj) + { } - public int GetNativeDataSize() { + public int GetNativeDataSize() + { return -1; } - public static ICustomMarshaler GetInstance(string cookie) { - if (marshaler == null) { + public static ICustomMarshaler GetInstance(string cookie) + { + if (marshaler == null) + { marshaler = new StringKeepOwnershipMarshaler(); } + return marshaler; } + static private StringKeepOwnershipMarshaler marshaler; } -public class StringsharePassOwnershipMarshaler : ICustomMarshaler { - public object MarshalNativeToManaged(IntPtr pNativeData) { +public class StringsharePassOwnershipMarshaler : ICustomMarshaler +{ + public object MarshalNativeToManaged(IntPtr pNativeData) + { var ret = Eina.StringConversion.NativeUtf8ToManagedString(pNativeData); Eina.Stringshare.eina_stringshare_del(pNativeData); return ret; } - public IntPtr MarshalManagedToNative(object managedObj) { + public IntPtr MarshalManagedToNative(object managedObj) + { return Eina.Stringshare.eina_stringshare_add((string)managedObj); } - public void CleanUpNativeData(IntPtr pNativeData) { + public void CleanUpNativeData(IntPtr pNativeData) + { // No need to free as it's for own() parameters. } - public void CleanUpManagedData(object managedObj) { + public void CleanUpManagedData(object managedObj) + { } - public int GetNativeDataSize() { + public int GetNativeDataSize() + { return -1; } - public static ICustomMarshaler GetInstance(string cookie) { - if (marshaler == null) { + public static ICustomMarshaler GetInstance(string cookie) + { + if (marshaler == null) + { marshaler = new StringsharePassOwnershipMarshaler(); } + return marshaler; } + static private StringsharePassOwnershipMarshaler marshaler; } -public class StringshareKeepOwnershipMarshaler : ICustomMarshaler { - public object MarshalNativeToManaged(IntPtr pNativeData) { +public class StringshareKeepOwnershipMarshaler : ICustomMarshaler +{ + public object MarshalNativeToManaged(IntPtr pNativeData) + { return Eina.StringConversion.NativeUtf8ToManagedString(pNativeData); } - public IntPtr MarshalManagedToNative(object managedObj) { + public IntPtr MarshalManagedToNative(object managedObj) + { return Eina.Stringshare.eina_stringshare_add((string)managedObj); } - public void CleanUpNativeData(IntPtr pNativeData) { + public void CleanUpNativeData(IntPtr pNativeData) + { // No need to free, as the native side will keep ownership. } - public void CleanUpManagedData(object managedObj) { + public void CleanUpManagedData(object managedObj) + { } - public int GetNativeDataSize() { + public int GetNativeDataSize() + { return -1; } - public static ICustomMarshaler GetInstance(string cookie) { - if (marshaler == null) { + public static ICustomMarshaler GetInstance(string cookie) + { + if (marshaler == null) + { marshaler = new StringshareKeepOwnershipMarshaler(); } + return marshaler; } + static private StringshareKeepOwnershipMarshaler marshaler; } -public class StrbufPassOwnershipMarshaler : ICustomMarshaler { - public object MarshalNativeToManaged(IntPtr pNativeData) { +public class StrbufPassOwnershipMarshaler : ICustomMarshaler +{ + public object MarshalNativeToManaged(IntPtr pNativeData) + { return new Eina.Strbuf(pNativeData, Eina.Ownership.Managed); } - public IntPtr MarshalManagedToNative(object managedObj) { + public IntPtr MarshalManagedToNative(object managedObj) + { Eina.Strbuf buf = managedObj as Eina.Strbuf; buf.ReleaseOwnership(); return buf.Handle; } - public void CleanUpNativeData(IntPtr pNativeData) { + public void CleanUpNativeData(IntPtr pNativeData) + { // No need to cleanup. C will take care of it. } - public void CleanUpManagedData(object managedObj) { + public void CleanUpManagedData(object managedObj) + { } - public int GetNativeDataSize() { + public int GetNativeDataSize() + { return -1; } - public static ICustomMarshaler GetInstance(string cookie) { - if (marshaler == null) { + public static ICustomMarshaler GetInstance(string cookie) + { + if (marshaler == null) + { marshaler = new StrbufPassOwnershipMarshaler(); } + return marshaler; } + static private StrbufPassOwnershipMarshaler marshaler; } -public class StrbufKeepOwnershipMarshaler: ICustomMarshaler { - public object MarshalNativeToManaged(IntPtr pNativeData) { +public class StrbufKeepOwnershipMarshaler: ICustomMarshaler +{ + public object MarshalNativeToManaged(IntPtr pNativeData) + { return new Eina.Strbuf(pNativeData, Eina.Ownership.Unmanaged); } - public IntPtr MarshalManagedToNative(object managedObj) { + public IntPtr MarshalManagedToNative(object managedObj) + { Eina.Strbuf buf = managedObj as Eina.Strbuf; return buf.Handle; } - public void CleanUpNativeData(IntPtr pNativeData) { + public void CleanUpNativeData(IntPtr pNativeData) + { // No need to free. The Native side will keep the ownership. } - public void CleanUpManagedData(object managedObj) { + public void CleanUpManagedData(object managedObj) + { } - public int GetNativeDataSize() { + public int GetNativeDataSize() + { return -1; } - public static ICustomMarshaler GetInstance(string cookie) { - if (marshaler == null) { + public static ICustomMarshaler GetInstance(string cookie) + { + if (marshaler == null) + { marshaler = new StrbufKeepOwnershipMarshaler(); } + return marshaler; } + static private StrbufKeepOwnershipMarshaler marshaler; } - - } // namespace eo /// General exception for errors inside the binding. @@ -981,7 +1126,10 @@ public class FutureException : EflException public FutureException(Eina.Value value) : base("Future failed.") { if (value.GetValueType() != Eina.ValueType.Error) + { throw new ArgumentException("FutureException must receive an Eina.Value with Eina.Error."); + } + Eina.Error err; value.Get(out err); Error = err; diff --git a/src/bindings/mono/eo_mono/workaround.cs b/src/bindings/mono/eo_mono/workaround.cs index b1f9d9fea7..1ef9ef0aba 100644 --- a/src/bindings/mono/eo_mono/workaround.cs +++ b/src/bindings/mono/eo_mono/workaround.cs @@ -51,28 +51,35 @@ public struct EolianPD } #pragma warning disable 0169 + public struct EvasObjectBoxLayout { IntPtr o; IntPtr priv; IntPtr user_data; }; + [StructLayout(LayoutKind.Sequential, CharSet=CharSet.Ansi)] public struct EvasObjectBoxData { } -public struct EvasObjectBoxOption { + +public struct EvasObjectBoxOption +{ IntPtr obj; [MarshalAsAttribute(UnmanagedType.U1)] bool max_reached; [MarshalAsAttribute(UnmanagedType.U1)] bool min_reached; Evas.Coord alloc_size; }; + #pragma warning restore 0169 -namespace Efl { +namespace Efl +{ [StructLayout(LayoutKind.Sequential)] -public struct EventDescription { +public struct EventDescription +{ public IntPtr Name; [MarshalAs(UnmanagedType.U1)] public bool Unfreezable; [MarshalAs(UnmanagedType.U1)] public bool Legacy_is; @@ -94,12 +101,15 @@ public struct EventDescription { { IntPtr data = Efl.Eo.FunctionInterop.LoadFunctionPointer(module, name); - if (data == IntPtr.Zero) { + if (data == IntPtr.Zero) + { string error = Eina.StringConversion.NativeUtf8ToManagedString(Efl.Eo.Globals.dlerror()); throw new Exception(error); } + descriptions.Add(name, data); } + return descriptions[name]; } }; @@ -107,7 +117,8 @@ public struct EventDescription { public delegate void EventCb(System.IntPtr data, ref Event.NativeStruct evt); [StructLayout(LayoutKind.Sequential)] -public struct TextCursorCursor { +public struct TextCursorCursor +{ IntPtr obj; UIntPtr pos; // UIntPtr to automatically change size_t between 32/64 IntPtr node; @@ -115,7 +126,8 @@ public struct TextCursorCursor { } [StructLayout(LayoutKind.Sequential)] -public struct TextAnnotateAnnotation { +public struct TextAnnotateAnnotation +{ IntPtr list; IntPtr obj; IntPtr start_node; @@ -125,9 +137,11 @@ public struct TextAnnotateAnnotation { public delegate void SignalCb(IntPtr data, IntPtr obj, IntPtr emission, IntPtr source); -namespace Access { +namespace Access +{ -public struct ActionData { +public struct ActionData +{ public IntPtr name; public IntPtr action; public IntPtr param; @@ -138,16 +152,25 @@ public struct ActionData { } // namespace Efl -namespace Evas { +namespace Evas +{ -public struct Coord { +public struct Coord +{ int val; - public Coord(int value) { val = value; } - static public implicit operator Coord(int val) { + public Coord(int value) + { + val = value; + } + + static public implicit operator Coord(int val) + { return new Coord(val); } - static public implicit operator int(Coord coord) { + + static public implicit operator int(Coord coord) + { return coord.val; } } @@ -155,44 +178,44 @@ public struct Coord { /* Copied from Evas_Legacy.h */ public enum TextStyleType { - /// plain, standard text. - Plain = 0, - /// text with shadow underneath. - Shadow, - /// text with an outline. - Outline, - /// text with a soft outline. - SoftOutline, - /// text with a glow effect. - Glow, - /// text with both outline and shadow effects. - OutlineShadow, - /// text with (far) shadow underneath. - FarShadow, - /// text with outline and soft shadow effects combined. - OutlineSoftShadow, - /// text with (soft) shadow underneath. - SoftShadow, - /// text with (far soft) shadow underneath. - FarSoftShadow, + /// plain, standard text. + Plain = 0, + /// text with shadow underneath. + Shadow, + /// text with an outline. + Outline, + /// text with a soft outline. + SoftOutline, + /// text with a glow effect. + Glow, + /// text with both outline and shadow effects. + OutlineShadow, + /// text with (far) shadow underneath. + FarShadow, + /// text with outline and soft shadow effects combined. + OutlineSoftShadow, + /// text with (soft) shadow underneath. + SoftShadow, + /// text with (far soft) shadow underneath. + FarSoftShadow, - // Shadow direction modifiers - /// shadow growing to bottom right. - ShadowDirectionBottomRight = 0 /* 0 >> 4 */, - /// shadow growing to the bottom. - ShadowDirectionBottom= 16 /* 1 >> 4 */, - /// shadow growing to bottom left. - ShadowDirectionBottomLeft = 32 /* 2 >> 4 */, - /// shadow growing to the left. - ShadowDirectionLeft = 48 /* 3 >> 4 */, - /// shadow growing to top left. - ShadowDirectionTopLeft = 64 /* 4 >> 4 */, - /// shadow growing to the top. - ShadowDirectionTop = 80 /* 5 >> 4 */, - /// shadow growing to top right. - ShadowDirectionTopRight = 96 /* 6 >> 4 */, - /// shadow growing to the right. - ShadowDirectionRight = 112 /* 7 >> 4 */ + // Shadow direction modifiers + /// shadow growing to bottom right. + ShadowDirectionBottomRight = 0 /* 0 >> 4 */, + /// shadow growing to the bottom. + ShadowDirectionBottom = 16 /* 1 >> 4 */, + /// shadow growing to bottom left. + ShadowDirectionBottomLeft = 32 /* 2 >> 4 */, + /// shadow growing to the left. + ShadowDirectionLeft = 48 /* 3 >> 4 */, + /// shadow growing to top left. + ShadowDirectionTopLeft = 64 /* 4 >> 4 */, + /// shadow growing to the top. + ShadowDirectionTop = 80 /* 5 >> 4 */, + /// shadow growing to top right. + ShadowDirectionTopRight = 96 /* 6 >> 4 */, + /// shadow growing to the right. + ShadowDirectionRight = 112 /* 7 >> 4 */ }; } // namespace Evas @@ -201,8 +224,8 @@ public enum TextStyleType public delegate int Eina_Compare_Cb(IntPtr a, IntPtr b); public delegate void ElmInterfaceScrollableCb(IntPtr obj, IntPtr data); public delegate void ElmInterfaceScrollableMinLimitCb(IntPtr obj, - [MarshalAsAttribute(UnmanagedType.U1)]bool w, - [MarshalAsAttribute(UnmanagedType.U1)]bool h); + [MarshalAsAttribute(UnmanagedType.U1)]bool w, + [MarshalAsAttribute(UnmanagedType.U1)]bool h); public delegate void ElmInterfaceScrollableResizeCb(IntPtr obj, Evas.Coord w, Evas.Coord h); [return: MarshalAsAttribute(UnmanagedType.U1)] public delegate bool ElmMultibuttonentryItemFilterCb(IntPtr obj, IntPtr item_label, IntPtr item_data, IntPtr data);