forked from enlightenment/efl
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:
parent
731db8b644
commit
0d37e8ff49
|
@ -6,10 +6,11 @@ using System.Threading;
|
|||
|
||||
using static Efl.UnsafeNativeMethods;
|
||||
|
||||
namespace Efl {
|
||||
|
||||
static class UnsafeNativeMethods {
|
||||
namespace Efl
|
||||
{
|
||||
|
||||
static class UnsafeNativeMethods
|
||||
{
|
||||
private delegate void init_func_delegate();
|
||||
[DllImport(efl.Libs.Ecore)] public static extern void ecore_init();
|
||||
[DllImport(efl.Libs.Ecore)] public static extern void ecore_shutdown();
|
||||
|
@ -27,39 +28,48 @@ static class UnsafeNativeMethods {
|
|||
[DllImport(efl.Libs.Elementary)] public static extern void elm_run();
|
||||
[DllImport(efl.Libs.Elementary)] public static extern void elm_exit();
|
||||
|
||||
static UnsafeNativeMethods() {
|
||||
static UnsafeNativeMethods()
|
||||
{
|
||||
_evas_init = new Efl.Eo.FunctionWrapper<init_func_delegate>("evas", "evas_init");
|
||||
}
|
||||
|
||||
public static void evas_init()
|
||||
{
|
||||
_evas_init.Value.Delegate();
|
||||
}
|
||||
}
|
||||
|
||||
public static class All {
|
||||
public static class All
|
||||
{
|
||||
private static bool InitializedUi = false;
|
||||
|
||||
public static void Init(Efl.Csharp.Components components=Efl.Csharp.Components.Basic) {
|
||||
public static void Init(Efl.Csharp.Components components = Efl.Csharp.Components.Basic)
|
||||
{
|
||||
Eina.Config.Init();
|
||||
Efl.Eo.Config.Init();
|
||||
ecore_init();
|
||||
evas_init();
|
||||
eldbus.Config.Init();
|
||||
|
||||
if (components == Efl.Csharp.Components.Ui) {
|
||||
if (components == Efl.Csharp.Components.Ui)
|
||||
{
|
||||
Efl.Ui.Config.Init();
|
||||
InitializedUi = true;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Shutdowns all EFL subsystems.</summary>
|
||||
public static void Shutdown() {
|
||||
public static void Shutdown()
|
||||
{
|
||||
// Try to cleanup everything before actually shutting down.
|
||||
System.GC.Collect();
|
||||
System.GC.WaitForPendingFinalizers();
|
||||
|
||||
if (InitializedUi)
|
||||
{
|
||||
Efl.Ui.Config.Shutdown();
|
||||
}
|
||||
|
||||
eldbus.Config.Shutdown();
|
||||
evas_shutdown();
|
||||
ecore_shutdown();
|
||||
|
@ -69,29 +79,38 @@ public static class All {
|
|||
}
|
||||
|
||||
// Placeholder. Will move to elm_config.cs later
|
||||
namespace Ui {
|
||||
namespace Ui
|
||||
{
|
||||
|
||||
public static class Config {
|
||||
public static void Init() {
|
||||
public static class Config
|
||||
{
|
||||
public static void Init()
|
||||
{
|
||||
// TODO Support elm command line arguments
|
||||
#if WIN32 // Not a native define, we define it in our build system
|
||||
// Ecore_Win32 uses OleInitialize, which requires single thread apartments
|
||||
if (System.Threading.Thread.CurrentThread.GetApartmentState() != ApartmentState.STA)
|
||||
{
|
||||
throw new InvalidOperationException("UI Applications require STAThreadAttribute in Main()");
|
||||
}
|
||||
#endif
|
||||
elm_init(0, IntPtr.Zero);
|
||||
|
||||
elm_policy_set((int)Elm.Policy.Quit, (int)Elm.PolicyQuit.LastWindowHidden);
|
||||
}
|
||||
public static void Shutdown() {
|
||||
|
||||
public static void Shutdown()
|
||||
{
|
||||
elm_shutdown();
|
||||
}
|
||||
|
||||
public static void Run() {
|
||||
public static void Run()
|
||||
{
|
||||
elm_run();
|
||||
}
|
||||
|
||||
public static void Exit() {
|
||||
public static void Exit()
|
||||
{
|
||||
elm_exit();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,74 +3,93 @@ using System.Runtime.InteropServices;
|
|||
using System.Threading;
|
||||
using static Efl.UnsafeNativeMethods;
|
||||
|
||||
namespace Efl {
|
||||
namespace Csharp {
|
||||
///<summary>The components to be initialized.</summary>
|
||||
public enum Components {
|
||||
namespace Efl
|
||||
{
|
||||
|
||||
namespace Csharp
|
||||
{
|
||||
|
||||
///<summary>The components to be initialized.</summary>
|
||||
public enum Components
|
||||
{
|
||||
///<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>
|
||||
Ui,
|
||||
}
|
||||
/// <summary>
|
||||
/// This represents the entry point for the EFL framework
|
||||
/// You can use this class to implement the 4 abstract methods which will then be called accordingly
|
||||
/// All subsystems of efl are booted up correctly when the abstract methods of this class are called.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Calls to efl outside those efl-callbacks or outside the mainloop are not allowed and will lead to issues
|
||||
/// </remarks>
|
||||
/// <example>
|
||||
/// UserApp is the class that implements the Application abstract
|
||||
/// <code>
|
||||
/// public static void Main() {
|
||||
/// UserApp editor = new UserApp();
|
||||
/// editor.Launch(editor);
|
||||
/// }
|
||||
/// </code>
|
||||
/// </example>
|
||||
public abstract class Application {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This represents the entry point for the EFL framework
|
||||
/// You can use this class to implement the 4 abstract methods which will then be called accordingly
|
||||
/// All subsystems of efl are booted up correctly when the abstract methods of this class are called.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Calls to efl outside those efl-callbacks or outside the mainloop are not allowed and will lead to issues
|
||||
/// </remarks>
|
||||
/// <example>
|
||||
/// UserApp is the class that implements the Application abstract
|
||||
/// <code>
|
||||
/// public static void Main()
|
||||
/// {
|
||||
/// UserApp editor = new UserApp();
|
||||
/// editor.Launch(editor);
|
||||
/// }
|
||||
/// </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) {
|
||||
private static void Init(Efl.Csharp.Components component)
|
||||
{
|
||||
Eina.Config.Init();
|
||||
Efl.Eo.Config.Init();
|
||||
ecore_init();
|
||||
evas_init();
|
||||
eldbus.Config.Init();
|
||||
|
||||
if (component == Components.Ui) {
|
||||
if (component == Components.Ui)
|
||||
{
|
||||
// TODO Support elm command line arguments
|
||||
#if WIN32 // Not a native define, we define it in our build system
|
||||
// Ecore_Win32 uses OleInitialize, which requires single thread apartments
|
||||
if (System.Threading.Thread.CurrentThread.GetApartmentState() != ApartmentState.STA)
|
||||
{
|
||||
throw new InvalidOperationException("UI Applications require STAThreadAttribute in Main()");
|
||||
}
|
||||
#endif
|
||||
elm_init(0, IntPtr.Zero);
|
||||
|
||||
elm_policy_set((int)Elm.Policy.Quit, (int)Elm.PolicyQuit.LastWindowHidden);
|
||||
}
|
||||
|
||||
initComponent = component;
|
||||
}
|
||||
private static void Shutdown() {
|
||||
|
||||
private static void Shutdown()
|
||||
{
|
||||
// Try to cleanup everything before actually shutting down.
|
||||
System.GC.Collect();
|
||||
System.GC.WaitForPendingFinalizers();
|
||||
|
||||
if (initComponent == Components.Ui) {
|
||||
if (initComponent == Components.Ui)
|
||||
{
|
||||
elm_shutdown();
|
||||
}
|
||||
|
||||
eldbus.Config.Shutdown();
|
||||
evas_shutdown();
|
||||
ecore_shutdown();
|
||||
Efl.Eo.Config.Shutdown();
|
||||
Eina.Config.Shutdown();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called when the application is started. Arguments from the command line are passed here.
|
||||
/// </summary>
|
||||
protected abstract void OnInitialize(Eina.Array<System.String> args);
|
||||
|
||||
/// <summary>
|
||||
/// Arguments are passed here, Additional calls to this function may occure,
|
||||
/// but then the initialization flag is set to false.
|
||||
|
@ -78,24 +97,37 @@ namespace Efl {
|
|||
/// <remarks>
|
||||
/// When Initialize is true then OnInitialize is also called
|
||||
/// </remarks>
|
||||
protected virtual void OnArguments(Efl.LoopArguments args) { }
|
||||
protected virtual void OnArguments(Efl.LoopArguments args)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called when the application is not going to be displayed, or is not used by a user for some time.
|
||||
/// </summary>
|
||||
protected virtual void OnPause() { }
|
||||
protected virtual void OnPause()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called before an application is used again after a call to OnPause().
|
||||
/// </summary>
|
||||
protected virtual void OnResume() { }
|
||||
protected virtual void OnResume()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called before starting the shutdown of the application.
|
||||
/// </summary>
|
||||
protected virtual void OnTerminate() { }
|
||||
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) {
|
||||
public void Launch(Efl.Csharp.Components components = Components.Ui)
|
||||
{
|
||||
Init(components);
|
||||
Efl.App app = Efl.App.AppMain;
|
||||
Eina.Array<String> command_line = new Eina.Array<String>();
|
||||
|
@ -103,26 +135,32 @@ namespace Efl {
|
|||
#if EFL_BETA
|
||||
app.SetCommandArray(command_line);
|
||||
#endif
|
||||
app.ArgumentsEvt += (object sender, LoopArgumentsEvt_Args evt) => {
|
||||
if (evt.arg.Initialization) {
|
||||
app.ArgumentsEvt += (object sender, LoopArgumentsEvt_Args evt) =>
|
||||
{
|
||||
if (evt.arg.Initialization)
|
||||
{
|
||||
OnInitialize(evt.arg.Argv);
|
||||
}
|
||||
|
||||
OnArguments(evt.arg);
|
||||
};
|
||||
app.PauseEvt += (object sender, EventArgs e) => {
|
||||
app.PauseEvt += (object sender, EventArgs e) =>
|
||||
{
|
||||
OnPause();
|
||||
};
|
||||
app.ResumeEvt += (object sender, EventArgs e) => {
|
||||
app.ResumeEvt += (object sender, EventArgs e) =>
|
||||
{
|
||||
OnResume();
|
||||
};
|
||||
app.TerminateEvt += (object sender, EventArgs e) => {
|
||||
app.TerminateEvt += (object sender, EventArgs e) =>
|
||||
{
|
||||
OnTerminate();
|
||||
};
|
||||
app.Begin();
|
||||
Shutdown();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -7,7 +7,8 @@ using static Eina.TraitFunctions;
|
|||
|
||||
using static Eina.AccessorNativeFunctions;
|
||||
|
||||
namespace Eina {
|
||||
namespace Eina
|
||||
{
|
||||
|
||||
internal class AccessorNativeFunctions
|
||||
{
|
||||
|
@ -43,7 +44,7 @@ public class Accessor<T> : IEnumerable<T>, IDisposable
|
|||
/// <summary>Create a new accessor wrapping the given pointer.</summary>
|
||||
/// <param name="handle">The native handle to be wrapped.</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;
|
||||
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="own">Whether this wrapper owns the native accessor.</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)
|
||||
{
|
||||
}
|
||||
|
@ -96,13 +97,16 @@ public class Accessor<T> : IEnumerable<T>, IDisposable
|
|||
public IEnumerator<T> GetEnumerator()
|
||||
{
|
||||
if (Handle == IntPtr.Zero)
|
||||
{
|
||||
throw new ObjectDisposedException(base.GetType().Name);
|
||||
}
|
||||
|
||||
IntPtr tmp = MemoryNative.Alloc(Marshal.SizeOf(typeof(IntPtr)));
|
||||
uint position = 0;
|
||||
|
||||
try
|
||||
{
|
||||
while(eina_accessor_data_get(Handle, position, tmp))
|
||||
while (eina_accessor_data_get(Handle, position, tmp))
|
||||
{
|
||||
IntPtr data = (IntPtr)Marshal.PtrToStructure(tmp, typeof(IntPtr));
|
||||
yield return Convert(data);
|
||||
|
@ -124,11 +128,12 @@ public class Accessor<T> : IEnumerable<T>, IDisposable
|
|||
///<summary>Accessor for Inlists.</summary>
|
||||
public class AccessorInList<T> : Accessor<T>
|
||||
{
|
||||
|
||||
/// <summary>Create a new accessor wrapping the given pointer.</summary>
|
||||
/// <param name="handle">The native handle to be wrapped.</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
|
||||
/// <see cref="System.Collections.Generic.IEnumerator<T>"/>.</summary>
|
||||
|
@ -146,7 +151,9 @@ public class AccessorInArray<T> : Accessor<T>
|
|||
/// <summary>Create a new accessor wrapping the given pointer.</summary>
|
||||
/// <param name="handle">The native handle to be wrapped.</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
|
||||
/// <see cref="System.Collections.Generic.IEnumerator<T>"/>.</summary>
|
||||
|
|
|
@ -7,7 +7,8 @@ using System.Collections.Generic;
|
|||
using static Eina.TraitFunctions;
|
||||
using static Eina.ArrayNativeFunctions;
|
||||
|
||||
namespace Eina {
|
||||
namespace Eina
|
||||
{
|
||||
|
||||
public static class ArrayNativeFunctions
|
||||
{
|
||||
|
@ -64,8 +65,10 @@ public class Array<T> : IEnumerable<T>, IDisposable
|
|||
Own = true;
|
||||
OwnContent = true;
|
||||
if (Handle == IntPtr.Zero)
|
||||
{
|
||||
throw new SEHException("Could not alloc array");
|
||||
}
|
||||
}
|
||||
|
||||
internal bool InternalPush(IntPtr ele)
|
||||
{
|
||||
|
@ -131,20 +134,24 @@ public class Array<T> : IEnumerable<T>, IDisposable
|
|||
IntPtr h = Handle;
|
||||
Handle = IntPtr.Zero;
|
||||
if (h == IntPtr.Zero)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (OwnContent)
|
||||
{
|
||||
int len = (int)eina_array_count_custom_export_mono(h);
|
||||
for(int i = 0; i < len; ++i)
|
||||
for (int i = 0; i < len; ++i)
|
||||
{
|
||||
NativeFree<T>(eina_array_data_get_custom_export_mono(h, (uint)i));
|
||||
}
|
||||
}
|
||||
|
||||
if (Own)
|
||||
{
|
||||
eina_array_free(h);
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
|
@ -169,7 +176,7 @@ public class Array<T> : IEnumerable<T>, IDisposable
|
|||
if (OwnContent)
|
||||
{
|
||||
int len = Length;
|
||||
for(int i = 0; i < len; ++i)
|
||||
for (int i = 0; i < len; ++i)
|
||||
{
|
||||
NativeFree<T>(InternalDataGet(i));
|
||||
}
|
||||
|
@ -190,7 +197,7 @@ public class Array<T> : IEnumerable<T>, IDisposable
|
|||
|
||||
public int Count()
|
||||
{
|
||||
return (int) eina_array_count_custom_export_mono(Handle);
|
||||
return (int)eina_array_count_custom_export_mono(Handle);
|
||||
}
|
||||
|
||||
public void SetOwnership(bool ownAll)
|
||||
|
@ -210,7 +217,10 @@ public class Array<T> : IEnumerable<T>, IDisposable
|
|||
IntPtr ele = ManagedToNativeAlloc(val);
|
||||
var r = InternalPush(ele);
|
||||
if (!r)
|
||||
{
|
||||
NativeFree<T>(ele);
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
|
@ -218,7 +228,9 @@ public class Array<T> : IEnumerable<T>, IDisposable
|
|||
// public void Add(T val)
|
||||
// {
|
||||
// if (!Push(val))
|
||||
// {
|
||||
// throw;
|
||||
// }
|
||||
// }
|
||||
|
||||
public T Pop()
|
||||
|
@ -226,7 +238,10 @@ public class Array<T> : IEnumerable<T>, IDisposable
|
|||
IntPtr ele = InternalPop();
|
||||
var r = NativeToManaged<T>(ele);
|
||||
if (OwnContent && ele != IntPtr.Zero)
|
||||
{
|
||||
NativeFree<T>(ele);
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
|
@ -245,7 +260,10 @@ public class Array<T> : IEnumerable<T>, IDisposable
|
|||
{
|
||||
IntPtr ele = InternalDataGet(idx); // TODO: check bondaries ??
|
||||
if (OwnContent && ele != IntPtr.Zero)
|
||||
{
|
||||
NativeFree<T>(ele);
|
||||
}
|
||||
|
||||
ele = ManagedToNativeAlloc(val);
|
||||
InternalDataSet(idx, ele);
|
||||
}
|
||||
|
@ -266,18 +284,24 @@ public class Array<T> : IEnumerable<T>, IDisposable
|
|||
{
|
||||
int len = Length;
|
||||
var managed = new T[len];
|
||||
for(int i = 0; i < len; ++i)
|
||||
for (int i = 0; i < len; ++i)
|
||||
{
|
||||
managed[i] = DataGet(i);
|
||||
}
|
||||
|
||||
return managed;
|
||||
}
|
||||
|
||||
public bool Append(T[] values)
|
||||
{
|
||||
foreach(T v in values)
|
||||
foreach (T v in values)
|
||||
{
|
||||
if (!Push(v))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -290,7 +314,7 @@ public class Array<T> : IEnumerable<T>, IDisposable
|
|||
public IEnumerator<T> GetEnumerator()
|
||||
{
|
||||
int len = Length;
|
||||
for(int i = 0; i < len; ++i)
|
||||
for (int i = 0; i < len; ++i)
|
||||
{
|
||||
yield return DataGet(i);
|
||||
}
|
||||
|
|
|
@ -3,7 +3,8 @@
|
|||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Eina {
|
||||
namespace Eina
|
||||
{
|
||||
|
||||
public class Binbuf : IDisposable
|
||||
{
|
||||
|
@ -43,7 +44,7 @@ public class Binbuf : IDisposable
|
|||
|
||||
public int Length
|
||||
{
|
||||
get { return (int) GetLength(); }
|
||||
get { return (int)GetLength(); }
|
||||
}
|
||||
|
||||
private void InitNew()
|
||||
|
@ -51,8 +52,10 @@ public class Binbuf : IDisposable
|
|||
Handle = eina_binbuf_new();
|
||||
Own = true;
|
||||
if (Handle == IntPtr.Zero)
|
||||
{
|
||||
throw new SEHException("Could not alloc binbuf");
|
||||
}
|
||||
}
|
||||
|
||||
public Binbuf()
|
||||
{
|
||||
|
@ -98,7 +101,8 @@ public class Binbuf : IDisposable
|
|||
{
|
||||
IntPtr h = Handle;
|
||||
Handle = IntPtr.Zero;
|
||||
if (Own && h != IntPtr.Zero) {
|
||||
if (Own && h != IntPtr.Zero)
|
||||
{
|
||||
eina_binbuf_free(Handle);
|
||||
}
|
||||
}
|
||||
|
@ -180,7 +184,9 @@ public class Binbuf : IDisposable
|
|||
{
|
||||
var ptr = eina_binbuf_string_get(Handle);
|
||||
if (ptr == IntPtr.Zero)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var size = (int)(this.GetLength());
|
||||
byte[] mArray = new byte[size];
|
||||
|
|
|
@ -6,6 +6,7 @@ using System.Runtime.InteropServices;
|
|||
|
||||
namespace Eina
|
||||
{
|
||||
|
||||
namespace Callbacks
|
||||
{
|
||||
|
||||
|
@ -41,7 +42,8 @@ internal static class NativeCustomExportFunctions
|
|||
}
|
||||
|
||||
/// <summary>Wrapper around native memory DllImport'd functions</summary>
|
||||
public static class MemoryNative {
|
||||
public static class MemoryNative
|
||||
{
|
||||
public static void Free(IntPtr ptr)
|
||||
{
|
||||
NativeCustomExportFunctions.efl_mono_native_free(ptr);
|
||||
|
@ -122,7 +124,9 @@ public static class StringConversion
|
|||
public static IntPtr ManagedStringToNativeUtf8Alloc(string managedString)
|
||||
{
|
||||
if (managedString == null)
|
||||
{
|
||||
return IntPtr.Zero;
|
||||
}
|
||||
|
||||
byte[] strbuf = Encoding.UTF8.GetBytes(managedString);
|
||||
IntPtr native = MemoryNative.Alloc(strbuf.Length + 1);
|
||||
|
@ -134,11 +138,15 @@ public static class StringConversion
|
|||
public static string NativeUtf8ToManagedString(IntPtr pNativeData)
|
||||
{
|
||||
if (pNativeData == IntPtr.Zero)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
int len = 0;
|
||||
while (Marshal.ReadByte(pNativeData, len) != 0)
|
||||
{
|
||||
++len;
|
||||
}
|
||||
|
||||
byte[] strbuf = new byte[len];
|
||||
Marshal.Copy(pNativeData, strbuf, 0, strbuf.Length);
|
||||
|
@ -147,7 +155,8 @@ public static class StringConversion
|
|||
}
|
||||
|
||||
/// <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>
|
||||
Managed,
|
||||
/// <summary> The resource is owned by the unmanaged code. It won't be freed on disposal.</summary>
|
||||
|
|
|
@ -3,18 +3,24 @@
|
|||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Eina {
|
||||
namespace Eina
|
||||
{
|
||||
|
||||
public class Config {
|
||||
public class Config
|
||||
{
|
||||
[DllImport(efl.Libs.Eina)] private static extern int eina_init();
|
||||
[DllImport(efl.Libs.Eina)] private static extern int eina_shutdown();
|
||||
|
||||
public static void Init() {
|
||||
public static void Init()
|
||||
{
|
||||
if (eina_init() == 0)
|
||||
{
|
||||
throw (new Efl.EflException("Failed to initialize Eina"));
|
||||
}
|
||||
}
|
||||
|
||||
public static int Shutdown() {
|
||||
public static int Shutdown()
|
||||
{
|
||||
return eina_shutdown();
|
||||
}
|
||||
|
||||
|
@ -24,15 +30,15 @@ public class Config {
|
|||
/// Wrapper class for pointers that need some cleanup afterwards
|
||||
/// like strings.
|
||||
/// </summary>
|
||||
public class DisposableIntPtr : IDisposable {
|
||||
|
||||
public class DisposableIntPtr : IDisposable
|
||||
{
|
||||
public IntPtr Handle { get; set; }
|
||||
private bool ShouldFree;
|
||||
private bool Disposed;
|
||||
|
||||
/// <summary>Wraps a new ptr what will be freed based on the
|
||||
/// value of shouldFree</summary>
|
||||
public DisposableIntPtr(IntPtr ptr, bool shouldFree=false)
|
||||
public DisposableIntPtr(IntPtr ptr, bool shouldFree = false)
|
||||
{
|
||||
Handle = ptr;
|
||||
ShouldFree = shouldFree;
|
||||
|
@ -46,9 +52,11 @@ public class DisposableIntPtr : IDisposable {
|
|||
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
if (!Disposed && ShouldFree) {
|
||||
if (!Disposed && ShouldFree)
|
||||
{
|
||||
MemoryNative.Free(this.Handle);
|
||||
}
|
||||
|
||||
Disposed = true;
|
||||
}
|
||||
|
||||
|
@ -57,4 +65,5 @@ public class DisposableIntPtr : IDisposable {
|
|||
Dispose(false);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -11,9 +11,15 @@ using static Eina.InarrayNativeFunctions;
|
|||
using static Eina.InlistNativeFunctions;
|
||||
using static Eina.NativeCustomExportFunctions;
|
||||
|
||||
namespace Eina {
|
||||
namespace Eina
|
||||
{
|
||||
|
||||
public enum ElementType { NumericType, StringType, ObjectType };
|
||||
public enum ElementType
|
||||
{
|
||||
NumericType,
|
||||
StringType,
|
||||
ObjectType
|
||||
};
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct InlistMem
|
||||
|
@ -82,13 +88,18 @@ public class StringElementTraits : IBaseElementTraits<string>
|
|||
public void NativeFree(IntPtr nat)
|
||||
{
|
||||
if (nat != IntPtr.Zero)
|
||||
{
|
||||
MemoryNative.Free(nat);
|
||||
}
|
||||
}
|
||||
|
||||
public void NativeFreeInlistNodeElement(IntPtr nat)
|
||||
{
|
||||
if (nat == IntPtr.Zero)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var val = Marshal.PtrToStructure<IntPtr>
|
||||
(nat + Marshal.SizeOf<InlistMem>());
|
||||
NativeFree(val);
|
||||
|
@ -97,9 +108,15 @@ public class StringElementTraits : IBaseElementTraits<string>
|
|||
public void NativeFreeInlistNode(IntPtr nat, bool freeElement)
|
||||
{
|
||||
if (nat == IntPtr.Zero)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (freeElement)
|
||||
{
|
||||
NativeFreeInlistNodeElement(nat);
|
||||
}
|
||||
|
||||
MemoryNative.Free(nat);
|
||||
}
|
||||
|
||||
|
@ -115,7 +132,10 @@ public class StringElementTraits : IBaseElementTraits<string>
|
|||
public string NativeToManaged(IntPtr nat)
|
||||
{
|
||||
if (nat == IntPtr.Zero)
|
||||
{
|
||||
return default(string);
|
||||
}
|
||||
|
||||
return StringConversion.NativeUtf8ToManagedString(nat);
|
||||
}
|
||||
|
||||
|
@ -126,6 +146,7 @@ public class StringElementTraits : IBaseElementTraits<string>
|
|||
Eina.Log.Error("Null pointer for Inlist node.");
|
||||
return default(string);
|
||||
}
|
||||
|
||||
IntPtr ptr_location = nat + Marshal.SizeOf<InlistMem>();
|
||||
return NativeToManaged(Marshal.ReadIntPtr(ptr_location));
|
||||
}
|
||||
|
@ -134,10 +155,16 @@ public class StringElementTraits : IBaseElementTraits<string>
|
|||
public string NativeToManagedInplace(IntPtr nat)
|
||||
{
|
||||
if (nat == IntPtr.Zero)
|
||||
{
|
||||
return default(string);
|
||||
}
|
||||
|
||||
nat = Marshal.ReadIntPtr(nat);
|
||||
if (nat == IntPtr.Zero)
|
||||
{
|
||||
return default(string);
|
||||
}
|
||||
|
||||
return NativeToManaged(nat);
|
||||
}
|
||||
|
||||
|
@ -180,7 +207,10 @@ public class EflObjectElementTraits<T> : IBaseElementTraits<T>
|
|||
{
|
||||
IntPtr h = ((Efl.Eo.IWrapper)man).NativeHandle;
|
||||
if (h == IntPtr.Zero)
|
||||
{
|
||||
return h;
|
||||
}
|
||||
|
||||
return Efl.Eo.Globals.efl_ref(h);
|
||||
}
|
||||
|
||||
|
@ -204,19 +234,26 @@ public class EflObjectElementTraits<T> : IBaseElementTraits<T>
|
|||
public void NativeFree(IntPtr nat)
|
||||
{
|
||||
if (nat != IntPtr.Zero)
|
||||
{
|
||||
Efl.Eo.Globals.efl_unref(nat);
|
||||
}
|
||||
}
|
||||
|
||||
public void NativeFreeRef(IntPtr nat, bool unrefs)
|
||||
{
|
||||
if (unrefs)
|
||||
{
|
||||
NativeFree(nat);
|
||||
}
|
||||
}
|
||||
|
||||
public void NativeFreeInlistNodeElement(IntPtr nat)
|
||||
{
|
||||
if (nat == IntPtr.Zero)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var val = Marshal.PtrToStructure<IntPtr>
|
||||
(nat + Marshal.SizeOf<InlistMem>());
|
||||
NativeFree(val);
|
||||
|
@ -225,9 +262,15 @@ public class EflObjectElementTraits<T> : IBaseElementTraits<T>
|
|||
public void NativeFreeInlistNode(IntPtr nat, bool freeElement)
|
||||
{
|
||||
if (nat == IntPtr.Zero)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (freeElement)
|
||||
{
|
||||
NativeFreeInlistNodeElement(nat);
|
||||
}
|
||||
|
||||
MemoryNative.Free(nat);
|
||||
}
|
||||
|
||||
|
@ -243,14 +286,20 @@ public class EflObjectElementTraits<T> : IBaseElementTraits<T>
|
|||
public T NativeToManaged(IntPtr nat)
|
||||
{
|
||||
if (nat == IntPtr.Zero)
|
||||
{
|
||||
return default(T);
|
||||
return (T) Activator.CreateInstance(concreteType, Efl.Eo.Globals.efl_ref(nat));
|
||||
}
|
||||
|
||||
return (T)Activator.CreateInstance(concreteType, Efl.Eo.Globals.efl_ref(nat));
|
||||
}
|
||||
|
||||
public T NativeToManagedRef(IntPtr nat)
|
||||
{
|
||||
if (nat == IntPtr.Zero)
|
||||
{
|
||||
return default(T);
|
||||
}
|
||||
|
||||
return NativeToManaged(nat);
|
||||
}
|
||||
|
||||
|
@ -261,6 +310,7 @@ public class EflObjectElementTraits<T> : IBaseElementTraits<T>
|
|||
Eina.Log.Error("Null pointer for Inlist node.");
|
||||
return default(T);
|
||||
}
|
||||
|
||||
IntPtr ptr_location = nat + Marshal.SizeOf<InlistMem>();
|
||||
return NativeToManaged(Marshal.ReadIntPtr(ptr_location));
|
||||
}
|
||||
|
@ -269,10 +319,16 @@ public class EflObjectElementTraits<T> : IBaseElementTraits<T>
|
|||
public T NativeToManagedInplace(IntPtr nat)
|
||||
{
|
||||
if (nat == IntPtr.Zero)
|
||||
{
|
||||
return default(T);
|
||||
}
|
||||
|
||||
nat = Marshal.ReadIntPtr(nat);
|
||||
if (nat == IntPtr.Zero)
|
||||
{
|
||||
return default(T);
|
||||
}
|
||||
|
||||
return NativeToManaged(nat);
|
||||
}
|
||||
|
||||
|
@ -355,6 +411,7 @@ public abstract class PrimitiveElementTraits<T>
|
|||
Eina.Log.Error("Null pointer on primitive/struct container.");
|
||||
return default(T);
|
||||
}
|
||||
|
||||
return PrimitiveConversion.PointerToManaged<T>(nat);
|
||||
}
|
||||
|
||||
|
@ -371,7 +428,7 @@ public abstract class PrimitiveElementTraits<T>
|
|||
|
||||
private int PrimitiveCompareCb(IntPtr ptr1, IntPtr ptr2)
|
||||
{
|
||||
var m1 = (IComparable) NativeToManaged(ptr1);
|
||||
var m1 = (IComparable)NativeToManaged(ptr1);
|
||||
var m2 = NativeToManaged(ptr2);
|
||||
return m1.CompareTo(m2);
|
||||
}
|
||||
|
@ -379,7 +436,10 @@ public abstract class PrimitiveElementTraits<T>
|
|||
public IntPtr EinaCompareCb()
|
||||
{
|
||||
if (dlgt == null)
|
||||
{
|
||||
dlgt = new Eina_Compare_Cb(PrimitiveCompareCb);
|
||||
}
|
||||
|
||||
return Marshal.GetFunctionPointerForDelegate(dlgt);
|
||||
}
|
||||
|
||||
|
@ -406,11 +466,17 @@ abstract public class Primitive32ElementTraits<T> : PrimitiveElementTraits<T>, I
|
|||
public Primitive32ElementTraits()
|
||||
{
|
||||
if (int32Traits == null)
|
||||
{
|
||||
if (typeof(T) == typeof(Int32)) // avoid infinite recursion
|
||||
{
|
||||
int32Traits = (IBaseElementTraits<Int32>)this;
|
||||
}
|
||||
else
|
||||
{
|
||||
int32Traits = TraitFunctions.GetTypeTraits<Int32>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public abstract void ManagedToNativeCopyTo(T man, IntPtr mem);
|
||||
public abstract T NativeToManagedInlistNode(IntPtr nat);
|
||||
|
@ -438,11 +504,17 @@ abstract public class Primitive64ElementTraits<T> : PrimitiveElementTraits<T>, I
|
|||
public Primitive64ElementTraits()
|
||||
{
|
||||
if (int64Traits == null)
|
||||
{
|
||||
if (typeof(T) == typeof(Int64)) // avoid infinite recursion
|
||||
{
|
||||
int64Traits = (IBaseElementTraits<Int64>)this;
|
||||
}
|
||||
else
|
||||
{
|
||||
int64Traits = TraitFunctions.GetTypeTraits<Int64>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public abstract void ManagedToNativeCopyTo(T man, IntPtr mem);
|
||||
public abstract T NativeToManagedInlistNode(IntPtr nat);
|
||||
|
@ -471,6 +543,7 @@ public class IntElementTraits : Primitive32ElementTraits<int>, IBaseElementTrait
|
|||
arr[0] = man;
|
||||
Marshal.Copy(arr, 0, mem, 1);
|
||||
}
|
||||
|
||||
override public int NativeToManagedInlistNode(IntPtr nat)
|
||||
{
|
||||
if (nat == IntPtr.Zero)
|
||||
|
@ -478,6 +551,7 @@ public class IntElementTraits : Primitive32ElementTraits<int>, IBaseElementTrait
|
|||
Eina.Log.Error("Null pointer for Inlist node.");
|
||||
return default(int);
|
||||
}
|
||||
|
||||
IntPtr loc = nat + Marshal.SizeOf<InlistMem>();
|
||||
var v = new int[1];
|
||||
Marshal.Copy(loc, v, 0, 1);
|
||||
|
@ -493,6 +567,7 @@ public class CharElementTraits : Primitive32ElementTraits<char>, IBaseElementTra
|
|||
arr[0] = man;
|
||||
Marshal.Copy(arr, 0, mem, 1);
|
||||
}
|
||||
|
||||
override public char NativeToManagedInlistNode(IntPtr nat)
|
||||
{
|
||||
if (nat == IntPtr.Zero)
|
||||
|
@ -500,12 +575,14 @@ public class CharElementTraits : Primitive32ElementTraits<char>, IBaseElementTra
|
|||
Eina.Log.Error("Null pointer for Inlist node.");
|
||||
return default(char);
|
||||
}
|
||||
|
||||
IntPtr loc = nat + Marshal.SizeOf<InlistMem>();
|
||||
var v = new char[1];
|
||||
Marshal.Copy(loc, v, 0, 1);
|
||||
return v[0];
|
||||
}
|
||||
}
|
||||
|
||||
public class LongElementTraits : Primitive64ElementTraits<long>, IBaseElementTraits<long>
|
||||
{
|
||||
override public void ManagedToNativeCopyTo(long man, IntPtr mem)
|
||||
|
@ -514,6 +591,7 @@ public class LongElementTraits : Primitive64ElementTraits<long>, IBaseElementTra
|
|||
arr[0] = man;
|
||||
Marshal.Copy(arr, 0, mem, 1);
|
||||
}
|
||||
|
||||
override public long NativeToManagedInlistNode(IntPtr nat)
|
||||
{
|
||||
if (nat == IntPtr.Zero)
|
||||
|
@ -521,6 +599,7 @@ public class LongElementTraits : Primitive64ElementTraits<long>, IBaseElementTra
|
|||
Eina.Log.Error("Null pointer for Inlist node.");
|
||||
return default(long);
|
||||
}
|
||||
|
||||
IntPtr loc = nat + Marshal.SizeOf<InlistMem>();
|
||||
var v = new long[1];
|
||||
Marshal.Copy(loc, v, 0, 1);
|
||||
|
@ -536,6 +615,7 @@ public class ShortElementTraits : Primitive32ElementTraits<short>, IBaseElementT
|
|||
arr[0] = man;
|
||||
Marshal.Copy(arr, 0, mem, 1);
|
||||
}
|
||||
|
||||
override public short NativeToManagedInlistNode(IntPtr nat)
|
||||
{
|
||||
if (nat == IntPtr.Zero)
|
||||
|
@ -543,6 +623,7 @@ public class ShortElementTraits : Primitive32ElementTraits<short>, IBaseElementT
|
|||
Eina.Log.Error("Null pointer for Inlist node.");
|
||||
return default(short);
|
||||
}
|
||||
|
||||
IntPtr loc = nat + Marshal.SizeOf<InlistMem>();
|
||||
var v = new short[1];
|
||||
Marshal.Copy(loc, v, 0, 1);
|
||||
|
@ -558,6 +639,7 @@ public class FloatElementTraits : Primitive32ElementTraits<float>, IBaseElementT
|
|||
arr[0] = man;
|
||||
Marshal.Copy(arr, 0, mem, 1);
|
||||
}
|
||||
|
||||
override public float NativeToManagedInlistNode(IntPtr nat)
|
||||
{
|
||||
if (nat == IntPtr.Zero)
|
||||
|
@ -565,6 +647,7 @@ public class FloatElementTraits : Primitive32ElementTraits<float>, IBaseElementT
|
|||
Eina.Log.Error("Null pointer for Inlist node.");
|
||||
return default(float);
|
||||
}
|
||||
|
||||
IntPtr loc = nat + Marshal.SizeOf<InlistMem>();
|
||||
var v = new float[1];
|
||||
Marshal.Copy(loc, v, 0, 1);
|
||||
|
@ -580,6 +663,7 @@ public class DoubleElementTraits : Primitive64ElementTraits<double>, IBaseElemen
|
|||
arr[0] = man;
|
||||
Marshal.Copy(arr, 0, mem, 1);
|
||||
}
|
||||
|
||||
override public double NativeToManagedInlistNode(IntPtr nat)
|
||||
{
|
||||
if (nat == IntPtr.Zero)
|
||||
|
@ -587,6 +671,7 @@ public class DoubleElementTraits : Primitive64ElementTraits<double>, IBaseElemen
|
|||
Eina.Log.Error("Null pointer for Inlist node.");
|
||||
return default(double);
|
||||
}
|
||||
|
||||
IntPtr loc = nat + Marshal.SizeOf<InlistMem>();
|
||||
var v = new double[1];
|
||||
Marshal.Copy(loc, v, 0, 1);
|
||||
|
@ -602,6 +687,7 @@ public class ByteElementTraits : Primitive32ElementTraits<byte>, IBaseElementTra
|
|||
arr[0] = man;
|
||||
Marshal.Copy(arr, 0, mem, 1);
|
||||
}
|
||||
|
||||
override public byte NativeToManagedInlistNode(IntPtr nat)
|
||||
{
|
||||
if (nat == IntPtr.Zero)
|
||||
|
@ -609,6 +695,7 @@ public class ByteElementTraits : Primitive32ElementTraits<byte>, IBaseElementTra
|
|||
Eina.Log.Error("Null pointer for Inlist node.");
|
||||
return default(byte);
|
||||
}
|
||||
|
||||
IntPtr loc = nat + Marshal.SizeOf<InlistMem>();
|
||||
var v = new byte[1];
|
||||
Marshal.Copy(loc, v, 0, 1);
|
||||
|
@ -631,19 +718,27 @@ public static class TraitFunctions
|
|||
public static Eina.ElementType GetElementTypeCode(System.Type type)
|
||||
{
|
||||
if (IsEflObject(type))
|
||||
{
|
||||
return ElementType.ObjectType;
|
||||
}
|
||||
else if (IsString(type))
|
||||
{
|
||||
return ElementType.StringType;
|
||||
}
|
||||
else
|
||||
{
|
||||
return ElementType.NumericType;
|
||||
}
|
||||
}
|
||||
|
||||
private static IDictionary<System.Type, object> register = new Dictionary<System.Type, object>();
|
||||
|
||||
private static System.Type AsEflInstantiableType(System.Type type)
|
||||
{
|
||||
if (!IsEflObject(type))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
if (type.IsInterface)
|
||||
{
|
||||
|
@ -663,32 +758,55 @@ public static class TraitFunctions
|
|||
{
|
||||
System.Type concrete = AsEflInstantiableType(type);
|
||||
if (concrete == null || !type.IsAssignableFrom(concrete))
|
||||
{
|
||||
throw new Exception("Failed to get a suitable concrete class for this type.");
|
||||
}
|
||||
|
||||
traits = new EflObjectElementTraits<T>(concrete);
|
||||
}
|
||||
else if (IsString(type))
|
||||
{
|
||||
traits = new StringElementTraits();
|
||||
}
|
||||
else if (type.IsValueType)
|
||||
{
|
||||
if (type == typeof(int))
|
||||
{
|
||||
traits = new IntElementTraits();
|
||||
}
|
||||
else if (type == typeof(char))
|
||||
{
|
||||
traits = new CharElementTraits();
|
||||
}
|
||||
else if (type == typeof(long))
|
||||
{
|
||||
traits = new LongElementTraits();
|
||||
}
|
||||
else if (type == typeof(short))
|
||||
{
|
||||
traits = new ShortElementTraits();
|
||||
}
|
||||
else if (type == typeof(float))
|
||||
{
|
||||
traits = new FloatElementTraits();
|
||||
}
|
||||
else if (type == typeof(double))
|
||||
{
|
||||
traits = new DoubleElementTraits();
|
||||
}
|
||||
else if (type == typeof(byte))
|
||||
{
|
||||
traits = new ByteElementTraits();
|
||||
else
|
||||
throw new Exception("No traits registered for this type");
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("No traits registered for this type");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("No traits registered for this type");
|
||||
}
|
||||
|
||||
register[type] = traits;
|
||||
return traits;
|
||||
|
@ -704,8 +822,11 @@ public static class TraitFunctions
|
|||
{
|
||||
object traits;
|
||||
if (!register.TryGetValue(typeof(T), out traits))
|
||||
{
|
||||
traits = RegisterTypeTraits<T>();
|
||||
return (IBaseElementTraits<T>) traits;
|
||||
}
|
||||
|
||||
return (IBaseElementTraits<T>)traits;
|
||||
}
|
||||
|
||||
// //
|
||||
|
|
|
@ -3,7 +3,8 @@
|
|||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Eina {
|
||||
namespace Eina
|
||||
{
|
||||
|
||||
public struct Error : IComparable<Error>
|
||||
{
|
||||
|
@ -21,19 +22,26 @@ public struct Error : IComparable<Error>
|
|||
public static Error ENOENT = new Error(2);
|
||||
public static Error ECANCELED = new Error(125);
|
||||
|
||||
public Error(int value) { code = value; }
|
||||
public Error(int value)
|
||||
{
|
||||
code = value;
|
||||
}
|
||||
|
||||
static public implicit operator Error(int val)
|
||||
{
|
||||
return new Error(val);
|
||||
}
|
||||
|
||||
static public implicit operator int(Error error)
|
||||
{
|
||||
return error.code;
|
||||
}
|
||||
|
||||
public int CompareTo(Error err)
|
||||
{
|
||||
return code.CompareTo(err.code);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return "Eina.Error(" + code + ")";
|
||||
|
@ -80,8 +88,10 @@ public struct Error : IComparable<Error>
|
|||
public static void Raise(Error e)
|
||||
{
|
||||
if (e != 0)
|
||||
{
|
||||
throw (new Efl.EflException(MsgGet(e)));
|
||||
}
|
||||
}
|
||||
|
||||
public static void Clear()
|
||||
{
|
||||
|
@ -93,4 +103,5 @@ public struct Error : IComparable<Error>
|
|||
return eina_error_msg_register(msg);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -137,8 +137,10 @@ public class Hash<TKey, TValue> : IEnumerable<KeyValuePair<TKey, TValue>>, IDi
|
|||
public bool OwnKey {get; set;}
|
||||
public bool OwnValue {get; set;}
|
||||
|
||||
public int Count {
|
||||
get {
|
||||
public int Count
|
||||
{
|
||||
get
|
||||
{
|
||||
return Population();
|
||||
}
|
||||
}
|
||||
|
@ -179,11 +181,15 @@ public class Hash<TKey, TValue> : IEnumerable<KeyValuePair<TKey, TValue>>, IDi
|
|||
IntPtr h = Handle;
|
||||
Handle = IntPtr.Zero;
|
||||
if (h == IntPtr.Zero)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (Own)
|
||||
{
|
||||
eina_hash_free(h);
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
|
@ -218,8 +224,10 @@ public class Hash<TKey, TValue> : IEnumerable<KeyValuePair<TKey, TValue>>, IDi
|
|||
OwnValue = ownValue;
|
||||
|
||||
if (ownValue)
|
||||
{
|
||||
eina_hash_free_cb_set(Handle, EinaFreeCb<TValue>());
|
||||
}
|
||||
}
|
||||
|
||||
public void SetOwnership(bool ownAll)
|
||||
{
|
||||
|
@ -289,7 +297,9 @@ public class Hash<TKey, TValue> : IEnumerable<KeyValuePair<TKey, TValue>>, IDi
|
|||
//NativeFreeRef<TKey>(nk);
|
||||
FreeNativeIndirection<TKey>(gchnk, ForceRefKey<TKey>());
|
||||
if (found == IntPtr.Zero)
|
||||
{
|
||||
throw new KeyNotFoundException();
|
||||
}
|
||||
|
||||
return NativeToManaged<TValue>(IndirectNative<TValue>(found, false));
|
||||
}
|
||||
|
@ -305,6 +315,7 @@ public class Hash<TKey, TValue> : IEnumerable<KeyValuePair<TKey, TValue>>, IDi
|
|||
val = default(TValue);
|
||||
return false;
|
||||
}
|
||||
|
||||
val = NativeToManaged<TValue>(IndirectNative<TValue>(found, false));
|
||||
return true;
|
||||
}
|
||||
|
@ -334,8 +345,12 @@ public class Hash<TKey, TValue> : IEnumerable<KeyValuePair<TKey, TValue>>, IDi
|
|||
NativeFree<TValue>(nv);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (OwnValue)
|
||||
{
|
||||
NativeFree<TValue>(old);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -355,7 +370,7 @@ public class Hash<TKey, TValue> : IEnumerable<KeyValuePair<TKey, TValue>>, IDi
|
|||
|
||||
return GCHandle.ToIntPtr(gch);
|
||||
}
|
||||
else if(IsEflObject(typeof(T)) && forceRef)
|
||||
else if (IsEflObject(typeof(T)) && forceRef)
|
||||
{
|
||||
GCHandle gch = GCHandle.Alloc(new byte[Marshal.SizeOf<IntPtr>()], GCHandleType.Pinned);
|
||||
IntPtr pin = gch.AddrOfPinnedObject();
|
||||
|
@ -369,6 +384,7 @@ public class Hash<TKey, TValue> : IEnumerable<KeyValuePair<TKey, TValue>>, IDi
|
|||
return ManagedToNativeAlloc(value);
|
||||
}
|
||||
}
|
||||
|
||||
private static IntPtr GetNativePtr<T>(IntPtr gchptr, bool forceRef)
|
||||
{
|
||||
if (forceRef)
|
||||
|
@ -383,6 +399,7 @@ public class Hash<TKey, TValue> : IEnumerable<KeyValuePair<TKey, TValue>>, IDi
|
|||
return gchptr;
|
||||
}
|
||||
}
|
||||
|
||||
private static void FreeNativeIndirection<T>(IntPtr gchptr, bool forceRef)
|
||||
{
|
||||
if (forceRef)
|
||||
|
@ -416,8 +433,10 @@ public class Hash<TKey, TValue> : IEnumerable<KeyValuePair<TKey, TValue>>, IDi
|
|||
FreeNativeIndirection<TKey>(gchnk, ForceRefKey<TKey>());
|
||||
FreeNativeIndirection<TValue>(gchnv, false);
|
||||
if (OwnValue || old != IntPtr.Zero)
|
||||
{
|
||||
NativeFree<TValue>(old);
|
||||
}
|
||||
}
|
||||
|
||||
public TValue this[TKey key]
|
||||
{
|
||||
|
@ -494,4 +513,3 @@ public class Hash<TKey, TValue> : IEnumerable<KeyValuePair<TKey, TValue>>, IDi
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -7,7 +7,8 @@ using System.Collections.Generic;
|
|||
using static Eina.TraitFunctions;
|
||||
using static Eina.InarrayNativeFunctions;
|
||||
|
||||
namespace Eina {
|
||||
namespace Eina
|
||||
{
|
||||
|
||||
public static class InarrayNativeFunctions
|
||||
{
|
||||
|
@ -86,8 +87,10 @@ public class Inarray<T> : IEnumerable<T>, IDisposable
|
|||
Own = true;
|
||||
OwnContent = true;
|
||||
if (Handle == IntPtr.Zero)
|
||||
{
|
||||
throw new SEHException("Could not alloc inarray");
|
||||
}
|
||||
}
|
||||
|
||||
public Inarray()
|
||||
{
|
||||
|
@ -123,20 +126,24 @@ public class Inarray<T> : IEnumerable<T>, IDisposable
|
|||
IntPtr h = Handle;
|
||||
Handle = IntPtr.Zero;
|
||||
if (h == IntPtr.Zero)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (OwnContent)
|
||||
{
|
||||
uint len = eina_inarray_count(h);
|
||||
for(uint i = 0; i < len; ++i)
|
||||
for (uint i = 0; i < len; ++i)
|
||||
{
|
||||
NativeFreeInplace<T>(eina_inarray_nth(h, i));
|
||||
}
|
||||
}
|
||||
|
||||
if (Own)
|
||||
{
|
||||
eina_inarray_free(h);
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
|
@ -176,7 +183,7 @@ public class Inarray<T> : IEnumerable<T>, IDisposable
|
|||
|
||||
public int Count()
|
||||
{
|
||||
return (int) eina_inarray_count(Handle);
|
||||
return (int)eina_inarray_count(Handle);
|
||||
}
|
||||
|
||||
public void SetOwnership(bool ownAll)
|
||||
|
@ -201,7 +208,10 @@ public class Inarray<T> : IEnumerable<T>, IDisposable
|
|||
|
||||
var r = eina_inarray_push(Handle, ind);
|
||||
if (r == -1)
|
||||
{
|
||||
NativeFreeInplace<T>(ele);
|
||||
}
|
||||
|
||||
ResidueFreeInplace<T>(ele);
|
||||
gch.Free();
|
||||
return r;
|
||||
|
@ -211,7 +221,9 @@ public class Inarray<T> : IEnumerable<T>, IDisposable
|
|||
// public void Add(T val)
|
||||
// {
|
||||
// if (!Push(val))
|
||||
// {
|
||||
// throw;
|
||||
// }
|
||||
// }
|
||||
|
||||
public T Pop()
|
||||
|
@ -219,7 +231,10 @@ public class Inarray<T> : IEnumerable<T>, IDisposable
|
|||
IntPtr ele = eina_inarray_pop(Handle);
|
||||
var r = NativeToManagedInplace<T>(ele);
|
||||
if (OwnContent && ele != IntPtr.Zero)
|
||||
{
|
||||
NativeFreeInplace<T>(ele);
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
|
@ -244,7 +259,10 @@ public class Inarray<T> : IEnumerable<T>, IDisposable
|
|||
|
||||
var r = eina_inarray_insert_at(Handle, idx, ind);
|
||||
if (!r)
|
||||
{
|
||||
NativeFreeInplace<T>(ele);
|
||||
}
|
||||
|
||||
ResidueFreeInplace<T>(ele);
|
||||
return r;
|
||||
}
|
||||
|
@ -253,9 +271,15 @@ public class Inarray<T> : IEnumerable<T>, IDisposable
|
|||
{
|
||||
var old = eina_inarray_nth(Handle, idx);
|
||||
if (old == IntPtr.Zero)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (OwnContent)
|
||||
{
|
||||
NativeFreeInplace<T>(old);
|
||||
}
|
||||
|
||||
var ele = IntPtr.Zero;
|
||||
GCHandle gch = GCHandle.Alloc(ele, GCHandleType.Pinned);
|
||||
IntPtr ind = gch.AddrOfPinnedObject();
|
||||
|
@ -283,9 +307,14 @@ public class Inarray<T> : IEnumerable<T>, IDisposable
|
|||
{
|
||||
IntPtr ele = eina_inarray_nth(Handle, idx);
|
||||
if (ele == IntPtr.Zero)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (OwnContent)
|
||||
{
|
||||
NativeFreeInplace<T>(ele);
|
||||
}
|
||||
|
||||
return eina_inarray_remove_at(Handle, idx);
|
||||
}
|
||||
|
@ -299,18 +328,24 @@ public class Inarray<T> : IEnumerable<T>, IDisposable
|
|||
{
|
||||
int len = Length;
|
||||
var managed = new T[len];
|
||||
for(int i = 0; i < len; ++i)
|
||||
for (int i = 0; i < len; ++i)
|
||||
{
|
||||
managed[i] = At(i);
|
||||
}
|
||||
|
||||
return managed;
|
||||
}
|
||||
|
||||
public bool Append(T[] values)
|
||||
{
|
||||
foreach(T v in values)
|
||||
foreach (T v in values)
|
||||
{
|
||||
if (Push(v) == -1)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -327,7 +362,7 @@ public class Inarray<T> : IEnumerable<T>, IDisposable
|
|||
public IEnumerator<T> GetEnumerator()
|
||||
{
|
||||
int len = Length;
|
||||
for(int i = 0; i < len; ++i)
|
||||
for (int i = 0; i < len; ++i)
|
||||
{
|
||||
yield return At(i);
|
||||
}
|
||||
|
|
|
@ -8,7 +8,8 @@ using static Eina.TraitFunctions;
|
|||
using static Eina.InlistNativeFunctions;
|
||||
using Eina.Callbacks;
|
||||
|
||||
namespace Eina {
|
||||
namespace Eina
|
||||
{
|
||||
|
||||
public static class InlistNativeFunctions
|
||||
{
|
||||
|
@ -111,11 +112,16 @@ public class Inlist<T> : IEnumerable<T>, IDisposable
|
|||
private IntPtr InternalAt(int idx)
|
||||
{
|
||||
if (idx < 0)
|
||||
{
|
||||
return IntPtr.Zero;
|
||||
}
|
||||
|
||||
IntPtr curr = Handle;
|
||||
for (int n = 0; n != idx && curr != IntPtr.Zero; ++n)
|
||||
{
|
||||
curr = InternalNext(curr);
|
||||
}
|
||||
|
||||
return curr;
|
||||
}
|
||||
|
||||
|
@ -159,11 +165,13 @@ public class Inlist<T> : IEnumerable<T>, IDisposable
|
|||
IntPtr h = Handle;
|
||||
Handle = IntPtr.Zero;
|
||||
if (h == IntPtr.Zero)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (OwnContent)
|
||||
{
|
||||
for(IntPtr curr = h; curr != IntPtr.Zero; curr = InternalNext(curr))
|
||||
for (IntPtr curr = h; curr != IntPtr.Zero; curr = InternalNext(curr))
|
||||
{
|
||||
NativeFreeInlistNodeElement<T>(curr);
|
||||
}
|
||||
|
@ -212,7 +220,7 @@ public class Inlist<T> : IEnumerable<T>, IDisposable
|
|||
|
||||
public int Count()
|
||||
{
|
||||
return (int) eina_inlist_count(Handle);
|
||||
return (int)eina_inlist_count(Handle);
|
||||
}
|
||||
|
||||
public void Clean()
|
||||
|
@ -248,7 +256,10 @@ public class Inlist<T> : IEnumerable<T>, IDisposable
|
|||
{
|
||||
IntPtr node = InternalAt(idx);
|
||||
if (node == IntPtr.Zero)
|
||||
{
|
||||
throw new IndexOutOfRangeException();
|
||||
}
|
||||
|
||||
return NativeToManagedInlistNode<T>(node);
|
||||
}
|
||||
|
||||
|
@ -256,7 +267,9 @@ public class Inlist<T> : IEnumerable<T>, IDisposable
|
|||
{
|
||||
IntPtr old = InternalAt(idx);
|
||||
if (old == IntPtr.Zero)
|
||||
{
|
||||
throw new IndexOutOfRangeException();
|
||||
}
|
||||
|
||||
IntPtr new_node = ManagedToNativeAllocInlistNode(val);
|
||||
|
||||
|
@ -282,18 +295,21 @@ public class Inlist<T> : IEnumerable<T>, IDisposable
|
|||
{
|
||||
var managed = new T[Count()];
|
||||
int i = 0;
|
||||
for(IntPtr curr = Handle; curr != IntPtr.Zero; ++i, curr = InternalNext(curr))
|
||||
for (IntPtr curr = Handle; curr != IntPtr.Zero; ++i, curr = InternalNext(curr))
|
||||
{
|
||||
managed[i] = NativeToManagedInlistNode<T>(curr);
|
||||
}
|
||||
|
||||
return managed;
|
||||
}
|
||||
|
||||
public void AppendArray(T[] values)
|
||||
{
|
||||
foreach (T v in values)
|
||||
{
|
||||
Append(v);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public Eina.Iterator<T> GetIterator()
|
||||
|
@ -303,7 +319,7 @@ public class Inlist<T> : IEnumerable<T>, IDisposable
|
|||
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -7,7 +7,8 @@ using System.Collections.Generic;
|
|||
using static Eina.TraitFunctions;
|
||||
using static Eina.IteratorNativeFunctions;
|
||||
|
||||
namespace Eina {
|
||||
namespace Eina
|
||||
{
|
||||
|
||||
public static class IteratorNativeFunctions
|
||||
{
|
||||
|
@ -58,19 +59,23 @@ public class Iterator<T> : IEnumerable<T>, IDisposable
|
|||
var h = Handle;
|
||||
Handle = IntPtr.Zero;
|
||||
if (h == IntPtr.Zero)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (OwnContent)
|
||||
{
|
||||
for(IntPtr data; eina_iterator_next(h, out data);)
|
||||
for (IntPtr data; eina_iterator_next(h, out data);)
|
||||
{
|
||||
NativeFree<T>(data);
|
||||
}
|
||||
}
|
||||
|
||||
if (Own)
|
||||
{
|
||||
eina_iterator_free(h);
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
|
@ -114,7 +119,9 @@ public class Iterator<T> : IEnumerable<T>, IDisposable
|
|||
res = NativeToManaged<T>(data);
|
||||
|
||||
if (OwnContent)
|
||||
{
|
||||
NativeFree<T>(data);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -131,7 +138,7 @@ public class Iterator<T> : IEnumerable<T>, IDisposable
|
|||
|
||||
public IEnumerator<T> GetEnumerator()
|
||||
{
|
||||
for(T curr; Next(out curr);)
|
||||
for (T curr; Next(out curr);)
|
||||
{
|
||||
yield return curr;
|
||||
}
|
||||
|
|
|
@ -8,7 +8,8 @@ using static Eina.TraitFunctions;
|
|||
using static Eina.ListNativeFunctions;
|
||||
using Eina.Callbacks;
|
||||
|
||||
namespace Eina {
|
||||
namespace Eina
|
||||
{
|
||||
|
||||
public static class ListNativeFunctions
|
||||
{
|
||||
|
@ -175,19 +176,23 @@ public class List<T> : IEnumerable<T>, IDisposable
|
|||
IntPtr h = Handle;
|
||||
Handle = IntPtr.Zero;
|
||||
if (h == IntPtr.Zero)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (OwnContent)
|
||||
{
|
||||
for(IntPtr curr = h; curr != IntPtr.Zero; curr = InternalNext(curr))
|
||||
for (IntPtr curr = h; curr != IntPtr.Zero; curr = InternalNext(curr))
|
||||
{
|
||||
NativeFree<T>(InternalDataGet(curr));
|
||||
}
|
||||
}
|
||||
|
||||
if (Own)
|
||||
{
|
||||
eina_list_free(h);
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
|
@ -221,7 +226,7 @@ public class List<T> : IEnumerable<T>, IDisposable
|
|||
|
||||
public int Count()
|
||||
{
|
||||
return (int) eina_list_count_custom_export_mono(Handle);
|
||||
return (int)eina_list_count_custom_export_mono(Handle);
|
||||
}
|
||||
|
||||
public void Append(T val)
|
||||
|
@ -274,9 +279,15 @@ public class List<T> : IEnumerable<T>, IDisposable
|
|||
{
|
||||
IntPtr pos = eina_list_nth_list(Handle, (uint)idx);
|
||||
if (pos == IntPtr.Zero)
|
||||
{
|
||||
throw new IndexOutOfRangeException();
|
||||
}
|
||||
|
||||
if (OwnContent)
|
||||
{
|
||||
NativeFree<T>(InternalDataGet(pos));
|
||||
}
|
||||
|
||||
IntPtr ele = ManagedToNativeAlloc(val);
|
||||
InternalDataSet(pos, ele);
|
||||
}
|
||||
|
@ -314,18 +325,21 @@ public class List<T> : IEnumerable<T>, IDisposable
|
|||
{
|
||||
var managed = new T[Count()];
|
||||
int i = 0;
|
||||
for(IntPtr curr = Handle; curr != IntPtr.Zero; curr = InternalNext(curr), ++i)
|
||||
for (IntPtr curr = Handle; curr != IntPtr.Zero; curr = InternalNext(curr), ++i)
|
||||
{
|
||||
managed[i] = NativeToManaged<T>(InternalDataGet(curr));
|
||||
}
|
||||
|
||||
return managed;
|
||||
}
|
||||
|
||||
public void AppendArray(T[] values)
|
||||
{
|
||||
foreach (T v in values)
|
||||
{
|
||||
Append(v);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public Eina.Iterator<T> GetIterator()
|
||||
|
@ -340,7 +354,7 @@ public class List<T> : IEnumerable<T>, IDisposable
|
|||
|
||||
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));
|
||||
}
|
||||
|
|
|
@ -5,7 +5,9 @@ using System.Runtime.InteropServices;
|
|||
using System.Runtime.CompilerServices;
|
||||
using System.Diagnostics.Contracts;
|
||||
|
||||
namespace Eina { // Manual wrappers around eina functions
|
||||
namespace Eina
|
||||
{
|
||||
// Manual wrappers around eina functions
|
||||
|
||||
public class Log
|
||||
{
|
||||
|
@ -55,44 +57,54 @@ public class Log
|
|||
|
||||
static Log()
|
||||
{
|
||||
const String name="mono";
|
||||
const String color="\033[32;1m";
|
||||
const String name = "mono";
|
||||
const String color = "\033[32;1m";
|
||||
|
||||
// Maybe move this check outside when other eina stuff get support?
|
||||
domain = eina_log_domain_register(name, color);
|
||||
if (domain < 0)
|
||||
{
|
||||
Console.WriteLine("Error: Couldn't register Eina log domain for name {0}.", name);
|
||||
}
|
||||
else
|
||||
{
|
||||
Info($"Registered mono domain with number {domain}");
|
||||
}
|
||||
}
|
||||
|
||||
private static void EnsureDomainRegistered()
|
||||
{
|
||||
if (domain < 0)
|
||||
{
|
||||
throw new InvalidOperationException("Log domain is not registered.");
|
||||
}
|
||||
}
|
||||
|
||||
public static void Critical(String message, [CallerLineNumber] int line=0, [CallerFilePath] string file=null, [CallerMemberName] string member = null)
|
||||
public static void Critical(String message, [CallerLineNumber] int line = 0, [CallerFilePath] string file = null, [CallerMemberName] string member = null)
|
||||
{
|
||||
EnsureDomainRegistered();
|
||||
eina_log_print(domain, Level.Critical, file, member, line, message);
|
||||
}
|
||||
public static void Error(String message, [CallerLineNumber] int line=0, [CallerFilePath] string file=null, [CallerMemberName] string member = null)
|
||||
|
||||
public static void Error(String message, [CallerLineNumber] int line = 0, [CallerFilePath] string file = null, [CallerMemberName] string member = null)
|
||||
{
|
||||
EnsureDomainRegistered();
|
||||
eina_log_print(domain, Level.Error, file, member, line, message);
|
||||
}
|
||||
public static void Warning(String message, [CallerLineNumber] int line=0, [CallerFilePath] string file=null, [CallerMemberName] string member = null)
|
||||
|
||||
public static void Warning(String message, [CallerLineNumber] int line = 0, [CallerFilePath] string file = null, [CallerMemberName] string member = null)
|
||||
{
|
||||
EnsureDomainRegistered();
|
||||
eina_log_print(domain, Level.Warning, file, member, line, message);
|
||||
}
|
||||
public static void Info(String message, [CallerLineNumber] int line=0, [CallerFilePath] string file=null, [CallerMemberName] string member = null)
|
||||
|
||||
public static void Info(String message, [CallerLineNumber] int line = 0, [CallerFilePath] string file = null, [CallerMemberName] string member = null)
|
||||
{
|
||||
EnsureDomainRegistered();
|
||||
eina_log_print(domain, Level.Info, file, member, line, message);
|
||||
}
|
||||
public static void Debug(String message, [CallerLineNumber] int line=0, [CallerFilePath] string file=null, [CallerMemberName] string member = null)
|
||||
|
||||
public static void Debug(String message, [CallerLineNumber] int line = 0, [CallerFilePath] string file = null, [CallerMemberName] string member = null)
|
||||
{
|
||||
EnsureDomainRegistered();
|
||||
eina_log_print(domain, Level.Debug, file, member, line, message);
|
||||
|
@ -108,4 +120,5 @@ public class Log
|
|||
return eina_log_level_get();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -6,9 +6,11 @@ using System.Linq;
|
|||
|
||||
using static Eina.EinaNative.PromiseNativeMethods;
|
||||
|
||||
namespace Eina {
|
||||
namespace Eina
|
||||
{
|
||||
|
||||
namespace EinaNative {
|
||||
namespace EinaNative
|
||||
{
|
||||
|
||||
static internal class PromiseNativeMethods
|
||||
{
|
||||
|
@ -80,7 +82,7 @@ public class Promise : IDisposable
|
|||
/// Currently, creating a promise directly uses the Main Loop scheduler the source of notifications (i.e. the
|
||||
/// future callbacks will be called mainly from a loop iteration).
|
||||
/// </summary>
|
||||
public Promise(CancelCb cancelCb=null)
|
||||
public Promise(CancelCb cancelCb = null)
|
||||
{
|
||||
Efl.Loop loop = Efl.App.AppMain;
|
||||
|
||||
|
@ -90,10 +92,13 @@ public class Promise : IDisposable
|
|||
IntPtr cb_data = IntPtr.Zero;
|
||||
|
||||
// A safety clean callback to mark this wrapper as invalid
|
||||
CancelCb safetyCb = () => {
|
||||
CancelCb safetyCb = () =>
|
||||
{
|
||||
Handle = IntPtr.Zero;
|
||||
if (cancelCb != null)
|
||||
{
|
||||
cancelCb();
|
||||
}
|
||||
};
|
||||
|
||||
CleanupHandle = GCHandle.Alloc(safetyCb);
|
||||
|
@ -105,14 +110,21 @@ public class Promise : IDisposable
|
|||
private static void NativeCancelCb(IntPtr data, IntPtr dead)
|
||||
{
|
||||
if (data == IntPtr.Zero)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
GCHandle handle = GCHandle.FromIntPtr(data);
|
||||
CancelCb cb = handle.Target as CancelCb;
|
||||
if (cb != null)
|
||||
{
|
||||
cb();
|
||||
}
|
||||
else
|
||||
{
|
||||
Eina.Log.Info("Null promise CancelCb found");
|
||||
}
|
||||
|
||||
handle.Free();
|
||||
}
|
||||
|
||||
|
@ -144,8 +156,10 @@ public class Promise : IDisposable
|
|||
private void SanityChecks()
|
||||
{
|
||||
if (this.Handle == IntPtr.Zero)
|
||||
{
|
||||
throw new ObjectDisposedException(GetType().Name);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Fulfills a promise with the given value.
|
||||
|
@ -200,7 +214,8 @@ public class Future
|
|||
/// </summary>
|
||||
public Future(IntPtr handle)
|
||||
{
|
||||
Handle = ThenRaw(handle, (Eina.Value value) => {
|
||||
Handle = ThenRaw(handle, (Eina.Value value) =>
|
||||
{
|
||||
Handle = IntPtr.Zero;
|
||||
return value;
|
||||
});
|
||||
|
@ -212,12 +227,16 @@ public class Future
|
|||
/// Optionally a resolved callback may be provided. If so, it will be chained
|
||||
/// before the returned future.
|
||||
/// </summary>
|
||||
public Future(Promise promise, ResolvedCb cb=null)
|
||||
public Future(Promise promise, ResolvedCb cb = null)
|
||||
{
|
||||
IntPtr intermediate = eina_future_new(promise.Handle);
|
||||
Handle = ThenRaw(intermediate, (Eina.Value value) => {
|
||||
Handle = ThenRaw(intermediate, (Eina.Value value) =>
|
||||
{
|
||||
if (cb != null)
|
||||
{
|
||||
value = cb(value);
|
||||
}
|
||||
|
||||
Handle = IntPtr.Zero;
|
||||
return value;
|
||||
});
|
||||
|
@ -226,8 +245,10 @@ public class Future
|
|||
private void SanityChecks()
|
||||
{
|
||||
if (this.Handle == IntPtr.Zero)
|
||||
{
|
||||
throw new ObjectDisposedException(GetType().Name);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Cancels this future and the chain it belongs to, along with the promise linked against it.
|
||||
|
@ -266,14 +287,20 @@ public class Future
|
|||
desc.data = GCHandle.ToIntPtr(handle);
|
||||
return eina_future_then_from_desc(previous, desc);
|
||||
}
|
||||
|
||||
private static Eina.ValueNative NativeResolvedCb(IntPtr data, Eina.ValueNative value, IntPtr dead_future)
|
||||
{
|
||||
GCHandle handle = GCHandle.FromIntPtr(data);
|
||||
ResolvedCb cb = handle.Target as ResolvedCb;
|
||||
if (cb != null)
|
||||
{
|
||||
value = cb(value);
|
||||
}
|
||||
else
|
||||
{
|
||||
Eina.Log.Warning("Failed to get future callback.");
|
||||
}
|
||||
|
||||
handle.Free();
|
||||
return value;
|
||||
}
|
||||
|
@ -308,14 +335,18 @@ public class Future
|
|||
for (int j = 0; j <= i; j++)
|
||||
{
|
||||
if (descs[i].data == IntPtr.Zero)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
GCHandle handle = GCHandle.FromIntPtr(descs[i].data);
|
||||
handle.Free();
|
||||
}
|
||||
|
||||
Eina.Log.Error($"Failed to create native future description for callbacks. Error: {e.ToString()}");
|
||||
return null;
|
||||
}
|
||||
|
||||
return new Future(eina_future_chain_array(Handle, descs));
|
||||
}
|
||||
}
|
||||
|
@ -341,17 +372,24 @@ public class FutureMarshaler : ICustomMarshaler
|
|||
{
|
||||
Future f = managedObj as Future;
|
||||
if (f == null)
|
||||
{
|
||||
return IntPtr.Zero;
|
||||
}
|
||||
|
||||
return f.Handle;
|
||||
}
|
||||
|
||||
///<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>
|
||||
public void CleanUpNativeData(IntPtr pNativeData) { }
|
||||
public void CleanUpNativeData(IntPtr pNativeData)
|
||||
{
|
||||
}
|
||||
|
||||
///<summary>Not implemented. The runtime takes care of releasing it.</summary>
|
||||
///<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>
|
||||
///<returns>The size of the data.</returns>
|
||||
|
@ -363,9 +401,13 @@ public class FutureMarshaler : ICustomMarshaler
|
|||
///<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>
|
||||
///<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)
|
||||
{
|
||||
marshaler = new FutureMarshaler();
|
||||
}
|
||||
|
||||
return marshaler;
|
||||
}
|
||||
|
||||
|
|
|
@ -3,7 +3,8 @@
|
|||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Eina {
|
||||
namespace Eina
|
||||
{
|
||||
|
||||
public interface ISliceBase
|
||||
{
|
||||
|
@ -21,8 +22,8 @@ public struct Slice : ISliceBase
|
|||
|
||||
public int Length
|
||||
{
|
||||
get { return (int) Len; }
|
||||
set { Len = (UIntPtr) value; }
|
||||
get { return (int)Len; }
|
||||
set { Len = (UIntPtr)value; }
|
||||
}
|
||||
|
||||
public Slice(IntPtr mem, UIntPtr len)
|
||||
|
@ -47,8 +48,8 @@ public struct RwSlice : ISliceBase
|
|||
|
||||
public int Length
|
||||
{
|
||||
get { return (int) Len; }
|
||||
set { Len = (UIntPtr) value; }
|
||||
get { return (int)Len; }
|
||||
set { Len = (UIntPtr)value; }
|
||||
}
|
||||
|
||||
public RwSlice(IntPtr mem, UIntPtr len)
|
||||
|
|
|
@ -5,8 +5,10 @@ using static Eina.EinaNative.StrbufNativeMethods;
|
|||
|
||||
namespace Eina
|
||||
{
|
||||
|
||||
namespace EinaNative
|
||||
{
|
||||
|
||||
static internal class StrbufNativeMethods
|
||||
{
|
||||
[DllImport(efl.Libs.Eina)]
|
||||
|
@ -48,7 +50,7 @@ public class Strbuf : IDisposable
|
|||
private bool Disposed;
|
||||
|
||||
///<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.Ownership = ownership;
|
||||
|
@ -89,9 +91,11 @@ public class Strbuf : IDisposable
|
|||
return;
|
||||
}
|
||||
|
||||
if (!Disposed && (Handle != IntPtr.Zero)) {
|
||||
if (!Disposed && (Handle != IntPtr.Zero))
|
||||
{
|
||||
eina_strbuf_free(Handle);
|
||||
}
|
||||
|
||||
Disposed = true;
|
||||
}
|
||||
|
||||
|
@ -115,7 +119,10 @@ public class Strbuf : IDisposable
|
|||
public void Reset()
|
||||
{
|
||||
if (Disposed)
|
||||
{
|
||||
throw new ObjectDisposedException(base.GetType().Name);
|
||||
}
|
||||
|
||||
eina_strbuf_reset(Handle);
|
||||
}
|
||||
|
||||
|
@ -123,7 +130,10 @@ public class Strbuf : IDisposable
|
|||
public bool Append(string text)
|
||||
{
|
||||
if (Disposed)
|
||||
{
|
||||
throw new ObjectDisposedException(base.GetType().Name);
|
||||
}
|
||||
|
||||
return eina_strbuf_append(Handle, text);
|
||||
}
|
||||
|
||||
|
@ -131,7 +141,10 @@ public class Strbuf : IDisposable
|
|||
public bool AppendEscaped(string text)
|
||||
{
|
||||
if (Disposed)
|
||||
{
|
||||
throw new ObjectDisposedException(base.GetType().Name);
|
||||
}
|
||||
|
||||
return eina_strbuf_append_escaped(Handle, text);
|
||||
}
|
||||
|
||||
|
@ -139,7 +152,10 @@ public class Strbuf : IDisposable
|
|||
public bool Append(char c)
|
||||
{
|
||||
if (Disposed)
|
||||
{
|
||||
throw new ObjectDisposedException(base.GetType().Name);
|
||||
}
|
||||
|
||||
return eina_strbuf_append_char(Handle, c);
|
||||
}
|
||||
|
||||
|
@ -147,10 +163,12 @@ public class Strbuf : IDisposable
|
|||
public string Steal()
|
||||
{
|
||||
if (Disposed)
|
||||
{
|
||||
throw new ObjectDisposedException(base.GetType().Name);
|
||||
}
|
||||
|
||||
return eina_strbuf_string_steal(Handle);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace eina
|
||||
|
||||
|
|
|
@ -4,9 +4,11 @@ using System;
|
|||
using System.Runtime.InteropServices;
|
||||
|
||||
|
||||
namespace Eina {
|
||||
namespace Eina
|
||||
{
|
||||
|
||||
public class Stringshare {
|
||||
public class Stringshare
|
||||
{
|
||||
[DllImport(efl.Libs.Eina)] public static extern System.IntPtr
|
||||
eina_stringshare_add_length(string str, System.UInt32 slen);
|
||||
[DllImport(efl.Libs.Eina)] public static extern System.IntPtr
|
||||
|
@ -16,4 +18,3 @@ public class Stringshare {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -5,7 +5,8 @@ using System.Runtime.InteropServices;
|
|||
|
||||
using static eldbus.EldbusMessageNativeFunctions;
|
||||
|
||||
namespace eldbus {
|
||||
namespace eldbus
|
||||
{
|
||||
|
||||
public static class Timeout
|
||||
{
|
||||
|
@ -26,6 +27,7 @@ public struct ObjectPath
|
|||
{
|
||||
return new ObjectPath(str);
|
||||
}
|
||||
|
||||
public static implicit operator string(ObjectPath path)
|
||||
{
|
||||
return path.value;
|
||||
|
@ -46,6 +48,7 @@ public struct SignatureString
|
|||
{
|
||||
return new SignatureString(str);
|
||||
}
|
||||
|
||||
public static implicit operator string(SignatureString sig)
|
||||
{
|
||||
return sig.value;
|
||||
|
@ -66,6 +69,7 @@ public struct UnixFd
|
|||
{
|
||||
return new UnixFd(fd);
|
||||
}
|
||||
|
||||
public static implicit operator Int32(UnixFd unix_fd)
|
||||
{
|
||||
return unix_fd.value;
|
||||
|
@ -75,23 +79,107 @@ public struct UnixFd
|
|||
|
||||
public static class Argument
|
||||
{
|
||||
public class ByteType { public const char Code = 'y'; public const string Signature = "y"; }
|
||||
public class BooleanType { public const char Code = 'b'; public const string Signature = "b"; }
|
||||
public class Int16Type { public const char Code = 'n'; public const string Signature = "n"; }
|
||||
public class UInt16Type { public const char Code = 'q'; public const string Signature = "q"; }
|
||||
public class Int32Type { public const char Code = 'i'; public const string Signature = "i"; }
|
||||
public class UInt32Type { public const char Code = 'u'; public const string Signature = "u"; }
|
||||
public class Int64Type { public const char Code = 'x'; public const string Signature = "x"; }
|
||||
public class UInt64Type { public const char Code = 't'; public const string Signature = "t"; }
|
||||
public class DoubleType { public const char Code = 'd'; public const string Signature = "d"; }
|
||||
public class StringType { public const char Code = 's'; public const string Signature = "s"; }
|
||||
public class ObjectPathType { public const char Code = 'o'; public const string Signature = "o"; }
|
||||
public class SignatureType { public const char Code = 'g'; public const string Signature = "g"; }
|
||||
public class ArrayType { public const char Code = 'a'; public const string Signature = "a"; }
|
||||
public class StructType { public const char Code = 'r'; public const string Signature = "r"; }
|
||||
public class VariantType { public const char Code = 'v'; public const string Signature = "v"; }
|
||||
public class DictEntryType { public const char Code = 'e'; public const string Signature = "e"; }
|
||||
public class UnixFdType { public const char Code = 'h'; public const string Signature = "h"; }
|
||||
public class ByteType
|
||||
{
|
||||
public const char Code = 'y';
|
||||
public const string Signature = "y";
|
||||
}
|
||||
|
||||
public class BooleanType
|
||||
{
|
||||
public const char Code = 'b';
|
||||
public const string Signature = "b";
|
||||
}
|
||||
|
||||
public class Int16Type
|
||||
{
|
||||
public const char Code = 'n';
|
||||
public const string Signature = "n";
|
||||
}
|
||||
|
||||
public class UInt16Type
|
||||
{
|
||||
public const char Code = 'q';
|
||||
public const string Signature = "q";
|
||||
}
|
||||
|
||||
public class Int32Type
|
||||
{
|
||||
public const char Code = 'i';
|
||||
public const string Signature = "i";
|
||||
}
|
||||
|
||||
public class UInt32Type
|
||||
{
|
||||
public const char Code = 'u';
|
||||
public const string Signature = "u";
|
||||
}
|
||||
|
||||
public class Int64Type
|
||||
{
|
||||
public const char Code = 'x';
|
||||
public const string Signature = "x";
|
||||
}
|
||||
|
||||
public class UInt64Type
|
||||
{
|
||||
public const char Code = 't';
|
||||
public const string Signature = "t";
|
||||
}
|
||||
|
||||
public class DoubleType
|
||||
{
|
||||
public const char Code = 'd';
|
||||
public const string Signature = "d";
|
||||
}
|
||||
|
||||
public class StringType
|
||||
{
|
||||
public const char Code = 's';
|
||||
public const string Signature = "s";
|
||||
}
|
||||
|
||||
public class ObjectPathType
|
||||
{
|
||||
public const char Code = 'o';
|
||||
public const string Signature = "o";
|
||||
}
|
||||
|
||||
public class SignatureType
|
||||
{
|
||||
public const char Code = 'g';
|
||||
public const string Signature = "g";
|
||||
}
|
||||
|
||||
public class ArrayType
|
||||
{
|
||||
public const char Code = 'a';
|
||||
public const string Signature = "a";
|
||||
}
|
||||
|
||||
public class StructType
|
||||
{
|
||||
public const char Code = 'r';
|
||||
public const string Signature = "r";
|
||||
}
|
||||
|
||||
public class VariantType
|
||||
{
|
||||
public const char Code = 'v';
|
||||
public const string Signature = "v";
|
||||
}
|
||||
|
||||
public class DictEntryType
|
||||
{
|
||||
public const char Code = 'e';
|
||||
public const string Signature = "e";
|
||||
}
|
||||
|
||||
public class UnixFdType
|
||||
{
|
||||
public const char Code = 'h';
|
||||
public const string Signature = "h";
|
||||
}
|
||||
|
||||
// public static readonly ByteType ByteT = new ByteType();
|
||||
// public static readonly BooleanType BooleanT = new BooleanType();
|
||||
|
@ -135,14 +223,18 @@ public abstract class BasicMessageArgument
|
|||
public void AppendTo(eldbus.Message msg)
|
||||
{
|
||||
if (!InternalAppendTo(msg))
|
||||
{
|
||||
throw new SEHException("Eldbus: could not append basic type to eldbus.Message");
|
||||
}
|
||||
}
|
||||
|
||||
public void AppendTo(eldbus.MessageIterator iter)
|
||||
{
|
||||
if (!InternalAppendTo(iter))
|
||||
{
|
||||
throw new SEHException("Eldbus: could not append basic type to eldbus.MessageIterator");
|
||||
}
|
||||
}
|
||||
|
||||
public abstract char TypeCode {get;}
|
||||
public abstract string Signature {get;}
|
||||
|
@ -219,8 +311,15 @@ public class ByteMessageArgument : BasicMessageArgument
|
|||
value = arg;
|
||||
}
|
||||
|
||||
public override char TypeCode { get { return Argument.ByteType.Code; } }
|
||||
public override string Signature { get { return Argument.ByteType.Signature; } }
|
||||
public override char TypeCode
|
||||
{
|
||||
get { return Argument.ByteType.Code; }
|
||||
}
|
||||
|
||||
public override string Signature
|
||||
{
|
||||
get { return Argument.ByteType.Signature; }
|
||||
}
|
||||
|
||||
protected override bool InternalAppendTo(eldbus.Message msg)
|
||||
{
|
||||
|
@ -242,8 +341,15 @@ public class BoolMessageArgument : BasicMessageArgument
|
|||
value = Convert.ToInt32(arg);
|
||||
}
|
||||
|
||||
public override char TypeCode { get { return Argument.BooleanType.Code; } }
|
||||
public override string Signature { get { return Argument.ByteType.Signature; } }
|
||||
public override char TypeCode
|
||||
{
|
||||
get { return Argument.BooleanType.Code; }
|
||||
}
|
||||
|
||||
public override string Signature
|
||||
{
|
||||
get { return Argument.ByteType.Signature; }
|
||||
}
|
||||
|
||||
protected override bool InternalAppendTo(eldbus.Message msg)
|
||||
{
|
||||
|
@ -265,8 +371,15 @@ public class Int16MessageArgument : BasicMessageArgument
|
|||
value = arg;
|
||||
}
|
||||
|
||||
public override char TypeCode { get { return Argument.Int16Type.Code; } }
|
||||
public override string Signature { get { return Argument.ByteType.Signature; } }
|
||||
public override char TypeCode
|
||||
{
|
||||
get { return Argument.Int16Type.Code; }
|
||||
}
|
||||
|
||||
public override string Signature
|
||||
{
|
||||
get { return Argument.ByteType.Signature; }
|
||||
}
|
||||
|
||||
protected override bool InternalAppendTo(eldbus.Message msg)
|
||||
{
|
||||
|
@ -288,8 +401,15 @@ public class UInt16MessageArgument : BasicMessageArgument
|
|||
value = arg;
|
||||
}
|
||||
|
||||
public override char TypeCode { get { return Argument.UInt16Type.Code; } }
|
||||
public override string Signature { get { return Argument.ByteType.Signature; } }
|
||||
public override char TypeCode
|
||||
{
|
||||
get { return Argument.UInt16Type.Code; }
|
||||
}
|
||||
|
||||
public override string Signature
|
||||
{
|
||||
get { return Argument.ByteType.Signature; }
|
||||
}
|
||||
|
||||
protected override bool InternalAppendTo(eldbus.Message msg)
|
||||
{
|
||||
|
@ -311,8 +431,15 @@ public class Int32MessageArgument : BasicMessageArgument
|
|||
value = arg;
|
||||
}
|
||||
|
||||
public override char TypeCode { get { return Argument.Int32Type.Code; } }
|
||||
public override string Signature { get { return Argument.ByteType.Signature; } }
|
||||
public override char TypeCode
|
||||
{
|
||||
get { return Argument.Int32Type.Code; }
|
||||
}
|
||||
|
||||
public override string Signature
|
||||
{
|
||||
get { return Argument.ByteType.Signature; }
|
||||
}
|
||||
|
||||
protected override bool InternalAppendTo(eldbus.Message msg)
|
||||
{
|
||||
|
@ -334,8 +461,15 @@ public class UInt32MessageArgument : BasicMessageArgument
|
|||
value = arg;
|
||||
}
|
||||
|
||||
public override char TypeCode { get { return Argument.UInt32Type.Code; } }
|
||||
public override string Signature { get { return Argument.ByteType.Signature; } }
|
||||
public override char TypeCode
|
||||
{
|
||||
get { return Argument.UInt32Type.Code; }
|
||||
}
|
||||
|
||||
public override string Signature
|
||||
{
|
||||
get { return Argument.ByteType.Signature; }
|
||||
}
|
||||
|
||||
protected override bool InternalAppendTo(eldbus.Message msg)
|
||||
{
|
||||
|
@ -357,8 +491,15 @@ public class Int64MessageArgument : BasicMessageArgument
|
|||
value = arg;
|
||||
}
|
||||
|
||||
public override char TypeCode { get { return Argument.Int64Type.Code; } }
|
||||
public override string Signature { get { return Argument.ByteType.Signature; } }
|
||||
public override char TypeCode
|
||||
{
|
||||
get { return Argument.Int64Type.Code; }
|
||||
}
|
||||
|
||||
public override string Signature
|
||||
{
|
||||
get { return Argument.ByteType.Signature; }
|
||||
}
|
||||
|
||||
protected override bool InternalAppendTo(eldbus.Message msg)
|
||||
{
|
||||
|
@ -380,8 +521,15 @@ public class UInt64MessageArgument : BasicMessageArgument
|
|||
value = arg;
|
||||
}
|
||||
|
||||
public override char TypeCode { get { return Argument.UInt64Type.Code; } }
|
||||
public override string Signature { get { return Argument.ByteType.Signature; } }
|
||||
public override char TypeCode
|
||||
{
|
||||
get { return Argument.UInt64Type.Code; }
|
||||
}
|
||||
|
||||
public override string Signature
|
||||
{
|
||||
get { return Argument.ByteType.Signature; }
|
||||
}
|
||||
|
||||
protected override bool InternalAppendTo(eldbus.Message msg)
|
||||
{
|
||||
|
@ -403,8 +551,15 @@ public class DoubleMessageArgument : BasicMessageArgument
|
|||
value = arg;
|
||||
}
|
||||
|
||||
public override char TypeCode { get { return Argument.DoubleType.Code; } }
|
||||
public override string Signature { get { return Argument.ByteType.Signature; } }
|
||||
public override char TypeCode
|
||||
{
|
||||
get { return Argument.DoubleType.Code; }
|
||||
}
|
||||
|
||||
public override string Signature
|
||||
{
|
||||
get { return Argument.ByteType.Signature; }
|
||||
}
|
||||
|
||||
protected override bool InternalAppendTo(eldbus.Message msg)
|
||||
{
|
||||
|
@ -439,32 +594,53 @@ public abstract class StringLikeMessageArgument : BasicMessageArgument
|
|||
|
||||
public class StringMessageArgument : StringLikeMessageArgument
|
||||
{
|
||||
public StringMessageArgument(string arg)
|
||||
: base(arg)
|
||||
{}
|
||||
public StringMessageArgument(string arg) : base(arg)
|
||||
{
|
||||
}
|
||||
|
||||
public override char TypeCode { get { return Argument.StringType.Code; } }
|
||||
public override string Signature { get { return Argument.ByteType.Signature; } }
|
||||
public override char TypeCode
|
||||
{
|
||||
get { return Argument.StringType.Code; }
|
||||
}
|
||||
|
||||
public override string Signature
|
||||
{
|
||||
get { return Argument.ByteType.Signature; }
|
||||
}
|
||||
}
|
||||
|
||||
public class ObjectPathMessageArgument : StringLikeMessageArgument
|
||||
{
|
||||
public ObjectPathMessageArgument(ObjectPath arg)
|
||||
: base(arg.value)
|
||||
{}
|
||||
public ObjectPathMessageArgument(ObjectPath arg) : base(arg.value)
|
||||
{
|
||||
}
|
||||
|
||||
public override char TypeCode { get { return Argument.ObjectPathType.Code; } }
|
||||
public override string Signature { get { return Argument.ByteType.Signature; } }
|
||||
public override char TypeCode
|
||||
{
|
||||
get { return Argument.ObjectPathType.Code; }
|
||||
}
|
||||
|
||||
public override string Signature
|
||||
{
|
||||
get { return Argument.ByteType.Signature; }
|
||||
}
|
||||
}
|
||||
|
||||
public class SignatureMessageArgument : StringLikeMessageArgument
|
||||
{
|
||||
public SignatureMessageArgument(SignatureString arg)
|
||||
: base(arg.value)
|
||||
{}
|
||||
public SignatureMessageArgument(SignatureString arg) : base(arg.value)
|
||||
{
|
||||
}
|
||||
|
||||
public override char TypeCode { get { return Argument.SignatureType.Code; } }
|
||||
public override string Signature { get { return Argument.ByteType.Signature; } }
|
||||
public override char TypeCode
|
||||
{
|
||||
get { return Argument.SignatureType.Code; }
|
||||
}
|
||||
|
||||
public override string Signature
|
||||
{
|
||||
get { return Argument.ByteType.Signature; }
|
||||
}
|
||||
}
|
||||
|
||||
public class UnixFdMessageArgument : BasicMessageArgument
|
||||
|
@ -476,8 +652,15 @@ public class UnixFdMessageArgument : BasicMessageArgument
|
|||
value = arg.value;
|
||||
}
|
||||
|
||||
public override char TypeCode { get { return Argument.UnixFdType.Code; } }
|
||||
public override string Signature { get { return Argument.ByteType.Signature; } }
|
||||
public override char TypeCode
|
||||
{
|
||||
get { return Argument.UnixFdType.Code; }
|
||||
}
|
||||
|
||||
public override string Signature
|
||||
{
|
||||
get { return Argument.ByteType.Signature; }
|
||||
}
|
||||
|
||||
protected override bool InternalAppendTo(eldbus.Message msg)
|
||||
{
|
||||
|
@ -497,7 +680,10 @@ public static class Common
|
|||
public static void RaiseNullHandle()
|
||||
{
|
||||
if (NullHandleError == 0)
|
||||
{
|
||||
NullHandleError = Eina.Error.Register("Eldbus: null handle");
|
||||
}
|
||||
|
||||
Eina.Error.Raise(NullHandleError);
|
||||
}
|
||||
|
||||
|
@ -511,7 +697,10 @@ public static class Common
|
|||
public static Eldbus_Message_Cb GetMessageCbWrapper()
|
||||
{
|
||||
if (message_cb_wrapper == null)
|
||||
{
|
||||
message_cb_wrapper = new Eldbus_Message_Cb(MessageCbWrapper);
|
||||
}
|
||||
|
||||
return message_cb_wrapper;
|
||||
}
|
||||
|
||||
|
@ -532,7 +721,7 @@ public static class Common
|
|||
msg = new eldbus.Message(msg_hdl, false);
|
||||
pending = new eldbus.Pending(pending_hdl, false);
|
||||
}
|
||||
catch(Exception e)
|
||||
catch (Exception e)
|
||||
{
|
||||
Eina.Log.Error("Eldbus: could not convert Eldbus_Message_Cb parameters. Exception: " + e.ToString());
|
||||
return;
|
||||
|
@ -542,7 +731,7 @@ public static class Common
|
|||
{
|
||||
dlgt(msg, pending);
|
||||
}
|
||||
catch(Exception e)
|
||||
catch (Exception e)
|
||||
{
|
||||
Eina.Log.Error("Eldbus: Eldbus_Message_Cb delegate error. Exception: " + e.ToString());
|
||||
}
|
||||
|
@ -553,5 +742,3 @@ public static class Common
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -3,7 +3,8 @@
|
|||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace eldbus {
|
||||
namespace eldbus
|
||||
{
|
||||
|
||||
public static class Config
|
||||
{
|
||||
|
@ -13,8 +14,10 @@ public static class Config
|
|||
public static void Init()
|
||||
{
|
||||
if (eldbus_init() == 0)
|
||||
{
|
||||
throw new Efl.EflException("Failed to initialize Eldbus");
|
||||
}
|
||||
}
|
||||
|
||||
public static void Shutdown()
|
||||
{
|
||||
|
|
|
@ -5,8 +5,8 @@ using System.Runtime.InteropServices;
|
|||
|
||||
using static eldbus.EldbusConnectionNativeFunctions;
|
||||
|
||||
namespace eldbus {
|
||||
|
||||
namespace eldbus
|
||||
{
|
||||
|
||||
public static class EldbusConnectionNativeFunctions
|
||||
{
|
||||
|
@ -155,11 +155,15 @@ public class Connection : IDisposable
|
|||
IntPtr h = Handle;
|
||||
Handle = IntPtr.Zero;
|
||||
if (h == IntPtr.Zero)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (Own)
|
||||
{
|
||||
eldbus_connection_unref(h);
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
|
@ -184,15 +188,19 @@ public class Connection : IDisposable
|
|||
CheckHandle();
|
||||
|
||||
if (msg == null)
|
||||
{
|
||||
throw new ArgumentNullException("msg");
|
||||
}
|
||||
|
||||
IntPtr cb_wrapper = (dlgt == null ? IntPtr.Zero : eldbus.Common.GetMessageCbWrapperPtr());
|
||||
IntPtr cb_data = (dlgt == null ? IntPtr.Zero : Marshal.GetFunctionPointerForDelegate(dlgt));
|
||||
|
||||
var pending_hdl = eldbus_connection_send(Handle, msg.Handle, cb_wrapper, cb_data, timeout);
|
||||
|
||||
if(pending_hdl == IntPtr.Zero)
|
||||
if (pending_hdl == IntPtr.Zero)
|
||||
{
|
||||
throw new SEHException("Eldbus: could not get `Pending' object from eldbus_connection_send");
|
||||
}
|
||||
|
||||
msg.Ref();
|
||||
|
||||
|
@ -204,7 +212,10 @@ public class Connection : IDisposable
|
|||
CheckHandle();
|
||||
var ptr = eldbus_connection_unique_name_get(Handle);
|
||||
if (ptr == IntPtr.Zero)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return Eina.StringConversion.NativeUtf8ToManagedString(ptr);
|
||||
}
|
||||
|
||||
|
@ -213,15 +224,19 @@ public class Connection : IDisposable
|
|||
CheckHandle();
|
||||
|
||||
if (bus == null)
|
||||
{
|
||||
throw new ArgumentNullException("bus");
|
||||
}
|
||||
|
||||
IntPtr cb_wrapper = (dlgt == null ? IntPtr.Zero : eldbus.Common.GetMessageCbWrapperPtr());
|
||||
IntPtr cb_data = (dlgt == null ? IntPtr.Zero : Marshal.GetFunctionPointerForDelegate(dlgt));
|
||||
|
||||
var pending_hdl = eldbus_name_request(Handle, bus, flags, cb_wrapper, cb_data);
|
||||
|
||||
if(pending_hdl == IntPtr.Zero)
|
||||
if (pending_hdl == IntPtr.Zero)
|
||||
{
|
||||
throw new SEHException("Eldbus: could not get `Pending' object from eldbus_name_request");
|
||||
}
|
||||
|
||||
return new eldbus.Pending(pending_hdl, false);
|
||||
}
|
||||
|
@ -231,15 +246,19 @@ public class Connection : IDisposable
|
|||
CheckHandle();
|
||||
|
||||
if (bus == null)
|
||||
{
|
||||
throw new ArgumentNullException("bus");
|
||||
}
|
||||
|
||||
IntPtr cb_wrapper = (dlgt == null ? IntPtr.Zero : eldbus.Common.GetMessageCbWrapperPtr());
|
||||
IntPtr cb_data = (dlgt == null ? IntPtr.Zero : Marshal.GetFunctionPointerForDelegate(dlgt));
|
||||
|
||||
var pending_hdl = eldbus_name_release(Handle, bus, cb_wrapper, cb_data);
|
||||
|
||||
if(pending_hdl == IntPtr.Zero)
|
||||
if (pending_hdl == IntPtr.Zero)
|
||||
{
|
||||
throw new SEHException("Eldbus: could not get `Pending' object from eldbus_name_release");
|
||||
}
|
||||
|
||||
return new eldbus.Pending(pending_hdl, false);
|
||||
}
|
||||
|
@ -249,15 +268,19 @@ public class Connection : IDisposable
|
|||
CheckHandle();
|
||||
|
||||
if (bus == null)
|
||||
{
|
||||
throw new ArgumentNullException("bus");
|
||||
}
|
||||
|
||||
IntPtr cb_wrapper = (dlgt == null ? IntPtr.Zero : eldbus.Common.GetMessageCbWrapperPtr());
|
||||
IntPtr cb_data = (dlgt == null ? IntPtr.Zero : Marshal.GetFunctionPointerForDelegate(dlgt));
|
||||
|
||||
var pending_hdl = eldbus_name_owner_get(Handle, bus, cb_wrapper, cb_data);
|
||||
|
||||
if(pending_hdl == IntPtr.Zero)
|
||||
if (pending_hdl == IntPtr.Zero)
|
||||
{
|
||||
throw new SEHException("Eldbus: could not get `Pending' object from eldbus_name_owner_get");
|
||||
}
|
||||
|
||||
return new eldbus.Pending(pending_hdl, false);
|
||||
}
|
||||
|
@ -267,15 +290,19 @@ public class Connection : IDisposable
|
|||
CheckHandle();
|
||||
|
||||
if (bus == null)
|
||||
{
|
||||
throw new ArgumentNullException("bus");
|
||||
}
|
||||
|
||||
IntPtr cb_wrapper = (dlgt == null ? IntPtr.Zero : eldbus.Common.GetMessageCbWrapperPtr());
|
||||
IntPtr cb_data = (dlgt == null ? IntPtr.Zero : Marshal.GetFunctionPointerForDelegate(dlgt));
|
||||
|
||||
var pending_hdl = eldbus_name_owner_has(Handle, bus, cb_wrapper, cb_data);
|
||||
|
||||
if(pending_hdl == IntPtr.Zero)
|
||||
if (pending_hdl == IntPtr.Zero)
|
||||
{
|
||||
throw new SEHException("Eldbus: could not get `Pending' object from eldbus_name_owner_has");
|
||||
}
|
||||
|
||||
return new eldbus.Pending(pending_hdl, false);
|
||||
}
|
||||
|
@ -289,8 +316,10 @@ public class Connection : IDisposable
|
|||
|
||||
var pending_hdl = eldbus_names_list(Handle, cb_wrapper, cb_data);
|
||||
|
||||
if(pending_hdl == IntPtr.Zero)
|
||||
if (pending_hdl == IntPtr.Zero)
|
||||
{
|
||||
throw new SEHException("Eldbus: could not get `Pending' object from eldbus_names_list");
|
||||
}
|
||||
|
||||
return new eldbus.Pending(pending_hdl, false);
|
||||
}
|
||||
|
@ -304,8 +333,10 @@ public class Connection : IDisposable
|
|||
|
||||
var pending_hdl = eldbus_names_activatable_list(Handle, cb_wrapper, cb_data);
|
||||
|
||||
if(pending_hdl == IntPtr.Zero)
|
||||
if (pending_hdl == IntPtr.Zero)
|
||||
{
|
||||
throw new SEHException("Eldbus: could not get `Pending' object from eldbus_names_activatable_list");
|
||||
}
|
||||
|
||||
return new eldbus.Pending(pending_hdl, false);
|
||||
}
|
||||
|
@ -319,8 +350,10 @@ public class Connection : IDisposable
|
|||
|
||||
var pending_hdl = eldbus_hello(Handle, cb_wrapper, cb_data);
|
||||
|
||||
if(pending_hdl == IntPtr.Zero)
|
||||
if (pending_hdl == IntPtr.Zero)
|
||||
{
|
||||
throw new SEHException("Eldbus: could not get `Pending' object from eldbus_hello");
|
||||
}
|
||||
|
||||
return new eldbus.Pending(pending_hdl, false);
|
||||
}
|
||||
|
@ -330,15 +363,19 @@ public class Connection : IDisposable
|
|||
CheckHandle();
|
||||
|
||||
if (bus == null)
|
||||
{
|
||||
throw new ArgumentNullException("bus");
|
||||
}
|
||||
|
||||
IntPtr cb_wrapper = (dlgt == null ? IntPtr.Zero : eldbus.Common.GetMessageCbWrapperPtr());
|
||||
IntPtr cb_data = (dlgt == null ? IntPtr.Zero : Marshal.GetFunctionPointerForDelegate(dlgt));
|
||||
|
||||
var pending_hdl = eldbus_name_start(Handle, bus, flags, cb_wrapper, cb_data);
|
||||
|
||||
if(pending_hdl == IntPtr.Zero)
|
||||
if (pending_hdl == IntPtr.Zero)
|
||||
{
|
||||
throw new SEHException("Eldbus: could not get `Pending' object from eldbus_name_start");
|
||||
}
|
||||
|
||||
return new eldbus.Pending(pending_hdl, false);
|
||||
}
|
||||
|
|
|
@ -5,7 +5,8 @@ using System.Runtime.InteropServices;
|
|||
|
||||
using static eldbus.EldbusMessageNativeFunctions;
|
||||
|
||||
namespace eldbus {
|
||||
namespace eldbus
|
||||
{
|
||||
|
||||
public static class EldbusMessageNativeFunctions
|
||||
{
|
||||
|
@ -223,11 +224,15 @@ public class Message : IDisposable
|
|||
IntPtr h = Handle;
|
||||
Handle = IntPtr.Zero;
|
||||
if (h == IntPtr.Zero)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (Own)
|
||||
{
|
||||
eldbus_message_unref(h);
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
|
@ -251,7 +256,10 @@ public class Message : IDisposable
|
|||
{
|
||||
var ptr = eldbus_message_method_call_new(dest, path, iface, method);
|
||||
if (ptr == IntPtr.Zero)
|
||||
{
|
||||
throw new SEHException("Eldbus: could not get `Message' object from eldbus_message_method_call_new");
|
||||
}
|
||||
|
||||
return new eldbus.Message(ptr, true);
|
||||
}
|
||||
|
||||
|
@ -259,7 +267,10 @@ public class Message : IDisposable
|
|||
{
|
||||
var ptr = eldbus_message_signal_new(path, _interface, name);
|
||||
if (ptr == IntPtr.Zero)
|
||||
{
|
||||
throw new SEHException("Eldbus: could not get `Message' object from eldbus_message_signal_new");
|
||||
}
|
||||
|
||||
return new eldbus.Message(ptr, true);
|
||||
}
|
||||
|
||||
|
@ -322,7 +333,10 @@ public class Message : IDisposable
|
|||
CheckHandle();
|
||||
var ptr = eldbus_message_error_new(Handle, error_name, error_msg);
|
||||
if (ptr == IntPtr.Zero)
|
||||
{
|
||||
throw new SEHException("Eldbus: could not get `Message' object from eldbus_message_error_new");
|
||||
}
|
||||
|
||||
return new eldbus.Message(ptr, false);
|
||||
}
|
||||
|
||||
|
@ -331,7 +345,10 @@ public class Message : IDisposable
|
|||
CheckHandle();
|
||||
var ptr = eldbus_message_method_return_new(Handle);
|
||||
if (ptr == IntPtr.Zero)
|
||||
{
|
||||
throw new SEHException("Eldbus: could not get `Message' object from eldbus_message_method_return_new");
|
||||
}
|
||||
|
||||
return new eldbus.Message(ptr, false);
|
||||
}
|
||||
|
||||
|
@ -459,7 +476,10 @@ public class Message : IDisposable
|
|||
CheckHandle();
|
||||
var ptr = eldbus_message_iter_get(Handle);
|
||||
if (ptr == IntPtr.Zero)
|
||||
{
|
||||
throw new SEHException("Eldbus: could not get `MessageIterator' object from eldbus_message_iter_get");
|
||||
}
|
||||
|
||||
return new eldbus.MessageIterator(ptr, IntPtr.Zero);
|
||||
}
|
||||
}
|
||||
|
@ -514,12 +534,18 @@ public class MessageIterator
|
|||
IntPtr new_iter = IntPtr.Zero;
|
||||
|
||||
if (signature[0] == 'v')
|
||||
{
|
||||
new_iter = eldbus_message_iter_container_new(Handle, 'v', signature.Substring(1));
|
||||
}
|
||||
else if (!eldbus_message_iter_arguments_append(Handle, signature, out new_iter))
|
||||
{
|
||||
throw new SEHException("Eldbus: could not append container type");
|
||||
}
|
||||
|
||||
if (new_iter == IntPtr.Zero)
|
||||
{
|
||||
throw new SEHException("Eldbus: could not get `MessageIterator' object from eldbus_message_iter_arguments_append");
|
||||
}
|
||||
|
||||
return new eldbus.MessageIterator(new_iter, Handle);
|
||||
}
|
||||
|
@ -531,7 +557,9 @@ public class MessageIterator
|
|||
IntPtr new_iter = eldbus_message_iter_container_new(Handle, type, contained_signature);
|
||||
|
||||
if (new_iter == IntPtr.Zero)
|
||||
{
|
||||
throw new SEHException("Eldbus: could not get `MessageIterator' object from eldbus_message_iter_container_new");
|
||||
}
|
||||
|
||||
return new eldbus.MessageIterator(new_iter, Handle);
|
||||
}
|
||||
|
@ -541,10 +569,14 @@ public class MessageIterator
|
|||
CheckHandle();
|
||||
|
||||
if (Parent == IntPtr.Zero)
|
||||
{
|
||||
throw new SEHException("Eldbus: can not close MessageIterator open container without a parent");
|
||||
}
|
||||
|
||||
if (!eldbus_message_iter_container_close(Parent, Handle))
|
||||
{
|
||||
throw new SEHException("Eldbus: could not close MessageIterator");
|
||||
}
|
||||
|
||||
Handle = IntPtr.Zero;
|
||||
Parent = IntPtr.Zero;
|
||||
|
@ -654,7 +686,10 @@ public class MessageIterator
|
|||
IntPtr hdl = IntPtr.Zero;
|
||||
bool r = eldbus_message_iter_get_and_next(Handle, typecode, out hdl);
|
||||
if (hdl == IntPtr.Zero)
|
||||
{
|
||||
throw new SEHException("Eldbus: could not get argument");
|
||||
}
|
||||
|
||||
iter = new eldbus.MessageIterator(hdl, Handle);
|
||||
|
||||
return r;
|
||||
|
@ -665,7 +700,10 @@ public class MessageIterator
|
|||
CheckHandle();
|
||||
IntPtr hdl = IntPtr.Zero;
|
||||
if (!eldbus_message_iter_arguments_get(Handle, signatue, out hdl) || hdl == IntPtr.Zero)
|
||||
{
|
||||
throw new SEHException("Eldbus: could not get argument");
|
||||
}
|
||||
|
||||
iter = new eldbus.MessageIterator(hdl, Handle);
|
||||
|
||||
return Next();
|
||||
|
@ -764,7 +802,10 @@ public class MessageIterator
|
|||
CheckHandle();
|
||||
IntPtr hdl = IntPtr.Zero;
|
||||
if (!eldbus_message_iter_arguments_get(Handle, signatue, out hdl) || hdl == IntPtr.Zero)
|
||||
{
|
||||
throw new SEHException("Eldbus: could not get argument");
|
||||
}
|
||||
|
||||
iter = new eldbus.MessageIterator(hdl, Handle);
|
||||
}
|
||||
|
||||
|
@ -789,8 +830,10 @@ public class MessageIterator
|
|||
CheckHandle();
|
||||
|
||||
if (!eldbus_message_iter_fixed_array_get(Handle, type_code, out value, out n_elements))
|
||||
{
|
||||
throw new SEHException("Eldbus: could not get fixed array");
|
||||
}
|
||||
}
|
||||
|
||||
public void GetFixedArray(out byte[] array)
|
||||
{
|
||||
|
@ -880,4 +923,3 @@ public class MessageIterator
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -7,8 +7,8 @@ using static eldbus.EldbusObjectNativeFunctions;
|
|||
|
||||
using IntPtr = System.IntPtr;
|
||||
|
||||
namespace eldbus {
|
||||
|
||||
namespace eldbus
|
||||
{
|
||||
|
||||
public static class EldbusObjectNativeFunctions
|
||||
{
|
||||
|
@ -112,16 +112,26 @@ public class Object : System.IDisposable
|
|||
public Object(eldbus.Connection conn, string bus, string path)
|
||||
{
|
||||
if (conn == null)
|
||||
{
|
||||
throw new System.ArgumentNullException("conn");
|
||||
}
|
||||
|
||||
if (bus == null)
|
||||
{
|
||||
throw new System.ArgumentNullException("bus");
|
||||
}
|
||||
|
||||
if (path == null)
|
||||
{
|
||||
throw new System.ArgumentNullException("path");
|
||||
}
|
||||
|
||||
var handle = eldbus_object_get(conn.Handle, bus, path);
|
||||
|
||||
if (handle == IntPtr.Zero)
|
||||
{
|
||||
throw new SEHException("Eldbus: could not get `Object' object from eldbus_object_get");
|
||||
}
|
||||
|
||||
InitNew(handle, true);
|
||||
}
|
||||
|
@ -136,11 +146,15 @@ public class Object : System.IDisposable
|
|||
IntPtr h = Handle;
|
||||
Handle = IntPtr.Zero;
|
||||
if (h == IntPtr.Zero)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (Own)
|
||||
{
|
||||
eldbus_object_unref(h);
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
|
@ -166,7 +180,9 @@ public class Object : System.IDisposable
|
|||
var conn = eldbus_object_connection_get(Handle);
|
||||
|
||||
if (conn == IntPtr.Zero)
|
||||
{
|
||||
throw new SEHException("Eldbus: could not get `Connection' object from eldbus_object_connection_get");
|
||||
}
|
||||
|
||||
return new eldbus.Connection(conn, false);
|
||||
}
|
||||
|
@ -202,7 +218,9 @@ public class Object : System.IDisposable
|
|||
CheckHandle();
|
||||
|
||||
if (msg == null)
|
||||
{
|
||||
throw new System.ArgumentNullException("msg");
|
||||
}
|
||||
|
||||
IntPtr cb_wrapper = dlgt == null ? IntPtr.Zero : eldbus.Common.GetMessageCbWrapperPtr();
|
||||
IntPtr cb_data = dlgt == null ? IntPtr.Zero : Marshal.GetFunctionPointerForDelegate(dlgt);
|
||||
|
@ -210,7 +228,9 @@ public class Object : System.IDisposable
|
|||
var pending_hdl = eldbus_object_send(Handle, msg.Handle, cb_wrapper, cb_data, timeout);
|
||||
|
||||
if (pending_hdl == IntPtr.Zero)
|
||||
{
|
||||
throw new SEHException("Eldbus: could not get `Pending' object from eldbus_object_send");
|
||||
}
|
||||
|
||||
return new eldbus.Pending(pending_hdl, false);
|
||||
}
|
||||
|
@ -222,7 +242,9 @@ public class Object : System.IDisposable
|
|||
var hdl = eldbus_object_method_call_new(Handle, _interface, member);
|
||||
|
||||
if (hdl == IntPtr.Zero)
|
||||
{
|
||||
throw new SEHException("Eldbus: could not get `Message' object from eldbus_object_method_call_new");
|
||||
}
|
||||
|
||||
return new eldbus.Message(hdl, false);
|
||||
}
|
||||
|
@ -237,7 +259,9 @@ public class Object : System.IDisposable
|
|||
var pending_hdl = eldbus_object_peer_ping(Handle, cb_wrapper, cb_data);
|
||||
|
||||
if (pending_hdl == IntPtr.Zero)
|
||||
{
|
||||
throw new SEHException("Eldbus: could not get `Pending' object from eldbus_object_peer_ping");
|
||||
}
|
||||
|
||||
return new eldbus.Pending(pending_hdl, false);
|
||||
}
|
||||
|
@ -252,7 +276,9 @@ public class Object : System.IDisposable
|
|||
var pending_hdl = eldbus_object_peer_machine_id_get(Handle, cb_wrapper, cb_data);
|
||||
|
||||
if (pending_hdl == IntPtr.Zero)
|
||||
{
|
||||
throw new SEHException("Eldbus: could not get `Pending' object from eldbus_object_peer_machine_id_get");
|
||||
}
|
||||
|
||||
return new eldbus.Pending(pending_hdl, false);
|
||||
}
|
||||
|
@ -267,7 +293,9 @@ public class Object : System.IDisposable
|
|||
var pending_hdl = eldbus_object_introspect(Handle, cb_wrapper, cb_data);
|
||||
|
||||
if (pending_hdl == IntPtr.Zero)
|
||||
{
|
||||
throw new SEHException("Eldbus: could not get `Pending' object from eldbus_object_introspect");
|
||||
}
|
||||
|
||||
return new eldbus.Pending(pending_hdl, false);
|
||||
}
|
||||
|
@ -282,12 +310,12 @@ public class Object : System.IDisposable
|
|||
var pending_hdl = eldbus_object_managed_objects_get(Handle, cb_wrapper, cb_data);
|
||||
|
||||
if (pending_hdl == IntPtr.Zero)
|
||||
{
|
||||
throw new SEHException("Eldbus: could not get `Pending' object from eldbus_object_managed_objects_get");
|
||||
}
|
||||
|
||||
return new eldbus.Pending(pending_hdl, false);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -5,7 +5,8 @@ using System.Runtime.InteropServices;
|
|||
|
||||
using static eldbus.EldbusPendingNativeFunctions;
|
||||
|
||||
namespace eldbus {
|
||||
namespace eldbus
|
||||
{
|
||||
|
||||
public static class EldbusPendingNativeFunctions
|
||||
{
|
||||
|
@ -108,4 +109,3 @@ public class Pending
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -5,7 +5,8 @@ using System.Runtime.InteropServices;
|
|||
|
||||
using static eldbus.EldbusProxyNativeFunctions;
|
||||
|
||||
namespace eldbus {
|
||||
namespace eldbus
|
||||
{
|
||||
|
||||
public static class EldbusProxyNativeFunctions
|
||||
{
|
||||
|
@ -104,11 +105,15 @@ public class Proxy : IDisposable
|
|||
IntPtr h = Handle;
|
||||
Handle = IntPtr.Zero;
|
||||
if (h == IntPtr.Zero)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (Own)
|
||||
{
|
||||
eldbus_proxy_unref(h);
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
|
@ -133,7 +138,10 @@ public class Proxy : IDisposable
|
|||
CheckHandle();
|
||||
var ptr = eldbus_proxy_object_get(Handle);
|
||||
if (ptr == IntPtr.Zero)
|
||||
{
|
||||
throw new SEHException("Eldbus: could not get `Object' object from eldbus_proxy_object_get");
|
||||
}
|
||||
|
||||
return new eldbus.Object(ptr, false);
|
||||
}
|
||||
|
||||
|
@ -149,11 +157,16 @@ public class Proxy : IDisposable
|
|||
CheckHandle();
|
||||
|
||||
if (member == null)
|
||||
{
|
||||
throw new ArgumentNullException("member");
|
||||
}
|
||||
|
||||
var ptr = eldbus_proxy_method_call_new(Handle, member);
|
||||
if (ptr == IntPtr.Zero)
|
||||
{
|
||||
throw new SEHException("Eldbus: could not get `Message' object from eldbus_proxy_method_call_new");
|
||||
}
|
||||
|
||||
return new eldbus.Message(ptr, false);
|
||||
}
|
||||
|
||||
|
@ -162,7 +175,9 @@ public class Proxy : IDisposable
|
|||
CheckHandle();
|
||||
|
||||
if (msg == null)
|
||||
{
|
||||
throw new ArgumentNullException("msg");
|
||||
}
|
||||
|
||||
IntPtr cb_wrapper = dlgt == null ? IntPtr.Zero : eldbus.Common.GetMessageCbWrapperPtr();
|
||||
IntPtr cb_data = dlgt == null ? IntPtr.Zero : Marshal.GetFunctionPointerForDelegate(dlgt);
|
||||
|
@ -170,7 +185,9 @@ public class Proxy : IDisposable
|
|||
var pending_hdl = eldbus_proxy_send(Handle, msg.Handle, cb_wrapper, cb_data, timeout);
|
||||
|
||||
if (pending_hdl == IntPtr.Zero)
|
||||
{
|
||||
throw new SEHException("Eldbus: could not get `Pending' object from eldbus_proxy_send");
|
||||
}
|
||||
|
||||
return new eldbus.Pending(pending_hdl, false);
|
||||
}
|
||||
|
@ -180,7 +197,10 @@ public class Proxy : IDisposable
|
|||
CheckHandle();
|
||||
var ptr = eldbus_proxy_send_and_block(Handle, msg.Handle, timeout);
|
||||
if (ptr == IntPtr.Zero)
|
||||
{
|
||||
throw new SEHException("Eldbus: could not get `Message' object from eldbus_proxy_send_and_block");
|
||||
}
|
||||
|
||||
return new eldbus.Message(ptr, true);
|
||||
}
|
||||
|
||||
|
@ -205,4 +225,3 @@ public class Proxy : IDisposable
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -5,7 +5,8 @@ using System.Runtime.InteropServices;
|
|||
|
||||
using static eldbus.EldbusServiceNativeFunctions;
|
||||
|
||||
namespace eldbus {
|
||||
namespace eldbus
|
||||
{
|
||||
|
||||
public static class EldbusServiceNativeFunctions
|
||||
{
|
||||
|
@ -65,4 +66,3 @@ public static class EldbusServiceNativeFunctions
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,11 @@
|
|||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Efl { namespace Eo {
|
||||
namespace Efl
|
||||
{
|
||||
|
||||
namespace Eo
|
||||
{
|
||||
|
||||
///<summary>Class to load functions pointers from a native module.
|
||||
///
|
||||
|
@ -51,22 +55,28 @@ public class FunctionWrapper<T> // NOTE: When supporting C# >=7.3, add a where T
|
|||
private static FunctionLoadResult<T> LazyInitialization(NativeModule module, string functionName)
|
||||
{
|
||||
if (module.Module == IntPtr.Zero)
|
||||
{
|
||||
return new FunctionLoadResult<T>(FunctionLoadResultKind.LibraryNotFound);
|
||||
}
|
||||
else
|
||||
{
|
||||
IntPtr funcptr = FunctionInterop.LoadFunctionPointer(module.Module, functionName);
|
||||
if (funcptr == IntPtr.Zero)
|
||||
{
|
||||
return new FunctionLoadResult<T>(FunctionLoadResultKind.FunctionNotFound);
|
||||
}
|
||||
else
|
||||
{
|
||||
return new FunctionLoadResult<T>(Marshal.GetDelegateForFunctionPointer<T>(funcptr));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
///<summary>Creates a wrapper for the given function of the given module.</summary>
|
||||
///<param name="moduleName">The name of the module containing the function.</param>
|
||||
///<param name="functionName">The name of the function to search for.</param>
|
||||
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>
|
||||
public enum FunctionLoadResultKind {
|
||||
public enum FunctionLoadResultKind
|
||||
{
|
||||
///<summary>Function was loaded successfully.</summary>
|
||||
Success,
|
||||
///<summary>Library was not found.</summary>
|
||||
|
@ -116,9 +127,13 @@ public class FunctionLoadResult<T>
|
|||
///Throws InvalidOperationException if trying to access while not loaded.</summary>
|
||||
public T Delegate
|
||||
{
|
||||
get {
|
||||
get
|
||||
{
|
||||
if (_Delegate == null)
|
||||
{
|
||||
throw new InvalidOperationException($"Trying to get Delegate while not loaded. Load result: {Kind}");
|
||||
}
|
||||
|
||||
return _Delegate;
|
||||
}
|
||||
}
|
||||
|
@ -139,4 +154,6 @@ public class FunctionLoadResult<T>
|
|||
}
|
||||
}
|
||||
|
||||
} }
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,7 +1,11 @@
|
|||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Efl { namespace Eo {
|
||||
namespace Efl
|
||||
{
|
||||
|
||||
namespace Eo
|
||||
{
|
||||
|
||||
public partial class FunctionInterop
|
||||
{
|
||||
|
@ -21,4 +25,6 @@ public partial class FunctionInterop
|
|||
}
|
||||
}
|
||||
|
||||
} }
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,7 +1,11 @@
|
|||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Efl { namespace Eo {
|
||||
namespace Efl
|
||||
{
|
||||
|
||||
namespace Eo
|
||||
{
|
||||
|
||||
public partial class FunctionInterop
|
||||
{
|
||||
|
@ -12,4 +16,6 @@ public partial class FunctionInterop
|
|||
=> FunctionInterop.GetProcAddress(nativeLibraryHandle, functionName);
|
||||
}
|
||||
|
||||
} }
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
using System;
|
||||
|
||||
namespace Efl { namespace Eo {
|
||||
namespace Efl
|
||||
{
|
||||
|
||||
namespace Eo
|
||||
{
|
||||
|
||||
///<summary>Wraps a native module that was opened with dlopen/LoadLibrary.</summary>
|
||||
public partial class NativeModule : IDisposable
|
||||
|
@ -35,4 +39,6 @@ public partial class NativeModule : IDisposable
|
|||
}
|
||||
}
|
||||
|
||||
} }
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,7 +1,11 @@
|
|||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Efl { namespace Eo {
|
||||
namespace Efl
|
||||
{
|
||||
|
||||
namespace Eo
|
||||
{
|
||||
|
||||
public partial class NativeModule
|
||||
{
|
||||
|
@ -60,11 +64,11 @@ public partial class NativeModule
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
} }
|
||||
}
|
||||
|
|
|
@ -1,7 +1,11 @@
|
|||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Efl { namespace Eo {
|
||||
namespace Efl
|
||||
{
|
||||
|
||||
namespace Eo
|
||||
{
|
||||
|
||||
public class partial NativeModule
|
||||
{
|
||||
|
@ -9,7 +13,6 @@ public class partial NativeModule
|
|||
public static extern IntPtr LoadLibrary(string libFilename);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
} }
|
||||
}
|
||||
|
|
|
@ -9,12 +9,17 @@ using System.Threading;
|
|||
using static Eina.NativeCustomExportFunctions;
|
||||
using EoG = Efl.Eo.Globals;
|
||||
|
||||
namespace Efl { namespace Eo {
|
||||
namespace Efl
|
||||
{
|
||||
|
||||
public class Globals {
|
||||
namespace Eo
|
||||
{
|
||||
|
||||
public class Globals
|
||||
{
|
||||
/// <summary>Represents the type of the native Efl_Class.</summary>
|
||||
public enum EflClassType {
|
||||
public enum EflClassType
|
||||
{
|
||||
/// <summary>Regular EFL classes.</summary>
|
||||
Regular = 0,
|
||||
/// <summary>Non-instantiable efl classes (i.e. Abstracts).</summary>
|
||||
|
@ -205,14 +210,17 @@ public class Globals {
|
|||
{
|
||||
return v.Value;
|
||||
}
|
||||
|
||||
public static U GetParamHelper<U>(U v)
|
||||
{
|
||||
return v;
|
||||
}
|
||||
|
||||
public static bool ParamHelperCheck<T>(Nullable<T> v) where T : struct
|
||||
{
|
||||
return v.HasValue;
|
||||
}
|
||||
|
||||
public static bool ParamHelperCheck<U>(U v)
|
||||
{
|
||||
return v != null;
|
||||
|
@ -243,12 +251,18 @@ public class Globals {
|
|||
|
||||
Eina.Log.Debug($"Going to register new class named {class_name}");
|
||||
IntPtr klass = EoG.call_efl_class_new(description_ptr, base_klass, interface_list);
|
||||
if(klass == IntPtr.Zero)
|
||||
if (klass == IntPtr.Zero)
|
||||
{
|
||||
Eina.Log.Error("klass was not registered");
|
||||
}
|
||||
else
|
||||
{
|
||||
Eina.Log.Debug("Registered class successfully");
|
||||
}
|
||||
|
||||
return klass;
|
||||
}
|
||||
|
||||
public static List<IntPtr> get_efl_interfaces(System.Type type)
|
||||
{
|
||||
System.Type base_type = type.BaseType;
|
||||
|
@ -263,26 +277,32 @@ public class Globals {
|
|||
var attrs = System.Attribute.GetCustomAttributes(iface);
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ifaces_lst;
|
||||
}
|
||||
|
||||
private static Efl.Eo.NativeClass get_native_class(System.Type type)
|
||||
{
|
||||
var attrs = System.Attribute.GetCustomAttributes(type);
|
||||
foreach (var attr in attrs)
|
||||
{
|
||||
if (attr is Efl.Eo.NativeClass) {
|
||||
if (attr is Efl.Eo.NativeClass)
|
||||
{
|
||||
return (Efl.Eo.NativeClass)attr;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static byte class_initializer_call(IntPtr klass, System.Type type)
|
||||
{
|
||||
Eina.Log.Debug($"called with 0x{klass.ToInt64():x} {type}");
|
||||
|
@ -301,7 +321,7 @@ public class Globals {
|
|||
if (!System.Array.Exists(base_interfaces, element => element == iface))
|
||||
{
|
||||
var nc = get_native_class(iface);
|
||||
if(nc != null)
|
||||
if (nc != null)
|
||||
{
|
||||
var moredescs = nc.GetEoOps(type);
|
||||
Eina.Log.Debug($"adding {moredescs.Count} more descs to registration");
|
||||
|
@ -311,13 +331,14 @@ public class Globals {
|
|||
}
|
||||
}
|
||||
|
||||
IntPtr descs_ptr = Marshal.AllocHGlobal(Marshal.SizeOf(descs[0])*count);
|
||||
IntPtr descs_ptr = Marshal.AllocHGlobal(Marshal.SizeOf(descs[0]) * count);
|
||||
IntPtr ptr = descs_ptr;
|
||||
for(int i = 0; i != count; ++i)
|
||||
for (int i = 0; i != count; ++i)
|
||||
{
|
||||
Marshal.StructureToPtr(descs[i], ptr, false);
|
||||
ptr = IntPtr.Add(ptr, Marshal.SizeOf(descs[0]));
|
||||
}
|
||||
|
||||
Efl_Object_Ops ops;
|
||||
ops.descs = descs_ptr;
|
||||
ops.count = (UIntPtr)count;
|
||||
|
@ -327,15 +348,18 @@ public class Globals {
|
|||
//EoKlass = klass;
|
||||
}
|
||||
else
|
||||
{
|
||||
Eina.Log.Debug("nativeClass == null");
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
public static IntPtr call_efl_class_new(IntPtr desc, IntPtr bk, List<IntPtr> il = null)
|
||||
{
|
||||
IntPtr nul = IntPtr.Zero;
|
||||
int iface_list_count = (il == null ? 0 : il.Count);
|
||||
switch(iface_list_count)
|
||||
switch (iface_list_count)
|
||||
{
|
||||
default: return nul;
|
||||
case 0: return EoG.efl_class_new(desc, bk, nul);
|
||||
|
@ -389,12 +413,15 @@ public class Globals {
|
|||
case 48: return EoG.efl_class_new(desc, bk, il[0], il[1], il[2], il[3], il[4], il[5], il[6], il[7], il[8], il[9], il[10], il[11], il[12], il[13], il[14], il[15], il[16], il[17], il[18], il[19], il[20], il[21], il[22], il[23], il[24], il[25], il[26], il[27], il[28], il[29], il[30], il[31], il[32], il[33], il[34], il[35], il[36], il[37], il[38], il[39], il[40], il[41], il[42], il[43], il[44], il[45], il[46], il[47], nul);
|
||||
}
|
||||
}
|
||||
|
||||
public static IntPtr instantiate_start(IntPtr klass, Efl.Object parent)
|
||||
{
|
||||
Eina.Log.Debug($"Instantiating from klass 0x{klass.ToInt64():x}");
|
||||
System.IntPtr parent_ptr = System.IntPtr.Zero;
|
||||
if(parent != null)
|
||||
if (parent != null)
|
||||
{
|
||||
parent_ptr = parent.NativeHandle;
|
||||
}
|
||||
|
||||
System.IntPtr eo = Efl.Eo.Globals._efl_add_internal_start("file", 0, klass, parent_ptr, 1, 0);
|
||||
if (eo == System.IntPtr.Zero)
|
||||
|
@ -407,12 +434,14 @@ public class Globals {
|
|||
return eo;
|
||||
}
|
||||
|
||||
public static IntPtr instantiate_end(IntPtr eo) {
|
||||
public static IntPtr instantiate_end(IntPtr eo)
|
||||
{
|
||||
Eina.Log.Debug("calling efl_add_internal_end");
|
||||
eo = Efl.Eo.Globals._efl_add_end(eo, 1, 0);
|
||||
Eina.Log.Debug($"efl_add_end returned eo 0x{eo.ToInt64():x}");
|
||||
return eo;
|
||||
}
|
||||
|
||||
public static void data_set(Efl.Eo.IWrapper obj)
|
||||
{
|
||||
Eina.Log.Debug($"Calling data_scope_get with obj {obj.NativeHandle.ToInt64():x} and klass {obj.NativeClass.ToInt64():x}");
|
||||
|
@ -424,21 +453,24 @@ public class Globals {
|
|||
Marshal.StructureToPtr(epd, pd, false);
|
||||
}
|
||||
}
|
||||
|
||||
public static Efl.Eo.IWrapper data_get(IntPtr pd)
|
||||
{
|
||||
EolianPD epd = (EolianPD)Marshal.PtrToStructure(pd, typeof(EolianPD));
|
||||
if(epd.pointer != IntPtr.Zero)
|
||||
if (epd.pointer != IntPtr.Zero)
|
||||
{
|
||||
GCHandle gch = GCHandle.FromIntPtr(epd.pointer);
|
||||
return (Efl.Eo.IWrapper)gch.Target;
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static void free_dict_values(Dictionary<String, IntPtr> dict)
|
||||
{
|
||||
foreach(IntPtr ptr in dict.Values)
|
||||
foreach (IntPtr ptr in dict.Values)
|
||||
{
|
||||
Eina.MemoryNative.Free(ptr);
|
||||
}
|
||||
|
@ -446,7 +478,7 @@ public class Globals {
|
|||
|
||||
public static void free_stringshare_values(Dictionary<String, IntPtr> dict)
|
||||
{
|
||||
foreach(IntPtr ptr in dict.Values)
|
||||
foreach (IntPtr ptr in dict.Values)
|
||||
{
|
||||
Eina.Stringshare.eina_stringshare_del(ptr);
|
||||
}
|
||||
|
@ -467,7 +499,8 @@ public class Globals {
|
|||
// Flag to be passed to the cancell callback
|
||||
bool fulfilled = false;
|
||||
|
||||
future.Then((Eina.Value received) => {
|
||||
future.Then((Eina.Value received) =>
|
||||
{
|
||||
lock (future)
|
||||
{
|
||||
// Convert an failed Future to a failed Task.
|
||||
|
@ -476,27 +509,35 @@ public class Globals {
|
|||
Eina.Error err;
|
||||
received.Get(out err);
|
||||
if (err == Eina.Error.ECANCELED)
|
||||
{
|
||||
tcs.SetCanceled();
|
||||
}
|
||||
else
|
||||
{
|
||||
tcs.TrySetException(new Efl.FutureException(received));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Will mark the returned task below as completed.
|
||||
tcs.SetResult(received);
|
||||
}
|
||||
|
||||
fulfilled = true;
|
||||
return received;
|
||||
}
|
||||
});
|
||||
// Callback to be called when the token is cancelled.
|
||||
token.Register(() => {
|
||||
token.Register(() =>
|
||||
{
|
||||
lock (future)
|
||||
{
|
||||
// Will trigger the Then callback above with an Eina.Error
|
||||
if (!fulfilled)
|
||||
{
|
||||
future.Cancel();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return tcs.Task;
|
||||
|
@ -534,6 +575,7 @@ public interface IWrapper
|
|||
{
|
||||
get;
|
||||
}
|
||||
|
||||
/// <summary>Pointer to internal Eo class.</summary>
|
||||
IntPtr NativeClass
|
||||
{
|
||||
|
@ -547,11 +589,14 @@ public static class ClassRegister
|
|||
{
|
||||
System.Type t;
|
||||
if (Efl.Eo.ClassRegister.typeFromKlass.TryGetValue(klass, out t))
|
||||
{
|
||||
return t;
|
||||
}
|
||||
|
||||
// If it isn't on the dictionary then it is a Native binding class
|
||||
IntPtr namePtr = Efl.Eo.Globals.efl_class_name_get(klass);
|
||||
if (namePtr == IntPtr.Zero) {
|
||||
if (namePtr == IntPtr.Zero)
|
||||
{
|
||||
throw new System.InvalidOperationException($"Could not get Native class name. Handle: {klass}");
|
||||
}
|
||||
|
||||
|
@ -574,16 +619,23 @@ public static class ClassRegister
|
|||
foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
|
||||
{
|
||||
if (assembly == curr_asm)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
t = assembly.GetType(name);
|
||||
if (t != null)
|
||||
{
|
||||
break;
|
||||
}
|
||||
if (t == null) {
|
||||
}
|
||||
|
||||
if (t == null)
|
||||
{
|
||||
throw new System.InvalidOperationException($"Could not find the C# binding class for the EFL class: {name}");
|
||||
}
|
||||
}
|
||||
|
||||
AddToKlassTypeBiDictionary(klass, t); // Cache it in the dictionary
|
||||
return t;
|
||||
}
|
||||
|
@ -592,11 +644,14 @@ public static class ClassRegister
|
|||
{
|
||||
IntPtr klass;
|
||||
if (klassFromType.TryGetValue(objectType, out klass))
|
||||
{
|
||||
return klass;
|
||||
}
|
||||
|
||||
// Check if it is a Native binding class
|
||||
klass = GetNativeKlassPtr(objectType);
|
||||
if (klass != IntPtr.Zero) {
|
||||
if (klass != IntPtr.Zero)
|
||||
{
|
||||
// Add to the dictionary cache
|
||||
AddToKlassTypeBiDictionary(klass, objectType);
|
||||
return klass;
|
||||
|
@ -605,7 +660,10 @@ public static class ClassRegister
|
|||
// Unregistered Inherited class, let's register it
|
||||
IntPtr baseKlass = GetNativeBaseKlassPtr(objectType);
|
||||
if (baseKlass == IntPtr.Zero)
|
||||
{
|
||||
throw new System.InvalidOperationException($"Could not get base C# binding class for Inherited type: {objectType.FullName}");
|
||||
}
|
||||
|
||||
return RegisterKlass(baseKlass, objectType);
|
||||
}
|
||||
|
||||
|
@ -613,18 +671,23 @@ public static class ClassRegister
|
|||
{
|
||||
IntPtr klass;
|
||||
if (klassFromType.TryGetValue(objectType, out klass))
|
||||
{
|
||||
return klass;
|
||||
}
|
||||
|
||||
return RegisterKlass(baseKlass, objectType);
|
||||
}
|
||||
|
||||
private static IntPtr RegisterKlass(IntPtr baseKlass, System.Type objectType)
|
||||
{
|
||||
lock (klassAllocLock) {
|
||||
lock (klassAllocLock)
|
||||
{
|
||||
IntPtr newKlass = Efl.Eo.Globals.register_class(objectType.FullName, baseKlass, objectType);
|
||||
if (newKlass == IntPtr.Zero) {
|
||||
if (newKlass == IntPtr.Zero)
|
||||
{
|
||||
throw new System.InvalidOperationException($"Failed to register class '{objectType.FullName}'");
|
||||
}
|
||||
|
||||
AddToKlassTypeBiDictionary(newKlass, objectType);
|
||||
return newKlass;
|
||||
}
|
||||
|
@ -636,15 +699,20 @@ public static class ClassRegister
|
|||
{
|
||||
var ptr = GetNativeKlassPtr(t);
|
||||
if (ptr != IntPtr.Zero)
|
||||
{
|
||||
return ptr;
|
||||
}
|
||||
}
|
||||
|
||||
throw new System.InvalidOperationException($"Class '{objectType.FullName}' is not an Efl object");
|
||||
}
|
||||
|
||||
private static IntPtr GetNativeKlassPtr(System.Type objectType)
|
||||
{
|
||||
if (objectType == null)
|
||||
{
|
||||
return IntPtr.Zero;
|
||||
}
|
||||
|
||||
if (objectType.IsInterface)
|
||||
{
|
||||
|
@ -653,15 +721,20 @@ public static class ClassRegister
|
|||
objectType = assembly.GetType(objectType.FullName + "Concrete");
|
||||
|
||||
if (objectType == null)
|
||||
{
|
||||
return IntPtr.Zero;
|
||||
}
|
||||
}
|
||||
|
||||
var method = objectType.GetMethod("GetEflClassStatic",
|
||||
System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic);
|
||||
|
||||
if (method == null)
|
||||
{
|
||||
return IntPtr.Zero;
|
||||
return (IntPtr) (method.Invoke(null, null));
|
||||
}
|
||||
|
||||
return (IntPtr)(method.Invoke(null, null));
|
||||
}
|
||||
|
||||
public static void AddToKlassTypeBiDictionary(IntPtr klassPtr, System.Type objectType)
|
||||
|
@ -699,6 +772,7 @@ public class MarshalTest<T, U> : ICustomMarshaler
|
|||
Eina.Log.Debug("MarshalTest.GetInstace cookie " + cookie);
|
||||
return new MarshalTest<T, U>();
|
||||
}
|
||||
|
||||
public void CleanUpManagedData(object ManagedObj)
|
||||
{
|
||||
//Eina.Log.Warning("MarshalTest.CleanUpManagedData not implemented");
|
||||
|
@ -723,7 +797,10 @@ public class MarshalTest<T, U> : ICustomMarshaler
|
|||
Eina.Log.Debug("MarshalTest.MarshallManagedToNative");
|
||||
var r = ((IWrapper)ManagedObj).NativeHandle;
|
||||
if (typeof(U) == typeof(OwnTag))
|
||||
{
|
||||
Efl.Eo.Globals.efl_ref(r);
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
|
@ -731,9 +808,12 @@ public class MarshalTest<T, U> : ICustomMarshaler
|
|||
{
|
||||
Eina.Log.Debug("MarshalTest.MarshalNativeToManaged");
|
||||
if (typeof(U) != typeof(OwnTag))
|
||||
{
|
||||
Efl.Eo.Globals.efl_ref(pNativeData);
|
||||
}
|
||||
|
||||
return Activator.CreateInstance(typeof(T), new System.Object[] {pNativeData});
|
||||
// return null;
|
||||
//return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -745,6 +825,7 @@ public class MarshalEflClass : ICustomMarshaler
|
|||
Eina.Log.Debug("MarshalTest.GetInstance cookie " + cookie);
|
||||
return new MarshalEflClass();
|
||||
}
|
||||
|
||||
public void CleanUpManagedData(object ManagedObj)
|
||||
{
|
||||
}
|
||||
|
@ -763,8 +844,11 @@ public class MarshalEflClass : ICustomMarshaler
|
|||
{
|
||||
Eina.Log.Debug("MarshalTest.MarshallManagedToNative");
|
||||
if (ManagedObj == null)
|
||||
{
|
||||
return IntPtr.Zero;
|
||||
var t = (System.Type) ManagedObj;
|
||||
}
|
||||
|
||||
var t = (System.Type)ManagedObj;
|
||||
return Efl.Eo.ClassRegister.GetKlass(t);
|
||||
}
|
||||
|
||||
|
@ -772,194 +856,255 @@ public class MarshalEflClass : ICustomMarshaler
|
|||
{
|
||||
Eina.Log.Debug("MarshalTest.MarshalNativeToManaged");
|
||||
if (pNativeData == IntPtr.Zero)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return Efl.Eo.ClassRegister.GetManagedType(pNativeData);
|
||||
}
|
||||
}
|
||||
|
||||
public class StringPassOwnershipMarshaler : ICustomMarshaler {
|
||||
public object MarshalNativeToManaged(IntPtr pNativeData) {
|
||||
public class StringPassOwnershipMarshaler : ICustomMarshaler
|
||||
{
|
||||
public object MarshalNativeToManaged(IntPtr pNativeData)
|
||||
{
|
||||
var ret = Eina.StringConversion.NativeUtf8ToManagedString(pNativeData);
|
||||
Eina.MemoryNative.Free(pNativeData);
|
||||
return ret;
|
||||
}
|
||||
|
||||
public IntPtr MarshalManagedToNative(object managedObj) {
|
||||
public IntPtr MarshalManagedToNative(object managedObj)
|
||||
{
|
||||
return Eina.MemoryNative.StrDup((string)managedObj);
|
||||
}
|
||||
|
||||
public void CleanUpNativeData(IntPtr pNativeData) {
|
||||
public void CleanUpNativeData(IntPtr pNativeData)
|
||||
{
|
||||
// No need to cleanup. C will take care of it.
|
||||
}
|
||||
|
||||
public void CleanUpManagedData(object managedObj) {
|
||||
public void CleanUpManagedData(object managedObj)
|
||||
{
|
||||
}
|
||||
|
||||
public int GetNativeDataSize() {
|
||||
public int GetNativeDataSize()
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
public static ICustomMarshaler GetInstance(string cookie) {
|
||||
if (marshaler == null) {
|
||||
public static ICustomMarshaler GetInstance(string cookie)
|
||||
{
|
||||
if (marshaler == null)
|
||||
{
|
||||
marshaler = new StringPassOwnershipMarshaler();
|
||||
}
|
||||
|
||||
return marshaler;
|
||||
}
|
||||
|
||||
static private StringPassOwnershipMarshaler marshaler;
|
||||
}
|
||||
|
||||
public class StringKeepOwnershipMarshaler: ICustomMarshaler {
|
||||
public object MarshalNativeToManaged(IntPtr pNativeData) {
|
||||
public class StringKeepOwnershipMarshaler: ICustomMarshaler
|
||||
{
|
||||
public object MarshalNativeToManaged(IntPtr pNativeData)
|
||||
{
|
||||
return Eina.StringConversion.NativeUtf8ToManagedString(pNativeData);
|
||||
}
|
||||
|
||||
public IntPtr MarshalManagedToNative(object managedObj) {
|
||||
public IntPtr MarshalManagedToNative(object managedObj)
|
||||
{
|
||||
return Eina.StringConversion.ManagedStringToNativeUtf8Alloc((string)managedObj);
|
||||
}
|
||||
|
||||
public void CleanUpNativeData(IntPtr pNativeData) {
|
||||
public void CleanUpNativeData(IntPtr pNativeData)
|
||||
{
|
||||
// No need to free. The Native side will keep the ownership.
|
||||
}
|
||||
|
||||
public void CleanUpManagedData(object managedObj) {
|
||||
public void CleanUpManagedData(object managedObj)
|
||||
{
|
||||
}
|
||||
|
||||
public int GetNativeDataSize() {
|
||||
public int GetNativeDataSize()
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
public static ICustomMarshaler GetInstance(string cookie) {
|
||||
if (marshaler == null) {
|
||||
public static ICustomMarshaler GetInstance(string cookie)
|
||||
{
|
||||
if (marshaler == null)
|
||||
{
|
||||
marshaler = new StringKeepOwnershipMarshaler();
|
||||
}
|
||||
|
||||
return marshaler;
|
||||
}
|
||||
|
||||
static private StringKeepOwnershipMarshaler marshaler;
|
||||
}
|
||||
|
||||
public class StringsharePassOwnershipMarshaler : ICustomMarshaler {
|
||||
public object MarshalNativeToManaged(IntPtr pNativeData) {
|
||||
public class StringsharePassOwnershipMarshaler : ICustomMarshaler
|
||||
{
|
||||
public object MarshalNativeToManaged(IntPtr pNativeData)
|
||||
{
|
||||
var ret = Eina.StringConversion.NativeUtf8ToManagedString(pNativeData);
|
||||
Eina.Stringshare.eina_stringshare_del(pNativeData);
|
||||
return ret;
|
||||
}
|
||||
|
||||
public IntPtr MarshalManagedToNative(object managedObj) {
|
||||
public IntPtr MarshalManagedToNative(object managedObj)
|
||||
{
|
||||
return Eina.Stringshare.eina_stringshare_add((string)managedObj);
|
||||
}
|
||||
|
||||
public void CleanUpNativeData(IntPtr pNativeData) {
|
||||
public void CleanUpNativeData(IntPtr pNativeData)
|
||||
{
|
||||
// No need to free as it's for own() parameters.
|
||||
}
|
||||
|
||||
public void CleanUpManagedData(object managedObj) {
|
||||
public void CleanUpManagedData(object managedObj)
|
||||
{
|
||||
}
|
||||
|
||||
public int GetNativeDataSize() {
|
||||
public int GetNativeDataSize()
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
public static ICustomMarshaler GetInstance(string cookie) {
|
||||
if (marshaler == null) {
|
||||
public static ICustomMarshaler GetInstance(string cookie)
|
||||
{
|
||||
if (marshaler == null)
|
||||
{
|
||||
marshaler = new StringsharePassOwnershipMarshaler();
|
||||
}
|
||||
|
||||
return marshaler;
|
||||
}
|
||||
|
||||
static private StringsharePassOwnershipMarshaler marshaler;
|
||||
}
|
||||
|
||||
public class StringshareKeepOwnershipMarshaler : ICustomMarshaler {
|
||||
public object MarshalNativeToManaged(IntPtr pNativeData) {
|
||||
public class StringshareKeepOwnershipMarshaler : ICustomMarshaler
|
||||
{
|
||||
public object MarshalNativeToManaged(IntPtr pNativeData)
|
||||
{
|
||||
return Eina.StringConversion.NativeUtf8ToManagedString(pNativeData);
|
||||
}
|
||||
|
||||
public IntPtr MarshalManagedToNative(object managedObj) {
|
||||
public IntPtr MarshalManagedToNative(object managedObj)
|
||||
{
|
||||
return Eina.Stringshare.eina_stringshare_add((string)managedObj);
|
||||
}
|
||||
|
||||
public void CleanUpNativeData(IntPtr pNativeData) {
|
||||
public void CleanUpNativeData(IntPtr pNativeData)
|
||||
{
|
||||
// No need to free, as the native side will keep ownership.
|
||||
}
|
||||
|
||||
public void CleanUpManagedData(object managedObj) {
|
||||
public void CleanUpManagedData(object managedObj)
|
||||
{
|
||||
}
|
||||
|
||||
public int GetNativeDataSize() {
|
||||
public int GetNativeDataSize()
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
public static ICustomMarshaler GetInstance(string cookie) {
|
||||
if (marshaler == null) {
|
||||
public static ICustomMarshaler GetInstance(string cookie)
|
||||
{
|
||||
if (marshaler == null)
|
||||
{
|
||||
marshaler = new StringshareKeepOwnershipMarshaler();
|
||||
}
|
||||
|
||||
return marshaler;
|
||||
}
|
||||
|
||||
static private StringshareKeepOwnershipMarshaler marshaler;
|
||||
}
|
||||
|
||||
public class StrbufPassOwnershipMarshaler : ICustomMarshaler {
|
||||
public object MarshalNativeToManaged(IntPtr pNativeData) {
|
||||
public class StrbufPassOwnershipMarshaler : ICustomMarshaler
|
||||
{
|
||||
public object MarshalNativeToManaged(IntPtr pNativeData)
|
||||
{
|
||||
return new Eina.Strbuf(pNativeData, Eina.Ownership.Managed);
|
||||
}
|
||||
|
||||
public IntPtr MarshalManagedToNative(object managedObj) {
|
||||
public IntPtr MarshalManagedToNative(object managedObj)
|
||||
{
|
||||
Eina.Strbuf buf = managedObj as Eina.Strbuf;
|
||||
buf.ReleaseOwnership();
|
||||
return buf.Handle;
|
||||
}
|
||||
|
||||
public void CleanUpNativeData(IntPtr pNativeData) {
|
||||
public void CleanUpNativeData(IntPtr pNativeData)
|
||||
{
|
||||
// No need to cleanup. C will take care of it.
|
||||
}
|
||||
|
||||
public void CleanUpManagedData(object managedObj) {
|
||||
public void CleanUpManagedData(object managedObj)
|
||||
{
|
||||
}
|
||||
|
||||
public int GetNativeDataSize() {
|
||||
public int GetNativeDataSize()
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
public static ICustomMarshaler GetInstance(string cookie) {
|
||||
if (marshaler == null) {
|
||||
public static ICustomMarshaler GetInstance(string cookie)
|
||||
{
|
||||
if (marshaler == null)
|
||||
{
|
||||
marshaler = new StrbufPassOwnershipMarshaler();
|
||||
}
|
||||
|
||||
return marshaler;
|
||||
}
|
||||
|
||||
static private StrbufPassOwnershipMarshaler marshaler;
|
||||
}
|
||||
|
||||
public class StrbufKeepOwnershipMarshaler: ICustomMarshaler {
|
||||
public object MarshalNativeToManaged(IntPtr pNativeData) {
|
||||
public class StrbufKeepOwnershipMarshaler: ICustomMarshaler
|
||||
{
|
||||
public object MarshalNativeToManaged(IntPtr pNativeData)
|
||||
{
|
||||
return new Eina.Strbuf(pNativeData, Eina.Ownership.Unmanaged);
|
||||
}
|
||||
|
||||
public IntPtr MarshalManagedToNative(object managedObj) {
|
||||
public IntPtr MarshalManagedToNative(object managedObj)
|
||||
{
|
||||
Eina.Strbuf buf = managedObj as Eina.Strbuf;
|
||||
return buf.Handle;
|
||||
}
|
||||
|
||||
public void CleanUpNativeData(IntPtr pNativeData) {
|
||||
public void CleanUpNativeData(IntPtr pNativeData)
|
||||
{
|
||||
// No need to free. The Native side will keep the ownership.
|
||||
}
|
||||
|
||||
public void CleanUpManagedData(object managedObj) {
|
||||
public void CleanUpManagedData(object managedObj)
|
||||
{
|
||||
}
|
||||
|
||||
public int GetNativeDataSize() {
|
||||
public int GetNativeDataSize()
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
public static ICustomMarshaler GetInstance(string cookie) {
|
||||
if (marshaler == null) {
|
||||
public static ICustomMarshaler GetInstance(string cookie)
|
||||
{
|
||||
if (marshaler == null)
|
||||
{
|
||||
marshaler = new StrbufKeepOwnershipMarshaler();
|
||||
}
|
||||
|
||||
return marshaler;
|
||||
}
|
||||
|
||||
static private StrbufKeepOwnershipMarshaler marshaler;
|
||||
}
|
||||
|
||||
|
||||
|
||||
} // namespace eo
|
||||
|
||||
/// <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.")
|
||||
{
|
||||
if (value.GetValueType() != Eina.ValueType.Error)
|
||||
{
|
||||
throw new ArgumentException("FutureException must receive an Eina.Value with Eina.Error.");
|
||||
}
|
||||
|
||||
Eina.Error err;
|
||||
value.Get(out err);
|
||||
Error = err;
|
||||
|
|
|
@ -51,28 +51,35 @@ public struct EolianPD
|
|||
}
|
||||
|
||||
#pragma warning disable 0169
|
||||
|
||||
public struct EvasObjectBoxLayout
|
||||
{
|
||||
IntPtr o;
|
||||
IntPtr priv;
|
||||
IntPtr user_data;
|
||||
};
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Ansi)]
|
||||
public struct EvasObjectBoxData
|
||||
{
|
||||
}
|
||||
public struct EvasObjectBoxOption {
|
||||
|
||||
public struct EvasObjectBoxOption
|
||||
{
|
||||
IntPtr obj;
|
||||
[MarshalAsAttribute(UnmanagedType.U1)] bool max_reached;
|
||||
[MarshalAsAttribute(UnmanagedType.U1)] bool min_reached;
|
||||
Evas.Coord alloc_size;
|
||||
};
|
||||
|
||||
#pragma warning restore 0169
|
||||
|
||||
namespace Efl {
|
||||
namespace Efl
|
||||
{
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct EventDescription {
|
||||
public struct EventDescription
|
||||
{
|
||||
public IntPtr Name;
|
||||
[MarshalAs(UnmanagedType.U1)] public bool Unfreezable;
|
||||
[MarshalAs(UnmanagedType.U1)] public bool Legacy_is;
|
||||
|
@ -94,12 +101,15 @@ public struct EventDescription {
|
|||
{
|
||||
IntPtr data = Efl.Eo.FunctionInterop.LoadFunctionPointer(module, name);
|
||||
|
||||
if (data == IntPtr.Zero) {
|
||||
if (data == IntPtr.Zero)
|
||||
{
|
||||
string error = Eina.StringConversion.NativeUtf8ToManagedString(Efl.Eo.Globals.dlerror());
|
||||
throw new Exception(error);
|
||||
}
|
||||
|
||||
descriptions.Add(name, data);
|
||||
}
|
||||
|
||||
return descriptions[name];
|
||||
}
|
||||
};
|
||||
|
@ -107,7 +117,8 @@ public struct EventDescription {
|
|||
public delegate void EventCb(System.IntPtr data, ref Event.NativeStruct evt);
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct TextCursorCursor {
|
||||
public struct TextCursorCursor
|
||||
{
|
||||
IntPtr obj;
|
||||
UIntPtr pos; // UIntPtr to automatically change size_t between 32/64
|
||||
IntPtr node;
|
||||
|
@ -115,7 +126,8 @@ public struct TextCursorCursor {
|
|||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct TextAnnotateAnnotation {
|
||||
public struct TextAnnotateAnnotation
|
||||
{
|
||||
IntPtr list;
|
||||
IntPtr obj;
|
||||
IntPtr start_node;
|
||||
|
@ -125,9 +137,11 @@ public struct TextAnnotateAnnotation {
|
|||
|
||||
public delegate void SignalCb(IntPtr data, IntPtr obj, IntPtr emission, IntPtr source);
|
||||
|
||||
namespace Access {
|
||||
namespace Access
|
||||
{
|
||||
|
||||
public struct ActionData {
|
||||
public struct ActionData
|
||||
{
|
||||
public IntPtr name;
|
||||
public IntPtr action;
|
||||
public IntPtr param;
|
||||
|
@ -138,16 +152,25 @@ public struct ActionData {
|
|||
|
||||
} // namespace Efl
|
||||
|
||||
namespace Evas {
|
||||
namespace Evas
|
||||
{
|
||||
|
||||
public struct Coord {
|
||||
public struct Coord
|
||||
{
|
||||
int val;
|
||||
|
||||
public Coord(int value) { val = value; }
|
||||
static public implicit operator Coord(int val) {
|
||||
public Coord(int value)
|
||||
{
|
||||
val = value;
|
||||
}
|
||||
|
||||
static public implicit operator Coord(int val)
|
||||
{
|
||||
return new Coord(val);
|
||||
}
|
||||
static public implicit operator int(Coord coord) {
|
||||
|
||||
static public implicit operator int(Coord coord)
|
||||
{
|
||||
return coord.val;
|
||||
}
|
||||
}
|
||||
|
@ -180,7 +203,7 @@ public enum TextStyleType
|
|||
///<summary> shadow growing to bottom right.</summary>
|
||||
ShadowDirectionBottomRight = 0 /* 0 >> 4 */,
|
||||
///<summary> shadow growing to the bottom.</summary>
|
||||
ShadowDirectionBottom= 16 /* 1 >> 4 */,
|
||||
ShadowDirectionBottom = 16 /* 1 >> 4 */,
|
||||
///<summary> shadow growing to bottom left.</summary>
|
||||
ShadowDirectionBottomLeft = 32 /* 2 >> 4 */,
|
||||
///<summary> shadow growing to the left.</summary>
|
||||
|
|
Loading…
Reference in New Issue