summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/bin/eolian_mono/eolian/mono/marshall_annotation.hh6
-rw-r--r--src/bin/eolian_mono/eolian/mono/marshall_type_impl.hh7
-rw-r--r--src/bindings/mono/eina_mono/eina_value.cs85
-rw-r--r--src/lib/efl_mono/efl_custom_exports_mono.c3
-rw-r--r--src/tests/efl_mono/ValueEolian.cs11
-rw-r--r--src/tests/efl_mono/dummy_test_object.c5
-rw-r--r--src/tests/efl_mono/dummy_test_object.eo7
7 files changed, 124 insertions, 0 deletions
diff --git a/src/bin/eolian_mono/eolian/mono/marshall_annotation.hh b/src/bin/eolian_mono/eolian/mono/marshall_annotation.hh
index 632696d6a7..6d56b2493c 100644
--- a/src/bin/eolian_mono/eolian/mono/marshall_annotation.hh
+++ b/src/bin/eolian_mono/eolian/mono/marshall_annotation.hh
@@ -82,6 +82,9 @@ struct marshall_annotation_visitor_generate
82 {"strbuf", false, [&] { 82 {"strbuf", false, [&] {
83 return "[MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Efl.Eo.StrbufKeepOwnershipMarshaler))]"; 83 return "[MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Efl.Eo.StrbufKeepOwnershipMarshaler))]";
84 }}, 84 }},
85 {"Value_Type", false, [&] {
86 return "[MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Eina.ValueTypeMarshaler))]";
87 }},
85 }; 88 };
86 match const return_match_table[] = 89 match const return_match_table[] =
87 { 90 {
@@ -117,6 +120,9 @@ struct marshall_annotation_visitor_generate
117 {"strbuf", false, [&] { 120 {"strbuf", false, [&] {
118 return "[return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Efl.Eo.StrbufKeepOwnershipMarshaler))]"; 121 return "[return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Efl.Eo.StrbufKeepOwnershipMarshaler))]";
119 }}, 122 }},
123 {"Value_Type", false, [&] {
124 return "[return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Eina.ValueTypeMarshaler))]";
125 }},
120 }; 126 };
121 127
122 if(eina::optional<bool> b = call_annotation_match 128 if(eina::optional<bool> b = call_annotation_match
diff --git a/src/bin/eolian_mono/eolian/mono/marshall_type_impl.hh b/src/bin/eolian_mono/eolian/mono/marshall_type_impl.hh
index 8de109e88b..588e8c2465 100644
--- a/src/bin/eolian_mono/eolian/mono/marshall_type_impl.hh
+++ b/src/bin/eolian_mono/eolian/mono/marshall_type_impl.hh
@@ -161,6 +161,13 @@ struct marshall_type_visitor_generate
161 r.base_type = "void"; 161 r.base_type = "void";
162 return r; 162 return r;
163 }} 163 }}
164 , {"Value_Type", nullptr, [&]
165 {
166 regular_type_def r = regular;
167 r.namespaces.clear();
168 r.base_type = "Eina.ValueTypeBox";
169 return r;
170 }}
164 }; 171 };
165 172
166 if (regular.is_struct() && !blacklist::is_struct_blacklisted(regular) && !(bool)(regular.base_qualifier & qualifier_info::is_own)) 173 if (regular.is_struct() && !blacklist::is_struct_blacklisted(regular) && !(bool)(regular.base_qualifier & qualifier_info::is_own))
diff --git a/src/bindings/mono/eina_mono/eina_value.cs b/src/bindings/mono/eina_mono/eina_value.cs
index cedf5001c2..57a615772b 100644
--- a/src/bindings/mono/eina_mono/eina_value.cs
+++ b/src/bindings/mono/eina_mono/eina_value.cs
@@ -3,6 +3,7 @@
3#define CODE_ANALYSIS 3#define CODE_ANALYSIS
4 4
5using System; 5using System;
6using System.ComponentModel;
6using System.Linq; 7using System.Linq;
7using System.Runtime.InteropServices; 8using System.Runtime.InteropServices;
8using System.Collections.Generic; 9using System.Collections.Generic;
@@ -515,6 +516,8 @@ static internal class UnsafeNativeMethods
515 internal static extern IntPtr type_array(); 516 internal static extern IntPtr type_array();
516 [DllImport(efl.Libs.CustomExports)] 517 [DllImport(efl.Libs.CustomExports)]
517 internal static extern IntPtr type_list(); 518 internal static extern IntPtr type_list();
519 [DllImport(efl.Libs.CustomExports)]
520 internal static extern IntPtr type_hash();
518 521
519 // Optional 522 // Optional
520 [DllImport(efl.Libs.CustomExports)] 523 [DllImport(efl.Libs.CustomExports)]
@@ -716,6 +719,39 @@ static class ValueTypeMethods
716 } 719 }
717} 720}
718 721
722/// <summary>Boxing class for custom marshalling of ValueType enums.
723///
724/// <para>As custom marshalling of enums (and other value types) is not supported, use
725/// use this boxing class as an intermediate at the Marshalling API level (like in
726/// marshall_type_impl.hh in the generator). User-facing API still uses Eina.ValueType
727/// normally.</para>
728/// </summary>
729[EditorBrowsable(EditorBrowsableState.Never)]
730public class ValueTypeBox
731{
732 public ValueType _payload;
733
734 public ValueTypeBox(ValueType v)
735 {
736 _payload = v;
737 }
738
739 public static implicit operator ValueTypeBox(ValueType v)
740 {
741 return new ValueTypeBox(v);
742 }
743
744 public static implicit operator ValueType(ValueTypeBox box)
745 {
746 if (box == null)
747 {
748 return Eina.ValueType.Empty;
749 }
750
751 return box._payload;
752 }
753}
754
719static class ValueTypeBridge 755static class ValueTypeBridge
720{ 756{
721 private static Dictionary<ValueType, IntPtr> ManagedToNative = new Dictionary<ValueType, IntPtr>(); 757 private static Dictionary<ValueType, IntPtr> ManagedToNative = new Dictionary<ValueType, IntPtr>();
@@ -860,6 +896,9 @@ static class ValueTypeBridge
860 ManagedToNative.Add(ValueType.List, type_list()); 896 ManagedToNative.Add(ValueType.List, type_list());
861 NativeToManaged.Add(type_list(), ValueType.List); 897 NativeToManaged.Add(type_list(), ValueType.List);
862 898
899 ManagedToNative.Add(ValueType.Hash, type_hash());
900 NativeToManaged.Add(type_hash(), ValueType.Hash);
901
863 ManagedToNative.Add(ValueType.Optional, type_optional()); 902 ManagedToNative.Add(ValueType.Optional, type_optional());
864 NativeToManaged.Add(type_optional(), ValueType.Optional); 903 NativeToManaged.Add(type_optional(), ValueType.Optional);
865 904
@@ -2898,6 +2937,7 @@ public class Value : IDisposable, IComparable<Value>, IEquatable<Value>
2898 2937
2899/// <summary> Custom marshaler to convert value pointers to managed values and back, 2938/// <summary> Custom marshaler to convert value pointers to managed values and back,
2900/// without changing ownership.</summary> 2939/// without changing ownership.</summary>
2940[EditorBrowsable(EditorBrowsableState.Never)]
2901public class ValueMarshaler : ICustomMarshaler 2941public class ValueMarshaler : ICustomMarshaler
2902{ 2942{
2903 /// <summary>Creates a managed value from a C pointer, whitout taking ownership of it.</summary> 2943 /// <summary>Creates a managed value from a C pointer, whitout taking ownership of it.</summary>
@@ -3000,4 +3040,49 @@ public class ValueMarshalerOwn : ICustomMarshaler
3000 static private ValueMarshalerOwn marshaler; 3040 static private ValueMarshalerOwn marshaler;
3001} 3041}
3002 3042
3043/// <summary> Custom marshaler to convert value type pointers to managed boxed enum values
3044/// and back.</summary>
3045public class ValueTypeMarshaler : ICustomMarshaler
3046{
3047 /// <summary>Creates a boxed ValueType enum value from a C pointer.</summary>
3048 public object MarshalNativeToManaged(IntPtr pNativeData)
3049 {
3050 var r = ValueTypeBridge.GetManaged(pNativeData);
3051 return new ValueTypeBox(r);
3052 }
3053 public static Eina.ValueType vtype;
3054
3055 /// <summary>Retrieves the C pointer from a given boxed enum value type.</summary>
3056 public IntPtr MarshalManagedToNative(object managedObj)
3057 {
3058 ValueTypeBox v = (ValueTypeBox)managedObj;
3059 return ValueTypeBridge.GetNative(v);
3060 }
3061
3062 public void CleanUpNativeData(IntPtr pNativeData)
3063 {
3064 }
3065
3066 public void CleanUpManagedData(object managedObj)
3067 {
3068 }
3069
3070 public int GetNativeDataSize()
3071 {
3072 return -1;
3073 }
3074
3075 public static ICustomMarshaler GetInstance(string cookie)
3076 {
3077 if (marshaler == null)
3078 {
3079 marshaler = new ValueTypeMarshaler();
3080 }
3081
3082 return marshaler;
3083 }
3084
3085 static private ValueTypeMarshaler marshaler;
3086}
3087
3003} 3088}
diff --git a/src/lib/efl_mono/efl_custom_exports_mono.c b/src/lib/efl_mono/efl_custom_exports_mono.c
index aa2572f49d..590bb4e784 100644
--- a/src/lib/efl_mono/efl_custom_exports_mono.c
+++ b/src/lib/efl_mono/efl_custom_exports_mono.c
@@ -421,6 +421,9 @@ EAPI const Eina_Value_Type *type_array() {
421EAPI const Eina_Value_Type *type_list() { 421EAPI const Eina_Value_Type *type_list() {
422 return EINA_VALUE_TYPE_LIST; 422 return EINA_VALUE_TYPE_LIST;
423} 423}
424EAPI const Eina_Value_Type *type_hash() {
425 return EINA_VALUE_TYPE_HASH;
426}
424EAPI const Eina_Value_Type *type_error() { 427EAPI const Eina_Value_Type *type_error() {
425 return EINA_VALUE_TYPE_ERROR; 428 return EINA_VALUE_TYPE_ERROR;
426} 429}
diff --git a/src/tests/efl_mono/ValueEolian.cs b/src/tests/efl_mono/ValueEolian.cs
index ea178d4ac9..945228a6db 100644
--- a/src/tests/efl_mono/ValueEolian.cs
+++ b/src/tests/efl_mono/ValueEolian.cs
@@ -160,6 +160,17 @@ public static class TestEinaValueEolian {
160 Test.AssertEquals(expected, received); 160 Test.AssertEquals(expected, received);
161 Test.AssertEquals(Eina.ValueType.Int32, received.GetValueType()); 161 Test.AssertEquals(Eina.ValueType.Int32, received.GetValueType());
162 } 162 }
163
164 public static void TestEolianEinaValueTypeMarshalling()
165 {
166 var obj = new Dummy.TestObject();
167
168 var values = Enum.GetValues(typeof(Eina.ValueType));
169 foreach (Eina.ValueType type in values)
170 {
171 Test.AssertEquals(type, obj.MirrorValueType(type));
172 }
173 }
163} 174}
164#pragma warning restore 1591 175#pragma warning restore 1591
165} 176}
diff --git a/src/tests/efl_mono/dummy_test_object.c b/src/tests/efl_mono/dummy_test_object.c
index 6717b12476..8ba7536720 100644
--- a/src/tests/efl_mono/dummy_test_object.c
+++ b/src/tests/efl_mono/dummy_test_object.c
@@ -4685,6 +4685,11 @@ Efl_Object *_dummy_test_object_call_find_provider_for_iface(Eo *obj, EINA_UNUSED
4685 return efl_provider_find(obj, DUMMY_TEST_IFACE_INTERFACE); 4685 return efl_provider_find(obj, DUMMY_TEST_IFACE_INTERFACE);
4686} 4686}
4687 4687
4688const Eina_Value_Type *_dummy_test_object_mirror_value_type(EINA_UNUSED const Eo *obj, EINA_UNUSED Dummy_Test_Object_Data *pd, const Eina_Value_Type *type)
4689{
4690 return type;
4691}
4692
4688// Inherit 4693// Inherit
4689int _dummy_inherit_helper_receive_dummy_and_call_int_out(Dummy_Test_Object *x) 4694int _dummy_inherit_helper_receive_dummy_and_call_int_out(Dummy_Test_Object *x)
4690{ 4695{
diff --git a/src/tests/efl_mono/dummy_test_object.eo b/src/tests/efl_mono/dummy_test_object.eo
index 2273c23a20..4f26beba0a 100644
--- a/src/tests/efl_mono/dummy_test_object.eo
+++ b/src/tests/efl_mono/dummy_test_object.eo
@@ -1642,6 +1642,13 @@ class Dummy.Test_Object extends Efl.Object implements Dummy.Test_Iface {
1642 call_find_provider_for_iface { 1642 call_find_provider_for_iface {
1643 return: Efl.Object; 1643 return: Efl.Object;
1644 } 1644 }
1645
1646 mirror_value_type @beta @const {
1647 params {
1648 @in type: const(ptr(Eina.Value_Type));
1649 }
1650 return: const(ptr(Eina.Value_Type));
1651 }
1645 } 1652 }
1646 implements { 1653 implements {
1647 Efl.Object.constructor; 1654 Efl.Object.constructor;