Fix vc_elm api for setting voice touch
[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 int __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         return 0;
91 }
92
93 static void __efl_app_finish(void)
94 {
95         vconf_ignore_key_changed(VCONFKEY_VC_VOICE_TOUCH_AUTOMODE,
96                         __vc_vtauto_changed_cb);
97         if (vc_elm_initialized) {
98                 vc_elm_deinitialize();
99                 vc_elm_initialized = false;
100         }
101
102         elm_shutdown();
103
104         /* Check loader case */
105         if (getenv("AUL_LOADER_INIT")) {
106                 unsetenv("AUL_LOADER_INIT");
107                 elm_shutdown();
108         }
109 }
110
111 static void __efl_app_run(void *data)
112 {
113         elm_run();
114 }
115
116 static void __efl_app_exit(void *data)
117 {
118         elm_exit();
119 }
120
121 EXPORT_API int appcore_efl_base_init(appcore_efl_base_ops ops, int argc,
122                 char **argv, void *data, unsigned int hint)
123 {
124         return appcore_ui_base_init(ops.ui_base, argc, argv, data, hint);
125 }
126
127 EXPORT_API void appcore_efl_base_fini(void)
128 {
129         appcore_ui_base_fini();
130 }
131
132 EXPORT_API appcore_efl_base_ops appcore_efl_base_get_default_ops(void)
133 {
134         appcore_efl_base_ops ops;
135
136         ops.ui_base = appcore_ui_base_get_default_ops();
137
138         /* override methods */
139         ops.ui_base.base.init = __efl_app_init;
140         ops.ui_base.base.finish = __efl_app_finish;
141         ops.ui_base.base.run = __efl_app_run;
142         ops.ui_base.base.exit = __efl_app_exit;
143
144         return ops;
145 }
146
147 EXPORT_API int appcore_efl_base_on_receive(aul_type type, bundle *b)
148 {
149         return appcore_ui_base_on_receive(type, b);
150 }
151
152 EXPORT_API int appcore_efl_base_on_create(void)
153 {
154         return appcore_ui_base_on_create();
155 }
156
157 EXPORT_API int appcore_efl_base_on_terminate(void)
158 {
159         return appcore_ui_base_on_terminate();
160 }
161
162 EXPORT_API int appcore_efl_base_on_pause(void)
163 {
164         return appcore_ui_base_on_pause();
165 }
166
167 EXPORT_API int appcore_efl_base_on_resume(void)
168 {
169         return appcore_ui_base_on_resume();
170 }
171
172 EXPORT_API int appcore_efl_base_on_control(bundle *b)
173 {
174         return appcore_ui_base_on_control(b);
175 }
176
177 EXPORT_API void appcore_efl_base_window_on_show(int type, void *event)
178 {
179         appcore_ui_base_window_on_show(type, event);
180 }
181
182 EXPORT_API void appcore_efl_base_window_on_hide(int type, void *event)
183 {
184         appcore_ui_base_window_on_hide(type, event);
185 }
186
187 EXPORT_API void appcore_efl_base_window_on_lower(int type, void *event)
188 {
189         appcore_ui_base_window_on_lower(type, event);
190 }
191
192 EXPORT_API void appcore_efl_base_window_on_visibility(int type, void *event)
193 {
194         appcore_ui_base_window_on_visibility(type, event);
195 }
196
197 EXPORT_API void appcore_efl_base_pause(void)
198 {
199         appcore_ui_base_pause();
200 }
201
202 EXPORT_API void appcore_efl_base_resume(void)
203 {
204         appcore_ui_base_resume();
205 }
206
207 EXPORT_API bool appcore_efl_base_is_resumed(void)
208 {
209         return appcore_ui_base_is_resumed();
210 }
211
212 EXPORT_API void appcore_efl_base_exit(void)
213 {
214         appcore_ui_base_exit();
215 }
216
217 EXPORT_API void appcore_efl_base_group_add(void)
218 {
219         appcore_ui_base_group_add();
220 }
221
222 EXPORT_API void appcore_efl_base_group_remove(void)
223 {
224         appcore_ui_base_group_remove();
225 }
226
227 EXPORT_API unsigned int appcore_efl_base_get_main_window(void)
228 {
229         return appcore_ui_base_get_main_window();
230 }
231
232 EXPORT_API unsigned int appcore_efl_base_get_main_surface(void)
233 {
234         return appcore_ui_base_get_main_surface();
235 }
236
237 EXPORT_API int appcore_efl_base_get_hint(void)
238 {
239         return appcore_ui_base_get_hint();
240 }
241
242 EXPORT_API bool appcore_efl_base_get_bg_state(void)
243 {
244         return appcore_ui_base_get_bg_state();
245 }
246
247 EXPORT_API void appcore_efl_base_set_bg_state(bool bg_state)
248 {
249         appcore_ui_base_set_bg_state(bg_state);
250 }