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>
30 #include <X11/Xatom.h>
36 #include <Ecore_Evas.h>
37 #include <Ecore_Input_Evas.h>
38 #include <Elementary.h>
39 #include <glib-object.h>
47 #include "appcore-internal.h"
48 #include "appcore-efl.h"
50 #define RESOURCED_PROCESS_PATH "/Org/Tizen/ResourceD/Process"
51 #define RESOURCED_PROCESS_INTERFACE "org.tizen.resourced.process"
52 #define RESOURCED_PROCSTATUS_SIGNAL "ProcStatus"
55 static bool resource_reclaiming = TRUE;
56 static int tmp_val = 0;
58 /* cgroup command type */
59 enum proc_status_type {
62 PROC_STATUS_TERMINATE,
71 Ecore_Event_Handler *hshow;
72 Ecore_Event_Handler *hhide;
73 Ecore_Event_Handler *hvchange;
75 Ecore_Event_Handler *hlower;
77 Ecore_Event_Handler *hcmsg; /* WM_ROTATE */
79 Ecore_Timer *mftimer; /* Ecore Timer for memory flushing */
81 #ifdef _APPFW_FEATURE_BACKGROUND_MANAGEMENT
82 struct appcore *app_core;
83 void (*prepare_to_suspend) (void *data);
84 void (*exit_from_suspend) (void *data);
86 struct appcore_ops *ops;
87 void (*mfcb) (void); /* Memory Flushing Callback */
92 int (*rot_cb) (void *event_info, enum appcore_rm, void *);
94 enum appcore_rm rot_mode;
98 static struct ui_priv priv;
100 static const char *_ae_name[AE_MAX] = {
101 [AE_UNKNOWN] = "UNKNOWN",
102 [AE_CREATE] = "CREATE",
103 [AE_TERMINATE] = "TERMINATE",
104 [AE_PAUSE] = "PAUSE",
105 [AE_RESUME] = "RESUME",
106 [AE_RESET] = "RESET",
107 [AE_LOWMEM_POST] = "LOWMEM_POST",
108 [AE_MEM_FLUSH] = "MEM_FLUSH",
111 static const char *_as_name[] = {
113 [AS_CREATED] = "CREATED",
114 [AS_RUNNING] = "RUNNING",
115 [AS_PAUSED] = "PAUSED",
116 [AS_DYING] = "DYING",
119 static bool b_active = FALSE;
120 static bool first_launch = TRUE;
131 static struct ui_wm_rotate wm_rotate;
133 static Eina_Bool __visibility_cb(void *data, int type, void *event);
135 static void __send_to_resourced(enum proc_status_type type)
137 GDBusConnection *conn;
140 conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &err);
142 _ERR("g_bus_bus_get() is failed: [%s]", err->message);
147 if (g_dbus_connection_emit_signal(conn,
149 RESOURCED_PROCESS_PATH,
150 RESOURCED_PROCESS_INTERFACE,
151 RESOURCED_PROCSTATUS_SIGNAL,
152 g_variant_new("(ii)", type, _pid),
154 _ERR("g_dbus_connection_emit_signal() is failed: [%s]",
160 if (g_dbus_connection_flush_sync(conn, NULL, &err) == FALSE)
161 _ERR("g_dbus_connection_flush_sync() is failed: [%s]",
165 g_object_unref(conn);
168 static GSList *g_winnode_list;
170 #ifdef _APPFW_FEATURE_BACKGROUND_MANAGEMENT
171 static void __appcore_efl_prepare_to_suspend(void *data)
173 struct ui_priv *ui = (struct ui_priv *)data;
174 struct sys_op *op = NULL;
175 int suspend = APPCORE_SUSPENDED_STATE_WILL_ENTER_SUSPEND;
177 if (ui->app_core && !ui->app_core->allowed_bg && !ui->app_core->suspended_state) {
178 op = &ui->app_core->sops[SE_SUSPENDED_STATE];
180 op->func((void *)&suspend, op->data); /* calls c-api handler */
182 ui->app_core->suspended_state = true;
184 _DBG("[__SUSPEND__]");
187 static void __appcore_efl_exit_from_suspend(void *data)
189 struct ui_priv *ui = (struct ui_priv *)data;
190 struct sys_op *op = NULL;
191 int suspend = APPCORE_SUSPENDED_STATE_DID_EXIT_FROM_SUSPEND;
193 if (ui->app_core && !ui->app_core->allowed_bg && ui->app_core->suspended_state) {
194 op = &ui->app_core->sops[SE_SUSPENDED_STATE];
196 op->func((void *)&suspend, op->data); /* calls c-api handler */
198 ui->app_core->suspended_state = false;
200 _DBG("[__SUSPEND__]");
204 #if defined(MEMORY_FLUSH_ACTIVATE)
205 static Eina_Bool __appcore_memory_flush_cb(void *data)
207 struct ui_priv *ui = (struct ui_priv *)data;
209 appcore_flush_memory();
213 #ifdef _APPFW_FEATURE_BACKGROUND_MANAGEMENT
214 if (ui && ui->prepare_to_suspend) {
215 _DBG("[__SUSPEND__] flush case");
216 ui->prepare_to_suspend(ui);
220 return ECORE_CALLBACK_CANCEL;
223 static int __appcore_low_memory_post_cb(struct ui_priv *ui)
225 if (ui->state == AS_PAUSED)
226 appcore_flush_memory();
233 static void __appcore_timer_add(struct ui_priv *ui)
235 ui->mftimer = ecore_timer_add(5, __appcore_memory_flush_cb, ui);
238 static void __appcore_timer_del(struct ui_priv *ui)
241 ecore_timer_del(ui->mftimer);
248 static int __appcore_low_memory_post_cb(ui_priv *ui)
253 #define __appcore_timer_add(ui) 0
254 #define __appcore_timer_del(ui) 0
258 static void __appcore_efl_memory_flush_cb(void)
260 _DBG("[APP %d] __appcore_efl_memory_flush_cb()", _pid);
261 elm_cache_all_flush();
264 static void wl_raise_win(void)
266 Ecore_Wl_Window *win;
267 unsigned int win_id = appcore_get_main_window();
269 _DBG("Raise window: %d", win_id);
270 win = ecore_wl_window_find(win_id);
271 ecore_wl_window_activate(win);
274 static void wl_pause_win(void)
276 Ecore_Wl_Window *win;
277 GSList *wlist = g_winnode_list;
278 struct win_node *entry = NULL;
280 _DBG("Pause window");
285 _DBG("Pause window: %d", entry->win);
286 win = ecore_wl_window_find(entry->win);
287 ecore_wl_window_iconified_set(win, EINA_TRUE);
295 static void __do_app(enum app_event event, void *data, bundle * b)
298 struct ui_priv *ui = data;
300 _DBG("[APP %d] Event: %d", _pid, event);
301 _ret_if(ui == NULL || event >= AE_MAX);
302 _DBG("[APP %d] Event: %s State: %s", _pid, _ae_name[event],
303 _as_name[ui->state]);
305 if (event == AE_MEM_FLUSH) {
310 if (event == AE_LOWMEM_POST) {
311 if (__appcore_low_memory_post_cb(ui) == 0)
315 if (!(ui->state == AS_PAUSED && event == AE_PAUSE))
316 __appcore_timer_del(ui);
318 if (ui->state == AS_DYING) {
319 _ERR("Skip the event in dying state");
323 if (event == AE_TERMINATE) {
324 _DBG("[APP %d] TERMINATE", _pid);
326 aul_status_update(STATUS_DYING);
330 if (event == AE_RAISE) {
332 x_raise_win(getpid());
333 #elif defined(WAYLAND)
339 if (event == AE_LOWER) {
341 x_pause_win(getpid());
342 #elif defined(WAYLAND)
348 _ret_if(ui->ops == NULL);
352 _DBG("[APP %d] RESET", _pid);
353 ui->pending_data = bundle_dup(b);
354 LOG(LOG_DEBUG, "LAUNCH", "[%s:Application:reset:start]", ui->name);
356 #ifdef _APPFW_FEATURE_BACKGROUND_MANAGEMENT
357 if (ui->exit_from_suspend) {
358 _DBG("[__SUSPEND__] reset case");
359 ui->exit_from_suspend(ui);
363 if (ui->ops->reset) {
364 traceBegin(TTRACE_TAG_APPLICATION_MANAGER,
366 r = ui->ops->reset(b, ui->ops->data);
367 traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
369 LOG(LOG_DEBUG, "LAUNCH", "[%s:Application:reset:done]", ui->name);
372 first_launch = FALSE;
374 _INFO("[APP %d] App already running, raise the window", _pid);
376 x_raise_win(getpid());
381 LOG(LOG_DEBUG, "LAUNCH", "[%s:Application:reset:done]",
385 if (ui->state == AS_RUNNING) {
386 _DBG("[APP %d] PAUSE", _pid);
387 if (ui->ops->pause) {
388 traceBegin(TTRACE_TAG_APPLICATION_MANAGER,
390 r = ui->ops->pause(ui->ops->data);
391 traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
393 ui->state = AS_PAUSED;
394 if (r >= 0 && resource_reclaiming == TRUE)
395 __appcore_timer_add(ui);
396 #ifdef _APPFW_FEATURE_BACKGROUND_MANAGEMENT
397 else if (r >= 0 && resource_reclaiming == FALSE
398 && ui->prepare_to_suspend) {
399 _DBG("[__SUSPEND__] pause case");
400 ui->prepare_to_suspend(ui);
404 /* TODO : rotation stop */
405 /* r = appcore_pause_rotation_cb(); */
406 aul_status_update(STATUS_BG);
407 __send_to_resourced(PROC_STATUS_BACKGRD);
410 LOG(LOG_DEBUG, "LAUNCH", "[%s:Application:resume:start]",
412 #ifdef _APPFW_FEATURE_BACKGROUND_MANAGEMENT
413 if (ui->exit_from_suspend) {
414 _DBG("[__SUSPEND__] resume case");
415 ui->exit_from_suspend(ui);
419 if (ui->state == AS_PAUSED || ui->state == AS_CREATED) {
420 _DBG("[APP %d] RESUME", _pid);
422 if (ui->state == AS_CREATED) {
423 bundle_free(ui->pending_data);
424 ui->pending_data = NULL;
427 if (ui->ops->resume) {
428 traceBegin(TTRACE_TAG_APPLICATION_MANAGER,
430 ui->ops->resume(ui->ops->data);
431 traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
433 ui->state = AS_RUNNING;
435 /*TODO : rotation start*/
436 /* r = appcore_resume_rotation_cb(); */
437 LOG(LOG_DEBUG, "LAUNCH", "[%s:Application:resume:done]",
439 LOG(LOG_DEBUG, "LAUNCH", "[%s:Application:Launching:done]",
441 aul_status_update(STATUS_VISIBLE);
442 __send_to_resourced(PROC_STATUS_FOREGRD);
444 case AE_TERMINATE_BGAPP:
445 if (ui->state == AS_PAUSED) {
446 _DBG("[APP %d] is paused. TERMINATE", _pid);
447 ui->state = AS_DYING;
448 aul_status_update(STATUS_DYING);
450 } else if (ui->state == AS_RUNNING) {
451 _DBG("[APP %d] is running.", _pid);
453 _DBG("[APP %d] is another state", _pid);
462 static struct ui_ops efl_ops = {
467 static bool __check_visible(void)
470 struct win_node *entry = NULL;
472 _DBG("[EVENT_TEST][EVENT] __check_visible\n");
474 for (iter = g_winnode_list; iter != NULL; iter = g_slist_next(iter)) {
476 _DBG("win : %x obscured : %d\n", entry->win, entry->bfobscured);
477 if (entry->bfobscured == FALSE)
484 static GSList *__find_win(unsigned int win)
489 for (iter = g_winnode_list; iter; iter = g_slist_next(iter)) {
491 if (t && t->win == win)
499 static bool __add_win(unsigned int win)
504 _DBG("[EVENT_TEST][EVENT] __add_win WIN:%x\n", win);
509 _DBG("[EVENT_TEST][EVENT] ERROR There is already window : %x \n", win);
513 t = calloc(1, sizeof(struct win_node));
518 t->bfobscured = FALSE;
520 g_winnode_list = g_slist_append(g_winnode_list, t);
524 #elif defined(WAYLAND)
525 static bool __add_win(unsigned int win, unsigned int surf)
530 _DBG("[EVENT_TEST][EVENT] __add_win WIN:%x\n", win);
535 _DBG("[EVENT_TEST][EVENT] ERROR There is already window : %x \n", win);
539 t = calloc(1, sizeof(struct win_node));
545 t->bfobscured = FALSE;
547 g_winnode_list = g_slist_append(g_winnode_list, t);
553 static bool __delete_win(unsigned int win)
560 _DBG("[EVENT_TEST][EVENT] ERROR There is no window : %x \n",
566 g_winnode_list = g_slist_delete_link(g_winnode_list, f);
572 static bool __update_win(unsigned int win, bool bfobscured)
577 _DBG("[EVENT_TEST][EVENT] __update_win WIN:%x fully_obscured %d\n", win,
583 _DBG("[EVENT_TEST][EVENT] ERROR There is no window : %x \n", win);
587 g_winnode_list = g_slist_remove_link(g_winnode_list, f);
589 t = (struct win_node *)f->data;
591 t->bfobscured = bfobscured;
593 g_winnode_list = g_slist_concat(g_winnode_list, f);
597 #elif defined(WAYLAND)
598 static bool __update_win(unsigned int win, unsigned int surf, bool bfobscured)
603 _DBG("[EVENT_TEST][EVENT] __update_win WIN:%x fully_obscured %d\n", win,
609 _DBG("[EVENT_TEST][EVENT] ERROR There is no window : %x \n", win);
613 g_winnode_list = g_slist_remove_link(g_winnode_list, f);
615 t = (struct win_node *)f->data;
619 t->bfobscured = bfobscured;
621 g_winnode_list = g_slist_concat(g_winnode_list, f);
629 static Ecore_X_Atom _WM_WINDOW_ROTATION_SUPPORTED = 0;
630 static Ecore_X_Atom _WM_WINDOW_ROTATION_CHANGE_REQUEST = 0;
632 static int __check_wm_rotation_support(void)
634 _DBG("Disable window manager rotation");
637 Ecore_X_Window root, win, win2;
640 if (!_WM_WINDOW_ROTATION_SUPPORTED) {
641 _WM_WINDOW_ROTATION_SUPPORTED =
642 ecore_x_atom_get("_E_WINDOW_ROTATION_SUPPORTED");
645 if (!_WM_WINDOW_ROTATION_CHANGE_REQUEST) {
646 _WM_WINDOW_ROTATION_CHANGE_REQUEST =
647 ecore_x_atom_get("_E_WINDOW_ROTATION_CHANGE_REQUEST");
650 root = ecore_x_window_root_first_get();
651 ret = ecore_x_window_prop_xid_get(root,
652 _WM_WINDOW_ROTATION_SUPPORTED,
655 if ((ret == 1) && (win)) {
656 ret = ecore_x_window_prop_xid_get(win,
657 _WM_WINDOW_ROTATION_SUPPORTED,
660 if ((ret == 1) && (win2 == win))
667 static void __set_wm_rotation_support(unsigned int win, unsigned int set)
670 struct win_node *entry = NULL;
673 for (iter = g_winnode_list; iter != NULL; iter = g_slist_next(iter)) {
676 ecore_x_window_prop_card32_set(entry->win,
677 _WM_WINDOW_ROTATION_SUPPORTED,
682 ecore_x_window_prop_card32_set(win,
683 _WM_WINDOW_ROTATION_SUPPORTED,
689 static Eina_Bool __show_cb(void *data, int type, void *event)
692 Ecore_Wl_Event_Window_Show *ev;
695 if (ev->parent_win != 0) {
696 /* This is child window. Skip!!! */
697 return ECORE_CALLBACK_PASS_ON;
700 _DBG("[EVENT_TEST][EVENT] GET SHOW EVENT!!!. WIN:%x, %d\n", ev->win, ev->data[0]);
702 if (!__find_win((unsigned int)ev->win))
703 __add_win((unsigned int)ev->win, (unsigned int)ev->data[0]);
705 __update_win((unsigned int)ev->win, (unsigned int)ev->data[0], FALSE);
708 Ecore_X_Event_Window_Show *ev;
712 _DBG("[EVENT_TEST][EVENT] GET SHOW EVENT!!!. WIN:%x\n", ev->win);
714 if (!__find_win((unsigned int)ev->win)) {
716 if ((priv.wm_rot_supported) && (1 == priv.rot_started))
717 __set_wm_rotation_support(ev->win, 1);
718 __add_win((unsigned int)ev->win);
720 __update_win((unsigned int)ev->win, FALSE);
724 appcore_group_attach();
725 return ECORE_CALLBACK_RENEW;
728 static Eina_Bool __hide_cb(void *data, int type, void *event)
731 Ecore_Wl_Event_Window_Hide *ev;
733 Ecore_X_Event_Window_Hide *ev;
739 _DBG("[EVENT_TEST][EVENT] GET HIDE EVENT!!!. WIN:%x\n", ev->win);
741 if (__find_win((unsigned int)ev->win)) {
742 __delete_win((unsigned int)ev->win);
743 bvisibility = __check_visible();
744 if (!bvisibility && b_active == TRUE) {
745 _DBG(" Go to Pasue state \n");
747 __do_app(AE_PAUSE, data, NULL);
751 return ECORE_CALLBACK_RENEW;
755 static Eina_Bool __lower_cb(void *data, int type, void *event)
757 Ecore_Wl_Event_Window_Lower *ev;
759 if (!ev) return ECORE_CALLBACK_RENEW;
760 _DBG("ECORE_WL_EVENT_WINDOW_LOWER window id:%u\n", ev->win);
761 appcore_group_lower();
762 return ECORE_CALLBACK_RENEW;
766 static Eina_Bool __visibility_cb(void *data, int type, void *event)
769 Ecore_Wl_Event_Window_Visibility_Change *ev;
772 __update_win((unsigned int)ev->win, 0, ev->fully_obscured);
774 Ecore_X_Event_Window_Visibility_Change *ev;
779 __update_win((unsigned int)ev->win, ev->fully_obscured);
781 bvisibility = __check_visible();
783 _DBG("bvisibility %d, b_active %d", bvisibility, b_active);
785 if (bvisibility && b_active == FALSE) {
786 _DBG(" Go to Resume state\n");
788 __do_app(AE_RESUME, data, NULL);
790 } else if (!bvisibility && b_active == TRUE) {
791 _DBG(" Go to Pasue state \n");
793 __do_app(AE_PAUSE, data, NULL);
795 _DBG(" No change state \n");
797 return ECORE_CALLBACK_RENEW;
803 static Eina_Bool __cmsg_cb(void *data, int type, void *event)
805 struct ui_priv *ui = (struct ui_priv *)data;
806 Ecore_X_Event_Client_Message *e = event;
809 return ECORE_CALLBACK_PASS_ON;
812 return ECORE_CALLBACK_PASS_ON;
814 if (e->message_type == _WM_WINDOW_ROTATION_CHANGE_REQUEST) {
815 if ((ui->wm_rot_supported == 0)
816 || (ui->rot_started == 0)
817 || (ui->rot_cb == NULL)) {
818 return ECORE_CALLBACK_PASS_ON;
822 switch (e->data.l[1]) {
824 rm = APPCORE_RM_PORTRAIT_NORMAL;
827 rm = APPCORE_RM_LANDSCAPE_REVERSE;
830 rm = APPCORE_RM_PORTRAIT_REVERSE;
833 rm = APPCORE_RM_LANDSCAPE_NORMAL;
836 rm = APPCORE_RM_UNKNOWN;
842 if (APPCORE_RM_UNKNOWN != rm)
843 ui->rot_cb((void *)&rm, rm, ui->rot_cb_data);
846 return ECORE_CALLBACK_PASS_ON;
850 static void __add_climsg_cb(struct ui_priv *ui)
855 ecore_event_handler_add(ECORE_WL_EVENT_WINDOW_SHOW, __show_cb, ui);
857 ecore_event_handler_add(ECORE_WL_EVENT_WINDOW_HIDE, __hide_cb, ui);
859 ecore_event_handler_add(ECORE_WL_EVENT_WINDOW_VISIBILITY_CHANGE,
860 __visibility_cb, ui);
862 ecore_event_handler_add(ECORE_WL_EVENT_WINDOW_LOWER,
866 ecore_event_handler_add(ECORE_X_EVENT_WINDOW_SHOW, __show_cb, ui);
868 ecore_event_handler_add(ECORE_X_EVENT_WINDOW_HIDE, __hide_cb, ui);
870 ecore_event_handler_add(ECORE_X_EVENT_WINDOW_VISIBILITY_CHANGE,
871 __visibility_cb, ui);
873 /* Add client message callback for WM_ROTATE */
874 if (!__check_wm_rotation_support()) {
875 ui->hcmsg = ecore_event_handler_add(ECORE_X_EVENT_CLIENT_MESSAGE,
877 ui->wm_rot_supported = 1;
878 appcore_set_wm_rotation(&wm_rotate);
883 static int __before_loop(struct ui_priv *ui, int *argc, char ***argv)
888 if (argc == NULL || argv == NULL) {
889 _ERR("argc/argv is NULL");
894 #if !(GLIB_CHECK_VERSION(2, 36, 0))
897 elm_init(*argc, *argv);
899 hwacc = getenv("HWACC");
901 _DBG("elm_config_accel_preference_set is not called");
902 } else if (strcmp(hwacc, "USE") == 0) {
903 elm_config_accel_preference_set("hw");
904 _DBG("elm_config_accel_preference_set : hw");
905 } else if (strcmp(hwacc, "NOT_USE") == 0) {
906 elm_config_accel_preference_set("none");
907 _DBG("elm_config_accel_preference_set : none");
909 _DBG("elm_config_accel_preference_set is not called");
912 r = appcore_init(ui->name, &efl_ops, *argc, *argv);
913 _retv_if(r == -1, -1);
915 #if _APPFW_FEATURE_BACKGROUND_MANAGEMENT
916 appcore_get_app_core(&ac);
918 SECURE_LOGD("[__SUSPEND__] appcore initialized, appcore addr: 0x%x", ac);
921 LOG(LOG_DEBUG, "LAUNCH", "[%s:Platform:appcore_init:done]", ui->name);
922 if (ui->ops && ui->ops->create) {
923 traceBegin(TTRACE_TAG_APPLICATION_MANAGER, "APPCORE:CREATE");
924 r = ui->ops->create(ui->ops->data);
925 traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
927 _ERR("create() return error");
929 if (ui->ops && ui->ops->terminate) {
930 traceBegin(TTRACE_TAG_APPLICATION_MANAGER,
931 "APPCORE:TERMINATE");
932 ui->ops->terminate(ui->ops->data);
933 traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
938 LOG(LOG_DEBUG, "LAUNCH", "[%s:Application:create:done]",
941 ui->state = AS_CREATED;
948 static void __after_loop(struct ui_priv *ui)
950 appcore_unset_rotation_cb();
953 if (ui->state == AS_RUNNING) {
954 _DBG("[APP %d] PAUSE before termination", _pid);
955 if (ui->ops && ui->ops->pause) {
956 traceBegin(TTRACE_TAG_APPLICATION_MANAGER,
958 ui->ops->pause(ui->ops->data);
959 traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
963 if (ui->ops && ui->ops->terminate) {
964 traceBegin(TTRACE_TAG_APPLICATION_MANAGER, "APPCORE:TERMINATE");
965 ui->ops->terminate(ui->ops->data);
966 traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
969 ui->state = AS_DYING;
972 ecore_event_handler_del(ui->hshow);
974 ecore_event_handler_del(ui->hhide);
976 ecore_event_handler_del(ui->hvchange);
979 ecore_event_handler_del(ui->hlower);
982 __appcore_timer_del(ui);
987 static int __set_data(struct ui_priv *ui, const char *name,
988 struct appcore_ops *ops)
991 _ERR("Mainloop already started");
996 if (name == NULL || name[0] == '\0') {
997 _ERR("Invalid name");
1003 _ERR("ops is NULL");
1008 ui->name = strdup(name);
1009 _retv_if(ui->name == NULL, -1);
1012 ui->mfcb = __appcore_efl_memory_flush_cb;
1016 ui->wm_rot_supported = 0;
1017 ui->rot_started = 0;
1019 ui->rot_cb_data = NULL;
1020 ui->rot_mode = APPCORE_RM_UNKNOWN;
1022 #ifdef _APPFW_FEATURE_BACKGROUND_MANAGEMENT
1023 ui->app_core = NULL;
1024 ui->prepare_to_suspend = __appcore_efl_prepare_to_suspend;
1025 ui->exit_from_suspend = __appcore_efl_exit_from_suspend;
1031 static void __unset_data(struct ui_priv *ui)
1034 free((void *)ui->name);
1036 memset(ui, 0, sizeof(struct ui_priv));
1041 static int __wm_set_rotation_cb(int (*cb) (void *event_info, enum appcore_rm, void *), void *data)
1048 if ((priv.wm_rot_supported) && (0 == priv.rot_started))
1049 __set_wm_rotation_support(0, 1);
1052 priv.rot_cb_data = data;
1053 priv.rot_started = 1;
1058 static int __wm_unset_rotation_cb(void)
1060 if ((priv.wm_rot_supported) && (1 == priv.rot_started))
1061 __set_wm_rotation_support(0, 0);
1064 priv.rot_cb_data = NULL;
1065 priv.rot_started = 0;
1070 static int __wm_get_rotation_state(enum appcore_rm *curr)
1077 *curr = priv.rot_mode;
1082 static int __wm_pause_rotation_cb(void)
1084 if ((priv.rot_started == 1) && (priv.wm_rot_supported))
1085 __set_wm_rotation_support(0, 0);
1087 priv.rot_started = 0;
1092 static int __wm_resume_rotation_cb(void)
1094 if ((priv.rot_started == 0) && (priv.wm_rot_supported))
1095 __set_wm_rotation_support(0, 1);
1097 priv.rot_started = 1;
1102 static struct ui_wm_rotate wm_rotate = {
1103 __wm_set_rotation_cb,
1104 __wm_unset_rotation_cb,
1105 __wm_get_rotation_state,
1106 __wm_pause_rotation_cb,
1107 __wm_resume_rotation_cb
1111 EXPORT_API int appcore_efl_init(const char *name, int *argc, char ***argv,
1112 struct appcore_ops *ops)
1116 LOG(LOG_DEBUG, "LAUNCH", "[%s:Application:main:done]", name);
1118 r = __set_data(&priv, name, ops);
1119 _retv_if(r == -1, -1);
1121 r = __before_loop(&priv, argc, argv);
1123 aul_status_update(STATUS_DYING);
1124 __unset_data(&priv);
1131 EXPORT_API void appcore_efl_fini(void)
1133 aul_status_update(STATUS_DYING);
1135 __after_loop(&priv);
1137 __unset_data(&priv);
1140 EXPORT_API int appcore_efl_main(const char *name, int *argc, char ***argv,
1141 struct appcore_ops *ops)
1145 r = appcore_efl_init(name, argc, argv, ops);
1146 _retv_if(r == -1, -1);
1155 EXPORT_API int appcore_set_system_resource_reclaiming(bool enable)
1157 resource_reclaiming = enable;
1162 EXPORT_API int appcore_set_app_state(int state)
1171 EXPORT_API int appcore_set_preinit_window_name(const char *win_name)
1174 void *preinit_window = NULL;
1175 const Evas *e = NULL;
1178 _ERR("invalid parameter");
1182 preinit_window = aul_get_preinit_window(win_name);
1183 if (!preinit_window) {
1184 _ERR("Failed to get preinit window");
1188 e = evas_object_evas_get((const Evas_Object *)preinit_window);
1190 Ecore_Evas *ee = ecore_evas_ecore_evas_get(e);
1192 ecore_evas_name_class_set(ee, win_name, win_name);
1200 EXPORT_API unsigned int appcore_get_main_window(void)
1202 struct win_node *entry = NULL;
1204 if (g_winnode_list != NULL) {
1205 entry = g_winnode_list->data;
1206 return (unsigned int) entry->win;
1212 #if defined(WAYLAND)
1213 EXPORT_API unsigned int appcore_get_main_surface(void)
1215 struct win_node *entry = NULL;
1217 if (g_winnode_list != NULL) {
1218 entry = g_winnode_list->data;
1219 return (unsigned int) entry->surf;