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
devs/lauromoura/csharp_conventions
Jaehyun Cho 4 years ago committed by Xavi Artigas
parent 731db8b644
commit 0d37e8ff49
  1. 47
      src/bindings/mono/efl_mono/efl_all.cs
  2. 210
      src/bindings/mono/efl_mono/efl_csharp_application.cs
  3. 21
      src/bindings/mono/eina_mono/eina_accessor.cs
  4. 40
      src/bindings/mono/eina_mono/eina_array.cs
  5. 12
      src/bindings/mono/eina_mono/eina_binbuf.cs
  6. 13
      src/bindings/mono/eina_mono/eina_common.cs
  7. 25
      src/bindings/mono/eina_mono/eina_config.cs
  8. 131
      src/bindings/mono/eina_mono/eina_container_common.cs
  9. 15
      src/bindings/mono/eina_mono/eina_error.cs
  10. 26
      src/bindings/mono/eina_mono/eina_hash.cs
  11. 49
      src/bindings/mono/eina_mono/eina_inarray.cs
  12. 26
      src/bindings/mono/eina_mono/eina_inlist.cs
  13. 13
      src/bindings/mono/eina_mono/eina_iterator.cs
  14. 24
      src/bindings/mono/eina_mono/eina_list.cs
  15. 35
      src/bindings/mono/eina_mono/eina_log.cs
  16. 62
      src/bindings/mono/eina_mono/eina_promises.cs
  17. 11
      src/bindings/mono/eina_mono/eina_slice.cs
  18. 24
      src/bindings/mono/eina_mono/eina_strbuf.cs
  19. 7
      src/bindings/mono/eina_mono/eina_stringshare.cs
  20. 567
      src/bindings/mono/eina_mono/eina_value.cs
  21. 301
      src/bindings/mono/eldbus_mono/eldbus_common.cs
  22. 5
      src/bindings/mono/eldbus_mono/eldbus_config.cs
  23. 59
      src/bindings/mono/eldbus_mono/eldbus_connection.cs
  24. 46
      src/bindings/mono/eldbus_mono/eldbus_message.cs
  25. 36
      src/bindings/mono/eldbus_mono/eldbus_object.cs
  26. 4
      src/bindings/mono/eldbus_mono/eldbus_pending.cs
  27. 23
      src/bindings/mono/eldbus_mono/eldbus_proxy.cs
  28. 4
      src/bindings/mono/eldbus_mono/eldbus_service.cs
  29. 27
      src/bindings/mono/eo_mono/FunctionWrapper.cs
  30. 10
      src/bindings/mono/eo_mono/FunctionWrapper_Unix.cs
  31. 10
      src/bindings/mono/eo_mono/FunctionWrapper_Windows.cs
  32. 10
      src/bindings/mono/eo_mono/NativeModule.cs
  33. 12
      src/bindings/mono/eo_mono/NativeModule_Unix.cs
  34. 11
      src/bindings/mono/eo_mono/NativeModule_Windows.cs
  35. 506
      src/bindings/mono/eo_mono/iwrapper.cs
  36. 129
      src/bindings/mono/eo_mono/workaround.cs

@ -6,10 +6,11 @@ using System.Threading;
using static Efl.UnsafeNativeMethods;
namespace Efl {
static class UnsafeNativeMethods {
namespace Efl
{
static class UnsafeNativeMethods
{
private delegate void init_func_delegate();
[DllImport(efl.Libs.Ecore)] public static extern void ecore_init();
[DllImport(efl.Libs.Ecore)] public static extern void ecore_shutdown();
@ -27,39 +28,48 @@ static class UnsafeNativeMethods {
[DllImport(efl.Libs.Elementary)] public static extern void elm_run();
[DllImport(efl.Libs.Elementary)] public static extern void elm_exit();
static UnsafeNativeMethods() {
static UnsafeNativeMethods()
{
_evas_init = new Efl.Eo.FunctionWrapper<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,99 +3,131 @@ 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 {
///<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 {
//the initializied components
private static Components initComponent;
//what follows are 3 private functions to boot up the internals of efl
private static void Init(Efl.Csharp.Components component) {
namespace Efl
{
namespace Csharp
{
///<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
{
//the initializied components
private static Components initComponent;
//what follows are 3 private functions to boot up the internals of efl
private static void Init(Efl.Csharp.Components component)
{
Eina.Config.Init();
Efl.Eo.Config.Init();
ecore_init();
evas_init();
eldbus.Config.Init();
if (component == Components.Ui) {
// TODO Support elm command line arguments
#if WIN32 // Not a native define, we define it in our build system
// Ecore_Win32 uses OleInitialize, which requires single thread apartments
if (System.Threading.Thread.CurrentThread.GetApartmentState() != ApartmentState.STA)
throw new InvalidOperationException("UI Applications require STAThreadAttribute in Main()");
if (component == Components.Ui)
{
// TODO Support elm command line arguments
#if WIN32 // Not a native define, we define it in our build system
// Ecore_Win32 uses OleInitialize, which requires single thread apartments
if (System.Threading.Thread.CurrentThread.GetApartmentState() != ApartmentState.STA)
{
throw new InvalidOperationException("UI Applications require STAThreadAttribute in Main()");
}
#endif
elm_init(0, IntPtr.Zero);
elm_init(0, IntPtr.Zero);
elm_policy_set((int)Elm.Policy.Quit, (int)Elm.PolicyQuit.LastWindowHidden);
elm_policy_set((int)Elm.Policy.Quit, (int)Elm.PolicyQuit.LastWindowHidden);
}
initComponent = component;
}
private static void Shutdown() {
}
private static void Shutdown()
{
// Try to cleanup everything before actually shutting down.
System.GC.Collect();
System.GC.WaitForPendingFinalizers();
if (initComponent == Components.Ui) {
elm_shutdown();
if (initComponent == Components.Ui)
{
elm_shutdown();
}
eldbus.Config.Shutdown();
evas_shutdown();
ecore_shutdown();
Efl.Eo.Config.Shutdown();
Eina.Config.Shutdown();
}
/// <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.
/// </summary>
/// <remarks>
/// When Initialize is true then OnInitialize is also called
/// </remarks>
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() { }
/// <summary>
/// Called before an application is used again after a call to OnPause().
/// </summary>
protected virtual void OnResume() { }
/// <summary>
/// Called before starting the shutdown of the application.
/// </summary>
protected virtual void OnTerminate() { }
/// <summary>
/// This function initializices everything in EFL and runs your application.
/// This call will result in a call to OnInitialize(), which you application should override.
/// </summary>
public void Launch(Efl.Csharp.Components components=Components.Ui) {
}
/// <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.
/// </summary>
/// <remarks>
/// When Initialize is true then OnInitialize is also called
/// </remarks>
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()
{
}
/// <summary>
/// Called before an application is used again after a call to OnPause().
/// </summary>
protected virtual void OnResume()
{
}
/// <summary>
/// Called before starting the shutdown of the application.
/// </summary>
protected virtual void OnTerminate()
{
}
/// <summary>
/// This function initializices everything in EFL and runs your application.
/// This call will result in a call to OnInitialize(), which you application should override.
/// </summary>
public void Launch(Efl.Csharp.Components components = Components.Ui)
{
Init(components);
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) {
OnInitialize(evt.arg.Argv);
}
OnArguments(evt.arg);
app.ArgumentsEvt += (object sender, LoopArgumentsEvt_Args evt) =>
{
if (evt.arg.Initialization)
{
OnInitialize(evt.arg.Argv);
}
OnArguments(evt.arg);
};
app.PauseEvt += (object sender, EventArgs e) => {
OnPause();
app.PauseEvt += (object sender, EventArgs e) =>
{
OnPause();
};
app.ResumeEvt += (object sender, EventArgs e) => {
OnResume();
app.ResumeEvt += (object sender, EventArgs e) =>
{
OnResume();
};
app.TerminateEvt += (object sender, EventArgs e) => {
OnTerminate();
app.TerminateEvt += (object sender, EventArgs e) =>
{
OnTerminate();
};
app.Begin();
Shutdown();
}
}
}
}
}
}

@ -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&lt;T&gt;"/>.</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&lt;T&gt;"/>.</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,7 +65,9 @@ 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,19 +134,23 @@ 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;
// {
// 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,7 +52,9 @@ public class Binbuf : IDisposable
Handle = eina_binbuf_new();
Own = true;
if (Handle == IntPtr.Zero)
{
throw new SEHException("Could not alloc binbuf");
}
}
public Binbuf()
@ -98,7 +101,8 @@ public class Binbuf : IDisposable
{
IntPtr h = Handle;
Handle = IntPtr.Zero;
if (Own && h != IntPtr.Zero) {
if (Own && h != IntPtr.Zero)
{
eina_binbuf_free(Handle);
}
}
@ -180,7 +184,9 @@ public class Binbuf : IDisposable
{
var ptr = eina_binbuf_string_get(Handle);
if (ptr == IntPtr.Zero)
{
return null;
}
var size = (int)(this.GetLength());
byte[] mArray = new byte[size];

@ -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,10 +466,16 @@ 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);
@ -438,10 +504,16 @@ 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);
@ -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,11 +718,17 @@ public static class TraitFunctions
public static Eina.ElementType GetElementTypeCode(System.Type type)
{
if (IsEflObject(type))
{
return ElementType.ObjectType;
}
else if (IsString(type))
{
return ElementType.StringType;
}
else
{
return ElementType.NumericType;
}
}
private static IDictionary<System.Type, object> register = new Dictionary<System.Type, object>();
@ -643,7 +736,9 @@ public static class TraitFunctions
private static System.Type AsEflInstantiableType(System.Type type)
{
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");
}
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,7 +88,9 @@ 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);
}