2 * Copyright (c) 2000 - 2016 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.
17 #include <sys/types.h>
18 #include <sys/socket.h>
28 #include <Ecore_Wayland.h>
29 #include <wayland-client.h>
30 #include <wayland-tbm-client.h>
31 #include <tizen-extension-client-protocol.h>
33 #include <X11/Xatom.h>
39 #include <Ecore_Evas.h>
40 #include <Ecore_Input_Evas.h>
41 #include <Elementary.h>
42 #include <glib-object.h>
49 #include <bundle_internal.h>
52 #include "appcore-internal.h"
53 #include "appcore-efl.h"
56 static bool resource_reclaiming = TRUE;
57 static int tmp_val = 0;
63 Ecore_Event_Handler *hshow;
64 Ecore_Event_Handler *hhide;
65 Ecore_Event_Handler *hvchange;
67 Ecore_Event_Handler *hlower;
69 Ecore_Event_Handler *hcmsg; /* WM_ROTATE */
71 Ecore_Timer *mftimer; /* Ecore Timer for memory flushing */
73 struct appcore *app_core;
74 #ifdef _APPFW_FEATURE_BACKGROUND_MANAGEMENT
75 void (*prepare_to_suspend) (void *data);
76 void (*exit_from_suspend) (void *data);
78 struct appcore_ops *ops;
79 void (*mfcb) (void); /* Memory Flushing Callback */
84 int (*rot_cb) (void *event_info, enum appcore_rm, void *);
86 enum appcore_rm rot_mode;
91 static struct ui_priv priv;
93 static const char *_ae_name[AE_MAX] = {
94 [AE_UNKNOWN] = "UNKNOWN",
95 [AE_CREATE] = "CREATE",
96 [AE_TERMINATE] = "TERMINATE",
98 [AE_RESUME] = "RESUME",
100 [AE_LOWMEM_POST] = "LOWMEM_POST",
101 [AE_MEM_FLUSH] = "MEM_FLUSH",
102 [AE_UPDATE_REQUESTED] = "UPDATE_REQUESTED",
105 static const char *_as_name[] = {
107 [AS_CREATED] = "CREATED",
108 [AS_RUNNING] = "RUNNING",
109 [AS_PAUSED] = "PAUSED",
110 [AS_DYING] = "DYING",
113 static bool b_active = FALSE;
114 static bool first_launch = TRUE;
125 static struct ui_wm_rotate wm_rotate;
127 static Eina_Bool __visibility_cb(void *data, int type, void *event);
128 static GSList *g_winnode_list;
130 static struct wl_display *dsp;
131 static struct wl_registry *reg;
132 static struct tizen_policy *tz_policy;
133 static bool bg_state = false;
135 static void __wl_listener_cb(void *data, struct wl_registry *reg,
136 uint32_t id, const char *interface, uint32_t ver)
138 if (interface && !strcmp(interface, "tizen_policy")) {
140 tz_policy = wl_registry_bind(reg, id,
141 &tizen_policy_interface, 1);
145 static void __wl_listener_remove_cb(void *data, struct wl_registry *reg,
151 static const struct wl_registry_listener reg_listener = {
153 __wl_listener_remove_cb
156 static int __init_wl(void)
158 _DBG("initialize wayland");
159 dsp = wl_display_connect(NULL);
161 _ERR("Failed to connect wl display");
165 reg = wl_display_get_registry(dsp);
167 _ERR("Failed to get registry");
168 wl_display_disconnect(dsp);
172 wl_registry_add_listener(reg, ®_listener, NULL);
173 wl_display_roundtrip(dsp);
176 _ERR("Failed to get tizen policy interface");
177 wl_registry_destroy(reg);
178 wl_display_disconnect(dsp);
185 static void __finish_wl(void)
188 tizen_policy_destroy(tz_policy);
193 wl_registry_destroy(reg);
198 wl_display_disconnect(dsp);
203 static void __set_bg_state(void)
208 tizen_policy_set_background_state(tz_policy, getpid());
209 wl_display_roundtrip(dsp);
211 _DBG("bg state: %d", bg_state);
214 static void __unset_bg_state(void)
219 tizen_policy_unset_background_state(tz_policy, getpid());
220 wl_display_roundtrip(dsp);
222 _DBG("bg state: %d", bg_state);
226 #ifdef _APPFW_FEATURE_BACKGROUND_MANAGEMENT
227 static void __appcore_efl_prepare_to_suspend(void *data)
229 struct ui_priv *ui = (struct ui_priv *)data;
230 struct sys_op *op = NULL;
231 int suspend = APPCORE_SUSPENDED_STATE_WILL_ENTER_SUSPEND;
233 if (ui->app_core && !ui->app_core->allowed_bg && !ui->app_core->suspended_state) {
234 op = &ui->app_core->sops[SE_SUSPENDED_STATE];
236 op->func((void *)&suspend, op->data); /* calls c-api handler */
238 ui->app_core->suspended_state = true;
240 _DBG("[__SUSPEND__]");
243 static void __appcore_efl_exit_from_suspend(void *data)
245 struct ui_priv *ui = (struct ui_priv *)data;
246 struct sys_op *op = NULL;
247 int suspend = APPCORE_SUSPENDED_STATE_DID_EXIT_FROM_SUSPEND;
249 if (ui->app_core && !ui->app_core->allowed_bg && ui->app_core->suspended_state) {
250 op = &ui->app_core->sops[SE_SUSPENDED_STATE];
252 op->func((void *)&suspend, op->data); /* calls c-api handler */
254 ui->app_core->suspended_state = false;
256 _DBG("[__SUSPEND__]");
260 static void __appcore_efl_update_requested(void *data)
262 struct ui_priv *ui = (struct ui_priv *)data;
267 op = &ui->app_core->sops[SE_UPDATE_REQUESTED];
269 op->func((void *)&dummy, op->data);
271 _DBG("[__UPDATE_REQUESTED__]");
274 #if defined(MEMORY_FLUSH_ACTIVATE)
275 static Eina_Bool __appcore_memory_flush_cb(void *data)
277 struct ui_priv *ui = (struct ui_priv *)data;
279 appcore_flush_memory();
283 #ifdef _APPFW_FEATURE_BACKGROUND_MANAGEMENT
284 if (ui && ui->prepare_to_suspend) {
285 _DBG("[__SUSPEND__] flush case");
286 ui->prepare_to_suspend(ui);
290 return ECORE_CALLBACK_CANCEL;
293 static int __appcore_low_memory_post_cb(struct ui_priv *ui)
295 if (ui->state == AS_PAUSED)
296 appcore_flush_memory();
303 static void __appcore_timer_add(struct ui_priv *ui)
305 ui->mftimer = ecore_timer_add(5, __appcore_memory_flush_cb, ui);
308 static void __appcore_timer_del(struct ui_priv *ui)
311 ecore_timer_del(ui->mftimer);
318 static int __appcore_low_memory_post_cb(ui_priv *ui)
323 #define __appcore_timer_add(ui) 0
324 #define __appcore_timer_del(ui) 0
328 static void __appcore_efl_memory_flush_cb(void)
330 _DBG("[APP %d] __appcore_efl_memory_flush_cb()", _pid);
331 elm_cache_all_flush();
334 static void wl_raise_win(void)
336 Ecore_Wl_Window *win;
337 unsigned int win_id = appcore_get_main_window();
339 _DBG("Raise window: %d", win_id);
340 win = ecore_wl_window_find(win_id);
341 ecore_wl_window_activate(win);
344 static void wl_pause_win(void)
346 Ecore_Wl_Window *win;
347 GSList *wlist = g_winnode_list;
348 struct win_node *entry = NULL;
350 _DBG("Pause window");
355 _DBG("Pause window: %d", entry->win);
356 win = ecore_wl_window_find(entry->win);
357 ecore_wl_window_iconified_set(win, EINA_TRUE);
365 static void __do_app(enum app_event event, void *data, bundle * b)
368 struct ui_priv *ui = data;
369 const char *below_app;
370 const char *bg_launch;
372 _DBG("[APP %d] Event: %d", _pid, event);
373 _ret_if(ui == NULL || event >= AE_MAX);
374 _DBG("[APP %d] Event: %s State: %s", _pid, _ae_name[event],
375 _as_name[ui->state]);
377 if (event == AE_MEM_FLUSH) {
382 if (event == AE_LOWMEM_POST) {
383 if (__appcore_low_memory_post_cb(ui) == 0)
387 if (!(ui->state == AS_PAUSED && event == AE_PAUSE))
388 __appcore_timer_del(ui);
390 if (ui->state == AS_DYING) {
391 _ERR("Skip the event in dying state");
395 if (event == AE_TERMINATE) {
396 _DBG("[APP %d] TERMINATE", _pid);
398 aul_status_update(STATUS_DYING);
402 if (event == AE_RAISE) {
404 x_raise_win(getpid());
405 #elif defined(WAYLAND)
411 if (event == AE_LOWER) {
413 x_pause_win(getpid());
414 #elif defined(WAYLAND)
420 _ret_if(ui->ops == NULL);
424 _DBG("[APP %d] RESET", _pid);
425 if (ui->pending_data)
426 bundle_free(ui->pending_data);
427 ui->pending_data = bundle_dup(b);
428 LOG(LOG_DEBUG, "LAUNCH", "[%s:Application:reset:start]", ui->name);
432 ui->below_app = NULL;
435 below_app = bundle_get_val(b, AUL_SVC_K_RELOCATE_BELOW);
437 ui->below_app = strdup(below_app);
438 #ifdef _APPFW_FEATURE_BACKGROUND_MANAGEMENT
439 if (ui->exit_from_suspend) {
440 _DBG("[__SUSPEND__] reset case");
441 ui->exit_from_suspend(ui);
445 if (ui->ops->reset) {
446 traceBegin(TTRACE_TAG_APPLICATION_MANAGER,
448 r = ui->ops->reset(b, ui->ops->data);
449 traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
451 LOG(LOG_DEBUG, "LAUNCH", "[%s:Application:reset:done]", ui->name);
454 #ifdef _APPFW_FEATURE_BACKGROUND_MANAGEMENT
455 if (ui->app_core->allowed_bg)
456 __appcore_timer_add(ui);
458 first_launch = FALSE;
460 _INFO("[APP %d] App already running, raise the window", _pid);
462 bg_launch = bundle_get_val(b, AUL_SVC_K_BG_LAUNCH);
463 if (!bg_launch || strcmp(bg_launch, "enable"))
467 x_raise_win(getpid());
472 LOG(LOG_DEBUG, "LAUNCH", "[%s:Application:reset:done]",
476 if (ui->state == AS_RUNNING) {
477 _DBG("[APP %d] PAUSE", _pid);
478 if (ui->ops->pause) {
479 traceBegin(TTRACE_TAG_APPLICATION_MANAGER,
481 r = ui->ops->pause(ui->ops->data);
482 traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
484 ui->state = AS_PAUSED;
485 if (r >= 0 && resource_reclaiming == TRUE)
486 __appcore_timer_add(ui);
487 #ifdef _APPFW_FEATURE_BACKGROUND_MANAGEMENT
488 else if (r >= 0 && resource_reclaiming == FALSE
489 && ui->prepare_to_suspend) {
490 _DBG("[__SUSPEND__] pause case");
491 ui->prepare_to_suspend(ui);
495 /* TODO : rotation stop */
496 /* r = appcore_pause_rotation_cb(); */
497 aul_status_update(STATUS_BG);
500 LOG(LOG_DEBUG, "LAUNCH", "[%s:Application:resume:start]",
502 #ifdef _APPFW_FEATURE_BACKGROUND_MANAGEMENT
503 if (ui->exit_from_suspend) {
504 _DBG("[__SUSPEND__] resume case");
505 ui->exit_from_suspend(ui);
507 if (ui->app_core->allowed_bg)
508 __appcore_timer_del(ui);
511 if (ui->state == AS_PAUSED || ui->state == AS_CREATED) {
512 _DBG("[APP %d] RESUME", _pid);
514 if (ui->state == AS_CREATED) {
515 bundle_free(ui->pending_data);
516 ui->pending_data = NULL;
519 if (ui->ops->resume) {
520 traceBegin(TTRACE_TAG_APPLICATION_MANAGER,
522 ui->ops->resume(ui->ops->data);
523 traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
525 ui->state = AS_RUNNING;
528 aul_app_group_activate_below(ui->below_app);
530 ui->below_app = NULL;
533 /*TODO : rotation start*/
534 /* r = appcore_resume_rotation_cb(); */
535 LOG(LOG_DEBUG, "LAUNCH", "[%s:Application:resume:done]",
537 LOG(LOG_DEBUG, "LAUNCH", "[%s:Application:Launching:done]",
539 aul_status_update(STATUS_VISIBLE);
541 case AE_TERMINATE_BGAPP:
542 if (ui->state == AS_PAUSED) {
543 _DBG("[APP %d] is paused. TERMINATE", _pid);
544 ui->state = AS_DYING;
545 aul_status_update(STATUS_DYING);
547 } else if (ui->state == AS_RUNNING) {
548 _DBG("[APP %d] is running.", _pid);
550 _DBG("[APP %d] is another state", _pid);
553 case AE_UPDATE_REQUESTED:
554 __appcore_efl_update_requested(ui);
562 static struct ui_ops efl_ops = {
567 static bool __check_visible(void)
570 struct win_node *entry = NULL;
572 _DBG("[EVENT_TEST][EVENT] __check_visible\n");
574 for (iter = g_winnode_list; iter != NULL; iter = g_slist_next(iter)) {
576 _DBG("win : %x obscured : %d\n", entry->win, entry->bfobscured);
577 if (entry->bfobscured == FALSE)
584 static GSList *__find_win(unsigned int win)
589 for (iter = g_winnode_list; iter; iter = g_slist_next(iter)) {
591 if (t && t->win == win)
599 static bool __add_win(unsigned int win)
604 _DBG("[EVENT_TEST][EVENT] __add_win WIN:%x\n", win);
609 _DBG("[EVENT_TEST][EVENT] ERROR There is already window : %x \n", win);
613 t = calloc(1, sizeof(struct win_node));
618 t->bfobscured = FALSE;
620 g_winnode_list = g_slist_append(g_winnode_list, t);
624 #elif defined(WAYLAND)
625 static bool __add_win(unsigned int win, unsigned int surf)
630 _DBG("[EVENT_TEST][EVENT] __add_win WIN:%x\n", win);
635 _DBG("[EVENT_TEST][EVENT] ERROR There is already window : %x \n", win);
639 t = calloc(1, sizeof(struct win_node));
645 t->bfobscured = FALSE;
647 g_winnode_list = g_slist_append(g_winnode_list, t);
653 static bool __delete_win(unsigned int win)
660 _DBG("[EVENT_TEST][EVENT] ERROR There is no window : %x \n",
666 g_winnode_list = g_slist_delete_link(g_winnode_list, f);
672 static bool __update_win(unsigned int win, bool bfobscured)
677 _DBG("[EVENT_TEST][EVENT] __update_win WIN:%x fully_obscured %d\n", win,
683 _DBG("[EVENT_TEST][EVENT] ERROR There is no window : %x \n", win);
687 t = (struct win_node *)f->data;
689 t->bfobscured = bfobscured;
693 #elif defined(WAYLAND)
694 static bool __update_win(unsigned int win, unsigned int surf, bool bfobscured)
699 _DBG("[EVENT_TEST][EVENT] __update_win WIN:%x fully_obscured %d\n", win,
705 _DBG("[EVENT_TEST][EVENT] ERROR There is no window : %x \n", win);
709 t = (struct win_node *)f->data;
713 t->bfobscured = bfobscured;
721 static Ecore_X_Atom _WM_WINDOW_ROTATION_SUPPORTED = 0;
722 static Ecore_X_Atom _WM_WINDOW_ROTATION_CHANGE_REQUEST = 0;
724 static int __check_wm_rotation_support(void)
726 _DBG("Disable window manager rotation");
729 Ecore_X_Window root, win, win2;
732 if (!_WM_WINDOW_ROTATION_SUPPORTED) {
733 _WM_WINDOW_ROTATION_SUPPORTED =
734 ecore_x_atom_get("_E_WINDOW_ROTATION_SUPPORTED");
737 if (!_WM_WINDOW_ROTATION_CHANGE_REQUEST) {
738 _WM_WINDOW_ROTATION_CHANGE_REQUEST =
739 ecore_x_atom_get("_E_WINDOW_ROTATION_CHANGE_REQUEST");
742 root = ecore_x_window_root_first_get();
743 ret = ecore_x_window_prop_xid_get(root,
744 _WM_WINDOW_ROTATION_SUPPORTED,
747 if ((ret == 1) && (win)) {
748 ret = ecore_x_window_prop_xid_get(win,
749 _WM_WINDOW_ROTATION_SUPPORTED,
752 if ((ret == 1) && (win2 == win))
759 static void __set_wm_rotation_support(unsigned int win, unsigned int set)
762 struct win_node *entry = NULL;
765 for (iter = g_winnode_list; iter != NULL; iter = g_slist_next(iter)) {
768 ecore_x_window_prop_card32_set(entry->win,
769 _WM_WINDOW_ROTATION_SUPPORTED,
774 ecore_x_window_prop_card32_set(win,
775 _WM_WINDOW_ROTATION_SUPPORTED,
781 static Eina_Bool __show_cb(void *data, int type, void *event)
784 Ecore_Wl_Event_Window_Show *ev;
787 if (ev->parent_win != 0) {
788 /* This is child window. Skip!!! */
789 return ECORE_CALLBACK_PASS_ON;
792 _DBG("[EVENT_TEST][EVENT] GET SHOW EVENT!!!. WIN:%x, %d\n", ev->win, ev->data[0]);
794 if (!__find_win((unsigned int)ev->win))
795 __add_win((unsigned int)ev->win, (unsigned int)ev->data[0]);
797 __update_win((unsigned int)ev->win, (unsigned int)ev->data[0], FALSE);
800 Ecore_X_Event_Window_Show *ev;
804 _DBG("[EVENT_TEST][EVENT] GET SHOW EVENT!!!. WIN:%x\n", ev->win);
806 if (!__find_win((unsigned int)ev->win)) {
808 if ((priv.wm_rot_supported) && (1 == priv.rot_started))
809 __set_wm_rotation_support(ev->win, 1);
810 __add_win((unsigned int)ev->win);
812 __update_win((unsigned int)ev->win, FALSE);
816 appcore_group_attach();
817 return ECORE_CALLBACK_RENEW;
820 static Eina_Bool __hide_cb(void *data, int type, void *event)
823 Ecore_Wl_Event_Window_Hide *ev;
825 Ecore_X_Event_Window_Hide *ev;
831 _DBG("[EVENT_TEST][EVENT] GET HIDE EVENT!!!. WIN:%x\n", ev->win);
833 if (__find_win((unsigned int)ev->win)) {
834 __delete_win((unsigned int)ev->win);
835 bvisibility = __check_visible();
836 if (!bvisibility && b_active == TRUE) {
837 _DBG(" Go to Pasue state \n");
839 __do_app(AE_PAUSE, data, NULL);
843 return ECORE_CALLBACK_RENEW;
847 static Eina_Bool __lower_cb(void *data, int type, void *event)
849 Ecore_Wl_Event_Window_Lower *ev;
851 if (!ev) return ECORE_CALLBACK_RENEW;
852 _DBG("ECORE_WL_EVENT_WINDOW_LOWER window id:%u\n", ev->win);
853 appcore_group_lower();
854 return ECORE_CALLBACK_RENEW;
858 static Eina_Bool __visibility_cb(void *data, int type, void *event)
861 Ecore_Wl_Event_Window_Visibility_Change *ev;
864 __update_win((unsigned int)ev->win, 0, ev->fully_obscured);
866 Ecore_X_Event_Window_Visibility_Change *ev;
871 __update_win((unsigned int)ev->win, ev->fully_obscured);
873 bvisibility = __check_visible();
875 _DBG("bvisibility %d, b_active %d", bvisibility, b_active);
877 if (bvisibility && b_active == FALSE) {
878 _DBG(" Go to Resume state\n");
880 __do_app(AE_RESUME, data, NULL);
882 } else if (!bvisibility && b_active == TRUE) {
883 _DBG(" Go to Pasue state \n");
885 __do_app(AE_PAUSE, data, NULL);
887 _DBG(" No change state \n");
889 return ECORE_CALLBACK_RENEW;
895 static Eina_Bool __cmsg_cb(void *data, int type, void *event)
897 struct ui_priv *ui = (struct ui_priv *)data;
898 Ecore_X_Event_Client_Message *e = event;
901 return ECORE_CALLBACK_PASS_ON;
904 return ECORE_CALLBACK_PASS_ON;
906 if (e->message_type == _WM_WINDOW_ROTATION_CHANGE_REQUEST) {
907 if ((ui->wm_rot_supported == 0)
908 || (ui->rot_started == 0)
909 || (ui->rot_cb == NULL)) {
910 return ECORE_CALLBACK_PASS_ON;
914 switch (e->data.l[1]) {
916 rm = APPCORE_RM_PORTRAIT_NORMAL;
919 rm = APPCORE_RM_LANDSCAPE_REVERSE;
922 rm = APPCORE_RM_PORTRAIT_REVERSE;
925 rm = APPCORE_RM_LANDSCAPE_NORMAL;
928 rm = APPCORE_RM_UNKNOWN;
934 if (APPCORE_RM_UNKNOWN != rm)
935 ui->rot_cb((void *)&rm, rm, ui->rot_cb_data);
938 return ECORE_CALLBACK_PASS_ON;
942 static void __add_climsg_cb(struct ui_priv *ui)
947 ecore_event_handler_add(ECORE_WL_EVENT_WINDOW_SHOW, __show_cb, ui);
949 ecore_event_handler_add(ECORE_WL_EVENT_WINDOW_HIDE, __hide_cb, ui);
951 ecore_event_handler_add(ECORE_WL_EVENT_WINDOW_VISIBILITY_CHANGE,
952 __visibility_cb, ui);
954 ecore_event_handler_add(ECORE_WL_EVENT_WINDOW_LOWER,
958 ecore_event_handler_add(ECORE_X_EVENT_WINDOW_SHOW, __show_cb, ui);
960 ecore_event_handler_add(ECORE_X_EVENT_WINDOW_HIDE, __hide_cb, ui);
962 ecore_event_handler_add(ECORE_X_EVENT_WINDOW_VISIBILITY_CHANGE,
963 __visibility_cb, ui);
965 /* Add client message callback for WM_ROTATE */
966 if (!__check_wm_rotation_support()) {
967 ui->hcmsg = ecore_event_handler_add(ECORE_X_EVENT_CLIENT_MESSAGE,
969 ui->wm_rot_supported = 1;
970 appcore_set_wm_rotation(&wm_rotate);
975 static int __before_loop(struct ui_priv *ui, int *argc, char ***argv)
979 #if _APPFW_FEATURE_BACKGROUND_MANAGEMENT
980 struct appcore *ac = NULL;
983 const char *bg_launch;
985 if (argc == NULL || argv == NULL) {
986 _ERR("argc/argv is NULL");
991 #if !(GLIB_CHECK_VERSION(2, 36, 0))
994 elm_init(*argc, *argv);
996 hwacc = getenv("HWACC");
998 _DBG("elm_config_accel_preference_set is not called");
999 } else if (strcmp(hwacc, "USE") == 0) {
1000 elm_config_accel_preference_set("hw");
1001 _DBG("elm_config_accel_preference_set : hw");
1002 } else if (strcmp(hwacc, "NOT_USE") == 0) {
1003 elm_config_accel_preference_set("none");
1004 _DBG("elm_config_accel_preference_set : none");
1006 _DBG("elm_config_accel_preference_set is not called");
1009 r = appcore_init(ui->name, &efl_ops, *argc, *argv);
1010 _retv_if(r == -1, -1);
1012 #if _APPFW_FEATURE_BACKGROUND_MANAGEMENT
1013 appcore_get_app_core(&ac);
1015 SECURE_LOGD("[__SUSPEND__] appcore initialized, appcore addr: #%x", ac);
1018 b = bundle_import_from_argv(*argc, *argv);
1020 bg_launch = bundle_get_val(b, AUL_SVC_K_BG_LAUNCH);
1021 if (bg_launch && strcmp(bg_launch, "enable") == 0)
1027 LOG(LOG_DEBUG, "LAUNCH", "[%s:Platform:appcore_init:done]", ui->name);
1028 if (ui->ops && ui->ops->create) {
1029 traceBegin(TTRACE_TAG_APPLICATION_MANAGER, "APPCORE:CREATE");
1030 r = ui->ops->create(ui->ops->data);
1031 traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
1033 _ERR("create() return error");
1035 if (ui->ops && ui->ops->terminate) {
1036 traceBegin(TTRACE_TAG_APPLICATION_MANAGER,
1037 "APPCORE:TERMINATE");
1038 ui->ops->terminate(ui->ops->data);
1039 traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
1044 LOG(LOG_DEBUG, "LAUNCH", "[%s:Application:create:done]",
1047 ui->state = AS_CREATED;
1049 __add_climsg_cb(ui);
1054 static void __after_loop(struct ui_priv *ui)
1056 appcore_unset_rotation_cb();
1059 if (ui->state == AS_RUNNING) {
1060 _DBG("[APP %d] PAUSE before termination", _pid);
1061 if (ui->ops && ui->ops->pause) {
1062 traceBegin(TTRACE_TAG_APPLICATION_MANAGER,
1064 ui->ops->pause(ui->ops->data);
1065 traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
1069 if (ui->ops && ui->ops->terminate) {
1070 traceBegin(TTRACE_TAG_APPLICATION_MANAGER, "APPCORE:TERMINATE");
1071 ui->ops->terminate(ui->ops->data);
1072 traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
1075 ui->state = AS_DYING;
1078 ecore_event_handler_del(ui->hshow);
1080 ecore_event_handler_del(ui->hhide);
1082 ecore_event_handler_del(ui->hvchange);
1083 #if defined(WAYLAND)
1085 ecore_event_handler_del(ui->hlower);
1088 __appcore_timer_del(ui);
1092 /* Check loader case */
1093 if (getenv("AUL_LOADER_INIT")) {
1094 unsetenv("AUL_LOADER_INIT");
1099 static int __set_data(struct ui_priv *ui, const char *name,
1100 struct appcore_ops *ops)
1103 _ERR("Mainloop already started");
1104 errno = EINPROGRESS;
1108 if (name == NULL || name[0] == '\0') {
1109 _ERR("Invalid name");
1115 _ERR("ops is NULL");
1120 ui->name = strdup(name);
1121 _retv_if(ui->name == NULL, -1);
1124 ui->mfcb = __appcore_efl_memory_flush_cb;
1128 ui->wm_rot_supported = 0;
1129 ui->rot_started = 0;
1131 ui->rot_cb_data = NULL;
1132 ui->rot_mode = APPCORE_RM_UNKNOWN;
1134 #ifdef _APPFW_FEATURE_BACKGROUND_MANAGEMENT
1135 ui->app_core = NULL;
1136 ui->prepare_to_suspend = __appcore_efl_prepare_to_suspend;
1137 ui->exit_from_suspend = __appcore_efl_exit_from_suspend;
1143 static void __unset_data(struct ui_priv *ui)
1146 free((void *)ui->name);
1148 memset(ui, 0, sizeof(struct ui_priv));
1153 static int __wm_set_rotation_cb(int (*cb) (void *event_info, enum appcore_rm, void *), void *data)
1160 if ((priv.wm_rot_supported) && (0 == priv.rot_started))
1161 __set_wm_rotation_support(0, 1);
1164 priv.rot_cb_data = data;
1165 priv.rot_started = 1;
1170 static int __wm_unset_rotation_cb(void)
1172 if ((priv.wm_rot_supported) && (1 == priv.rot_started))
1173 __set_wm_rotation_support(0, 0);
1176 priv.rot_cb_data = NULL;
1177 priv.rot_started = 0;
1182 static int __wm_get_rotation_state(enum appcore_rm *curr)
1189 *curr = priv.rot_mode;
1194 static int __wm_pause_rotation_cb(void)
1196 if ((priv.rot_started == 1) && (priv.wm_rot_supported))
1197 __set_wm_rotation_support(0, 0);
1199 priv.rot_started = 0;
1204 static int __wm_resume_rotation_cb(void)
1206 if ((priv.rot_started == 0) && (priv.wm_rot_supported))
1207 __set_wm_rotation_support(0, 1);
1209 priv.rot_started = 1;
1214 static struct ui_wm_rotate wm_rotate = {
1215 __wm_set_rotation_cb,
1216 __wm_unset_rotation_cb,
1217 __wm_get_rotation_state,
1218 __wm_pause_rotation_cb,
1219 __wm_resume_rotation_cb
1223 EXPORT_API int appcore_efl_init(const char *name, int *argc, char ***argv,
1224 struct appcore_ops *ops)
1228 LOG(LOG_DEBUG, "LAUNCH", "[%s:Application:main:done]", name);
1230 r = __set_data(&priv, name, ops);
1231 _retv_if(r == -1, -1);
1233 r = __before_loop(&priv, argc, argv);
1235 aul_status_update(STATUS_DYING);
1236 __unset_data(&priv);
1243 EXPORT_API void appcore_efl_fini(void)
1245 aul_status_update(STATUS_DYING);
1247 __after_loop(&priv);
1249 __unset_data(&priv);
1252 EXPORT_API int appcore_efl_main(const char *name, int *argc, char ***argv,
1253 struct appcore_ops *ops)
1257 r = appcore_efl_init(name, argc, argv, ops);
1258 _retv_if(r == -1, -1);
1267 EXPORT_API int appcore_set_system_resource_reclaiming(bool enable)
1269 resource_reclaiming = enable;
1274 EXPORT_API int appcore_set_app_state(int state)
1283 EXPORT_API int appcore_set_preinit_window_name(const char *win_name)
1286 void *preinit_window = NULL;
1287 const Evas *e = NULL;
1290 _ERR("invalid parameter");
1294 preinit_window = elm_win_precreated_object_get();
1295 if (!preinit_window) {
1296 _ERR("Failed to get preinit window");
1300 e = evas_object_evas_get((const Evas_Object *)preinit_window);
1302 Ecore_Evas *ee = ecore_evas_ecore_evas_get(e);
1304 ecore_evas_name_class_set(ee, win_name, win_name);
1312 EXPORT_API unsigned int appcore_get_main_window(void)
1314 struct win_node *entry = NULL;
1316 if (g_winnode_list != NULL) {
1317 entry = g_winnode_list->data;
1318 return (unsigned int) entry->win;
1324 #if defined(WAYLAND)
1325 EXPORT_API unsigned int appcore_get_main_surface(void)
1327 struct win_node *entry = NULL;
1329 if (g_winnode_list != NULL) {
1330 entry = g_winnode_list->data;
1331 return (unsigned int) entry->surf;