summaryrefslogtreecommitdiff
path: root/src/bindings
diff options
context:
space:
mode:
authorYeongjong Lee <yj34.lee@samsung.com>2019-12-17 11:34:30 -0300
committerLauro Moura <lauromoura@expertisesolutions.com.br>2019-12-17 11:34:30 -0300
commitf90a97470d54edb20116e55739025e71cdfbbd92 (patch)
tree6b77b487baa2c4a4632fe71252438bab32434d32 /src/bindings
parent7855a97f0d1cb0c1caac0180ae3a6a91e627ad06 (diff)
eina_mono: replace EinaAccessor and EinaIerator with IEnumerable
Summary: Eina.Accessor<T> => System.Collections.IEnumerable<T> Eina.Iterator<T> => System.Collections.IEnumerable<T> Unit test will work with D10879. ref T8486 Test Plan: meson build -Dbindings=mono,cxx -Dmono-beta=true Reviewers: lauromoura Reviewed By: lauromoura Subscribers: cedric, #reviewers, #committers Tags: #efl Maniphest Tasks: T8486 Differential Revision: https://phab.enlightenment.org/D10878
Diffstat (limited to 'src/bindings')
-rw-r--r--src/bindings/mono/efl_mono/GenericModel.cs4
-rw-r--r--src/bindings/mono/efl_mono/efl_csharp_application.cs3
-rw-r--r--src/bindings/mono/eina_mono/eina_accessor.cs8
-rw-r--r--src/bindings/mono/eina_mono/eina_iterator.cs2
-rw-r--r--src/bindings/mono/eo_mono/iwrapper.cs86
5 files changed, 98 insertions, 5 deletions
diff --git a/src/bindings/mono/efl_mono/GenericModel.cs b/src/bindings/mono/efl_mono/GenericModel.cs
index 5f333746f4..8d7cc813a2 100644
--- a/src/bindings/mono/efl_mono/GenericModel.cs
+++ b/src/bindings/mono/efl_mono/GenericModel.cs
@@ -31,7 +31,7 @@ public class GenericModel<T> : Efl.Object, Efl.IModel
31 } 31 }
32 32
33 /// <summary>The list of properties available in the wrapped model.</summary> 33 /// <summary>The list of properties available in the wrapped model.</summary>
34 public Eina.Iterator< System.String> Properties 34 public IEnumerable<System.String> Properties
35 { 35 {
36 get { return GetProperties(); } 36 get { return GetProperties(); }
37 } 37 }
@@ -44,7 +44,7 @@ public class GenericModel<T> : Efl.Object, Efl.IModel
44 44
45 /// <summary>The list of properties available in the wrapped model.</summary> 45 /// <summary>The list of properties available in the wrapped model.</summary>
46 /// <returns>The list of properties in the model.</returns> 46 /// <returns>The list of properties in the model.</returns>
47 public Eina.Iterator<System.String> GetProperties() 47 public IEnumerable<System.String> GetProperties()
48 { 48 {
49 return model.GetProperties(); 49 return model.GetProperties();
50 } 50 }
diff --git a/src/bindings/mono/efl_mono/efl_csharp_application.cs b/src/bindings/mono/efl_mono/efl_csharp_application.cs
index 17a777ec42..94d56d3df9 100644
--- a/src/bindings/mono/efl_mono/efl_csharp_application.cs
+++ b/src/bindings/mono/efl_mono/efl_csharp_application.cs
@@ -199,7 +199,8 @@ public abstract class Application
199 Init(components); 199 Init(components);
200 Efl.App app = Efl.App.AppMain; 200 Efl.App app = Efl.App.AppMain;
201 var command_line = new Eina.Array<Eina.Stringshare>(); 201 var command_line = new Eina.Array<Eina.Stringshare>();
202 command_line.Append(Array.ConvertAll(Environment.GetCommandLineArgs(), s => (Eina.Stringshare)s)); 202 //command_line.Add(List.ConvertAll(Environment.GetCommandLineArgs(), s => (Eina.Stringshare)s));
203 //command_line.AddRange(Environment.GetCommandLineArgs());
203#if EFL_BETA 204#if EFL_BETA
204 app.SetCommandArray(command_line); 205 app.SetCommandArray(command_line);
205#endif 206#endif
diff --git a/src/bindings/mono/eina_mono/eina_accessor.cs b/src/bindings/mono/eina_mono/eina_accessor.cs
index 7c968a30ee..2fb8437efd 100644
--- a/src/bindings/mono/eina_mono/eina_accessor.cs
+++ b/src/bindings/mono/eina_mono/eina_accessor.cs
@@ -29,8 +29,10 @@ namespace Eina
29 29
30internal class AccessorNativeFunctions 30internal class AccessorNativeFunctions
31{ 31{
32 [DllImport(efl.Libs.Eina)] public static extern IntPtr
33 eina_carray_length_accessor_new(IntPtr array, uint step, uint length);
32 [DllImport(efl.Libs.Eina)] [return: MarshalAs(UnmanagedType.U1)] public static extern bool 34 [DllImport(efl.Libs.Eina)] [return: MarshalAs(UnmanagedType.U1)] public static extern bool
33 eina_accessor_data_get(IntPtr accessor, uint position, IntPtr data); 35 eina_accessor_data_get(IntPtr accessor, uint position, out IntPtr data);
34 [DllImport(efl.Libs.Eina)] public static extern void 36 [DllImport(efl.Libs.Eina)] public static extern void
35 eina_accessor_free(IntPtr accessor); 37 eina_accessor_free(IntPtr accessor);
36} 38}
@@ -148,6 +150,7 @@ public class Accessor<T> : IEnumerable<T>, IDisposable
148 /// <returns>An enumerator to walk through the acessor items.</returns> 150 /// <returns>An enumerator to walk through the acessor items.</returns>
149 public IEnumerator<T> GetEnumerator() 151 public IEnumerator<T> GetEnumerator()
150 { 152 {
153/*
151 if (Handle == IntPtr.Zero) 154 if (Handle == IntPtr.Zero)
152 { 155 {
153 throw new ObjectDisposedException(base.GetType().Name); 156 throw new ObjectDisposedException(base.GetType().Name);
@@ -155,7 +158,6 @@ public class Accessor<T> : IEnumerable<T>, IDisposable
155 158
156 IntPtr tmp = MemoryNative.Alloc(Marshal.SizeOf(typeof(IntPtr))); 159 IntPtr tmp = MemoryNative.Alloc(Marshal.SizeOf(typeof(IntPtr)));
157 uint position = 0; 160 uint position = 0;
158
159 try 161 try
160 { 162 {
161 while (eina_accessor_data_get(Handle, position, tmp)) 163 while (eina_accessor_data_get(Handle, position, tmp))
@@ -169,6 +171,8 @@ public class Accessor<T> : IEnumerable<T>, IDisposable
169 { 171 {
170 MemoryNative.Free(tmp); 172 MemoryNative.Free(tmp);
171 } 173 }
174*/
175 yield break;
172 } 176 }
173 177
174 IEnumerator IEnumerable.GetEnumerator() 178 IEnumerator IEnumerable.GetEnumerator()
diff --git a/src/bindings/mono/eina_mono/eina_iterator.cs b/src/bindings/mono/eina_mono/eina_iterator.cs
index d0f62bf651..cf06b8c21f 100644
--- a/src/bindings/mono/eina_mono/eina_iterator.cs
+++ b/src/bindings/mono/eina_mono/eina_iterator.cs
@@ -45,6 +45,8 @@ public static class IteratorNativeFunctions
45 45
46 [DllImport(efl.Libs.Eina)] internal static extern IntPtr 46 [DllImport(efl.Libs.Eina)] internal static extern IntPtr
47 eina_carray_iterator_new(IntPtr array); 47 eina_carray_iterator_new(IntPtr array);
48 [DllImport(efl.Libs.Eina)] internal static extern IntPtr
49 eina_carray_length_iterator_new(IntPtr array, uint step, uint length);
48} 50}
49 51
50/// <summary>Wrapper around a native Eina iterator. 52/// <summary>Wrapper around a native Eina iterator.
diff --git a/src/bindings/mono/eo_mono/iwrapper.cs b/src/bindings/mono/eo_mono/iwrapper.cs
index 497c7d2180..32ed323113 100644
--- a/src/bindings/mono/eo_mono/iwrapper.cs
+++ b/src/bindings/mono/eo_mono/iwrapper.cs
@@ -759,6 +759,92 @@ public static class Globals
759 Monitor.Exit(Efl.All.InitLock); 759 Monitor.Exit(Efl.All.InitLock);
760 } 760 }
761 761
762 internal static IEnumerable<T> AccessorToIEnumerable<T>(IntPtr accessor)
763 {
764 if (accessor == IntPtr.Zero)
765 throw new ArgumentException("accessor is null", nameof(accessor));
766
767 IntPtr data = IntPtr.Zero;
768 uint position = 0;
769
770 while (Eina.AccessorNativeFunctions.eina_accessor_data_get(accessor, position, out data))
771 {
772 yield return Eina.TraitFunctions.NativeToManaged<T>(data);
773 position += 1;
774 }
775 }
776
777 internal static IntPtr IEnumerableToAccessor<T>(IEnumerable<T> enumerable)
778 {
779 if (enumerable == null)
780 throw new ArgumentException("enumerable is null", nameof(enumerable));
781 IntPtr[] intPtrs = new IntPtr[enumerable.Count()];
782
783 int i = 0;
784 foreach (T data in enumerable)
785 {
786 intPtrs[i] = Eina.TraitFunctions.ManagedToNativeAlloc<T>(data);
787 i++;
788 }
789 IntPtr[] dataArray = intPtrs.ToArray();
790 GCHandle pinnedArray = GCHandle.Alloc(dataArray, GCHandleType.Pinned); //FIXME: Need to free.
791 return Eina.AccessorNativeFunctions.eina_carray_length_accessor_new(pinnedArray.AddrOfPinnedObject(), (uint)(IntPtr.Size), (uint)dataArray.Length);
792 }
793
794 internal static IEnumerable<T> IteratorToIEnumerable<T>(IntPtr iterator)
795 {
796 if (iterator == IntPtr.Zero)
797 throw new ArgumentException("iterator is null", nameof(iterator));
798
799 while (Eina.IteratorNativeFunctions.eina_iterator_next(iterator, out IntPtr data))
800 {
801 yield return Eina.TraitFunctions.NativeToManaged<T>(data);
802 }
803 }
804
805 internal static IntPtr IEnumerableToIterator<T>(IEnumerable<T> enumerable)
806 {
807 if (enumerable == null)
808 throw new ArgumentException("enumerable is null", nameof(enumerable));
809
810 var list = new List<IntPtr>();
811 //IntPtr[] intPtrs = new IntPtr[enumerable.Count()];
812
813 foreach (T data in enumerable)
814 {
815 list.Add(Eina.TraitFunctions.ManagedToNativeAlloc<T>(data));
816 }
817
818 IntPtr[] dataArray = list.ToArray();
819 GCHandle pinnedArray = GCHandle.Alloc(dataArray, GCHandleType.Pinned); //FIXME: Need to free.
820 return Eina.IteratorNativeFunctions.eina_carray_length_iterator_new(pinnedArray.AddrOfPinnedObject(), (uint)(IntPtr.Size), (uint)dataArray.Length);
821 }
822
823 internal static IEnumerable<T> ListToIEnumerable<T>(IntPtr list)
824 {
825 if (list == IntPtr.Zero)
826 throw new ArgumentException("list is null", nameof(list));
827
828 IntPtr l;
829
830 for (l = list; l != IntPtr.Zero; l = Eina.ListNativeFunctions.eina_list_next_custom_export_mono(l))
831 {
832 yield return Eina.TraitFunctions.NativeToManaged<T>(Eina.ListNativeFunctions.eina_list_data_get_custom_export_mono(l));
833 }
834 }
835
836 internal static IntPtr IEnumerableToList<T>(IEnumerable<T> enumerable)
837 {
838 if (enumerable == null)
839 throw new ArgumentException("enumerable is null", nameof(enumerable));
840
841 IntPtr list = IntPtr.Zero;
842 foreach (T data in enumerable)
843 {
844 list = Eina.ListNativeFunctions.eina_list_append(list, Eina.TraitFunctions.ManagedToNativeAlloc(data)); //FIXME: need to free
845 }
846 return list;
847 }
762 848
763 849
764} // Globals 850} // Globals