summaryrefslogtreecommitdiff
path: root/src/bindings
diff options
context:
space:
mode:
authorYeongjong Lee <yj34.lee@samsung.com>2019-12-09 13:45:56 -0300
committerLauro Moura <lauromoura@expertisesolutions.com.br>2019-12-09 13:56:19 -0300
commit06c2bbf798ca318efe23baec8e6454f8c5b177f4 (patch)
treef1bf886d17cd7e13d3f76908e06ec41d80b04f93 /src/bindings
parent5448c43bab7d054dde57dcc50e9d7239ff891729 (diff)
downloadefl-06c2bbf798ca318efe23baec8e6454f8c5b177f4.tar.gz
eolian_mono: reduce duplicated code in OnXXXEvent
Summary: `CallNativeEventCallback` is used to reduce duplicated code. E.g. Before ``` protected virtual void OnFullscreenChangedEvent(Efl.Ui.WinFullscreenChangedEventArgs e) { var key = "_EFL_UI_WIN_EVENT_FULLSCREEN_CHANGED"; IntPtr desc = Efl.EventDescription.GetNative(efl.Libs.Elementary, key); if (desc == IntPtr.Zero) { Eina.Log.Error($"Failed to get native event {key}"); return; } IntPtr info = Eina.PrimitiveConversion.ManagedToPointerAlloc(e.arg ? (byte) 1 : (byte) 0); try { Efl.Eo.Globals.efl_event_callback_call(this.NativeHandle, desc, info); } finally { Marshal.FreeHGlobal(info); } } ``` After ``` protected virtual void OnFullscreenChangedEvent(Efl.Ui.WinFullscreenChangedEventArgs e) { IntPtr info = Eina.PrimitiveConversion.ManagedToPointerAlloc(e.arg ? (byte) 1 : (byte) 0); CallNativeEventCallback("elementary", "_EFL_UI_WIN_EVENT_FULLSCREEN_CHANGED", info, (p) => Marshal.FreeHGlobal(p)); } ``` Test Plan: meson setup -Dbindings=mono,cxx -Dmono-beta=true Reviewers: lauromoura Reviewed By: lauromoura Subscribers: cedric, #reviewers, #committers Tags: #efl Differential Revision: https://phab.enlightenment.org/D10661
Diffstat (limited to 'src/bindings')
-rw-r--r--src/bindings/mono/eo_mono/EoWrapper.cs19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/bindings/mono/eo_mono/EoWrapper.cs b/src/bindings/mono/eo_mono/EoWrapper.cs
index 554f4ec9bd..7445df3956 100644
--- a/src/bindings/mono/eo_mono/EoWrapper.cs
+++ b/src/bindings/mono/eo_mono/EoWrapper.cs
@@ -325,6 +325,7 @@ public abstract class EoWrapper : IWrapper, IDisposable
}
}
}
+
internal Efl.EventCb GetInternalEventCallback<T>(EventHandler<T> handler, Func<IntPtr, T> createArgsInstance) where T:EventArgs
{
return (IntPtr data, ref Efl.Event.NativeStruct evt) =>
@@ -344,6 +345,7 @@ public abstract class EoWrapper : IWrapper, IDisposable
}
};
}
+
internal Efl.EventCb GetInternalEventCallback(EventHandler handler)
{
return (IntPtr data, ref Efl.Event.NativeStruct evt) =>
@@ -364,6 +366,23 @@ public abstract class EoWrapper : IWrapper, IDisposable
};
}
+ internal void CallNativeEventCallback(string lib, string key, IntPtr eventInfo, Action<IntPtr> freeAction)
+ {
+ try
+ {
+ IntPtr desc = Efl.EventDescription.GetNative(lib, key);
+ if (desc == IntPtr.Zero)
+ throw new ArgumentException($"Failed to get native event {key}", "key");
+
+ Efl.Eo.Globals.CallEventCallback(NativeHandle, desc, eventInfo);
+ }
+ finally
+ {
+ if (freeAction != null)
+ freeAction(eventInfo);
+ }
+ }
+
private static void OwnershipUniqueCallback(IntPtr data, ref Efl.Event.NativeStruct evt)
{
var ws = Efl.Eo.Globals.WrapperSupervisorPtrToManaged(data);