Refactor appcore legacy api to cpp 04/274604/8
authorChanggyu Choi <changyu.choi@samsung.com>
Tue, 3 May 2022 08:19:38 +0000 (17:19 +0900)
committerChanggyu Choi <changyu.choi@samsung.com>
Thu, 9 Jun 2022 01:56:03 +0000 (10:56 +0900)
Some tizen appcore apps use a mixture defferent level APIs.
This patch is for compatibility between different levels of appcore API.

Change-Id: If39765cb2eff5cbb36118a2cc89323098bd856fc
Signed-off-by: Changgyu Choi <changyu.choi@samsung.com>
CMakeLists.txt
legacy/CMakeLists.txt
legacy/include/appcore_base.h
legacy/src/base/appcore_base.c [deleted file]
legacy/src/efl_base/appcore_efl_base.c [deleted file]
legacy/src/legacy/appcore-efl.c [deleted file]
legacy/src/legacy/appcore.c
legacy/src/legacy/appcore_base.cc [new file with mode: 0644]
legacy/src/legacy/appcore_efl.cc [new file with mode: 0644]
tizen-cpp/app-core-cpp/CMakeLists.txt

index e491eaf..a21670c 100644 (file)
@@ -50,8 +50,10 @@ PKG_CHECK_MODULES(VCONF_DEPS REQUIRED vconf)
 PKG_CHECK_MODULES(WAYLAND_CLIENT_DEPS REQUIRED wayland-client)
 PKG_CHECK_MODULES(WAYLAND_TBM_CLIENT_DEPS REQUIRED wayland-tbm-client)
 
-ADD_SUBDIRECTORY(legacy)
 ADD_SUBDIRECTORY(tizen-cpp)
+ADD_SUBDIRECTORY(legacy)
+ADD_DEPENDENCIES(appcore-common app-core-cpp)
+ADD_DEPENDENCIES(appcore-common app-core-efl-cpp)
 
 IF(NOT DEFINED MINIMUM_BUILD)
 ENABLE_TESTING()
index 622e737..d7dd697 100644 (file)
@@ -1,5 +1,5 @@
 CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
-PROJECT(appcore C)
+PROJECT(appcore C CXX)
 
 SET(PREFIX ${CMAKE_INSTALL_PREFIX})
 SET(EXEC_PREFIX "\${prefix}")
@@ -16,6 +16,7 @@ SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -g -Wall")
 SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -Wl,--as-needed")
 SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -Werror")
 SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
+SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS}")
 
 SET(CMAKE_SKIP_BUILD_RPATH TRUE)
 
@@ -28,7 +29,7 @@ SET(SRCS_common
        src/legacy/appcore-measure.c
        src/legacy/appcore-rotation.c
        src/legacy/appcore-i18n.c
-       src/base/appcore_base.c
+       src/legacy/appcore_base.cc
        src/base/appcore_base_control.c
        src/watchdog/appcore_watchdog.c)
 
@@ -51,8 +52,9 @@ ADD_LIBRARY(${APPCORE_COMMON} SHARED ${SRCS_common})
 SET_TARGET_PROPERTIES(${APPCORE_COMMON} PROPERTIES SOVERSION ${MAJORVER})
 SET_TARGET_PROPERTIES(${APPCORE_COMMON} PROPERTIES VERSION ${FULLVER})
 SET_TARGET_PROPERTIES(${APPCORE_COMMON} PROPERTIES COMPILE_FLAGS ${EXTRA_CFLAGS_common})
-TARGET_LINK_LIBRARIES(${APPCORE_COMMON} ${pkg_common_LDFLAGS} "-ldl")
+TARGET_LINK_LIBRARIES(${APPCORE_COMMON} ${pkg_common_LDFLAGS} "-ldl" app-core-cpp)
 
+TARGET_INCLUDE_DIRECTORIES(${APPCORE_COMMON} PUBLIC ${CMAKE_SOURCE_DIR}/tizen-cpp/app-core-cpp/)
 CONFIGURE_FILE(${APPCORE_COMMON}.pc.in ${APPCORE_COMMON}.pc @ONLY)
 
 INSTALL(TARGETS ${APPCORE_COMMON} DESTINATION ${LIB_INSTALL_DIR} COMPONENT RuntimeLibraries)
@@ -95,7 +97,7 @@ ENDFOREACH(hfile)
 # Build appcore-efl Library
 # ------------------------------
 SET(APPCORE_EFL "appcore-efl")
-SET(SRCS_efl src/legacy/appcore-efl.c src/efl_base/appcore_efl_base.c)
+SET(SRCS_efl src/legacy/appcore_efl.cc)
 SET(HEADERS_efl appcore-efl.h appcore_efl_base.h)
 
 INCLUDE(FindPkgConfig)
@@ -111,8 +113,9 @@ ADD_LIBRARY(${APPCORE_EFL} SHARED ${SRCS_efl})
 SET_TARGET_PROPERTIES(${APPCORE_EFL} PROPERTIES SOVERSION ${MAJORVER})
 SET_TARGET_PROPERTIES(${APPCORE_EFL} PROPERTIES VERSION ${FULLVER})
 SET_TARGET_PROPERTIES(${APPCORE_EFL} PROPERTIES COMPILE_FLAGS ${EXTRA_CFLAGS_efl})
-TARGET_LINK_LIBRARIES(${APPCORE_EFL} ${pkg_efl_LDFLAGS} ${APPCORE_UI})
+TARGET_LINK_LIBRARIES(${APPCORE_EFL} ${pkg_efl_LDFLAGS} ${APPCORE_UI} app-core-efl-cpp)
 
+TARGET_INCLUDE_DIRECTORIES(${APPCORE_EFL} PUBLIC ${CMAKE_SOURCE_DIR}/tizen-cpp/app-core-efl-cpp/)
 CONFIGURE_FILE(${APPCORE_EFL}.pc.in ${APPCORE_EFL}.pc @ONLY)
 
 INSTALL(TARGETS ${APPCORE_EFL} DESTINATION ${LIB_INSTALL_DIR} COMPONENT RuntimeLibraries)
index 760cade..e1d927f 100644 (file)
@@ -97,9 +97,9 @@ appcore_base_ops appcore_base_get_default_ops(void);
 appcore_base_event_h appcore_base_add_event(enum appcore_base_event event,
                appcore_base_event_cb cb, void *data);
 int appcore_base_remove_event(appcore_base_event_h handle);
-int appcore_base_raise_event(void *event, enum appcore_base_event type);
+int appcore_base_raise_event(voidevent, enum appcore_base_event type);
 int appcore_base_flush_memory(void);
-int appcore_base_get_rotation_state(enum appcore_base_rm *curr);
+int appcore_base_get_rotation_state(enum appcore_base_rmcurr);
 bool appcore_base_is_bg_allowed(void);
 bool appcore_base_is_suspended(void);
 void appcore_base_toggle_suspended_state(void);
@@ -113,5 +113,3 @@ int appcore_base_get_display_state(void);
 #ifdef __cplusplus
 }
 #endif
-
-
diff --git a/legacy/src/base/appcore_base.c b/legacy/src/base/appcore_base.c
deleted file mode 100644 (file)
index 40c0b1e..0000000
+++ /dev/null
@@ -1,1574 +0,0 @@
-/*
- * Copyright (c) 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 <stdbool.h>
-#include <errno.h>
-#include <string.h>
-#include <stdlib.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <unistd.h>
-#include <malloc.h>
-#include <locale.h>
-#include <libintl.h>
-#include <linux/limits.h>
-#include <glib.h>
-#include <gio/gio.h>
-#include <sys/time.h>
-#include <dlfcn.h>
-#include <vconf.h>
-#include <aul.h>
-#include <aul_app_lifecycle.h>
-#include <bundle_internal.h>
-#include <sensor_internal.h>
-#include <ttrace.h>
-#include <system_info.h>
-
-#include "appcore_base.h"
-#include "appcore_base_private.h"
-#include "appcore_watchdog.h"
-#include "appcore_base_control.h"
-
-#define PATH_LOCALE "locale"
-#define RESOURCED_FREEZER_PATH "/Org/Tizen/ResourceD/Freezer"
-#define RESOURCED_FREEZER_INTERFACE "org.tizen.resourced.freezer"
-#define RESOURCED_FREEZER_SIGNAL "FreezerState"
-#define SQLITE_FLUSH_MAX (1024 * 1024)
-
-typedef struct _appcore_base_context {
-       appcore_base_ops ops;
-       void *data;
-       int argc;
-       char **argv;
-       unsigned int tid;
-       bool suspended_state;
-       bool allowed_bg;
-       bool dirty;
-       guint sid;
-       int display_state;
-} appcore_base_context;
-
-typedef struct _appcore_base_event_node {
-       int type;
-       appcore_base_event_cb cb;
-       void *data;
-       void *prev_event;
-} appcore_base_event_node;
-
-typedef struct _appcore_base_rotation {
-       int conn;
-       int lock;
-       int ref;
-       enum appcore_base_rm rm;
-       int charger_status;
-       bool initialized;
-} appcore_base_rotation;
-
-struct lang_info_s {
-       char *parent;
-       GList *list;
-};
-
-static appcore_base_context __context;
-static GList *__events;
-static GDBusConnection *__bus;
-static guint __suspend_dbus_handler_initialized;
-static char *__locale_dir;
-static appcore_base_rotation __rotation;
-
-appcore_base_tizen_profile_t appcore_base_get_tizen_profile(void)
-{
-       static appcore_base_tizen_profile_t profile = TIZEN_PROFILE_UNKNOWN;
-       char *profile_name = NULL;
-
-       if (__builtin_expect(profile != TIZEN_PROFILE_UNKNOWN, 1))
-               return profile;
-
-       system_info_get_platform_string("http://tizen.org/feature/profile",
-                       &profile_name);
-       if (profile_name == NULL)
-               return profile;
-
-       switch (*profile_name) {
-       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:
-               profile = TIZEN_PROFILE_COMMON;
-               break;
-       }
-       free(profile_name);
-
-       return profile;
-}
-
-static int __compare_event(void *prev_event, void *curr_event, int type)
-{
-       char *curr_strval;
-       char *prev_strval;
-       int curr_intval;
-       int prev_intval;
-       int ret = -1;
-
-       switch (type) {
-       case APPCORE_BASE_EVENT_LOW_MEMORY:
-       case APPCORE_BASE_EVENT_LOW_BATTERY:
-       case APPCORE_BASE_EVENT_DEVICE_ORIENTATION_CHANGED:
-       case APPCORE_BASE_EVENT_SUSPENDED_STATE_CHANGE:
-               prev_intval = GPOINTER_TO_INT(prev_event);
-               curr_intval = *(int *)curr_event;
-               if (prev_intval == curr_intval)
-                       ret = 0;
-               break;
-       case APPCORE_BASE_EVENT_LANG_CHANGE:
-       case APPCORE_BASE_EVENT_REGION_CHANGE:
-               prev_strval = prev_event;
-               curr_strval = curr_event;
-               if (prev_strval && curr_strval &&
-                               !strcmp(prev_strval, curr_strval))
-                       ret = 0;
-               break;
-       default:
-               break;
-       }
-
-       return ret;
-}
-
-static void __unset_prev_event(void **prev_event, int type)
-{
-       if (type == APPCORE_BASE_EVENT_LANG_CHANGE ||
-                       type == APPCORE_BASE_EVENT_REGION_CHANGE)
-               free(*prev_event);
-       *prev_event = NULL;
-}
-
-static void __set_prev_event(void **prev_event, void *curr_event, int type)
-{
-       int curr_intval;
-       char *curr_strval;
-
-       switch (type) {
-       case APPCORE_BASE_EVENT_LOW_MEMORY:
-       case APPCORE_BASE_EVENT_LOW_BATTERY:
-       case APPCORE_BASE_EVENT_DEVICE_ORIENTATION_CHANGED:
-       case APPCORE_BASE_EVENT_SUSPENDED_STATE_CHANGE:
-               curr_intval = *(int *)curr_event;
-               *prev_event = GINT_TO_POINTER(curr_intval);
-               break;
-       case APPCORE_BASE_EVENT_LANG_CHANGE:
-       case APPCORE_BASE_EVENT_REGION_CHANGE:
-               curr_strval = curr_event;
-               if (curr_strval)
-                       *prev_event = strdup(curr_strval);
-               break;
-       default:
-               break;
-       }
-}
-
-static void __invoke_callback(void *event, int type)
-{
-       GList *iter = __events;
-
-       while (iter) {
-               appcore_base_event_node *node = iter->data;
-               iter = g_list_next(iter);
-
-               if (node->type != type)
-                       continue;
-
-               if (__compare_event(node->prev_event, event, type)) {
-                       node->cb(event, node->data);
-                       __unset_prev_event(&node->prev_event, type);
-                       __set_prev_event(&node->prev_event, event, type);
-               }
-       }
-}
-
-static bool __exist_callback(int type)
-{
-       GList *iter = __events;
-
-       while (iter) {
-               appcore_base_event_node *node = iter->data;
-
-               if (node->type == type)
-                       return true;
-
-               iter = g_list_next(iter);
-       }
-
-       return false;
-}
-
-static enum appcore_base_rm __get_rm(sensor_data_t data)
-{
-       int event;
-       enum appcore_base_rm rm;
-
-       if (data.value_count <= 0) {
-               _ERR("Failed to get sensor data");
-               return APPCORE_BASE_RM_UNKNOWN;
-       }
-
-       event = data.values[0];
-       switch (event) {
-       case AUTO_ROTATION_DEGREE_0:
-               rm = APPCORE_BASE_RM_PORTRAIT_NORMAL;
-               break;
-       case AUTO_ROTATION_DEGREE_90:
-               rm = APPCORE_BASE_RM_LANDSCAPE_NORMAL;
-               break;
-       case AUTO_ROTATION_DEGREE_180:
-               rm = APPCORE_BASE_RM_PORTRAIT_REVERSE;
-               break;
-       case AUTO_ROTATION_DEGREE_270:
-               rm = APPCORE_BASE_RM_LANDSCAPE_REVERSE;
-               break;
-       default:
-               rm = APPCORE_BASE_RM_UNKNOWN;
-               break;
-       }
-
-       return rm;
-}
-
-static void __lock_cb(keynode_t *node, void *user_data)
-{
-       bool r;
-       sensor_data_t data;
-       enum appcore_base_rm rm;
-
-       __rotation.lock = !vconf_keynode_get_bool(node);
-       if (__rotation.lock) {
-               _DBG("Rotation locked");
-               rm = APPCORE_BASE_RM_PORTRAIT_NORMAL;
-       } else {
-               _DBG("Rotation unlocked");
-               r = sensord_get_data(__rotation.conn, AUTO_ROTATION_SENSOR, &data);
-               if (!r) {
-                       _ERR("Failed to get sensor data");
-                       return;
-               }
-
-               rm = __get_rm(data);
-               if (rm == APPCORE_BASE_RM_UNKNOWN) {
-                       _ERR("Unknown mode");
-                       return;
-               }
-       }
-
-       if (__rotation.rm == rm)
-               return;
-
-       _DBG("Rotation: %d -> %d", __rotation.rm, rm);
-       __rotation.rm = rm;
-       __invoke_callback((void *)&__rotation.rm, APPCORE_BASE_EVENT_DEVICE_ORIENTATION_CHANGED);
-}
-
-static void __auto_rotation_changed_cb(sensor_t sensor, unsigned int event_type,
-               sensor_data_t *data, void *user_data)
-{
-       enum appcore_base_rm rm;
-
-       if (data == NULL)
-               return;
-
-       if (__rotation.lock)
-               return;
-
-       if (event_type != AUTO_ROTATION_CHANGE_STATE_EVENT)
-               return;
-
-       rm = __get_rm(*data);
-       if (rm == APPCORE_BASE_RM_UNKNOWN) {
-               _ERR("Unknown mode");
-               return;
-       }
-
-       _DBG("Rotation: %d -> %d", __rotation.rm, rm);
-       __rotation.rm = rm;
-       __invoke_callback((void *)&__rotation.rm, APPCORE_BASE_EVENT_DEVICE_ORIENTATION_CHANGED);
-}
-
-static void __fini_rotation(void)
-{
-       if (!__rotation.initialized)
-               return;
-
-       vconf_ignore_key_changed(VCONFKEY_SETAPPL_AUTO_ROTATE_SCREEN_BOOL, __lock_cb);
-       sensord_unregister_event(__rotation.conn, AUTO_ROTATION_CHANGE_STATE_EVENT);
-       sensord_stop(__rotation.conn);
-       sensord_disconnect(__rotation.conn);
-
-       __rotation.lock = 0;
-       __rotation.initialized = false;
-}
-
-static void __init_rotation(void)
-{
-       sensor_t sensor;
-       int lock;
-       bool r;
-
-       if (__rotation.initialized)
-               return;
-
-       sensor = sensord_get_sensor(AUTO_ROTATION_SENSOR);
-       __rotation.conn = sensord_connect(sensor);
-       if (__rotation.conn < 0) {
-               _ERR("Failed to connect sensord");
-               return;
-       }
-
-       r = sensord_register_event(__rotation.conn, AUTO_ROTATION_CHANGE_STATE_EVENT,
-                       SENSOR_INTERVAL_NORMAL, 0, __auto_rotation_changed_cb, NULL);
-       if (!r) {
-               _ERR("Failed to register auto rotation change event");
-               sensord_disconnect(__rotation.conn);
-               return;
-       }
-
-       r = sensord_start(__rotation.conn, 0);
-       if (!r) {
-               _ERR("Failed to start sensord");
-               sensord_unregister_event(__rotation.conn, AUTO_ROTATION_CHANGE_STATE_EVENT);
-               sensord_disconnect(__rotation.conn);
-               return;
-       }
-
-       lock = 0;
-       vconf_get_bool(VCONFKEY_SETAPPL_AUTO_ROTATE_SCREEN_BOOL, &lock);
-       vconf_notify_key_changed(VCONFKEY_SETAPPL_AUTO_ROTATE_SCREEN_BOOL, __lock_cb, NULL);
-
-       __rotation.lock = !lock;
-       __rotation.initialized = true;
-}
-
-static void __charger_status_changed_cb(keynode_t *keynode, void *user_data)
-{
-       if (TIZEN_FEATURE_CHARGER_STATUS) {
-               __rotation.charger_status = vconf_keynode_get_int(keynode);
-               if (__rotation.charger_status) {
-                       if (__rotation.ref)
-                               __init_rotation();
-               } else {
-                       if (__rotation.ref)
-                               __fini_rotation();
-               }
-               _DBG("charger status(%d)", __rotation.charger_status);
-       }
-}
-
-static void __unregister_rotation_changed_event(void)
-{
-       if (!__rotation.ref)
-               return;
-
-       __rotation.ref--;
-       if (__rotation.ref > 1)
-               return;
-
-       __fini_rotation();
-       if (TIZEN_FEATURE_CHARGER_STATUS) {
-               vconf_ignore_key_changed(VCONFKEY_SYSMAN_CHARGER_STATUS,
-                               __charger_status_changed_cb);
-       }
-
-       __rotation.ref = 0;
-}
-
-static void __register_rotation_changed_event(void)
-{
-       if (__rotation.ref) {
-               __rotation.ref++;
-               return;
-       }
-
-       if (TIZEN_FEATURE_CHARGER_STATUS) {
-               vconf_get_int(VCONFKEY_SYSMAN_CHARGER_STATUS,
-                               &__rotation.charger_status);
-               vconf_notify_key_changed(VCONFKEY_SYSMAN_CHARGER_STATUS,
-                               __charger_status_changed_cb, NULL);
-               if (__rotation.charger_status)
-                       __init_rotation();
-       } else {
-               __init_rotation();
-       }
-
-       __rotation.ref++;
-}
-
-static void __on_low_memory(keynode_t *key, void *data)
-{
-       int val;
-
-       val = vconf_keynode_get_int(key);
-
-       if (val >= VCONFKEY_SYSMAN_LOW_MEMORY_SOFT_WARNING) {
-               __invoke_callback(&val, APPCORE_BASE_EVENT_LOW_MEMORY);
-               malloc_trim(0);
-       }
-}
-
-static void __on_low_battery(keynode_t *key, void *data)
-{
-       int val;
-
-       val = vconf_keynode_get_int(key);
-
-       if (val <= VCONFKEY_SYSMAN_BAT_CRITICAL_LOW)
-               __invoke_callback(&val, APPCORE_BASE_EVENT_LOW_BATTERY);
-}
-
-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 == NULL || __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;
-
-       list = g_list_append(list, strdup(lang));
-
-       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);
-}
-
-static 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);
-               setenv("LC_ALL", lang, 1);
-               r = setlocale(LC_ALL, "");
-               if (r == NULL) {
-                       r = setlocale(LC_ALL, "en_US.UTF-8");
-                       if (r != NULL) {
-                               _DBG("*****appcore setlocale=%s\n", r);
-                       } else {
-                               _DBG("*****appcore setlocale=\"C\"");
-                               setenv("LC_ALL", "C", 1);
-                               r = setlocale(LC_ALL, "");
-                               if (r == NULL)
-                                       _ERR("failed to setlocale");
-                       }
-               }
-               free(lang);
-       }
-}
-
-static 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);
-               } else {
-                       _DBG("*****appcore setlocale=\"C\"");
-                       setenv("LC_ALL", "C", 1);
-                       r = setlocale(LC_ALL, "");
-                       if (r == NULL)
-                               _ERR("failed to setlocale");
-               }
-
-               free(region);
-       }
-}
-
-static void __on_language_change(keynode_t *key, void *data)
-{
-       char *val;
-
-       if (__context.sid) {
-               g_source_remove(__context.sid);
-               __context.sid = 0;
-       }
-
-       val = vconf_keynode_get_str(key);
-
-       __update_lang();
-       __invoke_callback((void *)val, APPCORE_BASE_EVENT_LANG_CHANGE);
-}
-
-static void __on_region_change(keynode_t *key, void *data)
-{
-       char *val;
-       const char *name;
-
-       name = vconf_keynode_get_name(key);
-       if (name == NULL)
-               return;
-
-       if (strcmp(name, VCONFKEY_REGIONFORMAT) &&
-                       strcmp(name, VCONFKEY_REGIONFORMAT_TIME1224))
-               return;
-
-       val = vconf_get_str(VCONFKEY_REGIONFORMAT);
-
-       __update_region();
-       __invoke_callback((void *)val, APPCORE_BASE_EVENT_REGION_CHANGE);
-       free(val);
-}
-
-static gboolean __invoke_lang_change(gpointer data)
-{
-       const char *lang;
-
-       __context.sid = 0;
-
-       lang = getenv("LANG");
-       if (!lang)
-               return G_SOURCE_REMOVE;
-
-       __invoke_callback((void *)lang, APPCORE_BASE_EVENT_LANG_CHANGE);
-
-       return G_SOURCE_REMOVE;
-}
-
-static void __verify_language(void)
-{
-       char *lang;
-       const char *env_lang;
-
-       env_lang = getenv("LANG");
-       if (!env_lang)
-               return;
-
-       lang = vconf_get_str(VCONFKEY_LANGSET);
-       if (!lang)
-               return;
-
-       if (strcmp(env_lang, lang) != 0) {
-               _INFO("LANG(%s), LANGSET(%s)", env_lang, lang);
-               __context.sid = g_idle_add(__invoke_lang_change, NULL);
-       }
-
-       free(lang);
-}
-
-static gboolean __flush_memory(gpointer data)
-{
-       int suspend = APPCORE_BASE_SUSPENDED_STATE_WILL_ENTER_SUSPEND;
-
-       if (__context.ops.trim_memory)
-               __context.ops.trim_memory(__context.data);
-
-       __context.tid = 0;
-
-       if (!__context.allowed_bg && !__context.suspended_state) {
-               _DBG("[__SUSPEND__] flush case");
-               __invoke_callback((void *)&suspend, APPCORE_BASE_EVENT_SUSPENDED_STATE_CHANGE);
-               __context.suspended_state = true;
-       }
-
-       return FALSE;
-}
-
-static void __add_suspend_timer(void)
-{
-       __context.tid = g_timeout_add_seconds(5, __flush_memory, NULL);
-}
-
-static void __remove_suspend_timer(void)
-{
-       if (__context.tid > 0) {
-               g_source_remove(__context.tid);
-               __context.tid = 0;
-       }
-}
-
-static void __on_receive_suspend_signal(GDBusConnection *connection,
-                                       const gchar *sender_name,
-                                       const gchar *object_path,
-                                       const gchar *interface_name,
-                                       const gchar *signal_name,
-                                       GVariant *parameters,
-                                       gpointer user_data)
-{
-       gint suspend = APPCORE_BASE_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) {
-                       if (!__context.allowed_bg && __context.suspended_state) {
-                               __remove_suspend_timer();
-                               __invoke_callback((void *)&suspend, APPCORE_BASE_EVENT_SUSPENDED_STATE_CHANGE);
-                               __context.suspended_state = false;
-                               __add_suspend_timer();
-                       }
-               }
-       }
-}
-
-static int __init_suspend_dbus_handler(void)
-{
-       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,
-                                               __on_receive_suspend_signal,
-                                               NULL,
-                                               NULL);
-       if (__suspend_dbus_handler_initialized == 0) {
-               _ERR("g_dbus_connection_signal_subscribe() is failed.");
-               return -1;
-       }
-
-       _DBG("[__SUSPEND__] suspend signal initialized");
-
-       return 0;
-}
-
-static void __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;
-}
-
-static gboolean __init_suspend(gpointer data)
-{
-       __init_suspend_dbus_handler();
-       return G_SOURCE_REMOVE;
-}
-
-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);
-       return 0;
-}
-
-static int __get_app_name(const char *appid, char **name)
-{
-       char *name_token = NULL;
-
-       if (appid == NULL)
-               return -1;
-
-       /* com.vendor.name -> name */
-       name_token = strrchr(appid, '.');
-       if (name_token == NULL) {
-               *name = strdup(appid);
-               return 0;
-       }
-
-       name_token++;
-
-       *name = strdup(name_token);
-       if (*name == NULL)
-               return -1;
-
-       return 0;
-}
-
-static int __set_i18n(const char *domain, const char *dir)
-{
-       char *r;
-
-       if (domain == NULL) {
-               errno = EINVAL;
-               return -1;
-       }
-
-       if (dir) {
-               if (__locale_dir)
-                       free(__locale_dir);
-               __locale_dir = strdup(dir);
-       }
-
-       __update_lang();
-       __update_region();
-
-       r = setlocale(LC_ALL, "");
-       /* if locale is not set properly, try to set "en_US" again */
-       if (r == NULL) {
-               r = setlocale(LC_ALL, "en_US.UTF-8");
-               if (r != NULL)
-                       _DBG("*****appcore setlocale=%s\n", r);
-       }
-       if (r == NULL) {
-               _ERR("appcore: setlocale() error");
-               _DBG("*****appcore setlocale=\"C\"");
-               setenv("LC_ALL", "C", 1);
-               r = setlocale(LC_ALL, "");
-               if (r == NULL)
-                       _ERR("failed to setlocale");
-       }
-
-       r = bindtextdomain(domain, dir);
-       if (r == NULL)
-               _ERR("appcore: bindtextdomain() error");
-
-       r = textdomain(domain);
-       if (r == NULL)
-               _ERR("appcore: textdomain() error");
-
-       return 0;
-}
-
-EXPORT_API int appcore_base_on_set_i18n(void)
-{
-       int r;
-       char locale_dir[PATH_MAX];
-       char appid[PATH_MAX];
-       char *name = NULL;
-
-       r = aul_app_get_appid_bypid(getpid(), appid, PATH_MAX);
-       if (r < 0) {
-               _ERR("Failed to get application ID - pid(%d)", getpid());
-               return -1;
-       }
-
-       r = __get_app_name(appid, &name);
-       if (r < 0)
-               return -1;
-
-       r = __get_locale_resource_dir(locale_dir, sizeof(locale_dir));
-       if (r < 0) {
-               free(name);
-               return -1;
-       }
-
-       r = __set_i18n(name, locale_dir);
-       if (r < 0) {
-               free(name);
-               return -1;
-       }
-
-       free(name);
-
-       return 0;
-}
-
-EXPORT_API int appcore_base_set_i18n(const char *domain_name, const char *dir_name)
-{
-       return __set_i18n(domain_name, dir_name);
-}
-
-static void __set_default_events(void)
-{
-       int r;
-
-       vconf_notify_key_changed(VCONFKEY_LANGSET, __on_language_change, NULL);
-       r = vconf_notify_key_changed(VCONFKEY_REGIONFORMAT, __on_region_change, NULL);
-       if (r == 0)
-               vconf_notify_key_changed(VCONFKEY_REGIONFORMAT_TIME1224, __on_region_change, NULL);
-       vconf_notify_key_changed(VCONFKEY_SYSMAN_LOW_MEMORY, __on_low_memory, NULL);
-}
-
-static void __unset_default_events(void)
-{
-       int r;
-
-       vconf_ignore_key_changed(VCONFKEY_LANGSET, __on_language_change);
-       r = vconf_ignore_key_changed(VCONFKEY_REGIONFORMAT, __on_region_change);
-       if (r == 0)
-               vconf_ignore_key_changed(VCONFKEY_REGIONFORMAT_TIME1224, __on_region_change);
-       vconf_ignore_key_changed(VCONFKEY_SYSMAN_LOW_MEMORY, __on_low_memory);
-}
-
-EXPORT_API int appcore_base_init(appcore_base_ops ops, int argc, char **argv, void *data)
-{
-       int i;
-       int r;
-
-       __context.ops = ops;
-       __context.argc = argc;
-       __context.argv = argv;
-       __context.data = data;
-       __context.tid = 0;
-       __context.suspended_state = false;
-       __context.allowed_bg = false;
-
-       traceBegin(TTRACE_TAG_APPLICATION_MANAGER, "APPCORE:OPS_INIT");
-       if (__context.ops.init)
-               __context.ops.init(argc, argv, data);
-       traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
-
-       if (TIZEN_FEATURE_BACKGROUND_MANAGEMENT)
-               g_idle_add(__init_suspend, NULL);
-
-       traceBegin(TTRACE_TAG_APPLICATION_MANAGER, "APPCORE:SET_SYSTEM_EVENT");
-       if (!__context.dirty) {
-               __context.dirty = true;
-
-               for (i = APPCORE_BASE_EVENT_START + 1; i < APPCORE_BASE_EVENT_MAX; i++) {
-                       if (__exist_callback(i)) {
-                               if (__context.ops.set_event)
-                                       __context.ops.set_event(i, __context.data);
-                       }
-               }
-       }
-       traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
-
-       traceBegin(TTRACE_TAG_APPLICATION_MANAGER, "APPCORE:VERIFY_LANG");
-       __verify_language();
-       traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
-       traceBegin(TTRACE_TAG_APPLICATION_MANAGER, "APPCORE:SET_DEFAULT_EVENTS");
-       __set_default_events();
-       traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
-       if (__context.ops.set_i18n)
-               __context.ops.set_i18n(__context.data);
-       aul_app_lifecycle_update_state(AUL_APP_LIFECYCLE_STATE_INITIALIZED);
-
-       if (__context.ops.create) {
-               traceBegin(TTRACE_TAG_APPLICATION_MANAGER, "APPCORE:CREATE");
-               r = __context.ops.create(__context.data);
-               traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
-               aul_app_lifecycle_update_state(AUL_APP_LIFECYCLE_STATE_CREATED);
-               if (r < 0) {
-                       aul_status_update(STATUS_DYING);
-                       return 0;
-               }
-       }
-
-       if (__context.ops.run)
-               __context.ops.run(__context.data);
-
-       return 0;
-}
-
-EXPORT_API void appcore_base_fini(void)
-{
-       int i;
-
-       aul_status_update(STATUS_DYING);
-       appcore_watchdog_disable();
-       if (__context.ops.terminate) {
-               aul_app_lifecycle_update_state(AUL_APP_LIFECYCLE_STATE_DESTROYED);
-               traceBegin(TTRACE_TAG_APPLICATION_MANAGER, "APPCORE:TERMINATE");
-               __context.ops.terminate(__context.data);
-               traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
-       }
-
-       for (i = APPCORE_BASE_EVENT_START + 1; i < APPCORE_BASE_EVENT_MAX; i++) {
-               if (__exist_callback(i)) {
-                       if (__context.ops.unset_event)
-                               __context.ops.unset_event(i, __context.data);
-               }
-       }
-
-       appcore_base_control_fini();
-       __unset_default_events();
-
-       if (__context.sid) {
-               g_source_remove(__context.sid);
-               __context.sid = 0;
-       }
-
-       __remove_suspend_timer();
-
-       g_list_free_full(__events, free);
-       __events = NULL;
-
-       if (TIZEN_FEATURE_BACKGROUND_MANAGEMENT)
-               __fini_suspend_dbus_handler();
-
-       if (__locale_dir) {
-               free(__locale_dir);
-               __locale_dir = NULL;
-       }
-
-       __context.dirty = false;
-
-       if (__context.ops.finish)
-               __context.ops.finish();
-}
-
-EXPORT_API int appcore_base_flush_memory(void)
-{
-       if (__context.ops.trim_memory)
-               __context.ops.trim_memory(__context.data);
-
-       return 0;
-}
-
-EXPORT_API int appcore_base_on_receive(aul_type type, bundle *b)
-{
-       const char *bg;
-       int dummy = 0;
-
-       switch (type) {
-       case AUL_START:
-               _DBG("[APP %d]     AUL event: AUL_START", getpid());
-               if (TIZEN_FEATURE_BACKGROUND_MANAGEMENT) {
-                       bg = bundle_get_val(b, AUL_K_ALLOWED_BG);
-                       if (bg && !strcmp(bg, "ALLOWED_BG")) {
-                               _DBG("[__SUSPEND__] allowed background");
-                               __context.allowed_bg = true;
-                               __remove_suspend_timer();
-                       }
-               }
-
-               if (__context.ops.control) {
-                       traceBegin(TTRACE_TAG_APPLICATION_MANAGER, "APPCORE:RESET");
-                       __context.ops.control(b, __context.data);
-                       traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
-               }
-               break;
-       case AUL_RESUME:
-               _DBG("[APP %d]     AUL event: AUL_RESUME", getpid());
-               if (TIZEN_FEATURE_BACKGROUND_MANAGEMENT) {
-                       bg = bundle_get_val(b, AUL_K_ALLOWED_BG);
-                       if (bg && !strcmp(bg, "ALLOWED_BG")) {
-                               _DBG("[__SUSPEND__] allowed background");
-                               __context.allowed_bg = true;
-                               __remove_suspend_timer();
-                       }
-               }
-               break;
-       case AUL_TERMINATE:
-               _DBG("[APP %d]     AUL event: AUL_TERMINATE", getpid());
-               aul_status_update(STATUS_DYING);
-               if (!__context.allowed_bg)
-                       __remove_suspend_timer();
-
-               if (__context.ops.exit)
-                       __context.ops.exit(__context.data);
-               break;
-       case AUL_TERMINATE_INST:
-       case AUL_TERMINATE_BG_INST:
-       case AUL_TERMINATE_BGAPP:
-               _DBG("[APP %d]     AUL event: %d", getpid(), type);
-               if (!__context.allowed_bg)
-                       __remove_suspend_timer();
-               break;
-       case AUL_WAKE:
-               _DBG("[APP %d]     AUL event: AUL_WAKE", getpid());
-               if (TIZEN_FEATURE_BACKGROUND_MANAGEMENT) {
-                       if (!__context.allowed_bg &&
-                                       __context.suspended_state) {
-                               int suspend = APPCORE_BASE_SUSPENDED_STATE_DID_EXIT_FROM_SUSPEND;
-                               __remove_suspend_timer();
-                               __invoke_callback((void *)&suspend, APPCORE_BASE_EVENT_SUSPENDED_STATE_CHANGE);
-                               __context.suspended_state = false;
-                       }
-               }
-               break;
-       case AUL_SUSPEND:
-               _DBG("[APP %d]     AUL event: AUL_SUSPEND", getpid());
-               if (TIZEN_FEATURE_BACKGROUND_MANAGEMENT) {
-                       if (!__context.allowed_bg &&
-                                       !__context.suspended_state) {
-                               __remove_suspend_timer();
-                               __flush_memory(NULL);
-                       }
-               }
-               break;
-       case AUL_UPDATE_REQUESTED:
-               _DBG("[APP %d]     AUL event: AUL_UPDATE_REQUESTED", getpid());
-               __invoke_callback((void *)&dummy, APPCORE_BASE_EVENT_UPDATE_REQUESTED);
-               break;
-       default:
-               _DBG("[APP %d]     AUL event: %d", getpid(), type);
-               /* do nothing */
-               break;
-       }
-
-       return 0;
-}
-
-EXPORT_API int appcore_base_on_create(void)
-{
-       int r;
-
-       r = aul_launch_init(__context.ops.receive, __context.data);
-       if (r < 0 && r != AUL_R_ECANCELED) {
-               _ERR("Aul init failed: %d", r);
-               return -1;
-       }
-
-       r = aul_launch_argv_handler(__context.argc, __context.argv);
-       if (r < 0) {
-               _ERR("Aul argv handler failed: %d", r);
-               return -1;
-       }
-
-       return 0;
-}
-
-EXPORT_API int appcore_base_on_control(bundle *b)
-{
-       appcore_base_control_invoke(b);
-
-       return 0;
-}
-
-EXPORT_API int appcore_base_on_terminate()
-{
-       aul_finalize();
-
-       return 0;
-}
-
-EXPORT_API void appcore_base_on_set_event(enum appcore_base_event event)
-{
-       switch (event) {
-       case APPCORE_BASE_EVENT_LOW_BATTERY:
-               vconf_notify_key_changed(VCONFKEY_SYSMAN_BATTERY_STATUS_LOW, __on_low_battery, NULL);
-               break;
-       case APPCORE_BASE_EVENT_DEVICE_ORIENTATION_CHANGED:
-               __register_rotation_changed_event();
-               break;
-       case APPCORE_BASE_EVENT_SUSPENDED_STATE_CHANGE:
-               break;
-
-       default:
-               break;
-       }
-
-}
-
-EXPORT_API void appcore_base_on_unset_event(enum appcore_base_event event)
-{
-       switch (event) {
-       case APPCORE_BASE_EVENT_LOW_BATTERY:
-               vconf_ignore_key_changed(VCONFKEY_SYSMAN_BATTERY_STATUS_LOW, __on_low_battery);
-               break;
-       case APPCORE_BASE_EVENT_DEVICE_ORIENTATION_CHANGED:
-               __unregister_rotation_changed_event();
-               break;
-       case APPCORE_BASE_EVENT_SUSPENDED_STATE_CHANGE:
-               break;
-       default:
-               break;
-       }
-}
-
-EXPORT_API int appcore_base_on_trim_memory(void)
-{
-       int (*sqlite3_free_heap_memory)(int);
-
-       sqlite3_free_heap_memory = dlsym(RTLD_DEFAULT,
-                       "sqlite3_release_memory");
-       if (sqlite3_free_heap_memory)
-               sqlite3_free_heap_memory(SQLITE_FLUSH_MAX);
-
-       malloc_trim(0);
-
-       return 0;
-}
-
-EXPORT_API appcore_base_event_h appcore_base_add_event(enum appcore_base_event event,
-               appcore_base_event_cb cb, void *data)
-{
-       appcore_base_event_node *node;
-
-       if (__context.dirty && !__exist_callback(event)) {
-               if (__context.ops.set_event)
-                       __context.ops.set_event(event, __context.data);
-       }
-
-       node = malloc(sizeof(appcore_base_event_node));
-
-       if (node == NULL)
-               return NULL;
-
-       node->cb = cb;
-       node->type = event;
-       node->data = data;
-
-       if (event == APPCORE_BASE_EVENT_LANG_CHANGE ||
-                       event == APPCORE_BASE_EVENT_REGION_CHANGE)
-               node->prev_event = NULL;
-       else
-               node->prev_event = GINT_TO_POINTER(-1);
-       __events = g_list_append(__events, node);
-
-       return node;
-}
-
-EXPORT_API int appcore_base_remove_event(appcore_base_event_h handle)
-{
-       appcore_base_event_node *node = handle;
-       enum appcore_base_event event;
-
-       if (!node || !g_list_find(__events, node))
-               return -1;
-
-       event = node->type;
-       __events = g_list_remove(__events, node);
-       __unset_prev_event(&node->prev_event, event);
-       free(node);
-       if (__context.dirty && !__exist_callback(event)) {
-               if (__context.ops.unset_event)
-                       __context.ops.unset_event(event, __context.data);
-       }
-
-       return 0;
-}
-
-EXPORT_API int appcore_base_raise_event(void *event, enum appcore_base_event type)
-{
-       __invoke_callback(event, type);
-       return 0;
-}
-
-EXPORT_API int appcore_base_get_rotation_state(enum appcore_base_rm *curr)
-{
-       if (curr == NULL)
-               return -1;
-
-       if (!__rotation.ref)
-               return -1;
-
-       *curr = __rotation.rm;
-       return 0;
-}
-
-EXPORT_API bool appcore_base_is_bg_allowed(void)
-{
-       return __context.allowed_bg;
-}
-
-EXPORT_API bool appcore_base_is_suspended(void)
-{
-       return __context.suspended_state;
-}
-
-EXPORT_API void appcore_base_toggle_suspended_state(void)
-{
-       __context.suspended_state ^= __context.suspended_state;
-}
-
-EXPORT_API void appcore_base_exit(void)
-{
-       aul_status_update(STATUS_DYING);
-       if (__context.ops.exit)
-               __context.ops.exit(__context.data);
-}
-
-EXPORT_API void appcore_base_add_suspend_timer(void)
-{
-       __add_suspend_timer();
-}
-
-EXPORT_API void appcore_base_remove_suspend_timer(void)
-{
-       __remove_suspend_timer();
-}
-
-EXPORT_API void appcore_base_set_display_state(int display_state)
-{
-       __context.display_state = display_state;
-}
-
-EXPORT_API int appcore_base_get_display_state(void)
-{
-       return __context.display_state;
-}
-
-static int __on_receive(aul_type type, bundle *b, void *data)
-{
-       return appcore_base_on_receive(type, b);
-}
-
-static int __on_create(void *data)
-{
-       return appcore_base_on_create();
-}
-
-static int __on_control(bundle *b, void *data)
-{
-       return appcore_base_on_control(b);
-}
-
-static int __on_terminate(void *data)
-{
-       return appcore_base_on_terminate();
-}
-
-static int __on_set_i18n(void *data)
-{
-       return appcore_base_on_set_i18n();
-}
-
-static void __on_set_event(enum appcore_base_event event, void *data)
-{
-       appcore_base_on_set_event(event);
-}
-
-static void __on_unset_event(enum appcore_base_event event, void *data)
-{
-       appcore_base_on_unset_event(event);
-}
-
-static void __on_trim_memory(void *data)
-{
-       appcore_base_on_trim_memory();
-}
-
-EXPORT_API appcore_base_ops appcore_base_get_default_ops(void)
-{
-       appcore_base_ops ops;
-
-       ops.create = __on_create;
-       ops.control = __on_control;
-       ops.terminate = __on_terminate;
-       ops.receive = __on_receive;
-       ops.set_i18n = __on_set_i18n;
-       ops.init = NULL;
-       ops.finish = NULL;
-       ops.run = NULL;
-       ops.exit = NULL;
-       ops.set_event = __on_set_event;
-       ops.unset_event = __on_unset_event;
-       ops.trim_memory = __on_trim_memory;
-
-       return ops;
-}
diff --git a/legacy/src/efl_base/appcore_efl_base.c b/legacy/src/efl_base/appcore_efl_base.c
deleted file mode 100644 (file)
index f84ad84..0000000
+++ /dev/null
@@ -1,406 +0,0 @@
-/*
- * Copyright (c) 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 <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-#include <stdbool.h>
-#include <dlfcn.h>
-#include <glib.h>
-#include <Elementary.h>
-#include <vconf.h>
-#include <ttrace.h>
-
-#include "appcore_efl_base_private.h"
-#include "appcore_efl_base.h"
-
-#define PATH_LIB_VC_ELM "/usr/lib/libvc-elm.so.0"
-
-static bool __vc_elm_initialized;
-static void *__vc_elm_handle;
-static int (*__vc_elm_initialize)(void);
-static int (*__vc_elm_deinitialize)(void);
-static int (*__vc_elm_set_auto_register_mode)(int, int);
-static GThread *__vc_elm_thread;
-
-static void __unload_vc_elm(void)
-{
-       if (!__vc_elm_handle)
-               return;
-
-       __vc_elm_initialize = NULL;
-       __vc_elm_deinitialize = NULL;
-       __vc_elm_set_auto_register_mode = NULL;
-
-       dlclose(__vc_elm_handle);
-       __vc_elm_handle = NULL;
-}
-
-static int __load_vc_elm(void)
-{
-       _DBG("Load voice-control-elm");
-
-       if (__vc_elm_handle) {
-               _DBG("Already exists");
-               return 0;
-       }
-
-       if (access(PATH_LIB_VC_ELM, F_OK) != 0) {
-               _ERR("Failed to access %s", PATH_LIB_VC_ELM);
-               return -1;
-       }
-
-       __vc_elm_handle = dlopen(PATH_LIB_VC_ELM, RTLD_LAZY | RTLD_LOCAL);
-       if (!__vc_elm_handle) {
-               _ERR("Failed to open %s", PATH_LIB_VC_ELM);
-               return -1;
-       }
-
-       __vc_elm_initialize = dlsym(__vc_elm_handle, "vc_elm_initialize");
-       if (!__vc_elm_initialize) {
-               _ERR("Failed to load vc_elm_initialize");
-               __unload_vc_elm();
-               return -1;
-       }
-
-       __vc_elm_deinitialize = dlsym(__vc_elm_handle, "vc_elm_deinitialize");
-       if (!__vc_elm_deinitialize) {
-               _ERR("Failed to load vc_elm_deinitialize");
-               __unload_vc_elm();
-               return -1;
-       }
-
-       __vc_elm_set_auto_register_mode = dlsym(__vc_elm_handle,
-                       "vc_elm_set_auto_register_mode");
-       if (!__vc_elm_set_auto_register_mode) {
-               _ERR("Failed to load vc_elm_set_auto_register_mode");
-               __unload_vc_elm();
-               return -1;
-       }
-
-       return 0;
-}
-
-static void __vc_vtauto_changed_cb(keynode_t *key, void *data)
-{
-       const char *name;
-       int vt_automode;
-
-       name = vconf_keynode_get_name(key);
-       if (!name || strcmp(name, VCONFKEY_VC_VOICE_TOUCH_AUTOMODE) != 0)
-               return;
-
-       vt_automode = vconf_keynode_get_bool(key);
-       if (vt_automode) {
-               if (!__vc_elm_initialized) {
-                       __vc_elm_initialize();
-                       __vc_elm_initialized = true;
-               }
-               __vc_elm_set_auto_register_mode(2, 0);
-       } else {
-               __vc_elm_deinitialize();
-               __vc_elm_initialized = false;
-       }
-}
-
-static void __vc_elm_init(void)
-{
-       int vt_automode = 0;
-
-       if (!__vc_elm_handle)
-               return;
-
-       vconf_notify_key_changed(VCONFKEY_VC_VOICE_TOUCH_AUTOMODE,
-                       __vc_vtauto_changed_cb, NULL);
-       vconf_get_bool(VCONFKEY_VC_VOICE_TOUCH_AUTOMODE, &vt_automode);
-       if (vt_automode) {
-               if (!__vc_elm_initialized) {
-                       __vc_elm_initialize();
-                       __vc_elm_initialized = true;
-               }
-               __vc_elm_set_auto_register_mode(2, 0);
-       }
-}
-
-static void __vc_elm_finish(void)
-{
-       if (!__vc_elm_handle)
-               return;
-
-       vconf_ignore_key_changed(VCONFKEY_VC_VOICE_TOUCH_AUTOMODE,
-                       __vc_vtauto_changed_cb);
-       if (__vc_elm_initialized) {
-               __vc_elm_deinitialize();
-               __vc_elm_initialized = false;
-       }
-}
-
-static gboolean __init_vc_elm(gpointer data)
-{
-       _DBG("Initialize vc-elm");
-       /* Postpone initialization to improve app launching performance */
-       /* VC voice touch setting */
-       __vc_elm_init();
-
-       return G_SOURCE_REMOVE;
-}
-
-static gpointer __vc_elm_loader(gpointer data)
-{
-       int r = 0;
-       int retry_count = 3;
-
-       do {
-               r = __load_vc_elm();
-               if (r == 0) {
-                       g_idle_add(__init_vc_elm, NULL);
-                       break;
-               }
-       } while (retry_count--);
-       LOGW("[vc-elm-loader] Result: %d", r);
-
-       return GINT_TO_POINTER(r);
-}
-
-static void __efl_app_init(int argc, char **argv, void *data)
-{
-       int hint;
-       const char *hwacc;
-       int vt_automode = 0;
-
-       traceBegin(TTRACE_TAG_APPLICATION_MANAGER, "APPCORE:ELM_INIT");
-       elm_init(argc, argv);
-       traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
-
-       traceBegin(TTRACE_TAG_APPLICATION_MANAGER, "APPCORE:ELM_CONFIG_SET");
-       hint = appcore_efl_base_get_hint();
-       if ((hint & APPCORE_EFL_BASE_HINT_HW_ACC_CONTROL) &&
-                       !getenv("AUL_HWACC")) {
-               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");
-               }
-       }
-       traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
-
-       traceBegin(TTRACE_TAG_APPLICATION_MANAGER, "APPCORE:VC_ELM_CHECK");
-       vconf_get_bool(VCONFKEY_VC_VOICE_TOUCH_AUTOMODE, &vt_automode);
-       if (vt_automode) {
-               __vc_elm_thread = g_thread_new("vc-elm-loader",
-                               __vc_elm_loader, NULL);
-       }
-       traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
-}
-
-static void __efl_app_finish(void)
-{
-       const char *env;
-       gpointer r;
-
-       __vc_elm_finish();
-       if (__vc_elm_thread) {
-               r = g_thread_join(__vc_elm_thread);
-               __vc_elm_thread = NULL;
-               _DBG("vc-elm-loader. result(%d)", GPOINTER_TO_INT(r));
-       }
-
-       elm_shutdown();
-
-       /* Check loader case */
-       env = getenv("AUL_LOADER_INIT");
-       if (env && env[0] == '1') {
-               setenv("AUL_LOADER_INIT", "0", 1);
-               elm_shutdown();
-       }
-}
-
-static void __efl_app_run(void *data)
-{
-       elm_run();
-}
-
-static void __efl_app_exit(void *data)
-{
-       elm_exit();
-}
-
-static void __efl_app_trim_memory(void *data)
-{
-       _DBG("Trim memory");
-       elm_cache_all_flush();
-       appcore_base_on_trim_memory();
-}
-
-EXPORT_API int appcore_efl_base_init(appcore_efl_base_ops ops, int argc,
-               char **argv, void *data, unsigned int hint)
-{
-       return appcore_ui_base_init(ops.ui_base, argc, argv, data, hint);
-}
-
-EXPORT_API void appcore_efl_base_fini(void)
-{
-       appcore_ui_base_fini();
-}
-
-EXPORT_API appcore_efl_base_ops appcore_efl_base_get_default_ops(void)
-{
-       appcore_efl_base_ops ops;
-
-       ops.ui_base = appcore_ui_base_get_default_ops();
-
-       /* override methods */
-       ops.ui_base.base.init = __efl_app_init;
-       ops.ui_base.base.finish = __efl_app_finish;
-       ops.ui_base.base.run = __efl_app_run;
-       ops.ui_base.base.exit = __efl_app_exit;
-       ops.ui_base.base.trim_memory = __efl_app_trim_memory;
-
-       return ops;
-}
-
-EXPORT_API int appcore_efl_base_on_receive(aul_type type, bundle *b)
-{
-       return appcore_ui_base_on_receive(type, b);
-}
-
-EXPORT_API int appcore_efl_base_on_create(void)
-{
-       return appcore_ui_base_on_create();
-}
-
-EXPORT_API int appcore_efl_base_on_terminate(void)
-{
-       return appcore_ui_base_on_terminate();
-}
-
-EXPORT_API int appcore_efl_base_on_pause(void)
-{
-       return appcore_ui_base_on_pause();
-}
-
-EXPORT_API int appcore_efl_base_on_resume(void)
-{
-       return appcore_ui_base_on_resume();
-}
-
-EXPORT_API int appcore_efl_base_on_control(bundle *b)
-{
-       return appcore_ui_base_on_control(b);
-}
-
-EXPORT_API int appcore_efl_base_on_trim_memory(void)
-{
-       return appcore_ui_base_on_trim_memory();
-}
-
-EXPORT_API void appcore_efl_base_window_on_show(int type, void *event)
-{
-       appcore_ui_base_window_on_show(type, event);
-}
-
-EXPORT_API void appcore_efl_base_window_on_hide(int type, void *event)
-{
-       appcore_ui_base_window_on_hide(type, event);
-}
-
-EXPORT_API void appcore_efl_base_window_on_lower(int type, void *event)
-{
-       appcore_ui_base_window_on_lower(type, event);
-}
-
-EXPORT_API void appcore_efl_base_window_on_visibility(int type, void *event)
-{
-       appcore_ui_base_window_on_visibility(type, event);
-}
-
-EXPORT_API void appcore_efl_base_window_on_pre_visibility(int type, void *event)
-{
-       appcore_ui_base_window_on_pre_visibility(type, event);
-}
-
-EXPORT_API void appcore_efl_base_window_on_aux_message(int type, void *event)
-{
-       appcore_ui_base_window_on_aux_message(type, event);
-}
-
-EXPORT_API void appcore_efl_base_pause(void)
-{
-       appcore_ui_base_pause();
-}
-
-EXPORT_API void appcore_efl_base_resume(void)
-{
-       appcore_ui_base_resume();
-}
-
-EXPORT_API bool appcore_efl_base_is_resumed(void)
-{
-       return appcore_ui_base_is_resumed();
-}
-
-EXPORT_API void appcore_efl_base_exit(void)
-{
-       appcore_ui_base_exit();
-}
-
-EXPORT_API void appcore_efl_base_group_add(void)
-{
-       appcore_ui_base_group_add();
-}
-
-EXPORT_API void appcore_efl_base_group_remove(void)
-{
-       appcore_ui_base_group_remove();
-}
-
-EXPORT_API unsigned int appcore_efl_base_get_main_window(void)
-{
-       return appcore_ui_base_get_main_window();
-}
-
-EXPORT_API unsigned int appcore_efl_base_get_main_surface(void)
-{
-       return appcore_ui_base_get_main_surface();
-}
-
-EXPORT_API int appcore_efl_base_get_hint(void)
-{
-       return appcore_ui_base_get_hint();
-}
-
-EXPORT_API bool appcore_efl_base_get_bg_state(void)
-{
-       return appcore_ui_base_get_bg_state();
-}
-
-EXPORT_API void appcore_efl_base_set_bg_state(bool bg_state)
-{
-       appcore_ui_base_set_bg_state(bg_state);
-}
-
-EXPORT_API void appcore_efl_base_set_system_resource_reclaiming(bool enable)
-{
-       appcore_ui_base_set_system_resource_reclaiming(enable);
-}
diff --git a/legacy/src/legacy/appcore-efl.c b/legacy/src/legacy/appcore-efl.c
deleted file mode 100644 (file)
index 0ec077f..0000000
+++ /dev/null
@@ -1,151 +0,0 @@
-/*
- * 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 <stdbool.h>
-
-#include "appcore-internal.h"
-#include "appcore-efl.h"
-#include "appcore_efl_base.h"
-
-struct appcore_efl_context {
-       struct appcore_ops ops;
-};
-
-static struct appcore_efl_context __context;
-
-static int __ui_app_create(void *data)
-{
-       appcore_efl_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_efl_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_efl_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_efl_base_on_pause();
-
-       if (__context.ops.pause)
-               __context.ops.pause(__context.ops.data);
-       return 0;
-}
-
-static int __ui_app_resume(void *data)
-{
-       appcore_efl_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_efl_base_ops efl_ops = appcore_efl_base_get_default_ops();
-
-       /* override methods */
-       efl_ops.ui_base.base.create = __ui_app_create;
-       efl_ops.ui_base.base.control = __ui_app_control;
-       efl_ops.ui_base.base.terminate = __ui_app_terminate;
-       efl_ops.ui_base.pause = __ui_app_pause;
-       efl_ops.ui_base.resume = __ui_app_resume;
-
-       __context.ops = *ops;
-
-       ret = appcore_efl_base_init(efl_ops, *argc, *argv, NULL,
-                       APPCORE_EFL_BASE_HINT_WINDOW_GROUP_CONTROL |
-                       APPCORE_EFL_BASE_HINT_WINDOW_STACK_CONTROL |
-                       APPCORE_EFL_BASE_HINT_BG_LAUNCH_CONTROL |
-                       APPCORE_EFL_BASE_HINT_HW_ACC_CONTROL |
-                       APPCORE_EFL_BASE_HINT_WINDOW_AUTO_CONTROL |
-                       APPCORE_EFL_BASE_HINT_LEGACY_CONTROL);
-
-       return ret;
-}
-
-EXPORT_API void appcore_efl_fini(void)
-{
-       appcore_efl_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)
-               return r;
-
-       appcore_efl_fini();
-
-       return 0;
-}
-
-EXPORT_API void appcore_group_attach()
-{
-       appcore_efl_base_group_add();
-}
-
-EXPORT_API void appcore_group_lower()
-{
-       appcore_efl_base_group_remove();
-}
-
-EXPORT_API unsigned int appcore_get_main_window(void)
-{
-       return appcore_efl_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)
-{
-       appcore_efl_base_set_system_resource_reclaiming(enable);
-       return 0;
-}
index 82d28bc..af0c251 100644 (file)
@@ -138,4 +138,3 @@ EXPORT_API int appcore_flush_memory(void)
 
        return 0;
 }
-
diff --git a/legacy/src/legacy/appcore_base.cc b/legacy/src/legacy/appcore_base.cc
new file mode 100644 (file)
index 0000000..0017eec
--- /dev/null
@@ -0,0 +1,391 @@
+/*
+ * Copyright (c) 2022 Samsung Electronics Co., Ltd.
+ *
+ * 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 "appcore_base.h"
+
+#include <aul.h>
+#include <aul_app_lifecycle.h>
+#include <dlog.h>
+
+#include <memory>
+#include <string>
+
+#include "app_core_base.hh"
+
+#undef EXPORT_API
+#define EXPORT_API __attribute__ ((visibility("default")))
+
+#undef DEPRECATED
+#define DEPRECATED __attribute__((__deprecated__))
+
+namespace tizen_cpp {
+
+namespace {
+
+class AppCore : public AppCoreBase {
+ public:
+  class AppCoreEvent : public AppCoreBase::EventBase {
+   public:
+    AppCoreEvent(appcore_base_event type, appcore_base_event_cb cb, void* data)
+        : EventBase(static_cast<Type>(type)),
+          cb_(cb),
+          data_(data) {}
+
+    void OnEvent(const std::string& value) override {
+      if (cb_ != nullptr)
+        cb_(reinterpret_cast<void*>(const_cast<char*>(value.c_str())), data_);
+    }
+
+    void OnEvent(int value) override {
+      if (cb_ != nullptr)
+        cb_(&value, data_);
+    }
+
+   private:
+    appcore_base_event_cb cb_;
+    void* data_;
+  };
+
+  AppCore(appcore_base_ops ops, void* data) : ops_(ops), data_(data) {}
+
+  void OnLoopInit(int argc, char** argv) override {
+    if (ops_.init)
+      ops_.init(argc, argv, data_);
+  }
+
+  void OnLoopFinish() override {
+    if (ops_.finish)
+      ops_.finish();
+  }
+
+  void OnLoopRun() override {
+    if (ops_.run)
+      ops_.run(data_);
+  }
+
+  void OnLoopExit() override {
+    if (ops_.exit)
+      ops_.exit(data_);
+  }
+
+  int OnReceive(aul_type type, tizen_base::Bundle b) override {
+    if (ops_.receive)
+      return ops_.receive(type, b.GetHandle(), data_);
+    return -1;
+  }
+
+  int OnCreate() override {
+    if (ops_.create)
+      return ops_.create(data_);
+    return -1;
+  }
+
+  int OnControl(tizen_base::Bundle b) override {
+    if (ops_.control)
+      return ops_.control(b.GetHandle(), data_);
+    return -1;
+  }
+
+  int OnTerminate() override {
+    if (ops_.terminate)
+      return ops_.terminate(data_);
+    return -1;
+  }
+
+  int OnSetI18n() override {
+    if (ops_.set_i18n)
+      return ops_.set_i18n(data_);
+    return -1;
+  }
+
+  int OnSetEvent(IEvent::Type event) override {
+    if (!ops_.set_event)
+      return -1;
+
+    ops_.set_event((appcore_base_event)event, data_);
+    return 0;
+  }
+
+  int OnUnsetEvent(IEvent::Type event) override {
+    if (!ops_.unset_event)
+      return -1;
+
+    ops_.unset_event((appcore_base_event)event, data_);
+    return 0;
+  }
+
+  int OnTrimMemory() override {
+    if (!ops_.trim_memory)
+      return -1;
+
+    ops_.trim_memory(data_);
+    return 0;
+  }
+
+ private:
+  appcore_base_ops ops_;
+  void* data_;
+};
+
+std::unique_ptr<AppCore> __context;
+
+int __on_control(bundle* b, void* data) {
+  return appcore_base_on_control(b);
+}
+
+int __on_set_i18n(void* data) {
+  return appcore_base_on_set_i18n();
+}
+
+void __on_set_event(enum appcore_base_event event, void* data) {
+  appcore_base_on_set_event(event);
+}
+
+void __on_unset_event(enum appcore_base_event event, void* data) {
+  appcore_base_on_unset_event(event);
+}
+
+void __on_trim_memory(void* data) {
+  appcore_base_on_trim_memory();
+}
+
+int __on_receive(aul_type type, bundle* b, void* data) {
+  return appcore_base_on_receive(type, b);
+}
+
+int __on_create(void* data) {
+  return appcore_base_on_create();
+}
+
+int __on_terminate(void* data) {
+  return appcore_base_on_terminate();
+}
+
+}  // namespace
+}  // namespace tizen_cpp
+
+using namespace tizen_cpp;
+
+extern "C" EXPORT_API int appcore_base_on_receive(aul_type type, bundle* b) {
+  if (__context.get() == nullptr)
+    return -1;
+  return __context->AppCoreBase::OnReceive(type, tizen_base::Bundle(b));
+}
+
+extern "C" EXPORT_API int appcore_base_on_create(void) {
+  if (__context.get() == nullptr)
+    return -1;
+  return __context->AppCoreBase::OnCreate();
+}
+
+extern "C" EXPORT_API int appcore_base_on_control(bundle* b) {
+  if (__context.get() == nullptr)
+    return -1;
+  return __context->AppCoreBase::OnControl(
+      b ? tizen_base::Bundle(b) : tizen_base::Bundle());
+}
+
+extern "C" EXPORT_API int appcore_base_on_terminate(void) {
+  if (__context.get() == nullptr)
+    return -1;
+  return __context->AppCoreBase::OnTerminate();
+}
+
+extern "C" EXPORT_API int appcore_base_on_set_i18n(void) {
+  if (__context.get() == nullptr)
+    return -1;
+  return __context->AppCoreBase::OnSetI18n();
+}
+
+extern "C" EXPORT_API void appcore_base_on_set_event(
+    enum appcore_base_event event) {
+  if (__context.get() == nullptr)
+    return;
+  __context->AppCoreBase::OnSetEvent(
+      static_cast<AppCoreBase::IEvent::Type>(event));
+}
+
+extern "C" EXPORT_API void appcore_base_on_unset_event(
+    enum appcore_base_event event) {
+  if (__context.get() == nullptr)
+    return;
+  __context->AppCoreBase::OnUnsetEvent(
+      static_cast<AppCoreBase::IEvent::Type>(event));
+}
+
+extern "C" EXPORT_API int appcore_base_on_trim_memory(void) {
+  if (__context.get() == nullptr)
+    return -1;
+  return __context->AppCoreBase::OnTrimMemory();
+}
+
+extern "C" EXPORT_API int appcore_base_init(appcore_base_ops ops,
+    int argc, char** argv, void* data) {
+  __context.reset(new AppCore(ops, data));
+  try {
+    __context->Init(argc, argv);
+  } catch (const std::runtime_error&) {
+    return -1;
+  }
+
+  return 0;
+}
+
+extern "C" EXPORT_API void appcore_base_fini(void) {
+  if (__context.get() == nullptr)
+    return;
+  __context->Fini();
+  __context.reset();
+}
+
+extern "C" EXPORT_API appcore_base_ops appcore_base_get_default_ops(void) {
+  appcore_base_ops ops;
+
+  ops.create = __on_create;
+  ops.control = __on_control;
+  ops.terminate = __on_terminate;
+  ops.receive = __on_receive;
+  ops.set_i18n = __on_set_i18n;
+  ops.init = nullptr;
+  ops.finish = nullptr;
+  ops.run = nullptr;
+  ops.exit = nullptr;
+  ops.set_event = __on_set_event;
+  ops.unset_event = __on_unset_event;
+  ops.trim_memory = __on_trim_memory;
+
+  return ops;
+}
+
+extern "C" EXPORT_API appcore_base_event_h appcore_base_add_event(
+    enum appcore_base_event event,
+    appcore_base_event_cb cb,
+    void* data) {
+  if (__context == nullptr)
+    return nullptr;
+
+  auto* ev = new std::shared_ptr<AppCore::AppCoreEvent>(
+      std::make_shared<AppCore::AppCoreEvent>(event, cb, data));
+  if (ev == nullptr)
+    return nullptr;
+
+  __context->AddEvent(*ev);
+  return static_cast<appcore_base_event_h>(ev);
+}
+
+extern "C" EXPORT_API int appcore_base_remove_event(
+    appcore_base_event_h handle) {
+  auto* ev = static_cast<std::shared_ptr<AppCoreBase::EventBase>*>(handle);
+  if (ev == nullptr || __context == nullptr)
+    return -1;
+
+  bool ret = __context->RemoveEvent(*ev);
+  delete ev;
+  return ret ? 0 : -1;
+}
+
+extern "C" DEPRECATED EXPORT_API int appcore_base_raise_event(
+    void* event,
+    enum appcore_base_event type) {
+  LOGE("This api was deprecated since 7.0");
+  if (__context == nullptr)
+    return -1;
+
+  return 0;
+}
+
+extern "C" EXPORT_API int appcore_base_flush_memory(void) {
+  if (__context == nullptr)
+    return -1;
+
+  __context->FlushMemory();
+  return 0;
+}
+
+extern "C" DEPRECATED EXPORT_API int appcore_base_get_rotation_state(
+    enum appcore_base_rm* curr) {
+  LOGE("This api was deprecated since 7.0");
+  if (__context == nullptr)
+    return -1;
+
+  return 0;
+}
+
+extern "C" EXPORT_API bool appcore_base_is_bg_allowed(void) {
+  if (__context == nullptr)
+    return false;
+
+  return __context->IsBgAllowed();
+}
+
+extern "C" EXPORT_API bool appcore_base_is_suspended(void) {
+  if (__context == nullptr)
+    return false;
+
+  return __context->IsSuspended();
+}
+
+extern "C" EXPORT_API void appcore_base_toggle_suspended_state(void) {
+  if (__context == nullptr)
+    return;
+
+  __context->ToggleSuspendedState();
+}
+
+extern "C" EXPORT_API int appcore_base_set_i18n(const char* domain_name,
+                                                const char* dir_name) {
+  if (__context == nullptr || domain_name == nullptr || dir_name == nullptr)
+    return -1;
+
+  return __context->SetI18n(domain_name, dir_name);
+}
+
+extern "C" EXPORT_API void appcore_base_exit(void) {
+  aul_status_update(STATUS_DYING);
+  if (__context == nullptr)
+    return;
+
+  __context->Exit();
+}
+
+extern "C" EXPORT_API void appcore_base_add_suspend_timer(void) {
+  if (__context == nullptr)
+    return;
+
+  __context->AddSuspendTimer();
+}
+
+extern "C" EXPORT_API void appcore_base_remove_suspend_timer(void) {
+  if (__context == nullptr)
+    return;
+
+  __context->RemoveSuspendTimer();
+}
+
+extern "C" EXPORT_API void appcore_base_set_display_state(int display_state) {
+  if (__context == nullptr)
+    return;
+
+  __context->SetDisplayState(
+      static_cast<AppCoreBase::DisplayState>(display_state));
+}
+
+extern "C" EXPORT_API int appcore_base_get_display_state(void) {
+  if (__context == nullptr)
+    return -1;
+
+  return __context->GetDisplayState();
+}
diff --git a/legacy/src/legacy/appcore_efl.cc b/legacy/src/legacy/appcore_efl.cc
new file mode 100644 (file)
index 0000000..d093dc3
--- /dev/null
@@ -0,0 +1,199 @@
+/*
+ * Copyright (c) 2022 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 <stdlib.h>
+#include <string.h>
+
+#include <list>
+#include <memory>
+
+#include "app_core_efl_base.hh"
+#include "appcore-efl.h"
+#include "common/log_private.hh"
+
+namespace {
+
+using namespace tizen_cpp;
+
+class EflAppContext : public AppCoreEflBase {
+ public:
+  enum AppState {
+    APP_STATE_NOT_RUNNING,
+    APP_STATE_CREATING,
+    APP_STATE_RUNNING,
+  };
+
+  EflAppContext(struct appcore_ops* callback, unsigned int hint)
+      : AppCoreEflBase(hint), callback_(callback) {
+    SetAppState(APP_STATE_CREATING);
+  }
+
+  void Run(int argc, char** argv) override {
+    SetAppState(APP_STATE_RUNNING);
+    AppCoreEflBase::Run(argc, argv);
+    SetAppState(APP_STATE_NOT_RUNNING);
+  }
+
+  int OnCreate() override {
+    AppCoreEflBase::OnCreate();
+    if (callback_->create == nullptr ||
+        callback_->create(callback_->data) == false)
+      return -1;
+
+    return 0;
+  }
+
+  int OnControl(tizen_base::Bundle b) override {
+    AppCoreEflBase::OnControl(b);
+
+    if (callback_->reset)
+      callback_->reset(b.GetHandle(), callback_->data);
+
+    return 0;
+  }
+
+  int OnTerminate() override {
+    if (callback_->terminate)
+      callback_->terminate(callback_->data);
+
+    return 0;
+  }
+
+  int OnPause() override {
+    AppCoreEflBase::OnPause();
+
+    if (callback_->pause)
+      callback_->pause(callback_->data);
+
+    return 0;
+  }
+
+  int OnResume() override {
+    AppCoreEflBase::OnResume();
+
+    if (callback_->resume)
+      callback_->resume(callback_->data);
+
+    return 0;
+  }
+
+  AppState GetAppState() const { return state_; }
+
+  void SetAppState(AppState state) { state_ = state; }
+
+ private:
+  struct appcore_ops* callback_;
+  AppState state_ = APP_STATE_NOT_RUNNING;
+};
+
+std::unique_ptr<EflAppContext> __context;
+
+}  // namespace
+
+EXPORT_API int appcore_efl_init(const char* name,
+                                int* argc,
+                                char*** argv,
+                                struct appcore_ops* ops) {
+  if (*argc < 1 || *argv == nullptr || ops == nullptr) {
+    _E("Invalid parameter");
+    return -1;
+  }
+
+  if (ops->create == nullptr) {
+    _E("app_create_cb() callback MUST be registerted");
+    return -1;
+  }
+
+  if (__context.get() != nullptr &&
+      __context->GetAppState() != EflAppContext::APP_STATE_NOT_RUNNING) {
+    _E("Already running");
+    return -1;
+  }
+
+  unsigned int hint = AppCoreEflBase::HINT_WINDOW_GROUP_CONTROL |
+                      AppCoreEflBase::HINT_WINDOW_STACK_CONTROL |
+                      AppCoreEflBase::HINT_BG_LAUNCH_CONTROL |
+                      AppCoreEflBase::HINT_HW_ACC_CONTROL |
+                      AppCoreEflBase::HINT_WINDOW_AUTO_CONTROL |
+                      AppCoreEflBase::HINT_LEGACY_CONTROL |
+                      AppCoreEflBase::HINT_WINDOW_ID_CONTROL;
+
+  LOGW("appcore_efl_init()");
+  try {
+    __context = std::make_unique<EflAppContext>(ops, hint);
+    __context->Run(*argc, *argv);
+  } catch (std::runtime_error& e) {
+    __context->SetAppState(EflAppContext::APP_STATE_NOT_RUNNING);
+  }
+
+  return 0;
+}
+
+EXPORT_API void appcore_efl_fini(void) {
+  LOGW("appcore_efl_fini()");
+  if (__context.get() &&
+      __context->GetAppState() == EflAppContext::APP_STATE_RUNNING)
+    __context->Exit();
+}
+
+EXPORT_API int appcore_efl_main(const char* name,
+                                int* argc,
+                                char*** argv,
+                                struct appcore_ops* ops) {
+  int r = appcore_efl_init(name, argc, argv, ops);
+  if (r < 0)
+    return r;
+
+  appcore_efl_fini();
+  return 0;
+}
+
+EXPORT_API void appcore_group_attach() {
+  if (__context == nullptr)
+    return;
+
+  __context->GroupAdd();
+}
+
+EXPORT_API void appcore_group_lower() {
+  if (__context == nullptr)
+    return;
+
+  __context->GroupRemove();
+}
+
+EXPORT_API unsigned int appcore_get_main_window(void) {
+  if (__context == nullptr)
+    return 0;
+
+  return __context->GetMainWindow();
+}
+
+EXPORT_API unsigned int appcore_get_main_surface(void) {
+  if (__context == nullptr)
+    return 0;
+
+  return __context->GetMainSurface();
+}
+
+EXPORT_API int appcore_set_system_resource_reclaiming(bool enable) {
+  if (__context == nullptr)
+    return -1;
+
+  __context->SetSystemResourceReclaiming(enable);
+  return 0;
+}
index 08a41fb..81264e4 100644 (file)
@@ -19,7 +19,6 @@ APPLY_PKG_CONFIG(${TARGET_APP_CORE_CPP} PUBLIC
   CAPI_SYSTEM_INFO_DEPS
   DLOG_DEPS
   GIO_2_DEPS
-  PKGMGR_INFO_DEPS
   SENSOR_DEPS
   TTRACE_DEPS
   VCONF_DEPS