1ac09fd6d09238ed910b02b127ea9abcbb26fa93
[platform/core/appfw/app-core.git] / src / efl_base / appcore_efl_base.c
1 /*
2  * Copyright (c) 2017 Samsung Electronics Co., Ltd. All rights reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #define _GNU_SOURCE
18 #include <stdio.h>
19 #include <string.h>
20 #include <stdlib.h>
21 #include <stdbool.h>
22 #include <Elementary.h>
23
24 #include "appcore_efl_base_private.h"
25 #include "appcore_efl_base.h"
26
27 static int __efl_app_init(int argc, char **argv, void *data)
28 {
29         int hint;
30         const char *hwacc;
31
32         elm_init(argc, argv);
33
34         hint = appcore_efl_base_get_hint();
35         if (hint & APPCORE_EFL_BASE_HINT_HW_ACC_CONTROL) {
36                 hwacc = getenv("HWACC");
37                 if (hwacc == NULL) {
38                         _DBG("elm_config_accel_preference_set is not called");
39                 } else if (strcmp(hwacc, "USE") == 0) {
40                         elm_config_accel_preference_set("hw");
41                         _DBG("elm_config_accel_preference_set : hw");
42                 } else if (strcmp(hwacc, "NOT_USE") == 0) {
43                         elm_config_accel_preference_set("none");
44                         _DBG("elm_config_accel_preference_set : none");
45                 } else {
46                         _DBG("elm_config_accel_preference_set is not called");
47                 }
48         }
49
50         return 0;
51 }
52
53 static void __efl_app_finish(void)
54 {
55         elm_shutdown();
56
57         /* Check loader case */
58         if (getenv("AUL_LOADER_INIT")) {
59                 unsetenv("AUL_LOADER_INIT");
60                 elm_shutdown();
61         }
62 }
63
64 static void __efl_app_run(void *data)
65 {
66         elm_run();
67 }
68
69 static void __efl_app_exit(void *data)
70 {
71         elm_exit();
72 }
73
74 EXPORT_API int appcore_efl_base_init(appcore_efl_base_ops ops, int argc,
75                 char **argv, void *data, unsigned int hint)
76 {
77         return appcore_ui_base_init(ops.ui_base, argc, argv, data, hint);
78 }
79
80 EXPORT_API void appcore_efl_base_fini(void)
81 {
82         appcore_ui_base_fini();
83 }
84
85 EXPORT_API appcore_efl_base_ops appcore_efl_base_get_default_ops(void)
86 {
87         appcore_efl_base_ops ops;
88
89         ops.ui_base = appcore_ui_base_get_default_ops();
90
91         /* override methods */
92         ops.ui_base.base.init = __efl_app_init;
93         ops.ui_base.base.finish = __efl_app_finish;
94         ops.ui_base.base.run = __efl_app_run;
95         ops.ui_base.base.exit = __efl_app_exit;
96
97         return ops;
98 }
99
100 EXPORT_API int appcore_efl_base_on_receive(aul_type type, bundle *b)
101 {
102         return appcore_ui_base_on_receive(type, b);
103 }
104
105 EXPORT_API int appcore_efl_base_on_create(void)
106 {
107         return appcore_ui_base_on_create();
108 }
109
110 EXPORT_API int appcore_efl_base_on_terminate(void)
111 {
112         return appcore_ui_base_on_terminate();
113 }
114
115 EXPORT_API int appcore_efl_base_on_pause(void)
116 {
117         return appcore_ui_base_on_pause();
118 }
119
120 EXPORT_API int appcore_efl_base_on_resume(void)
121 {
122         return appcore_ui_base_on_resume();
123 }
124
125 EXPORT_API int appcore_efl_base_on_control(bundle *b)
126 {
127         return appcore_ui_base_on_control(b);
128 }
129
130 EXPORT_API void appcore_efl_base_window_on_show(int type, void *event)
131 {
132         appcore_ui_base_window_on_show(type, event);
133 }
134
135 EXPORT_API void appcore_efl_base_window_on_hide(int type, void *event)
136 {
137         appcore_ui_base_window_on_hide(type, event);
138 }
139
140 EXPORT_API void appcore_efl_base_window_on_lower(int type, void *event)
141 {
142         appcore_ui_base_window_on_lower(type, event);
143 }
144
145 EXPORT_API void appcore_efl_base_window_on_visibility(int type, void *event)
146 {
147         appcore_ui_base_window_on_visibility(type, event);
148 }
149
150 EXPORT_API void appcore_efl_base_pause(void)
151 {
152         appcore_ui_base_pause();
153 }
154
155 EXPORT_API void appcore_efl_base_resume(void)
156 {
157         appcore_ui_base_resume();
158 }
159
160 EXPORT_API bool appcore_efl_base_is_resumed(void)
161 {
162         return appcore_ui_base_is_resumed();
163 }
164
165 EXPORT_API void appcore_efl_base_exit(void)
166 {
167         appcore_ui_base_exit();
168 }
169
170 EXPORT_API void appcore_efl_base_group_add(void)
171 {
172         appcore_ui_base_group_add();
173 }
174
175 EXPORT_API void appcore_efl_base_group_remove(void)
176 {
177         appcore_ui_base_group_remove();
178 }
179
180 EXPORT_API unsigned int appcore_efl_base_get_main_window(void)
181 {
182         return appcore_ui_base_get_main_window();
183 }
184
185 EXPORT_API unsigned int appcore_efl_base_get_main_surface(void)
186 {
187         return appcore_ui_base_get_main_surface();
188 }
189
190 EXPORT_API int appcore_efl_base_get_hint(void)
191 {
192         return appcore_ui_base_get_hint();
193 }
194
195 EXPORT_API bool appcore_efl_base_get_bg_state(void)
196 {
197         return appcore_ui_base_get_bg_state();
198 }
199
200 EXPORT_API void appcore_efl_base_set_bg_state(bool bg_state)
201 {
202         appcore_ui_base_set_bg_state(bg_state);
203 }