2 * Copyright (c) 2017 Samsung Electronics Co., Ltd. All rights reserved.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
24 #include <Elementary.h>
27 #include "appcore_efl_base_private.h"
28 #include "appcore_efl_base.h"
30 #define PATH_LIB_VC_ELM "/usr/lib/libvc-elm.so.0"
32 static bool __vc_elm_initialized;
33 static void *__vc_elm_handle;
34 static int (*__vc_elm_initialize)(void);
35 static int (*__vc_elm_deinitialize)(void);
36 static int (*__vc_elm_set_auto_register_mode)(int, int);
38 static void __unload_vc_elm(void)
43 __vc_elm_initialize = NULL;
44 __vc_elm_deinitialize = NULL;
45 __vc_elm_set_auto_register_mode = NULL;
47 dlclose(__vc_elm_handle);
48 __vc_elm_handle = NULL;
51 static int __load_vc_elm(void)
56 if (access(PATH_LIB_VC_ELM, F_OK) != 0) {
57 _ERR("Failed to access %s", PATH_LIB_VC_ELM);
61 __vc_elm_handle = dlopen(PATH_LIB_VC_ELM, RTLD_LAZY | RTLD_GLOBAL);
62 if (!__vc_elm_handle) {
63 _ERR("Failed to open %s", PATH_LIB_VC_ELM);
67 __vc_elm_initialize = dlsym(__vc_elm_handle, "vc_elm_initialize");
68 if (!__vc_elm_initialize) {
69 _ERR("Failed to load vc_elm_initialize");
74 __vc_elm_deinitialize = dlsym(__vc_elm_handle, "vc_elm_deinitialize");
75 if (!__vc_elm_deinitialize) {
76 _ERR("Failed to load vc_elm_deinitialize");
81 __vc_elm_set_auto_register_mode = dlsym(__vc_elm_handle,
82 "vc_elm_set_auto_register_mode");
83 if (!__vc_elm_set_auto_register_mode) {
84 _ERR("Failed to load vc_elm_set_auto_register_mode");
92 static void __vc_vtauto_changed_cb(keynode_t *key, void *data)
97 name = vconf_keynode_get_name(key);
98 if (!name || strcmp(name, VCONFKEY_VC_VOICE_TOUCH_AUTOMODE) != 0)
101 vt_automode = vconf_keynode_get_bool(key);
103 if (!__vc_elm_initialized) {
104 __vc_elm_initialize();
105 __vc_elm_initialized = true;
107 __vc_elm_set_auto_register_mode(2, 0);
109 __vc_elm_deinitialize();
110 __vc_elm_initialized = false;
114 static void __vc_elm_init(void)
123 vconf_notify_key_changed(VCONFKEY_VC_VOICE_TOUCH_AUTOMODE,
124 __vc_vtauto_changed_cb, NULL);
125 vconf_get_bool(VCONFKEY_VC_VOICE_TOUCH_AUTOMODE, &vt_automode);
127 if (!__vc_elm_initialized) {
128 __vc_elm_initialize();
129 __vc_elm_initialized = true;
131 __vc_elm_set_auto_register_mode(2, 0);
135 static void __vc_elm_finish(void)
137 vconf_ignore_key_changed(VCONFKEY_VC_VOICE_TOUCH_AUTOMODE,
138 __vc_vtauto_changed_cb);
139 if (__vc_elm_initialized) {
140 __vc_elm_deinitialize();
141 __vc_elm_initialized = false;
145 static gboolean __init_vc_elm(gpointer data)
147 /* VC voice touch setting */
150 return G_SOURCE_REMOVE;
153 static void __efl_app_init(int argc, char **argv, void *data)
158 elm_init(argc, argv);
160 hint = appcore_efl_base_get_hint();
161 if (hint & APPCORE_EFL_BASE_HINT_HW_ACC_CONTROL) {
162 hwacc = getenv("HWACC");
164 _DBG("elm_config_accel_preference_set is not called");
165 } else if (strcmp(hwacc, "USE") == 0) {
166 elm_config_accel_preference_set("hw");
167 _DBG("elm_config_accel_preference_set : hw");
168 } else if (strcmp(hwacc, "NOT_USE") == 0) {
169 elm_config_accel_preference_set("none");
170 _DBG("elm_config_accel_preference_set : none");
172 _DBG("elm_config_accel_preference_set is not called");
176 /* Postpone initialization to improve app launching performance */
177 g_idle_add(__init_vc_elm, NULL);
180 static void __efl_app_finish(void)
186 /* Check loader case */
187 if (getenv("AUL_LOADER_INIT")) {
188 unsetenv("AUL_LOADER_INIT");
193 static void __efl_app_run(void *data)
198 static void __efl_app_exit(void *data)
203 static void __efl_app_trim_memory(void *data)
206 elm_cache_all_flush();
207 appcore_base_on_trim_memory();
210 EXPORT_API int appcore_efl_base_init(appcore_efl_base_ops ops, int argc,
211 char **argv, void *data, unsigned int hint)
213 return appcore_ui_base_init(ops.ui_base, argc, argv, data, hint);
216 EXPORT_API void appcore_efl_base_fini(void)
218 appcore_ui_base_fini();
221 EXPORT_API appcore_efl_base_ops appcore_efl_base_get_default_ops(void)
223 appcore_efl_base_ops ops;
225 ops.ui_base = appcore_ui_base_get_default_ops();
227 /* override methods */
228 ops.ui_base.base.init = __efl_app_init;
229 ops.ui_base.base.finish = __efl_app_finish;
230 ops.ui_base.base.run = __efl_app_run;
231 ops.ui_base.base.exit = __efl_app_exit;
232 ops.ui_base.base.trim_memory = __efl_app_trim_memory;
237 EXPORT_API int appcore_efl_base_on_receive(aul_type type, bundle *b)
239 return appcore_ui_base_on_receive(type, b);
242 EXPORT_API int appcore_efl_base_on_create(void)
244 return appcore_ui_base_on_create();
247 EXPORT_API int appcore_efl_base_on_terminate(void)
249 return appcore_ui_base_on_terminate();
252 EXPORT_API int appcore_efl_base_on_pause(void)
254 return appcore_ui_base_on_pause();
257 EXPORT_API int appcore_efl_base_on_resume(void)
259 return appcore_ui_base_on_resume();
262 EXPORT_API int appcore_efl_base_on_control(bundle *b)
264 return appcore_ui_base_on_control(b);
267 EXPORT_API int appcore_efl_base_on_trim_memory(void)
269 return appcore_ui_base_on_trim_memory();
272 EXPORT_API void appcore_efl_base_window_on_show(int type, void *event)
274 appcore_ui_base_window_on_show(type, event);
277 EXPORT_API void appcore_efl_base_window_on_hide(int type, void *event)
279 appcore_ui_base_window_on_hide(type, event);
282 EXPORT_API void appcore_efl_base_window_on_lower(int type, void *event)
284 appcore_ui_base_window_on_lower(type, event);
287 EXPORT_API void appcore_efl_base_window_on_visibility(int type, void *event)
289 appcore_ui_base_window_on_visibility(type, event);
292 EXPORT_API void appcore_efl_base_window_on_pre_visibility(int type, void *event)
294 appcore_ui_base_window_on_pre_visibility(type, event);
297 EXPORT_API void appcore_efl_base_window_on_aux_message(int type, void *event)
299 appcore_ui_base_window_on_aux_message(type, event);
302 EXPORT_API void appcore_efl_base_pause(void)
304 appcore_ui_base_pause();
307 EXPORT_API void appcore_efl_base_resume(void)
309 appcore_ui_base_resume();
312 EXPORT_API bool appcore_efl_base_is_resumed(void)
314 return appcore_ui_base_is_resumed();
317 EXPORT_API void appcore_efl_base_exit(void)
319 appcore_ui_base_exit();
322 EXPORT_API void appcore_efl_base_group_add(void)
324 appcore_ui_base_group_add();
327 EXPORT_API void appcore_efl_base_group_remove(void)
329 appcore_ui_base_group_remove();
332 EXPORT_API unsigned int appcore_efl_base_get_main_window(void)
334 return appcore_ui_base_get_main_window();
337 EXPORT_API unsigned int appcore_efl_base_get_main_surface(void)
339 return appcore_ui_base_get_main_surface();
342 EXPORT_API int appcore_efl_base_get_hint(void)
344 return appcore_ui_base_get_hint();
347 EXPORT_API bool appcore_efl_base_get_bg_state(void)
349 return appcore_ui_base_get_bg_state();
352 EXPORT_API void appcore_efl_base_set_bg_state(bool bg_state)
354 appcore_ui_base_set_bg_state(bg_state);
357 EXPORT_API void appcore_efl_base_set_system_resource_reclaiming(bool enable)
359 appcore_ui_base_set_system_resource_reclaiming(enable);