Revert "Revert "Revert "Add codes for setting voice touch as auto mode"""
[platform/core/appfw/app-core.git] / src / ui_base / appcore_ui_base.c
1 /*
2  * Copyright (c) 2016 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 #include <sys/types.h>
18 #include <sys/socket.h>
19 #include <sys/un.h>
20 #include <stdio.h>
21 #include <unistd.h>
22 #include <stdarg.h>
23 #include <errno.h>
24 #include <string.h>
25 #include <stdlib.h>
26 #include <linux/limits.h>
27
28 #include <Ecore_Wayland.h>
29 #include <wayland-client.h>
30 #include <wayland-tbm-client.h>
31 #include <tizen-extension-client-protocol.h>
32
33 #include <Ecore.h>
34 #include <Ecore_Evas.h>
35 #include <Ecore_Input_Evas.h>
36 #include <Elementary.h>
37 #include <glib-object.h>
38 #include <malloc.h>
39 #include <glib.h>
40 #include <gio/gio.h>
41 #include <stdbool.h>
42 #include <aul.h>
43 #include <aul_svc.h>
44 #include <bundle_internal.h>
45 #include <ttrace.h>
46
47 #include "appcore_base.h"
48 #include "appcore_ui_base.h"
49 #include "appcore_ui_base_private.h"
50 #include "appcore_ui_plugin.h"
51
52 enum app_state {
53         AS_NONE,
54         AS_CREATED,
55         AS_RUNNING,
56         AS_PAUSED,
57         AS_DYING,
58 };
59
60 typedef struct _appcore_ui_base_context {
61         appcore_ui_base_ops ops;
62         void *data;
63         int argc;
64         char **argv;
65         unsigned int hint;
66         char *below_app;
67         char *appid;
68
69         int state;
70         Ecore_Event_Handler *hshow;
71         Ecore_Event_Handler *hhide;
72         Ecore_Event_Handler *hvchange;
73         Ecore_Event_Handler *hlower;
74 } appcore_ui_base_context;
75
76
77 static bool b_active = false;
78 static bool first_launch = true;
79
80 struct win_node {
81         unsigned int win;
82         unsigned int surf;
83         bool bfobscured;
84 };
85
86 static GSList *g_winnode_list;
87 static appcore_ui_base_context __context;
88 static struct wl_display *dsp;
89 static struct wl_registry *reg;
90 static struct tizen_policy *tz_policy;
91 static bool bg_state = false;
92
93 static void __wl_listener_cb(void *data, struct wl_registry *reg,
94                 uint32_t id, const char *interface, uint32_t ver)
95 {
96         if (interface && !strcmp(interface, "tizen_policy")) {
97                 if (!tz_policy)
98                         tz_policy = wl_registry_bind(reg, id,
99                                         &tizen_policy_interface, 1);
100         }
101 }
102
103 static void __wl_listener_remove_cb(void *data, struct wl_registry *reg,
104                 unsigned int id)
105 {
106         /* do nothing */
107 }
108
109 static const struct wl_registry_listener reg_listener = {
110         __wl_listener_cb,
111         __wl_listener_remove_cb
112 };
113
114 static Eina_Bool __stub_show_cb(void *data, int type, void *event)
115 {
116         if (__context.ops.window.show)
117                 __context.ops.window.show(type, event, __context.data);
118
119         return ECORE_CALLBACK_RENEW;
120 }
121
122 static Eina_Bool __stub_hide_cb(void *data, int type, void *event)
123 {
124         if (__context.ops.window.hide)
125                 __context.ops.window.hide(type, event, __context.data);
126
127         return ECORE_CALLBACK_RENEW;
128 }
129
130 static Eina_Bool __stub_visibility_cb(void *data, int type, void *event)
131 {
132         if (__context.ops.window.visibility)
133                 __context.ops.window.visibility(type, event, __context.data);
134
135         return ECORE_CALLBACK_RENEW;
136 }
137
138 static Eina_Bool __stub_lower_cb(void *data, int type, void *event)
139 {
140         if (__context.ops.window.lower)
141                 __context.ops.window.lower(type, event, __context.data);
142
143         return ECORE_CALLBACK_RENEW;
144 }
145
146 static void __prepare_to_suspend(void)
147 {
148         int suspend = APPCORE_BASE_SUSPENDED_STATE_WILL_ENTER_SUSPEND;
149
150         if (appcore_base_is_bg_allowed() && !appcore_base_is_suspended()) {
151                 appcore_base_raise_event((void *)&suspend, APPCORE_BASE_EVENT_SUSPENDED_STATE_CHANGE);
152                 appcore_base_toggle_suspended_state();
153         }
154 }
155
156 static void __exit_from_suspend(void)
157 {
158         int suspend = APPCORE_BASE_SUSPENDED_STATE_DID_EXIT_FROM_SUSPEND;
159
160         if (appcore_base_is_suspended()) {
161                 appcore_base_raise_event((void *)&suspend, APPCORE_BASE_EVENT_SUSPENDED_STATE_CHANGE);
162                 appcore_base_toggle_suspended_state();
163         }
164 }
165
166 static void __do_pause(void)
167 {
168         if (__context.state == AS_RUNNING) {
169                 if (__context.ops.pause)
170                         __context.ops.pause(__context.data);
171
172                 __context.state = AS_PAUSED;
173                 __prepare_to_suspend();
174         }
175         aul_status_update(STATUS_BG);
176 }
177
178 static void __do_resume(void)
179 {
180         if (__context.state == AS_PAUSED || __context.state == AS_CREATED) {
181                 __exit_from_suspend();
182                 if (__context.ops.resume) {
183                         LOG(LOG_DEBUG, "LAUNCH", "[%s:Application:resume:start]", __context.appid);
184                         __context.ops.resume(__context.data);
185                         LOG(LOG_DEBUG, "LAUNCH", "[%s:Application:resume:done]", __context.appid);
186                         LOG(LOG_DEBUG, "LAUNCH", "[%s:Application:Launching:done]", __context.appid);
187                 }
188                 if ((__context.hint & APPCORE_UI_BASE_HINT_WINDOW_STACK_CONTROL) &&
189                                 __context.below_app) {
190                         aul_app_group_activate_below(__context.below_app);
191                         free(__context.below_app);
192                         __context.below_app = NULL;
193                 }
194                 __context.state = AS_RUNNING;
195         }
196
197         aul_status_update(STATUS_VISIBLE);
198 }
199
200 static GSList *__find_win(unsigned int win)
201 {
202         GSList *iter;
203         struct win_node *t;
204
205         for (iter = g_winnode_list; iter; iter = g_slist_next(iter)) {
206                 t = iter->data;
207                 if (t && t->win == win)
208                         return iter;
209         }
210
211         return NULL;
212 }
213
214 static int __get_main_window(void)
215 {
216         struct win_node *entry = NULL;
217
218         if (g_winnode_list != NULL) {
219                 entry = g_winnode_list->data;
220                 return (unsigned int) entry->win;
221         }
222
223         return 0;
224 }
225
226 static int __get_main_surface(void)
227 {
228         struct win_node *entry = NULL;
229
230         if (g_winnode_list != NULL) {
231                 entry = g_winnode_list->data;
232                 return (unsigned int) entry->surf;
233         }
234
235         return 0;
236 }
237
238 static bool __add_win(unsigned int win, unsigned int surf)
239 {
240         struct win_node *t;
241         GSList *f;
242
243         _DBG("[EVENT_TEST][EVENT] __add_win WIN:%x\n", win);
244
245         f = __find_win(win);
246         if (f) {
247                 errno = ENOENT;
248                 _DBG("[EVENT_TEST][EVENT] ERROR There is already window : %x \n", win);
249                 return FALSE;
250         }
251
252         t = calloc(1, sizeof(struct win_node));
253         if (t == NULL)
254                 return FALSE;
255
256         t->win = win;
257         t->surf = surf;
258         t->bfobscured = FALSE;
259
260         g_winnode_list = g_slist_append(g_winnode_list, t);
261
262         return TRUE;
263 }
264
265 static bool __delete_win(unsigned int win)
266 {
267         GSList *f;
268
269         f = __find_win(win);
270         if (!f) {
271                 errno = ENOENT;
272                 _DBG("[EVENT_TEST][EVENT] ERROR There is no window : %x \n",
273                                 win);
274                 return FALSE;
275         }
276
277         free(f->data);
278         g_winnode_list = g_slist_delete_link(g_winnode_list, f);
279
280         return TRUE;
281 }
282
283 static bool __update_win(unsigned int win, unsigned int surf, bool bfobscured)
284 {
285         GSList *f;
286         struct win_node *t;
287
288         _DBG("[EVENT_TEST][EVENT] __update_win WIN:%x fully_obscured %d\n", win,
289              bfobscured);
290
291         f = __find_win(win);
292         if (!f) {
293                 errno = ENOENT;
294                 _DBG("[EVENT_TEST][EVENT] ERROR There is no window : %x \n", win);
295                 return FALSE;
296         }
297
298         t = (struct win_node *)f->data;
299         t->win = win;
300         if (surf != 0)
301                 t->surf = surf;
302         t->bfobscured = bfobscured;
303
304         return TRUE;
305 }
306
307 static void __raise_win(void)
308 {
309         Ecore_Wl_Window *win;
310         unsigned int win_id;
311
312         if (!(__context.hint & APPCORE_UI_BASE_HINT_WINDOW_STACK_CONTROL))
313                 return;
314
315         win_id = __get_main_window();
316
317         _DBG("Raise window: %d", win_id);
318         win = ecore_wl_window_find(win_id);
319         ecore_wl_window_activate(win);
320 }
321
322 static void __pause_win(void)
323 {
324         Ecore_Wl_Window *win;
325         GSList *wlist = g_winnode_list;
326         struct win_node *entry = NULL;
327
328         if (!(__context.hint & APPCORE_UI_BASE_HINT_WINDOW_STACK_CONTROL))
329                 return;
330
331         _DBG("Pause window");
332
333         while (wlist) {
334                 entry = wlist->data;
335
336                 _DBG("Pause window: %d", entry->win);
337                 win = ecore_wl_window_find(entry->win);
338                 ecore_wl_window_iconified_set(win, EINA_TRUE);
339
340                 wlist = wlist->next;
341         }
342 }
343
344 static int __init_wl(void)
345 {
346         _DBG("initialize wayland");
347         dsp = wl_display_connect(NULL);
348         if (dsp == NULL) {
349                 _ERR("Failed to connect wl display");
350                 return -1;
351         }
352
353         reg = wl_display_get_registry(dsp);
354         if (reg == NULL) {
355                 _ERR("Failed to get registry");
356                 wl_display_disconnect(dsp);
357                 return -1;
358         }
359
360         wl_registry_add_listener(reg, &reg_listener, NULL);
361         wl_display_roundtrip(dsp);
362
363         if (!tz_policy) {
364                 _ERR("Failed to get tizen policy interface");
365                 wl_registry_destroy(reg);
366                 wl_display_disconnect(dsp);
367                 return -1;
368         }
369
370         return 0;
371 }
372
373 static void __finish_wl(void)
374 {
375         if (tz_policy) {
376                 tizen_policy_destroy(tz_policy);
377                 tz_policy = NULL;
378         }
379
380         if (reg) {
381                 wl_registry_destroy(reg);
382                 reg = NULL;
383         }
384
385         if (dsp) {
386                 wl_display_disconnect(dsp);
387                 dsp = NULL;
388         }
389 }
390
391 static void __set_bg_state(void)
392 {
393         if (!tz_policy && __init_wl() < 0)
394                 return;
395
396         tizen_policy_set_background_state(tz_policy, getpid());
397         wl_display_roundtrip(dsp);
398         bg_state = true;
399         _DBG("bg state: %d", bg_state);
400 }
401
402 static void __unset_bg_state(void)
403 {
404         if (!tz_policy)
405                 return;
406
407         tizen_policy_unset_background_state(tz_policy, getpid());
408         wl_display_roundtrip(dsp);
409         bg_state = false;
410         _DBG("bg state: %d", bg_state);
411 }
412
413 static void __do_start(bundle *b)
414 {
415         const char *bg_launch;
416         const char *below_app;
417
418         if (__context.hint & APPCORE_UI_BASE_HINT_WINDOW_STACK_CONTROL) {
419                 if (__context.below_app) {
420                         free(__context.below_app);
421                         __context.below_app = NULL;
422                 }
423
424                 below_app = bundle_get_val(b, AUL_SVC_K_RELOCATE_BELOW);
425                 if (below_app)
426                         __context.below_app = strdup(below_app);
427         }
428
429         if (first_launch) {
430                 first_launch = FALSE;
431                 return;
432         }
433
434         if (__context.hint & APPCORE_UI_BASE_HINT_BG_LAUNCH_CONTROL) {
435                 bg_launch = bundle_get_val(b, AUL_SVC_K_BG_LAUNCH);
436                 if (bg_launch && strcmp(bg_launch, "enable") == 0) {
437                         if (!bg_state && __context.state != AS_RUNNING)
438                                 __set_bg_state();
439                 } else {
440                         if (bg_state)
441                                 __unset_bg_state();
442                 }
443         }
444
445         if (__context.hint & APPCORE_UI_BASE_HINT_WINDOW_AUTO_CONTROL) {
446                 if (!bg_state)
447                         __raise_win();
448         }
449 }
450
451 EXPORT_API int appcore_ui_base_on_receive(aul_type type, bundle *b)
452 {
453         if (__context.state == AS_DYING) {
454                 _ERR("Skip the event in dying state");
455                 return 0;
456         }
457
458         if (type == AUL_TERMINATE_BGAPP && __context.state != AS_PAUSED)
459                 return 0;
460
461         if (type == AUL_START)
462                 __exit_from_suspend();
463
464         appcore_base_on_receive(type, b);
465
466         switch (type) {
467         case AUL_START:
468                 __do_start(b);
469                 break;
470         case AUL_RESUME:
471                 if (bg_state)
472                         __unset_bg_state();
473                 __raise_win();
474                 break;
475         case AUL_TERMINATE:
476                 break;
477         case AUL_TERMINATE_BGAPP:
478                 _DBG("[APP %d] is paused. TERMINATE", getpid());
479                 __context.state = AS_DYING;
480                 aul_status_update(STATUS_DYING);
481                 if (__context.ops.base.exit)
482                         __context.ops.base.exit(__context.data);
483                 break;
484         case AUL_PAUSE:
485                 __pause_win();
486                 break;
487         default:
488                 break;
489         }
490
491         return 0;
492 }
493
494 EXPORT_API int appcore_ui_base_on_create(void)
495 {
496         appcore_base_on_create();
497
498         __context.hshow = ecore_event_handler_add(ECORE_WL_EVENT_WINDOW_SHOW, __stub_show_cb, NULL);
499         __context.hhide = ecore_event_handler_add(ECORE_WL_EVENT_WINDOW_HIDE, __stub_hide_cb, NULL);
500         __context.hvchange = ecore_event_handler_add(ECORE_WL_EVENT_WINDOW_VISIBILITY_CHANGE,
501                                 __stub_visibility_cb, NULL);
502         __context.hlower = ecore_event_handler_add(ECORE_WL_EVENT_WINDOW_LOWER, __stub_lower_cb, NULL);
503         __context.state = AS_CREATED;
504         LOG(LOG_DEBUG, "LAUNCH", "[%s:Application:create:done]", __context.appid);
505
506         return 0;
507 }
508
509 EXPORT_API int appcore_ui_base_on_terminate(void)
510 {
511         if (__context.state == AS_RUNNING) {
512                 if (__context.ops.pause)
513                         __context.ops.pause(__context.data);
514         }
515
516         __context.state = AS_DYING;
517
518         appcore_base_on_terminate();
519
520         return 0;
521 }
522
523 EXPORT_API int appcore_ui_base_on_pause(void)
524 {
525         return 0;
526 }
527
528 EXPORT_API int appcore_ui_base_on_resume(void)
529 {
530         return 0;
531 }
532
533 EXPORT_API int appcore_ui_base_on_control(bundle *b)
534 {
535         LOG(LOG_DEBUG, "LAUNCH", "[%s:Application:reset:start]", __context.appid);
536         appcore_base_on_control(b);
537         LOG(LOG_DEBUG, "LAUNCH", "[%s:Application:reset:done]", __context.appid);
538
539         return 0;
540 }
541
542 static void __group_attach()
543 {
544         if (!(__context.hint & APPCORE_UI_BASE_HINT_WINDOW_GROUP_CONTROL))
545                 return;
546
547         appcore_ui_base_group_add();
548 }
549
550 static void __group_lower()
551 {
552         if (!(__context.hint & APPCORE_UI_BASE_HINT_WINDOW_GROUP_CONTROL))
553                 return;
554         appcore_ui_base_group_remove();
555 }
556
557 EXPORT_API void appcore_ui_base_group_add()
558 {
559         static bool attached = false;
560
561         _DBG("__group_attach");
562         if (attached)
563                 return;
564
565         int wid = __get_main_surface();
566         if (wid == 0) {
567                 _ERR("window wasn't ready");
568                 return;
569         }
570
571         aul_app_group_set_window(wid);
572         attached = true;
573 }
574
575 EXPORT_API void appcore_ui_base_group_remove()
576 {
577         int exit = 0;
578
579         _DBG("__group_lower");
580         aul_app_group_lower(&exit);
581         if (exit) {
582                 _DBG("__group_lower : sub-app!");
583                 if (__context.ops.base.exit)
584                         __context.ops.base.exit(__context.data);
585         }
586 }
587
588 EXPORT_API void appcore_ui_base_window_on_show(int type, void *event)
589 {
590         Ecore_Wl_Event_Window_Show *ev;
591
592         ev = event;
593         if (ev->parent_win != 0) {
594                 /* This is child window. Skip!!! */
595                 return;
596         }
597
598         _DBG("[EVENT_TEST][EVENT] GET SHOW EVENT!!!. WIN:%x, %d\n", ev->win, ev->data[0]);
599
600         if (!__find_win((unsigned int)ev->win))
601                 __add_win((unsigned int)ev->win, (unsigned int)ev->data[0]);
602         else
603                 __update_win((unsigned int)ev->win, (unsigned int)ev->data[0], FALSE);
604
605         if (ev->data[0] != 0)
606                 __group_attach();
607 }
608
609 static bool __check_visible(void)
610 {
611         GSList *iter = NULL;
612         struct win_node *entry = NULL;
613
614         _DBG("[EVENT_TEST][EVENT] __check_visible\n");
615
616         for (iter = g_winnode_list; iter != NULL; iter = g_slist_next(iter)) {
617                 entry = iter->data;
618                 _DBG("win : %x obscured : %d\n", entry->win, entry->bfobscured);
619                 if (entry->bfobscured == FALSE)
620                         return true;
621         }
622
623         return false;
624 }
625
626 EXPORT_API void appcore_ui_base_window_on_hide(int type, void *event)
627 {
628         Ecore_Wl_Event_Window_Hide *ev;
629         int bvisibility;
630
631         ev = event;
632         _DBG("[EVENT_TEST][EVENT] GET HIDE EVENT!!!. WIN:%x\n", ev->win);
633
634         if (__find_win((unsigned int)ev->win)) {
635                 __delete_win((unsigned int)ev->win);
636                 bvisibility = __check_visible();
637                 if (!bvisibility && b_active == TRUE) {
638                         _DBG(" Go to Pasue state \n");
639                         b_active = FALSE;
640                         __do_pause();
641                 }
642         }
643 }
644
645 EXPORT_API void appcore_ui_base_window_on_lower(int type, void *event)
646 {
647         Ecore_Wl_Event_Window_Lower *ev;
648
649         ev = event;
650         if (!ev)
651                 return;
652         _DBG("ECORE_WL_EVENT_WINDOW_LOWER window id:%u\n", ev->win);
653         __group_lower();
654 }
655
656 EXPORT_API void appcore_ui_base_window_on_visibility(int type, void *event)
657 {
658         Ecore_Wl_Event_Window_Visibility_Change *ev;
659         int bvisibility;
660
661         ev = event;
662         __update_win((unsigned int)ev->win, 0, ev->fully_obscured);
663         bvisibility = __check_visible();
664
665         _DBG("bvisibility %d, b_active %d", bvisibility, b_active);
666
667         if (bvisibility && b_active == FALSE) {
668                 _DBG(" Go to Resume state\n");
669                 b_active = TRUE;
670                 __do_resume();
671         } else if (!bvisibility && b_active == TRUE) {
672                 _DBG(" Go to Pasue state \n");
673                 b_active = FALSE;
674                 __do_pause();
675         } else {
676                 _DBG(" No change state \n");
677         }
678
679 }
680
681 EXPORT_API int appcore_ui_base_init(appcore_ui_base_ops ops, int argc, char **argv,
682                 void *data, unsigned int hint)
683 {
684         char *hwacc;
685         const char *bg_launch;
686         bundle *b;
687         char appid[PATH_MAX] = {0, };
688
689         appcore_ui_plugin_init(&ops, &hint);
690         aul_app_get_appid_bypid(getpid(), appid, sizeof(appid));
691         __context.ops = ops;
692         __context.data = data;
693         __context.argc = argc;
694         __context.argv = argv;
695         __context.hint = hint;
696         __context.state = AS_NONE;
697         __context.appid = strdup(appid);
698
699         LOG(LOG_DEBUG, "LAUNCH", "[%s:Application:main:done]", appid);
700         elm_init(argc, argv);
701
702         if (__context.hint & APPCORE_UI_BASE_HINT_HW_ACC_CONTROL) {
703                 hwacc = getenv("HWACC");
704
705                 if (hwacc == NULL) {
706                         _DBG("elm_config_accel_preference_set is not called");
707                 } else if (strcmp(hwacc, "USE") == 0) {
708                         elm_config_accel_preference_set("hw");
709                         _DBG("elm_config_accel_preference_set : hw");
710                 } else if (strcmp(hwacc, "NOT_USE") == 0) {
711                         elm_config_accel_preference_set("none");
712                         _DBG("elm_config_accel_preference_set : none");
713                 } else {
714                         _DBG("elm_config_accel_preference_set is not called");
715                 }
716         }
717
718         if (__context.hint & APPCORE_UI_BASE_HINT_BG_LAUNCH_CONTROL) {
719                 b = bundle_import_from_argv(argc, argv);
720                 if (b) {
721                         bg_launch = bundle_get_val(b, AUL_SVC_K_BG_LAUNCH);
722                         if (bg_launch && strcmp(bg_launch, "enable") == 0)
723                                 __set_bg_state();
724
725                         bundle_free(b);
726                 }
727         }
728
729         return appcore_base_init(ops.base, argc, argv, data);
730 }
731
732 EXPORT_API void appcore_ui_base_fini(void)
733 {
734         appcore_base_fini();
735         appcore_ui_plugin_fini();
736
737         if (__context.hshow)
738                 ecore_event_handler_del(__context.hshow);
739         if (__context.hhide)
740                 ecore_event_handler_del(__context.hhide);
741         if (__context.hvchange)
742                 ecore_event_handler_del(__context.hvchange);
743         if (__context.hlower)
744                 ecore_event_handler_del(__context.hlower);
745
746         __finish_wl();
747         elm_shutdown();
748
749         /* Check loader case */
750         if (getenv("AUL_LOADER_INIT")) {
751                 unsetenv("AUL_LOADER_INIT");
752                 elm_shutdown();
753         }
754
755         free(__context.appid);
756         __context.appid = NULL;
757 }
758
759 EXPORT_API void appcore_ui_base_pause(void)
760 {
761         __do_pause();
762 }
763
764 EXPORT_API void appcore_ui_base_resume(void)
765 {
766         __do_resume();
767 }
768
769 EXPORT_API bool appcore_ui_base_is_resumed(void)
770 {
771         return __context.state == AS_RUNNING;
772 }
773
774 EXPORT_API void appcore_ui_base_exit(void)
775 {
776         if (__context.ops.base.exit)
777                 __context.ops.base.exit(__context.data);
778 }
779
780 EXPORT_API unsigned int appcore_ui_base_get_main_window(void)
781 {
782         return __get_main_window();
783 }
784
785 EXPORT_API unsigned int appcore_ui_base_get_main_surface(void)
786 {
787         return __get_main_surface();
788 }
789
790 static int __on_receive(aul_type type, bundle *b, void *data)
791 {
792         return appcore_ui_base_on_receive(type, b);
793 }
794
795 static int __on_create(void *data)
796 {
797         return appcore_ui_base_on_create();
798 }
799
800 static int __on_terminate(void *data)
801 {
802         return appcore_ui_base_on_terminate();
803 }
804
805 static int __on_pause(void *data)
806 {
807         return appcore_ui_base_on_pause();
808 }
809
810 static int __on_resume(void *data)
811 {
812         return appcore_ui_base_on_resume();
813 }
814
815 static void __window_on_show(int type, void *event, void *data)
816 {
817         appcore_ui_base_window_on_show(type, event);
818 }
819
820 static void __window_on_hide(int type, void *event, void *data)
821 {
822         appcore_ui_base_window_on_hide(type, event);
823 }
824
825 static void __window_on_lower(int type, void *event, void *data)
826 {
827         appcore_ui_base_window_on_lower(type, event);
828 }
829
830 static void __window_on_visibility(int type, void *event, void *data)
831 {
832         appcore_ui_base_window_on_visibility(type, event);
833 }
834
835 static void __run(void *data)
836 {
837         elm_run();
838 }
839
840 static void __exit(void *data)
841 {
842         elm_exit();
843 }
844
845 EXPORT_API appcore_ui_base_ops appcore_ui_base_get_default_ops(void)
846 {
847         appcore_ui_base_ops ops;
848
849         ops.base = appcore_base_get_default_ops();
850
851         /* override methods */
852         ops.base.create = __on_create;
853         ops.base.terminate = __on_terminate;
854         ops.base.receive = __on_receive;
855         ops.base.run = __run;
856         ops.base.exit = __exit;
857
858         ops.pause = __on_pause;
859         ops.resume = __on_resume;
860         ops.window.show = __window_on_show;
861         ops.window.hide = __window_on_hide;
862         ops.window.lower = __window_on_lower;
863         ops.window.visibility = __window_on_visibility;
864
865         return ops;
866 }
867
868