summaryrefslogtreecommitdiff
path: root/src/efl_base/appcore_efl_base.c
blob: e2fd7c381f9f06bce145c143f5efd114bba864f6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
/*
 * Copyright (c) 2017 Samsung Electronics Co., Ltd. All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#define _GNU_SOURCE
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
#include <dlfcn.h>
#include <Elementary.h>
#include <vconf.h>

#include "appcore_efl_base_private.h"
#include "appcore_efl_base.h"

#define PATH_LIB_VC_ELM "/usr/lib/libvc-elm.so.0"

static bool __vc_elm_initialized;
static void *__vc_elm_handle;
static int (*__vc_elm_initialize)(void);
static int (*__vc_elm_deinitialize)(void);
static int (*__vc_elm_set_auto_register_mode)(int, int);

static void __unload_vc_elm(void)
{
	if (!__vc_elm_handle)
		return;

	__vc_elm_initialize = NULL;
	__vc_elm_deinitialize = NULL;
	__vc_elm_set_auto_register_mode = NULL;

	dlclose(__vc_elm_handle);
	__vc_elm_handle = NULL;
}

static int __load_vc_elm(void)
{
	if (__vc_elm_handle)
		return 0;

	if (access(PATH_LIB_VC_ELM, F_OK) != 0) {
		_ERR("Failed to access %s", PATH_LIB_VC_ELM);
		return -1;
	}

	__vc_elm_handle = dlopen(PATH_LIB_VC_ELM, RTLD_LAZY | RTLD_GLOBAL);
	if (!__vc_elm_handle) {
		_ERR("Failed to open %s", PATH_LIB_VC_ELM);
		return -1;
	}

	__vc_elm_initialize = dlsym(__vc_elm_handle, "vc_elm_initialize");
	if (!__vc_elm_initialize) {
		_ERR("Failed to load vc_elm_initialize");
		__unload_vc_elm();
		return -1;
	}

	__vc_elm_deinitialize = dlsym(__vc_elm_handle, "vc_elm_deinitialize");
	if (!__vc_elm_deinitialize) {
		_ERR("Failed to load vc_elm_deinitialize");
		__unload_vc_elm();
		return -1;
	}

	__vc_elm_set_auto_register_mode = dlsym(__vc_elm_handle,
			"vc_elm_set_auto_register_mode");
	if (!__vc_elm_set_auto_register_mode) {
		_ERR("Failed to load vc_elm_set_auto_register_mode");
		__unload_vc_elm();
		return -1;
	}

	return 0;
}

static void __vc_vtauto_changed_cb(keynode_t *key, void *data)
{
	const char *name;
	int vt_automode;

	name = vconf_keynode_get_name(key);
	if (!name || strcmp(name, VCONFKEY_VC_VOICE_TOUCH_AUTOMODE) != 0)
		return;

	vt_automode = vconf_keynode_get_bool(key);
	if (vt_automode) {
		if (!__vc_elm_initialized) {
			__vc_elm_initialize();
			__vc_elm_initialized = true;
		}
		__vc_elm_set_auto_register_mode(2, 0);
	} else {
		__vc_elm_deinitialize();
		__vc_elm_initialized = false;
	}
}

static void __vc_elm_init(void)
{
	int vt_automode = 0;
	int r;

	r = __load_vc_elm();
	if (r < 0)
		return;

	vconf_notify_key_changed(VCONFKEY_VC_VOICE_TOUCH_AUTOMODE,
			__vc_vtauto_changed_cb, NULL);
	vconf_get_bool(VCONFKEY_VC_VOICE_TOUCH_AUTOMODE, &vt_automode);
	if (vt_automode) {
		if (!__vc_elm_initialized) {
			__vc_elm_initialize();
			__vc_elm_initialized = true;
		}
		__vc_elm_set_auto_register_mode(2, 0);
	}
}

static void __vc_elm_finish(void)
{
	vconf_ignore_key_changed(VCONFKEY_VC_VOICE_TOUCH_AUTOMODE,
			__vc_vtauto_changed_cb);
	if (__vc_elm_initialized) {
		__vc_elm_deinitialize();
		__vc_elm_initialized = false;
	}
}

static void __efl_app_init(int argc, char **argv, void *data)
{
	int hint;
	const char *hwacc;

	elm_init(argc, argv);

	hint = appcore_efl_base_get_hint();
	if (hint & APPCORE_EFL_BASE_HINT_HW_ACC_CONTROL) {
		hwacc = getenv("HWACC");
		if (hwacc == NULL) {
			_DBG("elm_config_accel_preference_set is not called");
		} else if (strcmp(hwacc, "USE") == 0) {
			elm_config_accel_preference_set("hw");
			_DBG("elm_config_accel_preference_set : hw");
		} else if (strcmp(hwacc, "NOT_USE") == 0) {
			elm_config_accel_preference_set("none");
			_DBG("elm_config_accel_preference_set : none");
		} else {
			_DBG("elm_config_accel_preference_set is not called");
		}
	}

	/* VC voice touch setting */
	if (!getenv("VC_ELM_INIT"))
		__vc_elm_init();
}

static void __efl_app_finish(void)
{
	__vc_elm_finish();
	unsetenv("VC_ELM_INIT");

	elm_shutdown();

	/* Check loader case */
	if (getenv("AUL_LOADER_INIT")) {
		unsetenv("AUL_LOADER_INIT");
		elm_shutdown();
	}
}

static void __efl_app_run(void *data)
{
	elm_run();
}

static void __efl_app_exit(void *data)
{
	elm_exit();
}

EXPORT_API int appcore_efl_base_init(appcore_efl_base_ops ops, int argc,
		char **argv, void *data, unsigned int hint)
{
	return appcore_ui_base_init(ops.ui_base, argc, argv, data, hint);
}

EXPORT_API void appcore_efl_base_fini(void)
{
	appcore_ui_base_fini();
}

EXPORT_API appcore_efl_base_ops appcore_efl_base_get_default_ops(void)
{
	appcore_efl_base_ops ops;

	ops.ui_base = appcore_ui_base_get_default_ops();

	/* override methods */
	ops.ui_base.base.init = __efl_app_init;
	ops.ui_base.base.finish = __efl_app_finish;
	ops.ui_base.base.run = __efl_app_run;
	ops.ui_base.base.exit = __efl_app_exit;

	return ops;
}

EXPORT_API int appcore_efl_base_on_receive(aul_type type, bundle *b)
{
	return appcore_ui_base_on_receive(type, b);
}

EXPORT_API int appcore_efl_base_on_create(void)
{
	return appcore_ui_base_on_create();
}

EXPORT_API int appcore_efl_base_on_terminate(void)
{
	return appcore_ui_base_on_terminate();
}

EXPORT_API int appcore_efl_base_on_pause(void)
{
	return appcore_ui_base_on_pause();
}

EXPORT_API int appcore_efl_base_on_resume(void)
{
	return appcore_ui_base_on_resume();
}

EXPORT_API int appcore_efl_base_on_control(bundle *b)
{
	return appcore_ui_base_on_control(b);
}

EXPORT_API void appcore_efl_base_window_on_show(int type, void *event)
{
	appcore_ui_base_window_on_show(type, event);
}

EXPORT_API void appcore_efl_base_window_on_hide(int type, void *event)
{
	appcore_ui_base_window_on_hide(type, event);
}

EXPORT_API void appcore_efl_base_window_on_lower(int type, void *event)
{
	appcore_ui_base_window_on_lower(type, event);
}

EXPORT_API void appcore_efl_base_window_on_visibility(int type, void *event)
{
	appcore_ui_base_window_on_visibility(type, event);
}

EXPORT_API void appcore_efl_base_pause(void)
{
	appcore_ui_base_pause();
}

EXPORT_API void appcore_efl_base_resume(void)
{
	appcore_ui_base_resume();
}

EXPORT_API bool appcore_efl_base_is_resumed(void)
{
	return appcore_ui_base_is_resumed();
}

EXPORT_API void appcore_efl_base_exit(void)
{
	appcore_ui_base_exit();
}

EXPORT_API void appcore_efl_base_group_add(void)
{
	appcore_ui_base_group_add();
}

EXPORT_API void appcore_efl_base_group_remove(void)
{
	appcore_ui_base_group_remove();
}

EXPORT_API unsigned int appcore_efl_base_get_main_window(void)
{
	return appcore_ui_base_get_main_window();
}

EXPORT_API unsigned int appcore_efl_base_get_main_surface(void)
{
	return appcore_ui_base_get_main_surface();
}

EXPORT_API int appcore_efl_base_get_hint(void)
{
	return appcore_ui_base_get_hint();
}

EXPORT_API bool appcore_efl_base_get_bg_state(void)
{
	return appcore_ui_base_get_bg_state();
}

EXPORT_API void appcore_efl_base_set_bg_state(bool bg_state)
{
	appcore_ui_base_set_bg_state(bg_state);
}