[Bluetooth][Non-ACR] Fix no data exception issue (#787)
[platform/core/csapi/tizenfx.git] / internals / src / EflSharp / EflSharp / efl_all.cs
1 #pragma warning disable 1591
2
3 using System;
4 using System.Runtime.InteropServices;
5 using System.Threading;
6
7 using static Efl.UnsafeNativeMethods;
8
9 namespace Efl {
10
11 static class UnsafeNativeMethods {
12
13     private delegate void init_func_delegate();
14     [DllImport(efl.Libs.Ecore)] public static extern void ecore_init();
15     [DllImport(efl.Libs.Ecore)] public static extern void ecore_shutdown();
16     // 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
18     // with libevas, leading to symbol not found errors when trying to open them.
19     // The call to FunctionWrapper makes sure evas is loaded with RTLD_GLOBAL,
20     // allowing the symbols to remain visible for the modules until the build
21     // is sorted out.
22     private static Efl.Eo.FunctionWrapper<init_func_delegate> _evas_init;
23     [DllImport(efl.Libs.Evas)] public 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() {
31         _evas_init = new Efl.Eo.FunctionWrapper<init_func_delegate>("evas", "evas_init");
32     }
33     public static void evas_init()
34     {
35         _evas_init.Value.Delegate();
36     }
37 }
38
39 public enum Components {
40     Basic,
41     Ui
42 }
43
44 public static class All {
45     private static bool InitializedUi = false;
46
47     public static void Init(Efl.Components components=Components.Basic) {
48         Eina.Config.Init();
49         Efl.Eo.Config.Init();
50         ecore_init();
51         evas_init();
52         eldbus.Config.Init();
53
54         if (components == Components.Ui) {
55             Efl.Ui.Config.Init();
56             InitializedUi = true;
57         }
58     }
59
60     /// <summary>Shutdowns all EFL subsystems.</summary>
61     public static void Shutdown() {
62         // Try to cleanup everything before actually shutting down.
63         System.GC.Collect();
64         System.GC.WaitForPendingFinalizers();
65
66         if (InitializedUi)
67             Efl.Ui.Config.Shutdown();
68         eldbus.Config.Shutdown();
69         evas_shutdown();
70         ecore_shutdown();
71         Efl.Eo.Config.Shutdown();
72         Eina.Config.Shutdown();
73     }
74 }
75
76 // Placeholder. Will move to elm_config.cs later
77 namespace Ui {
78
79 public static class Config {
80     public static void Init() {
81         // TODO Support elm command line arguments
82 #if WIN32 // Not a native define, we define it in our build system
83         // Ecore_Win32 uses OleInitialize, which requires single thread apartments
84         if (System.Threading.Thread.CurrentThread.GetApartmentState() != ApartmentState.STA)
85             throw new InvalidOperationException("UI Applications require STAThreadAttribute in Main()");
86 #endif
87         elm_init(0, IntPtr.Zero);
88
89         elm_policy_set((int)Elm.Policy.Quit, (int)Elm.PolicyQuit.LastWindowHidden);
90     }
91     public static void Shutdown() {
92         elm_shutdown();
93     }
94
95     public static void Run() {
96         elm_run();
97     }
98
99     public static void Exit() {
100         elm_exit();
101     }
102 }
103
104 }
105
106 }