summaryrefslogtreecommitdiff
path: root/src/bindings
diff options
context:
space:
mode:
authorLauro Moura <lauromoura@expertisesolutions.com.br>2019-07-30 11:05:26 -0300
committerVitor Sousa <vitorsousa@expertisesolutions.com.br>2019-07-30 11:47:07 -0300
commit29d24aa409371bd0252b34eb54b1adcb256ca2a1 (patch)
tree4c822a2c82f67e85980ced2ce1707729732fb1f2 /src/bindings
parent1530d0386cff30b20da85e06b2688ea203b17cc7 (diff)
csharp: Add marshal support for Eina.ValueType
Summary: It uses a custom marshaler and a helper boxing class to convert between the managed enum values and the native Eina_Value_Type pointers. To be used by future MVVM machinery. Reviewers: vitor.sousa, felipealmeida Reviewed By: vitor.sousa Subscribers: cedric, #reviewers, #committers Tags: #efl Differential Revision: https://phab.enlightenment.org/D9443
Diffstat (limited to 'src/bindings')
-rw-r--r--src/bindings/mono/eina_mono/eina_value.cs85
1 files changed, 85 insertions, 0 deletions
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}