summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLauro Moura <lauromoura@expertisesolutions.com.br>2019-03-22 12:56:44 -0300
committerLauro Moura <lauromoura@expertisesolutions.com.br>2019-03-25 10:16:02 -0300
commit905cd33b3f49fb37fe8da80ab1a395fc0b18c2de (patch)
tree9ce3e2805943f4561f2a33c52dcc647ebbce1909
parent6e92acd4e2538da0cb6e544e5ebbb2d551523ec3 (diff)
csharp: Hide Efl.Ui.Config and fix initialization
The manual call to elm_init is now hidden in a internal class. Also fixed an ocurrence of two calls to CommandLine.SetCommandArray by making Efl.Csharp.Application forward the command line parameters to elm_init.
-rw-r--r--src/bindings/mono/efl_mono/efl_all.cs49
-rw-r--r--src/bindings/mono/efl_mono/efl_csharp_application.cs31
-rw-r--r--src/bindings/mono/efl_mono/efl_csharp_ui.cs74
-rw-r--r--src/bindings/mono/efl_mono/meson.build1
4 files changed, 103 insertions, 52 deletions
diff --git a/src/bindings/mono/efl_mono/efl_all.cs b/src/bindings/mono/efl_mono/efl_all.cs
index bf78df1d3d..dcf5450c57 100644
--- a/src/bindings/mono/efl_mono/efl_all.cs
+++ b/src/bindings/mono/efl_mono/efl_all.cs
@@ -2,7 +2,6 @@
2 2
3using System; 3using System;
4using System.Runtime.InteropServices; 4using System.Runtime.InteropServices;
5using System.Threading;
6 5
7using static Efl.UnsafeNativeMethods; 6using static Efl.UnsafeNativeMethods;
8 7
@@ -11,8 +10,8 @@ namespace Efl {
11static class UnsafeNativeMethods { 10static class UnsafeNativeMethods {
12 11
13 private delegate void init_func_delegate(); 12 private delegate void init_func_delegate();
14 [DllImport(efl.Libs.Ecore)] public static extern void ecore_init(); 13 [DllImport(efl.Libs.Ecore)] internal static extern void ecore_init();
15 [DllImport(efl.Libs.Ecore)] public static extern void ecore_shutdown(); 14 [DllImport(efl.Libs.Ecore)] internal static extern void ecore_shutdown();
16 // dotnet loads libraries from DllImport with RTLD_LOCAL. Due to the 15 // dotnet loads libraries from DllImport with RTLD_LOCAL. Due to the
17 // way evas modules are built with meson, currently they do not link directly 16 // way evas modules are built with meson, currently they do not link directly
18 // with libevas, leading to symbol not found errors when trying to open them. 17 // with libevas, leading to symbol not found errors when trying to open them.
@@ -20,17 +19,11 @@ static class UnsafeNativeMethods {
20 // allowing the symbols to remain visible for the modules until the build 19 // allowing the symbols to remain visible for the modules until the build
21 // is sorted out. 20 // is sorted out.
22 private static Efl.Eo.FunctionWrapper<init_func_delegate> _evas_init; 21 private static Efl.Eo.FunctionWrapper<init_func_delegate> _evas_init;
23 [DllImport(efl.Libs.Evas)] public static extern void evas_shutdown(); 22 [DllImport(efl.Libs.Evas)] internal static extern void evas_shutdown();
24 [DllImport(efl.Libs.Elementary)] public static extern int elm_init(int argc, IntPtr argv);
25 [DllImport(efl.Libs.Elementary)] public static extern void elm_policy_set(int policy, int policy_detail);
26 [DllImport(efl.Libs.Elementary)] public static extern void elm_shutdown();
27 [DllImport(efl.Libs.Elementary)] public static extern void elm_run();
28 [DllImport(efl.Libs.Elementary)] public static extern void elm_exit();
29
30 static UnsafeNativeMethods() { 23 static UnsafeNativeMethods() {
31 _evas_init = new Efl.Eo.FunctionWrapper<init_func_delegate>("evas", "evas_init"); 24 _evas_init = new Efl.Eo.FunctionWrapper<init_func_delegate>("evas", "evas_init");
32 } 25 }
33 public static void evas_init() 26 internal static void evas_init()
34 { 27 {
35 _evas_init.Value.Delegate(); 28 _evas_init.Value.Delegate();
36 } 29 }
@@ -47,7 +40,7 @@ public static class All {
47 eldbus.Config.Init(); 40 eldbus.Config.Init();
48 41
49 if (components == Efl.Csharp.Components.Ui) { 42 if (components == Efl.Csharp.Components.Ui) {
50 Efl.Ui.Config.Init(); 43 Efl.Csharp.Ui.Config.Init();
51 InitializedUi = true; 44 InitializedUi = true;
52 } 45 }
53 } 46 }
@@ -59,7 +52,7 @@ public static class All {
59 System.GC.WaitForPendingFinalizers(); 52 System.GC.WaitForPendingFinalizers();
60 53
61 if (InitializedUi) 54 if (InitializedUi)
62 Efl.Ui.Config.Shutdown(); 55 Efl.Csharp.Ui.Config.Shutdown();
63 eldbus.Config.Shutdown(); 56 eldbus.Config.Shutdown();
64 evas_shutdown(); 57 evas_shutdown();
65 ecore_shutdown(); 58 ecore_shutdown();
@@ -68,34 +61,4 @@ public static class All {
68 } 61 }
69} 62}
70 63
71// Placeholder. Will move to elm_config.cs later
72namespace Ui {
73
74public static class Config {
75 public static void Init() {
76 // TODO Support elm command line arguments
77#if WIN32 // Not a native define, we define it in our build system
78 // Ecore_Win32 uses OleInitialize, which requires single thread apartments
79 if (System.Threading.Thread.CurrentThread.GetApartmentState() != ApartmentState.STA)
80 throw new InvalidOperationException("UI Applications require STAThreadAttribute in Main()");
81#endif
82 elm_init(0, IntPtr.Zero);
83
84 elm_policy_set((int)Elm.Policy.Quit, (int)Elm.PolicyQuit.LastWindowHidden);
85 }
86 public static void Shutdown() {
87 elm_shutdown();
88 }
89
90 public static void Run() {
91 elm_run();
92 }
93
94 public static void Exit() {
95 elm_exit();
96 }
97}
98
99}
100
101} 64}
diff --git a/src/bindings/mono/efl_mono/efl_csharp_application.cs b/src/bindings/mono/efl_mono/efl_csharp_application.cs
index 3bac96170d..e3ec832294 100644
--- a/src/bindings/mono/efl_mono/efl_csharp_application.cs
+++ b/src/bindings/mono/efl_mono/efl_csharp_application.cs
@@ -1,7 +1,9 @@
1using System; 1using System;
2using System.Runtime.InteropServices; 2using System.Runtime.InteropServices;
3using System.Threading; 3using System.Threading;
4
4using static Efl.UnsafeNativeMethods; 5using static Efl.UnsafeNativeMethods;
6using static Efl.Csharp.Ui.UnsafeNativeMethods;
5 7
6namespace Efl { 8namespace Efl {
7 namespace Csharp { 9 namespace Csharp {
@@ -33,24 +35,39 @@ namespace Efl {
33 //the initializied components 35 //the initializied components
34 private static Components initComponent; 36 private static Components initComponent;
35 //what follows are 3 private functions to boot up the internals of efl 37 //what follows are 3 private functions to boot up the internals of efl
36 private static void Init(Efl.Csharp.Components component) { 38 private static void Init(Efl.Csharp.Components component, string[] commandLineArguments) {
37 Eina.Config.Init(); 39 Eina.Config.Init();
38 Efl.Eo.Config.Init(); 40 Efl.Eo.Config.Init();
39 ecore_init(); 41 ecore_init();
40 evas_init(); 42 evas_init();
41 eldbus.Config.Init(); 43 eldbus.Config.Init();
42 44
43 if (component == Components.Ui) { 45 if (component == Components.Ui)
46 {
44 // TODO Support elm command line arguments 47 // TODO Support elm command line arguments
45#if WIN32 // Not a native define, we define it in our build system 48#if WIN32 // Not a native define, we define it in our build system
46 // Ecore_Win32 uses OleInitialize, which requires single thread apartments 49 // Ecore_Win32 uses OleInitialize, which requires single thread apartments
47 if (System.Threading.Thread.CurrentThread.GetApartmentState() != ApartmentState.STA) 50 if (System.Threading.Thread.CurrentThread.GetApartmentState() != ApartmentState.STA)
48 throw new InvalidOperationException("UI Applications require STAThreadAttribute in Main()"); 51 throw new InvalidOperationException("UI Applications require STAThreadAttribute in Main()");
49#endif 52#endif
50 elm_init(0, IntPtr.Zero); 53 if (commandLineArguments == null)
54 {
55 elm_init(0, IntPtr.Zero);
56 }
57 else
58 {
59 elm_init(commandLineArguments.Length, commandLineArguments);
60 }
51 61
52 elm_policy_set((int)Elm.Policy.Quit, (int)Elm.PolicyQuit.LastWindowHidden); 62 elm_policy_set((int)Elm.Policy.Quit, (int)Elm.PolicyQuit.LastWindowHidden);
53 } 63 }
64 else
65 {
66 Eina.Array<String> commandLine = new Eina.Array<String>();
67 commandLine.Append(commandLineArguments);
68 Efl.App.AppMain.SetCommandArray(commandLine);
69 }
70
54 initComponent = component; 71 initComponent = component;
55 } 72 }
56 private static void Shutdown() { 73 private static void Shutdown() {
@@ -96,13 +113,9 @@ namespace Efl {
96 /// This call will result in a call to OnInitialize(), which you application should override. 113 /// This call will result in a call to OnInitialize(), which you application should override.
97 /// </summary> 114 /// </summary>
98 public void Launch(Efl.Csharp.Components components=Components.Ui) { 115 public void Launch(Efl.Csharp.Components components=Components.Ui) {
99 Init(components); 116 Init(components, Environment.GetCommandLineArgs());
117
100 Efl.App app = Efl.App.AppMain; 118 Efl.App app = Efl.App.AppMain;
101 Eina.Array<String> command_line = new Eina.Array<String>();
102 command_line.Append(Environment.GetCommandLineArgs());
103#if EFL_BETA
104 app.SetCommandArray(command_line);
105#endif
106 app.ArgumentsEvt += (object sender, LoopArgumentsEvt_Args evt) => { 119 app.ArgumentsEvt += (object sender, LoopArgumentsEvt_Args evt) => {
107 if (evt.arg.Initialization) { 120 if (evt.arg.Initialization) {
108 OnInitialize(evt.arg.Argv); 121 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
new file mode 100644
index 0000000000..18b9b2bcfb
--- /dev/null
+++ b/src/bindings/mono/efl_mono/efl_csharp_ui.cs
@@ -0,0 +1,74 @@
1using System;
2using System.Runtime.InteropServices;
3using System.Threading;
4
5using static Efl.Csharp.Ui.UnsafeNativeMethods;
6
7namespace Efl
8{
9
10namespace Csharp
11{
12
13namespace Ui
14{
15
16static class UnsafeNativeMethods
17{
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] 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_shutdown();
22 [DllImport(efl.Libs.Elementary)] internal static extern void elm_run();
23 [DllImport(efl.Libs.Elementary)] internal static extern void elm_exit();
24}
25
26/// <summary>Configuration of Elementary EFL UI Library.</summary>
27internal static class Config
28{
29
30 /// <summary>Initializes the library.
31 ///
32 /// Also sets the default policy to <see cref="Elm.PolicyQuit.LastWindowHidden" />.</summary>
33 internal static void Init(string[] commandLineArgs = null)
34 {
35#if WIN32 // Not a native define, we define it in our build system
36 // Ecore_Win32 uses OleInitialize, which requires single thread apartments
37 if (System.Threading.Thread.CurrentThread.GetApartmentState() != ApartmentState.STA)
38 {
39 throw new InvalidOperationException("UI Applications require STAThreadAttribute in Main()");
40 }
41
42#endif
43 if (commandLineArgs == null)
44 elm_init(0, IntPtr.Zero);
45 else
46 elm_init(commandLineArgs.Length, commandLineArgs);
47
48 elm_policy_set((int)Elm.Policy.Quit, (int)Elm.PolicyQuit.LastWindowHidden);
49 }
50
51 /// <summary>Shuts down the library.</summary>
52 internal static void Shutdown()
53 {
54 elm_shutdown();
55 }
56
57 /// <summary>Starts the Elementary main loop.</summary>
58 internal static void Run()
59 {
60 elm_run();
61 }
62
63 /// <summary>Signals the main loop to exit.</summary>
64 internal static void Exit()
65 {
66 elm_exit();
67 }
68}
69
70}
71
72}
73
74}
diff --git a/src/bindings/mono/efl_mono/meson.build b/src/bindings/mono/efl_mono/meson.build
index acfeb4bc3f..160a724d2c 100644
--- a/src/bindings/mono/efl_mono/meson.build
+++ b/src/bindings/mono/efl_mono/meson.build
@@ -1,5 +1,6 @@
1mono_files += files( 1mono_files += files(
2 'efl_all.cs', 2 'efl_all.cs',
3 'efl_csharp_ui.cs',
3 'efl_csharp_application.cs' 4 'efl_csharp_application.cs'
4 ) 5 )
5 6