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 g_winnode_list = g_slist_remove_link(g_winnode_list, f);
689 t = (struct win_node *)f->data;
691 t->bfobscured = bfobscured;
693 g_winnode_list = g_slist_concat(g_winnode_list, f);
697 #elif defined(WAYLAND)
698 static bool __update_win(unsigned int win, unsigned int surf, bool bfobscured)
703 _DBG("[EVENT_TEST][EVENT] __update_win WIN:%x fully_obscured %d\n", win,
709 _DBG("[EVENT_TEST][EVENT] ERROR There is no window : %x \n", win);
713 g_winnode_list = g_slist_remove_link(g_winnode_list, f);
715 t = (struct win_node *)f->data;
719 t->bfobscured = bfobscured;
721 g_winnode_list = g_slist_concat(g_winnode_list, f);
729 static Ecore_X_Atom _WM_WINDOW_ROTATION_SUPPORTED = 0;
730 static Ecore_X_Atom _WM_WINDOW_ROTATION_CHANGE_REQUEST = 0;
732 static int __check_wm_rotation_support(void)
734 _DBG("Disable window manager rotation");
737 Ecore_X_Window root, win, win2;
740 if (!_WM_WINDOW_ROTATION_SUPPORTED) {
741 _WM_WINDOW_ROTATION_SUPPORTED =
742 ecore_x_atom_get("_E_WINDOW_ROTATION_SUPPORTED");
745 if (!_WM_WINDOW_ROTATION_CHANGE_REQUEST) {
746 _WM_WINDOW_ROTATION_CHANGE_REQUEST =
747 ecore_x_atom_get("_E_WINDOW_ROTATION_CHANGE_REQUEST");
750 root = ecore_x_window_root_first_get();
751 ret = ecore_x_window_prop_xid_get(root,
752 _WM_WINDOW_ROTATION_SUPPORTED,
755 if ((ret == 1) && (win)) {
756 ret = ecore_x_window_prop_xid_get(win,
757 _WM_WINDOW_ROTATION_SUPPORTED,
760 if ((ret == 1) && (win2 == win))
767 static void __set_wm_rotation_support(unsigned int win, unsigned int set)
770 struct win_node *entry = NULL;
773 for (iter = g_winnode_list; iter != NULL; iter = g_slist_next(iter)) {
776 ecore_x_window_prop_card32_set(entry->win,
777 _WM_WINDOW_ROTATION_SUPPORTED,
782 ecore_x_window_prop_card32_set(win,
783 _WM_WINDOW_ROTATION_SUPPORTED,
789 static Eina_Bool __show_cb(void *data, int type, void *event)
792 Ecore_Wl_Event_Window_Show *ev;
795 if (ev->parent_win != 0) {
796 /* This is child window. Skip!!! */
797 return ECORE_CALLBACK_PASS_ON;
800 _DBG("[EVENT_TEST][EVENT] GET SHOW EVENT!!!. WIN:%x, %d\n", ev->win, ev->data[0]);
802 if (!__find_win((unsigned int)ev->win))
803 __add_win((unsigned int)ev->win, (unsigned int)ev->data[0]);
805 __update_win((unsigned int)ev->win, (unsigned int)ev->data[0], FALSE);
808 Ecore_X_Event_Window_Show *ev;
812 _DBG("[EVENT_TEST][EVENT] GET SHOW EVENT!!!. WIN:%x\n", ev->win);
814 if (!__find_win((unsigned int)ev->win)) {
816 if ((priv.wm_rot_supported) && (1 == priv.rot_started))
817 __set_wm_rotation_support(ev->win, 1);
818 __add_win((unsigned int)ev->win);
820 __update_win((unsigned int)ev->win, FALSE);
824 appcore_group_attach();
825 return ECORE_CALLBACK_RENEW;
828 static Eina_Bool __hide_cb(void *data, int type, void *event)
831 Ecore_Wl_Event_Window_Hide *ev;
833 Ecore_X_Event_Window_Hide *ev;
839 _DBG("[EVENT_TEST][EVENT] GET HIDE EVENT!!!. WIN:%x\n", ev->win);
841 if (__find_win((unsigned int)ev->win)) {
842 __delete_win((unsigned int)ev->win);
843 bvisibility = __check_visible();
844 if (!bvisibility && b_active == TRUE) {
845 _DBG(" Go to Pasue state \n");
847 __do_app(AE_PAUSE, data, NULL);
851 return ECORE_CALLBACK_RENEW;
855 static Eina_Bool __lower_cb(void *data, int type, void *event)
857 Ecore_Wl_Event_Window_Lower *ev;
859 if (!ev) return ECORE_CALLBACK_RENEW;
860 _DBG("ECORE_WL_EVENT_WINDOW_LOWER window id:%u\n", ev->win);
861 appcore_group_lower();
862 return ECORE_CALLBACK_RENEW;
866 static Eina_Bool __visibility_cb(void *data, int type, void *event)
869 Ecore_Wl_Event_Window_Visibility_Change *ev;
872 __update_win((unsigned int)ev->win, 0, ev->fully_obscured);
874 Ecore_X_Event_Window_Visibility_Change *ev;
879 __update_win((unsigned int)ev->win, ev->fully_obscured);
881 bvisibility = __check_visible();
883 _DBG("bvisibility %d, b_active %d", bvisibility, b_active);
885 if (bvisibility && b_active == FALSE) {
886 _DBG(" Go to Resume state\n");
888 __do_app(AE_RESUME, data, NULL);
890 } else if (!bvisibility && b_active == TRUE) {
891 _DBG(" Go to Pasue state \n");
893 __do_app(AE_PAUSE, data, NULL);
895 _DBG(" No change state \n");
897 return ECORE_CALLBACK_RENEW;
903 static Eina_Bool __cmsg_cb(void *data, int type, void *event)
905 struct ui_priv *ui = (struct ui_priv *)data;
906 Ecore_X_Event_Client_Message *e = event;
909 return ECORE_CALLBACK_PASS_ON;
912 return ECORE_CALLBACK_PASS_ON;
914 if (e->message_type == _WM_WINDOW_ROTATION_CHANGE_REQUEST) {
915 if ((ui->wm_rot_supported == 0)
916 || (ui->rot_started == 0)
917 || (ui->rot_cb == NULL)) {
918 return ECORE_CALLBACK_PASS_ON;
922 switch (e->data.l[1]) {
924 rm = APPCORE_RM_PORTRAIT_NORMAL;
927 rm = APPCORE_RM_LANDSCAPE_REVERSE;
930 rm = APPCORE_RM_PORTRAIT_REVERSE;
933 rm = APPCORE_RM_LANDSCAPE_NORMAL;
936 rm = APPCORE_RM_UNKNOWN;
942 if (APPCORE_RM_UNKNOWN != rm)
943 ui->rot_cb((void *)&rm, rm, ui->rot_cb_data);
946 return ECORE_CALLBACK_PASS_ON;
950 static void __add_climsg_cb(struct ui_priv *ui)
955 ecore_event_handler_add(ECORE_WL_EVENT_WINDOW_SHOW, __show_cb, ui);
957 ecore_event_handler_add(ECORE_WL_EVENT_WINDOW_HIDE, __hide_cb, ui);
959 ecore_event_handler_add(ECORE_WL_EVENT_WINDOW_VISIBILITY_CHANGE,
960 __visibility_cb, ui);
962 ecore_event_handler_add(ECORE_WL_EVENT_WINDOW_LOWER,
966 ecore_event_handler_add(ECORE_X_EVENT_WINDOW_SHOW, __show_cb, ui);
968 ecore_event_handler_add(ECORE_X_EVENT_WINDOW_HIDE, __hide_cb, ui);
970 ecore_event_handler_add(ECORE_X_EVENT_WINDOW_VISIBILITY_CHANGE,
971 __visibility_cb, ui);
973 /* Add client message callback for WM_ROTATE */
974 if (!__check_wm_rotation_support()) {
975 ui->hcmsg = ecore_event_handler_add(ECORE_X_EVENT_CLIENT_MESSAGE,
977 ui->wm_rot_supported = 1;
978 appcore_set_wm_rotation(&wm_rotate);
983 static int __before_loop(struct ui_priv *ui, int *argc, char ***argv)
987 #if _APPFW_FEATURE_BACKGROUND_MANAGEMENT
988 struct appcore *ac = NULL;
991 const char *bg_launch;
993 if (argc == NULL || argv == NULL) {
994 _ERR("argc/argv is NULL");
999 #if !(GLIB_CHECK_VERSION(2, 36, 0))
1002 elm_init(*argc, *argv);
1004 hwacc = getenv("HWACC");
1005 if (hwacc == NULL) {
1006 _DBG("elm_config_accel_preference_set is not called");
1007 } else if (strcmp(hwacc, "USE") == 0) {
1008 elm_config_accel_preference_set("hw");
1009 _DBG("elm_config_accel_preference_set : hw");
1010 } else if (strcmp(hwacc, "NOT_USE") == 0) {
1011 elm_config_accel_preference_set("none");
1012 _DBG("elm_config_accel_preference_set : none");
1014 _DBG("elm_config_accel_preference_set is not called");
1017 r = appcore_init(ui->name, &efl_ops, *argc, *argv);
1018 _retv_if(r == -1, -1);
1020 #if _APPFW_FEATURE_BACKGROUND_MANAGEMENT
1021 appcore_get_app_core(&ac);
1023 SECURE_LOGD("[__SUSPEND__] appcore initialized, appcore addr: #%x", ac);
1026 b = bundle_import_from_argv(*argc, *argv);
1028 bg_launch = bundle_get_val(b, AUL_SVC_K_BG_LAUNCH);
1029 if (bg_launch && strcmp(bg_launch, "enable") == 0)
1035 LOG(LOG_DEBUG, "LAUNCH", "[%s:Platform:appcore_init:done]", ui->name);
1036 if (ui->ops && ui->ops->create) {
1037 traceBegin(TTRACE_TAG_APPLICATION_MANAGER, "APPCORE:CREATE");
1038 r = ui->ops->create(ui->ops->data);
1039 traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
1041 _ERR("create() return error");
1043 if (ui->ops && ui->ops->terminate) {
1044 traceBegin(TTRACE_TAG_APPLICATION_MANAGER,
1045 "APPCORE:TERMINATE");
1046 ui->ops->terminate(ui->ops->data);
1047 traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
1052 LOG(LOG_DEBUG, "LAUNCH", "[%s:Application:create:done]",
1055 ui->state = AS_CREATED;
1057 __add_climsg_cb(ui);
1062 static void __after_loop(struct ui_priv *ui)
1064 appcore_unset_rotation_cb();
1067 if (ui->state == AS_RUNNING) {
1068 _DBG("[APP %d] PAUSE before termination", _pid);
1069 if (ui->ops && ui->ops->pause) {
1070 traceBegin(TTRACE_TAG_APPLICATION_MANAGER,
1072 ui->ops->pause(ui->ops->data);
1073 traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
1077 if (ui->ops && ui->ops->terminate) {
1078 traceBegin(TTRACE_TAG_APPLICATION_MANAGER, "APPCORE:TERMINATE");
1079 ui->ops->terminate(ui->ops->data);
1080 traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
1083 ui->state = AS_DYING;
1086 ecore_event_handler_del(ui->hshow);
1088 ecore_event_handler_del(ui->hhide);
1090 ecore_event_handler_del(ui->hvchange);
1091 #if defined(WAYLAND)
1093 ecore_event_handler_del(ui->hlower);
1096 __appcore_timer_del(ui);
1100 /* Check loader case */
1101 if (getenv("AUL_LOADER_INIT")) {
1102 unsetenv("AUL_LOADER_INIT");
1107 static int __set_data(struct ui_priv *ui, const char *name,
1108 struct appcore_ops *ops)
1111 _ERR("Mainloop already started");
1112 errno = EINPROGRESS;
1116 if (name == NULL || name[0] == '\0') {
1117 _ERR("Invalid name");
1123 _ERR("ops is NULL");
1128 ui->name = strdup(name);
1129 _retv_if(ui->name == NULL, -1);
1132 ui->mfcb = __appcore_efl_memory_flush_cb;
1136 ui->wm_rot_supported = 0;
1137 ui->rot_started = 0;
1139 ui->rot_cb_data = NULL;
1140 ui->rot_mode = APPCORE_RM_UNKNOWN;
1142 #ifdef _APPFW_FEATURE_BACKGROUND_MANAGEMENT
1143 ui->app_core = NULL;
1144 ui->prepare_to_suspend = __appcore_efl_prepare_to_suspend;
1145 ui->exit_from_suspend = __appcore_efl_exit_from_suspend;
1151 static void __unset_data(struct ui_priv *ui)
1154 free((void *)ui->name);
1156 memset(ui, 0, sizeof(struct ui_priv));
1161 static int __wm_set_rotation_cb(int (*cb) (void *event_info, enum appcore_rm, void *), void *data)
1168 if ((priv.wm_rot_supported) && (0 == priv.rot_started))
1169 __set_wm_rotation_support(0, 1);
1172 priv.rot_cb_data = data;
1173 priv.rot_started = 1;
1178 static int __wm_unset_rotation_cb(void)
1180 if ((priv.wm_rot_supported) && (1 == priv.rot_started))
1181 __set_wm_rotation_support(0, 0);
1184 priv.rot_cb_data = NULL;
1185 priv.rot_started = 0;
1190 static int __wm_get_rotation_state(enum appcore_rm *curr)
1197 *curr = priv.rot_mode;
1202 static int __wm_pause_rotation_cb(void)
1204 if ((priv.rot_started == 1) && (priv.wm_rot_supported))
1205 __set_wm_rotation_support(0, 0);
1207 priv.rot_started = 0;
1212 static int __wm_resume_rotation_cb(void)
1214 if ((priv.rot_started == 0) && (priv.wm_rot_supported))
1215 __set_wm_rotation_support(0, 1);
1217 priv.rot_started = 1;
1222 static struct ui_wm_rotate wm_rotate = {
1223 __wm_set_rotation_cb,
1224 __wm_unset_rotation_cb,
1225 __wm_get_rotation_state,
1226 __wm_pause_rotation_cb,
1227 __wm_resume_rotation_cb
1231 EXPORT_API int appcore_efl_init(const char *name, int *argc, char ***argv,
1232 struct appcore_ops *ops)
1236 LOG(LOG_DEBUG, "LAUNCH", "[%s:Application:main:done]", name);
1238 r = __set_data(&priv, name, ops);
1239 _retv_if(r == -1, -1);
1241 r = __before_loop(&priv, argc, argv);
1243 aul_status_update(STATUS_DYING);
1244 __unset_data(&priv);
1251 EXPORT_API void appcore_efl_fini(void)
1253 aul_status_update(STATUS_DYING);
1255 __after_loop(&priv);
1257 __unset_data(&priv);
1260 EXPORT_API int appcore_efl_main(const char *name, int *argc, char ***argv,
1261 struct appcore_ops *ops)
1265 r = appcore_efl_init(name, argc, argv, ops);
1266 _retv_if(r == -1, -1);
1275 EXPORT_API int appcore_set_system_resource_reclaiming(bool enable)
1277 resource_reclaiming = enable;
1282 EXPORT_API int appcore_set_app_state(int state)
1291 EXPORT_API int appcore_set_preinit_window_name(const char *win_name)
1294 void *preinit_window = NULL;
1295 const Evas *e = NULL;
1298 _ERR("invalid parameter");
1302 preinit_window = elm_win_precreated_object_get();
1303 if (!preinit_window) {
1304 _ERR("Failed to get preinit window");
1308 e = evas_object_evas_get((const Evas_Object *)preinit_window);
1310 Ecore_Evas *ee = ecore_evas_ecore_evas_get(e);
1312 ecore_evas_name_class_set(ee, win_name, win_name);
1320 EXPORT_API unsigned int appcore_get_main_window(void)
1322 struct win_node *entry = NULL;
1324 if (g_winnode_list != NULL) {
1325 entry = g_winnode_list->data;
1326 return (unsigned int) entry->win;
1332 #if defined(WAYLAND)
1333 EXPORT_API unsigned int appcore_get_main_surface(void)
1335 struct win_node *entry = NULL;
1337 if (g_winnode_list != NULL) {
1338 entry = g_winnode_list->data;
1339 return (unsigned int) entry->surf;