aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLauro Moura <lauromoura@expertisesolutions.com.br>2019-03-22 18:12:29 -0300
committerLauro Moura <lauromoura@expertisesolutions.com.br>2019-03-25 10:17:44 -0300
commit9145a0f8363e5ca1def1627792fb6a30d0f77124 (patch)
tree980e2ddeee99de922f9e653b8c6a32d78916fbe1
parentcsharp: Hide Efl.Ui.Config and fix initialization (diff)
downloadefl-devs/lauromoura/csharp_application.tar.gz
WIP - Csharp.Application refactordevs/lauromoura/csharp_application
Our tests are still failing. Apps working by doing manual marshalling of strings to elm_init.
-rw-r--r--src/bindings/mono/efl_mono/efl_csharp_application.cs47
-rw-r--r--src/bindings/mono/efl_mono/efl_csharp_ui.cs1
-rw-r--r--src/tests/efl_mono/Main.cs12
3 files changed, 54 insertions, 6 deletions
diff --git a/src/bindings/mono/efl_mono/efl_csharp_application.cs b/src/bindings/mono/efl_mono/efl_csharp_application.cs
index e3ec832294..8d3014c106 100644
--- a/src/bindings/mono/efl_mono/efl_csharp_application.cs
+++ b/src/bindings/mono/efl_mono/efl_csharp_application.cs
@@ -1,6 +1,7 @@
using System;
using System.Runtime.InteropServices;
using System.Threading;
+using System.Collections.Generic;
using static Efl.UnsafeNativeMethods;
using static Efl.Csharp.Ui.UnsafeNativeMethods;
@@ -34,6 +35,9 @@ namespace Efl {
public abstract class Application {
//the initializied components
private static Components initComponent;
+ private static bool initialized;
+ private Efl.App app = null;
+ private static IntPtr[] argv = null; // Holding the Native strings
//what follows are 3 private functions to boot up the internals of efl
private static void Init(Efl.Csharp.Components component, string[] commandLineArguments) {
Eina.Config.Init();
@@ -56,7 +60,15 @@ namespace Efl {
}
else
{
- elm_init(commandLineArguments.Length, commandLineArguments);
+ // Elementary expects the argument strings to outlive the call to eina_init.
+ // As C# assumes native strings are valid only during the call, we have to manage then explicitly.
+ List<IntPtr> argList = new List<IntPtr>();
+ foreach (var arg in commandLineArguments)
+ {
+ argList.Add(Eina.StringConversion.ManagedStringToNativeUtf8Alloc(arg));
+ }
+ argv = argList.ToArray();
+ elm_init(commandLineArguments.Length, argv);
}
elm_policy_set((int)Elm.Policy.Quit, (int)Elm.PolicyQuit.LastWindowHidden);
@@ -69,8 +81,13 @@ namespace Efl {
}
initComponent = component;
+ initialized = true;
}
- private static void Shutdown() {
+
+ /// <summary>Finalizes the application by shutting down efl libraries.
+ ///
+ /// Usually called indirectly by the Launch method.</summary>
+ protected static void Shutdown() {
// Try to cleanup everything before actually shutting down.
System.GC.Collect();
System.GC.WaitForPendingFinalizers();
@@ -82,6 +99,17 @@ namespace Efl {
evas_shutdown();
ecore_shutdown();
Efl.Eo.Config.Shutdown();
+
+ if (argv != null)
+ {
+ foreach (var arg in argv)
+ {
+ Eina.MemoryNative.Free(arg);
+ }
+
+ argv = null;
+ }
+
Eina.Config.Shutdown();
}
/// <summary>
@@ -108,14 +136,25 @@ namespace Efl {
/// Called before starting the shutdown of the application.
/// </summary>
protected virtual void OnTerminate() { }
+
+ /// <summary>
+ /// </summary>
+ public void Setup(Efl.Csharp.Components components=Components.Ui) {
+ Eina.Log.Error($"Calling Init. With component {components}");
+ Init(components, Environment.GetCommandLineArgs());
+ }
+
/// <summary>
/// This function initializices everything in EFL and runs your application.
/// This call will result in a call to OnInitialize(), which you application should override.
/// </summary>
public void Launch(Efl.Csharp.Components components=Components.Ui) {
- Init(components, Environment.GetCommandLineArgs());
+ if (!initialized)
+ {
+ this.Setup(components);
+ }
- Efl.App app = Efl.App.AppMain;
+ app = Efl.App.AppMain;
app.ArgumentsEvt += (object sender, LoopArgumentsEvt_Args evt) => {
if (evt.arg.Initialization) {
OnInitialize(evt.arg.Argv);
diff --git a/src/bindings/mono/efl_mono/efl_csharp_ui.cs b/src/bindings/mono/efl_mono/efl_csharp_ui.cs
index 18b9b2bcfb..59e2e3bf69 100644
--- a/src/bindings/mono/efl_mono/efl_csharp_ui.cs
+++ b/src/bindings/mono/efl_mono/efl_csharp_ui.cs
@@ -16,6 +16,7 @@ namespace Ui
static class UnsafeNativeMethods
{
[DllImport(efl.Libs.Elementary)] internal static extern int elm_init(int argc, IntPtr argv);
+ [DllImport(efl.Libs.Elementary)] internal static extern int elm_init(int argc, [In] IntPtr[] argv);
[DllImport(efl.Libs.Elementary)] internal static extern int elm_init(int argc, [In] string[] argv);
[DllImport(efl.Libs.Elementary)] internal static extern void elm_policy_set(int policy, int policy_detail);
[DllImport(efl.Libs.Elementary)] internal static extern void elm_shutdown();
diff --git a/src/tests/efl_mono/Main.cs b/src/tests/efl_mono/Main.cs
index 3ae3584798..48ac566bdd 100644
--- a/src/tests/efl_mono/Main.cs
+++ b/src/tests/efl_mono/Main.cs
@@ -4,7 +4,7 @@ using System.Runtime.CompilerServices;
using System.Reflection;
using System.Linq;
-class TestMain
+class TestMain : Efl.Csharp.Application
{
static Type[] GetTestCases(String name="")
{
@@ -13,9 +13,15 @@ class TestMain
t.Name.Contains(name)).ToArray();
}
+ // Empty as we do not actually depend on it to run the tests.
+ protected override void OnInitialize(Eina.Array<System.String> args)
+ {
+ }
+
static int Main(string[] args)
{
- Efl.All.Init();
+ var app = new TestMain();
+ app.Setup();
bool pass = true;
@@ -92,6 +98,8 @@ class TestMain
}
Console.WriteLine("[ END SUITE ] " + ckRunSuite);
+ Efl.Csharp.Application.Shutdown();
+
if (!pass)
return -1;