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 first_launch = FALSE;
439 _INFO("[APP %d] App already running, raise the window", _pid);
441 bg_launch = bundle_get_val(b, AUL_SVC_K_BG_LAUNCH);
442 if (!bg_launch || strcmp(bg_launch, "enable"))
446 x_raise_win(getpid());
451 LOG(LOG_DEBUG, "LAUNCH", "[%s:Application:reset:done]",
455 if (ui->state == AS_RUNNING) {
456 _DBG("[APP %d] PAUSE", _pid);
457 if (ui->ops->pause) {
458 traceBegin(TTRACE_TAG_APPLICATION_MANAGER,
460 r = ui->ops->pause(ui->ops->data);
461 traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
463 ui->state = AS_PAUSED;
464 if (r >= 0 && resource_reclaiming == TRUE)
465 __appcore_timer_add(ui);
466 #ifdef _APPFW_FEATURE_BACKGROUND_MANAGEMENT
467 else if (r >= 0 && resource_reclaiming == FALSE
468 && ui->prepare_to_suspend) {
469 _DBG("[__SUSPEND__] pause case");
470 ui->prepare_to_suspend(ui);
474 /* TODO : rotation stop */
475 /* r = appcore_pause_rotation_cb(); */
476 aul_status_update(STATUS_BG);
479 LOG(LOG_DEBUG, "LAUNCH", "[%s:Application:resume:start]",
481 #ifdef _APPFW_FEATURE_BACKGROUND_MANAGEMENT
482 if (ui->exit_from_suspend) {
483 _DBG("[__SUSPEND__] resume case");
484 ui->exit_from_suspend(ui);
488 if (ui->state == AS_PAUSED || ui->state == AS_CREATED) {
489 _DBG("[APP %d] RESUME", _pid);
491 if (ui->state == AS_CREATED) {
492 bundle_free(ui->pending_data);
493 ui->pending_data = NULL;
496 if (ui->ops->resume) {
497 traceBegin(TTRACE_TAG_APPLICATION_MANAGER,
499 ui->ops->resume(ui->ops->data);
500 traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
502 ui->state = AS_RUNNING;
505 aul_app_group_activate_below(ui->below_app);
507 ui->below_app = NULL;
510 /*TODO : rotation start*/
511 /* r = appcore_resume_rotation_cb(); */
512 LOG(LOG_DEBUG, "LAUNCH", "[%s:Application:resume:done]",
514 LOG(LOG_DEBUG, "LAUNCH", "[%s:Application:Launching:done]",
516 aul_status_update(STATUS_VISIBLE);
518 case AE_TERMINATE_BGAPP:
519 if (ui->state == AS_PAUSED) {
520 _DBG("[APP %d] is paused. TERMINATE", _pid);
521 ui->state = AS_DYING;
522 aul_status_update(STATUS_DYING);
524 } else if (ui->state == AS_RUNNING) {
525 _DBG("[APP %d] is running.", _pid);
527 _DBG("[APP %d] is another state", _pid);
536 static struct ui_ops efl_ops = {
541 static bool __check_visible(void)
544 struct win_node *entry = NULL;
546 _DBG("[EVENT_TEST][EVENT] __check_visible\n");
548 for (iter = g_winnode_list; iter != NULL; iter = g_slist_next(iter)) {
550 _DBG("win : %x obscured : %d\n", entry->win, entry->bfobscured);
551 if (entry->bfobscured == FALSE)
558 static GSList *__find_win(unsigned int win)
563 for (iter = g_winnode_list; iter; iter = g_slist_next(iter)) {
565 if (t && t->win == win)
573 static bool __add_win(unsigned int win)
578 _DBG("[EVENT_TEST][EVENT] __add_win WIN:%x\n", win);
583 _DBG("[EVENT_TEST][EVENT] ERROR There is already window : %x \n", win);
587 t = calloc(1, sizeof(struct win_node));
592 t->bfobscured = FALSE;
594 g_winnode_list = g_slist_append(g_winnode_list, t);
598 #elif defined(WAYLAND)
599 static bool __add_win(unsigned int win, unsigned int surf)
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));
619 t->bfobscured = FALSE;
621 g_winnode_list = g_slist_append(g_winnode_list, t);
627 static bool __delete_win(unsigned int win)
634 _DBG("[EVENT_TEST][EVENT] ERROR There is no window : %x \n",
640 g_winnode_list = g_slist_delete_link(g_winnode_list, f);
646 static bool __update_win(unsigned int win, bool bfobscured)
651 _DBG("[EVENT_TEST][EVENT] __update_win WIN:%x fully_obscured %d\n", win,
657 _DBG("[EVENT_TEST][EVENT] ERROR There is no window : %x \n", win);
661 g_winnode_list = g_slist_remove_link(g_winnode_list, f);
663 t = (struct win_node *)f->data;
665 t->bfobscured = bfobscured;
667 g_winnode_list = g_slist_concat(g_winnode_list, f);
671 #elif defined(WAYLAND)
672 static bool __update_win(unsigned int win, unsigned int surf, 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 g_winnode_list = g_slist_remove_link(g_winnode_list, f);
689 t = (struct win_node *)f->data;
693 t->bfobscured = bfobscured;
695 g_winnode_list = g_slist_concat(g_winnode_list, f);
703 static Ecore_X_Atom _WM_WINDOW_ROTATION_SUPPORTED = 0;
704 static Ecore_X_Atom _WM_WINDOW_ROTATION_CHANGE_REQUEST = 0;
706 static int __check_wm_rotation_support(void)
708 _DBG("Disable window manager rotation");
711 Ecore_X_Window root, win, win2;
714 if (!_WM_WINDOW_ROTATION_SUPPORTED) {
715 _WM_WINDOW_ROTATION_SUPPORTED =
716 ecore_x_atom_get("_E_WINDOW_ROTATION_SUPPORTED");
719 if (!_WM_WINDOW_ROTATION_CHANGE_REQUEST) {
720 _WM_WINDOW_ROTATION_CHANGE_REQUEST =
721 ecore_x_atom_get("_E_WINDOW_ROTATION_CHANGE_REQUEST");
724 root = ecore_x_window_root_first_get();
725 ret = ecore_x_window_prop_xid_get(root,
726 _WM_WINDOW_ROTATION_SUPPORTED,
729 if ((ret == 1) && (win)) {
730 ret = ecore_x_window_prop_xid_get(win,
731 _WM_WINDOW_ROTATION_SUPPORTED,
734 if ((ret == 1) && (win2 == win))
741 static void __set_wm_rotation_support(unsigned int win, unsigned int set)
744 struct win_node *entry = NULL;
747 for (iter = g_winnode_list; iter != NULL; iter = g_slist_next(iter)) {
750 ecore_x_window_prop_card32_set(entry->win,
751 _WM_WINDOW_ROTATION_SUPPORTED,
756 ecore_x_window_prop_card32_set(win,
757 _WM_WINDOW_ROTATION_SUPPORTED,
763 static Eina_Bool __show_cb(void *data, int type, void *event)
766 Ecore_Wl_Event_Window_Show *ev;
769 if (ev->parent_win != 0) {
770 /* This is child window. Skip!!! */
771 return ECORE_CALLBACK_PASS_ON;
774 _DBG("[EVENT_TEST][EVENT] GET SHOW EVENT!!!. WIN:%x, %d\n", ev->win, ev->data[0]);
776 if (!__find_win((unsigned int)ev->win))
777 __add_win((unsigned int)ev->win, (unsigned int)ev->data[0]);
779 __update_win((unsigned int)ev->win, (unsigned int)ev->data[0], FALSE);
782 Ecore_X_Event_Window_Show *ev;
786 _DBG("[EVENT_TEST][EVENT] GET SHOW EVENT!!!. WIN:%x\n", ev->win);
788 if (!__find_win((unsigned int)ev->win)) {
790 if ((priv.wm_rot_supported) && (1 == priv.rot_started))
791 __set_wm_rotation_support(ev->win, 1);
792 __add_win((unsigned int)ev->win);
794 __update_win((unsigned int)ev->win, FALSE);
798 appcore_group_attach();
799 return ECORE_CALLBACK_RENEW;
802 static Eina_Bool __hide_cb(void *data, int type, void *event)
805 Ecore_Wl_Event_Window_Hide *ev;
807 Ecore_X_Event_Window_Hide *ev;
813 _DBG("[EVENT_TEST][EVENT] GET HIDE EVENT!!!. WIN:%x\n", ev->win);
815 if (__find_win((unsigned int)ev->win)) {
816 __delete_win((unsigned int)ev->win);
817 bvisibility = __check_visible();
818 if (!bvisibility && b_active == TRUE) {
819 _DBG(" Go to Pasue state \n");
821 __do_app(AE_PAUSE, data, NULL);
825 return ECORE_CALLBACK_RENEW;
829 static Eina_Bool __lower_cb(void *data, int type, void *event)
831 Ecore_Wl_Event_Window_Lower *ev;
833 if (!ev) return ECORE_CALLBACK_RENEW;
834 _DBG("ECORE_WL_EVENT_WINDOW_LOWER window id:%u\n", ev->win);
835 appcore_group_lower();
836 return ECORE_CALLBACK_RENEW;
840 static Eina_Bool __visibility_cb(void *data, int type, void *event)
843 Ecore_Wl_Event_Window_Visibility_Change *ev;
846 __update_win((unsigned int)ev->win, 0, ev->fully_obscured);
848 Ecore_X_Event_Window_Visibility_Change *ev;
853 __update_win((unsigned int)ev->win, ev->fully_obscured);
855 bvisibility = __check_visible();
857 _DBG("bvisibility %d, b_active %d", bvisibility, b_active);
859 if (bvisibility && b_active == FALSE) {
860 _DBG(" Go to Resume state\n");
862 __do_app(AE_RESUME, data, NULL);
864 } else if (!bvisibility && b_active == TRUE) {
865 _DBG(" Go to Pasue state \n");
867 __do_app(AE_PAUSE, data, NULL);
869 _DBG(" No change state \n");
871 return ECORE_CALLBACK_RENEW;
877 static Eina_Bool __cmsg_cb(void *data, int type, void *event)
879 struct ui_priv *ui = (struct ui_priv *)data;
880 Ecore_X_Event_Client_Message *e = event;
883 return ECORE_CALLBACK_PASS_ON;
886 return ECORE_CALLBACK_PASS_ON;
888 if (e->message_type == _WM_WINDOW_ROTATION_CHANGE_REQUEST) {
889 if ((ui->wm_rot_supported == 0)
890 || (ui->rot_started == 0)
891 || (ui->rot_cb == NULL)) {
892 return ECORE_CALLBACK_PASS_ON;
896 switch (e->data.l[1]) {
898 rm = APPCORE_RM_PORTRAIT_NORMAL;
901 rm = APPCORE_RM_LANDSCAPE_REVERSE;
904 rm = APPCORE_RM_PORTRAIT_REVERSE;
907 rm = APPCORE_RM_LANDSCAPE_NORMAL;
910 rm = APPCORE_RM_UNKNOWN;
916 if (APPCORE_RM_UNKNOWN != rm)
917 ui->rot_cb((void *)&rm, rm, ui->rot_cb_data);
920 return ECORE_CALLBACK_PASS_ON;
924 static void __add_climsg_cb(struct ui_priv *ui)
929 ecore_event_handler_add(ECORE_WL_EVENT_WINDOW_SHOW, __show_cb, ui);
931 ecore_event_handler_add(ECORE_WL_EVENT_WINDOW_HIDE, __hide_cb, ui);
933 ecore_event_handler_add(ECORE_WL_EVENT_WINDOW_VISIBILITY_CHANGE,
934 __visibility_cb, ui);
936 ecore_event_handler_add(ECORE_WL_EVENT_WINDOW_LOWER,
940 ecore_event_handler_add(ECORE_X_EVENT_WINDOW_SHOW, __show_cb, ui);
942 ecore_event_handler_add(ECORE_X_EVENT_WINDOW_HIDE, __hide_cb, ui);
944 ecore_event_handler_add(ECORE_X_EVENT_WINDOW_VISIBILITY_CHANGE,
945 __visibility_cb, ui);
947 /* Add client message callback for WM_ROTATE */
948 if (!__check_wm_rotation_support()) {
949 ui->hcmsg = ecore_event_handler_add(ECORE_X_EVENT_CLIENT_MESSAGE,
951 ui->wm_rot_supported = 1;
952 appcore_set_wm_rotation(&wm_rotate);
957 static int __before_loop(struct ui_priv *ui, int *argc, char ***argv)
961 #if _APPFW_FEATURE_BACKGROUND_MANAGEMENT
962 struct appcore *ac = NULL;
965 const char *bg_launch;
967 if (argc == NULL || argv == NULL) {
968 _ERR("argc/argv is NULL");
973 #if !(GLIB_CHECK_VERSION(2, 36, 0))
976 elm_init(*argc, *argv);
978 hwacc = getenv("HWACC");
980 _DBG("elm_config_accel_preference_set is not called");
981 } else if (strcmp(hwacc, "USE") == 0) {
982 elm_config_accel_preference_set("hw");
983 _DBG("elm_config_accel_preference_set : hw");
984 } else if (strcmp(hwacc, "NOT_USE") == 0) {
985 elm_config_accel_preference_set("none");
986 _DBG("elm_config_accel_preference_set : none");
988 _DBG("elm_config_accel_preference_set is not called");
991 r = appcore_init(ui->name, &efl_ops, *argc, *argv);
992 _retv_if(r == -1, -1);
994 #if _APPFW_FEATURE_BACKGROUND_MANAGEMENT
995 appcore_get_app_core(&ac);
997 SECURE_LOGD("[__SUSPEND__] appcore initialized, appcore addr: #%x", ac);
1000 b = bundle_import_from_argv(*argc, *argv);
1002 bg_launch = bundle_get_val(b, AUL_SVC_K_BG_LAUNCH);
1003 if (bg_launch && strcmp(bg_launch, "enable") == 0)
1009 LOG(LOG_DEBUG, "LAUNCH", "[%s:Platform:appcore_init:done]", ui->name);
1010 if (ui->ops && ui->ops->create) {
1011 traceBegin(TTRACE_TAG_APPLICATION_MANAGER, "APPCORE:CREATE");
1012 r = ui->ops->create(ui->ops->data);
1013 traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
1015 _ERR("create() return error");
1017 if (ui->ops && ui->ops->terminate) {
1018 traceBegin(TTRACE_TAG_APPLICATION_MANAGER,
1019 "APPCORE:TERMINATE");
1020 ui->ops->terminate(ui->ops->data);
1021 traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
1026 LOG(LOG_DEBUG, "LAUNCH", "[%s:Application:create:done]",
1029 ui->state = AS_CREATED;
1031 __add_climsg_cb(ui);
1036 static void __after_loop(struct ui_priv *ui)
1038 appcore_unset_rotation_cb();
1041 if (ui->state == AS_RUNNING) {
1042 _DBG("[APP %d] PAUSE before termination", _pid);
1043 if (ui->ops && ui->ops->pause) {
1044 traceBegin(TTRACE_TAG_APPLICATION_MANAGER,
1046 ui->ops->pause(ui->ops->data);
1047 traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
1051 if (ui->ops && ui->ops->terminate) {
1052 traceBegin(TTRACE_TAG_APPLICATION_MANAGER, "APPCORE:TERMINATE");
1053 ui->ops->terminate(ui->ops->data);
1054 traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
1057 ui->state = AS_DYING;
1060 ecore_event_handler_del(ui->hshow);
1062 ecore_event_handler_del(ui->hhide);
1064 ecore_event_handler_del(ui->hvchange);
1065 #if defined(WAYLAND)
1067 ecore_event_handler_del(ui->hlower);
1070 __appcore_timer_del(ui);
1075 static int __set_data(struct ui_priv *ui, const char *name,
1076 struct appcore_ops *ops)
1079 _ERR("Mainloop already started");
1080 errno = EINPROGRESS;
1084 if (name == NULL || name[0] == '\0') {
1085 _ERR("Invalid name");
1091 _ERR("ops is NULL");
1096 ui->name = strdup(name);
1097 _retv_if(ui->name == NULL, -1);
1100 ui->mfcb = __appcore_efl_memory_flush_cb;
1104 ui->wm_rot_supported = 0;
1105 ui->rot_started = 0;
1107 ui->rot_cb_data = NULL;
1108 ui->rot_mode = APPCORE_RM_UNKNOWN;
1110 #ifdef _APPFW_FEATURE_BACKGROUND_MANAGEMENT
1111 ui->app_core = NULL;
1112 ui->prepare_to_suspend = __appcore_efl_prepare_to_suspend;
1113 ui->exit_from_suspend = __appcore_efl_exit_from_suspend;
1119 static void __unset_data(struct ui_priv *ui)
1122 free((void *)ui->name);
1124 memset(ui, 0, sizeof(struct ui_priv));
1129 static int __wm_set_rotation_cb(int (*cb) (void *event_info, enum appcore_rm, void *), void *data)
1136 if ((priv.wm_rot_supported) && (0 == priv.rot_started))
1137 __set_wm_rotation_support(0, 1);
1140 priv.rot_cb_data = data;
1141 priv.rot_started = 1;
1146 static int __wm_unset_rotation_cb(void)
1148 if ((priv.wm_rot_supported) && (1 == priv.rot_started))
1149 __set_wm_rotation_support(0, 0);
1152 priv.rot_cb_data = NULL;
1153 priv.rot_started = 0;
1158 static int __wm_get_rotation_state(enum appcore_rm *curr)
1165 *curr = priv.rot_mode;
1170 static int __wm_pause_rotation_cb(void)
1172 if ((priv.rot_started == 1) && (priv.wm_rot_supported))
1173 __set_wm_rotation_support(0, 0);
1175 priv.rot_started = 0;
1180 static int __wm_resume_rotation_cb(void)
1182 if ((priv.rot_started == 0) && (priv.wm_rot_supported))
1183 __set_wm_rotation_support(0, 1);
1185 priv.rot_started = 1;
1190 static struct ui_wm_rotate wm_rotate = {
1191 __wm_set_rotation_cb,
1192 __wm_unset_rotation_cb,
1193 __wm_get_rotation_state,
1194 __wm_pause_rotation_cb,
1195 __wm_resume_rotation_cb
1199 EXPORT_API int appcore_efl_init(const char *name, int *argc, char ***argv,
1200 struct appcore_ops *ops)
1204 LOG(LOG_DEBUG, "LAUNCH", "[%s:Application:main:done]", name);
1206 r = __set_data(&priv, name, ops);
1207 _retv_if(r == -1, -1);
1209 r = __before_loop(&priv, argc, argv);
1211 aul_status_update(STATUS_DYING);
1212 __unset_data(&priv);
1219 EXPORT_API void appcore_efl_fini(void)
1221 aul_status_update(STATUS_DYING);
1223 __after_loop(&priv);
1225 __unset_data(&priv);
1228 EXPORT_API int appcore_efl_main(const char *name, int *argc, char ***argv,
1229 struct appcore_ops *ops)
1233 r = appcore_efl_init(name, argc, argv, ops);
1234 _retv_if(r == -1, -1);
1243 EXPORT_API int appcore_set_system_resource_reclaiming(bool enable)
1245 resource_reclaiming = enable;
1250 EXPORT_API int appcore_set_app_state(int state)
1259 EXPORT_API int appcore_set_preinit_window_name(const char *win_name)
1262 void *preinit_window = NULL;
1263 const Evas *e = NULL;
1266 _ERR("invalid parameter");
1270 preinit_window = elm_win_precreated_object_get();
1271 if (!preinit_window) {
1272 _ERR("Failed to get preinit window");
1276 e = evas_object_evas_get((const Evas_Object *)preinit_window);
1278 Ecore_Evas *ee = ecore_evas_ecore_evas_get(e);
1280 ecore_evas_name_class_set(ee, win_name, win_name);
1288 EXPORT_API unsigned int appcore_get_main_window(void)
1290 struct win_node *entry = NULL;
1292 if (g_winnode_list != NULL) {
1293 entry = g_winnode_list->data;
1294 return (unsigned int) entry->win;
1300 #if defined(WAYLAND)
1301 EXPORT_API unsigned int appcore_get_main_surface(void)
1303 struct win_node *entry = NULL;
1305 if (g_winnode_list != NULL) {
1306 entry = g_winnode_list->data;
1307 return (unsigned int) entry->surf;