summaryrefslogtreecommitdiff
path: root/src/bindings/mono/eo_mono
diff options
context:
space:
mode:
authorVitor Sousa <vitorsousa@expertisesolutions.com.br>2019-06-28 18:20:01 -0300
committerJaehyun-Cho <35288529+Jaehyun-Cho@users.noreply.github.com>2019-07-05 09:57:23 +0900
commit73df0d47ff914211ee0a0b5fe46a381f1cd30f10 (patch)
tree4c805aafe893038363f97bd1b18be7264536d08d /src/bindings/mono/eo_mono
parenta94c72f4dec91153d45b5e98bdb169b56fe0132b (diff)
csharp: encapsulate some internal code of EoWrapper
Summary: Encapsulate some parts of EoWrapper making them less accessible to lib users. This can avoid unnecessary and risky usage of code that is only intended for internal usage. `inherited` field was made private and renamed to `generated`. Now its value can only be obtained through the `IsGeneratedBindingClass` property. `handle` field was made private. `eventLock` was renamed to `eflBindingEventLock` `ConstructingHandle` property set was made private. Constructors that are used to create new EFL# managed objects by wrapping a preexisting eo handle now receive a specific struct wrapping the handle pointer. This can avoid faulty interactions with the Reflection engine used only for generated classes that implement this constructor. Test Plan: meson test Reviewers: lauromoura, felipealmeida, YOhoho Subscribers: cedric, #reviewers, #committers Tags: #efl Differential Revision: https://phab.enlightenment.org/D9212
Diffstat (limited to 'src/bindings/mono/eo_mono')
-rw-r--r--src/bindings/mono/eo_mono/EoWrapper.cs28
-rw-r--r--src/bindings/mono/eo_mono/iwrapper.cs20
2 files changed, 35 insertions, 13 deletions
diff --git a/src/bindings/mono/eo_mono/EoWrapper.cs b/src/bindings/mono/eo_mono/EoWrapper.cs
index 7e512ac..5b14b48 100644
--- a/src/bindings/mono/eo_mono/EoWrapper.cs
+++ b/src/bindings/mono/eo_mono/EoWrapper.cs
@@ -12,9 +12,9 @@ namespace Eo
12 12
13public abstract class EoWrapper : IWrapper, IDisposable 13public abstract class EoWrapper : IWrapper, IDisposable
14{ 14{
15 protected readonly object eventLock = new object(); 15 protected readonly object eflBindingEventLock = new object();
16 protected bool inherited = false; 16 private bool generated = true;
17 protected System.IntPtr handle = IntPtr.Zero; 17 private System.IntPtr handle = IntPtr.Zero;
18 18
19 private static Efl.EventCb ownershipUniqueDelegate = new Efl.EventCb(OwnershipUniqueCallback); 19 private static Efl.EventCb ownershipUniqueDelegate = new Efl.EventCb(OwnershipUniqueCallback);
20 private static Efl.EventCb ownershipSharedDelegate = new Efl.EventCb(OwnershipSharedCallback); 20 private static Efl.EventCb ownershipSharedDelegate = new Efl.EventCb(OwnershipSharedCallback);
@@ -32,7 +32,7 @@ public abstract class EoWrapper : IWrapper, IDisposable
32 /// <param name="ch">Tag struct storing the native handle of the object being constructed.</param> 32 /// <param name="ch">Tag struct storing the native handle of the object being constructed.</param>
33 protected EoWrapper(ConstructingHandle ch) 33 protected EoWrapper(ConstructingHandle ch)
34 { 34 {
35 inherited = true; 35 generated = false;
36 handle = Efl.Eo.Globals.efl_constructor(Efl.Eo.Globals.efl_super(ch.NativeHandle, Efl.Eo.Globals.efl_class_get(ch.NativeHandle))); 36 handle = Efl.Eo.Globals.efl_constructor(Efl.Eo.Globals.efl_super(ch.NativeHandle, Efl.Eo.Globals.efl_class_get(ch.NativeHandle)));
37 if (handle == IntPtr.Zero) 37 if (handle == IntPtr.Zero)
38 { 38 {
@@ -47,11 +47,12 @@ public abstract class EoWrapper : IWrapper, IDisposable
47 } 47 }
48 48
49 /// <summary>Initializes a new instance of the <see cref="Object"/> class. 49 /// <summary>Initializes a new instance of the <see cref="Object"/> class.
50 /// Internal usage: Constructs an instance from a native pointer. This is used when interacting with C code and should not be used directly.</summary> 50 /// Internal usage: Constructs an instance from a native pointer. This is used when interacting with C code and should not be used directly.
51 /// Do not implement this constructor.</summary>
51 /// <param name="raw">The native pointer to be wrapped.</param> 52 /// <param name="raw">The native pointer to be wrapped.</param>
52 protected EoWrapper(System.IntPtr raw) 53 protected EoWrapper(Efl.Eo.Globals.WrappingHandle wh)
53 { 54 {
54 handle = raw; 55 handle = wh.NativeHandle;
55 AddWrapperSupervisor(); 56 AddWrapperSupervisor();
56 } 57 }
57 58
@@ -67,9 +68,9 @@ public abstract class EoWrapper : IWrapper, IDisposable
67 [CallerFilePath] string file = null, 68 [CallerFilePath] string file = null,
68 [CallerLineNumber] int line = 0) 69 [CallerLineNumber] int line = 0)
69 { 70 {
70 inherited = ((object)this).GetType() != managedType; 71 generated = ((object)this).GetType() == managedType;
71 IntPtr actual_klass = baseKlass; 72 IntPtr actual_klass = baseKlass;
72 if (inherited) 73 if (!generated)
73 { 74 {
74 actual_klass = Efl.Eo.ClassRegister.GetInheritKlassOrRegister(baseKlass, ((object)this).GetType()); 75 actual_klass = Efl.Eo.ClassRegister.GetInheritKlassOrRegister(baseKlass, ((object)this).GetType());
75 } 76 }
@@ -82,7 +83,7 @@ public abstract class EoWrapper : IWrapper, IDisposable
82 parent_ptr = parent.NativeHandle; 83 parent_ptr = parent.NativeHandle;
83 } 84 }
84 85
85 if (!inherited) 86 if (generated)
86 { 87 {
87 handle = Efl.Eo.Globals._efl_add_internal_start(file, line, actual_klass, parent_ptr, 1, 0); 88 handle = Efl.Eo.Globals._efl_add_internal_start(file, line, actual_klass, parent_ptr, 1, 0);
88 } 89 }
@@ -123,6 +124,11 @@ public abstract class EoWrapper : IWrapper, IDisposable
123 get; 124 get;
124 } 125 }
125 126
127 protected bool IsGeneratedBindingClass
128 {
129 get { return generated; }
130 }
131
126 /// <summary>Releases the underlying native instance.</summary> 132 /// <summary>Releases the underlying native instance.</summary>
127 protected virtual void Dispose(bool disposing) 133 protected virtual void Dispose(bool disposing)
128 { 134 {
@@ -292,7 +298,7 @@ public abstract class EoWrapper : IWrapper, IDisposable
292 NativeHandle = h; 298 NativeHandle = h;
293 } 299 }
294 300
295 public IntPtr NativeHandle { get; set; } 301 public IntPtr NativeHandle { get; private set; }
296 } 302 }
297 303
298 public abstract class NativeMethods : Efl.Eo.NativeClass 304 public abstract class NativeMethods : Efl.Eo.NativeClass
diff --git a/src/bindings/mono/eo_mono/iwrapper.cs b/src/bindings/mono/eo_mono/iwrapper.cs
index caf28a7..7c2eeb4 100644
--- a/src/bindings/mono/eo_mono/iwrapper.cs
+++ b/src/bindings/mono/eo_mono/iwrapper.cs
@@ -624,14 +624,15 @@ public class Globals
624 try 624 try
625 { 625 {
626 var flags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic; 626 var flags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;
627 constructor = managedType.GetConstructor(flags, null, new Type[1] { typeof(System.IntPtr) }, null); 627 constructor = managedType.GetConstructor(flags, null, new Type[1] { typeof(WrappingHandle) }, null);
628 } 628 }
629 catch (InvalidOperationException) 629 catch (InvalidOperationException)
630 { 630 {
631 throw new InvalidOperationException($"Can't get constructor for type {managedType}"); 631 throw new InvalidOperationException($"Can't get constructor for type {managedType}");
632 } 632 }
633 633
634 var ret = (Efl.Eo.IWrapper) constructor.Invoke(new object[1] { handle }); 634 WrappingHandle wh = new WrappingHandle(handle);
635 var ret = (Efl.Eo.IWrapper) constructor.Invoke(new object[1] { wh });
635 636
636 if (ret == null) 637 if (ret == null)
637 { 638 {
@@ -715,6 +716,21 @@ public class Globals
715 Monitor.Exit(Efl.All.InitLock); 716 Monitor.Exit(Efl.All.InitLock);
716 } 717 }
717 718
719 /// <sumary>
720 /// Internal struct used by the binding to pass the native handle pointer
721 /// to the managed object wrapping constructor.
722 /// Internal usage only: do not use this class in inherited classes.
723 /// </sumary>
724 public struct WrappingHandle
725 {
726 public WrappingHandle(IntPtr h)
727 {
728 NativeHandle = h;
729 }
730
731 public IntPtr NativeHandle { get; private set; }
732 }
733
718} // Globals 734} // Globals
719 735
720public static class Config 736public static class Config