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 #ifdef _APPFW_FEATURE_BACKGROUND_MANAGEMENT
74 struct appcore *app_core;
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",
104 static const char *_as_name[] = {
106 [AS_CREATED] = "CREATED",
107 [AS_RUNNING] = "RUNNING",
108 [AS_PAUSED] = "PAUSED",
109 [AS_DYING] = "DYING",
112 static bool b_active = FALSE;
113 static bool first_launch = TRUE;
124 static struct ui_wm_rotate wm_rotate;
126 static Eina_Bool __visibility_cb(void *data, int type, void *event);
127 static GSList *g_winnode_list;
129 static struct wl_display *dsp;
130 static struct wl_registry *reg;
131 static struct tizen_policy *tz_policy;
132 static bool bg_state = false;
134 static void __wl_listener_cb(void *data, struct wl_registry *reg,
135 uint32_t id, const char *interface, uint32_t ver)
137 if (interface && !strcmp(interface, "tizen_policy")) {
139 tz_policy = wl_registry_bind(reg, id,
140 &tizen_policy_interface, 1);
144 static void __wl_listener_remove_cb(void *data, struct wl_registry *reg,
150 static const struct wl_registry_listener reg_listener = {
152 __wl_listener_remove_cb
155 static int __init_wl(void)
157 _DBG("initialize wayland");
158 dsp = wl_display_connect(NULL);
160 _ERR("Failed to connect wl display");
164 reg = wl_display_get_registry(dsp);
166 _ERR("Failed to get registry");
167 wl_display_disconnect(dsp);
171 wl_registry_add_listener(reg, ®_listener, NULL);
172 wl_display_roundtrip(dsp);
175 _ERR("Failed to get tizen policy interface");
176 wl_registry_destroy(reg);
177 wl_display_disconnect(dsp);
184 static void __finish_wl(void)
187 tizen_policy_destroy(tz_policy);
192 wl_registry_destroy(reg);
197 wl_display_disconnect(dsp);
202 static void __set_bg_state(void)
207 tizen_policy_set_background_state(tz_policy, getpid());
208 wl_display_roundtrip(dsp);
210 _DBG("bg state: %d", bg_state);
213 static void __unset_bg_state(void)
218 tizen_policy_unset_background_state(tz_policy, getpid());
219 wl_display_roundtrip(dsp);
221 _DBG("bg state: %d", bg_state);
225 #ifdef _APPFW_FEATURE_BACKGROUND_MANAGEMENT
226 static void __appcore_efl_prepare_to_suspend(void *data)
228 struct ui_priv *ui = (struct ui_priv *)data;
229 struct sys_op *op = NULL;
230 int suspend = APPCORE_SUSPENDED_STATE_WILL_ENTER_SUSPEND;
232 if (ui->app_core && !ui->app_core->allowed_bg && !ui->app_core->suspended_state) {
233 op = &ui->app_core->sops[SE_SUSPENDED_STATE];
235 op->func((void *)&suspend, op->data); /* calls c-api handler */
237 ui->app_core->suspended_state = true;
239 _DBG("[__SUSPEND__]");
242 static void __appcore_efl_exit_from_suspend(void *data)
244 struct ui_priv *ui = (struct ui_priv *)data;
245 struct sys_op *op = NULL;
246 int suspend = APPCORE_SUSPENDED_STATE_DID_EXIT_FROM_SUSPEND;
248 if (ui->app_core && !ui->app_core->allowed_bg && ui->app_core->suspended_state) {
249 op = &ui->app_core->sops[SE_SUSPENDED_STATE];
251 op->func((void *)&suspend, op->data); /* calls c-api handler */
253 ui->app_core->suspended_state = false;
255 _DBG("[__SUSPEND__]");
259 #if defined(MEMORY_FLUSH_ACTIVATE)
260 static Eina_Bool __appcore_memory_flush_cb(void *data)
262 struct ui_priv *ui = (struct ui_priv *)data;
264 appcore_flush_memory();
268 #ifdef _APPFW_FEATURE_BACKGROUND_MANAGEMENT
269 if (ui && ui->prepare_to_suspend) {
270 _DBG("[__SUSPEND__] flush case");
271 ui->prepare_to_suspend(ui);
275 return ECORE_CALLBACK_CANCEL;
278 static int __appcore_low_memory_post_cb(struct ui_priv *ui)
280 if (ui->state == AS_PAUSED)
281 appcore_flush_memory();
288 static void __appcore_timer_add(struct ui_priv *ui)
290 ui->mftimer = ecore_timer_add(5, __appcore_memory_flush_cb, ui);
293 static void __appcore_timer_del(struct ui_priv *ui)
296 ecore_timer_del(ui->mftimer);
303 static int __appcore_low_memory_post_cb(ui_priv *ui)
308 #define __appcore_timer_add(ui) 0
309 #define __appcore_timer_del(ui) 0
313 static void __appcore_efl_memory_flush_cb(void)
315 _DBG("[APP %d] __appcore_efl_memory_flush_cb()", _pid);
316 elm_cache_all_flush();
319 static void wl_raise_win(void)
321 Ecore_Wl_Window *win;
322 unsigned int win_id = appcore_get_main_window();
324 _DBG("Raise window: %d", win_id);
325 win = ecore_wl_window_find(win_id);
326 ecore_wl_window_activate(win);
329 static void wl_pause_win(void)
331 Ecore_Wl_Window *win;
332 GSList *wlist = g_winnode_list;
333 struct win_node *entry = NULL;
335 _DBG("Pause window");
340 _DBG("Pause window: %d", entry->win);
341 win = ecore_wl_window_find(entry->win);
342 ecore_wl_window_iconified_set(win, EINA_TRUE);
350 static void __do_app(enum app_event event, void *data, bundle * b)
353 struct ui_priv *ui = data;
354 const char *below_app;
355 const char *bg_launch;
357 _DBG("[APP %d] Event: %d", _pid, event);
358 _ret_if(ui == NULL || event >= AE_MAX);
359 _DBG("[APP %d] Event: %s State: %s", _pid, _ae_name[event],
360 _as_name[ui->state]);
362 if (event == AE_MEM_FLUSH) {
367 if (event == AE_LOWMEM_POST) {
368 if (__appcore_low_memory_post_cb(ui) == 0)
372 if (!(ui->state == AS_PAUSED && event == AE_PAUSE))
373 __appcore_timer_del(ui);
375 if (ui->state == AS_DYING) {
376 _ERR("Skip the event in dying state");
380 if (event == AE_TERMINATE) {
381 _DBG("[APP %d] TERMINATE", _pid);
383 aul_status_update(STATUS_DYING);
387 if (event == AE_RAISE) {
389 x_raise_win(getpid());
390 #elif defined(WAYLAND)
396 if (event == AE_LOWER) {
398 x_pause_win(getpid());
399 #elif defined(WAYLAND)
405 _ret_if(ui->ops == NULL);
409 _DBG("[APP %d] RESET", _pid);
410 ui->pending_data = bundle_dup(b);
411 LOG(LOG_DEBUG, "LAUNCH", "[%s:Application:reset:start]", ui->name);
415 ui->below_app = NULL;
418 below_app = bundle_get_val(b, AUL_SVC_K_RELOCATE_BELOW);
420 ui->below_app = strdup(below_app);
421 #ifdef _APPFW_FEATURE_BACKGROUND_MANAGEMENT
422 if (ui->exit_from_suspend) {
423 _DBG("[__SUSPEND__] reset case");
424 ui->exit_from_suspend(ui);
428 if (ui->ops->reset) {
429 traceBegin(TTRACE_TAG_APPLICATION_MANAGER,
431 r = ui->ops->reset(b, ui->ops->data);
432 traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
434 LOG(LOG_DEBUG, "LAUNCH", "[%s:Application:reset:done]", ui->name);
437 #ifdef _APPFW_FEATURE_BACKGROUND_MANAGEMENT
438 if (ui->app_core->allowed_bg)
439 __appcore_timer_add(ui);
441 first_launch = FALSE;
443 _INFO("[APP %d] App already running, raise the window", _pid);
445 bg_launch = bundle_get_val(b, AUL_SVC_K_BG_LAUNCH);
446 if (!bg_launch || strcmp(bg_launch, "enable"))
450 x_raise_win(getpid());
455 LOG(LOG_DEBUG, "LAUNCH", "[%s:Application:reset:done]",
459 if (ui->state == AS_RUNNING) {
460 _DBG("[APP %d] PAUSE", _pid);
461 if (ui->ops->pause) {
462 traceBegin(TTRACE_TAG_APPLICATION_MANAGER,
464 r = ui->ops->pause(ui->ops->data);
465 traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
467 ui->state = AS_PAUSED;
468 if (r >= 0 && resource_reclaiming == TRUE)
469 __appcore_timer_add(ui);
470 #ifdef _APPFW_FEATURE_BACKGROUND_MANAGEMENT
471 else if (r >= 0 && resource_reclaiming == FALSE
472 && ui->prepare_to_suspend) {
473 _DBG("[__SUSPEND__] pause case");
474 ui->prepare_to_suspend(ui);
478 /* TODO : rotation stop */
479 /* r = appcore_pause_rotation_cb(); */
480 aul_status_update(STATUS_BG);
483 LOG(LOG_DEBUG, "LAUNCH", "[%s:Application:resume:start]",
485 #ifdef _APPFW_FEATURE_BACKGROUND_MANAGEMENT
486 if (ui->exit_from_suspend) {
487 _DBG("[__SUSPEND__] resume case");
488 ui->exit_from_suspend(ui);
490 if (ui->app_core->allowed_bg)
491 __appcore_timer_del(ui);
494 if (ui->state == AS_PAUSED || ui->state == AS_CREATED) {
495 _DBG("[APP %d] RESUME", _pid);
497 if (ui->state == AS_CREATED) {
498 bundle_free(ui->pending_data);
499 ui->pending_data = NULL;
502 if (ui->ops->resume) {
503 traceBegin(TTRACE_TAG_APPLICATION_MANAGER,
505 ui->ops->resume(ui->ops->data);
506 traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
508 ui->state = AS_RUNNING;
511 aul_app_group_activate_below(ui->below_app);
513 ui->below_app = NULL;
516 /*TODO : rotation start*/
517 /* r = appcore_resume_rotation_cb(); */
518 LOG(LOG_DEBUG, "LAUNCH", "[%s:Application:resume:done]",
520 LOG(LOG_DEBUG, "LAUNCH", "[%s:Application:Launching:done]",
522 aul_status_update(STATUS_VISIBLE);
524 case AE_TERMINATE_BGAPP:
525 if (ui->state == AS_PAUSED) {
526 _DBG("[APP %d] is paused. TERMINATE", _pid);
527 ui->state = AS_DYING;
528 aul_status_update(STATUS_DYING);
530 } else if (ui->state == AS_RUNNING) {
531 _DBG("[APP %d] is running.", _pid);
533 _DBG("[APP %d] is another state", _pid);
542 static struct ui_ops efl_ops = {
547 static bool __check_visible(void)
550 struct win_node *entry = NULL;
552 _DBG("[EVENT_TEST][EVENT] __check_visible\n");
554 for (iter = g_winnode_list; iter != NULL; iter = g_slist_next(iter)) {
556 _DBG("win : %x obscured : %d\n", entry->win, entry->bfobscured);
557 if (entry->bfobscured == FALSE)
564 static GSList *__find_win(unsigned int win)
569 for (iter = g_winnode_list; iter; iter = g_slist_next(iter)) {
571 if (t && t->win == win)
579 static bool __add_win(unsigned int win)
584 _DBG("[EVENT_TEST][EVENT] __add_win WIN:%x\n", win);
589 _DBG("[EVENT_TEST][EVENT] ERROR There is already window : %x \n", win);
593 t = calloc(1, sizeof(struct win_node));
598 t->bfobscured = FALSE;
600 g_winnode_list = g_slist_append(g_winnode_list, t);
604 #elif defined(WAYLAND)
605 static bool __add_win(unsigned int win, unsigned int surf)
610 _DBG("[EVENT_TEST][EVENT] __add_win WIN:%x\n", win);
615 _DBG("[EVENT_TEST][EVENT] ERROR There is already window : %x \n", win);
619 t = calloc(1, sizeof(struct win_node));
625 t->bfobscured = FALSE;
627 g_winnode_list = g_slist_append(g_winnode_list, t);
633 static bool __delete_win(unsigned int win)
640 _DBG("[EVENT_TEST][EVENT] ERROR There is no window : %x \n",
646 g_winnode_list = g_slist_delete_link(g_winnode_list, f);
652 static bool __update_win(unsigned int win, bool bfobscured)
657 _DBG("[EVENT_TEST][EVENT] __update_win WIN:%x fully_obscured %d\n", win,
663 _DBG("[EVENT_TEST][EVENT] ERROR There is no window : %x \n", win);
667 g_winnode_list = g_slist_remove_link(g_winnode_list, f);
669 t = (struct win_node *)f->data;
671 t->bfobscured = bfobscured;
673 g_winnode_list = g_slist_concat(g_winnode_list, f);
677 #elif defined(WAYLAND)
678 static bool __update_win(unsigned int win, unsigned int surf, bool bfobscured)
683 _DBG("[EVENT_TEST][EVENT] __update_win WIN:%x fully_obscured %d\n", win,
689 _DBG("[EVENT_TEST][EVENT] ERROR There is no window : %x \n", win);
693 g_winnode_list = g_slist_remove_link(g_winnode_list, f);
695 t = (struct win_node *)f->data;
699 t->bfobscured = bfobscured;
701 g_winnode_list = g_slist_concat(g_winnode_list, f);
709 static Ecore_X_Atom _WM_WINDOW_ROTATION_SUPPORTED = 0;
710 static Ecore_X_Atom _WM_WINDOW_ROTATION_CHANGE_REQUEST = 0;
712 static int __check_wm_rotation_support(void)
714 _DBG("Disable window manager rotation");
717 Ecore_X_Window root, win, win2;
720 if (!_WM_WINDOW_ROTATION_SUPPORTED) {
721 _WM_WINDOW_ROTATION_SUPPORTED =
722 ecore_x_atom_get("_E_WINDOW_ROTATION_SUPPORTED");
725 if (!_WM_WINDOW_ROTATION_CHANGE_REQUEST) {
726 _WM_WINDOW_ROTATION_CHANGE_REQUEST =
727 ecore_x_atom_get("_E_WINDOW_ROTATION_CHANGE_REQUEST");
730 root = ecore_x_window_root_first_get();
731 ret = ecore_x_window_prop_xid_get(root,
732 _WM_WINDOW_ROTATION_SUPPORTED,
735 if ((ret == 1) && (win)) {
736 ret = ecore_x_window_prop_xid_get(win,
737 _WM_WINDOW_ROTATION_SUPPORTED,
740 if ((ret == 1) && (win2 == win))
747 static void __set_wm_rotation_support(unsigned int win, unsigned int set)
750 struct win_node *entry = NULL;
753 for (iter = g_winnode_list; iter != NULL; iter = g_slist_next(iter)) {
756 ecore_x_window_prop_card32_set(entry->win,
757 _WM_WINDOW_ROTATION_SUPPORTED,
762 ecore_x_window_prop_card32_set(win,
763 _WM_WINDOW_ROTATION_SUPPORTED,
769 static Eina_Bool __show_cb(void *data, int type, void *event)
772 Ecore_Wl_Event_Window_Show *ev;
775 if (ev->parent_win != 0) {
776 /* This is child window. Skip!!! */
777 return ECORE_CALLBACK_PASS_ON;
780 _DBG("[EVENT_TEST][EVENT] GET SHOW EVENT!!!. WIN:%x, %d\n", ev->win, ev->data[0]);
782 if (!__find_win((unsigned int)ev->win))
783 __add_win((unsigned int)ev->win, (unsigned int)ev->data[0]);
785 __update_win((unsigned int)ev->win, (unsigned int)ev->data[0], FALSE);
788 Ecore_X_Event_Window_Show *ev;
792 _DBG("[EVENT_TEST][EVENT] GET SHOW EVENT!!!. WIN:%x\n", ev->win);
794 if (!__find_win((unsigned int)ev->win)) {
796 if ((priv.wm_rot_supported) && (1 == priv.rot_started))
797 __set_wm_rotation_support(ev->win, 1);
798 __add_win((unsigned int)ev->win);
800 __update_win((unsigned int)ev->win, FALSE);
804 appcore_group_attach();
805 return ECORE_CALLBACK_RENEW;
808 static Eina_Bool __hide_cb(void *data, int type, void *event)
811 Ecore_Wl_Event_Window_Hide *ev;
813 Ecore_X_Event_Window_Hide *ev;
819 _DBG("[EVENT_TEST][EVENT] GET HIDE EVENT!!!. WIN:%x\n", ev->win);
821 if (__find_win((unsigned int)ev->win)) {
822 __delete_win((unsigned int)ev->win);
823 bvisibility = __check_visible();
824 if (!bvisibility && b_active == TRUE) {
825 _DBG(" Go to Pasue state \n");
827 __do_app(AE_PAUSE, data, NULL);
831 return ECORE_CALLBACK_RENEW;
835 static Eina_Bool __lower_cb(void *data, int type, void *event)
837 Ecore_Wl_Event_Window_Lower *ev;
839 if (!ev) return ECORE_CALLBACK_RENEW;
840 _DBG("ECORE_WL_EVENT_WINDOW_LOWER window id:%u\n", ev->win);
841 appcore_group_lower();
842 return ECORE_CALLBACK_RENEW;
846 static Eina_Bool __visibility_cb(void *data, int type, void *event)
849 Ecore_Wl_Event_Window_Visibility_Change *ev;
852 __update_win((unsigned int)ev->win, 0, ev->fully_obscured);
854 Ecore_X_Event_Window_Visibility_Change *ev;
859 __update_win((unsigned int)ev->win, ev->fully_obscured);
861 bvisibility = __check_visible();
863 _DBG("bvisibility %d, b_active %d", bvisibility, b_active);
865 if (bvisibility && b_active == FALSE) {
866 _DBG(" Go to Resume state\n");
868 __do_app(AE_RESUME, data, NULL);
870 } else if (!bvisibility && b_active == TRUE) {
871 _DBG(" Go to Pasue state \n");
873 __do_app(AE_PAUSE, data, NULL);
875 _DBG(" No change state \n");
877 return ECORE_CALLBACK_RENEW;
883 static Eina_Bool __cmsg_cb(void *data, int type, void *event)
885 struct ui_priv *ui = (struct ui_priv *)data;
886 Ecore_X_Event_Client_Message *e = event;
889 return ECORE_CALLBACK_PASS_ON;
892 return ECORE_CALLBACK_PASS_ON;
894 if (e->message_type == _WM_WINDOW_ROTATION_CHANGE_REQUEST) {
895 if ((ui->wm_rot_supported == 0)
896 || (ui->rot_started == 0)
897 || (ui->rot_cb == NULL)) {
898 return ECORE_CALLBACK_PASS_ON;
902 switch (e->data.l[1]) {
904 rm = APPCORE_RM_PORTRAIT_NORMAL;
907 rm = APPCORE_RM_LANDSCAPE_REVERSE;
910 rm = APPCORE_RM_PORTRAIT_REVERSE;
913 rm = APPCORE_RM_LANDSCAPE_NORMAL;
916 rm = APPCORE_RM_UNKNOWN;
922 if (APPCORE_RM_UNKNOWN != rm)
923 ui->rot_cb((void *)&rm, rm, ui->rot_cb_data);
926 return ECORE_CALLBACK_PASS_ON;
930 static void __add_climsg_cb(struct ui_priv *ui)
935 ecore_event_handler_add(ECORE_WL_EVENT_WINDOW_SHOW, __show_cb, ui);
937 ecore_event_handler_add(ECORE_WL_EVENT_WINDOW_HIDE, __hide_cb, ui);
939 ecore_event_handler_add(ECORE_WL_EVENT_WINDOW_VISIBILITY_CHANGE,
940 __visibility_cb, ui);
942 ecore_event_handler_add(ECORE_WL_EVENT_WINDOW_LOWER,
946 ecore_event_handler_add(ECORE_X_EVENT_WINDOW_SHOW, __show_cb, ui);
948 ecore_event_handler_add(ECORE_X_EVENT_WINDOW_HIDE, __hide_cb, ui);
950 ecore_event_handler_add(ECORE_X_EVENT_WINDOW_VISIBILITY_CHANGE,
951 __visibility_cb, ui);
953 /* Add client message callback for WM_ROTATE */
954 if (!__check_wm_rotation_support()) {
955 ui->hcmsg = ecore_event_handler_add(ECORE_X_EVENT_CLIENT_MESSAGE,
957 ui->wm_rot_supported = 1;
958 appcore_set_wm_rotation(&wm_rotate);
963 static int __before_loop(struct ui_priv *ui, int *argc, char ***argv)
967 #if _APPFW_FEATURE_BACKGROUND_MANAGEMENT
968 struct appcore *ac = NULL;
971 const char *bg_launch;
973 if (argc == NULL || argv == NULL) {
974 _ERR("argc/argv is NULL");
979 #if !(GLIB_CHECK_VERSION(2, 36, 0))
982 elm_init(*argc, *argv);
984 hwacc = getenv("HWACC");
986 _DBG("elm_config_accel_preference_set is not called");
987 } else if (strcmp(hwacc, "USE") == 0) {
988 elm_config_accel_preference_set("hw");
989 _DBG("elm_config_accel_preference_set : hw");
990 } else if (strcmp(hwacc, "NOT_USE") == 0) {
991 elm_config_accel_preference_set("none");
992 _DBG("elm_config_accel_preference_set : none");
994 _DBG("elm_config_accel_preference_set is not called");
997 r = appcore_init(ui->name, &efl_ops, *argc, *argv);
998 _retv_if(r == -1, -1);
1000 #if _APPFW_FEATURE_BACKGROUND_MANAGEMENT
1001 appcore_get_app_core(&ac);
1003 SECURE_LOGD("[__SUSPEND__] appcore initialized, appcore addr: #%x", ac);
1006 b = bundle_import_from_argv(*argc, *argv);
1008 bg_launch = bundle_get_val(b, AUL_SVC_K_BG_LAUNCH);
1009 if (bg_launch && strcmp(bg_launch, "enable") == 0)
1015 LOG(LOG_DEBUG, "LAUNCH", "[%s:Platform:appcore_init:done]", ui->name);
1016 if (ui->ops && ui->ops->create) {
1017 traceBegin(TTRACE_TAG_APPLICATION_MANAGER, "APPCORE:CREATE");
1018 r = ui->ops->create(ui->ops->data);
1019 traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
1021 _ERR("create() return error");
1023 if (ui->ops && ui->ops->terminate) {
1024 traceBegin(TTRACE_TAG_APPLICATION_MANAGER,
1025 "APPCORE:TERMINATE");
1026 ui->ops->terminate(ui->ops->data);
1027 traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
1032 LOG(LOG_DEBUG, "LAUNCH", "[%s:Application:create:done]",
1035 ui->state = AS_CREATED;
1037 __add_climsg_cb(ui);
1042 static void __after_loop(struct ui_priv *ui)
1044 appcore_unset_rotation_cb();
1047 if (ui->state == AS_RUNNING) {
1048 _DBG("[APP %d] PAUSE before termination", _pid);
1049 if (ui->ops && ui->ops->pause) {
1050 traceBegin(TTRACE_TAG_APPLICATION_MANAGER,
1052 ui->ops->pause(ui->ops->data);
1053 traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
1057 if (ui->ops && ui->ops->terminate) {
1058 traceBegin(TTRACE_TAG_APPLICATION_MANAGER, "APPCORE:TERMINATE");
1059 ui->ops->terminate(ui->ops->data);
1060 traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
1063 ui->state = AS_DYING;
1066 ecore_event_handler_del(ui->hshow);
1068 ecore_event_handler_del(ui->hhide);
1070 ecore_event_handler_del(ui->hvchange);
1071 #if defined(WAYLAND)
1073 ecore_event_handler_del(ui->hlower);
1076 __appcore_timer_del(ui);
1078 /* Check the launchpad-loader case */
1079 while (elm_shutdown() > 0);
1082 static int __set_data(struct ui_priv *ui, const char *name,
1083 struct appcore_ops *ops)
1086 _ERR("Mainloop already started");
1087 errno = EINPROGRESS;
1091 if (name == NULL || name[0] == '\0') {
1092 _ERR("Invalid name");
1098 _ERR("ops is NULL");
1103 ui->name = strdup(name);
1104 _retv_if(ui->name == NULL, -1);
1107 ui->mfcb = __appcore_efl_memory_flush_cb;
1111 ui->wm_rot_supported = 0;
1112 ui->rot_started = 0;
1114 ui->rot_cb_data = NULL;
1115 ui->rot_mode = APPCORE_RM_UNKNOWN;
1117 #ifdef _APPFW_FEATURE_BACKGROUND_MANAGEMENT
1118 ui->app_core = NULL;
1119 ui->prepare_to_suspend = __appcore_efl_prepare_to_suspend;
1120 ui->exit_from_suspend = __appcore_efl_exit_from_suspend;
1126 static void __unset_data(struct ui_priv *ui)
1129 free((void *)ui->name);
1131 memset(ui, 0, sizeof(struct ui_priv));
1136 static int __wm_set_rotation_cb(int (*cb) (void *event_info, enum appcore_rm, void *), void *data)
1143 if ((priv.wm_rot_supported) && (0 == priv.rot_started))
1144 __set_wm_rotation_support(0, 1);
1147 priv.rot_cb_data = data;
1148 priv.rot_started = 1;
1153 static int __wm_unset_rotation_cb(void)
1155 if ((priv.wm_rot_supported) && (1 == priv.rot_started))
1156 __set_wm_rotation_support(0, 0);
1159 priv.rot_cb_data = NULL;
1160 priv.rot_started = 0;
1165 static int __wm_get_rotation_state(enum appcore_rm *curr)
1172 *curr = priv.rot_mode;
1177 static int __wm_pause_rotation_cb(void)
1179 if ((priv.rot_started == 1) && (priv.wm_rot_supported))
1180 __set_wm_rotation_support(0, 0);
1182 priv.rot_started = 0;
1187 static int __wm_resume_rotation_cb(void)
1189 if ((priv.rot_started == 0) && (priv.wm_rot_supported))
1190 __set_wm_rotation_support(0, 1);
1192 priv.rot_started = 1;
1197 static struct ui_wm_rotate wm_rotate = {
1198 __wm_set_rotation_cb,
1199 __wm_unset_rotation_cb,
1200 __wm_get_rotation_state,
1201 __wm_pause_rotation_cb,
1202 __wm_resume_rotation_cb
1206 EXPORT_API int appcore_efl_init(const char *name, int *argc, char ***argv,
1207 struct appcore_ops *ops)
1211 LOG(LOG_DEBUG, "LAUNCH", "[%s:Application:main:done]", name);
1213 r = __set_data(&priv, name, ops);
1214 _retv_if(r == -1, -1);
1216 r = __before_loop(&priv, argc, argv);
1218 aul_status_update(STATUS_DYING);
1219 __unset_data(&priv);
1226 EXPORT_API void appcore_efl_fini(void)
1228 aul_status_update(STATUS_DYING);
1230 __after_loop(&priv);
1232 __unset_data(&priv);
1235 EXPORT_API int appcore_efl_main(const char *name, int *argc, char ***argv,
1236 struct appcore_ops *ops)
1240 r = appcore_efl_init(name, argc, argv, ops);
1241 _retv_if(r == -1, -1);
1250 EXPORT_API int appcore_set_system_resource_reclaiming(bool enable)
1252 resource_reclaiming = enable;
1257 EXPORT_API int appcore_set_app_state(int state)
1266 EXPORT_API int appcore_set_preinit_window_name(const char *win_name)
1269 void *preinit_window = NULL;
1270 const Evas *e = NULL;
1273 _ERR("invalid parameter");
1277 preinit_window = elm_win_precreated_object_get();
1278 if (!preinit_window) {
1279 _ERR("Failed to get preinit window");
1283 e = evas_object_evas_get((const Evas_Object *)preinit_window);
1285 Ecore_Evas *ee = ecore_evas_ecore_evas_get(e);
1287 ecore_evas_name_class_set(ee, win_name, win_name);
1295 EXPORT_API unsigned int appcore_get_main_window(void)
1297 struct win_node *entry = NULL;
1299 if (g_winnode_list != NULL) {
1300 entry = g_winnode_list->data;
1301 return (unsigned int) entry->win;
1307 #if defined(WAYLAND)
1308 EXPORT_API unsigned int appcore_get_main_surface(void)
1310 struct win_node *entry = NULL;
1312 if (g_winnode_list != NULL) {
1313 entry = g_winnode_list->data;
1314 return (unsigned int) entry->surf;