mono: fix space and brace warnings of StyleCop

Summary:
The following warning rules of StyleCop are checked.
Space rules  : SA1000, SA1003, SA1008, SA1009, SA1010, SA1011
Brace rules  : SA1500, SA1501, SA1502, SA1503, SA1513

Indentation is also applied.

Reviewers: lauromoura, felipealmeida, vitor.sousa, woohyun

Reviewed By: vitor.sousa

Subscribers: cedric, #reviewers, #committers

Tags: #efl

Differential Revision: https://phab.enlightenment.org/D8485
This commit is contained in:
Jaehyun Cho 2019-04-02 16:51:05 +02:00 committed by Xavi Artigas
parent 731db8b644
commit 0d37e8ff49
36 changed files with 1938 additions and 609 deletions

View File

@ -6,10 +6,11 @@ using System.Threading;
using static Efl.UnsafeNativeMethods; using static Efl.UnsafeNativeMethods;
namespace Efl { namespace Efl
{
static class UnsafeNativeMethods {
static class UnsafeNativeMethods
{
private delegate void init_func_delegate(); 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_init();
[DllImport(efl.Libs.Ecore)] public static extern void ecore_shutdown(); [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_run();
[DllImport(efl.Libs.Elementary)] public static extern void elm_exit(); [DllImport(efl.Libs.Elementary)] public static extern void elm_exit();
static UnsafeNativeMethods() { static UnsafeNativeMethods()
{
_evas_init = new Efl.Eo.FunctionWrapper<init_func_delegate>("evas", "evas_init"); _evas_init = new Efl.Eo.FunctionWrapper<init_func_delegate>("evas", "evas_init");
} }
public static void evas_init() public static void evas_init()
{ {
_evas_init.Value.Delegate(); _evas_init.Value.Delegate();
} }
} }
public static class All { public static class All
{
private static bool InitializedUi = false; 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(); Eina.Config.Init();
Efl.Eo.Config.Init(); Efl.Eo.Config.Init();
ecore_init(); ecore_init();
evas_init(); evas_init();
eldbus.Config.Init(); eldbus.Config.Init();
if (components == Efl.Csharp.Components.Ui) { if (components == Efl.Csharp.Components.Ui)
{
Efl.Ui.Config.Init(); Efl.Ui.Config.Init();
InitializedUi = true; InitializedUi = true;
} }
} }
/// <summary>Shutdowns all EFL subsystems.</summary> /// <summary>Shutdowns all EFL subsystems.</summary>
public static void Shutdown() { public static void Shutdown()
{
// Try to cleanup everything before actually shutting down. // Try to cleanup everything before actually shutting down.
System.GC.Collect(); System.GC.Collect();
System.GC.WaitForPendingFinalizers(); System.GC.WaitForPendingFinalizers();
if (InitializedUi) if (InitializedUi)
{
Efl.Ui.Config.Shutdown(); Efl.Ui.Config.Shutdown();
}
eldbus.Config.Shutdown(); eldbus.Config.Shutdown();
evas_shutdown(); evas_shutdown();
ecore_shutdown(); ecore_shutdown();
@ -69,29 +79,38 @@ public static class All {
} }
// Placeholder. Will move to elm_config.cs later // Placeholder. Will move to elm_config.cs later
namespace Ui { namespace Ui
{
public static class Config { public static class Config
public static void Init() { {
public static void Init()
{
// TODO Support elm command line arguments // TODO Support elm command line arguments
#if WIN32 // Not a native define, we define it in our build system #if WIN32 // Not a native define, we define it in our build system
// Ecore_Win32 uses OleInitialize, which requires single thread apartments // Ecore_Win32 uses OleInitialize, which requires single thread apartments
if (System.Threading.Thread.CurrentThread.GetApartmentState() != ApartmentState.STA) if (System.Threading.Thread.CurrentThread.GetApartmentState() != ApartmentState.STA)
{
throw new InvalidOperationException("UI Applications require STAThreadAttribute in Main()"); throw new InvalidOperationException("UI Applications require STAThreadAttribute in Main()");
}
#endif #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);
} }
public static void Shutdown() {
public static void Shutdown()
{
elm_shutdown(); elm_shutdown();
} }
public static void Run() { public static void Run()
{
elm_run(); elm_run();
} }
public static void Exit() { public static void Exit()
{
elm_exit(); elm_exit();
} }
} }

View File

@ -3,99 +3,131 @@ using System.Runtime.InteropServices;
using System.Threading; using System.Threading;
using static Efl.UnsafeNativeMethods; using static Efl.UnsafeNativeMethods;
namespace Efl { namespace Efl
namespace Csharp { {
///<summary>The components to be initialized.</summary>
public enum Components { namespace Csharp
///<summary>Basic components: Eina, Eo, Ecore, Evas and DBus.</summary> {
Basic,
///<summary>The same components of <see cref="Efl.Csharp.Components.Basic"/> and the Elementary widget toolkit.</summary> ///<summary>The components to be initialized.</summary>
Ui, public enum Components
} {
/// <summary> ///<summary>Basic components: Eina, Eo, Ecore, Evas and DBus.</summary>
/// This represents the entry point for the EFL framework Basic,
/// You can use this class to implement the 4 abstract methods which will then be called accordingly ///<summary>The same components of <see cref="Efl.Csharp.Components.Basic"/> and the Elementary widget toolkit.</summary>
/// All subsystems of efl are booted up correctly when the abstract methods of this class are called. Ui,
/// </summary> }
/// <remarks>
/// Calls to efl outside those efl-callbacks or outside the mainloop are not allowed and will lead to issues /// <summary>
/// </remarks> /// This represents the entry point for the EFL framework
/// <example> /// You can use this class to implement the 4 abstract methods which will then be called accordingly
/// UserApp is the class that implements the Application abstract /// All subsystems of efl are booted up correctly when the abstract methods of this class are called.
/// <code> /// </summary>
/// public static void Main() { /// <remarks>
/// UserApp editor = new UserApp(); /// Calls to efl outside those efl-callbacks or outside the mainloop are not allowed and will lead to issues
/// editor.Launch(editor); /// </remarks>
/// } /// <example>
/// </code> /// UserApp is the class that implements the Application abstract
/// </example> /// <code>
public abstract class Application { /// public static void Main()
//the initializied components /// {
private static Components initComponent; /// UserApp editor = new UserApp();
//what follows are 3 private functions to boot up the internals of efl /// editor.Launch(editor);
private static void Init(Efl.Csharp.Components component) { /// }
/// </code>
/// </example>
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(); Eina.Config.Init();
Efl.Eo.Config.Init(); Efl.Eo.Config.Init();
ecore_init(); ecore_init();
evas_init(); evas_init();
eldbus.Config.Init(); eldbus.Config.Init();
if (component == Components.Ui) { if (component == Components.Ui)
// TODO Support elm command line arguments {
#if WIN32 // Not a native define, we define it in our build system // TODO Support elm command line arguments
// Ecore_Win32 uses OleInitialize, which requires single thread apartments #if WIN32 // Not a native define, we define it in our build system
if (System.Threading.Thread.CurrentThread.GetApartmentState() != ApartmentState.STA) // Ecore_Win32 uses OleInitialize, which requires single thread apartments
throw new InvalidOperationException("UI Applications require STAThreadAttribute in Main()"); if (System.Threading.Thread.CurrentThread.GetApartmentState() != ApartmentState.STA)
{
throw new InvalidOperationException("UI Applications require STAThreadAttribute in Main()");
}
#endif #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; initComponent = component;
} }
private static void Shutdown() {
private static void Shutdown()
{
// Try to cleanup everything before actually shutting down. // Try to cleanup everything before actually shutting down.
System.GC.Collect(); System.GC.Collect();
System.GC.WaitForPendingFinalizers(); System.GC.WaitForPendingFinalizers();
if (initComponent == Components.Ui) { if (initComponent == Components.Ui)
elm_shutdown(); {
elm_shutdown();
} }
eldbus.Config.Shutdown(); eldbus.Config.Shutdown();
evas_shutdown(); evas_shutdown();
ecore_shutdown(); ecore_shutdown();
Efl.Eo.Config.Shutdown(); Efl.Eo.Config.Shutdown();
Eina.Config.Shutdown(); Eina.Config.Shutdown();
} }
/// <summary>
/// Called when the application is started. Arguments from the command line are passed here. /// <summary>
/// </summary> /// Called when the application is started. Arguments from the command line are passed here.
protected abstract void OnInitialize(Eina.Array<System.String> args); /// </summary>
/// <summary> protected abstract void OnInitialize(Eina.Array<System.String> args);
/// Arguments are passed here, Additional calls to this function may occure,
/// but then the initialization flag is set to false. /// <summary>
/// </summary> /// Arguments are passed here, Additional calls to this function may occure,
/// <remarks> /// but then the initialization flag is set to false.
/// When Initialize is true then OnInitialize is also called /// </summary>
/// </remarks> /// <remarks>
protected virtual void OnArguments(Efl.LoopArguments args) { } /// When Initialize is true then OnInitialize is also called
/// <summary> /// </remarks>
/// Called when the application is not going to be displayed, or is not used by a user for some time. protected virtual void OnArguments(Efl.LoopArguments args)
/// </summary> {
protected virtual void OnPause() { } }
/// <summary>
/// Called before an application is used again after a call to OnPause(). /// <summary>
/// </summary> /// Called when the application is not going to be displayed, or is not used by a user for some time.
protected virtual void OnResume() { } /// </summary>
/// <summary> protected virtual void OnPause()
/// Called before starting the shutdown of the application. {
/// </summary> }
protected virtual void OnTerminate() { }
/// <summary> /// <summary>
/// This function initializices everything in EFL and runs your application. /// Called before an application is used again after a call to OnPause().
/// This call will result in a call to OnInitialize(), which you application should override. /// </summary>
/// </summary> protected virtual void OnResume()
public void Launch(Efl.Csharp.Components components=Components.Ui) { {
}
/// <summary>
/// Called before starting the shutdown of the application.
/// </summary>
protected virtual void OnTerminate()
{
}
/// <summary>
/// This function initializices everything in EFL and runs your application.
/// This call will result in a call to OnInitialize(), which you application should override.
/// </summary>
public void Launch(Efl.Csharp.Components components = Components.Ui)
{
Init(components); Init(components);
Efl.App app = Efl.App.AppMain; Efl.App app = Efl.App.AppMain;
Eina.Array<String> command_line = new Eina.Array<String>(); Eina.Array<String> command_line = new Eina.Array<String>();
@ -103,26 +135,32 @@ namespace Efl {
#if EFL_BETA #if EFL_BETA
app.SetCommandArray(command_line); app.SetCommandArray(command_line);
#endif #endif
app.ArgumentsEvt += (object sender, LoopArgumentsEvt_Args evt) => { app.ArgumentsEvt += (object sender, LoopArgumentsEvt_Args evt) =>
if (evt.arg.Initialization) { {
OnInitialize(evt.arg.Argv); if (evt.arg.Initialization)
} {
OnArguments(evt.arg); OnInitialize(evt.arg.Argv);
}
OnArguments(evt.arg);
}; };
app.PauseEvt += (object sender, EventArgs e) => { app.PauseEvt += (object sender, EventArgs e) =>
OnPause(); {
OnPause();
}; };
app.ResumeEvt += (object sender, EventArgs e) => { app.ResumeEvt += (object sender, EventArgs e) =>
OnResume(); {
OnResume();
}; };
app.TerminateEvt += (object sender, EventArgs e) => { app.TerminateEvt += (object sender, EventArgs e) =>
OnTerminate(); {
OnTerminate();
}; };
app.Begin(); app.Begin();
Shutdown(); Shutdown();
}
} }
}
} }
}
}

View File

@ -7,7 +7,8 @@ using static Eina.TraitFunctions;
using static Eina.AccessorNativeFunctions; using static Eina.AccessorNativeFunctions;
namespace Eina { namespace Eina
{
internal class AccessorNativeFunctions internal class AccessorNativeFunctions
{ {
@ -43,7 +44,7 @@ public class Accessor<T> : IEnumerable<T>, IDisposable
/// <summary>Create a new accessor wrapping the given pointer.</summary> /// <summary>Create a new accessor wrapping the given pointer.</summary>
/// <param name="handle">The native handle to be wrapped.</param> /// <param name="handle">The native handle to be wrapped.</param>
/// <param name="owner">Whether this wrapper owns the native accessor.</param> /// <param name="owner">Whether this wrapper owns the native accessor.</param>
public Accessor(IntPtr handle, Ownership owner=Ownership.Managed) public Accessor(IntPtr handle, Ownership owner = Ownership.Managed)
{ {
Handle = handle; Handle = handle;
Ownership = owner; Ownership = owner;
@ -53,7 +54,7 @@ public class Accessor<T> : IEnumerable<T>, IDisposable
/// <param name="handle">The native handle to be wrapped.</param> /// <param name="handle">The native handle to be wrapped.</param>
/// <param name="own">Whether this wrapper owns the native accessor.</param> /// <param name="own">Whether this wrapper owns the native accessor.</param>
/// <param name="ownContent">For compatibility with other EFL# containers. Ignored in acessors.</param> /// <param name="ownContent">For compatibility with other EFL# containers. Ignored in acessors.</param>
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) : this(handle, own ? Ownership.Managed : Ownership.Unmanaged)
{ {
} }
@ -96,13 +97,16 @@ public class Accessor<T> : IEnumerable<T>, IDisposable
public IEnumerator<T> GetEnumerator() public IEnumerator<T> GetEnumerator()
{ {
if (Handle == IntPtr.Zero) if (Handle == IntPtr.Zero)
{
throw new ObjectDisposedException(base.GetType().Name); throw new ObjectDisposedException(base.GetType().Name);
}
IntPtr tmp = MemoryNative.Alloc(Marshal.SizeOf(typeof(IntPtr))); IntPtr tmp = MemoryNative.Alloc(Marshal.SizeOf(typeof(IntPtr)));
uint position = 0; uint position = 0;
try 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)); IntPtr data = (IntPtr)Marshal.PtrToStructure(tmp, typeof(IntPtr));
yield return Convert(data); yield return Convert(data);
@ -124,11 +128,12 @@ public class Accessor<T> : IEnumerable<T>, IDisposable
///<summary>Accessor for Inlists.</summary> ///<summary>Accessor for Inlists.</summary>
public class AccessorInList<T> : Accessor<T> public class AccessorInList<T> : Accessor<T>
{ {
/// <summary>Create a new accessor wrapping the given pointer.</summary> /// <summary>Create a new accessor wrapping the given pointer.</summary>
/// <param name="handle">The native handle to be wrapped.</param> /// <param name="handle">The native handle to be wrapped.</param>
/// <param name="own">Whether this wrapper owns the native accessor.</param> /// <param name="own">Whether this wrapper owns the native accessor.</param>
public AccessorInList(IntPtr handle, Ownership own): base(handle, own) {} public AccessorInList(IntPtr handle, Ownership own) : base(handle, own)
{
}
/// <summary>Convert the native data into managed. This is used when returning the data through a /// <summary>Convert the native data into managed. This is used when returning the data through a
/// <see cref="System.Collections.Generic.IEnumerator&lt;T&gt;"/>.</summary> /// <see cref="System.Collections.Generic.IEnumerator&lt;T&gt;"/>.</summary>
@ -146,7 +151,9 @@ public class AccessorInArray<T> : Accessor<T>
/// <summary>Create a new accessor wrapping the given pointer.</summary> /// <summary>Create a new accessor wrapping the given pointer.</summary>
/// <param name="handle">The native handle to be wrapped.</param> /// <param name="handle">The native handle to be wrapped.</param>
/// <param name="own">Whether this wrapper owns the native accessor.</param> /// <param name="own">Whether this wrapper owns the native accessor.</param>
public AccessorInArray(IntPtr handle, Ownership own): base(handle, own) {} public AccessorInArray(IntPtr handle, Ownership own) : base(handle, own)
{
}
/// <summary>Convert the native data into managed. This is used when returning the data through a /// <summary>Convert the native data into managed. This is used when returning the data through a
/// <see cref="System.Collections.Generic.IEnumerator&lt;T&gt;"/>.</summary> /// <see cref="System.Collections.Generic.IEnumerator&lt;T&gt;"/>.</summary>

View File

@ -7,7 +7,8 @@ using System.Collections.Generic;
using static Eina.TraitFunctions; using static Eina.TraitFunctions;
using static Eina.ArrayNativeFunctions; using static Eina.ArrayNativeFunctions;
namespace Eina { namespace Eina
{
public static class ArrayNativeFunctions public static class ArrayNativeFunctions
{ {
@ -64,7 +65,9 @@ public class Array<T> : IEnumerable<T>, IDisposable
Own = true; Own = true;
OwnContent = true; OwnContent = true;
if (Handle == IntPtr.Zero) if (Handle == IntPtr.Zero)
{
throw new SEHException("Could not alloc array"); throw new SEHException("Could not alloc array");
}
} }
internal bool InternalPush(IntPtr ele) internal bool InternalPush(IntPtr ele)
@ -131,19 +134,23 @@ public class Array<T> : IEnumerable<T>, IDisposable
IntPtr h = Handle; IntPtr h = Handle;
Handle = IntPtr.Zero; Handle = IntPtr.Zero;
if (h == IntPtr.Zero) if (h == IntPtr.Zero)
{
return; return;
}
if (OwnContent) if (OwnContent)
{ {
int len = (int)eina_array_count_custom_export_mono(h); 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<T>(eina_array_data_get_custom_export_mono(h, (uint)i)); NativeFree<T>(eina_array_data_get_custom_export_mono(h, (uint)i));
} }
} }
if (Own) if (Own)
{
eina_array_free(h); eina_array_free(h);
}
} }
public void Dispose() public void Dispose()
@ -169,7 +176,7 @@ public class Array<T> : IEnumerable<T>, IDisposable
if (OwnContent) if (OwnContent)
{ {
int len = Length; int len = Length;
for(int i = 0; i < len; ++i) for (int i = 0; i < len; ++i)
{ {
NativeFree<T>(InternalDataGet(i)); NativeFree<T>(InternalDataGet(i));
} }
@ -190,7 +197,7 @@ public class Array<T> : IEnumerable<T>, IDisposable
public int Count() 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) public void SetOwnership(bool ownAll)
@ -210,7 +217,10 @@ public class Array<T> : IEnumerable<T>, IDisposable
IntPtr ele = ManagedToNativeAlloc(val); IntPtr ele = ManagedToNativeAlloc(val);
var r = InternalPush(ele); var r = InternalPush(ele);
if (!r) if (!r)
{
NativeFree<T>(ele); NativeFree<T>(ele);
}
return r; return r;
} }
@ -218,7 +228,9 @@ public class Array<T> : IEnumerable<T>, IDisposable
// public void Add(T val) // public void Add(T val)
// { // {
// if (!Push(val)) // if (!Push(val))
// throw; // {
// throw;
// }
// } // }
public T Pop() public T Pop()
@ -226,7 +238,10 @@ public class Array<T> : IEnumerable<T>, IDisposable
IntPtr ele = InternalPop(); IntPtr ele = InternalPop();
var r = NativeToManaged<T>(ele); var r = NativeToManaged<T>(ele);
if (OwnContent && ele != IntPtr.Zero) if (OwnContent && ele != IntPtr.Zero)
{
NativeFree<T>(ele); NativeFree<T>(ele);
}
return r; return r;
} }
@ -245,7 +260,10 @@ public class Array<T> : IEnumerable<T>, IDisposable
{ {
IntPtr ele = InternalDataGet(idx); // TODO: check bondaries ?? IntPtr ele = InternalDataGet(idx); // TODO: check bondaries ??
if (OwnContent && ele != IntPtr.Zero) if (OwnContent && ele != IntPtr.Zero)
{
NativeFree<T>(ele); NativeFree<T>(ele);
}
ele = ManagedToNativeAlloc(val); ele = ManagedToNativeAlloc(val);
InternalDataSet(idx, ele); InternalDataSet(idx, ele);
} }
@ -266,18 +284,24 @@ public class Array<T> : IEnumerable<T>, IDisposable
{ {
int len = Length; int len = Length;
var managed = new T[len]; var managed = new T[len];
for(int i = 0; i < len; ++i) for (int i = 0; i < len; ++i)
{ {
managed[i] = DataGet(i); managed[i] = DataGet(i);
} }
return managed; return managed;
} }
public bool Append(T[] values) public bool Append(T[] values)
{ {
foreach(T v in values) foreach (T v in values)
{
if (!Push(v)) if (!Push(v))
{
return false; return false;
}
}
return true; return true;
} }
@ -290,7 +314,7 @@ public class Array<T> : IEnumerable<T>, IDisposable
public IEnumerator<T> GetEnumerator() public IEnumerator<T> GetEnumerator()
{ {
int len = Length; int len = Length;
for(int i = 0; i < len; ++i) for (int i = 0; i < len; ++i)
{ {
yield return DataGet(i); yield return DataGet(i);
} }

View File

@ -3,7 +3,8 @@
using System; using System;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
namespace Eina { namespace Eina
{
public class Binbuf : IDisposable public class Binbuf : IDisposable
{ {
@ -43,7 +44,7 @@ public class Binbuf : IDisposable
public int Length public int Length
{ {
get { return (int) GetLength(); } get { return (int)GetLength(); }
} }
private void InitNew() private void InitNew()
@ -51,7 +52,9 @@ public class Binbuf : IDisposable
Handle = eina_binbuf_new(); Handle = eina_binbuf_new();
Own = true; Own = true;
if (Handle == IntPtr.Zero) if (Handle == IntPtr.Zero)
{
throw new SEHException("Could not alloc binbuf"); throw new SEHException("Could not alloc binbuf");
}
} }
public Binbuf() public Binbuf()
@ -98,7 +101,8 @@ public class Binbuf : IDisposable
{ {
IntPtr h = Handle; IntPtr h = Handle;
Handle = IntPtr.Zero; Handle = IntPtr.Zero;
if (Own && h != IntPtr.Zero) { if (Own && h != IntPtr.Zero)
{
eina_binbuf_free(Handle); eina_binbuf_free(Handle);
} }
} }
@ -180,7 +184,9 @@ public class Binbuf : IDisposable
{ {
var ptr = eina_binbuf_string_get(Handle); var ptr = eina_binbuf_string_get(Handle);
if (ptr == IntPtr.Zero) if (ptr == IntPtr.Zero)
{
return null; return null;
}
var size = (int)(this.GetLength()); var size = (int)(this.GetLength());
byte[] mArray = new byte[size]; byte[] mArray = new byte[size];

View File

@ -6,6 +6,7 @@ using System.Runtime.InteropServices;
namespace Eina namespace Eina
{ {
namespace Callbacks namespace Callbacks
{ {
@ -41,7 +42,8 @@ internal static class NativeCustomExportFunctions
} }
/// <summary>Wrapper around native memory DllImport'd functions</summary> /// <summary>Wrapper around native memory DllImport'd functions</summary>
public static class MemoryNative { public static class MemoryNative
{
public static void Free(IntPtr ptr) public static void Free(IntPtr ptr)
{ {
NativeCustomExportFunctions.efl_mono_native_free(ptr); NativeCustomExportFunctions.efl_mono_native_free(ptr);
@ -122,7 +124,9 @@ public static class StringConversion
public static IntPtr ManagedStringToNativeUtf8Alloc(string managedString) public static IntPtr ManagedStringToNativeUtf8Alloc(string managedString)
{ {
if (managedString == null) if (managedString == null)
{
return IntPtr.Zero; return IntPtr.Zero;
}
byte[] strbuf = Encoding.UTF8.GetBytes(managedString); byte[] strbuf = Encoding.UTF8.GetBytes(managedString);
IntPtr native = MemoryNative.Alloc(strbuf.Length + 1); IntPtr native = MemoryNative.Alloc(strbuf.Length + 1);
@ -134,11 +138,15 @@ public static class StringConversion
public static string NativeUtf8ToManagedString(IntPtr pNativeData) public static string NativeUtf8ToManagedString(IntPtr pNativeData)
{ {
if (pNativeData == IntPtr.Zero) if (pNativeData == IntPtr.Zero)
{
return null; return null;
}
int len = 0; int len = 0;
while (Marshal.ReadByte(pNativeData, len) != 0) while (Marshal.ReadByte(pNativeData, len) != 0)
{
++len; ++len;
}
byte[] strbuf = new byte[len]; byte[] strbuf = new byte[len];
Marshal.Copy(pNativeData, strbuf, 0, strbuf.Length); Marshal.Copy(pNativeData, strbuf, 0, strbuf.Length);
@ -147,7 +155,8 @@ public static class StringConversion
} }
/// <summary>Enum to handle resource ownership between managed and unmanaged code.</summary> /// <summary>Enum to handle resource ownership between managed and unmanaged code.</summary>
public enum Ownership { public enum Ownership
{
/// <summary> The resource is owned by the managed code. It should free the handle on disposal.</summary> /// <summary> The resource is owned by the managed code. It should free the handle on disposal.</summary>
Managed, Managed,
/// <summary> The resource is owned by the unmanaged code. It won't be freed on disposal.</summary> /// <summary> The resource is owned by the unmanaged code. It won't be freed on disposal.</summary>

View File

@ -3,18 +3,24 @@
using System; using System;
using System.Runtime.InteropServices; 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_init();
[DllImport(efl.Libs.Eina)] private static extern int eina_shutdown(); [DllImport(efl.Libs.Eina)] private static extern int eina_shutdown();
public static void Init() { public static void Init()
{
if (eina_init() == 0) if (eina_init() == 0)
{
throw (new Efl.EflException("Failed to initialize Eina")); throw (new Efl.EflException("Failed to initialize Eina"));
}
} }
public static int Shutdown() { public static int Shutdown()
{
return eina_shutdown(); return eina_shutdown();
} }
@ -24,15 +30,15 @@ public class Config {
/// Wrapper class for pointers that need some cleanup afterwards /// Wrapper class for pointers that need some cleanup afterwards
/// like strings. /// like strings.
/// </summary> /// </summary>
public class DisposableIntPtr : IDisposable { public class DisposableIntPtr : IDisposable
{
public IntPtr Handle { get; set; } public IntPtr Handle { get; set; }
private bool ShouldFree; private bool ShouldFree;
private bool Disposed; private bool Disposed;
/// <summary>Wraps a new ptr what will be freed based on the /// <summary>Wraps a new ptr what will be freed based on the
/// value of shouldFree</summary> /// value of shouldFree</summary>
public DisposableIntPtr(IntPtr ptr, bool shouldFree=false) public DisposableIntPtr(IntPtr ptr, bool shouldFree = false)
{ {
Handle = ptr; Handle = ptr;
ShouldFree = shouldFree; ShouldFree = shouldFree;
@ -46,9 +52,11 @@ public class DisposableIntPtr : IDisposable {
protected virtual void Dispose(bool disposing) protected virtual void Dispose(bool disposing)
{ {
if (!Disposed && ShouldFree) { if (!Disposed && ShouldFree)
{
MemoryNative.Free(this.Handle); MemoryNative.Free(this.Handle);
} }
Disposed = true; Disposed = true;
} }
@ -57,4 +65,5 @@ public class DisposableIntPtr : IDisposable {
Dispose(false); Dispose(false);
} }
} }
} }

View File

@ -11,9 +11,15 @@ using static Eina.InarrayNativeFunctions;
using static Eina.InlistNativeFunctions; using static Eina.InlistNativeFunctions;
using static Eina.NativeCustomExportFunctions; using static Eina.NativeCustomExportFunctions;
namespace Eina { namespace Eina
{
public enum ElementType { NumericType, StringType, ObjectType }; public enum ElementType
{
NumericType,
StringType,
ObjectType
};
[StructLayout(LayoutKind.Sequential)] [StructLayout(LayoutKind.Sequential)]
public struct InlistMem public struct InlistMem
@ -82,13 +88,18 @@ public class StringElementTraits : IBaseElementTraits<string>
public void NativeFree(IntPtr nat) public void NativeFree(IntPtr nat)
{ {
if (nat != IntPtr.Zero) if (nat != IntPtr.Zero)
{
MemoryNative.Free(nat); MemoryNative.Free(nat);
}
} }
public void NativeFreeInlistNodeElement(IntPtr nat) public void NativeFreeInlistNodeElement(IntPtr nat)
{ {
if (nat == IntPtr.Zero) if (nat == IntPtr.Zero)
{
return; return;
}
var val = Marshal.PtrToStructure<IntPtr> var val = Marshal.PtrToStructure<IntPtr>
(nat + Marshal.SizeOf<InlistMem>()); (nat + Marshal.SizeOf<InlistMem>());
NativeFree(val); NativeFree(val);
@ -97,9 +108,15 @@ public class StringElementTraits : IBaseElementTraits<string>
public void NativeFreeInlistNode(IntPtr nat, bool freeElement) public void NativeFreeInlistNode(IntPtr nat, bool freeElement)
{ {
if (nat == IntPtr.Zero) if (nat == IntPtr.Zero)
{
return; return;
}
if (freeElement) if (freeElement)
{
NativeFreeInlistNodeElement(nat); NativeFreeInlistNodeElement(nat);
}
MemoryNative.Free(nat); MemoryNative.Free(nat);
} }
@ -115,7 +132,10 @@ public class StringElementTraits : IBaseElementTraits<string>
public string NativeToManaged(IntPtr nat) public string NativeToManaged(IntPtr nat)
{ {
if (nat == IntPtr.Zero) if (nat == IntPtr.Zero)
{
return default(string); return default(string);
}
return StringConversion.NativeUtf8ToManagedString(nat); return StringConversion.NativeUtf8ToManagedString(nat);
} }
@ -126,6 +146,7 @@ public class StringElementTraits : IBaseElementTraits<string>
Eina.Log.Error("Null pointer for Inlist node."); Eina.Log.Error("Null pointer for Inlist node.");
return default(string); return default(string);
} }
IntPtr ptr_location = nat + Marshal.SizeOf<InlistMem>(); IntPtr ptr_location = nat + Marshal.SizeOf<InlistMem>();
return NativeToManaged(Marshal.ReadIntPtr(ptr_location)); return NativeToManaged(Marshal.ReadIntPtr(ptr_location));
} }
@ -134,10 +155,16 @@ public class StringElementTraits : IBaseElementTraits<string>
public string NativeToManagedInplace(IntPtr nat) public string NativeToManagedInplace(IntPtr nat)
{ {
if (nat == IntPtr.Zero) if (nat == IntPtr.Zero)
{
return default(string); return default(string);
}
nat = Marshal.ReadIntPtr(nat); nat = Marshal.ReadIntPtr(nat);
if (nat == IntPtr.Zero) if (nat == IntPtr.Zero)
{
return default(string); return default(string);
}
return NativeToManaged(nat); return NativeToManaged(nat);
} }
@ -180,7 +207,10 @@ public class EflObjectElementTraits<T> : IBaseElementTraits<T>
{ {
IntPtr h = ((Efl.Eo.IWrapper)man).NativeHandle; IntPtr h = ((Efl.Eo.IWrapper)man).NativeHandle;
if (h == IntPtr.Zero) if (h == IntPtr.Zero)
{
return h; return h;
}
return Efl.Eo.Globals.efl_ref(h); return Efl.Eo.Globals.efl_ref(h);
} }
@ -204,19 +234,26 @@ public class EflObjectElementTraits<T> : IBaseElementTraits<T>
public void NativeFree(IntPtr nat) public void NativeFree(IntPtr nat)
{ {
if (nat != IntPtr.Zero) if (nat != IntPtr.Zero)
{
Efl.Eo.Globals.efl_unref(nat); Efl.Eo.Globals.efl_unref(nat);
}
} }
public void NativeFreeRef(IntPtr nat, bool unrefs) public void NativeFreeRef(IntPtr nat, bool unrefs)
{ {
if (unrefs) if (unrefs)
{
NativeFree(nat); NativeFree(nat);
}
} }
public void NativeFreeInlistNodeElement(IntPtr nat) public void NativeFreeInlistNodeElement(IntPtr nat)
{ {
if (nat == IntPtr.Zero) if (nat == IntPtr.Zero)
{
return; return;
}
var val = Marshal.PtrToStructure<IntPtr> var val = Marshal.PtrToStructure<IntPtr>
(nat + Marshal.SizeOf<InlistMem>()); (nat + Marshal.SizeOf<InlistMem>());
NativeFree(val); NativeFree(val);
@ -225,9 +262,15 @@ public class EflObjectElementTraits<T> : IBaseElementTraits<T>
public void NativeFreeInlistNode(IntPtr nat, bool freeElement) public void NativeFreeInlistNode(IntPtr nat, bool freeElement)
{ {
if (nat == IntPtr.Zero) if (nat == IntPtr.Zero)
{
return; return;
}
if (freeElement) if (freeElement)
{
NativeFreeInlistNodeElement(nat); NativeFreeInlistNodeElement(nat);
}
MemoryNative.Free(nat); MemoryNative.Free(nat);
} }
@ -243,14 +286,20 @@ public class EflObjectElementTraits<T> : IBaseElementTraits<T>
public T NativeToManaged(IntPtr nat) public T NativeToManaged(IntPtr nat)
{ {
if (nat == IntPtr.Zero) if (nat == IntPtr.Zero)
{
return default(T); 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) public T NativeToManagedRef(IntPtr nat)
{ {
if (nat == IntPtr.Zero) if (nat == IntPtr.Zero)
{
return default(T); return default(T);
}
return NativeToManaged(nat); return NativeToManaged(nat);
} }
@ -261,6 +310,7 @@ public class EflObjectElementTraits<T> : IBaseElementTraits<T>
Eina.Log.Error("Null pointer for Inlist node."); Eina.Log.Error("Null pointer for Inlist node.");
return default(T); return default(T);
} }
IntPtr ptr_location = nat + Marshal.SizeOf<InlistMem>(); IntPtr ptr_location = nat + Marshal.SizeOf<InlistMem>();
return NativeToManaged(Marshal.ReadIntPtr(ptr_location)); return NativeToManaged(Marshal.ReadIntPtr(ptr_location));
} }
@ -269,10 +319,16 @@ public class EflObjectElementTraits<T> : IBaseElementTraits<T>
public T NativeToManagedInplace(IntPtr nat) public T NativeToManagedInplace(IntPtr nat)
{ {
if (nat == IntPtr.Zero) if (nat == IntPtr.Zero)
{
return default(T); return default(T);
}
nat = Marshal.ReadIntPtr(nat); nat = Marshal.ReadIntPtr(nat);
if (nat == IntPtr.Zero) if (nat == IntPtr.Zero)
{
return default(T); return default(T);
}
return NativeToManaged(nat); return NativeToManaged(nat);
} }
@ -355,6 +411,7 @@ public abstract class PrimitiveElementTraits<T>
Eina.Log.Error("Null pointer on primitive/struct container."); Eina.Log.Error("Null pointer on primitive/struct container.");
return default(T); return default(T);
} }
return PrimitiveConversion.PointerToManaged<T>(nat); return PrimitiveConversion.PointerToManaged<T>(nat);
} }
@ -371,7 +428,7 @@ public abstract class PrimitiveElementTraits<T>
private int PrimitiveCompareCb(IntPtr ptr1, IntPtr ptr2) private int PrimitiveCompareCb(IntPtr ptr1, IntPtr ptr2)
{ {
var m1 = (IComparable) NativeToManaged(ptr1); var m1 = (IComparable)NativeToManaged(ptr1);
var m2 = NativeToManaged(ptr2); var m2 = NativeToManaged(ptr2);
return m1.CompareTo(m2); return m1.CompareTo(m2);
} }
@ -379,7 +436,10 @@ public abstract class PrimitiveElementTraits<T>
public IntPtr EinaCompareCb() public IntPtr EinaCompareCb()
{ {
if (dlgt == null) if (dlgt == null)
{
dlgt = new Eina_Compare_Cb(PrimitiveCompareCb); dlgt = new Eina_Compare_Cb(PrimitiveCompareCb);
}
return Marshal.GetFunctionPointerForDelegate(dlgt); return Marshal.GetFunctionPointerForDelegate(dlgt);
} }
@ -406,10 +466,16 @@ abstract public class Primitive32ElementTraits<T> : PrimitiveElementTraits<T>, I
public Primitive32ElementTraits() public Primitive32ElementTraits()
{ {
if (int32Traits == null) if (int32Traits == null)
{
if (typeof(T) == typeof(Int32)) // avoid infinite recursion if (typeof(T) == typeof(Int32)) // avoid infinite recursion
{
int32Traits = (IBaseElementTraits<Int32>)this; int32Traits = (IBaseElementTraits<Int32>)this;
}
else else
{
int32Traits = TraitFunctions.GetTypeTraits<Int32>(); int32Traits = TraitFunctions.GetTypeTraits<Int32>();
}
}
} }
public abstract void ManagedToNativeCopyTo(T man, IntPtr mem); public abstract void ManagedToNativeCopyTo(T man, IntPtr mem);
@ -438,10 +504,16 @@ abstract public class Primitive64ElementTraits<T> : PrimitiveElementTraits<T>, I
public Primitive64ElementTraits() public Primitive64ElementTraits()
{ {
if (int64Traits == null) if (int64Traits == null)
{
if (typeof(T) == typeof(Int64)) // avoid infinite recursion if (typeof(T) == typeof(Int64)) // avoid infinite recursion
{
int64Traits = (IBaseElementTraits<Int64>)this; int64Traits = (IBaseElementTraits<Int64>)this;
}
else else
{
int64Traits = TraitFunctions.GetTypeTraits<Int64>(); int64Traits = TraitFunctions.GetTypeTraits<Int64>();
}
}
} }
public abstract void ManagedToNativeCopyTo(T man, IntPtr mem); public abstract void ManagedToNativeCopyTo(T man, IntPtr mem);
@ -471,6 +543,7 @@ public class IntElementTraits : Primitive32ElementTraits<int>, IBaseElementTrait
arr[0] = man; arr[0] = man;
Marshal.Copy(arr, 0, mem, 1); Marshal.Copy(arr, 0, mem, 1);
} }
override public int NativeToManagedInlistNode(IntPtr nat) override public int NativeToManagedInlistNode(IntPtr nat)
{ {
if (nat == IntPtr.Zero) if (nat == IntPtr.Zero)
@ -478,6 +551,7 @@ public class IntElementTraits : Primitive32ElementTraits<int>, IBaseElementTrait
Eina.Log.Error("Null pointer for Inlist node."); Eina.Log.Error("Null pointer for Inlist node.");
return default(int); return default(int);
} }
IntPtr loc = nat + Marshal.SizeOf<InlistMem>(); IntPtr loc = nat + Marshal.SizeOf<InlistMem>();
var v = new int[1]; var v = new int[1];
Marshal.Copy(loc, v, 0, 1); Marshal.Copy(loc, v, 0, 1);
@ -493,6 +567,7 @@ public class CharElementTraits : Primitive32ElementTraits<char>, IBaseElementTra
arr[0] = man; arr[0] = man;
Marshal.Copy(arr, 0, mem, 1); Marshal.Copy(arr, 0, mem, 1);
} }
override public char NativeToManagedInlistNode(IntPtr nat) override public char NativeToManagedInlistNode(IntPtr nat)
{ {
if (nat == IntPtr.Zero) if (nat == IntPtr.Zero)
@ -500,12 +575,14 @@ public class CharElementTraits : Primitive32ElementTraits<char>, IBaseElementTra
Eina.Log.Error("Null pointer for Inlist node."); Eina.Log.Error("Null pointer for Inlist node.");
return default(char); return default(char);
} }
IntPtr loc = nat + Marshal.SizeOf<InlistMem>(); IntPtr loc = nat + Marshal.SizeOf<InlistMem>();
var v = new char[1]; var v = new char[1];
Marshal.Copy(loc, v, 0, 1); Marshal.Copy(loc, v, 0, 1);
return v[0]; return v[0];
} }
} }
public class LongElementTraits : Primitive64ElementTraits<long>, IBaseElementTraits<long> public class LongElementTraits : Primitive64ElementTraits<long>, IBaseElementTraits<long>
{ {
override public void ManagedToNativeCopyTo(long man, IntPtr mem) override public void ManagedToNativeCopyTo(long man, IntPtr mem)
@ -514,6 +591,7 @@ public class LongElementTraits : Primitive64ElementTraits<long>, IBaseElementTra
arr[0] = man; arr[0] = man;
Marshal.Copy(arr, 0, mem, 1); Marshal.Copy(arr, 0, mem, 1);
} }
override public long NativeToManagedInlistNode(IntPtr nat) override public long NativeToManagedInlistNode(IntPtr nat)
{ {
if (nat == IntPtr.Zero) if (nat == IntPtr.Zero)
@ -521,6 +599,7 @@ public class LongElementTraits : Primitive64ElementTraits<long>, IBaseElementTra
Eina.Log.Error("Null pointer for Inlist node."); Eina.Log.Error("Null pointer for Inlist node.");
return default(long); return default(long);
} }
IntPtr loc = nat + Marshal.SizeOf<InlistMem>(); IntPtr loc = nat + Marshal.SizeOf<InlistMem>();
var v = new long[1]; var v = new long[1];
Marshal.Copy(loc, v, 0, 1); Marshal.Copy(loc, v, 0, 1);
@ -536,6 +615,7 @@ public class ShortElementTraits : Primitive32ElementTraits<short>, IBaseElementT
arr[0] = man; arr[0] = man;
Marshal.Copy(arr, 0, mem, 1); Marshal.Copy(arr, 0, mem, 1);
} }
override public short NativeToManagedInlistNode(IntPtr nat) override public short NativeToManagedInlistNode(IntPtr nat)
{ {
if (nat == IntPtr.Zero) if (nat == IntPtr.Zero)
@ -543,6 +623,7 @@ public class ShortElementTraits : Primitive32ElementTraits<short>, IBaseElementT
Eina.Log.Error("Null pointer for Inlist node."); Eina.Log.Error("Null pointer for Inlist node.");
return default(short); return default(short);
} }
IntPtr loc = nat + Marshal.SizeOf<InlistMem>(); IntPtr loc = nat + Marshal.SizeOf<InlistMem>();
var v = new short[1]; var v = new short[1];
Marshal.Copy(loc, v, 0, 1); Marshal.Copy(loc, v, 0, 1);
@ -558,6 +639,7 @@ public class FloatElementTraits : Primitive32ElementTraits<float>, IBaseElementT
arr[0] = man; arr[0] = man;
Marshal.Copy(arr, 0, mem, 1); Marshal.Copy(arr, 0, mem, 1);
} }
override public float NativeToManagedInlistNode(IntPtr nat) override public float NativeToManagedInlistNode(IntPtr nat)
{ {
if (nat == IntPtr.Zero) if (nat == IntPtr.Zero)
@ -565,6 +647,7 @@ public class FloatElementTraits : Primitive32ElementTraits<float>, IBaseElementT
Eina.Log.Error("Null pointer for Inlist node."); Eina.Log.Error("Null pointer for Inlist node.");
return default(float); return default(float);
} }
IntPtr loc = nat + Marshal.SizeOf<InlistMem>(); IntPtr loc = nat + Marshal.SizeOf<InlistMem>();
var v = new float[1]; var v = new float[1];
Marshal.Copy(loc, v, 0, 1); Marshal.Copy(loc, v, 0, 1);
@ -580,6 +663,7 @@ public class DoubleElementTraits : Primitive64ElementTraits<double>, IBaseElemen
arr[0] = man; arr[0] = man;
Marshal.Copy(arr, 0, mem, 1); Marshal.Copy(arr, 0, mem, 1);
} }
override public double NativeToManagedInlistNode(IntPtr nat) override public double NativeToManagedInlistNode(IntPtr nat)
{ {
if (nat == IntPtr.Zero) if (nat == IntPtr.Zero)
@ -587,6 +671,7 @@ public class DoubleElementTraits : Primitive64ElementTraits<double>, IBaseElemen
Eina.Log.Error("Null pointer for Inlist node."); Eina.Log.Error("Null pointer for Inlist node.");
return default(double); return default(double);
} }
IntPtr loc = nat + Marshal.SizeOf<InlistMem>(); IntPtr loc = nat + Marshal.SizeOf<InlistMem>();
var v = new double[1]; var v = new double[1];
Marshal.Copy(loc, v, 0, 1); Marshal.Copy(loc, v, 0, 1);
@ -602,6 +687,7 @@ public class ByteElementTraits : Primitive32ElementTraits<byte>, IBaseElementTra
arr[0] = man; arr[0] = man;
Marshal.Copy(arr, 0, mem, 1); Marshal.Copy(arr, 0, mem, 1);
} }
override public byte NativeToManagedInlistNode(IntPtr nat) override public byte NativeToManagedInlistNode(IntPtr nat)
{ {
if (nat == IntPtr.Zero) if (nat == IntPtr.Zero)
@ -609,6 +695,7 @@ public class ByteElementTraits : Primitive32ElementTraits<byte>, IBaseElementTra
Eina.Log.Error("Null pointer for Inlist node."); Eina.Log.Error("Null pointer for Inlist node.");
return default(byte); return default(byte);
} }
IntPtr loc = nat + Marshal.SizeOf<InlistMem>(); IntPtr loc = nat + Marshal.SizeOf<InlistMem>();
var v = new byte[1]; var v = new byte[1];
Marshal.Copy(loc, v, 0, 1); Marshal.Copy(loc, v, 0, 1);
@ -631,11 +718,17 @@ public static class TraitFunctions
public static Eina.ElementType GetElementTypeCode(System.Type type) public static Eina.ElementType GetElementTypeCode(System.Type type)
{ {
if (IsEflObject(type)) if (IsEflObject(type))
{
return ElementType.ObjectType; return ElementType.ObjectType;
}
else if (IsString(type)) else if (IsString(type))
{
return ElementType.StringType; return ElementType.StringType;
}
else else
{
return ElementType.NumericType; return ElementType.NumericType;
}
} }
private static IDictionary<System.Type, object> register = new Dictionary<System.Type, object>(); private static IDictionary<System.Type, object> register = new Dictionary<System.Type, object>();
@ -643,7 +736,9 @@ public static class TraitFunctions
private static System.Type AsEflInstantiableType(System.Type type) private static System.Type AsEflInstantiableType(System.Type type)
{ {
if (!IsEflObject(type)) if (!IsEflObject(type))
{
return null; return null;
}
if (type.IsInterface) if (type.IsInterface)
{ {
@ -663,32 +758,55 @@ public static class TraitFunctions
{ {
System.Type concrete = AsEflInstantiableType(type); System.Type concrete = AsEflInstantiableType(type);
if (concrete == null || !type.IsAssignableFrom(concrete)) if (concrete == null || !type.IsAssignableFrom(concrete))
{
throw new Exception("Failed to get a suitable concrete class for this type."); throw new Exception("Failed to get a suitable concrete class for this type.");
}
traits = new EflObjectElementTraits<T>(concrete); traits = new EflObjectElementTraits<T>(concrete);
} }
else if (IsString(type)) else if (IsString(type))
{
traits = new StringElementTraits(); traits = new StringElementTraits();
}
else if (type.IsValueType) else if (type.IsValueType)
{ {
if (type == typeof(int)) if (type == typeof(int))
{
traits = new IntElementTraits(); traits = new IntElementTraits();
}
else if (type == typeof(char)) else if (type == typeof(char))
{
traits = new CharElementTraits(); traits = new CharElementTraits();
}
else if (type == typeof(long)) else if (type == typeof(long))
{
traits = new LongElementTraits(); traits = new LongElementTraits();
}
else if (type == typeof(short)) else if (type == typeof(short))
{
traits = new ShortElementTraits(); traits = new ShortElementTraits();
}
else if (type == typeof(float)) else if (type == typeof(float))
{
traits = new FloatElementTraits(); traits = new FloatElementTraits();
}
else if (type == typeof(double)) else if (type == typeof(double))
{
traits = new DoubleElementTraits(); traits = new DoubleElementTraits();
}
else if (type == typeof(byte)) else if (type == typeof(byte))
{
traits = new ByteElementTraits(); traits = new ByteElementTraits();
}
else else
{
throw new Exception("No traits registered for this type"); throw new Exception("No traits registered for this type");
}
} }
else else
{
throw new Exception("No traits registered for this type"); throw new Exception("No traits registered for this type");
}
register[type] = traits; register[type] = traits;
return traits; return traits;
@ -704,8 +822,11 @@ public static class TraitFunctions
{ {
object traits; object traits;
if (!register.TryGetValue(typeof(T), out traits)) if (!register.TryGetValue(typeof(T), out traits))
{
traits = RegisterTypeTraits<T>(); traits = RegisterTypeTraits<T>();
return (IBaseElementTraits<T>) traits; }
return (IBaseElementTraits<T>)traits;
} }
// // // //

View File

@ -3,7 +3,8 @@
using System; using System;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
namespace Eina { namespace Eina
{
public struct Error : IComparable<Error> public struct Error : IComparable<Error>
{ {
@ -21,19 +22,26 @@ public struct Error : IComparable<Error>
public static Error ENOENT = new Error(2); public static Error ENOENT = new Error(2);
public static Error ECANCELED = new Error(125); 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) static public implicit operator Error(int val)
{ {
return new Error(val); return new Error(val);
} }
static public implicit operator int(Error error) static public implicit operator int(Error error)
{ {
return error.code; return error.code;
} }
public int CompareTo(Error err) public int CompareTo(Error err)
{ {
return code.CompareTo(err.code); return code.CompareTo(err.code);
} }
public override string ToString() public override string ToString()
{ {
return "Eina.Error(" + code + ")"; return "Eina.Error(" + code + ")";
@ -80,7 +88,9 @@ public struct Error : IComparable<Error>
public static void Raise(Error e) public static void Raise(Error e)
{ {
if (e != 0) if (e != 0)
{
throw (new Efl.EflException(MsgGet(e))); throw (new Efl.EflException(MsgGet(e)));
}
} }
public static void Clear() public static void Clear()
@ -93,4 +103,5 @@ public struct Error : IComparable<Error>
return eina_error_msg_register(msg); return eina_error_msg_register(msg);
} }
} }
} }

View File

@ -137,8 +137,10 @@ public class Hash<TKey, TValue> : IEnumerable<KeyValuePair<TKey,TValue>>, IDi
public bool OwnKey {get; set;} public bool OwnKey {get; set;}
public bool OwnValue {get; set;} public bool OwnValue {get; set;}
public int Count { public int Count
get { {
get
{
return Population(); return Population();
} }
} }
@ -179,10 +181,14 @@ public class Hash<TKey, TValue> : IEnumerable<KeyValuePair<TKey,TValue>>, IDi
IntPtr h = Handle; IntPtr h = Handle;
Handle = IntPtr.Zero; Handle = IntPtr.Zero;
if (h == IntPtr.Zero) if (h == IntPtr.Zero)
{
return; return;
}
if (Own) if (Own)
{
eina_hash_free(h); eina_hash_free(h);
}
} }
public void Dispose() public void Dispose()
@ -218,7 +224,9 @@ public class Hash<TKey, TValue> : IEnumerable<KeyValuePair<TKey,TValue>>, IDi
OwnValue = ownValue; OwnValue = ownValue;
if (ownValue) if (ownValue)
{
eina_hash_free_cb_set(Handle, EinaFreeCb<TValue>()); eina_hash_free_cb_set(Handle, EinaFreeCb<TValue>());
}
} }
public void SetOwnership(bool ownAll) public void SetOwnership(bool ownAll)
@ -289,7 +297,9 @@ public class Hash<TKey, TValue> : IEnumerable<KeyValuePair<TKey,TValue>>, IDi
//NativeFreeRef<TKey>(nk); //NativeFreeRef<TKey>(nk);
FreeNativeIndirection<TKey>(gchnk, ForceRefKey<TKey>()); FreeNativeIndirection<TKey>(gchnk, ForceRefKey<TKey>());
if (found == IntPtr.Zero) if (found == IntPtr.Zero)
{
throw new KeyNotFoundException(); throw new KeyNotFoundException();
}
return NativeToManaged<TValue>(IndirectNative<TValue>(found, false)); return NativeToManaged<TValue>(IndirectNative<TValue>(found, false));
} }
@ -305,6 +315,7 @@ public class Hash<TKey, TValue> : IEnumerable<KeyValuePair<TKey,TValue>>, IDi
val = default(TValue); val = default(TValue);
return false; return false;
} }
val = NativeToManaged<TValue>(IndirectNative<TValue>(found, false)); val = NativeToManaged<TValue>(IndirectNative<TValue>(found, false));
return true; return true;
} }
@ -334,8 +345,12 @@ public class Hash<TKey, TValue> : IEnumerable<KeyValuePair<TKey,TValue>>, IDi
NativeFree<TValue>(nv); NativeFree<TValue>(nv);
return false; return false;
} }
if (OwnValue) if (OwnValue)
{
NativeFree<TValue>(old); NativeFree<TValue>(old);
}
return true; return true;
} }
@ -355,7 +370,7 @@ public class Hash<TKey, TValue> : IEnumerable<KeyValuePair<TKey,TValue>>, IDi
return GCHandle.ToIntPtr(gch); return GCHandle.ToIntPtr(gch);
} }
else if(IsEflObject(typeof(T)) && forceRef) else if (IsEflObject(typeof(T)) && forceRef)
{ {
GCHandle gch = GCHandle.Alloc(new byte[Marshal.SizeOf<IntPtr>()], GCHandleType.Pinned); GCHandle gch = GCHandle.Alloc(new byte[Marshal.SizeOf<IntPtr>()], GCHandleType.Pinned);
IntPtr pin = gch.AddrOfPinnedObject(); IntPtr pin = gch.AddrOfPinnedObject();
@ -369,6 +384,7 @@ public class Hash<TKey, TValue> : IEnumerable<KeyValuePair<TKey,TValue>>, IDi
return ManagedToNativeAlloc(value); return ManagedToNativeAlloc(value);
} }
} }
private static IntPtr GetNativePtr<T>(IntPtr gchptr, bool forceRef) private static IntPtr GetNativePtr<T>(IntPtr gchptr, bool forceRef)
{ {
if (forceRef) if (forceRef)
@ -383,6 +399,7 @@ public class Hash<TKey, TValue> : IEnumerable<KeyValuePair<TKey,TValue>>, IDi
return gchptr; return gchptr;
} }
} }
private static void FreeNativeIndirection<T>(IntPtr gchptr, bool forceRef) private static void FreeNativeIndirection<T>(IntPtr gchptr, bool forceRef)
{ {
if (forceRef) if (forceRef)
@ -416,7 +433,9 @@ public class Hash<TKey, TValue> : IEnumerable<KeyValuePair<TKey,TValue>>, IDi
FreeNativeIndirection<TKey>(gchnk, ForceRefKey<TKey>()); FreeNativeIndirection<TKey>(gchnk, ForceRefKey<TKey>());
FreeNativeIndirection<TValue>(gchnv, false); FreeNativeIndirection<TValue>(gchnv, false);
if (OwnValue || old != IntPtr.Zero) if (OwnValue || old != IntPtr.Zero)
{
NativeFree<TValue>(old); NativeFree<TValue>(old);
}
} }
public TValue this[TKey key] public TValue this[TKey key]
@ -494,4 +513,3 @@ public class Hash<TKey, TValue> : IEnumerable<KeyValuePair<TKey,TValue>>, IDi
} }
} }

View File

@ -7,7 +7,8 @@ using System.Collections.Generic;
using static Eina.TraitFunctions; using static Eina.TraitFunctions;
using static Eina.InarrayNativeFunctions; using static Eina.InarrayNativeFunctions;
namespace Eina { namespace Eina
{
public static class InarrayNativeFunctions public static class InarrayNativeFunctions
{ {
@ -86,7 +87,9 @@ public class Inarray<T> : IEnumerable<T>, IDisposable
Own = true; Own = true;
OwnContent = true; OwnContent = true;
if (Handle == IntPtr.Zero) if (Handle == IntPtr.Zero)
{
throw new SEHException("Could not alloc inarray"); throw new SEHException("Could not alloc inarray");
}
} }
public Inarray() public Inarray()
@ -123,19 +126,23 @@ public class Inarray<T> : IEnumerable<T>, IDisposable
IntPtr h = Handle; IntPtr h = Handle;
Handle = IntPtr.Zero; Handle = IntPtr.Zero;
if (h == IntPtr.Zero) if (h == IntPtr.Zero)
{
return; return;
}
if (OwnContent) if (OwnContent)
{ {
uint len = eina_inarray_count(h); uint len = eina_inarray_count(h);
for(uint i = 0; i < len; ++i) for (uint i = 0; i < len; ++i)
{ {
NativeFreeInplace<T>(eina_inarray_nth(h, i)); NativeFreeInplace<T>(eina_inarray_nth(h, i));
} }
} }
if (Own) if (Own)
{
eina_inarray_free(h); eina_inarray_free(h);
}
} }
public void Dispose() public void Dispose()
@ -176,7 +183,7 @@ public class Inarray<T> : IEnumerable<T>, IDisposable
public int Count() public int Count()
{ {
return (int) eina_inarray_count(Handle); return (int)eina_inarray_count(Handle);
} }
public void SetOwnership(bool ownAll) public void SetOwnership(bool ownAll)
@ -201,7 +208,10 @@ public class Inarray<T> : IEnumerable<T>, IDisposable
var r = eina_inarray_push(Handle, ind); var r = eina_inarray_push(Handle, ind);
if (r == -1) if (r == -1)
{
NativeFreeInplace<T>(ele); NativeFreeInplace<T>(ele);
}
ResidueFreeInplace<T>(ele); ResidueFreeInplace<T>(ele);
gch.Free(); gch.Free();
return r; return r;
@ -211,7 +221,9 @@ public class Inarray<T> : IEnumerable<T>, IDisposable
// public void Add(T val) // public void Add(T val)
// { // {
// if (!Push(val)) // if (!Push(val))
// throw; // {
// throw;
// }
// } // }
public T Pop() public T Pop()
@ -219,7 +231,10 @@ public class Inarray<T> : IEnumerable<T>, IDisposable
IntPtr ele = eina_inarray_pop(Handle); IntPtr ele = eina_inarray_pop(Handle);
var r = NativeToManagedInplace<T>(ele); var r = NativeToManagedInplace<T>(ele);
if (OwnContent && ele != IntPtr.Zero) if (OwnContent && ele != IntPtr.Zero)
{
NativeFreeInplace<T>(ele); NativeFreeInplace<T>(ele);
}
return r; return r;
} }
@ -244,7 +259,10 @@ public class Inarray<T> : IEnumerable<T>, IDisposable
var r = eina_inarray_insert_at(Handle, idx, ind); var r = eina_inarray_insert_at(Handle, idx, ind);
if (!r) if (!r)
{
NativeFreeInplace<T>(ele); NativeFreeInplace<T>(ele);
}
ResidueFreeInplace<T>(ele); ResidueFreeInplace<T>(ele);
return r; return r;
} }
@ -253,9 +271,15 @@ public class Inarray<T> : IEnumerable<T>, IDisposable
{ {
var old = eina_inarray_nth(Handle, idx); var old = eina_inarray_nth(Handle, idx);
if (old == IntPtr.Zero) if (old == IntPtr.Zero)
{
return false; return false;
}
if (OwnContent) if (OwnContent)
{
NativeFreeInplace<T>(old); NativeFreeInplace<T>(old);
}
var ele = IntPtr.Zero; var ele = IntPtr.Zero;
GCHandle gch = GCHandle.Alloc(ele, GCHandleType.Pinned); GCHandle gch = GCHandle.Alloc(ele, GCHandleType.Pinned);
IntPtr ind = gch.AddrOfPinnedObject(); IntPtr ind = gch.AddrOfPinnedObject();
@ -283,9 +307,14 @@ public class Inarray<T> : IEnumerable<T>, IDisposable
{ {
IntPtr ele = eina_inarray_nth(Handle, idx); IntPtr ele = eina_inarray_nth(Handle, idx);
if (ele == IntPtr.Zero) if (ele == IntPtr.Zero)
{
return false; return false;
}
if (OwnContent) if (OwnContent)
{
NativeFreeInplace<T>(ele); NativeFreeInplace<T>(ele);
}
return eina_inarray_remove_at(Handle, idx); return eina_inarray_remove_at(Handle, idx);
} }
@ -299,18 +328,24 @@ public class Inarray<T> : IEnumerable<T>, IDisposable
{ {
int len = Length; int len = Length;
var managed = new T[len]; var managed = new T[len];
for(int i = 0; i < len; ++i) for (int i = 0; i < len; ++i)
{ {
managed[i] = At(i); managed[i] = At(i);
} }
return managed; return managed;
} }
public bool Append(T[] values) public bool Append(T[] values)
{ {
foreach(T v in values) foreach (T v in values)
{
if (Push(v) == -1) if (Push(v) == -1)
{
return false; return false;
}
}
return true; return true;
} }
@ -327,7 +362,7 @@ public class Inarray<T> : IEnumerable<T>, IDisposable
public IEnumerator<T> GetEnumerator() public IEnumerator<T> GetEnumerator()
{ {
int len = Length; int len = Length;
for(int i = 0; i < len; ++i) for (int i = 0; i < len; ++i)
{ {
yield return At(i); yield return At(i);
} }

View File

@ -8,7 +8,8 @@ using static Eina.TraitFunctions;
using static Eina.InlistNativeFunctions; using static Eina.InlistNativeFunctions;
using Eina.Callbacks; using Eina.Callbacks;
namespace Eina { namespace Eina
{
public static class InlistNativeFunctions public static class InlistNativeFunctions
{ {
@ -111,11 +112,16 @@ public class Inlist<T> : IEnumerable<T>, IDisposable
private IntPtr InternalAt(int idx) private IntPtr InternalAt(int idx)
{ {
if (idx < 0) if (idx < 0)
{
return IntPtr.Zero; return IntPtr.Zero;
}
IntPtr curr = Handle; IntPtr curr = Handle;
for (int n = 0; n != idx && curr != IntPtr.Zero; ++n) for (int n = 0; n != idx && curr != IntPtr.Zero; ++n)
{
curr = InternalNext(curr); curr = InternalNext(curr);
}
return curr; return curr;
} }
@ -159,11 +165,13 @@ public class Inlist<T> : IEnumerable<T>, IDisposable
IntPtr h = Handle; IntPtr h = Handle;
Handle = IntPtr.Zero; Handle = IntPtr.Zero;
if (h == IntPtr.Zero) if (h == IntPtr.Zero)
{
return; return;
}
if (OwnContent) if (OwnContent)
{ {
for(IntPtr curr = h; curr != IntPtr.Zero; curr = InternalNext(curr)) for (IntPtr curr = h; curr != IntPtr.Zero; curr = InternalNext(curr))
{ {
NativeFreeInlistNodeElement<T>(curr); NativeFreeInlistNodeElement<T>(curr);
} }
@ -212,7 +220,7 @@ public class Inlist<T> : IEnumerable<T>, IDisposable
public int Count() public int Count()
{ {
return (int) eina_inlist_count(Handle); return (int)eina_inlist_count(Handle);
} }
public void Clean() public void Clean()
@ -248,7 +256,10 @@ public class Inlist<T> : IEnumerable<T>, IDisposable
{ {
IntPtr node = InternalAt(idx); IntPtr node = InternalAt(idx);
if (node == IntPtr.Zero) if (node == IntPtr.Zero)
{
throw new IndexOutOfRangeException(); throw new IndexOutOfRangeException();
}
return NativeToManagedInlistNode<T>(node); return NativeToManagedInlistNode<T>(node);
} }
@ -256,7 +267,9 @@ public class Inlist<T> : IEnumerable<T>, IDisposable
{ {
IntPtr old = InternalAt(idx); IntPtr old = InternalAt(idx);
if (old == IntPtr.Zero) if (old == IntPtr.Zero)
{
throw new IndexOutOfRangeException(); throw new IndexOutOfRangeException();
}
IntPtr new_node = ManagedToNativeAllocInlistNode(val); IntPtr new_node = ManagedToNativeAllocInlistNode(val);
@ -282,17 +295,20 @@ public class Inlist<T> : IEnumerable<T>, IDisposable
{ {
var managed = new T[Count()]; var managed = new T[Count()];
int i = 0; 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<T>(curr); managed[i] = NativeToManagedInlistNode<T>(curr);
} }
return managed; return managed;
} }
public void AppendArray(T[] values) public void AppendArray(T[] values)
{ {
foreach (T v in values) foreach (T v in values)
{
Append(v); Append(v);
}
} }
@ -303,7 +319,7 @@ public class Inlist<T> : IEnumerable<T>, IDisposable
public IEnumerator<T> GetEnumerator() public IEnumerator<T> GetEnumerator()
{ {
for(IntPtr curr = Handle; curr != IntPtr.Zero; curr = InternalNext(curr)) for (IntPtr curr = Handle; curr != IntPtr.Zero; curr = InternalNext(curr))
{ {
yield return NativeToManagedInlistNode<T>(curr); yield return NativeToManagedInlistNode<T>(curr);
} }

View File

@ -7,7 +7,8 @@ using System.Collections.Generic;
using static Eina.TraitFunctions; using static Eina.TraitFunctions;
using static Eina.IteratorNativeFunctions; using static Eina.IteratorNativeFunctions;
namespace Eina { namespace Eina
{
public static class IteratorNativeFunctions public static class IteratorNativeFunctions
{ {
@ -58,18 +59,22 @@ public class Iterator<T> : IEnumerable<T>, IDisposable
var h = Handle; var h = Handle;
Handle = IntPtr.Zero; Handle = IntPtr.Zero;
if (h == IntPtr.Zero) if (h == IntPtr.Zero)
{
return; return;
}
if (OwnContent) if (OwnContent)
{ {
for(IntPtr data; eina_iterator_next(h, out data);) for (IntPtr data; eina_iterator_next(h, out data);)
{ {
NativeFree<T>(data); NativeFree<T>(data);
} }
} }
if (Own) if (Own)
{
eina_iterator_free(h); eina_iterator_free(h);
}
} }
public void Dispose() public void Dispose()
@ -114,7 +119,9 @@ public class Iterator<T> : IEnumerable<T>, IDisposable
res = NativeToManaged<T>(data); res = NativeToManaged<T>(data);
if (OwnContent) if (OwnContent)
{
NativeFree<T>(data); NativeFree<T>(data);
}
return true; return true;
} }
@ -131,7 +138,7 @@ public class Iterator<T> : IEnumerable<T>, IDisposable
public IEnumerator<T> GetEnumerator() public IEnumerator<T> GetEnumerator()
{ {
for(T curr; Next(out curr);) for (T curr; Next(out curr);)
{ {
yield return curr; yield return curr;
} }

View File

@ -8,7 +8,8 @@ using static Eina.TraitFunctions;
using static Eina.ListNativeFunctions; using static Eina.ListNativeFunctions;
using Eina.Callbacks; using Eina.Callbacks;
namespace Eina { namespace Eina
{
public static class ListNativeFunctions public static class ListNativeFunctions
{ {
@ -175,18 +176,22 @@ public class List<T> : IEnumerable<T>, IDisposable
IntPtr h = Handle; IntPtr h = Handle;
Handle = IntPtr.Zero; Handle = IntPtr.Zero;
if (h == IntPtr.Zero) if (h == IntPtr.Zero)
{
return; return;
}
if (OwnContent) if (OwnContent)
{ {
for(IntPtr curr = h; curr != IntPtr.Zero; curr = InternalNext(curr)) for (IntPtr curr = h; curr != IntPtr.Zero; curr = InternalNext(curr))
{ {
NativeFree<T>(InternalDataGet(curr)); NativeFree<T>(InternalDataGet(curr));
} }
} }
if (Own) if (Own)
{
eina_list_free(h); eina_list_free(h);
}
} }
public void Dispose() public void Dispose()
@ -221,7 +226,7 @@ public class List<T> : IEnumerable<T>, IDisposable
public int Count() 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) public void Append(T val)
@ -274,9 +279,15 @@ public class List<T> : IEnumerable<T>, IDisposable
{ {
IntPtr pos = eina_list_nth_list(Handle, (uint)idx); IntPtr pos = eina_list_nth_list(Handle, (uint)idx);
if (pos == IntPtr.Zero) if (pos == IntPtr.Zero)
{
throw new IndexOutOfRangeException(); throw new IndexOutOfRangeException();
}
if (OwnContent) if (OwnContent)
{
NativeFree<T>(InternalDataGet(pos)); NativeFree<T>(InternalDataGet(pos));
}
IntPtr ele = ManagedToNativeAlloc(val); IntPtr ele = ManagedToNativeAlloc(val);
InternalDataSet(pos, ele); InternalDataSet(pos, ele);
} }
@ -314,17 +325,20 @@ public class List<T> : IEnumerable<T>, IDisposable
{ {
var managed = new T[Count()]; var managed = new T[Count()];
int i = 0; 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<T>(InternalDataGet(curr)); managed[i] = NativeToManaged<T>(InternalDataGet(curr));
} }
return managed; return managed;
} }
public void AppendArray(T[] values) public void AppendArray(T[] values)
{ {
foreach (T v in values) foreach (T v in values)
{
Append(v); Append(v);
}
} }
@ -340,7 +354,7 @@ public class List<T> : IEnumerable<T>, IDisposable
public IEnumerator<T> GetEnumerator() public IEnumerator<T> GetEnumerator()
{ {
for(IntPtr curr = Handle; curr != IntPtr.Zero; curr = InternalNext(curr)) for (IntPtr curr = Handle; curr != IntPtr.Zero; curr = InternalNext(curr))
{ {
yield return NativeToManaged<T>(InternalDataGet(curr)); yield return NativeToManaged<T>(InternalDataGet(curr));
} }

View File

@ -5,7 +5,9 @@ using System.Runtime.InteropServices;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using System.Diagnostics.Contracts; using System.Diagnostics.Contracts;
namespace Eina { // Manual wrappers around eina functions namespace Eina
{
// Manual wrappers around eina functions
public class Log public class Log
{ {
@ -55,44 +57,54 @@ public class Log
static Log() static Log()
{ {
const String name="mono"; const String name = "mono";
const String color="\033[32;1m"; const String color = "\033[32;1m";
// Maybe move this check outside when other eina stuff get support? // Maybe move this check outside when other eina stuff get support?
domain = eina_log_domain_register(name, color); domain = eina_log_domain_register(name, color);
if (domain < 0) 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 else
Info($"Registered mono domain with number {domain}"); {
Info($"Registered mono domain with number {domain}");
}
} }
private static void EnsureDomainRegistered() private static void EnsureDomainRegistered()
{ {
if (domain < 0) 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(); EnsureDomainRegistered();
eina_log_print(domain, Level.Critical, file, member, line, message); 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(); EnsureDomainRegistered();
eina_log_print(domain, Level.Error, file, member, line, message); 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(); EnsureDomainRegistered();
eina_log_print(domain, Level.Warning, file, member, line, message); 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(); EnsureDomainRegistered();
eina_log_print(domain, Level.Info, file, member, line, message); 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(); EnsureDomainRegistered();
eina_log_print(domain, Level.Debug, file, member, line, message); eina_log_print(domain, Level.Debug, file, member, line, message);
@ -108,4 +120,5 @@ public class Log
return eina_log_level_get(); return eina_log_level_get();
} }
} }
} }

View File

@ -6,9 +6,11 @@ using System.Linq;
using static Eina.EinaNative.PromiseNativeMethods; using static Eina.EinaNative.PromiseNativeMethods;
namespace Eina { namespace Eina
{
namespace EinaNative { namespace EinaNative
{
static internal class PromiseNativeMethods 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 /// 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). /// future callbacks will be called mainly from a loop iteration).
/// </summary> /// </summary>
public Promise(CancelCb cancelCb=null) public Promise(CancelCb cancelCb = null)
{ {
Efl.Loop loop = Efl.App.AppMain; Efl.Loop loop = Efl.App.AppMain;
@ -90,10 +92,13 @@ public class Promise : IDisposable
IntPtr cb_data = IntPtr.Zero; IntPtr cb_data = IntPtr.Zero;
// A safety clean callback to mark this wrapper as invalid // A safety clean callback to mark this wrapper as invalid
CancelCb safetyCb = () => { CancelCb safetyCb = () =>
{
Handle = IntPtr.Zero; Handle = IntPtr.Zero;
if (cancelCb != null) if (cancelCb != null)
{
cancelCb(); cancelCb();
}
}; };
CleanupHandle = GCHandle.Alloc(safetyCb); CleanupHandle = GCHandle.Alloc(safetyCb);
@ -105,14 +110,21 @@ public class Promise : IDisposable
private static void NativeCancelCb(IntPtr data, IntPtr dead) private static void NativeCancelCb(IntPtr data, IntPtr dead)
{ {
if (data == IntPtr.Zero) if (data == IntPtr.Zero)
{
return; return;
}
GCHandle handle = GCHandle.FromIntPtr(data); GCHandle handle = GCHandle.FromIntPtr(data);
CancelCb cb = handle.Target as CancelCb; CancelCb cb = handle.Target as CancelCb;
if (cb != null) if (cb != null)
{
cb(); cb();
}
else else
{
Eina.Log.Info("Null promise CancelCb found"); Eina.Log.Info("Null promise CancelCb found");
}
handle.Free(); handle.Free();
} }
@ -144,7 +156,9 @@ public class Promise : IDisposable
private void SanityChecks() private void SanityChecks()
{ {
if (this.Handle == IntPtr.Zero) if (this.Handle == IntPtr.Zero)
{
throw new ObjectDisposedException(GetType().Name); throw new ObjectDisposedException(GetType().Name);
}
} }
/// <summary> /// <summary>
@ -200,7 +214,8 @@ public class Future
/// </summary> /// </summary>
public Future(IntPtr handle) public Future(IntPtr handle)
{ {
Handle = ThenRaw(handle, (Eina.Value value) => { Handle = ThenRaw(handle, (Eina.Value value) =>
{
Handle = IntPtr.Zero; Handle = IntPtr.Zero;
return value; return value;
}); });
@ -212,12 +227,16 @@ public class Future
/// Optionally a resolved callback may be provided. If so, it will be chained /// Optionally a resolved callback may be provided. If so, it will be chained
/// before the returned future. /// before the returned future.
/// </summary> /// </summary>
public Future(Promise promise, ResolvedCb cb=null) public Future(Promise promise, ResolvedCb cb = null)
{ {
IntPtr intermediate = eina_future_new(promise.Handle); IntPtr intermediate = eina_future_new(promise.Handle);
Handle = ThenRaw(intermediate, (Eina.Value value) => { Handle = ThenRaw(intermediate, (Eina.Value value) =>
{
if (cb != null) if (cb != null)
{
value = cb(value); value = cb(value);
}
Handle = IntPtr.Zero; Handle = IntPtr.Zero;
return value; return value;
}); });
@ -226,7 +245,9 @@ public class Future
private void SanityChecks() private void SanityChecks()
{ {
if (this.Handle == IntPtr.Zero) if (this.Handle == IntPtr.Zero)
{
throw new ObjectDisposedException(GetType().Name); throw new ObjectDisposedException(GetType().Name);
}
} }
/// <summary> /// <summary>
@ -266,14 +287,20 @@ public class Future
desc.data = GCHandle.ToIntPtr(handle); desc.data = GCHandle.ToIntPtr(handle);
return eina_future_then_from_desc(previous, desc); return eina_future_then_from_desc(previous, desc);
} }
private static Eina.ValueNative NativeResolvedCb(IntPtr data, Eina.ValueNative value, IntPtr dead_future) private static Eina.ValueNative NativeResolvedCb(IntPtr data, Eina.ValueNative value, IntPtr dead_future)
{ {
GCHandle handle = GCHandle.FromIntPtr(data); GCHandle handle = GCHandle.FromIntPtr(data);
ResolvedCb cb = handle.Target as ResolvedCb; ResolvedCb cb = handle.Target as ResolvedCb;
if (cb != null) if (cb != null)
{
value = cb(value); value = cb(value);
}
else else
{
Eina.Log.Warning("Failed to get future callback."); Eina.Log.Warning("Failed to get future callback.");
}
handle.Free(); handle.Free();
return value; return value;
} }
@ -308,14 +335,18 @@ public class Future
for (int j = 0; j <= i; j++) for (int j = 0; j <= i; j++)
{ {
if (descs[i].data == IntPtr.Zero) if (descs[i].data == IntPtr.Zero)
{
continue; continue;
}
GCHandle handle = GCHandle.FromIntPtr(descs[i].data); GCHandle handle = GCHandle.FromIntPtr(descs[i].data);
handle.Free(); handle.Free();
} }
Eina.Log.Error($"Failed to create native future description for callbacks. Error: {e.ToString()}"); Eina.Log.Error($"Failed to create native future description for callbacks. Error: {e.ToString()}");
return null; return null;
} }
return new Future(eina_future_chain_array(Handle, descs)); return new Future(eina_future_chain_array(Handle, descs));
} }
} }
@ -341,17 +372,24 @@ public class FutureMarshaler : ICustomMarshaler
{ {
Future f = managedObj as Future; Future f = managedObj as Future;
if (f == null) if (f == null)
{
return IntPtr.Zero; return IntPtr.Zero;
}
return f.Handle; return f.Handle;
} }
///<summary>Not implemented. The code receiving the native data is in charge of releasing it.</summary> ///<summary>Not implemented. The code receiving the native data is in charge of releasing it.</summary>
///<param name="pNativeData">The native pointer to be released.</param> ///<param name="pNativeData">The native pointer to be released.</param>
public void CleanUpNativeData(IntPtr pNativeData) { } public void CleanUpNativeData(IntPtr pNativeData)
{
}
///<summary>Not implemented. The runtime takes care of releasing it.</summary> ///<summary>Not implemented. The runtime takes care of releasing it.</summary>
///<param name="managedObj">The managed object to be cleaned.</param> ///<param name="managedObj">The managed object to be cleaned.</param>
public void CleanUpManagedData(object managedObj) { } public void CleanUpManagedData(object managedObj)
{
}
///<summary>Size of the native data size returned</summary> ///<summary>Size of the native data size returned</summary>
///<returns>The size of the data.</returns> ///<returns>The size of the data.</returns>
@ -363,9 +401,13 @@ public class FutureMarshaler : ICustomMarshaler
///<summary>Gets an instance of this marshaller.</summary> ///<summary>Gets an instance of this marshaller.</summary>
///<param name="cookie">A name that could be used to customize the returned marshaller. Currently not used.</param> ///<param name="cookie">A name that could be used to customize the returned marshaller. Currently not used.</param>
///<returns>The <see cref="Eina.FutureMarshaler"/> instance that will marshall the data.</returns> ///<returns>The <see cref="Eina.FutureMarshaler"/> instance that will marshall the data.</returns>
public static ICustomMarshaler GetInstance(string cookie) { public static ICustomMarshaler GetInstance(string cookie)
{
if (marshaler == null) if (marshaler == null)
{
marshaler = new FutureMarshaler(); marshaler = new FutureMarshaler();
}
return marshaler; return marshaler;
} }

View File

@ -3,7 +3,8 @@
using System; using System;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
namespace Eina { namespace Eina
{
public interface ISliceBase public interface ISliceBase
{ {
@ -21,8 +22,8 @@ public struct Slice : ISliceBase
public int Length public int Length
{ {
get { return (int) Len; } get { return (int)Len; }
set { Len = (UIntPtr) value; } set { Len = (UIntPtr)value; }
} }
public Slice(IntPtr mem, UIntPtr len) public Slice(IntPtr mem, UIntPtr len)
@ -47,8 +48,8 @@ public struct RwSlice : ISliceBase
public int Length public int Length
{ {
get { return (int) Len; } get { return (int)Len; }
set { Len = (UIntPtr) value; } set { Len = (UIntPtr)value; }
} }
public RwSlice(IntPtr mem, UIntPtr len) public RwSlice(IntPtr mem, UIntPtr len)

View File

@ -5,8 +5,10 @@ using static Eina.EinaNative.StrbufNativeMethods;
namespace Eina namespace Eina
{ {
namespace EinaNative namespace EinaNative
{ {
static internal class StrbufNativeMethods static internal class StrbufNativeMethods
{ {
[DllImport(efl.Libs.Eina)] [DllImport(efl.Libs.Eina)]
@ -48,7 +50,7 @@ public class Strbuf : IDisposable
private bool Disposed; private bool Disposed;
///<summary>Creates a new Strbuf. By default its lifetime is managed.</summary> ///<summary>Creates a new Strbuf. By default its lifetime is managed.</summary>
public Strbuf(Ownership ownership=Ownership.Managed) public Strbuf(Ownership ownership = Ownership.Managed)
{ {
this.Handle = eina_strbuf_new(); this.Handle = eina_strbuf_new();
this.Ownership = ownership; this.Ownership = ownership;
@ -89,9 +91,11 @@ public class Strbuf : IDisposable
return; return;
} }
if (!Disposed && (Handle != IntPtr.Zero)) { if (!Disposed && (Handle != IntPtr.Zero))
{
eina_strbuf_free(Handle); eina_strbuf_free(Handle);
} }
Disposed = true; Disposed = true;
} }
@ -115,7 +119,10 @@ public class Strbuf : IDisposable
public void Reset() public void Reset()
{ {
if (Disposed) if (Disposed)
{
throw new ObjectDisposedException(base.GetType().Name); throw new ObjectDisposedException(base.GetType().Name);
}
eina_strbuf_reset(Handle); eina_strbuf_reset(Handle);
} }
@ -123,7 +130,10 @@ public class Strbuf : IDisposable
public bool Append(string text) public bool Append(string text)
{ {
if (Disposed) if (Disposed)
{
throw new ObjectDisposedException(base.GetType().Name); throw new ObjectDisposedException(base.GetType().Name);
}
return eina_strbuf_append(Handle, text); return eina_strbuf_append(Handle, text);
} }
@ -131,7 +141,10 @@ public class Strbuf : IDisposable
public bool AppendEscaped(string text) public bool AppendEscaped(string text)
{ {
if (Disposed) if (Disposed)
{
throw new ObjectDisposedException(base.GetType().Name); throw new ObjectDisposedException(base.GetType().Name);
}
return eina_strbuf_append_escaped(Handle, text); return eina_strbuf_append_escaped(Handle, text);
} }
@ -139,7 +152,10 @@ public class Strbuf : IDisposable
public bool Append(char c) public bool Append(char c)
{ {
if (Disposed) if (Disposed)
{
throw new ObjectDisposedException(base.GetType().Name); throw new ObjectDisposedException(base.GetType().Name);
}
return eina_strbuf_append_char(Handle, c); return eina_strbuf_append_char(Handle, c);
} }
@ -147,10 +163,12 @@ public class Strbuf : IDisposable
public string Steal() public string Steal()
{ {
if (Disposed) if (Disposed)
{
throw new ObjectDisposedException(base.GetType().Name); throw new ObjectDisposedException(base.GetType().Name);
}
return eina_strbuf_string_steal(Handle); return eina_strbuf_string_steal(Handle);
} }
} }
} // namespace eina } // namespace eina

View File

@ -4,9 +4,11 @@ using System;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
namespace Eina { namespace Eina
{
public class Stringshare { public class Stringshare
{
[DllImport(efl.Libs.Eina)] public static extern System.IntPtr [DllImport(efl.Libs.Eina)] public static extern System.IntPtr
eina_stringshare_add_length(string str, System.UInt32 slen); eina_stringshare_add_length(string str, System.UInt32 slen);
[DllImport(efl.Libs.Eina)] public static extern System.IntPtr [DllImport(efl.Libs.Eina)] public static extern System.IntPtr
@ -16,4 +18,3 @@ public class Stringshare {
} }
} }

File diff suppressed because it is too large Load Diff

View File

@ -5,7 +5,8 @@ using System.Runtime.InteropServices;
using static eldbus.EldbusMessageNativeFunctions; using static eldbus.EldbusMessageNativeFunctions;
namespace eldbus { namespace eldbus
{
public static class Timeout public static class Timeout
{ {
@ -26,6 +27,7 @@ public struct ObjectPath
{ {
return new ObjectPath(str); return new ObjectPath(str);
} }
public static implicit operator string(ObjectPath path) public static implicit operator string(ObjectPath path)
{ {
return path.value; return path.value;
@ -46,6 +48,7 @@ public struct SignatureString
{ {
return new SignatureString(str); return new SignatureString(str);
} }
public static implicit operator string(SignatureString sig) public static implicit operator string(SignatureString sig)
{ {
return sig.value; return sig.value;
@ -66,6 +69,7 @@ public struct UnixFd
{ {
return new UnixFd(fd); return new UnixFd(fd);
} }
public static implicit operator Int32(UnixFd unix_fd) public static implicit operator Int32(UnixFd unix_fd)
{ {
return unix_fd.value; return unix_fd.value;
@ -75,23 +79,107 @@ public struct UnixFd
public static class Argument public static class Argument
{ {
public class ByteType { public const char Code = 'y'; public const string Signature = "y"; } public class ByteType
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 const char Code = 'y';
public class UInt16Type { public const char Code = 'q'; public const string Signature = "q"; } public const string Signature = "y";
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 BooleanType
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 const char Code = 'b';
public class StringType { public const char Code = 's'; public const string Signature = "s"; } public const string Signature = "b";
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 Int16Type
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 const char Code = 'n';
public class DictEntryType { public const char Code = 'e'; public const string Signature = "e"; } public const string Signature = "n";
public class UnixFdType { public const char Code = 'h'; public const string Signature = "h"; } }
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 ByteType ByteT = new ByteType();
// public static readonly BooleanType BooleanT = new BooleanType(); // public static readonly BooleanType BooleanT = new BooleanType();
@ -135,13 +223,17 @@ public abstract class BasicMessageArgument
public void AppendTo(eldbus.Message msg) public void AppendTo(eldbus.Message msg)
{ {
if (!InternalAppendTo(msg)) if (!InternalAppendTo(msg))
{
throw new SEHException("Eldbus: could not append basic type to eldbus.Message"); throw new SEHException("Eldbus: could not append basic type to eldbus.Message");
}
} }
public void AppendTo(eldbus.MessageIterator iter) public void AppendTo(eldbus.MessageIterator iter)
{ {
if (!InternalAppendTo(iter)) if (!InternalAppendTo(iter))
{
throw new SEHException("Eldbus: could not append basic type to eldbus.MessageIterator"); throw new SEHException("Eldbus: could not append basic type to eldbus.MessageIterator");
}
} }
public abstract char TypeCode {get;} public abstract char TypeCode {get;}
@ -219,8 +311,15 @@ public class ByteMessageArgument : BasicMessageArgument
value = arg; value = arg;
} }
public override char TypeCode { get { return Argument.ByteType.Code; } } public override char TypeCode
public override string Signature { get { return Argument.ByteType.Signature; } } {
get { return Argument.ByteType.Code; }
}
public override string Signature
{
get { return Argument.ByteType.Signature; }
}
protected override bool InternalAppendTo(eldbus.Message msg) protected override bool InternalAppendTo(eldbus.Message msg)
{ {
@ -242,8 +341,15 @@ public class BoolMessageArgument : BasicMessageArgument
value = Convert.ToInt32(arg); value = Convert.ToInt32(arg);
} }
public override char TypeCode { get { return Argument.BooleanType.Code; } } public override char TypeCode
public override string Signature { get { return Argument.ByteType.Signature; } } {
get { return Argument.BooleanType.Code; }
}
public override string Signature
{
get { return Argument.ByteType.Signature; }
}
protected override bool InternalAppendTo(eldbus.Message msg) protected override bool InternalAppendTo(eldbus.Message msg)
{ {
@ -265,8 +371,15 @@ public class Int16MessageArgument : BasicMessageArgument
value = arg; value = arg;
} }
public override char TypeCode { get { return Argument.Int16Type.Code; } } public override char TypeCode
public override string Signature { get { return Argument.ByteType.Signature; } } {
get { return Argument.Int16Type.Code; }
}
public override string Signature
{
get { return Argument.ByteType.Signature; }
}
protected override bool InternalAppendTo(eldbus.Message msg) protected override bool InternalAppendTo(eldbus.Message msg)
{ {
@ -288,8 +401,15 @@ public class UInt16MessageArgument : BasicMessageArgument
value = arg; value = arg;
} }
public override char TypeCode { get { return Argument.UInt16Type.Code; } } public override char TypeCode
public override string Signature { get { return Argument.ByteType.Signature; } } {
get { return Argument.UInt16Type.Code; }
}
public override string Signature
{
get { return Argument.ByteType.Signature; }
}
protected override bool InternalAppendTo(eldbus.Message msg) protected override bool InternalAppendTo(eldbus.Message msg)
{ {
@ -311,8 +431,15 @@ public class Int32MessageArgument : BasicMessageArgument
value = arg; value = arg;
} }
public override char TypeCode { get { return Argument.Int32Type.Code; } } public override char TypeCode
public override string Signature { get { return Argument.ByteType.Signature; } } {
get { return Argument.Int32Type.Code; }
}
public override string Signature
{
get { return Argument.ByteType.Signature; }
}
protected override bool InternalAppendTo(eldbus.Message msg) protected override bool InternalAppendTo(eldbus.Message msg)
{ {
@ -334,8 +461,15 @@ public class UInt32MessageArgument : BasicMessageArgument
value = arg; value = arg;
} }
public override char TypeCode { get { return Argument.UInt32Type.Code; } } public override char TypeCode
public override string Signature { get { return Argument.ByteType.Signature; } } {
get { return Argument.UInt32Type.Code; }
}
public override string Signature
{
get { return Argument.ByteType.Signature; }
}
protected override bool InternalAppendTo(eldbus.Message msg) protected override bool InternalAppendTo(eldbus.Message msg)
{ {
@ -357,8 +491,15 @@ public class Int64MessageArgument : BasicMessageArgument
value = arg; value = arg;
} }
public override char TypeCode { get { return Argument.Int64Type.Code; } } public override char TypeCode
public override string Signature { get { return Argument.ByteType.Signature; } } {
get { return Argument.Int64Type.Code; }
}
public override string Signature
{
get { return Argument.ByteType.Signature; }
}
protected override bool InternalAppendTo(eldbus.Message msg) protected override bool InternalAppendTo(eldbus.Message msg)
{ {
@ -380,8 +521,15 @@ public class UInt64MessageArgument : BasicMessageArgument
value = arg; value = arg;
} }
public override char TypeCode { get { return Argument.UInt64Type.Code; } } public override char TypeCode
public override string Signature { get { return Argument.ByteType.Signature; } } {
get { return Argument.UInt64Type.Code; }
}
public override string Signature
{
get { return Argument.ByteType.Signature; }
}
protected override bool InternalAppendTo(eldbus.Message msg) protected override bool InternalAppendTo(eldbus.Message msg)
{ {
@ -403,8 +551,15 @@ public class DoubleMessageArgument : BasicMessageArgument
value = arg; value = arg;
} }
public override char TypeCode { get { return Argument.DoubleType.Code; } } public override char TypeCode
public override string Signature { get { return Argument.ByteType.Signature; } } {
get { return Argument.DoubleType.Code; }
}
public override string Signature
{
get { return Argument.ByteType.Signature; }
}
protected override bool InternalAppendTo(eldbus.Message msg) protected override bool InternalAppendTo(eldbus.Message msg)
{ {
@ -439,32 +594,53 @@ public abstract class StringLikeMessageArgument : BasicMessageArgument
public class StringMessageArgument : StringLikeMessageArgument public class StringMessageArgument : StringLikeMessageArgument
{ {
public StringMessageArgument(string arg) public StringMessageArgument(string arg) : base(arg)
: base(arg) {
{} }
public override char TypeCode { get { return Argument.StringType.Code; } } public override char TypeCode
public override string Signature { get { return Argument.ByteType.Signature; } } {
get { return Argument.StringType.Code; }
}
public override string Signature
{
get { return Argument.ByteType.Signature; }
}
} }
public class ObjectPathMessageArgument : StringLikeMessageArgument public class ObjectPathMessageArgument : StringLikeMessageArgument
{ {
public ObjectPathMessageArgument(ObjectPath arg) public ObjectPathMessageArgument(ObjectPath arg) : base(arg.value)
: base(arg.value) {
{} }
public override char TypeCode { get { return Argument.ObjectPathType.Code; } } public override char TypeCode
public override string Signature { get { return Argument.ByteType.Signature; } } {
get { return Argument.ObjectPathType.Code; }
}
public override string Signature
{
get { return Argument.ByteType.Signature; }
}
} }
public class SignatureMessageArgument : StringLikeMessageArgument public class SignatureMessageArgument : StringLikeMessageArgument
{ {
public SignatureMessageArgument(SignatureString arg) public SignatureMessageArgument(SignatureString arg) : base(arg.value)
: base(arg.value) {
{} }
public override char TypeCode { get { return Argument.SignatureType.Code; } } public override char TypeCode
public override string Signature { get { return Argument.ByteType.Signature; } } {
get { return Argument.SignatureType.Code; }
}
public override string Signature
{
get { return Argument.ByteType.Signature; }
}
} }
public class UnixFdMessageArgument : BasicMessageArgument public class UnixFdMessageArgument : BasicMessageArgument
@ -476,8 +652,15 @@ public class UnixFdMessageArgument : BasicMessageArgument
value = arg.value; value = arg.value;
} }
public override char TypeCode { get { return Argument.UnixFdType.Code; } } public override char TypeCode
public override string Signature { get { return Argument.ByteType.Signature; } } {
get { return Argument.UnixFdType.Code; }
}
public override string Signature
{
get { return Argument.ByteType.Signature; }
}
protected override bool InternalAppendTo(eldbus.Message msg) protected override bool InternalAppendTo(eldbus.Message msg)
{ {
@ -497,7 +680,10 @@ public static class Common
public static void RaiseNullHandle() public static void RaiseNullHandle()
{ {
if (NullHandleError == 0) if (NullHandleError == 0)
{
NullHandleError = Eina.Error.Register("Eldbus: null handle"); NullHandleError = Eina.Error.Register("Eldbus: null handle");
}
Eina.Error.Raise(NullHandleError); Eina.Error.Raise(NullHandleError);
} }
@ -511,7 +697,10 @@ public static class Common
public static Eldbus_Message_Cb GetMessageCbWrapper() public static Eldbus_Message_Cb GetMessageCbWrapper()
{ {
if (message_cb_wrapper == null) if (message_cb_wrapper == null)
{
message_cb_wrapper = new Eldbus_Message_Cb(MessageCbWrapper); message_cb_wrapper = new Eldbus_Message_Cb(MessageCbWrapper);
}
return message_cb_wrapper; return message_cb_wrapper;
} }
@ -532,7 +721,7 @@ public static class Common
msg = new eldbus.Message(msg_hdl, false); msg = new eldbus.Message(msg_hdl, false);
pending = new eldbus.Pending(pending_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()); Eina.Log.Error("Eldbus: could not convert Eldbus_Message_Cb parameters. Exception: " + e.ToString());
return; return;
@ -542,7 +731,7 @@ public static class Common
{ {
dlgt(msg, pending); dlgt(msg, pending);
} }
catch(Exception e) catch (Exception e)
{ {
Eina.Log.Error("Eldbus: Eldbus_Message_Cb delegate error. Exception: " + e.ToString()); Eina.Log.Error("Eldbus: Eldbus_Message_Cb delegate error. Exception: " + e.ToString());
} }
@ -553,5 +742,3 @@ public static class Common
} }
} }

View File

@ -3,7 +3,8 @@
using System; using System;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
namespace eldbus { namespace eldbus
{
public static class Config public static class Config
{ {
@ -13,7 +14,9 @@ public static class Config
public static void Init() public static void Init()
{ {
if (eldbus_init() == 0) if (eldbus_init() == 0)
{
throw new Efl.EflException("Failed to initialize Eldbus"); throw new Efl.EflException("Failed to initialize Eldbus");
}
} }
public static void Shutdown() public static void Shutdown()

View File

@ -5,8 +5,8 @@ using System.Runtime.InteropServices;
using static eldbus.EldbusConnectionNativeFunctions; using static eldbus.EldbusConnectionNativeFunctions;
namespace eldbus { namespace eldbus
{
public static class EldbusConnectionNativeFunctions public static class EldbusConnectionNativeFunctions
{ {
@ -155,10 +155,14 @@ public class Connection : IDisposable
IntPtr h = Handle; IntPtr h = Handle;
Handle = IntPtr.Zero; Handle = IntPtr.Zero;
if (h == IntPtr.Zero) if (h == IntPtr.Zero)
{
return; return;
}
if (Own) if (Own)
{
eldbus_connection_unref(h); eldbus_connection_unref(h);
}
} }
public void Dispose() public void Dispose()
@ -184,15 +188,19 @@ public class Connection : IDisposable
CheckHandle(); CheckHandle();
if (msg == null) if (msg == null)
{
throw new ArgumentNullException("msg"); throw new ArgumentNullException("msg");
}
IntPtr cb_wrapper = (dlgt == null ? IntPtr.Zero : eldbus.Common.GetMessageCbWrapperPtr()); IntPtr cb_wrapper = (dlgt == null ? IntPtr.Zero : eldbus.Common.GetMessageCbWrapperPtr());
IntPtr cb_data = (dlgt == null ? IntPtr.Zero : Marshal.GetFunctionPointerForDelegate(dlgt)); IntPtr cb_data = (dlgt == null ? IntPtr.Zero : Marshal.GetFunctionPointerForDelegate(dlgt));
var pending_hdl = eldbus_connection_send(Handle, msg.Handle, cb_wrapper, cb_data, timeout); 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"); throw new SEHException("Eldbus: could not get `Pending' object from eldbus_connection_send");
}
msg.Ref(); msg.Ref();
@ -204,7 +212,10 @@ public class Connection : IDisposable
CheckHandle(); CheckHandle();
var ptr = eldbus_connection_unique_name_get(Handle); var ptr = eldbus_connection_unique_name_get(Handle);
if (ptr == IntPtr.Zero) if (ptr == IntPtr.Zero)
{
return null; return null;
}
return Eina.StringConversion.NativeUtf8ToManagedString(ptr); return Eina.StringConversion.NativeUtf8ToManagedString(ptr);
} }
@ -213,15 +224,19 @@ public class Connection : IDisposable
CheckHandle(); CheckHandle();
if (bus == null) if (bus == null)
{
throw new ArgumentNullException("bus"); throw new ArgumentNullException("bus");
}
IntPtr cb_wrapper = (dlgt == null ? IntPtr.Zero : eldbus.Common.GetMessageCbWrapperPtr()); IntPtr cb_wrapper = (dlgt == null ? IntPtr.Zero : eldbus.Common.GetMessageCbWrapperPtr());
IntPtr cb_data = (dlgt == null ? IntPtr.Zero : Marshal.GetFunctionPointerForDelegate(dlgt)); IntPtr cb_data = (dlgt == null ? IntPtr.Zero : Marshal.GetFunctionPointerForDelegate(dlgt));
var pending_hdl = eldbus_name_request(Handle, bus, flags, cb_wrapper, cb_data); 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"); throw new SEHException("Eldbus: could not get `Pending' object from eldbus_name_request");
}
return new eldbus.Pending(pending_hdl, false); return new eldbus.Pending(pending_hdl, false);
} }
@ -231,15 +246,19 @@ public class Connection : IDisposable
CheckHandle(); CheckHandle();
if (bus == null) if (bus == null)
{
throw new ArgumentNullException("bus"); throw new ArgumentNullException("bus");
}
IntPtr cb_wrapper = (dlgt == null ? IntPtr.Zero : eldbus.Common.GetMessageCbWrapperPtr()); IntPtr cb_wrapper = (dlgt == null ? IntPtr.Zero : eldbus.Common.GetMessageCbWrapperPtr());
IntPtr cb_data = (dlgt == null ? IntPtr.Zero : Marshal.GetFunctionPointerForDelegate(dlgt)); IntPtr cb_data = (dlgt == null ? IntPtr.Zero : Marshal.GetFunctionPointerForDelegate(dlgt));
var pending_hdl = eldbus_name_release(Handle, bus, cb_wrapper, cb_data); 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"); throw new SEHException("Eldbus: could not get `Pending' object from eldbus_name_release");
}
return new eldbus.Pending(pending_hdl, false); return new eldbus.Pending(pending_hdl, false);
} }
@ -249,15 +268,19 @@ public class Connection : IDisposable
CheckHandle(); CheckHandle();
if (bus == null) if (bus == null)
{
throw new ArgumentNullException("bus"); throw new ArgumentNullException("bus");
}
IntPtr cb_wrapper = (dlgt == null ? IntPtr.Zero : eldbus.Common.GetMessageCbWrapperPtr()); IntPtr cb_wrapper = (dlgt == null ? IntPtr.Zero : eldbus.Common.GetMessageCbWrapperPtr());
IntPtr cb_data = (dlgt == null ? IntPtr.Zero : Marshal.GetFunctionPointerForDelegate(dlgt)); IntPtr cb_data = (dlgt == null ? IntPtr.Zero : Marshal.GetFunctionPointerForDelegate(dlgt));
var pending_hdl = eldbus_name_owner_get(Handle, bus, cb_wrapper, cb_data); 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"); throw new SEHException("Eldbus: could not get `Pending' object from eldbus_name_owner_get");
}
return new eldbus.Pending(pending_hdl, false); return new eldbus.Pending(pending_hdl, false);
} }
@ -267,15 +290,19 @@ public class Connection : IDisposable
CheckHandle(); CheckHandle();
if (bus == null) if (bus == null)
{
throw new ArgumentNullException("bus"); throw new ArgumentNullException("bus");
}
IntPtr cb_wrapper = (dlgt == null ? IntPtr.Zero : eldbus.Common.GetMessageCbWrapperPtr()); IntPtr cb_wrapper = (dlgt == null ? IntPtr.Zero : eldbus.Common.GetMessageCbWrapperPtr());
IntPtr cb_data = (dlgt == null ? IntPtr.Zero : Marshal.GetFunctionPointerForDelegate(dlgt)); IntPtr cb_data = (dlgt == null ? IntPtr.Zero : Marshal.GetFunctionPointerForDelegate(dlgt));
var pending_hdl = eldbus_name_owner_has(Handle, bus, cb_wrapper, cb_data); 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"); throw new SEHException("Eldbus: could not get `Pending' object from eldbus_name_owner_has");
}
return new eldbus.Pending(pending_hdl, false); 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); 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"); throw new SEHException("Eldbus: could not get `Pending' object from eldbus_names_list");
}
return new eldbus.Pending(pending_hdl, false); 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); 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"); throw new SEHException("Eldbus: could not get `Pending' object from eldbus_names_activatable_list");
}
return new eldbus.Pending(pending_hdl, false); 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); 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"); throw new SEHException("Eldbus: could not get `Pending' object from eldbus_hello");
}
return new eldbus.Pending(pending_hdl, false); return new eldbus.Pending(pending_hdl, false);
} }
@ -330,15 +363,19 @@ public class Connection : IDisposable
CheckHandle(); CheckHandle();
if (bus == null) if (bus == null)
{
throw new ArgumentNullException("bus"); throw new ArgumentNullException("bus");
}
IntPtr cb_wrapper = (dlgt == null ? IntPtr.Zero : eldbus.Common.GetMessageCbWrapperPtr()); IntPtr cb_wrapper = (dlgt == null ? IntPtr.Zero : eldbus.Common.GetMessageCbWrapperPtr());
IntPtr cb_data = (dlgt == null ? IntPtr.Zero : Marshal.GetFunctionPointerForDelegate(dlgt)); IntPtr cb_data = (dlgt == null ? IntPtr.Zero : Marshal.GetFunctionPointerForDelegate(dlgt));
var pending_hdl = eldbus_name_start(Handle, bus, flags, cb_wrapper, cb_data); 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"); throw new SEHException("Eldbus: could not get `Pending' object from eldbus_name_start");
}
return new eldbus.Pending(pending_hdl, false); return new eldbus.Pending(pending_hdl, false);
} }

View File

@ -5,7 +5,8 @@ using System.Runtime.InteropServices;
using static eldbus.EldbusMessageNativeFunctions; using static eldbus.EldbusMessageNativeFunctions;
namespace eldbus { namespace eldbus
{
public static class EldbusMessageNativeFunctions public static class EldbusMessageNativeFunctions
{ {
@ -223,10 +224,14 @@ public class Message : IDisposable
IntPtr h = Handle; IntPtr h = Handle;
Handle = IntPtr.Zero; Handle = IntPtr.Zero;
if (h == IntPtr.Zero) if (h == IntPtr.Zero)
{
return; return;
}
if (Own) if (Own)
{
eldbus_message_unref(h); eldbus_message_unref(h);
}
} }
public void Dispose() public void Dispose()
@ -251,7 +256,10 @@ public class Message : IDisposable
{ {
var ptr = eldbus_message_method_call_new(dest, path, iface, method); var ptr = eldbus_message_method_call_new(dest, path, iface, method);
if (ptr == IntPtr.Zero) if (ptr == IntPtr.Zero)
{
throw new SEHException("Eldbus: could not get `Message' object from eldbus_message_method_call_new"); throw new SEHException("Eldbus: could not get `Message' object from eldbus_message_method_call_new");
}
return new eldbus.Message(ptr, true); return new eldbus.Message(ptr, true);
} }
@ -259,7 +267,10 @@ public class Message : IDisposable
{ {
var ptr = eldbus_message_signal_new(path, _interface, name); var ptr = eldbus_message_signal_new(path, _interface, name);
if (ptr == IntPtr.Zero) if (ptr == IntPtr.Zero)
{
throw new SEHException("Eldbus: could not get `Message' object from eldbus_message_signal_new"); throw new SEHException("Eldbus: could not get `Message' object from eldbus_message_signal_new");
}
return new eldbus.Message(ptr, true); return new eldbus.Message(ptr, true);
} }
@ -322,7 +333,10 @@ public class Message : IDisposable
CheckHandle(); CheckHandle();
var ptr = eldbus_message_error_new(Handle, error_name, error_msg); var ptr = eldbus_message_error_new(Handle, error_name, error_msg);
if (ptr == IntPtr.Zero) if (ptr == IntPtr.Zero)
{
throw new SEHException("Eldbus: could not get `Message' object from eldbus_message_error_new"); throw new SEHException("Eldbus: could not get `Message' object from eldbus_message_error_new");
}
return new eldbus.Message(ptr, false); return new eldbus.Message(ptr, false);
} }
@ -331,7 +345,10 @@ public class Message : IDisposable
CheckHandle(); CheckHandle();
var ptr = eldbus_message_method_return_new(Handle); var ptr = eldbus_message_method_return_new(Handle);
if (ptr == IntPtr.Zero) if (ptr == IntPtr.Zero)
{
throw new SEHException("Eldbus: could not get `Message' object from eldbus_message_method_return_new"); throw new SEHException("Eldbus: could not get `Message' object from eldbus_message_method_return_new");
}
return new eldbus.Message(ptr, false); return new eldbus.Message(ptr, false);
} }
@ -459,7 +476,10 @@ public class Message : IDisposable
CheckHandle(); CheckHandle();
var ptr = eldbus_message_iter_get(Handle); var ptr = eldbus_message_iter_get(Handle);
if (ptr == IntPtr.Zero) if (ptr == IntPtr.Zero)
{
throw new SEHException("Eldbus: could not get `MessageIterator' object from eldbus_message_iter_get"); throw new SEHException("Eldbus: could not get `MessageIterator' object from eldbus_message_iter_get");
}
return new eldbus.MessageIterator(ptr, IntPtr.Zero); return new eldbus.MessageIterator(ptr, IntPtr.Zero);
} }
} }
@ -514,12 +534,18 @@ public class MessageIterator
IntPtr new_iter = IntPtr.Zero; IntPtr new_iter = IntPtr.Zero;
if (signature[0] == 'v') if (signature[0] == 'v')
{
new_iter = eldbus_message_iter_container_new(Handle, 'v', signature.Substring(1)); new_iter = eldbus_message_iter_container_new(Handle, 'v', signature.Substring(1));
}
else if (!eldbus_message_iter_arguments_append(Handle, signature, out new_iter)) else if (!eldbus_message_iter_arguments_append(Handle, signature, out new_iter))
{
throw new SEHException("Eldbus: could not append container type"); throw new SEHException("Eldbus: could not append container type");
}
if (new_iter == IntPtr.Zero) if (new_iter == IntPtr.Zero)
{
throw new SEHException("Eldbus: could not get `MessageIterator' object from eldbus_message_iter_arguments_append"); throw new SEHException("Eldbus: could not get `MessageIterator' object from eldbus_message_iter_arguments_append");
}
return new eldbus.MessageIterator(new_iter, Handle); 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); IntPtr new_iter = eldbus_message_iter_container_new(Handle, type, contained_signature);
if (new_iter == IntPtr.Zero) if (new_iter == IntPtr.Zero)
{
throw new SEHException("Eldbus: could not get `MessageIterator' object from eldbus_message_iter_container_new"); throw new SEHException("Eldbus: could not get `MessageIterator' object from eldbus_message_iter_container_new");
}
return new eldbus.MessageIterator(new_iter, Handle); return new eldbus.MessageIterator(new_iter, Handle);
} }
@ -541,10 +569,14 @@ public class MessageIterator
CheckHandle(); CheckHandle();
if (Parent == IntPtr.Zero) if (Parent == IntPtr.Zero)
{
throw new SEHException("Eldbus: can not close MessageIterator open container without a parent"); throw new SEHException("Eldbus: can not close MessageIterator open container without a parent");
}
if (!eldbus_message_iter_container_close(Parent, Handle)) if (!eldbus_message_iter_container_close(Parent, Handle))
{
throw new SEHException("Eldbus: could not close MessageIterator"); throw new SEHException("Eldbus: could not close MessageIterator");
}
Handle = IntPtr.Zero; Handle = IntPtr.Zero;
Parent = IntPtr.Zero; Parent = IntPtr.Zero;
@ -654,7 +686,10 @@ public class MessageIterator
IntPtr hdl = IntPtr.Zero; IntPtr hdl = IntPtr.Zero;
bool r = eldbus_message_iter_get_and_next(Handle, typecode, out hdl); bool r = eldbus_message_iter_get_and_next(Handle, typecode, out hdl);
if (hdl == IntPtr.Zero) if (hdl == IntPtr.Zero)
{
throw new SEHException("Eldbus: could not get argument"); throw new SEHException("Eldbus: could not get argument");
}
iter = new eldbus.MessageIterator(hdl, Handle); iter = new eldbus.MessageIterator(hdl, Handle);
return r; return r;
@ -665,7 +700,10 @@ public class MessageIterator
CheckHandle(); CheckHandle();
IntPtr hdl = IntPtr.Zero; IntPtr hdl = IntPtr.Zero;
if (!eldbus_message_iter_arguments_get(Handle, signatue, out hdl) || hdl == IntPtr.Zero) if (!eldbus_message_iter_arguments_get(Handle, signatue, out hdl) || hdl == IntPtr.Zero)
{
throw new SEHException("Eldbus: could not get argument"); throw new SEHException("Eldbus: could not get argument");
}
iter = new eldbus.MessageIterator(hdl, Handle); iter = new eldbus.MessageIterator(hdl, Handle);
return Next(); return Next();
@ -764,7 +802,10 @@ public class MessageIterator
CheckHandle(); CheckHandle();
IntPtr hdl = IntPtr.Zero; IntPtr hdl = IntPtr.Zero;
if (!eldbus_message_iter_arguments_get(Handle, signatue, out hdl) || hdl == IntPtr.Zero) if (!eldbus_message_iter_arguments_get(Handle, signatue, out hdl) || hdl == IntPtr.Zero)
{
throw new SEHException("Eldbus: could not get argument"); throw new SEHException("Eldbus: could not get argument");
}
iter = new eldbus.MessageIterator(hdl, Handle); iter = new eldbus.MessageIterator(hdl, Handle);
} }
@ -789,7 +830,9 @@ public class MessageIterator
CheckHandle(); CheckHandle();
if (!eldbus_message_iter_fixed_array_get(Handle, type_code, out value, out n_elements)) if (!eldbus_message_iter_fixed_array_get(Handle, type_code, out value, out n_elements))
{
throw new SEHException("Eldbus: could not get fixed array"); throw new SEHException("Eldbus: could not get fixed array");
}
} }
public void GetFixedArray(out byte[] array) public void GetFixedArray(out byte[] array)
@ -880,4 +923,3 @@ public class MessageIterator
} }
} }

View File

@ -7,8 +7,8 @@ using static eldbus.EldbusObjectNativeFunctions;
using IntPtr = System.IntPtr; using IntPtr = System.IntPtr;
namespace eldbus { namespace eldbus
{
public static class EldbusObjectNativeFunctions public static class EldbusObjectNativeFunctions
{ {
@ -112,16 +112,26 @@ public class Object : System.IDisposable
public Object(eldbus.Connection conn, string bus, string path) public Object(eldbus.Connection conn, string bus, string path)
{ {
if (conn == null) if (conn == null)
{
throw new System.ArgumentNullException("conn"); throw new System.ArgumentNullException("conn");
}
if (bus == null) if (bus == null)
{
throw new System.ArgumentNullException("bus"); throw new System.ArgumentNullException("bus");
}
if (path == null) if (path == null)
{
throw new System.ArgumentNullException("path"); throw new System.ArgumentNullException("path");
}
var handle = eldbus_object_get(conn.Handle, bus, path); var handle = eldbus_object_get(conn.Handle, bus, path);
if (handle == IntPtr.Zero) if (handle == IntPtr.Zero)
{
throw new SEHException("Eldbus: could not get `Object' object from eldbus_object_get"); throw new SEHException("Eldbus: could not get `Object' object from eldbus_object_get");
}
InitNew(handle, true); InitNew(handle, true);
} }
@ -136,10 +146,14 @@ public class Object : System.IDisposable
IntPtr h = Handle; IntPtr h = Handle;
Handle = IntPtr.Zero; Handle = IntPtr.Zero;
if (h == IntPtr.Zero) if (h == IntPtr.Zero)
{
return; return;
}
if (Own) if (Own)
{
eldbus_object_unref(h); eldbus_object_unref(h);
}
} }
public void Dispose() public void Dispose()
@ -166,7 +180,9 @@ public class Object : System.IDisposable
var conn = eldbus_object_connection_get(Handle); var conn = eldbus_object_connection_get(Handle);
if (conn == IntPtr.Zero) if (conn == IntPtr.Zero)
{
throw new SEHException("Eldbus: could not get `Connection' object from eldbus_object_connection_get"); throw new SEHException("Eldbus: could not get `Connection' object from eldbus_object_connection_get");
}
return new eldbus.Connection(conn, false); return new eldbus.Connection(conn, false);
} }
@ -202,7 +218,9 @@ public class Object : System.IDisposable
CheckHandle(); CheckHandle();
if (msg == null) if (msg == null)
{
throw new System.ArgumentNullException("msg"); throw new System.ArgumentNullException("msg");
}
IntPtr cb_wrapper = dlgt == null ? IntPtr.Zero : eldbus.Common.GetMessageCbWrapperPtr(); IntPtr cb_wrapper = dlgt == null ? IntPtr.Zero : eldbus.Common.GetMessageCbWrapperPtr();
IntPtr cb_data = dlgt == null ? IntPtr.Zero : Marshal.GetFunctionPointerForDelegate(dlgt); 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); var pending_hdl = eldbus_object_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_object_send"); throw new SEHException("Eldbus: could not get `Pending' object from eldbus_object_send");
}
return new eldbus.Pending(pending_hdl, false); 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); var hdl = eldbus_object_method_call_new(Handle, _interface, member);
if (hdl == IntPtr.Zero) if (hdl == IntPtr.Zero)
{
throw new SEHException("Eldbus: could not get `Message' object from eldbus_object_method_call_new"); throw new SEHException("Eldbus: could not get `Message' object from eldbus_object_method_call_new");
}
return new eldbus.Message(hdl, false); 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); var pending_hdl = eldbus_object_peer_ping(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_object_peer_ping"); throw new SEHException("Eldbus: could not get `Pending' object from eldbus_object_peer_ping");
}
return new eldbus.Pending(pending_hdl, false); 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); var pending_hdl = eldbus_object_peer_machine_id_get(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_object_peer_machine_id_get"); throw new SEHException("Eldbus: could not get `Pending' object from eldbus_object_peer_machine_id_get");
}
return new eldbus.Pending(pending_hdl, false); 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); var pending_hdl = eldbus_object_introspect(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_object_introspect"); throw new SEHException("Eldbus: could not get `Pending' object from eldbus_object_introspect");
}
return new eldbus.Pending(pending_hdl, false); 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); var pending_hdl = eldbus_object_managed_objects_get(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_object_managed_objects_get"); throw new SEHException("Eldbus: could not get `Pending' object from eldbus_object_managed_objects_get");
}
return new eldbus.Pending(pending_hdl, false); return new eldbus.Pending(pending_hdl, false);
} }
} }
} }

View File

@ -5,7 +5,8 @@ using System.Runtime.InteropServices;
using static eldbus.EldbusPendingNativeFunctions; using static eldbus.EldbusPendingNativeFunctions;
namespace eldbus { namespace eldbus
{
public static class EldbusPendingNativeFunctions public static class EldbusPendingNativeFunctions
{ {
@ -108,4 +109,3 @@ public class Pending
} }
} }

View File

@ -5,7 +5,8 @@ using System.Runtime.InteropServices;
using static eldbus.EldbusProxyNativeFunctions; using static eldbus.EldbusProxyNativeFunctions;
namespace eldbus { namespace eldbus
{
public static class EldbusProxyNativeFunctions public static class EldbusProxyNativeFunctions
{ {
@ -104,10 +105,14 @@ public class Proxy : IDisposable
IntPtr h = Handle; IntPtr h = Handle;
Handle = IntPtr.Zero; Handle = IntPtr.Zero;
if (h == IntPtr.Zero) if (h == IntPtr.Zero)
{
return; return;
}
if (Own) if (Own)
{
eldbus_proxy_unref(h); eldbus_proxy_unref(h);
}
} }
public void Dispose() public void Dispose()
@ -133,7 +138,10 @@ public class Proxy : IDisposable
CheckHandle(); CheckHandle();
var ptr = eldbus_proxy_object_get(Handle); var ptr = eldbus_proxy_object_get(Handle);
if (ptr == IntPtr.Zero) if (ptr == IntPtr.Zero)
{
throw new SEHException("Eldbus: could not get `Object' object from eldbus_proxy_object_get"); throw new SEHException("Eldbus: could not get `Object' object from eldbus_proxy_object_get");
}
return new eldbus.Object(ptr, false); return new eldbus.Object(ptr, false);
} }
@ -149,11 +157,16 @@ public class Proxy : IDisposable
CheckHandle(); CheckHandle();
if (member == null) if (member == null)
{
throw new ArgumentNullException("member"); throw new ArgumentNullException("member");
}
var ptr = eldbus_proxy_method_call_new(Handle, member); var ptr = eldbus_proxy_method_call_new(Handle, member);
if (ptr == IntPtr.Zero) if (ptr == IntPtr.Zero)
{
throw new SEHException("Eldbus: could not get `Message' object from eldbus_proxy_method_call_new"); throw new SEHException("Eldbus: could not get `Message' object from eldbus_proxy_method_call_new");
}
return new eldbus.Message(ptr, false); return new eldbus.Message(ptr, false);
} }
@ -162,7 +175,9 @@ public class Proxy : IDisposable
CheckHandle(); CheckHandle();
if (msg == null) if (msg == null)
{
throw new ArgumentNullException("msg"); throw new ArgumentNullException("msg");
}
IntPtr cb_wrapper = dlgt == null ? IntPtr.Zero : eldbus.Common.GetMessageCbWrapperPtr(); IntPtr cb_wrapper = dlgt == null ? IntPtr.Zero : eldbus.Common.GetMessageCbWrapperPtr();
IntPtr cb_data = dlgt == null ? IntPtr.Zero : Marshal.GetFunctionPointerForDelegate(dlgt); 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); var pending_hdl = eldbus_proxy_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_proxy_send"); throw new SEHException("Eldbus: could not get `Pending' object from eldbus_proxy_send");
}
return new eldbus.Pending(pending_hdl, false); return new eldbus.Pending(pending_hdl, false);
} }
@ -180,7 +197,10 @@ public class Proxy : IDisposable
CheckHandle(); CheckHandle();
var ptr = eldbus_proxy_send_and_block(Handle, msg.Handle, timeout); var ptr = eldbus_proxy_send_and_block(Handle, msg.Handle, timeout);
if (ptr == IntPtr.Zero) if (ptr == IntPtr.Zero)
{
throw new SEHException("Eldbus: could not get `Message' object from eldbus_proxy_send_and_block"); throw new SEHException("Eldbus: could not get `Message' object from eldbus_proxy_send_and_block");
}
return new eldbus.Message(ptr, true); return new eldbus.Message(ptr, true);
} }
@ -205,4 +225,3 @@ public class Proxy : IDisposable
} }
} }

View File

@ -5,7 +5,8 @@ using System.Runtime.InteropServices;
using static eldbus.EldbusServiceNativeFunctions; using static eldbus.EldbusServiceNativeFunctions;
namespace eldbus { namespace eldbus
{
public static class EldbusServiceNativeFunctions public static class EldbusServiceNativeFunctions
{ {
@ -65,4 +66,3 @@ public static class EldbusServiceNativeFunctions
} }
} }

View File

@ -1,7 +1,11 @@
using System; using System;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
namespace Efl { namespace Eo { namespace Efl
{
namespace Eo
{
///<summary>Class to load functions pointers from a native module. ///<summary>Class to load functions pointers from a native module.
/// ///
@ -51,14 +55,20 @@ public class FunctionWrapper<T> // NOTE: When supporting C# >=7.3, add a where T
private static FunctionLoadResult<T> LazyInitialization(NativeModule module, string functionName) private static FunctionLoadResult<T> LazyInitialization(NativeModule module, string functionName)
{ {
if (module.Module == IntPtr.Zero) if (module.Module == IntPtr.Zero)
{
return new FunctionLoadResult<T>(FunctionLoadResultKind.LibraryNotFound); return new FunctionLoadResult<T>(FunctionLoadResultKind.LibraryNotFound);
}
else else
{ {
IntPtr funcptr = FunctionInterop.LoadFunctionPointer(module.Module, functionName); IntPtr funcptr = FunctionInterop.LoadFunctionPointer(module.Module, functionName);
if (funcptr == IntPtr.Zero) if (funcptr == IntPtr.Zero)
{
return new FunctionLoadResult<T>(FunctionLoadResultKind.FunctionNotFound); return new FunctionLoadResult<T>(FunctionLoadResultKind.FunctionNotFound);
}
else else
{
return new FunctionLoadResult<T>(Marshal.GetDelegateForFunctionPointer<T>(funcptr)); return new FunctionLoadResult<T>(Marshal.GetDelegateForFunctionPointer<T>(funcptr));
}
} }
} }
@ -66,7 +76,7 @@ public class FunctionWrapper<T> // NOTE: When supporting C# >=7.3, add a where T
///<param name="moduleName">The name of the module containing the function.</param> ///<param name="moduleName">The name of the module containing the function.</param>
///<param name="functionName">The name of the function to search for.</param> ///<param name="functionName">The name of the function to search for.</param>
public FunctionWrapper(string moduleName, string functionName) public FunctionWrapper(string moduleName, string functionName)
: this (new NativeModule(moduleName), functionName) : this(new NativeModule(moduleName), functionName)
{ {
} }
@ -95,7 +105,8 @@ public class FunctionWrapper<T> // NOTE: When supporting C# >=7.3, add a where T
} }
///<summary>The outcome of the function load process.</summary> ///<summary>The outcome of the function load process.</summary>
public enum FunctionLoadResultKind { public enum FunctionLoadResultKind
{
///<summary>Function was loaded successfully.</summary> ///<summary>Function was loaded successfully.</summary>
Success, Success,
///<summary>Library was not found.</summary> ///<summary>Library was not found.</summary>
@ -116,9 +127,13 @@ public class FunctionLoadResult<T>
///Throws InvalidOperationException if trying to access while not loaded.</summary> ///Throws InvalidOperationException if trying to access while not loaded.</summary>
public T Delegate public T Delegate
{ {
get { get
{
if (_Delegate == null) if (_Delegate == null)
{
throw new InvalidOperationException($"Trying to get Delegate while not loaded. Load result: {Kind}"); throw new InvalidOperationException($"Trying to get Delegate while not loaded. Load result: {Kind}");
}
return _Delegate; return _Delegate;
} }
} }
@ -139,4 +154,6 @@ public class FunctionLoadResult<T>
} }
} }
} } }
}

View File

@ -1,7 +1,11 @@
using System; using System;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
namespace Efl { namespace Eo { namespace Efl
{
namespace Eo
{
public partial class FunctionInterop public partial class FunctionInterop
{ {
@ -21,4 +25,6 @@ public partial class FunctionInterop
} }
} }
} } }
}

View File

@ -1,7 +1,11 @@
using System; using System;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
namespace Efl { namespace Eo { namespace Efl
{
namespace Eo
{
public partial class FunctionInterop public partial class FunctionInterop
{ {
@ -12,4 +16,6 @@ public partial class FunctionInterop
=> FunctionInterop.GetProcAddress(nativeLibraryHandle, functionName); => FunctionInterop.GetProcAddress(nativeLibraryHandle, functionName);
} }
} } }
}

View File

@ -1,6 +1,10 @@
using System; using System;
namespace Efl { namespace Eo { namespace Efl
{
namespace Eo
{
///<summary>Wraps a native module that was opened with dlopen/LoadLibrary.</summary> ///<summary>Wraps a native module that was opened with dlopen/LoadLibrary.</summary>
public partial class NativeModule : IDisposable public partial class NativeModule : IDisposable
@ -35,4 +39,6 @@ public partial class NativeModule : IDisposable
} }
} }
} } }
}

View File

@ -1,7 +1,11 @@
using System; using System;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
namespace Efl { namespace Eo { namespace Efl
{
namespace Eo
{
public partial class NativeModule public partial class NativeModule
{ {
@ -60,11 +64,11 @@ public partial class NativeModule
} }
} }
} }
return r; return r;
} }
} }
}
}
} }

View File

@ -1,7 +1,11 @@
using System; using System;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
namespace Efl { namespace Eo { namespace Efl
{
namespace Eo
{
public class partial NativeModule public class partial NativeModule
{ {
@ -9,7 +13,6 @@ public class partial NativeModule
public static extern IntPtr LoadLibrary(string libFilename); public static extern IntPtr LoadLibrary(string libFilename);
} }
}
}
} }

View File

@ -9,12 +9,17 @@ using System.Threading;
using static Eina.NativeCustomExportFunctions; using static Eina.NativeCustomExportFunctions;
using EoG = Efl.Eo.Globals; using EoG = Efl.Eo.Globals;
namespace Efl { namespace Eo { namespace Efl
{
public class Globals { namespace Eo
{
public class Globals
{
/// <summary>Represents the type of the native Efl_Class.</summary> /// <summary>Represents the type of the native Efl_Class.</summary>
public enum EflClassType { public enum EflClassType
{
/// <summary>Regular EFL classes.</summary> /// <summary>Regular EFL classes.</summary>
Regular = 0, Regular = 0,
/// <summary>Non-instantiable efl classes (i.e. Abstracts).</summary> /// <summary>Non-instantiable efl classes (i.e. Abstracts).</summary>
@ -175,27 +180,27 @@ public class Globals {
[DllImport(efl.Libs.Evil)] public static extern IntPtr dlerror(); [DllImport(efl.Libs.Evil)] public static extern IntPtr dlerror();
public delegate bool efl_event_callback_priority_add_delegate( public delegate bool efl_event_callback_priority_add_delegate(
System.IntPtr obj, System.IntPtr obj,
IntPtr desc, IntPtr desc,
short priority, short priority,
Efl.EventCb cb, Efl.EventCb cb,
System.IntPtr data); System.IntPtr data);
[DllImport(efl.Libs.Eo)] public static extern bool efl_event_callback_priority_add( [DllImport(efl.Libs.Eo)] public static extern bool efl_event_callback_priority_add(
System.IntPtr obj, System.IntPtr obj,
IntPtr desc, IntPtr desc,
short priority, short priority,
Efl.EventCb cb, Efl.EventCb cb,
System.IntPtr data); System.IntPtr data);
public delegate bool efl_event_callback_del_delegate( public delegate bool efl_event_callback_del_delegate(
System.IntPtr obj, System.IntPtr obj,
IntPtr desc, IntPtr desc,
Efl.EventCb cb, Efl.EventCb cb,
System.IntPtr data); System.IntPtr data);
[DllImport(efl.Libs.Eo)] public static extern bool efl_event_callback_del( [DllImport(efl.Libs.Eo)] public static extern bool efl_event_callback_del(
System.IntPtr obj, System.IntPtr obj,
IntPtr desc, IntPtr desc,
Efl.EventCb cb, Efl.EventCb cb,
System.IntPtr data); System.IntPtr data);
public const int RTLD_NOW = 2; public const int RTLD_NOW = 2;
@ -205,14 +210,17 @@ public class Globals {
{ {
return v.Value; return v.Value;
} }
public static U GetParamHelper<U>(U v) public static U GetParamHelper<U>(U v)
{ {
return v; return v;
} }
public static bool ParamHelperCheck<T>(Nullable<T> v) where T : struct public static bool ParamHelperCheck<T>(Nullable<T> v) where T : struct
{ {
return v.HasValue; return v.HasValue;
} }
public static bool ParamHelperCheck<U>(U v) public static bool ParamHelperCheck<U>(U v)
{ {
return v != null; return v != null;
@ -230,9 +238,9 @@ public class Globals {
description.class_destructor = IntPtr.Zero; description.class_destructor = IntPtr.Zero;
class_initializer init = (IntPtr kls) => 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); description.class_initializer = Marshal.GetFunctionPointerForDelegate(init);
@ -243,12 +251,18 @@ public class Globals {
Eina.Log.Debug($"Going to register new class named {class_name}"); Eina.Log.Debug($"Going to register new class named {class_name}");
IntPtr klass = EoG.call_efl_class_new(description_ptr, base_klass, interface_list); 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"); Eina.Log.Error("klass was not registered");
}
else else
{
Eina.Log.Debug("Registered class successfully"); Eina.Log.Debug("Registered class successfully");
}
return klass; return klass;
} }
public static List<IntPtr> get_efl_interfaces(System.Type type) public static List<IntPtr> get_efl_interfaces(System.Type type)
{ {
System.Type base_type = type.BaseType; System.Type base_type = type.BaseType;
@ -260,29 +274,35 @@ public class Globals {
{ {
if (!System.Array.Exists(base_ifaces, element => element == iface)) if (!System.Array.Exists(base_ifaces, element => element == iface))
{ {
var attrs = System.Attribute.GetCustomAttributes(iface); var attrs = System.Attribute.GetCustomAttributes(iface);
foreach (var attr in attrs) foreach (var attr in attrs)
{ {
if (attr is Efl.Eo.NativeClass) { if (attr is Efl.Eo.NativeClass)
ifaces_lst.Add(((Efl.Eo.NativeClass)attr).GetEflClass()); {
break; ifaces_lst.Add(((Efl.Eo.NativeClass)attr).GetEflClass());
} break;
} }
}
} }
} }
return ifaces_lst; return ifaces_lst;
} }
private static Efl.Eo.NativeClass get_native_class(System.Type type) private static Efl.Eo.NativeClass get_native_class(System.Type type)
{ {
var attrs = System.Attribute.GetCustomAttributes(type); var attrs = System.Attribute.GetCustomAttributes(type);
foreach (var attr in attrs) foreach (var attr in attrs)
{ {
if (attr is Efl.Eo.NativeClass) { if (attr is Efl.Eo.NativeClass)
{
return (Efl.Eo.NativeClass)attr; return (Efl.Eo.NativeClass)attr;
} }
} }
return null; return null;
} }
public static byte class_initializer_call(IntPtr klass, System.Type type) public static byte class_initializer_call(IntPtr klass, System.Type type)
{ {
Eina.Log.Debug($"called with 0x{klass.ToInt64():x} {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)) if (!System.Array.Exists(base_interfaces, element => element == iface))
{ {
var nc = get_native_class(iface); var nc = get_native_class(iface);
if(nc != null) if (nc != null)
{ {
var moredescs = nc.GetEoOps(type); var moredescs = nc.GetEoOps(type);
Eina.Log.Debug($"adding {moredescs.Count} more descs to registration"); 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; IntPtr ptr = descs_ptr;
for(int i = 0; i != count; ++i) for (int i = 0; i != count; ++i)
{ {
Marshal.StructureToPtr(descs[i], ptr, false); Marshal.StructureToPtr(descs[i], ptr, false);
ptr = IntPtr.Add(ptr, Marshal.SizeOf(descs[0])); ptr = IntPtr.Add(ptr, Marshal.SizeOf(descs[0]));
} }
Efl_Object_Ops ops; Efl_Object_Ops ops;
ops.descs = descs_ptr; ops.descs = descs_ptr;
ops.count = (UIntPtr)count; ops.count = (UIntPtr)count;
@ -327,74 +348,80 @@ public class Globals {
//EoKlass = klass; //EoKlass = klass;
} }
else else
{
Eina.Log.Debug("nativeClass == null"); Eina.Log.Debug("nativeClass == null");
}
return 1; return 1;
} }
public static IntPtr call_efl_class_new(IntPtr desc, IntPtr bk, List<IntPtr> il = null) public static IntPtr call_efl_class_new(IntPtr desc, IntPtr bk, List<IntPtr> il = null)
{ {
IntPtr nul = IntPtr.Zero; IntPtr nul = IntPtr.Zero;
int iface_list_count = (il == null ? 0 : il.Count); int iface_list_count = (il == null ? 0 : il.Count);
switch(iface_list_count) switch (iface_list_count)
{ {
default: return nul; default: return nul;
case 0: return EoG.efl_class_new(desc, bk, nul); case 0: return EoG.efl_class_new(desc, bk, nul);
case 1: return EoG.efl_class_new(desc, bk, il[0], 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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); 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) public static IntPtr instantiate_start(IntPtr klass, Efl.Object parent)
{ {
Eina.Log.Debug($"Instantiating from klass 0x{klass.ToInt64():x}"); Eina.Log.Debug($"Instantiating from klass 0x{klass.ToInt64():x}");
System.IntPtr parent_ptr = System.IntPtr.Zero; System.IntPtr parent_ptr = System.IntPtr.Zero;
if(parent != null) if (parent != null)
{
parent_ptr = parent.NativeHandle; parent_ptr = parent.NativeHandle;
}
System.IntPtr eo = Efl.Eo.Globals._efl_add_internal_start("file", 0, klass, parent_ptr, 1, 0); System.IntPtr eo = Efl.Eo.Globals._efl_add_internal_start("file", 0, klass, parent_ptr, 1, 0);
if (eo == System.IntPtr.Zero) if (eo == System.IntPtr.Zero)
@ -407,38 +434,43 @@ public class Globals {
return eo; return eo;
} }
public static IntPtr instantiate_end(IntPtr eo) { public static IntPtr instantiate_end(IntPtr eo)
{
Eina.Log.Debug("calling efl_add_internal_end"); Eina.Log.Debug("calling efl_add_internal_end");
eo = Efl.Eo.Globals._efl_add_end(eo, 1, 0); eo = Efl.Eo.Globals._efl_add_end(eo, 1, 0);
Eina.Log.Debug($"efl_add_end returned eo 0x{eo.ToInt64():x}"); Eina.Log.Debug($"efl_add_end returned eo 0x{eo.ToInt64():x}");
return eo; return eo;
} }
public static void data_set(Efl.Eo.IWrapper obj) 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}"); 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); IntPtr pd = Efl.Eo.Globals.efl_data_scope_get(obj.NativeHandle, obj.NativeClass);
{ {
GCHandle gch = GCHandle.Alloc(obj); GCHandle gch = GCHandle.Alloc(obj);
EolianPD epd; EolianPD epd;
epd.pointer = GCHandle.ToIntPtr(gch); epd.pointer = GCHandle.ToIntPtr(gch);
Marshal.StructureToPtr(epd, pd, false); Marshal.StructureToPtr(epd, pd, false);
} }
} }
public static Efl.Eo.IWrapper data_get(IntPtr pd) public static Efl.Eo.IWrapper data_get(IntPtr pd)
{ {
EolianPD epd = (EolianPD)Marshal.PtrToStructure(pd, typeof(EolianPD)); EolianPD epd = (EolianPD)Marshal.PtrToStructure(pd, typeof(EolianPD));
if(epd.pointer != IntPtr.Zero) if (epd.pointer != IntPtr.Zero)
{ {
GCHandle gch = GCHandle.FromIntPtr(epd.pointer); GCHandle gch = GCHandle.FromIntPtr(epd.pointer);
return (Efl.Eo.IWrapper)gch.Target; return (Efl.Eo.IWrapper)gch.Target;
} }
else else
{
return null; return null;
}
} }
public static void free_dict_values(Dictionary<String, IntPtr> dict) public static void free_dict_values(Dictionary<String, IntPtr> dict)
{ {
foreach(IntPtr ptr in dict.Values) foreach (IntPtr ptr in dict.Values)
{ {
Eina.MemoryNative.Free(ptr); Eina.MemoryNative.Free(ptr);
} }
@ -446,7 +478,7 @@ public class Globals {
public static void free_stringshare_values(Dictionary<String, IntPtr> dict) public static void free_stringshare_values(Dictionary<String, IntPtr> dict)
{ {
foreach(IntPtr ptr in dict.Values) foreach (IntPtr ptr in dict.Values)
{ {
Eina.Stringshare.eina_stringshare_del(ptr); Eina.Stringshare.eina_stringshare_del(ptr);
} }
@ -467,36 +499,45 @@ public class Globals {
// Flag to be passed to the cancell callback // Flag to be passed to the cancell callback
bool fulfilled = false; bool fulfilled = false;
future.Then((Eina.Value received) => { future.Then((Eina.Value received) =>
lock (future) {
lock (future)
{
// Convert an failed Future to a failed Task.
if (received.GetValueType() == Eina.ValueType.Error)
{ {
// Convert an failed Future to a failed Task. Eina.Error err;
if (received.GetValueType() == Eina.ValueType.Error) received.Get(out err);
if (err == Eina.Error.ECANCELED)
{ {
Eina.Error err; tcs.SetCanceled();
received.Get(out err);
if (err == Eina.Error.ECANCELED)
tcs.SetCanceled();
else
tcs.TrySetException(new Efl.FutureException(received));
} }
else else
{ {
// Will mark the returned task below as completed. tcs.TrySetException(new Efl.FutureException(received));
tcs.SetResult(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. // Callback to be called when the token is cancelled.
token.Register(() => { token.Register(() =>
lock (future) {
lock (future)
{
// Will trigger the Then callback above with an Eina.Error
if (!fulfilled)
{ {
// Will trigger the Then callback above with an Eina.Error future.Cancel();
if (!fulfilled)
future.Cancel();
} }
}
}); });
return tcs.Task; return tcs.Task;
@ -534,6 +575,7 @@ public interface IWrapper
{ {
get; get;
} }
/// <summary>Pointer to internal Eo class.</summary> /// <summary>Pointer to internal Eo class.</summary>
IntPtr NativeClass IntPtr NativeClass
{ {
@ -547,11 +589,14 @@ public static class ClassRegister
{ {
System.Type t; System.Type t;
if (Efl.Eo.ClassRegister.typeFromKlass.TryGetValue(klass, out t)) if (Efl.Eo.ClassRegister.typeFromKlass.TryGetValue(klass, out t))
{
return t; return t;
}
// If it isn't on the dictionary then it is a Native binding class // If it isn't on the dictionary then it is a Native binding class
IntPtr namePtr = Efl.Eo.Globals.efl_class_name_get(klass); 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}"); 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()) foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
{ {
if (assembly == curr_asm) if (assembly == curr_asm)
{
continue; continue;
}
t = assembly.GetType(name); t = assembly.GetType(name);
if (t != null) if (t != null)
{
break; break;
}
} }
if (t == null) {
if (t == null)
{
throw new System.InvalidOperationException($"Could not find the C# binding class for the EFL class: {name}"); throw new System.InvalidOperationException($"Could not find the C# binding class for the EFL class: {name}");
} }
} }
AddToKlassTypeBiDictionary(klass, t); // Cache it in the dictionary AddToKlassTypeBiDictionary(klass, t); // Cache it in the dictionary
return t; return t;
} }
@ -592,11 +644,14 @@ public static class ClassRegister
{ {
IntPtr klass; IntPtr klass;
if (klassFromType.TryGetValue(objectType, out klass)) if (klassFromType.TryGetValue(objectType, out klass))
{
return klass; return klass;
}
// Check if it is a Native binding class // Check if it is a Native binding class
klass = GetNativeKlassPtr(objectType); klass = GetNativeKlassPtr(objectType);
if (klass != IntPtr.Zero) { if (klass != IntPtr.Zero)
{
// Add to the dictionary cache // Add to the dictionary cache
AddToKlassTypeBiDictionary(klass, objectType); AddToKlassTypeBiDictionary(klass, objectType);
return klass; return klass;
@ -605,7 +660,10 @@ public static class ClassRegister
// Unregistered Inherited class, let's register it // Unregistered Inherited class, let's register it
IntPtr baseKlass = GetNativeBaseKlassPtr(objectType); IntPtr baseKlass = GetNativeBaseKlassPtr(objectType);
if (baseKlass == IntPtr.Zero) if (baseKlass == IntPtr.Zero)
{
throw new System.InvalidOperationException($"Could not get base C# binding class for Inherited type: {objectType.FullName}"); throw new System.InvalidOperationException($"Could not get base C# binding class for Inherited type: {objectType.FullName}");
}
return RegisterKlass(baseKlass, objectType); return RegisterKlass(baseKlass, objectType);
} }
@ -613,18 +671,23 @@ public static class ClassRegister
{ {
IntPtr klass; IntPtr klass;
if (klassFromType.TryGetValue(objectType, out klass)) if (klassFromType.TryGetValue(objectType, out klass))
{
return klass; return klass;
}
return RegisterKlass(baseKlass, objectType); return RegisterKlass(baseKlass, objectType);
} }
private static IntPtr RegisterKlass(IntPtr baseKlass, System.Type 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); 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}'"); throw new System.InvalidOperationException($"Failed to register class '{objectType.FullName}'");
} }
AddToKlassTypeBiDictionary(newKlass, objectType); AddToKlassTypeBiDictionary(newKlass, objectType);
return newKlass; return newKlass;
} }
@ -636,15 +699,20 @@ public static class ClassRegister
{ {
var ptr = GetNativeKlassPtr(t); var ptr = GetNativeKlassPtr(t);
if (ptr != IntPtr.Zero) if (ptr != IntPtr.Zero)
{
return ptr; return ptr;
}
} }
throw new System.InvalidOperationException($"Class '{objectType.FullName}' is not an Efl object"); throw new System.InvalidOperationException($"Class '{objectType.FullName}' is not an Efl object");
} }
private static IntPtr GetNativeKlassPtr(System.Type objectType) private static IntPtr GetNativeKlassPtr(System.Type objectType)
{ {
if (objectType == null) if (objectType == null)
{
return IntPtr.Zero; return IntPtr.Zero;
}
if (objectType.IsInterface) if (objectType.IsInterface)
{ {
@ -653,15 +721,20 @@ public static class ClassRegister
objectType = assembly.GetType(objectType.FullName + "Concrete"); objectType = assembly.GetType(objectType.FullName + "Concrete");
if (objectType == null) if (objectType == null)
{
return IntPtr.Zero; return IntPtr.Zero;
}
} }
var method = objectType.GetMethod("GetEflClassStatic", var method = objectType.GetMethod("GetEflClassStatic",
System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic); System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic);
if (method == null) if (method == null)
{
return IntPtr.Zero; return IntPtr.Zero;
return (IntPtr) (method.Invoke(null, null)); }
return (IntPtr)(method.Invoke(null, null));
} }
public static void AddToKlassTypeBiDictionary(IntPtr klassPtr, System.Type objectType) public static void AddToKlassTypeBiDictionary(IntPtr klassPtr, System.Type objectType)
@ -699,6 +772,7 @@ public class MarshalTest<T, U> : ICustomMarshaler
Eina.Log.Debug("MarshalTest.GetInstace cookie " + cookie); Eina.Log.Debug("MarshalTest.GetInstace cookie " + cookie);
return new MarshalTest<T, U>(); return new MarshalTest<T, U>();
} }
public void CleanUpManagedData(object ManagedObj) public void CleanUpManagedData(object ManagedObj)
{ {
//Eina.Log.Warning("MarshalTest.CleanUpManagedData not implemented"); //Eina.Log.Warning("MarshalTest.CleanUpManagedData not implemented");
@ -723,7 +797,10 @@ public class MarshalTest<T, U> : ICustomMarshaler
Eina.Log.Debug("MarshalTest.MarshallManagedToNative"); Eina.Log.Debug("MarshalTest.MarshallManagedToNative");
var r = ((IWrapper)ManagedObj).NativeHandle; var r = ((IWrapper)ManagedObj).NativeHandle;
if (typeof(U) == typeof(OwnTag)) if (typeof(U) == typeof(OwnTag))
{
Efl.Eo.Globals.efl_ref(r); Efl.Eo.Globals.efl_ref(r);
}
return r; return r;
} }
@ -731,9 +808,12 @@ public class MarshalTest<T, U> : ICustomMarshaler
{ {
Eina.Log.Debug("MarshalTest.MarshalNativeToManaged"); Eina.Log.Debug("MarshalTest.MarshalNativeToManaged");
if (typeof(U) != typeof(OwnTag)) if (typeof(U) != typeof(OwnTag))
{
Efl.Eo.Globals.efl_ref(pNativeData); Efl.Eo.Globals.efl_ref(pNativeData);
}
return Activator.CreateInstance(typeof(T), new System.Object[] {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); Eina.Log.Debug("MarshalTest.GetInstance cookie " + cookie);
return new MarshalEflClass(); return new MarshalEflClass();
} }
public void CleanUpManagedData(object ManagedObj) public void CleanUpManagedData(object ManagedObj)
{ {
} }
@ -763,8 +844,11 @@ public class MarshalEflClass : ICustomMarshaler
{ {
Eina.Log.Debug("MarshalTest.MarshallManagedToNative"); Eina.Log.Debug("MarshalTest.MarshallManagedToNative");
if (ManagedObj == null) if (ManagedObj == null)
{
return IntPtr.Zero; return IntPtr.Zero;
var t = (System.Type) ManagedObj; }
var t = (System.Type)ManagedObj;
return Efl.Eo.ClassRegister.GetKlass(t); return Efl.Eo.ClassRegister.GetKlass(t);
} }
@ -772,194 +856,255 @@ public class MarshalEflClass : ICustomMarshaler
{ {
Eina.Log.Debug("MarshalTest.MarshalNativeToManaged"); Eina.Log.Debug("MarshalTest.MarshalNativeToManaged");
if (pNativeData == IntPtr.Zero) if (pNativeData == IntPtr.Zero)
{
return null; return null;
}
return Efl.Eo.ClassRegister.GetManagedType(pNativeData); return Efl.Eo.ClassRegister.GetManagedType(pNativeData);
} }
} }
public class StringPassOwnershipMarshaler : ICustomMarshaler { public class StringPassOwnershipMarshaler : ICustomMarshaler
public object MarshalNativeToManaged(IntPtr pNativeData) { {
public object MarshalNativeToManaged(IntPtr pNativeData)
{
var ret = Eina.StringConversion.NativeUtf8ToManagedString(pNativeData); var ret = Eina.StringConversion.NativeUtf8ToManagedString(pNativeData);
Eina.MemoryNative.Free(pNativeData); Eina.MemoryNative.Free(pNativeData);
return ret; return ret;
} }
public IntPtr MarshalManagedToNative(object managedObj) { public IntPtr MarshalManagedToNative(object managedObj)
{
return Eina.MemoryNative.StrDup((string)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. // 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; return -1;
} }
public static ICustomMarshaler GetInstance(string cookie) { public static ICustomMarshaler GetInstance(string cookie)
if (marshaler == null) { {
if (marshaler == null)
{
marshaler = new StringPassOwnershipMarshaler(); marshaler = new StringPassOwnershipMarshaler();
} }
return marshaler; return marshaler;
} }
static private StringPassOwnershipMarshaler marshaler; static private StringPassOwnershipMarshaler marshaler;
} }
public class StringKeepOwnershipMarshaler: ICustomMarshaler { public class StringKeepOwnershipMarshaler: ICustomMarshaler
public object MarshalNativeToManaged(IntPtr pNativeData) { {
public object MarshalNativeToManaged(IntPtr pNativeData)
{
return Eina.StringConversion.NativeUtf8ToManagedString(pNativeData); return Eina.StringConversion.NativeUtf8ToManagedString(pNativeData);
} }
public IntPtr MarshalManagedToNative(object managedObj) { public IntPtr MarshalManagedToNative(object managedObj)
{
return Eina.StringConversion.ManagedStringToNativeUtf8Alloc((string)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. // 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; return -1;
} }
public static ICustomMarshaler GetInstance(string cookie) { public static ICustomMarshaler GetInstance(string cookie)
if (marshaler == null) { {
if (marshaler == null)
{
marshaler = new StringKeepOwnershipMarshaler(); marshaler = new StringKeepOwnershipMarshaler();
} }
return marshaler; return marshaler;
} }
static private StringKeepOwnershipMarshaler marshaler; static private StringKeepOwnershipMarshaler marshaler;
} }
public class StringsharePassOwnershipMarshaler : ICustomMarshaler { public class StringsharePassOwnershipMarshaler : ICustomMarshaler
public object MarshalNativeToManaged(IntPtr pNativeData) { {
public object MarshalNativeToManaged(IntPtr pNativeData)
{
var ret = Eina.StringConversion.NativeUtf8ToManagedString(pNativeData); var ret = Eina.StringConversion.NativeUtf8ToManagedString(pNativeData);
Eina.Stringshare.eina_stringshare_del(pNativeData); Eina.Stringshare.eina_stringshare_del(pNativeData);
return ret; return ret;
} }
public IntPtr MarshalManagedToNative(object managedObj) { public IntPtr MarshalManagedToNative(object managedObj)
{
return Eina.Stringshare.eina_stringshare_add((string)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. // 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; return -1;
} }
public static ICustomMarshaler GetInstance(string cookie) { public static ICustomMarshaler GetInstance(string cookie)
if (marshaler == null) { {
if (marshaler == null)
{
marshaler = new StringsharePassOwnershipMarshaler(); marshaler = new StringsharePassOwnershipMarshaler();
} }
return marshaler; return marshaler;
} }
static private StringsharePassOwnershipMarshaler marshaler; static private StringsharePassOwnershipMarshaler marshaler;
} }
public class StringshareKeepOwnershipMarshaler : ICustomMarshaler { public class StringshareKeepOwnershipMarshaler : ICustomMarshaler
public object MarshalNativeToManaged(IntPtr pNativeData) { {
public object MarshalNativeToManaged(IntPtr pNativeData)
{
return Eina.StringConversion.NativeUtf8ToManagedString(pNativeData); return Eina.StringConversion.NativeUtf8ToManagedString(pNativeData);
} }
public IntPtr MarshalManagedToNative(object managedObj) { public IntPtr MarshalManagedToNative(object managedObj)
{
return Eina.Stringshare.eina_stringshare_add((string)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. // 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; return -1;
} }
public static ICustomMarshaler GetInstance(string cookie) { public static ICustomMarshaler GetInstance(string cookie)
if (marshaler == null) { {
if (marshaler == null)
{
marshaler = new StringshareKeepOwnershipMarshaler(); marshaler = new StringshareKeepOwnershipMarshaler();
} }
return marshaler; return marshaler;
} }
static private StringshareKeepOwnershipMarshaler marshaler; static private StringshareKeepOwnershipMarshaler marshaler;
} }
public class StrbufPassOwnershipMarshaler : ICustomMarshaler { public class StrbufPassOwnershipMarshaler : ICustomMarshaler
public object MarshalNativeToManaged(IntPtr pNativeData) { {
public object MarshalNativeToManaged(IntPtr pNativeData)
{
return new Eina.Strbuf(pNativeData, Eina.Ownership.Managed); 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; Eina.Strbuf buf = managedObj as Eina.Strbuf;
buf.ReleaseOwnership(); buf.ReleaseOwnership();
return buf.Handle; return buf.Handle;
} }
public void CleanUpNativeData(IntPtr pNativeData) { public void CleanUpNativeData(IntPtr pNativeData)
{
// No need to cleanup. C will take care of it. // 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; return -1;
} }
public static ICustomMarshaler GetInstance(string cookie) { public static ICustomMarshaler GetInstance(string cookie)
if (marshaler == null) { {
if (marshaler == null)
{
marshaler = new StrbufPassOwnershipMarshaler(); marshaler = new StrbufPassOwnershipMarshaler();
} }
return marshaler; return marshaler;
} }
static private StrbufPassOwnershipMarshaler marshaler; static private StrbufPassOwnershipMarshaler marshaler;
} }
public class StrbufKeepOwnershipMarshaler: ICustomMarshaler { public class StrbufKeepOwnershipMarshaler: ICustomMarshaler
public object MarshalNativeToManaged(IntPtr pNativeData) { {
public object MarshalNativeToManaged(IntPtr pNativeData)
{
return new Eina.Strbuf(pNativeData, Eina.Ownership.Unmanaged); 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; Eina.Strbuf buf = managedObj as Eina.Strbuf;
return buf.Handle; return buf.Handle;
} }
public void CleanUpNativeData(IntPtr pNativeData) { public void CleanUpNativeData(IntPtr pNativeData)
{
// No need to free. The Native side will keep the ownership. // 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; return -1;
} }
public static ICustomMarshaler GetInstance(string cookie) { public static ICustomMarshaler GetInstance(string cookie)
if (marshaler == null) { {
if (marshaler == null)
{
marshaler = new StrbufKeepOwnershipMarshaler(); marshaler = new StrbufKeepOwnershipMarshaler();
} }
return marshaler; return marshaler;
} }
static private StrbufKeepOwnershipMarshaler marshaler; static private StrbufKeepOwnershipMarshaler marshaler;
} }
} // namespace eo } // namespace eo
/// <summary>General exception for errors inside the binding.</summary> /// <summary>General exception for errors inside the binding.</summary>
@ -981,7 +1126,10 @@ public class FutureException : EflException
public FutureException(Eina.Value value) : base("Future failed.") public FutureException(Eina.Value value) : base("Future failed.")
{ {
if (value.GetValueType() != Eina.ValueType.Error) if (value.GetValueType() != Eina.ValueType.Error)
{
throw new ArgumentException("FutureException must receive an Eina.Value with Eina.Error."); throw new ArgumentException("FutureException must receive an Eina.Value with Eina.Error.");
}
Eina.Error err; Eina.Error err;
value.Get(out err); value.Get(out err);
Error = err; Error = err;

View File

@ -51,28 +51,35 @@ public struct EolianPD
} }
#pragma warning disable 0169 #pragma warning disable 0169
public struct EvasObjectBoxLayout public struct EvasObjectBoxLayout
{ {
IntPtr o; IntPtr o;
IntPtr priv; IntPtr priv;
IntPtr user_data; IntPtr user_data;
}; };
[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Ansi)] [StructLayout(LayoutKind.Sequential, CharSet=CharSet.Ansi)]
public struct EvasObjectBoxData public struct EvasObjectBoxData
{ {
} }
public struct EvasObjectBoxOption {
public struct EvasObjectBoxOption
{
IntPtr obj; IntPtr obj;
[MarshalAsAttribute(UnmanagedType.U1)] bool max_reached; [MarshalAsAttribute(UnmanagedType.U1)] bool max_reached;
[MarshalAsAttribute(UnmanagedType.U1)] bool min_reached; [MarshalAsAttribute(UnmanagedType.U1)] bool min_reached;
Evas.Coord alloc_size; Evas.Coord alloc_size;
}; };
#pragma warning restore 0169 #pragma warning restore 0169
namespace Efl { namespace Efl
{
[StructLayout(LayoutKind.Sequential)] [StructLayout(LayoutKind.Sequential)]
public struct EventDescription { public struct EventDescription
{
public IntPtr Name; public IntPtr Name;
[MarshalAs(UnmanagedType.U1)] public bool Unfreezable; [MarshalAs(UnmanagedType.U1)] public bool Unfreezable;
[MarshalAs(UnmanagedType.U1)] public bool Legacy_is; [MarshalAs(UnmanagedType.U1)] public bool Legacy_is;
@ -94,12 +101,15 @@ public struct EventDescription {
{ {
IntPtr data = Efl.Eo.FunctionInterop.LoadFunctionPointer(module, name); 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()); string error = Eina.StringConversion.NativeUtf8ToManagedString(Efl.Eo.Globals.dlerror());
throw new Exception(error); throw new Exception(error);
} }
descriptions.Add(name, data); descriptions.Add(name, data);
} }
return descriptions[name]; return descriptions[name];
} }
}; };
@ -107,7 +117,8 @@ public struct EventDescription {
public delegate void EventCb(System.IntPtr data, ref Event.NativeStruct evt); public delegate void EventCb(System.IntPtr data, ref Event.NativeStruct evt);
[StructLayout(LayoutKind.Sequential)] [StructLayout(LayoutKind.Sequential)]
public struct TextCursorCursor { public struct TextCursorCursor
{
IntPtr obj; IntPtr obj;
UIntPtr pos; // UIntPtr to automatically change size_t between 32/64 UIntPtr pos; // UIntPtr to automatically change size_t between 32/64
IntPtr node; IntPtr node;
@ -115,7 +126,8 @@ public struct TextCursorCursor {
} }
[StructLayout(LayoutKind.Sequential)] [StructLayout(LayoutKind.Sequential)]
public struct TextAnnotateAnnotation { public struct TextAnnotateAnnotation
{
IntPtr list; IntPtr list;
IntPtr obj; IntPtr obj;
IntPtr start_node; IntPtr start_node;
@ -125,9 +137,11 @@ public struct TextAnnotateAnnotation {
public delegate void SignalCb(IntPtr data, IntPtr obj, IntPtr emission, IntPtr source); 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 name;
public IntPtr action; public IntPtr action;
public IntPtr param; public IntPtr param;
@ -138,16 +152,25 @@ public struct ActionData {
} // namespace Efl } // namespace Efl
namespace Evas { namespace Evas
{
public struct Coord { public struct Coord
{
int val; int val;
public Coord(int value) { val = value; } public Coord(int value)
static public implicit operator Coord(int val) { {
val = value;
}
static public implicit operator Coord(int val)
{
return new Coord(val); return new Coord(val);
} }
static public implicit operator int(Coord coord) {
static public implicit operator int(Coord coord)
{
return coord.val; return coord.val;
} }
} }
@ -155,44 +178,44 @@ public struct Coord {
/* Copied from Evas_Legacy.h */ /* Copied from Evas_Legacy.h */
public enum TextStyleType public enum TextStyleType
{ {
///<summary> plain, standard text.</summary> ///<summary> plain, standard text.</summary>
Plain = 0, Plain = 0,
///<summary> text with shadow underneath.</summary> ///<summary> text with shadow underneath.</summary>
Shadow, Shadow,
///<summary> text with an outline.</summary> ///<summary> text with an outline.</summary>
Outline, Outline,
///<summary> text with a soft outline.</summary> ///<summary> text with a soft outline.</summary>
SoftOutline, SoftOutline,
///<summary> text with a glow effect.</summary> ///<summary> text with a glow effect.</summary>
Glow, Glow,
///<summary> text with both outline and shadow effects.</summary> ///<summary> text with both outline and shadow effects.</summary>
OutlineShadow, OutlineShadow,
///<summary> text with (far) shadow underneath.</summary> ///<summary> text with (far) shadow underneath.</summary>
FarShadow, FarShadow,
///<summary> text with outline and soft shadow effects combined.</summary> ///<summary> text with outline and soft shadow effects combined.</summary>
OutlineSoftShadow, OutlineSoftShadow,
///<summary> text with (soft) shadow underneath.</summary> ///<summary> text with (soft) shadow underneath.</summary>
SoftShadow, SoftShadow,
///<summary> text with (far soft) shadow underneath.</summary> ///<summary> text with (far soft) shadow underneath.</summary>
FarSoftShadow, FarSoftShadow,
// Shadow direction modifiers // Shadow direction modifiers
///<summary> shadow growing to bottom right.</summary> ///<summary> shadow growing to bottom right.</summary>
ShadowDirectionBottomRight = 0 /* 0 >> 4 */, ShadowDirectionBottomRight = 0 /* 0 >> 4 */,
///<summary> shadow growing to the bottom.</summary> ///<summary> shadow growing to the bottom.</summary>
ShadowDirectionBottom= 16 /* 1 >> 4 */, ShadowDirectionBottom = 16 /* 1 >> 4 */,
///<summary> shadow growing to bottom left.</summary> ///<summary> shadow growing to bottom left.</summary>
ShadowDirectionBottomLeft = 32 /* 2 >> 4 */, ShadowDirectionBottomLeft = 32 /* 2 >> 4 */,
///<summary> shadow growing to the left.</summary> ///<summary> shadow growing to the left.</summary>
ShadowDirectionLeft = 48 /* 3 >> 4 */, ShadowDirectionLeft = 48 /* 3 >> 4 */,
///<summary> shadow growing to top left.</summary> ///<summary> shadow growing to top left.</summary>
ShadowDirectionTopLeft = 64 /* 4 >> 4 */, ShadowDirectionTopLeft = 64 /* 4 >> 4 */,
///<summary> shadow growing to the top.</summary> ///<summary> shadow growing to the top.</summary>
ShadowDirectionTop = 80 /* 5 >> 4 */, ShadowDirectionTop = 80 /* 5 >> 4 */,
///<summary> shadow growing to top right.</summary> ///<summary> shadow growing to top right.</summary>
ShadowDirectionTopRight = 96 /* 6 >> 4 */, ShadowDirectionTopRight = 96 /* 6 >> 4 */,
///<summary> shadow growing to the right.</summary> ///<summary> shadow growing to the right.</summary>
ShadowDirectionRight = 112 /* 7 >> 4 */ ShadowDirectionRight = 112 /* 7 >> 4 */
}; };
} // namespace Evas } // namespace Evas
@ -201,8 +224,8 @@ public enum TextStyleType
public delegate int Eina_Compare_Cb(IntPtr a, IntPtr b); public delegate int Eina_Compare_Cb(IntPtr a, IntPtr b);
public delegate void ElmInterfaceScrollableCb(IntPtr obj, IntPtr data); public delegate void ElmInterfaceScrollableCb(IntPtr obj, IntPtr data);
public delegate void ElmInterfaceScrollableMinLimitCb(IntPtr obj, public delegate void ElmInterfaceScrollableMinLimitCb(IntPtr obj,
[MarshalAsAttribute(UnmanagedType.U1)]bool w, [MarshalAsAttribute(UnmanagedType.U1)]bool w,
[MarshalAsAttribute(UnmanagedType.U1)]bool h); [MarshalAsAttribute(UnmanagedType.U1)]bool h);
public delegate void ElmInterfaceScrollableResizeCb(IntPtr obj, Evas.Coord w, Evas.Coord h); public delegate void ElmInterfaceScrollableResizeCb(IntPtr obj, Evas.Coord w, Evas.Coord h);
[return: MarshalAsAttribute(UnmanagedType.U1)] [return: MarshalAsAttribute(UnmanagedType.U1)]
public delegate bool ElmMultibuttonentryItemFilterCb(IntPtr obj, IntPtr item_label, IntPtr item_data, IntPtr data); public delegate bool ElmMultibuttonentryItemFilterCb(IntPtr obj, IntPtr item_label, IntPtr item_data, IntPtr data);