Remove voice-control-elm dependency
[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 <dlfcn.h>
23 #include <Elementary.h>
24 #include <vconf.h>
25
26 #include "appcore_efl_base_private.h"
27 #include "appcore_efl_base.h"
28
29 #define PATH_LIB_VC_ELM "/usr/lib/libvc-elm.so.0"
30
31 static bool __vc_elm_initialized;
32 static void *__vc_elm_handle;
33 static int (*__vc_elm_initialize)(void);
34 static int (*__vc_elm_deinitialize)(void);
35 static int (*__vc_elm_set_auto_register_mode)(int, int);
36
37 static void __unload_vc_elm(void)
38 {
39         if (!__vc_elm_handle)
40                 return;
41
42         __vc_elm_initialize = NULL;
43         __vc_elm_deinitialize = NULL;
44         __vc_elm_set_auto_register_mode = NULL;
45
46         dlclose(__vc_elm_handle);
47         __vc_elm_handle = NULL;
48 }
49
50 static int __load_vc_elm(void)
51 {
52         if (__vc_elm_handle)
53                 return 0;
54
55         if (access(PATH_LIB_VC_ELM, F_OK) != 0) {
56                 _ERR("Failed to access %s", PATH_LIB_VC_ELM);
57                 return -1;
58         }
59
60         __vc_elm_handle = dlopen(PATH_LIB_VC_ELM, RTLD_LAZY | RTLD_GLOBAL);
61         if (!__vc_elm_handle) {
62                 _ERR("Failed to open %s", PATH_LIB_VC_ELM);
63                 return -1;
64         }
65
66         __vc_elm_initialize = dlsym(__vc_elm_handle, "vc_elm_initialize");
67         if (!__vc_elm_initialize) {
68                 _ERR("Failed to load vc_elm_initialize");
69                 __unload_vc_elm();
70                 return -1;
71         }
72
73         __vc_elm_deinitialize = dlsym(__vc_elm_handle, "vc_elm_deinitialize");
74         if (!__vc_elm_deinitialize) {
75                 _ERR("Failed to load vc_elm_deinitialize");
76                 __unload_vc_elm();
77                 return -1;
78         }
79
80         __vc_elm_set_auto_register_mode = dlsym(__vc_elm_handle,
81                         "vc_elm_set_auto_register_mode");
82         if (!__vc_elm_set_auto_register_mode) {
83                 _ERR("Failed to load vc_elm_set_auto_register_mode");
84                 __unload_vc_elm();
85                 return -1;
86         }
87
88         return 0;
89 }
90
91 static void __vc_vtauto_changed_cb(keynode_t *key, void *data)
92 {
93         const char *name;
94         int vt_automode;
95
96         name = vconf_keynode_get_name(key);
97         if (!name || strcmp(name, VCONFKEY_VC_VOICE_TOUCH_AUTOMODE) != 0)
98                 return;
99
100         vt_automode = vconf_keynode_get_bool(key);
101         if (vt_automode) {
102                 if (!__vc_elm_initialized) {
103                         __vc_elm_initialize();
104                         __vc_elm_initialized = true;
105                 }
106                 __vc_elm_set_auto_register_mode(2, 0);
107         } else {
108                 __vc_elm_deinitialize();
109                 __vc_elm_initialized = false;
110         }
111 }
112
113 static void __vc_elm_init(void)
114 {
115         int vt_automode = 0;
116         int r;
117
118         r = __load_vc_elm();
119         if (r < 0)
120                 return;
121
122         vconf_notify_key_changed(VCONFKEY_VC_VOICE_TOUCH_AUTOMODE,
123                         __vc_vtauto_changed_cb, NULL);
124         vconf_get_bool(VCONFKEY_VC_VOICE_TOUCH_AUTOMODE, &vt_automode);
125         if (vt_automode) {
126                 if (!__vc_elm_initialized) {
127                         __vc_elm_initialize();
128                         __vc_elm_initialized = true;
129                 }
130                 __vc_elm_set_auto_register_mode(2, 0);
131         }
132 }
133
134 static void __vc_elm_finish(void)
135 {
136         vconf_ignore_key_changed(VCONFKEY_VC_VOICE_TOUCH_AUTOMODE,
137                         __vc_vtauto_changed_cb);
138         if (__vc_elm_initialized) {
139                 __vc_elm_deinitialize();
140                 __vc_elm_initialized = false;
141         }
142
143         __unload_vc_elm();
144 }
145
146 static void __efl_app_init(int argc, char **argv, void *data)
147 {
148         int hint;
149         const char *hwacc;
150
151         elm_init(argc, argv);
152
153         hint = appcore_efl_base_get_hint();
154         if (hint & APPCORE_EFL_BASE_HINT_HW_ACC_CONTROL) {
155                 hwacc = getenv("HWACC");
156                 if (hwacc == NULL) {
157                         _DBG("elm_config_accel_preference_set is not called");
158                 } else if (strcmp(hwacc, "USE") == 0) {
159                         elm_config_accel_preference_set("hw");
160                         _DBG("elm_config_accel_preference_set : hw");
161                 } else if (strcmp(hwacc, "NOT_USE") == 0) {
162                         elm_config_accel_preference_set("none");
163                         _DBG("elm_config_accel_preference_set : none");
164                 } else {
165                         _DBG("elm_config_accel_preference_set is not called");
166                 }
167         }
168
169         /* VC voice touch setting */
170         __vc_elm_init();
171 }
172
173 static void __efl_app_finish(void)
174 {
175         __vc_elm_finish();
176
177         elm_shutdown();
178
179         /* Check loader case */
180         if (getenv("AUL_LOADER_INIT")) {
181                 unsetenv("AUL_LOADER_INIT");
182                 elm_shutdown();
183         }
184 }
185
186 static void __efl_app_run(void *data)
187 {
188         elm_run();
189 }
190
191 static void __efl_app_exit(void *data)
192 {
193         elm_exit();
194 }
195
196 EXPORT_API int appcore_efl_base_init(appcore_efl_base_ops ops, int argc,
197                 char **argv, void *data, unsigned int hint)
198 {
199         return appcore_ui_base_init(ops.ui_base, argc, argv, data, hint);
200 }
201
202 EXPORT_API void appcore_efl_base_fini(void)
203 {
204         appcore_ui_base_fini();
205 }
206
207 EXPORT_API appcore_efl_base_ops appcore_efl_base_get_default_ops(void)
208 {
209         appcore_efl_base_ops ops;
210
211         ops.ui_base = appcore_ui_base_get_default_ops();
212
213         /* override methods */
214         ops.ui_base.base.init = __efl_app_init;
215         ops.ui_base.base.finish = __efl_app_finish;
216         ops.ui_base.base.run = __efl_app_run;
217         ops.ui_base.base.exit = __efl_app_exit;
218
219         return ops;
220 }
221
222 EXPORT_API int appcore_efl_base_on_receive(aul_type type, bundle *b)
223 {
224         return appcore_ui_base_on_receive(type, b);
225 }
226
227 EXPORT_API int appcore_efl_base_on_create(void)
228 {
229         return appcore_ui_base_on_create();
230 }
231
232 EXPORT_API int appcore_efl_base_on_terminate(void)
233 {
234         return appcore_ui_base_on_terminate();
235 }
236
237 EXPORT_API int appcore_efl_base_on_pause(void)
238 {
239         return appcore_ui_base_on_pause();
240 }
241
242 EXPORT_API int appcore_efl_base_on_resume(void)
243 {
244         return appcore_ui_base_on_resume();
245 }
246
247 EXPORT_API int appcore_efl_base_on_control(bundle *b)
248 {
249         return appcore_ui_base_on_control(b);
250 }
251
252 EXPORT_API void appcore_efl_base_window_on_show(int type, void *event)
253 {
254         appcore_ui_base_window_on_show(type, event);
255 }
256
257 EXPORT_API void appcore_efl_base_window_on_hide(int type, void *event)
258 {
259         appcore_ui_base_window_on_hide(type, event);
260 }
261
262 EXPORT_API void appcore_efl_base_window_on_lower(int type, void *event)
263 {
264         appcore_ui_base_window_on_lower(type, event);
265 }
266
267 EXPORT_API void appcore_efl_base_window_on_visibility(int type, void *event)
268 {
269         appcore_ui_base_window_on_visibility(type, event);
270 }
271
272 EXPORT_API void appcore_efl_base_pause(void)
273 {
274         appcore_ui_base_pause();
275 }
276
277 EXPORT_API void appcore_efl_base_resume(void)
278 {
279         appcore_ui_base_resume();
280 }
281
282 EXPORT_API bool appcore_efl_base_is_resumed(void)
283 {
284         return appcore_ui_base_is_resumed();
285 }
286
287 EXPORT_API void appcore_efl_base_exit(void)
288 {
289         appcore_ui_base_exit();
290 }
291
292 EXPORT_API void appcore_efl_base_group_add(void)
293 {
294         appcore_ui_base_group_add();
295 }
296
297 EXPORT_API void appcore_efl_base_group_remove(void)
298 {
299         appcore_ui_base_group_remove();
300 }
301
302 EXPORT_API unsigned int appcore_efl_base_get_main_window(void)
303 {
304         return appcore_ui_base_get_main_window();
305 }
306
307 EXPORT_API unsigned int appcore_efl_base_get_main_surface(void)
308 {
309         return appcore_ui_base_get_main_surface();
310 }
311
312 EXPORT_API int appcore_efl_base_get_hint(void)
313 {
314         return appcore_ui_base_get_hint();
315 }
316
317 EXPORT_API bool appcore_efl_base_get_bg_state(void)
318 {
319         return appcore_ui_base_get_bg_state();
320 }
321
322 EXPORT_API void appcore_efl_base_set_bg_state(bool bg_state)
323 {
324         appcore_ui_base_set_bg_state(bg_state);
325 }