summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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 @@
1using System; 1using System;
2using System.Runtime.InteropServices; 2using System.Runtime.InteropServices;
3using System.Threading; 3using System.Threading;
4using System.Collections.Generic;
4 5
5using static Efl.UnsafeNativeMethods; 6using static Efl.UnsafeNativeMethods;
6using static Efl.Csharp.Ui.UnsafeNativeMethods; 7using static Efl.Csharp.Ui.UnsafeNativeMethods;
@@ -34,6 +35,9 @@ namespace Efl {
34 public abstract class Application { 35 public abstract class Application {
35 //the initializied components 36 //the initializied components
36 private static Components initComponent; 37 private static Components initComponent;
38 private static bool initialized;
39 private Efl.App app = null;
40 private static IntPtr[] argv = null; // Holding the Native strings
37 //what follows are 3 private functions to boot up the internals of efl 41 //what follows are 3 private functions to boot up the internals of efl
38 private static void Init(Efl.Csharp.Components component, string[] commandLineArguments) { 42 private static void Init(Efl.Csharp.Components component, string[] commandLineArguments) {
39 Eina.Config.Init(); 43 Eina.Config.Init();
@@ -56,7 +60,15 @@ namespace Efl {
56 } 60 }
57 else 61 else
58 { 62 {
59 elm_init(commandLineArguments.Length, commandLineArguments); 63 // Elementary expects the argument strings to outlive the call to eina_init.
64 // As C# assumes native strings are valid only during the call, we have to manage then explicitly.
65 List<IntPtr> argList = new List<IntPtr>();
66 foreach (var arg in commandLineArguments)
67 {
68 argList.Add(Eina.StringConversion.ManagedStringToNativeUtf8Alloc(arg));
69 }
70 argv = argList.ToArray();
71 elm_init(commandLineArguments.Length, argv);
60 } 72 }
61 73
62 elm_policy_set((int)Elm.Policy.Quit, (int)Elm.PolicyQuit.LastWindowHidden); 74 elm_policy_set((int)Elm.Policy.Quit, (int)Elm.PolicyQuit.LastWindowHidden);
@@ -69,8 +81,13 @@ namespace Efl {
69 } 81 }
70 82
71 initComponent = component; 83 initComponent = component;
84 initialized = true;
72 } 85 }
73 private static void Shutdown() { 86
87 /// <summary>Finalizes the application by shutting down efl libraries.
88 ///
89 /// Usually called indirectly by the Launch method.</summary>
90 protected static void Shutdown() {
74 // Try to cleanup everything before actually shutting down. 91 // Try to cleanup everything before actually shutting down.
75 System.GC.Collect(); 92 System.GC.Collect();
76 System.GC.WaitForPendingFinalizers(); 93 System.GC.WaitForPendingFinalizers();
@@ -82,6 +99,17 @@ namespace Efl {
82 evas_shutdown(); 99 evas_shutdown();
83 ecore_shutdown(); 100 ecore_shutdown();
84 Efl.Eo.Config.Shutdown(); 101 Efl.Eo.Config.Shutdown();
102
103 if (argv != null)
104 {
105 foreach (var arg in argv)
106 {
107 Eina.MemoryNative.Free(arg);
108 }
109
110 argv = null;
111 }
112
85 Eina.Config.Shutdown(); 113 Eina.Config.Shutdown();
86 } 114 }
87 /// <summary> 115 /// <summary>
@@ -108,14 +136,25 @@ namespace Efl {
108 /// Called before starting the shutdown of the application. 136 /// Called before starting the shutdown of the application.
109 /// </summary> 137 /// </summary>
110 protected virtual void OnTerminate() { } 138 protected virtual void OnTerminate() { }
139
140 /// <summary>
141 /// </summary>
142 public void Setup(Efl.Csharp.Components components=Components.Ui) {
143 Eina.Log.Error($"Calling Init. With component {components}");
144 Init(components, Environment.GetCommandLineArgs());
145 }
146
111 /// <summary> 147 /// <summary>
112 /// This function initializices everything in EFL and runs your application. 148 /// This function initializices everything in EFL and runs your application.
113 /// This call will result in a call to OnInitialize(), which you application should override. 149 /// This call will result in a call to OnInitialize(), which you application should override.
114 /// </summary> 150 /// </summary>
115 public void Launch(Efl.Csharp.Components components=Components.Ui) { 151 public void Launch(Efl.Csharp.Components components=Components.Ui) {
116 Init(components, Environment.GetCommandLineArgs()); 152 if (!initialized)
153 {
154 this.Setup(components);
155 }
117 156
118 Efl.App app = Efl.App.AppMain; 157 app = Efl.App.AppMain;
119 app.ArgumentsEvt += (object sender, LoopArgumentsEvt_Args evt) => { 158 app.ArgumentsEvt += (object sender, LoopArgumentsEvt_Args evt) => {
120 if (evt.arg.Initialization) { 159 if (evt.arg.Initialization) {
121 OnInitialize(evt.arg.Argv); 160 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
16static class UnsafeNativeMethods 16static class UnsafeNativeMethods
17{ 17{
18 [DllImport(efl.Libs.Elementary)] internal static extern int elm_init(int argc, IntPtr argv); 18 [DllImport(efl.Libs.Elementary)] internal static extern int elm_init(int argc, IntPtr argv);
19 [DllImport(efl.Libs.Elementary)] internal static extern int elm_init(int argc, [In] IntPtr[] argv);
19 [DllImport(efl.Libs.Elementary)] internal static extern int elm_init(int argc, [In] string[] argv); 20 [DllImport(efl.Libs.Elementary)] internal static extern int elm_init(int argc, [In] string[] argv);
20 [DllImport(efl.Libs.Elementary)] internal static extern void elm_policy_set(int policy, int policy_detail); 21 [DllImport(efl.Libs.Elementary)] internal static extern void elm_policy_set(int policy, int policy_detail);
21 [DllImport(efl.Libs.Elementary)] internal static extern void elm_shutdown(); 22 [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;
4using System.Reflection; 4using System.Reflection;
5using System.Linq; 5using System.Linq;
6 6
7class TestMain 7class TestMain : Efl.Csharp.Application
8{ 8{
9 static Type[] GetTestCases(String name="") 9 static Type[] GetTestCases(String name="")
10 { 10 {
@@ -13,9 +13,15 @@ class TestMain
13 t.Name.Contains(name)).ToArray(); 13 t.Name.Contains(name)).ToArray();
14 } 14 }
15 15
16 // Empty as we do not actually depend on it to run the tests.
17 protected override void OnInitialize(Eina.Array<System.String> args)
18 {
19 }
20
16 static int Main(string[] args) 21 static int Main(string[] args)
17 { 22 {
18 Efl.All.Init(); 23 var app = new TestMain();
24 app.Setup();
19 25
20 bool pass = true; 26 bool pass = true;
21 27
@@ -92,6 +98,8 @@ class TestMain
92 } 98 }
93 Console.WriteLine("[ END SUITE ] " + ckRunSuite); 99 Console.WriteLine("[ END SUITE ] " + ckRunSuite);
94 100
101 Efl.Csharp.Application.Shutdown();
102
95 if (!pass) 103 if (!pass)
96 return -1; 104 return -1;
97 105