Change the return type
[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 #include <vconf.h>
24 #include <voice_control_elm.h>
25 #include <voice_control_elm_private.h>
26
27 #include "appcore_efl_base_private.h"
28 #include "appcore_efl_base.h"
29
30 static bool vc_elm_initialized;
31
32 static void __vc_vtauto_changed_cb(keynode_t *key, void *data)
33 {
34         const char *name;
35         int vt_automode;
36
37         name = vconf_keynode_get_name(key);
38         if (!name || strcmp(name, VCONFKEY_VC_VOICE_TOUCH_AUTOMODE) != 0)
39                 return;
40
41         vt_automode = vconf_keynode_get_bool(key);
42         if (vt_automode) {
43                 if (!vc_elm_initialized) {
44                         vc_elm_initialize();
45                         vc_elm_initialized = true;
46                 }
47                 vc_elm_set_auto_register_mode(2, 0);
48         } else {
49                 vc_elm_deinitialize();
50                 vc_elm_initialized = false;
51         }
52 }
53
54 static void __efl_app_init(int argc, char **argv, void *data)
55 {
56         int hint;
57         const char *hwacc;
58         int vt_automode = 0;
59
60         elm_init(argc, argv);
61
62         hint = appcore_efl_base_get_hint();
63         if (hint & APPCORE_EFL_BASE_HINT_HW_ACC_CONTROL) {
64                 hwacc = getenv("HWACC");
65                 if (hwacc == NULL) {
66                         _DBG("elm_config_accel_preference_set is not called");
67                 } else if (strcmp(hwacc, "USE") == 0) {
68                         elm_config_accel_preference_set("hw");
69                         _DBG("elm_config_accel_preference_set : hw");
70                 } else if (strcmp(hwacc, "NOT_USE") == 0) {
71                         elm_config_accel_preference_set("none");
72                         _DBG("elm_config_accel_preference_set : none");
73                 } else {
74                         _DBG("elm_config_accel_preference_set is not called");
75                 }
76         }
77
78         /* VC voice touch setting */
79         vconf_notify_key_changed(VCONFKEY_VC_VOICE_TOUCH_AUTOMODE,
80                         __vc_vtauto_changed_cb, NULL);
81         vconf_get_bool(VCONFKEY_VC_VOICE_TOUCH_AUTOMODE, &vt_automode);
82         if (vt_automode) {
83                 if (!vc_elm_initialized) {
84                         vc_elm_initialize();
85                         vc_elm_initialized = true;
86                 }
87                 vc_elm_set_auto_register_mode(2, 0);
88         }
89 }
90
91 static void __efl_app_finish(void)
92 {
93         vconf_ignore_key_changed(VCONFKEY_VC_VOICE_TOUCH_AUTOMODE,
94                         __vc_vtauto_changed_cb);
95         if (vc_elm_initialized) {
96                 vc_elm_deinitialize();
97                 vc_elm_initialized = false;
98         }
99
100         elm_shutdown();
101
102         /* Check loader case */
103         if (getenv("AUL_LOADER_INIT")) {
104                 unsetenv("AUL_LOADER_INIT");
105                 elm_shutdown();
106         }
107 }
108
109 static void __efl_app_run(void *data)
110 {
111         elm_run();
112 }
113
114 static void __efl_app_exit(void *data)
115 {
116         elm_exit();
117 }
118
119 EXPORT_API int appcore_efl_base_init(appcore_efl_base_ops ops, int argc,
120                 char **argv, void *data, unsigned int hint)
121 {
122         return appcore_ui_base_init(ops.ui_base, argc, argv, data, hint);
123 }
124
125 EXPORT_API void appcore_efl_base_fini(void)
126 {
127         appcore_ui_base_fini();
128 }
129
130 EXPORT_API appcore_efl_base_ops appcore_efl_base_get_default_ops(void)
131 {
132         appcore_efl_base_ops ops;
133
134         ops.ui_base = appcore_ui_base_get_default_ops();
135
136         /* override methods */
137         ops.ui_base.base.init = __efl_app_init;
138         ops.ui_base.base.finish = __efl_app_finish;
139         ops.ui_base.base.run = __efl_app_run;
140         ops.ui_base.base.exit = __efl_app_exit;
141
142         return ops;
143 }
144
145 EXPORT_API int appcore_efl_base_on_receive(aul_type type, bundle *b)
146 {
147         return appcore_ui_base_on_receive(type, b);
148 }
149
150 EXPORT_API int appcore_efl_base_on_create(void)
151 {
152         return appcore_ui_base_on_create();
153 }
154
155 EXPORT_API int appcore_efl_base_on_terminate(void)
156 {
157         return appcore_ui_base_on_terminate();
158 }
159
160 EXPORT_API int appcore_efl_base_on_pause(void)
161 {
162         return appcore_ui_base_on_pause();
163 }
164
165 EXPORT_API int appcore_efl_base_on_resume(void)
166 {
167         return appcore_ui_base_on_resume();
168 }
169
170 EXPORT_API int appcore_efl_base_on_control(bundle *b)
171 {
172         return appcore_ui_base_on_control(b);
173 }
174
175 EXPORT_API void appcore_efl_base_window_on_show(int type, void *event)
176 {
177         appcore_ui_base_window_on_show(type, event);
178 }
179
180 EXPORT_API void appcore_efl_base_window_on_hide(int type, void *event)
181 {
182         appcore_ui_base_window_on_hide(type, event);
183 }
184
185 EXPORT_API void appcore_efl_base_window_on_lower(int type, void *event)
186 {
187         appcore_ui_base_window_on_lower(type, event);
188 }
189
190 EXPORT_API void appcore_efl_base_window_on_visibility(int type, void *event)
191 {
192         appcore_ui_base_window_on_visibility(type, event);
193 }
194
195 EXPORT_API void appcore_efl_base_pause(void)
196 {
197         appcore_ui_base_pause();
198 }
199
200 EXPORT_API void appcore_efl_base_resume(void)
201 {
202         appcore_ui_base_resume();
203 }
204
205 EXPORT_API bool appcore_efl_base_is_resumed(void)
206 {
207         return appcore_ui_base_is_resumed();
208 }
209
210 EXPORT_API void appcore_efl_base_exit(void)
211 {
212         appcore_ui_base_exit();
213 }
214
215 EXPORT_API void appcore_efl_base_group_add(void)
216 {
217         appcore_ui_base_group_add();
218 }
219
220 EXPORT_API void appcore_efl_base_group_remove(void)
221 {
222         appcore_ui_base_group_remove();
223 }
224
225 EXPORT_API unsigned int appcore_efl_base_get_main_window(void)
226 {
227         return appcore_ui_base_get_main_window();
228 }
229
230 EXPORT_API unsigned int appcore_efl_base_get_main_surface(void)
231 {
232         return appcore_ui_base_get_main_surface();
233 }
234
235 EXPORT_API int appcore_efl_base_get_hint(void)
236 {
237         return appcore_ui_base_get_hint();
238 }
239
240 EXPORT_API bool appcore_efl_base_get_bg_state(void)
241 {
242         return appcore_ui_base_get_bg_state();
243 }
244
245 EXPORT_API void appcore_efl_base_set_bg_state(bool bg_state)
246 {
247         appcore_ui_base_set_bg_state(bg_state);
248 }