# Build appcore-common Library
# ------------------------------
SET(APPCORE_COMMON "appcore-common")
-SET(SRCS_common src/appcore.c src/appcore-i18n.c src/appcore-measure.c src/appcore-rotation.c src/base/appcore_base.c)
-
+SET(SRCS_common src/legacy/appcore.c src/legacy/appcore-measure.c src/legacy/appcore-rotation.c src/legacy/appcore-i18n.c src/base/appcore_base.c)
SET(HEADERS_common appcore-common.h appcore_base.h)
INCLUDE(FindPkgConfig)
-SET(APPCORE_PKG_CHECK_MODULES "gio-2.0 vconf sensor aul dlog ecore capi-system-info")
-SET(APPCORE_PKG_CHECK_MODULES "${APPCORE_PKG_CHECK_MODULES} ecore-wayland wayland-client tizen-extension-client wayland-tbm-client")
+SET(APPCORE_PKG_CHECK_MODULES "gio-2.0 vconf sensor aul dlog capi-system-info")
pkg_check_modules(pkg_common REQUIRED ${APPCORE_PKG_CHECK_MODULES})
# Build appcore-efl Library
# ------------------------------
SET(APPCORE_EFL "appcore-efl")
-SET(SRCS_efl src/appcore-efl.c src/appcore-group.c src/ui_base/appcore_ui_base.c)
+SET(SRCS_efl src/legacy/appcore-efl.c src/ui_base/appcore_ui_base.c)
SET(HEADERS_efl appcore-efl.h appcore_ui_base.h)
INCLUDE(FindPkgConfig)
int appcore_efl_main(const char *name, int *argc, char ***argv,
struct appcore_ops *ops);
-/**
- * @par Description:
- * This API sets system resource reclaiming.
- *
- * @par Purpose:
- * When this is not enabled, the application doesn't reclaim system resource.
- *
- * @param[in] enable Application name
- *
- * @return 0 on success, -1 on error (<I>errno</I> set)
- *
- *
- * @pre None.
- * @post None.
- * @see None.
- * @remarks None.
- *
- * @par Sample code:
- * @code
-#include <appcore-efl.h>
-
-int _create(void *data)
-{
- int r;
-
- ...
- r = appcore_set_system_resource_reclaiming(FALSE);
- if (r) {
- // add exception handling
- perror("appcore_set_system_resource_reclaiming");
- }
- ...
-}
- * @endcode
- *
- */
int appcore_set_system_resource_reclaiming(bool enable);
-int appcore_set_preinit_window_name(const char *win_name);
-
#ifdef __cplusplus
}
#endif
void (*cb_app) (enum app_event evnt, void *data, bundle *b);
};
-/* appcore-i18n.c */
-extern void update_lang(void);
-extern int set_i18n(const char *domainname, const char *dirname);
-void update_region(void);
-
-/* appcore-util.c */
-/* extern void stack_trim(void);*/
-
-int appcore_pause_rotation_cb(void);
-int appcore_resume_rotation_cb(void);
-
struct ui_wm_rotate {
int (*set_rotation_cb) (int (*cb)(void *event_info, enum appcore_rm, void *), void *data);
int (*unset_rotation_cb) (void);
int (*pause_rotation_cb) (void);
int (*resume_rotation_cb) (void);
};
-int appcore_set_wm_rotation(struct ui_wm_rotate* wm_rotate);
-
void appcore_group_attach();
void appcore_group_lower();
unsigned int appcore_get_main_window(void);
unsigned int appcore_get_main_surface(void);
-void appcore_get_app_core(struct appcore **ac);
#define ENV_START "APP_START_TIME"
-#define MEMORY_FLUSH_ACTIVATE
-
-typedef enum {
- TIZEN_PROFILE_UNKNOWN = 0,
- TIZEN_PROFILE_MOBILE = 0x1,
- TIZEN_PROFILE_WEARABLE = 0x2,
- TIZEN_PROFILE_TV = 0x4,
- TIZEN_PROFILE_IVI = 0x8,
- TIZEN_PROFILE_COMMON = 0x10,
-} tizen_profile_t;
-extern tizen_profile_t _get_tizen_profile();
-
-#define _APPFW_FEATURE_BACKGROUND_MANAGEMENT (_get_tizen_profile() & (TIZEN_PROFILE_WEARABLE | TIZEN_PROFILE_MOBILE))
-
#endif /* __APPCORE_INTERNAL_H__ */
bool appcore_base_is_bg_allowed(void);
bool appcore_base_is_suspended(void);
void appcore_base_toggle_suspended_state(void);
+int appcore_base_set_i18n(const char *domain_name, const char *dir_name);
#ifdef __cplusplus
void appcore_ui_base_resume(void);
bool appcore_ui_base_is_resumed(void);
void appcore_ui_base_exit(void);
+void appcore_ui_base_group_add();
+void appcore_ui_base_group_remove();
+unsigned int appcore_ui_base_get_main_window(void);
+unsigned int appcore_ui_base_get_main_surface(void);
#ifdef __cplusplus
}
+++ /dev/null
-/*
- * Copyright (c) 2000 - 2016 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <sys/un.h>
-#include <stdio.h>
-#include <unistd.h>
-#include <stdarg.h>
-#include <errno.h>
-#include <string.h>
-#include <stdlib.h>
-
-#include <Ecore_Wayland.h>
-#include <wayland-client.h>
-#include <wayland-tbm-client.h>
-#include <tizen-extension-client-protocol.h>
-
-#include <Ecore.h>
-#include <Ecore_Evas.h>
-#include <Ecore_Input_Evas.h>
-#include <Elementary.h>
-#include <glib-object.h>
-#include <malloc.h>
-#include <glib.h>
-#include <gio/gio.h>
-#include <stdbool.h>
-#include <aul.h>
-#include <aul_svc.h>
-#include <bundle_internal.h>
-#include <ttrace.h>
-
-#include "appcore-internal.h"
-#include "appcore-efl.h"
-#include <system_info.h>
-
-static pid_t _pid;
-static bool resource_reclaiming = TRUE;
-static int tmp_val = 0;
-
-struct ui_priv {
- const char *name;
- enum app_state state;
-
- Ecore_Event_Handler *hshow;
- Ecore_Event_Handler *hhide;
- Ecore_Event_Handler *hvchange;
- Ecore_Event_Handler *hlower;
- Ecore_Event_Handler *hcmsg; /* WM_ROTATE */
-
- Ecore_Timer *mftimer; /* Ecore Timer for memory flushing */
-
- struct appcore *app_core;
- void (*prepare_to_suspend) (void *data);
- void (*exit_from_suspend) (void *data);
- struct appcore_ops *ops;
- void (*mfcb) (void); /* Memory Flushing Callback */
-
- /* WM_ROTATE */
- int wm_rot_supported;
- int rot_started;
- int (*rot_cb) (void *event_info, enum appcore_rm, void *);
- void *rot_cb_data;
- enum appcore_rm rot_mode;
- char *below_app;
-};
-
-static struct ui_priv priv;
-
-static const char *_ae_name[AE_MAX] = {
- [AE_UNKNOWN] = "UNKNOWN",
- [AE_CREATE] = "CREATE",
- [AE_TERMINATE] = "TERMINATE",
- [AE_PAUSE] = "PAUSE",
- [AE_RESUME] = "RESUME",
- [AE_RESET] = "RESET",
- [AE_LOWMEM_POST] = "LOWMEM_POST",
- [AE_MEM_FLUSH] = "MEM_FLUSH",
- [AE_UPDATE_REQUESTED] = "UPDATE_REQUESTED",
-};
-
-static const char *_as_name[] = {
- [AS_NONE] = "NONE",
- [AS_CREATED] = "CREATED",
- [AS_RUNNING] = "RUNNING",
- [AS_PAUSED] = "PAUSED",
- [AS_DYING] = "DYING",
-};
-
-static bool b_active = FALSE;
-static bool first_launch = TRUE;
-
-struct win_node {
- unsigned int win;
- unsigned int surf;
- bool bfobscured;
-};
-
-static Eina_Bool __visibility_cb(void *data, int type, void *event);
-static GSList *g_winnode_list;
-
-static struct wl_display *dsp;
-static struct wl_registry *reg;
-static struct tizen_policy *tz_policy;
-static bool bg_state = false;
-
-static void __wl_listener_cb(void *data, struct wl_registry *reg,
- uint32_t id, const char *interface, uint32_t ver)
-{
- if (interface && !strcmp(interface, "tizen_policy")) {
- if (!tz_policy)
- tz_policy = wl_registry_bind(reg, id,
- &tizen_policy_interface, 1);
- }
-}
-
-static void __wl_listener_remove_cb(void *data, struct wl_registry *reg,
- unsigned int id)
-{
- /* do nothing */
-}
-
-static const struct wl_registry_listener reg_listener = {
- __wl_listener_cb,
- __wl_listener_remove_cb
-};
-
-static int __init_wl(void)
-{
- _DBG("initialize wayland");
- dsp = wl_display_connect(NULL);
- if (dsp == NULL) {
- _ERR("Failed to connect wl display");
- return -1;
- }
-
- reg = wl_display_get_registry(dsp);
- if (reg == NULL) {
- _ERR("Failed to get registry");
- wl_display_disconnect(dsp);
- return -1;
- }
-
- wl_registry_add_listener(reg, ®_listener, NULL);
- wl_display_roundtrip(dsp);
-
- if (!tz_policy) {
- _ERR("Failed to get tizen policy interface");
- wl_registry_destroy(reg);
- wl_display_disconnect(dsp);
- return -1;
- }
-
- return 0;
-}
-
-static void __finish_wl(void)
-{
- if (tz_policy) {
- tizen_policy_destroy(tz_policy);
- tz_policy = NULL;
- }
-
- if (reg) {
- wl_registry_destroy(reg);
- reg = NULL;
- }
-
- if (dsp) {
- wl_display_disconnect(dsp);
- dsp = NULL;
- }
-}
-
-static void __set_bg_state(void)
-{
- if (!tz_policy && __init_wl() < 0)
- return;
-
- tizen_policy_set_background_state(tz_policy, getpid());
- wl_display_roundtrip(dsp);
- bg_state = true;
- _DBG("bg state: %d", bg_state);
-}
-
-static void __unset_bg_state(void)
-{
- if (!tz_policy)
- return;
-
- tizen_policy_unset_background_state(tz_policy, getpid());
- wl_display_roundtrip(dsp);
- bg_state = false;
- _DBG("bg state: %d", bg_state);
-}
-
-static void __appcore_efl_prepare_to_suspend(void *data)
-{
- struct ui_priv *ui = (struct ui_priv *)data;
- struct sys_op *op = NULL;
- int suspend = APPCORE_SUSPENDED_STATE_WILL_ENTER_SUSPEND;
-
- if (ui->app_core && !ui->app_core->allowed_bg && !ui->app_core->suspended_state) {
- op = &ui->app_core->sops[SE_SUSPENDED_STATE];
- if (op && op->func)
- op->func((void *)&suspend, op->data); /* calls c-api handler */
-
- ui->app_core->suspended_state = true;
- }
- _DBG("[__SUSPEND__]");
-}
-
-static void __appcore_efl_exit_from_suspend(void *data)
-{
- struct ui_priv *ui = (struct ui_priv *)data;
- struct sys_op *op = NULL;
- int suspend = APPCORE_SUSPENDED_STATE_DID_EXIT_FROM_SUSPEND;
-
- if (ui->app_core && !ui->app_core->allowed_bg && ui->app_core->suspended_state) {
- op = &ui->app_core->sops[SE_SUSPENDED_STATE];
- if (op && op->func)
- op->func((void *)&suspend, op->data); /* calls c-api handler */
-
- ui->app_core->suspended_state = false;
- }
- _DBG("[__SUSPEND__]");
-}
-
-static void __appcore_efl_update_requested(void *data)
-{
- struct ui_priv *ui = (struct ui_priv *)data;
- struct sys_op *op;
- int dummy = 0;
-
- if (ui->app_core) {
- op = &ui->app_core->sops[SE_UPDATE_REQUESTED];
- if (op && op->func)
- op->func((void *)&dummy, op->data);
- }
- _DBG("[__UPDATE_REQUESTED__]");
-}
-
-#if defined(MEMORY_FLUSH_ACTIVATE)
-static Eina_Bool __appcore_memory_flush_cb(void *data)
-{
- struct ui_priv *ui = (struct ui_priv *)data;
-
- appcore_flush_memory();
- if (ui)
- ui->mftimer = NULL;
-
- if (_APPFW_FEATURE_BACKGROUND_MANAGEMENT && ui && ui->prepare_to_suspend) {
- _DBG("[__SUSPEND__] flush case");
- ui->prepare_to_suspend(ui);
- }
-
- return ECORE_CALLBACK_CANCEL;
-}
-
-static int __appcore_low_memory_post_cb(struct ui_priv *ui)
-{
- if (ui->state == AS_PAUSED)
- appcore_flush_memory();
- else
- malloc_trim(0);
-
- return 0;
-}
-
-static void __appcore_timer_add(struct ui_priv *ui)
-{
- ui->mftimer = ecore_timer_add(5, __appcore_memory_flush_cb, ui);
-}
-
-static void __appcore_timer_del(struct ui_priv *ui)
-{
- if (ui->mftimer) {
- ecore_timer_del(ui->mftimer);
- ui->mftimer = NULL;
- }
-}
-
-#else
-
-static int __appcore_low_memory_post_cb(ui_priv *ui)
-{
- return -1;
-}
-
-#define __appcore_timer_add(ui) 0
-#define __appcore_timer_del(ui) 0
-
-#endif
-
-static void __appcore_efl_memory_flush_cb(void)
-{
- _DBG("[APP %d] __appcore_efl_memory_flush_cb()", _pid);
- elm_cache_all_flush();
-}
-static void wl_raise_win(void)
-{
- Ecore_Wl_Window *win;
- unsigned int win_id = appcore_get_main_window();
-
- _DBG("Raise window: %d", win_id);
- win = ecore_wl_window_find(win_id);
- ecore_wl_window_activate(win);
-}
-
-static void wl_pause_win(void)
-{
- Ecore_Wl_Window *win;
- GSList *wlist = g_winnode_list;
- struct win_node *entry = NULL;
-
- _DBG("Pause window");
-
- while (wlist) {
- entry = wlist->data;
-
- _DBG("Pause window: %d", entry->win);
- win = ecore_wl_window_find(entry->win);
- ecore_wl_window_iconified_set(win, EINA_TRUE);
-
- wlist = wlist->next;
- }
-}
-
-
-static void __do_app(enum app_event event, void *data, bundle * b)
-{
- int r = -1;
- struct ui_priv *ui = data;
- const char *below_app;
- const char *bg_launch;
-
- _DBG("[APP %d] Event: %d", _pid, event);
- _ret_if(ui == NULL || event >= AE_MAX);
- _DBG("[APP %d] Event: %s State: %s", _pid, _ae_name[event],
- _as_name[ui->state]);
-
- if (event == AE_MEM_FLUSH) {
- ui->mfcb();
- return;
- }
-
- if (event == AE_LOWMEM_POST) {
- if (__appcore_low_memory_post_cb(ui) == 0)
- return;
- }
-
- if (!(ui->state == AS_PAUSED && event == AE_PAUSE))
- __appcore_timer_del(ui);
-
- if (ui->state == AS_DYING) {
- _ERR("Skip the event in dying state");
- return;
- }
-
- if (event == AE_TERMINATE) {
- _DBG("[APP %d] TERMINATE", _pid);
- elm_exit();
- aul_status_update(STATUS_DYING);
- return;
- }
-
- if (event == AE_RAISE) {
- if (bg_state)
- __unset_bg_state();
- wl_raise_win();
- return;
- }
-
- if (event == AE_LOWER) {
- wl_pause_win();
- return;
- }
-
- _ret_if(ui->ops == NULL);
-
- switch (event) {
- case AE_RESET:
- _DBG("[APP %d] RESET", _pid);
- LOG(LOG_DEBUG, "LAUNCH", "[%s:Application:reset:start]", ui->name);
-
- if (ui->below_app) {
- free(ui->below_app);
- ui->below_app = NULL;
- }
-
- below_app = bundle_get_val(b, AUL_SVC_K_RELOCATE_BELOW);
- if (below_app)
- ui->below_app = strdup(below_app);
- if (_APPFW_FEATURE_BACKGROUND_MANAGEMENT && ui->exit_from_suspend) {
- _DBG("[__SUSPEND__] reset case");
- ui->exit_from_suspend(ui);
- }
-
- if (ui->ops->reset) {
- traceBegin(TTRACE_TAG_APPLICATION_MANAGER,
- "APPCORE:RESET");
- r = ui->ops->reset(b, ui->ops->data);
- traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
- }
- LOG(LOG_DEBUG, "LAUNCH", "[%s:Application:reset:done]", ui->name);
-
- if (first_launch) {
- if (_APPFW_FEATURE_BACKGROUND_MANAGEMENT && ui->app_core->allowed_bg)
- __appcore_timer_add(ui);
- first_launch = FALSE;
- } else {
- _INFO("[APP %d] App already running, raise the window", _pid);
- bg_launch = bundle_get_val(b, AUL_SVC_K_BG_LAUNCH);
- if (bg_launch && strcmp(bg_launch, "enable") == 0) {
- if (!bg_state && ui->state != AS_RUNNING)
- __set_bg_state();
- } else {
- if (bg_state)
- __unset_bg_state();
- }
- if (!bg_state)
- wl_raise_win();
- }
- LOG(LOG_DEBUG, "LAUNCH", "[%s:Application:reset:done]",
- ui->name);
- break;
- case AE_PAUSE:
- if (ui->state == AS_RUNNING) {
- _DBG("[APP %d] PAUSE", _pid);
- if (ui->ops->pause) {
- traceBegin(TTRACE_TAG_APPLICATION_MANAGER,
- "APPCORE:PAUSE");
- r = ui->ops->pause(ui->ops->data);
- traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
- }
- ui->state = AS_PAUSED;
- if (r >= 0 && resource_reclaiming == TRUE)
- __appcore_timer_add(ui);
- else if (_APPFW_FEATURE_BACKGROUND_MANAGEMENT && r >= 0 && resource_reclaiming == FALSE
- && ui->prepare_to_suspend) {
- _DBG("[__SUSPEND__] pause case");
- ui->prepare_to_suspend(ui);
- }
- }
- /* TODO : rotation stop */
- /* r = appcore_pause_rotation_cb(); */
- aul_status_update(STATUS_BG);
- break;
- case AE_RESUME:
- LOG(LOG_DEBUG, "LAUNCH", "[%s:Application:resume:start]",
- ui->name);
- if (_APPFW_FEATURE_BACKGROUND_MANAGEMENT) {
- if (ui->exit_from_suspend) {
- _DBG("[__SUSPEND__] resume case");
- ui->exit_from_suspend(ui);
- }
- if (ui->app_core->allowed_bg)
- __appcore_timer_del(ui);
- }
-
- if (ui->state == AS_PAUSED || ui->state == AS_CREATED) {
- _DBG("[APP %d] RESUME", _pid);
-
- if (ui->ops->resume) {
- traceBegin(TTRACE_TAG_APPLICATION_MANAGER,
- "APPCORE:RESUME");
- ui->ops->resume(ui->ops->data);
- traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
- }
- ui->state = AS_RUNNING;
-
- if (ui->below_app) {
- aul_app_group_activate_below(ui->below_app);
- free(ui->below_app);
- ui->below_app = NULL;
- }
- }
- /*TODO : rotation start*/
- /* r = appcore_resume_rotation_cb(); */
- LOG(LOG_DEBUG, "LAUNCH", "[%s:Application:resume:done]",
- ui->name);
- LOG(LOG_DEBUG, "LAUNCH", "[%s:Application:Launching:done]",
- ui->name);
- aul_status_update(STATUS_VISIBLE);
- break;
- case AE_TERMINATE_BGAPP:
- if (ui->state == AS_PAUSED) {
- _DBG("[APP %d] is paused. TERMINATE", _pid);
- ui->state = AS_DYING;
- aul_status_update(STATUS_DYING);
- elm_exit();
- } else if (ui->state == AS_RUNNING) {
- _DBG("[APP %d] is running.", _pid);
- } else {
- _DBG("[APP %d] is another state", _pid);
- }
- break;
- case AE_UPDATE_REQUESTED:
- __appcore_efl_update_requested(ui);
- break;
- default:
- /* do nothing */
- break;
- }
-}
-
-static struct ui_ops efl_ops = {
- .data = &priv,
- .cb_app = __do_app,
-};
-
-static bool __check_visible(void)
-{
- GSList *iter = NULL;
- struct win_node *entry = NULL;
-
- _DBG("[EVENT_TEST][EVENT] __check_visible\n");
-
- for (iter = g_winnode_list; iter != NULL; iter = g_slist_next(iter)) {
- entry = iter->data;
- _DBG("win : %x obscured : %d\n", entry->win, entry->bfobscured);
- if (entry->bfobscured == FALSE)
- return TRUE;
- }
-
- return FALSE;
-}
-
-static GSList *__find_win(unsigned int win)
-{
- GSList *iter;
- struct win_node *t;
-
- for (iter = g_winnode_list; iter; iter = g_slist_next(iter)) {
- t = iter->data;
- if (t && t->win == win)
- return iter;
- }
-
- return NULL;
-}
-
-static bool __add_win(unsigned int win, unsigned int surf)
-{
- struct win_node *t;
- GSList *f;
-
- _DBG("[EVENT_TEST][EVENT] __add_win WIN:%x\n", win);
-
- f = __find_win(win);
- if (f) {
- errno = ENOENT;
- _DBG("[EVENT_TEST][EVENT] ERROR There is already window : %x \n", win);
- return FALSE;
- }
-
- t = calloc(1, sizeof(struct win_node));
- if (t == NULL)
- return FALSE;
-
- t->win = win;
- t->surf = surf;
- t->bfobscured = FALSE;
-
- g_winnode_list = g_slist_append(g_winnode_list, t);
-
- return TRUE;
-}
-
-static bool __delete_win(unsigned int win)
-{
- GSList *f;
-
- f = __find_win(win);
- if (!f) {
- errno = ENOENT;
- _DBG("[EVENT_TEST][EVENT] ERROR There is no window : %x \n",
- win);
- return FALSE;
- }
-
- free(f->data);
- g_winnode_list = g_slist_delete_link(g_winnode_list, f);
-
- return TRUE;
-}
-
-static bool __update_win(unsigned int win, unsigned int surf, bool bfobscured)
-{
- GSList *f;
- struct win_node *t;
-
- _DBG("[EVENT_TEST][EVENT] __update_win WIN:%x fully_obscured %d\n", win,
- bfobscured);
-
- f = __find_win(win);
- if (!f) {
- errno = ENOENT;
- _DBG("[EVENT_TEST][EVENT] ERROR There is no window : %x \n", win);
- return FALSE;
- }
-
- t = (struct win_node *)f->data;
- t->win = win;
- if (surf != 0)
- t->surf = surf;
- t->bfobscured = bfobscured;
-
- return TRUE;
-}
-
-static Eina_Bool __show_cb(void *data, int type, void *event)
-{
- Ecore_Wl_Event_Window_Show *ev;
-
- ev = event;
- if (ev->parent_win != 0) {
- /* This is child window. Skip!!! */
- return ECORE_CALLBACK_PASS_ON;
- }
-
- _DBG("[EVENT_TEST][EVENT] GET SHOW EVENT!!!. WIN:%x, %d\n", ev->win, ev->data[0]);
-
- if (!__find_win((unsigned int)ev->win))
- __add_win((unsigned int)ev->win, (unsigned int)ev->data[0]);
- else
- __update_win((unsigned int)ev->win, (unsigned int)ev->data[0], FALSE);
-
- if (ev->data[0] != 0)
- appcore_group_attach();
- return ECORE_CALLBACK_RENEW;
-}
-
-static Eina_Bool __hide_cb(void *data, int type, void *event)
-{
- Ecore_Wl_Event_Window_Hide *ev;
- int bvisibility = 0;
-
- ev = event;
-
- _DBG("[EVENT_TEST][EVENT] GET HIDE EVENT!!!. WIN:%x\n", ev->win);
-
- if (__find_win((unsigned int)ev->win)) {
- __delete_win((unsigned int)ev->win);
- bvisibility = __check_visible();
- if (!bvisibility && b_active == TRUE) {
- _DBG(" Go to Pasue state \n");
- b_active = FALSE;
- __do_app(AE_PAUSE, data, NULL);
- }
- }
-
- return ECORE_CALLBACK_RENEW;
-}
-
-static Eina_Bool __lower_cb(void *data, int type, void *event)
-{
- Ecore_Wl_Event_Window_Lower *ev;
- ev = event;
- if (!ev) return ECORE_CALLBACK_RENEW;
- _DBG("ECORE_WL_EVENT_WINDOW_LOWER window id:%u\n", ev->win);
- appcore_group_lower();
- return ECORE_CALLBACK_RENEW;
-}
-
-static Eina_Bool __visibility_cb(void *data, int type, void *event)
-{
- Ecore_Wl_Event_Window_Visibility_Change *ev;
- int bvisibility = 0;
- ev = event;
- __update_win((unsigned int)ev->win, 0, ev->fully_obscured);
- bvisibility = __check_visible();
-
- _DBG("bvisibility %d, b_active %d", bvisibility, b_active);
-
- if (bvisibility && b_active == FALSE) {
- _DBG(" Go to Resume state\n");
- b_active = TRUE;
- __do_app(AE_RESUME, data, NULL);
-
- } else if (!bvisibility && b_active == TRUE) {
- _DBG(" Go to Pasue state \n");
- b_active = FALSE;
- __do_app(AE_PAUSE, data, NULL);
- } else
- _DBG(" No change state \n");
-
- return ECORE_CALLBACK_RENEW;
-
-}
-
-static void __add_climsg_cb(struct ui_priv *ui)
-{
- _ret_if(ui == NULL);
- ui->hshow =
- ecore_event_handler_add(ECORE_WL_EVENT_WINDOW_SHOW, __show_cb, ui);
- ui->hhide =
- ecore_event_handler_add(ECORE_WL_EVENT_WINDOW_HIDE, __hide_cb, ui);
- ui->hvchange =
- ecore_event_handler_add(ECORE_WL_EVENT_WINDOW_VISIBILITY_CHANGE,
- __visibility_cb, ui);
- ui->hlower =
- ecore_event_handler_add(ECORE_WL_EVENT_WINDOW_LOWER,
- __lower_cb, ui);
-}
-
-static int __before_loop(struct ui_priv *ui, int *argc, char ***argv)
-{
- int r;
- char *hwacc = NULL;
- struct appcore *ac = NULL;
- bundle *b;
- const char *bg_launch;
-
- if (argc == NULL || argv == NULL) {
- _ERR("argc/argv is NULL");
- errno = EINVAL;
- return -1;
- }
-
-#if !(GLIB_CHECK_VERSION(2, 36, 0))
- g_type_init();
-#endif
- elm_init(*argc, *argv);
-
- hwacc = getenv("HWACC");
- if (hwacc == NULL) {
- _DBG("elm_config_accel_preference_set is not called");
- } else if (strcmp(hwacc, "USE") == 0) {
- elm_config_accel_preference_set("hw");
- _DBG("elm_config_accel_preference_set : hw");
- } else if (strcmp(hwacc, "NOT_USE") == 0) {
- elm_config_accel_preference_set("none");
- _DBG("elm_config_accel_preference_set : none");
- } else {
- _DBG("elm_config_accel_preference_set is not called");
- }
-
- r = appcore_init(ui->name, &efl_ops, *argc, *argv);
- _retv_if(r == -1, -1);
-
- if (_APPFW_FEATURE_BACKGROUND_MANAGEMENT) {
- appcore_get_app_core(&ac);
- ui->app_core = ac;
- SECURE_LOGD("[__SUSPEND__] appcore initialized, appcore addr: #%x", ac);
- }
-
- b = bundle_import_from_argv(*argc, *argv);
- if (b) {
- bg_launch = bundle_get_val(b, AUL_SVC_K_BG_LAUNCH);
- if (bg_launch && strcmp(bg_launch, "enable") == 0)
- __set_bg_state();
-
- bundle_free(b);
- }
-
- LOG(LOG_DEBUG, "LAUNCH", "[%s:Platform:appcore_init:done]", ui->name);
- if (ui->ops && ui->ops->create) {
- traceBegin(TTRACE_TAG_APPLICATION_MANAGER, "APPCORE:CREATE");
- r = ui->ops->create(ui->ops->data);
- traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
- if (r < 0) {
- _ERR("create() return error");
- appcore_exit();
- if (ui->ops && ui->ops->terminate) {
- traceBegin(TTRACE_TAG_APPLICATION_MANAGER,
- "APPCORE:TERMINATE");
- ui->ops->terminate(ui->ops->data);
- traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
- }
- errno = ECANCELED;
- return -1;
- }
- LOG(LOG_DEBUG, "LAUNCH", "[%s:Application:create:done]",
- ui->name);
- }
- ui->state = AS_CREATED;
-
- __add_climsg_cb(ui);
-
- return 0;
-}
-
-static void __after_loop(struct ui_priv *ui)
-{
- appcore_unset_rotation_cb();
- appcore_exit();
-
- if (ui->state == AS_RUNNING) {
- _DBG("[APP %d] PAUSE before termination", _pid);
- if (ui->ops && ui->ops->pause) {
- traceBegin(TTRACE_TAG_APPLICATION_MANAGER,
- "APPCORE:PAUSE");
- ui->ops->pause(ui->ops->data);
- traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
- }
- }
-
- if (ui->ops && ui->ops->terminate) {
- traceBegin(TTRACE_TAG_APPLICATION_MANAGER, "APPCORE:TERMINATE");
- ui->ops->terminate(ui->ops->data);
- traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
- }
-
- ui->state = AS_DYING;
-
- if (ui->hshow)
- ecore_event_handler_del(ui->hshow);
- if (ui->hhide)
- ecore_event_handler_del(ui->hhide);
- if (ui->hvchange)
- ecore_event_handler_del(ui->hvchange);
- if (ui->hlower)
- ecore_event_handler_del(ui->hlower);
-
- __appcore_timer_del(ui);
- __finish_wl();
-
- elm_shutdown();
-
- /* Check loader case */
- if (getenv("AUL_LOADER_INIT")) {
- unsetenv("AUL_LOADER_INIT");
- elm_shutdown();
- }
-}
-
-static int __set_data(struct ui_priv *ui, const char *name,
- struct appcore_ops *ops)
-{
- if (ui->name) {
- _ERR("Mainloop already started");
- errno = EINPROGRESS;
- return -1;
- }
-
- if (name == NULL || name[0] == '\0') {
- _ERR("Invalid name");
- errno = EINVAL;
- return -1;
- }
-
- if (ops == NULL) {
- _ERR("ops is NULL");
- errno = EINVAL;
- return -1;
- }
-
- ui->name = strdup(name);
- _retv_if(ui->name == NULL, -1);
-
- ui->ops = ops;
- ui->mfcb = __appcore_efl_memory_flush_cb;
- _pid = getpid();
-
- /* WM_ROTATE */
- ui->wm_rot_supported = 0;
- ui->rot_started = 0;
- ui->rot_cb = NULL;
- ui->rot_cb_data = NULL;
- ui->rot_mode = APPCORE_RM_UNKNOWN;
-
- if (_APPFW_FEATURE_BACKGROUND_MANAGEMENT) {
- ui->app_core = NULL;
- ui->prepare_to_suspend = __appcore_efl_prepare_to_suspend;
- ui->exit_from_suspend = __appcore_efl_exit_from_suspend;
- }
-
- return 0;
-}
-
-static void __unset_data(struct ui_priv *ui)
-{
- if (ui->name)
- free((void *)ui->name);
-
- memset(ui, 0, sizeof(struct ui_priv));
-}
-
-EXPORT_API int appcore_efl_init(const char *name, int *argc, char ***argv,
- struct appcore_ops *ops)
-{
- int r;
-
- LOG(LOG_DEBUG, "LAUNCH", "[%s:Application:main:done]", name);
-
- r = __set_data(&priv, name, ops);
- _retv_if(r == -1, -1);
-
- r = __before_loop(&priv, argc, argv);
- if (r == -1) {
- aul_status_update(STATUS_DYING);
- __unset_data(&priv);
- return -1;
- }
-
- return 0;
-}
-
-EXPORT_API void appcore_efl_fini(void)
-{
- aul_status_update(STATUS_DYING);
-
- __after_loop(&priv);
-
- __unset_data(&priv);
-}
-
-EXPORT_API int appcore_efl_main(const char *name, int *argc, char ***argv,
- struct appcore_ops *ops)
-{
- int r;
-
- r = appcore_efl_init(name, argc, argv, ops);
- _retv_if(r == -1, -1);
-
- elm_run();
-
- appcore_efl_fini();
-
- return 0;
-}
-
-EXPORT_API int appcore_set_system_resource_reclaiming(bool enable)
-{
- resource_reclaiming = enable;
-
- return 0;
-}
-
-EXPORT_API int appcore_set_app_state(int state)
-{
- priv.state = state;
-
- tmp_val = 1;
-
- return 0;
-}
-
-EXPORT_API int appcore_set_preinit_window_name(const char *win_name)
-{
- int ret = -1;
- void *preinit_window = NULL;
- const Evas *e = NULL;
-
- if (!win_name) {
- _ERR("invalid parameter");
- return ret;
- }
-
- preinit_window = elm_win_precreated_object_get();
- if (!preinit_window) {
- _ERR("Failed to get preinit window");
- return ret;
- }
-
- e = evas_object_evas_get((const Evas_Object *)preinit_window);
- if (e) {
- Ecore_Evas *ee = ecore_evas_ecore_evas_get(e);
- if (ee) {
- ecore_evas_name_class_set(ee, win_name, win_name);
- ret = 0;
- }
- }
-
- return ret;
-}
-
-EXPORT_API unsigned int appcore_get_main_window(void)
-{
- struct win_node *entry = NULL;
-
- if (g_winnode_list != NULL) {
- entry = g_winnode_list->data;
- return (unsigned int) entry->win;
- }
-
- return 0;
-}
-
-EXPORT_API unsigned int appcore_get_main_surface(void)
-{
- struct win_node *entry = NULL;
-
- if (g_winnode_list != NULL) {
- entry = g_winnode_list->data;
- return (unsigned int) entry->surf;
- }
-
- return 0;
-}
-
-tizen_profile_t _get_tizen_profile()
-{
- static tizen_profile_t profile = TIZEN_PROFILE_UNKNOWN;
- if (__builtin_expect(profile != TIZEN_PROFILE_UNKNOWN, 1))
- return profile;
-
- char *profileName;
- system_info_get_platform_string("http://tizen.org/feature/profile", &profileName);
- switch (*profileName) {
- case 'm':
- case 'M':
- profile = TIZEN_PROFILE_MOBILE;
- break;
- case 'w':
- case 'W':
- profile = TIZEN_PROFILE_WEARABLE;
- break;
- case 't':
- case 'T':
- profile = TIZEN_PROFILE_TV;
- break;
- case 'i':
- case 'I':
- profile = TIZEN_PROFILE_IVI;
- break;
- default: // common or unTIZEN_nown ==> ALL ARE COMMON.
- profile = TIZEN_PROFILE_COMMON;
- }
- free(profileName);
-
- return profile;
-}
+++ /dev/null
-#include <Elementary.h>
-#include <stdio.h>
-#include <glib.h>
-#include <aul.h>
-#include <pkgmgr-info.h>
-#include <bundle_internal.h>
-
-#include "appcore-internal.h"
-
-void appcore_group_attach()
-{
- _DBG("appcore_group_attach");
- static bool attached = false;
-
- if (attached)
- return;
-
- int wid = appcore_get_main_surface();
- if (wid == 0) {
- _ERR("window wasn't ready");
- return;
- }
-
- aul_app_group_set_window(wid);
- attached = true;
-}
-
-void appcore_group_lower()
-{
- _DBG("appcore_group_lower");
- int exit = 0;
-
- aul_app_group_lower(&exit);
- if (exit) {
- _DBG("appcore_group_lower : sub-app!");
- elm_exit();
- }
-}
+++ /dev/null
-/*
- * app-core
- *
- * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>, Jaeho Lee <jaeho81.lee@samsung.com>
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-
-#include <locale.h>
-#include <libintl.h>
-#include <stdlib.h>
-#include <errno.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <unistd.h>
-#include <linux/limits.h>
-#include <glib.h>
-#include <vconf.h>
-
-#include "appcore-internal.h"
-
-struct lang_info_s {
- char *parent;
- GList *list;
-};
-
-static int _set;
-static char locale_dir[PATH_MAX];
-
-static void __destroy_lang_info(gpointer data)
-{
- struct lang_info_s *info = (struct lang_info_s *)data;
-
- if (info == NULL)
- return;
-
- if (info->list)
- g_list_free_full(info->list, free);
- if (info->parent)
- free(info->parent);
- free(info);
-}
-
-static struct lang_info_s *__create_lang_info(const char *lang)
-{
- struct lang_info_s *info;
-
- info = calloc(1, sizeof(struct lang_info_s));
- if (info == NULL) {
- _ERR("Out of memory");
- return NULL;
- }
-
- info->parent = strdup(lang);
- if (info->parent == NULL) {
- _ERR("Out of memory");
- free(info);
- return NULL;
- }
-
- return info;
-}
-
-static gint __compare_langs(gconstpointer a, gconstpointer b)
-{
- if (!a || !b)
- return -1;
-
- return strcmp(a, b);
-}
-
-static char *__get_string_before(const char *str, const char *delim)
-{
- char *new_str;
- char *dup_str;
- char *token;
-
- dup_str = strdup(str);
- if (dup_str == NULL)
- return NULL;
-
- token = strtok(dup_str, delim);
- if (token == NULL) {
- free(dup_str);
- return NULL;
- }
-
- new_str = strdup(token);
- free(dup_str);
-
- return new_str;
-}
-
-static GHashTable *__get_lang_table(void)
-{
- GHashTable *table;
- DIR *dp;
- struct dirent *dentry;
- char buf[PATH_MAX];
- struct stat stat_buf;
- int ret;
- char *parent_lang;
- struct lang_info_s *info;
-
- if (locale_dir[0] == 0 || locale_dir[0] == '\0')
- return NULL;
-
- table = g_hash_table_new_full(g_str_hash, g_str_equal,
- NULL, __destroy_lang_info);
- if (table == NULL) {
- _ERR("Out of memory");
- return NULL;
- }
-
- dp = opendir(locale_dir);
- if (dp == NULL) {
- g_hash_table_destroy(table);
- return NULL;
- }
-
- while ((dentry = readdir(dp)) != NULL) {
- if (!strcmp(dentry->d_name, ".") ||
- !strcmp(dentry->d_name, ".."))
- continue;
-
- snprintf(buf, sizeof(buf), "%s/%s", locale_dir, dentry->d_name);
- ret = stat(buf, &stat_buf);
- if (ret != 0 || !S_ISDIR(stat_buf.st_mode))
- continue;
-
- parent_lang = __get_string_before(dentry->d_name, "_");
- if (parent_lang == NULL) {
- _ERR("Out of memory");
- break;
- }
-
- info = g_hash_table_lookup(table, parent_lang);
- if (info == NULL) {
- info = __create_lang_info(parent_lang);
- if (info == NULL) {
- free(parent_lang);
- break;
- }
- g_hash_table_insert(table, info->parent, info);
- }
- info->list = g_list_append(info->list, strdup(dentry->d_name));
- free(parent_lang);
- }
- closedir(dp);
-
- return table;
-}
-
-static GList *__append_langs(const char *lang, GList *list, GHashTable *table)
-{
- struct lang_info_s *info;
- GList *found;
- char *parent_lang = NULL;
- char *extract_lang;
-
- if (lang == NULL)
- return list;
-
- extract_lang = __get_string_before(lang, ".");
- if (extract_lang == NULL)
- return list;
-
- found = g_list_find_custom(list, extract_lang, __compare_langs);
- if (found) {
- list = g_list_remove_link(list, found);
- list = g_list_concat(list, found);
- goto end;
- }
-
- parent_lang = __get_string_before(extract_lang, "_");
- if (parent_lang == NULL)
- goto end;
-
- info = g_hash_table_lookup(table, parent_lang);
- if (info == NULL)
- goto end;
-
- found = g_list_find_custom(info->list, extract_lang, __compare_langs);
- if (found) {
- info->list = g_list_remove_link(info->list, found);
- list = g_list_concat(list, found);
- goto end;
- }
-
- found = g_list_find_custom(info->list, parent_lang, __compare_langs);
- if (found) {
- info->list = g_list_remove_link(info->list, found);
- list = g_list_concat(list, found);
- goto end;
- }
-
- found = g_list_first(info->list);
- if (found) {
- info->list = g_list_remove_link(info->list, found);
- list = g_list_concat(list, found);
- }
-
-end:
- if (extract_lang)
- free(extract_lang);
- if (parent_lang)
- free(parent_lang);
-
- return list;
-}
-
-static GList *__split_language(const char *lang)
-{
- GList *list = NULL;
- char *dup_lang;
- char *token;
-
- dup_lang = strdup(lang);
- if (dup_lang == NULL) {
- _ERR("Out of memory");
- return NULL;
- }
-
- token = strtok(dup_lang, ":");
- while (token != NULL) {
- list = g_list_append(list, strdup(token));
- token = strtok(NULL, ":");
- }
- free(dup_lang);
-
- return list;
-}
-
-static GList *__append_default_langs(GList *list)
-{
- const char *langs[] = {"en_US", "en_GB", "en"};
- unsigned int i;
- GList *found;
-
- for (i = 0; i < (sizeof(langs) / sizeof(langs[0])); i++) {
- found = g_list_find_custom(list, langs[i], __compare_langs);
- if (found == NULL)
- list = g_list_append(list, strdup(langs[i]));
- }
-
- return list;
-}
-
-static char *__get_language(const char *lang)
-{
- GHashTable *table;
- GList *list;
- GList *lang_list = NULL;
- GList *iter;
- char *language;
- char buf[LINE_MAX] = {'\0'};
- size_t n;
-
- list = __split_language(lang);
- if (list == NULL)
- return NULL;
-
- table = __get_lang_table();
- if (table == NULL) {
- g_list_free_full(list, free);
- return NULL;
- }
-
- iter = g_list_first(list);
- while (iter) {
- language = (char *)iter->data;
- lang_list = __append_langs(language, lang_list, table);
- iter = g_list_next(iter);
- }
- g_list_free_full(list, free);
- g_hash_table_destroy(table);
-
- lang_list = __append_default_langs(lang_list);
- iter = g_list_first(lang_list);
- while (iter) {
- language = (char *)iter->data;
- if (language) {
- if (buf[0] == '\0') {
- snprintf(buf, sizeof(buf), "%s", language);
- } else {
- n = sizeof(buf) - strlen(buf) - 1;
- strncat(buf, ":", n);
- n = sizeof(buf) - strlen(buf) - 1;
- strncat(buf, language, n);
- }
- }
- iter = g_list_next(iter);
- }
- g_list_free_full(lang_list, free);
-
- return strdup(buf);
-}
-
-void update_lang(void)
-{
- char *language;
- char *lang;
- char *r;
-
- lang = vconf_get_str(VCONFKEY_LANGSET);
- if (lang) {
- /* TODO: Use VCONFKEY_SETAPPL_LANGUAGES key */
- language = __get_language(lang);
- if (language) {
- _DBG("*****language(%s)", language);
- setenv("LANGUAGE", language, 1);
- free(language);
- } else {
- setenv("LANGUAGE", lang, 1);
- }
- setenv("LANG", lang, 1);
- setenv("LC_MESSAGES", lang, 1);
- r = setlocale(LC_ALL, "");
- if (r == NULL) {
- r = setlocale(LC_ALL, lang);
- if (r != NULL)
- _DBG("*****appcore setlocale=%s\n", r);
- }
- free(lang);
- }
-}
-
-void update_region(void)
-{
- char *region;
- char *r;
-
- region = vconf_get_str(VCONFKEY_REGIONFORMAT);
- if (region) {
- setenv("LC_CTYPE", region, 1);
- setenv("LC_NUMERIC", region, 1);
- setenv("LC_TIME", region, 1);
- setenv("LC_COLLATE", region, 1);
- setenv("LC_MONETARY", region, 1);
- setenv("LC_PAPER", region, 1);
- setenv("LC_NAME", region, 1);
- setenv("LC_ADDRESS", region, 1);
- setenv("LC_TELEPHONE", region, 1);
- setenv("LC_MEASUREMENT", region, 1);
- setenv("LC_IDENTIFICATION", region, 1);
- r = setlocale(LC_ALL, "");
- if (r != NULL)
- _DBG("*****appcore setlocale=%s\n", r);
-
- free(region);
- }
-}
-
-static int __set_i18n(const char *domain, const char *dir)
-{
- char *r;
- char *lan;
-
- if (domain == NULL) {
- errno = EINVAL;
- return -1;
- }
-
- r = setlocale(LC_ALL, "");
- /* if locale is not set properly, try again to set as language base */
- if (r == NULL) {
- lan = vconf_get_str(VCONFKEY_LANGSET);
- if (lan != NULL) {
- r = setlocale(LC_ALL, lan);
- _DBG("*****appcore setlocale=%s\n", r);
- free(lan);
- }
- }
- if (r == NULL)
- _ERR("appcore: setlocale() error");
-
- r = bindtextdomain(domain, dir);
- if (r == NULL)
- _ERR("appcore: bindtextdomain() error");
-
- r = textdomain(domain);
- if (r == NULL)
- _ERR("appcore: textdomain() error");
-
- return 0;
-}
-
-static void __set_locale_dir(const char *dirname)
-{
- if (dirname == NULL)
- return;
-
- snprintf(locale_dir, sizeof(locale_dir), "%s", dirname);
-}
-
-EXPORT_API int appcore_set_i18n(const char *domainname, const char *dirname)
-{
- int r;
-
- __set_locale_dir(dirname);
- update_lang();
- update_region();
-
- r = __set_i18n(domainname, dirname);
- if (r == 0)
- _set = 1;
-
- return r;
-}
-
-int set_i18n(const char *domainname, const char *dirname)
-{
- _retv_if(_set, 0);
-
- __set_locale_dir(dirname);
- update_lang();
- update_region();
-
- return __set_i18n(domainname, dirname);
-}
-
-EXPORT_API int appcore_get_timeformat(enum appcore_time_format *timeformat)
-{
- int r;
-
- if (timeformat == NULL) {
- errno = EINVAL;
- return -1;
- }
-
- r = vconf_get_int(VCONFKEY_REGIONFORMAT_TIME1224, (int *)timeformat);
-
- if (r < 0) {
- *timeformat = APPCORE_TIME_FORMAT_UNKNOWN;
- return -1;
- } else
- return 0;
-}
+++ /dev/null
-/*
- * app-core
- *
- * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>, Jaeho Lee <jaeho81.lee@samsung.com>
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <sys/un.h>
-#include <unistd.h>
-#include <errno.h>
-
-#include <pmapi.h>
-
-#include "appcore-internal.h"
-
-EXPORT_API int appcore_lock_power_state(int s_bits)
-{
- switch (s_bits) {
- case LCD_NORMAL:
- return pm_lock_state(s_bits, GOTO_STATE_NOW, 0);
-
- case LCD_DIM:
- if (pm_lock_state(s_bits, STAY_CUR_STATE, 0) < 0)
- return -1;
- return pm_change_state(LCD_NORMAL);
-
- case LCD_OFF:
- return pm_lock_state(s_bits, STAY_CUR_STATE, 0);
-
- default:
- break;
- }
-
- return -1;
-}
-
-EXPORT_API int appcore_unlock_power_state(int s_bits)
-{
- return pm_unlock_state(s_bits, STAY_CUR_STATE);
-}
+++ /dev/null
-/*
- * app-core
- *
- * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>, Jaeho Lee <jaeho81.lee@samsung.com>
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-
-#include <stdlib.h>
-#include <unistd.h>
-#include <string.h>
-
-#include <sys/mman.h>
-
-#include "appcore-internal.h"
-
-#define GETSP() ({ unsigned int sp; asm volatile ("mov %0,sp " : "=r"(sp)); sp; })
-#define BUF_SIZE 256
-#define PAGE_SIZE (1 << 12)
-#define _ALIGN_UP(addr , size) (((addr)+((size)-1))&(~((size)-1)))
-#define _ALIGN_DOWN(addr , size) ((addr)&(~((size)-1)))
-#define PAGE_ALIGN(addr) _ALIGN_DOWN(addr, PAGE_SIZE)
-
-void stack_trim(void)
-{
-#if sizeof(unsigned int) == sizeof(void*)
- unsigned int sp;
- char buf[BUF_SIZE];
- FILE *file;
- unsigned int stacktop;
- int found = 0;
-
- sp = GETSP();
-
- sprintf(buf, "/proc/%d/maps", getpid());
- file = fopen(buf, "r");
- while (fgets(buf, BUF_SIZE, file) != NULL) {
- if (strstr(buf, "[stack]")) {
- found = 1;
- break;
- }
- }
- fclose(file);
-
- if (found) {
- sscanf(buf, "%x-", &stacktop);
- if (madvise
- ((void *)PAGE_ALIGN(stacktop), PAGE_ALIGN(sp) - stacktop,
- MADV_DONTNEED) < 0)
- perror("stack madvise fail");
- }
-#endif
-}
+++ /dev/null
-/*
- * Copyright (c) 2000 - 2016 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
-#define _GNU_SOURCE
-
-#include <errno.h>
-#include <string.h>
-#include <stdlib.h>
-#include <sys/types.h>
-#include <unistd.h>
-#include <malloc.h>
-#include <locale.h>
-#include <linux/limits.h>
-#include <glib.h>
-#include <sys/time.h>
-#include <dlfcn.h>
-#include <vconf.h>
-#include <aul.h>
-#include <bundle_internal.h>
-#include "appcore-internal.h"
-#include <system_info.h>
-
-#include <gio/gio.h>
-
-#define RESOURCED_FREEZER_PATH "/Org/Tizen/Resourced/Freezer"
-#define RESOURCED_FREEZER_INTERFACE "org.tizen.resourced.freezer"
-#define RESOURCED_FREEZER_SIGNAL "FreezerState"
-
-int __appcore_init_suspend_dbus_handler(void *data);
-void __appcore_fini_suspend_dbus_handler(void);
-
-#define SQLITE_FLUSH_MAX (1024*1024)
-
-#define PATH_LOCALE "locale"
-
-static struct appcore core;
-static pid_t _pid;
-
-static enum appcore_event to_ae[SE_MAX] = {
- APPCORE_EVENT_UNKNOWN, /* SE_UNKNOWN */
- APPCORE_EVENT_LOW_MEMORY, /* SE_LOWMEM */
- APPCORE_EVENT_LOW_BATTERY, /* SE_LOWBAT */
- APPCORE_EVENT_LANG_CHANGE, /* SE_LANGCGH */
- APPCORE_EVENT_REGION_CHANGE,
- APPCORE_EVENT_SUSPENDED_STATE_CHANGE,
- APPCORE_EVENT_UPDATE_REQUESTED,
-};
-
-static int appcore_event_initialized[SE_MAX] = {0,};
-
-enum cb_type { /* callback */
- _CB_NONE,
- _CB_SYSNOTI,
- _CB_APPNOTI,
- _CB_VCONF,
-};
-
-struct evt_ops {
- enum cb_type type;
- union {
- enum appcore_event sys;
- enum app_event app;
- const char *vkey;
- } key;
-
- int (*cb_pre) (void *);
- int (*cb) (void *);
- int (*cb_post) (void *);
-
- int (*vcb_pre) (void *, void *);
- int (*vcb) (void *, void *);
- int (*vcb_post) (void *, void *);
-};
-
-struct open_s {
- int (*callback) (void *);
- void *cbdata;
-};
-
-static struct open_s open;
-
-static int __app_terminate(void *data);
-static int __app_resume(void *data);
-static int __app_reset(void *data, bundle *k);
-
-static int __sys_lowmem_post(void *data, void *evt);
-static int __sys_lowmem(void *data, void *evt);
-static int __sys_lowbatt(void *data, void *evt);
-static int __sys_langchg_pre(void *data, void *evt);
-static int __sys_langchg(void *data, void *evt);
-static int __sys_regionchg_pre(void *data, void *evt);
-static int __sys_regionchg(void *data, void *evt);
-extern void aul_finalize();
-
-
-static struct evt_ops evtops[] = {
- {
- .type = _CB_VCONF,
- .key.vkey = VCONFKEY_SYSMAN_LOW_MEMORY,
- .vcb_post = __sys_lowmem_post,
- .vcb = __sys_lowmem,
- },
- {
- .type = _CB_VCONF,
- .key.vkey = VCONFKEY_SYSMAN_BATTERY_STATUS_LOW,
- .vcb = __sys_lowbatt,
- },
- {
- .type = _CB_VCONF,
- .key.vkey = VCONFKEY_LANGSET,
- .vcb_pre = __sys_langchg_pre,
- .vcb = __sys_langchg,
- },
- {
- .type = _CB_VCONF,
- .key.vkey = VCONFKEY_REGIONFORMAT,
- .vcb_pre = __sys_regionchg_pre,
- .vcb = __sys_regionchg,
- },
- {
- .type = _CB_VCONF,
- .key.vkey = VCONFKEY_REGIONFORMAT_TIME1224,
- .vcb = __sys_regionchg,
- },
-};
-
-static GDBusConnection *bus;
-static guint __suspend_dbus_handler_initialized;
-
-static int __get_locale_resource_dir(char *locale_dir, int size)
-{
- const char *res_path;
-
- res_path = aul_get_app_resource_path();
- if (res_path == NULL) {
- _ERR("Failed to get resource path");
- return -1;
- }
-
- snprintf(locale_dir, size, "%s" PATH_LOCALE, res_path);
- if (access(locale_dir, R_OK) != 0)
- return -1;
-
- return 0;
-}
-
-static int __app_terminate(void *data)
-{
- struct appcore *ac = data;
-
- _retv_if(ac == NULL || ac->ops == NULL, -1);
- _retv_if(ac->ops->cb_app == NULL, 0);
-
- ac->ops->cb_app(AE_TERMINATE, ac->ops->data, NULL);
-
- return 0;
-}
-
-static int __bgapp_terminate(void *data)
-{
- struct appcore *ac = data;
-
- _retv_if(ac == NULL || ac->ops == NULL, -1);
- _retv_if(ac->ops->cb_app == NULL, 0);
-
- ac->ops->cb_app(AE_TERMINATE_BGAPP, ac->ops->data, NULL);
-
- return 0;
-}
-
-static gboolean __prt_ltime(gpointer data)
-{
- int msec;
-
- msec = appcore_measure_time_from(NULL);
- if (msec)
- _DBG("[APP %d] first idle after reset: %d msec", _pid, msec);
-
- return FALSE;
-}
-
-static int __app_reset(void *data, bundle * k)
-{
- struct appcore *ac = data;
- _retv_if(ac == NULL || ac->ops == NULL, -1);
- _retv_if(ac->ops->cb_app == NULL, 0);
-
- g_idle_add(__prt_ltime, ac);
-
- ac->ops->cb_app(AE_RESET, ac->ops->data, k);
-
- return 0;
-}
-
-static int __app_resume(void *data)
-{
- struct appcore *ac = data;
- _retv_if(ac == NULL || ac->ops == NULL, -1);
- _retv_if(ac->ops->cb_app == NULL, 0);
-
- ac->ops->cb_app(AE_RAISE, ac->ops->data, NULL);
- return 0;
-}
-
-static int __app_pause(void *data)
-{
- struct appcore *ac = data;
- _retv_if(ac == NULL || ac->ops == NULL, -1);
- _retv_if(ac->ops->cb_app == NULL, 0);
-
- ac->ops->cb_app(AE_LOWER, ac->ops->data, NULL);
- return 0;
-}
-
-static int __app_update_requested(void *data)
-{
- struct appcore *ac = data;
-
- _retv_if(ac == NULL || ac->ops == NULL, -1);
- _retv_if(ac->ops->cb_app == NULL, 0);
- ac->ops->cb_app(AE_UPDATE_REQUESTED, ac->ops->data, NULL);
-
- return 0;
-}
-
-static int __sys_do_default(struct appcore *ac, enum sys_event event)
-{
- int r;
-
- switch (event) {
- case SE_LOWBAT:
- /*r = __def_lowbatt(ac);*/
- r = 0;
- break;
- default:
- r = 0;
- break;
- };
-
- return r;
-}
-
-static int __sys_do(struct appcore *ac, void *event_info, enum sys_event event)
-{
- struct sys_op *op;
-
- _retv_if(ac == NULL || event >= SE_MAX, -1);
-
- op = &ac->sops[event];
-
- if (op->func == NULL)
- return __sys_do_default(ac, event);
-
- return op->func(event_info, op->data);
-}
-
-static int __sys_lowmem_post(void *data, void *evt)
-{
- keynode_t *key = evt;
- int val;
-
- val = vconf_keynode_get_int(key);
-
- if (val >= VCONFKEY_SYSMAN_LOW_MEMORY_SOFT_WARNING) {
-#if defined(MEMORY_FLUSH_ACTIVATE)
- struct appcore *ac = data;
- ac->ops->cb_app(AE_LOWMEM_POST, ac->ops->data, NULL);
-#else
- malloc_trim(0);
-#endif
- }
- return 0;
-}
-
-static int __sys_lowmem(void *data, void *evt)
-{
- keynode_t *key = evt;
- int val;
-
- val = vconf_keynode_get_int(key);
-
- if (val >= VCONFKEY_SYSMAN_LOW_MEMORY_SOFT_WARNING)
- return __sys_do(data, (void *)&val, SE_LOWMEM);
-
- return 0;
-}
-
-static int __sys_lowbatt(void *data, void *evt)
-{
- keynode_t *key = evt;
- int val;
-
- val = vconf_keynode_get_int(key);
-
- /* VCONFKEY_SYSMAN_BAT_CRITICAL_LOW or VCONFKEY_SYSMAN_POWER_OFF */
- if (val <= VCONFKEY_SYSMAN_BAT_CRITICAL_LOW)
- return __sys_do(data, (void *)&val, SE_LOWBAT);
-
- return 0;
-}
-
-static int __sys_langchg_pre(void *data, void *evt)
-{
- update_lang();
- return 0;
-}
-
-static int __sys_langchg(void *data, void *evt)
-{
- keynode_t *key = evt;
- char *val;
-
- val = vconf_keynode_get_str(key);
-
- return __sys_do(data, (void *)val, SE_LANGCHG);
-}
-
-static int __sys_regionchg_pre(void *data, void *evt)
-{
- update_region();
- return 0;
-}
-
-static int __sys_regionchg(void *data, void *evt)
-{
- keynode_t *key = evt;
- char *val = NULL;
- const char *name;
-
- name = vconf_keynode_get_name(key);
- if (!strcmp(name, VCONFKEY_REGIONFORMAT))
- val = vconf_keynode_get_str(key);
-
- return __sys_do(data, (void *)val, SE_REGIONCHG);
-}
-
-static void __vconf_do(struct evt_ops *eo, keynode_t * key, void *data)
-{
- _ret_if(eo == NULL);
-
- if (eo->vcb_pre)
- eo->vcb_pre(data, key);
-
- if (eo->vcb)
- eo->vcb(data, key);
-
- if (eo->vcb_post)
- eo->vcb_post(data, key);
-}
-
-static void __vconf_cb(keynode_t *key, void *data)
-{
- int i;
- const char *name;
-
- name = vconf_keynode_get_name(key);
- _ret_if(name == NULL);
-
- _DBG("[APP %d] vconf changed: %s", _pid, name);
-
- for (i = 0; i < sizeof(evtops) / sizeof(evtops[0]); i++) {
- struct evt_ops *eo = &evtops[i];
-
- switch (eo->type) {
- case _CB_VCONF:
- if (!strcmp(name, eo->key.vkey))
- __vconf_do(eo, key, data);
- break;
- default:
- /* do nothing */
- break;
- }
- }
-}
-
-static int __add_vconf(struct appcore *ac, enum sys_event se)
-{
- int r;
-
- switch (se) {
- case SE_LOWMEM:
- r = vconf_notify_key_changed(VCONFKEY_SYSMAN_LOW_MEMORY, __vconf_cb, ac);
- break;
- case SE_LOWBAT:
- r = vconf_notify_key_changed(VCONFKEY_SYSMAN_BATTERY_STATUS_LOW, __vconf_cb, ac);
- break;
- case SE_LANGCHG:
- r = vconf_notify_key_changed(VCONFKEY_LANGSET, __vconf_cb, ac);
- break;
- case SE_REGIONCHG:
- r = vconf_notify_key_changed(VCONFKEY_REGIONFORMAT, __vconf_cb, ac);
- if (r < 0)
- break;
-
- r = vconf_notify_key_changed(VCONFKEY_REGIONFORMAT_TIME1224, __vconf_cb, ac);
- break;
- default:
- r = -1;
- break;
- }
-
- return r;
-}
-
-static int __del_vconf(enum sys_event se)
-{
- int r;
-
- switch (se) {
- case SE_LOWMEM:
- r = vconf_ignore_key_changed(VCONFKEY_SYSMAN_LOW_MEMORY, __vconf_cb);
- break;
- case SE_LOWBAT:
- r = vconf_ignore_key_changed(VCONFKEY_SYSMAN_BATTERY_STATUS_LOW, __vconf_cb);
- break;
- case SE_LANGCHG:
- r = vconf_ignore_key_changed(VCONFKEY_LANGSET, __vconf_cb);
- break;
- case SE_REGIONCHG:
- r = vconf_ignore_key_changed(VCONFKEY_REGIONFORMAT, __vconf_cb);
- if (r < 0)
- break;
-
- r = vconf_ignore_key_changed(VCONFKEY_REGIONFORMAT_TIME1224, __vconf_cb);
- break;
- default:
- r = -1;
- break;
- }
-
- return r;
-}
-
-static int __del_vconf_list(void)
-{
- int r;
- enum sys_event se;
-
- for (se = SE_LOWMEM; se < SE_MAX; se++) {
- if (appcore_event_initialized[se]) {
- r = __del_vconf(se);
- if (r < 0)
- _ERR("Delete vconf callback failed");
- else
- appcore_event_initialized[se] = 0;
- }
- }
-
- return 0;
-}
-
-static gboolean __flush_memory(gpointer data)
-{
- int suspend = APPCORE_SUSPENDED_STATE_WILL_ENTER_SUSPEND;
- struct appcore *ac = (struct appcore *)data;
-
- appcore_flush_memory();
-
- if (!ac)
- return FALSE;
-
- ac->tid = 0;
-
- if (!ac->allowed_bg && !ac->suspended_state) {
- _DBG("[__SUSPEND__] flush case");
- __sys_do(ac, &suspend, SE_SUSPENDED_STATE);
- ac->suspended_state = true;
- }
-
- return FALSE;
-}
-
-static void __add_suspend_timer(struct appcore *ac)
-{
- ac->tid = g_timeout_add_seconds(5, __flush_memory, ac);
-}
-
-static void __remove_suspend_timer(struct appcore *ac)
-{
- if (ac->tid > 0) {
- g_source_remove(ac->tid);
- ac->tid = 0;
- }
-}
-
-static int __aul_handler(aul_type type, bundle *b, void *data)
-{
- int ret;
- const char **tep_path = NULL;
- int len = 0;
- int i;
- const char *bg = NULL;
- struct appcore *ac = data;
- int suspend = APPCORE_SUSPENDED_STATE_DID_EXIT_FROM_SUSPEND;
-
- switch (type) {
- case AUL_START:
- _DBG("[APP %d] AUL event: AUL_START", _pid);
- tep_path = bundle_get_str_array(b, AUL_TEP_PATH, &len);
- if (tep_path) {
- for (i = 0; i < len; i++) {
- ret = aul_check_tep_mount(tep_path[i]);
- if (ret == -1) {
- _ERR("mount request not completed within 1 sec");
- exit(-1);
- }
- }
- }
-
- if (_APPFW_FEATURE_BACKGROUND_MANAGEMENT) {
- bg = bundle_get_val(b, AUL_K_ALLOWED_BG);
- if (bg && strncmp(bg, "ALLOWED_BG", strlen("ALLOWED_BG")) == 0) {
- _DBG("[__SUSPEND__] allowed background");
- ac->allowed_bg = true;
- __remove_suspend_timer(data);
- }
- }
-
- __app_reset(data, b);
- break;
- case AUL_RESUME:
- _DBG("[APP %d] AUL event: AUL_RESUME", _pid);
- if (_APPFW_FEATURE_BACKGROUND_MANAGEMENT) {
- bg = bundle_get_val(b, AUL_K_ALLOWED_BG);
- if (bg && strncmp(bg, "ALLOWED_BG", strlen("ALLOWED_BG")) == 0) {
- _DBG("[__SUSPEND__] allowed background");
- ac->allowed_bg = true;
- __remove_suspend_timer(data);
- }
- }
-
- if (open.callback) {
- ret = open.callback(open.cbdata);
- if (ret == 0)
- __app_resume(data);
- } else {
- __app_resume(data);
- }
- break;
- case AUL_TERMINATE:
- _DBG("[APP %d] AUL event: AUL_TERMINATE", _pid);
- if (_APPFW_FEATURE_BACKGROUND_MANAGEMENT && !ac->allowed_bg)
- __remove_suspend_timer(data);
-
- __app_terminate(data);
- break;
- case AUL_TERMINATE_BGAPP:
- _DBG("[APP %d] AUL event: AUL_TERMINATE_BGAPP", _pid);
- if (_APPFW_FEATURE_BACKGROUND_MANAGEMENT && !ac->allowed_bg)
- __remove_suspend_timer(data);
-
- __bgapp_terminate(data);
- break;
- case AUL_PAUSE:
- _DBG("[APP %d] AUL event: AUL_PAUSE", _pid);
- __app_pause(data);
- break;
- case AUL_WAKE:
- if (_APPFW_FEATURE_BACKGROUND_MANAGEMENT) {
- _DBG("[APP %d] AUL event: AUL_WAKE", _pid);
- if (!ac->allowed_bg && ac->suspended_state) {
- __remove_suspend_timer(data);
- __sys_do(ac, &suspend, SE_SUSPENDED_STATE);
- ac->suspended_state = false;
- }
- if (b) {
- bg = bundle_get_val(b, AUL_K_ALLOWED_BG);
- if (bg && strcmp(bg, "ALLOWED_BG") == 0) {
- _DBG("[__SUSPEND__] allowed background");
- ac->allowed_bg = true;
- }
- }
- break;
- }
- goto __default__;
- case AUL_SUSPEND:
- if (_APPFW_FEATURE_BACKGROUND_MANAGEMENT) {
- _DBG("[APP %d] AUL event: AUL_SUSPEND", _pid);
- ac->allowed_bg = false;
- if (!ac->suspended_state) {
- __remove_suspend_timer(data);
- __flush_memory((gpointer)ac);
- }
- break;
- }
- goto __default__;
- case AUL_UPDATE_REQUESTED:
- _DBG("[APP %d] AUL event: AUL_UPDATE_REQUESTED", _pid);
- __app_update_requested(data);
- break;
-__default__:
- default:
- _DBG("[APP %d] AUL event: %d", _pid, type);
- /* do nothing */
- break;
- }
-
- return 0;
-}
-
-
-static void __clear(struct appcore *ac)
-{
- memset(ac, 0, sizeof(struct appcore));
-}
-
-EXPORT_API void appcore_get_app_core(struct appcore **ac)
-{
- *ac = &core;
-}
-
-EXPORT_API int appcore_set_open_cb(int (*cb) (void *),
- void *data)
-{
- open.callback = cb;
- open.cbdata = data;
-
- return 0;
-}
-
-EXPORT_API int appcore_set_event_callback(enum appcore_event event,
- int (*cb) (void *, void *), void *data)
-{
- struct appcore *ac = &core;
- struct sys_op *op;
- enum sys_event se;
- int r = 0;
-
- for (se = SE_UNKNOWN; se < SE_MAX; se++) {
- if (event == to_ae[se])
- break;
- }
-
- if (se == SE_UNKNOWN || se >= SE_MAX) {
- _ERR("Unregistered event");
- errno = EINVAL;
- return -1;
- }
-
- op = &ac->sops[se];
-
- op->func = cb;
- op->data = data;
-
- if (op->func && !appcore_event_initialized[se]) {
- r = __add_vconf(ac, se);
- if (r < 0)
- _ERR("Add vconf callback failed");
- else
- appcore_event_initialized[se] = 1;
- } else if (!op->func && appcore_event_initialized[se]) {
- r = __del_vconf(se);
- if (r < 0)
- _ERR("Delete vconf callback failed");
- else
- appcore_event_initialized[se] = 0;
- }
-
- return 0;
-}
-
-static gboolean __init_suspend(gpointer data)
-{
- int r;
-
- r = __appcore_init_suspend_dbus_handler(&core);
- if (r == -1) {
- _ERR("Initailzing suspended state handler failed");
- }
-
- return FALSE;
-}
-
-EXPORT_API int appcore_init(const char *name, const struct ui_ops *ops,
- int argc, char **argv)
-{
- int r;
- char locale_dir[PATH_MAX];
-
- if (core.state != 0) {
- _ERR("Already in use");
- errno = EALREADY;
- return -1;
- }
-
- if (ops == NULL || ops->cb_app == NULL) {
- _ERR("ops or callback function is null");
- errno = EINVAL;
- return -1;
- }
-
- r = __get_locale_resource_dir(locale_dir, sizeof(locale_dir));
- r = set_i18n(name, locale_dir);
- _retv_if(r == -1, -1);
-
- r = aul_launch_init(__aul_handler, &core);
- if (r < 0) {
- _ERR("Aul init failed: %d", r);
- goto err;
- }
-
- r = aul_launch_argv_handler(argc, argv);
- if (r < 0) {
- _ERR("Aul argv handler failed: %d", r);
- goto err;
- }
-
- core.ops = ops;
- core.state = 1; /* TODO: use enum value */
- core.tid = 0;
- core.suspended_state = false;
- core.allowed_bg = false;
-
- _pid = getpid();
-
- if (_APPFW_FEATURE_BACKGROUND_MANAGEMENT)
- g_idle_add(__init_suspend, NULL);
-
- return 0;
- err:
- __del_vconf_list();
- __clear(&core);
- return -1;
-}
-
-EXPORT_API void appcore_exit(void)
-{
- if (core.state) {
- __del_vconf_list();
- __clear(&core);
- if (_APPFW_FEATURE_BACKGROUND_MANAGEMENT) {
- __remove_suspend_timer(&core);
- __appcore_fini_suspend_dbus_handler();
- }
- }
- aul_finalize();
-}
-
-EXPORT_API int appcore_flush_memory(void)
-{
- int (*flush_fn) (int);
-
- struct appcore *ac = &core;
-
- if (!core.state) {
- _ERR("Appcore not initialized");
- return -1;
- }
-
- _DBG("[APP %d] Flushing memory ...", _pid);
-
- if (ac->ops->cb_app)
- ac->ops->cb_app(AE_MEM_FLUSH, ac->ops->data, NULL);
-
- flush_fn = dlsym(RTLD_DEFAULT, "sqlite3_release_memory");
- if (flush_fn)
- flush_fn(SQLITE_FLUSH_MAX);
-
- malloc_trim(0);
- /*
- *Disabled - the impact of stack_trim() is unclear
- *stack_trim();
- */
-
- _DBG("[APP %d] Flushing memory DONE", _pid);
-
- return 0;
-}
-
-static void __suspend_dbus_signal_handler(GDBusConnection *connection,
- const gchar *sender_name,
- const gchar *object_path,
- const gchar *interface_name,
- const gchar *signal_name,
- GVariant *parameters,
- gpointer user_data)
-{
- struct appcore *ac = (struct appcore *)user_data;
- gint suspend = APPCORE_SUSPENDED_STATE_DID_EXIT_FROM_SUSPEND;
- gint pid;
- gint status;
-
- if (g_strcmp0(signal_name, RESOURCED_FREEZER_SIGNAL) == 0) {
- g_variant_get(parameters, "(ii)", &status, &pid);
- if (pid == getpid() && status == 0) { /* thawed */
- if (ac && !ac->allowed_bg && ac->suspended_state) {
- __remove_suspend_timer(ac);
- __sys_do(ac, &suspend, SE_SUSPENDED_STATE);
- ac->suspended_state = false;
- __add_suspend_timer(ac);
- }
- }
- }
-}
-
-int __appcore_init_suspend_dbus_handler(void *data)
-{
- GError *err = NULL;
-
- if (__suspend_dbus_handler_initialized)
- return 0;
-
- if (!bus) {
- bus = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &err);
- if (!bus) {
- _ERR("Failed to connect to the D-BUS daemon: %s",
- err->message);
- g_error_free(err);
- return -1;
- }
- }
-
- __suspend_dbus_handler_initialized = g_dbus_connection_signal_subscribe(
- bus,
- NULL,
- RESOURCED_FREEZER_INTERFACE,
- RESOURCED_FREEZER_SIGNAL,
- RESOURCED_FREEZER_PATH,
- NULL,
- G_DBUS_SIGNAL_FLAGS_NONE,
- __suspend_dbus_signal_handler,
- data,
- NULL);
- if (__suspend_dbus_handler_initialized == 0) {
- _ERR("g_dbus_connection_signal_subscribe() is failed.");
- return -1;
- }
-
- _DBG("[__SUSPEND__] suspend signal initialized");
-
- return 0;
-}
-
-void __appcore_fini_suspend_dbus_handler(void)
-{
- if (bus == NULL)
- return;
-
- if (__suspend_dbus_handler_initialized) {
- g_dbus_connection_signal_unsubscribe(bus,
- __suspend_dbus_handler_initialized);
- __suspend_dbus_handler_initialized = 0;
- }
-
- g_object_unref(bus);
- bus = NULL;
-}
-
-tizen_profile_t _get_tizen_profile()
-{
- static tizen_profile_t profile = TIZEN_PROFILE_UNKNOWN;
- if (__builtin_expect(profile != TIZEN_PROFILE_UNKNOWN, 1))
- return profile;
-
- char *profileName;
- system_info_get_platform_string("http://tizen.org/feature/profile", &profileName);
- switch (*profileName) {
- case 'm':
- case 'M':
- profile = TIZEN_PROFILE_MOBILE;
- break;
- case 'w':
- case 'W':
- profile = TIZEN_PROFILE_WEARABLE;
- break;
- case 't':
- case 'T':
- profile = TIZEN_PROFILE_TV;
- break;
- case 'i':
- case 'I':
- profile = TIZEN_PROFILE_IVI;
- break;
- default: // common or unTIZEN_nown ==> ALL ARE COMMON.
- profile = TIZEN_PROFILE_COMMON;
- }
- free(profileName);
-
- return profile;
-}
return 0;
}
+EXPORT_API int appcore_base_set_i18n(const char *domain_name, const char *dir_name)
+{
+ return __set_i18n(domain_name, dir_name);
+}
+
EXPORT_API int appcore_base_init(appcore_base_ops ops, int argc, char **argv, void *data)
{
int i;
--- /dev/null
+/*
+ * Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+
+#include <glib-object.h>
+#include <malloc.h>
+#include <glib.h>
+#include <gio/gio.h>
+#include <stdbool.h>
+#include <Elementary.h>
+
+#include "appcore-internal.h"
+#include "appcore-efl.h"
+#include "appcore_ui_base.h"
+#include <system_info.h>
+
+struct appcore_efl_context {
+ struct appcore_ops ops;
+};
+
+static struct appcore_efl_context __context;
+
+static int __ui_app_create(void *data)
+{
+ appcore_ui_base_on_create();
+
+ if (__context.ops.create) {
+ if (__context.ops.create(__context.ops.data) < 0)
+ return -1;
+ }
+
+ return 0;
+}
+
+static int __ui_app_terminate(void *data)
+{
+ appcore_ui_base_on_terminate();
+
+ if (__context.ops.terminate)
+ __context.ops.terminate(__context.ops.data);
+
+ return 0;
+}
+
+static int __ui_app_control(bundle *b, void *data)
+{
+ appcore_ui_base_on_control(b);
+
+ if (__context.ops.reset)
+ __context.ops.reset(b, __context.ops.data);
+
+ return 0;
+}
+
+static int __ui_app_pause(void *data)
+{
+ appcore_ui_base_on_pause();
+
+ if (__context.ops.pause)
+ __context.ops.pause(__context.ops.data);
+ return 0;
+}
+
+static int __ui_app_resume(void *data)
+{
+ appcore_ui_base_on_resume();
+
+ if (__context.ops.resume)
+ __context.ops.resume(__context.ops.data);
+ return 0;
+}
+
+EXPORT_API int appcore_efl_init(const char *name, int *argc, char ***argv,
+ struct appcore_ops *ops)
+{
+ int ret;
+ appcore_ui_base_ops ui_ops = appcore_ui_base_get_default_ops();
+
+ /* override methods */
+ ui_ops.base.create = __ui_app_create;
+ ui_ops.base.control = __ui_app_control;
+ ui_ops.base.terminate = __ui_app_terminate;
+ ui_ops.pause = __ui_app_pause;
+ ui_ops.resume = __ui_app_resume;
+ ui_ops.base.run = NULL;
+
+ __context.ops = *ops;
+
+ ret = appcore_ui_base_init(ui_ops, *argc, *argv, NULL,
+ APPCORE_UI_BASE_HINT_WINDOW_GROUP_CONTROL |
+ APPCORE_UI_BASE_HINT_WINDOW_STACK_CONTROL |
+ APPCORE_UI_BASE_HINT_BG_LAUNCH_CONTROL |
+ APPCORE_UI_BASE_HINT_HW_ACC_CONTROL);
+
+ return ret;
+}
+
+EXPORT_API void appcore_efl_fini(void)
+{
+ appcore_ui_base_fini();
+}
+
+EXPORT_API int appcore_efl_main(const char *name, int *argc, char ***argv,
+ struct appcore_ops *ops)
+{
+ int r;
+
+ r = appcore_efl_init(name, argc, argv, ops);
+
+ if (r >= 0)
+ elm_run();
+
+ appcore_efl_fini();
+
+ return 0;
+}
+
+EXPORT_API void appcore_group_attach()
+{
+ appcore_ui_base_group_add();
+}
+
+EXPORT_API void appcore_group_lower()
+{
+ appcore_ui_base_group_remove();
+}
+
+EXPORT_API unsigned int appcore_get_main_window(void)
+{
+ return appcore_ui_base_get_main_window();
+}
+
+EXPORT_API unsigned int appcore_get_main_surface(void)
+{
+ return appcore_get_main_surface();
+}
+
+EXPORT_API int appcore_set_system_resource_reclaiming(bool enable)
+{
+ return 0;
+}
+
+
--- /dev/null
+/*
+ * Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <locale.h>
+#include <libintl.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <linux/limits.h>
+#include <glib.h>
+#include <vconf.h>
+
+#include "appcore-internal.h"
+#include "appcore_base.h"
+
+EXPORT_API int appcore_set_i18n(const char *domainname, const char *dirname)
+{
+ return appcore_base_set_i18n(domainname, dirname);
+}
+
+EXPORT_API int appcore_get_timeformat(enum appcore_time_format *timeformat)
+{
+ int r;
+
+ if (timeformat == NULL) {
+ errno = EINVAL;
+ return -1;
+ }
+
+ r = vconf_get_int(VCONFKEY_REGIONFORMAT_TIME1224, (int *)timeformat);
+
+ if (r < 0) {
+ *timeformat = APPCORE_TIME_FORMAT_UNKNOWN;
+ return -1;
+ }
+
+ return 0;
+}
/*
- * app-core
- *
- * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>, Jaeho Lee <jaeho81.lee@samsung.com>
+ * Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- *
*/
-
#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>
/*
- * app-core
- *
- * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>, Jaeho Lee <jaeho81.lee@samsung.com>
+ * Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- *
*/
-
#include <errno.h>
#include <stdlib.h>
#include <unistd.h>
#include <sensor_internal.h>
#include <vconf.h>
-#include <Ecore.h>
#include "appcore-internal.h"
struct rot_s {
return 0;
}
-EXPORT_API int appcore_pause_rotation_cb(void)
-{
- if (rot.wm_rotate)
- return rot.wm_rotate->pause_rotation_cb();
- else {
- bool r;
- _retv_if(rot.callback == NULL, 0);
- _DBG("[APP %d] appcore_pause_rotation_cb is called", getpid());
-
- __del_rotlock();
-
- if (rot.cb_set) {
- r = sensord_unregister_event(rot.handle,
- AUTO_ROTATION_CHANGE_STATE_EVENT);
- if (!r) {
- _ERR("sensord_unregister_event failed");
- return -1;
- }
- rot.cb_set = 0;
- }
-
- if (rot.sensord_started == 1) {
- r = sensord_stop(rot.handle);
- if (!r) {
- _ERR("sensord_stop failed");
- return -1;
- }
- rot.sensord_started = 0;
- }
- }
-
- return 0;
-}
-
-EXPORT_API int appcore_resume_rotation_cb(void)
-{
- if (rot.wm_rotate)
- return rot.wm_rotate->resume_rotation_cb();
- else {
- bool r;
- enum appcore_rm m;
-
- _retv_if(rot.callback == NULL, 0);
- _DBG("[APP %d] appcore_resume_rotation_cb is called", getpid());
-
- if (rot.cb_set == 0) {
- r = sensord_register_event(rot.handle,
- AUTO_ROTATION_CHANGE_STATE_EVENT,
- SENSOR_INTERVAL_NORMAL, 0, __changed_cb, rot.cbdata);
- if (!r) {
- _ERR("sensord_register_event failed");
- return -1;
- }
- rot.cb_set = 1;
- }
-
- if (rot.sensord_started == 0) {
- r = sensord_start(rot.handle, 0);
- if (!r) {
- _ERR("sensord_start failed");
- r = sensord_unregister_event(rot.handle,
- AUTO_ROTATION_CHANGE_STATE_EVENT);
- if (!r)
- _ERR("sensord_unregister_event failed");
- rot.cb_set = 0;
- return -1;
- }
- rot.sensord_started = 1;
- }
-
- __add_rotlock(rot.cbdata);
-
- r = appcore_get_rotation_state(&m);
- _DBG("[APP %d] Rotmode prev %d -> curr %d", getpid(), rot.mode, m);
- if (!r && rot.mode != m && rot.lock == 0) {
- rot.callback((void *)&m, m, rot.cbdata);
- rot.mode = m;
- }
- }
- return 0;
-}
-
-EXPORT_API int appcore_set_wm_rotation(struct ui_wm_rotate* wm_rotate)
-{
- if (!wm_rotate) return -1;
-
- if (rot.callback) {
- wm_rotate->set_rotation_cb(rot.callback, rot.cbdata);
- appcore_unset_rotation_cb();
- }
- rot.wm_rotate = wm_rotate;
- _DBG("[APP %d] Support wm rotate:%p", getpid(), wm_rotate);
- return 0;
-}
--- /dev/null
+/*
+ * Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#define _GNU_SOURCE
+
+#include <errno.h>
+#include <string.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <malloc.h>
+#include <linux/limits.h>
+#include <glib.h>
+#include <sys/time.h>
+#include <dlfcn.h>
+#include <vconf.h>
+#include <bundle_internal.h>
+#include <system_info.h>
+#include <gio/gio.h>
+
+#include "appcore-internal.h"
+#include "appcore-common.h"
+#include "appcore_base.h"
+
+#define SQLITE_FLUSH_MAX (1024*1024)
+
+static appcore_base_event_h __handles[APPCORE_BASE_EVENT_MAX];
+static int __convertor[] = {
+ [APPCORE_EVENT_UNKNOWN] = APPCORE_BASE_EVENT_START,
+ [APPCORE_EVENT_LOW_MEMORY] = APPCORE_BASE_EVENT_LOW_MEMORY,
+ [APPCORE_EVENT_LOW_BATTERY] = APPCORE_BASE_EVENT_LOW_BATTERY,
+ [APPCORE_EVENT_LANG_CHANGE] = APPCORE_BASE_EVENT_LANG_CHANGE,
+ [APPCORE_EVENT_REGION_CHANGE] = APPCORE_BASE_EVENT_REGION_CHANGE,
+ [APPCORE_EVENT_SUSPENDED_STATE_CHANGE] = APPCORE_BASE_EVENT_SUSPENDED_STATE_CHANGE,
+ [APPCORE_EVENT_UPDATE_REQUESTED] = APPCORE_BASE_EVENT_UPDATE_REQUESTED,
+};
+
+struct appcore_context {
+ struct ui_ops ops;
+};
+
+static struct appcore_context __context;
+
+EXPORT_API int appcore_set_event_callback(enum appcore_event event,
+ int (*cb) (void *, void *), void *data)
+{
+ if (__handles[event])
+ appcore_base_remove_event(__handles[event]);
+ __handles[event] = appcore_base_add_event((enum appcore_base_event)__convertor[event], cb, data);
+
+ return 0;
+}
+
+static int __app_create(void *data)
+{
+ appcore_base_on_create();
+
+ if (__context.ops.cb_app == NULL)
+ return -1;
+
+ __context.ops.cb_app(AE_CREATE, __context.ops.data, NULL);
+ return 0;
+}
+
+static int __app_terminate(void *data)
+{
+ appcore_base_on_terminate();
+
+ if (__context.ops.cb_app)
+ __context.ops.cb_app(AE_TERMINATE, __context.ops.data, NULL);
+
+ return 0;
+}
+
+static int __app_control(bundle *b, void *data)
+{
+ appcore_base_on_control(b);
+
+ if (__context.ops.cb_app)
+ __context.ops.cb_app(AE_RESET, __context.ops.data, b);
+
+ return 0;
+}
+
+EXPORT_API int appcore_init(const char *name, const struct ui_ops *ops,
+ int argc, char **argv)
+{
+ appcore_base_ops base_ops = appcore_base_get_default_ops();
+
+ /* override methods */
+ base_ops.create = __app_create;
+ base_ops.terminate = __app_terminate;
+ base_ops.control = __app_control;
+ base_ops.run = NULL;
+ base_ops.exit = NULL;
+
+ __context.ops = *ops;
+
+ return appcore_base_init(base_ops, argc, argv, NULL);
+}
+
+EXPORT_API void appcore_exit(void)
+{
+ appcore_base_fini();
+}
+
+EXPORT_API int appcore_flush_memory(void)
+{
+ int (*flush_fn) (int);
+
+ _DBG("[APP %d] Flushing memory ...", getpid());
+ if (__context.ops.cb_app)
+ __context.ops.cb_app(AE_MEM_FLUSH, __context.ops.data, NULL);
+
+ flush_fn = dlsym(RTLD_DEFAULT, "sqlite3_release_memory");
+ if (flush_fn)
+ flush_fn(SQLITE_FLUSH_MAX);
+
+ malloc_trim(0);
+ _DBG("[APP %d] Flushing memory DONE", getpid());
+
+ return 0;
+}
+
static void __group_attach()
{
- static bool attached = false;
+ if (!(__context.hint & APPCORE_UI_BASE_HINT_WINDOW_GROUP_CONTROL))
+ return;
+ appcore_ui_base_group_add();
+}
+
+static void __group_lower()
+{
if (!(__context.hint & APPCORE_UI_BASE_HINT_WINDOW_GROUP_CONTROL))
return;
+ appcore_ui_base_group_remove();
+}
+
+EXPORT_API void appcore_ui_base_group_add()
+{
+ static bool attached = false;
_DBG("__group_attach");
if (attached)
attached = true;
}
-static void __group_lower()
+EXPORT_API void appcore_ui_base_group_remove()
{
int exit = 0;
- if (!(__context.hint & APPCORE_UI_BASE_HINT_WINDOW_GROUP_CONTROL))
- return;
-
_DBG("__group_lower");
aul_app_group_lower(&exit);
if (exit) {
__context.ops.base.exit(__context.data);
}
+EXPORT_API unsigned int appcore_ui_base_get_main_window(void)
+{
+ return __get_main_window();
+}
+
+EXPORT_API unsigned int appcore_ui_base_get_main_surface(void)
+{
+ return __get_main_surface();
+}
+
static int __on_receive(aul_type type, bundle *b, void *data)
{
return appcore_ui_base_on_receive(type, b);