2 * Copyright (c) 2016 Samsung Electronics Co., Ltd. All rights reserved.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
24 #include <sys/types.h>
30 #include <linux/limits.h>
37 #include <bundle_internal.h>
38 #include <sensor_internal.h>
40 #include <system_info.h>
41 #include "appcore_base.h"
42 #include "appcore_base_private.h"
44 #define PATH_LOCALE "locale"
45 #define RESOURCED_FREEZER_PATH "/Org/Tizen/Resourced/Freezer"
46 #define RESOURCED_FREEZER_INTERFACE "org.tizen.resourced.freezer"
47 #define RESOURCED_FREEZER_SIGNAL "FreezerState"
49 typedef struct _appcore_base_context {
59 } appcore_base_context;
61 typedef struct _appcore_base_event_node {
63 appcore_base_event_cb cb;
65 } appcore_base_event_node;
67 typedef struct _appcore_base_rotation {
71 enum appcore_base_rm rm;
72 } appcore_base_rotation;
79 static appcore_base_context __context;
80 static GList *__events;
81 static GDBusConnection *__bus;
82 static guint __suspend_dbus_handler_initialized;
83 static char *__locale_dir;
84 static appcore_base_rotation __rotation;
86 appcore_base_tizen_profile_t appcore_base_get_tizen_profile(void)
88 static appcore_base_tizen_profile_t profile = TIZEN_PROFILE_UNKNOWN;
89 char *profile_name = NULL;
91 if (__builtin_expect(profile != TIZEN_PROFILE_UNKNOWN, 1))
94 system_info_get_platform_string("http://tizen.org/feature/profile",
96 if (profile_name == NULL)
99 switch (*profile_name) {
102 profile = TIZEN_PROFILE_MOBILE;
106 profile = TIZEN_PROFILE_WEARABLE;
110 profile = TIZEN_PROFILE_TV;
114 profile = TIZEN_PROFILE_IVI;
117 profile = TIZEN_PROFILE_COMMON;
126 static void __invoke_callback(void *event, int type)
128 GList *iter = __events;
131 appcore_base_event_node *node = iter->data;
133 if (node->type == type)
134 node->cb(event, node->data);
135 iter = g_list_next(iter);
139 static bool __exist_callback(int type)
141 GList *iter = __events;
144 appcore_base_event_node *node = iter->data;
146 if (node->type == type)
149 iter = g_list_next(iter);
155 static enum appcore_base_rm __get_rm(sensor_data_t data)
158 enum appcore_base_rm rm;
160 if (data.value_count <= 0) {
161 _ERR("Failed to get sensor data");
162 return APPCORE_BASE_RM_UNKNOWN;
165 event = data.values[0];
167 case AUTO_ROTATION_DEGREE_0:
168 rm = APPCORE_BASE_RM_PORTRAIT_NORMAL;
170 case AUTO_ROTATION_DEGREE_90:
171 rm = APPCORE_BASE_RM_LANDSCAPE_NORMAL;
173 case AUTO_ROTATION_DEGREE_180:
174 rm = APPCORE_BASE_RM_PORTRAIT_REVERSE;
176 case AUTO_ROTATION_DEGREE_270:
177 rm = APPCORE_BASE_RM_LANDSCAPE_REVERSE;
180 rm = APPCORE_BASE_RM_UNKNOWN;
187 static void __lock_cb(keynode_t *node, void *user_data)
191 enum appcore_base_rm rm;
193 __rotation.lock = !vconf_keynode_get_bool(node);
194 if (__rotation.lock) {
195 _DBG("Rotation locked");
196 rm = APPCORE_BASE_RM_PORTRAIT_NORMAL;
198 _DBG("Rotation unlocked");
199 r = sensord_get_data(__rotation.conn, AUTO_ROTATION_SENSOR, &data);
201 _ERR("Failed to get sensor data");
206 if (rm == APPCORE_BASE_RM_UNKNOWN) {
207 _ERR("Unknown mode");
212 if (__rotation.rm == rm)
215 _DBG("Rotation: %d -> %d", __rotation.rm, rm);
217 __invoke_callback((void *)&__rotation.rm, APPCORE_BASE_EVENT_DEVICE_ORIENTATION_CHANGED);
220 static void __auto_rotation_changed_cb(sensor_t sensor, unsigned int event_type,
221 sensor_data_t *data, void *user_data)
223 enum appcore_base_rm rm;
231 if (event_type != AUTO_ROTATION_CHANGE_STATE_EVENT)
234 rm = __get_rm(*data);
235 if (rm == APPCORE_BASE_RM_UNKNOWN) {
236 _ERR("Unknown mode");
240 _DBG("Rotation: %d -> %d", __rotation.rm, rm);
242 __invoke_callback((void *)&__rotation.rm, APPCORE_BASE_EVENT_DEVICE_ORIENTATION_CHANGED);
245 static void __unregister_rotation_changed_event(void)
251 if (__rotation.ref > 1)
254 vconf_ignore_key_changed(VCONFKEY_SETAPPL_AUTO_ROTATE_SCREEN_BOOL, __lock_cb);
255 sensord_unregister_event(__rotation.conn, AUTO_ROTATION_CHANGE_STATE_EVENT);
256 sensord_stop(__rotation.conn);
257 sensord_disconnect(__rotation.conn);
263 static void __register_rotation_changed_event(void)
269 if (__rotation.ref) {
274 sensor = sensord_get_sensor(AUTO_ROTATION_SENSOR);
275 __rotation.conn = sensord_connect(sensor);
276 if (__rotation.conn < 0) {
277 _ERR("Failed to connect sensord");
281 r = sensord_register_event(__rotation.conn, AUTO_ROTATION_CHANGE_STATE_EVENT,
282 SENSOR_INTERVAL_NORMAL, 0, __auto_rotation_changed_cb, NULL);
284 _ERR("Failed to register auto rotation change event");
285 sensord_disconnect(__rotation.conn);
289 r = sensord_start(__rotation.conn, 0);
291 _ERR("Failed to start sensord");
292 sensord_unregister_event(__rotation.conn, AUTO_ROTATION_CHANGE_STATE_EVENT);
293 sensord_disconnect(__rotation.conn);
298 vconf_get_bool(VCONFKEY_SETAPPL_AUTO_ROTATE_SCREEN_BOOL, &lock);
299 vconf_notify_key_changed(VCONFKEY_SETAPPL_AUTO_ROTATE_SCREEN_BOOL, __lock_cb, NULL);
301 __rotation.lock = !lock;
305 static void __on_low_memory(keynode_t *key, void *data)
309 val = vconf_keynode_get_int(key);
311 if (val >= VCONFKEY_SYSMAN_LOW_MEMORY_SOFT_WARNING) {
312 __invoke_callback(&val, APPCORE_BASE_EVENT_LOW_MEMORY);
317 static void __on_low_battery(keynode_t *key, void *data)
321 val = vconf_keynode_get_int(key);
323 if (val <= VCONFKEY_SYSMAN_BAT_CRITICAL_LOW)
324 __invoke_callback(&val, APPCORE_BASE_EVENT_LOW_BATTERY);
327 static void __destroy_lang_info(gpointer data)
329 struct lang_info_s *info = (struct lang_info_s *)data;
335 g_list_free_full(info->list, free);
341 static struct lang_info_s *__create_lang_info(const char *lang)
343 struct lang_info_s *info;
345 info = calloc(1, sizeof(struct lang_info_s));
347 _ERR("Out of memory");
351 info->parent = strdup(lang);
352 if (info->parent == NULL) {
353 _ERR("Out of memory");
361 static gint __compare_langs(gconstpointer a, gconstpointer b)
369 static char *__get_string_before(const char *str, const char *delim)
375 dup_str = strdup(str);
379 token = strtok(dup_str, delim);
385 new_str = strdup(token);
391 static GHashTable *__get_lang_table(void)
395 struct dirent *dentry;
397 struct stat stat_buf;
400 struct lang_info_s *info;
402 if (__locale_dir == NULL || __locale_dir[0] == '\0')
405 table = g_hash_table_new_full(g_str_hash, g_str_equal,
406 NULL, __destroy_lang_info);
408 _ERR("Out of memory");
412 dp = opendir(__locale_dir);
414 g_hash_table_destroy(table);
418 while ((dentry = readdir(dp)) != NULL) {
419 if (!strcmp(dentry->d_name, ".") ||
420 !strcmp(dentry->d_name, ".."))
423 snprintf(buf, sizeof(buf), "%s/%s",
424 __locale_dir, dentry->d_name);
425 ret = stat(buf, &stat_buf);
426 if (ret != 0 || !S_ISDIR(stat_buf.st_mode))
429 parent_lang = __get_string_before(dentry->d_name, "_");
430 if (parent_lang == NULL) {
431 _ERR("Out of memory");
435 info = g_hash_table_lookup(table, parent_lang);
437 info = __create_lang_info(parent_lang);
442 g_hash_table_insert(table, info->parent, info);
444 info->list = g_list_append(info->list, strdup(dentry->d_name));
452 static GList *__append_langs(const char *lang, GList *list, GHashTable *table)
454 struct lang_info_s *info;
456 char *parent_lang = NULL;
462 list = g_list_append(list, strdup(lang));
464 extract_lang = __get_string_before(lang, ".");
465 if (extract_lang == NULL)
468 found = g_list_find_custom(list, extract_lang, __compare_langs);
470 list = g_list_remove_link(list, found);
471 list = g_list_concat(list, found);
475 parent_lang = __get_string_before(extract_lang, "_");
476 if (parent_lang == NULL)
479 info = g_hash_table_lookup(table, parent_lang);
483 found = g_list_find_custom(info->list, extract_lang, __compare_langs);
485 info->list = g_list_remove_link(info->list, found);
486 list = g_list_concat(list, found);
490 found = g_list_find_custom(info->list, parent_lang, __compare_langs);
492 info->list = g_list_remove_link(info->list, found);
493 list = g_list_concat(list, found);
497 found = g_list_first(info->list);
499 info->list = g_list_remove_link(info->list, found);
500 list = g_list_concat(list, found);
512 static GList *__split_language(const char *lang)
518 dup_lang = strdup(lang);
519 if (dup_lang == NULL) {
520 _ERR("Out of memory");
524 token = strtok(dup_lang, ":");
525 while (token != NULL) {
526 list = g_list_append(list, strdup(token));
527 token = strtok(NULL, ":");
534 static GList *__append_default_langs(GList *list)
536 const char *langs[] = {"en_US", "en_GB", "en"};
540 for (i = 0; i < (sizeof(langs) / sizeof(langs[0])); i++) {
541 found = g_list_find_custom(list, langs[i], __compare_langs);
543 list = g_list_append(list, strdup(langs[i]));
549 static char *__get_language(const char *lang)
553 GList *lang_list = NULL;
556 char buf[LINE_MAX] = {'\0'};
559 list = __split_language(lang);
563 table = __get_lang_table();
565 g_list_free_full(list, free);
569 iter = g_list_first(list);
571 language = (char *)iter->data;
572 lang_list = __append_langs(language, lang_list, table);
573 iter = g_list_next(iter);
575 g_list_free_full(list, free);
576 g_hash_table_destroy(table);
578 lang_list = __append_default_langs(lang_list);
579 iter = g_list_first(lang_list);
581 language = (char *)iter->data;
583 if (buf[0] == '\0') {
584 snprintf(buf, sizeof(buf), "%s", language);
586 n = sizeof(buf) - strlen(buf) - 1;
587 strncat(buf, ":", n);
588 n = sizeof(buf) - strlen(buf) - 1;
589 strncat(buf, language, n);
592 iter = g_list_next(iter);
594 g_list_free_full(lang_list, free);
599 static void __update_lang(void)
605 lang = vconf_get_str(VCONFKEY_LANGSET);
607 /* TODO: Use VCONFKEY_SETAPPL_LANGUAGES key */
608 language = __get_language(lang);
610 _DBG("*****language(%s)", language);
611 setenv("LANGUAGE", language, 1);
614 setenv("LANGUAGE", lang, 1);
616 setenv("LANG", lang, 1);
617 setenv("LC_MESSAGES", lang, 1);
618 r = setlocale(LC_ALL, "");
620 r = setlocale(LC_ALL, "en_US.UTF-8");
622 _DBG("*****appcore setlocale=%s\n", r);
628 static void __update_region(void)
633 region = vconf_get_str(VCONFKEY_REGIONFORMAT);
635 setenv("LC_CTYPE", region, 1);
636 setenv("LC_NUMERIC", region, 1);
637 setenv("LC_TIME", region, 1);
638 setenv("LC_COLLATE", region, 1);
639 setenv("LC_MONETARY", region, 1);
640 setenv("LC_PAPER", region, 1);
641 setenv("LC_NAME", region, 1);
642 setenv("LC_ADDRESS", region, 1);
643 setenv("LC_TELEPHONE", region, 1);
644 setenv("LC_MEASUREMENT", region, 1);
645 setenv("LC_IDENTIFICATION", region, 1);
646 r = setlocale(LC_ALL, "");
648 _DBG("*****appcore setlocale=%s\n", r);
654 static void __on_language_change(keynode_t *key, void *data)
659 g_source_remove(__context.sid);
663 val = vconf_keynode_get_str(key);
666 __invoke_callback((void *)val, APPCORE_BASE_EVENT_LANG_CHANGE);
669 static void __on_region_change(keynode_t *key, void *data)
674 name = vconf_keynode_get_name(key);
678 if (strcmp(name, VCONFKEY_REGIONFORMAT) &&
679 strcmp(name, VCONFKEY_REGIONFORMAT_TIME1224))
682 val = vconf_get_str(VCONFKEY_REGIONFORMAT);
685 __invoke_callback((void *)val, APPCORE_BASE_EVENT_REGION_CHANGE);
689 static gboolean __invoke_lang_change(gpointer data)
695 lang = getenv("LANG");
697 return G_SOURCE_REMOVE;
699 __invoke_callback((void *)lang, APPCORE_BASE_EVENT_LANG_CHANGE);
701 return G_SOURCE_REMOVE;
704 static void __verify_language(void)
707 const char *env_lang;
709 env_lang = getenv("LANG");
713 lang = vconf_get_str(VCONFKEY_LANGSET);
717 if (strcmp(env_lang, lang) != 0) {
718 _INFO("LANG(%s), LANGSET(%s)", env_lang, lang);
719 __context.sid = g_idle_add(__invoke_lang_change, NULL);
725 static gboolean __flush_memory(gpointer data)
727 int suspend = APPCORE_BASE_SUSPENDED_STATE_WILL_ENTER_SUSPEND;
729 appcore_base_flush_memory();
732 if (!__context.allowed_bg && !__context.suspended_state) {
733 _DBG("[__SUSPEND__] flush case");
734 __invoke_callback((void *)&suspend, APPCORE_BASE_EVENT_SUSPENDED_STATE_CHANGE);
735 __context.suspended_state = true;
741 static void __add_suspend_timer(void)
743 __context.tid = g_timeout_add_seconds(5, __flush_memory, NULL);
746 static void __remove_suspend_timer(void)
748 if (__context.tid > 0) {
749 g_source_remove(__context.tid);
754 static void __on_receive_suspend_signal(GDBusConnection *connection,
755 const gchar *sender_name,
756 const gchar *object_path,
757 const gchar *interface_name,
758 const gchar *signal_name,
759 GVariant *parameters,
762 gint suspend = APPCORE_BASE_SUSPENDED_STATE_DID_EXIT_FROM_SUSPEND;
766 if (g_strcmp0(signal_name, RESOURCED_FREEZER_SIGNAL) == 0) {
767 g_variant_get(parameters, "(ii)", &status, &pid);
768 if (pid == getpid() && status == 0) {
769 if (!__context.allowed_bg && __context.suspended_state) {
770 __remove_suspend_timer();
771 __invoke_callback((void *)&suspend, APPCORE_BASE_EVENT_SUSPENDED_STATE_CHANGE);
772 __context.suspended_state = false;
773 __add_suspend_timer();
779 static int __init_suspend_dbus_handler(void)
783 if (__suspend_dbus_handler_initialized)
787 __bus = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &err);
789 _ERR("Failed to connect to the D-BUS daemon: %s",
796 __suspend_dbus_handler_initialized = g_dbus_connection_signal_subscribe(
799 RESOURCED_FREEZER_INTERFACE,
800 RESOURCED_FREEZER_SIGNAL,
801 RESOURCED_FREEZER_PATH,
803 G_DBUS_SIGNAL_FLAGS_NONE,
804 __on_receive_suspend_signal,
807 if (__suspend_dbus_handler_initialized == 0) {
808 _ERR("g_dbus_connection_signal_subscribe() is failed.");
812 _DBG("[__SUSPEND__] suspend signal initialized");
817 static void __fini_suspend_dbus_handler(void)
822 if (__suspend_dbus_handler_initialized) {
823 g_dbus_connection_signal_unsubscribe(__bus,
824 __suspend_dbus_handler_initialized);
825 __suspend_dbus_handler_initialized = 0;
828 g_object_unref(__bus);
832 static gboolean __init_suspend(gpointer data)
834 __init_suspend_dbus_handler();
835 return G_SOURCE_REMOVE;
838 static int __get_locale_resource_dir(char *locale_dir, int size)
840 const char *res_path;
842 res_path = aul_get_app_resource_path();
843 if (res_path == NULL) {
844 _ERR("Failed to get resource path");
848 snprintf(locale_dir, size, "%s" PATH_LOCALE, res_path);
849 if (access(locale_dir, R_OK) != 0)
850 _DBG("%s does not exist", locale_dir);
855 static int __get_app_name(const char *appid, char **name)
857 char *name_token = NULL;
862 /* com.vendor.name -> name */
863 name_token = strrchr(appid, '.');
864 if (name_token == NULL)
869 *name = strdup(name_token);
876 static int __set_i18n(const char *domain, const char *dir)
880 if (domain == NULL) {
888 __locale_dir = strdup(dir);
894 r = setlocale(LC_ALL, "");
895 /* if locale is not set properly, try to set "en_US" again */
897 r = setlocale(LC_ALL, "en_US.UTF-8");
898 _DBG("*****appcore setlocale=%s\n", r);
901 _ERR("appcore: setlocale() error");
903 r = bindtextdomain(domain, dir);
905 _ERR("appcore: bindtextdomain() error");
907 r = textdomain(domain);
909 _ERR("appcore: textdomain() error");
914 EXPORT_API int appcore_base_on_set_i18n(void)
917 char locale_dir[PATH_MAX];
918 char appid[PATH_MAX];
921 r = aul_app_get_appid_bypid(getpid(), appid, PATH_MAX);
923 _ERR("Failed to get application ID - pid(%d)", getpid());
927 r = __get_app_name(appid, &name);
931 r = __get_locale_resource_dir(locale_dir, sizeof(locale_dir));
937 r = __set_i18n(name, locale_dir);
948 EXPORT_API int appcore_base_set_i18n(const char *domain_name, const char *dir_name)
950 return __set_i18n(domain_name, dir_name);
953 EXPORT_API int appcore_base_init(appcore_base_ops ops, int argc, char **argv, void *data)
959 __context.argc = argc;
960 __context.argv = argv;
961 __context.data = data;
963 __context.suspended_state = false;
964 __context.allowed_bg = false;
966 if (__context.ops.init)
967 __context.ops.init(argc, argv, data);
969 if (TIZEN_FEATURE_BACKGROUND_MANAGEMENT)
970 g_idle_add(__init_suspend, NULL);
972 if (!__context.dirty) {
973 __context.dirty = true;
975 for (i = APPCORE_BASE_EVENT_START + 1; i < APPCORE_BASE_EVENT_MAX; i++) {
976 if (__exist_callback(i)) {
977 if (__context.ops.set_event)
978 __context.ops.set_event(i, __context.data);
984 if (__context.ops.set_i18n)
985 __context.ops.set_i18n(__context.data);
987 if (__context.ops.create) {
988 traceBegin(TTRACE_TAG_APPLICATION_MANAGER, "APPCORE:CREATE");
989 r = __context.ops.create(__context.data);
990 traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
992 aul_status_update(STATUS_DYING);
997 if (__context.ops.run)
998 __context.ops.run(__context.data);
1003 EXPORT_API void appcore_base_fini(void)
1007 aul_status_update(STATUS_DYING);
1008 if (__context.ops.terminate) {
1009 traceBegin(TTRACE_TAG_APPLICATION_MANAGER, "APPCORE:TERMINATE");
1010 __context.ops.terminate(__context.data);
1011 traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
1014 for (i = APPCORE_BASE_EVENT_START + 1; i < APPCORE_BASE_EVENT_MAX; i++) {
1015 if (__exist_callback(i)) {
1016 if (__context.ops.unset_event)
1017 __context.ops.unset_event(i, __context.data);
1021 if (__context.sid) {
1022 g_source_remove(__context.sid);
1026 g_list_free_full(__events, free);
1029 if (TIZEN_FEATURE_BACKGROUND_MANAGEMENT)
1030 __fini_suspend_dbus_handler();
1034 __locale_dir = NULL;
1037 __context.dirty = false;
1039 if (__context.ops.finish)
1040 __context.ops.finish();
1043 EXPORT_API int appcore_base_flush_memory(void)
1049 EXPORT_API int appcore_base_on_receive(aul_type type, bundle *b)
1052 const char **tep_path;
1060 _DBG("[APP %d] AUL event: AUL_START", getpid());
1061 tep_path = bundle_get_str_array(b, AUL_TEP_PATH, &len);
1063 for (i = 0; i < len; i++) {
1064 ret = aul_check_tep_mount(tep_path[i]);
1066 _ERR("mount request not completed within 1 sec");
1072 if (TIZEN_FEATURE_BACKGROUND_MANAGEMENT) {
1073 bg = bundle_get_val(b, AUL_K_ALLOWED_BG);
1074 if (bg && !strcmp(bg, "ALLOWED_BG")) {
1075 _DBG("[__SUSPEND__] allowed background");
1076 __context.allowed_bg = true;
1077 __remove_suspend_timer();
1081 if (__context.ops.control) {
1082 traceBegin(TTRACE_TAG_APPLICATION_MANAGER, "APPCORE:RESET");
1083 __context.ops.control(b, __context.data);
1084 traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
1088 _DBG("[APP %d] AUL event: AUL_RESUME", getpid());
1089 if (TIZEN_FEATURE_BACKGROUND_MANAGEMENT) {
1090 bg = bundle_get_val(b, AUL_K_ALLOWED_BG);
1091 if (bg && !strcmp(bg, "ALLOWED_BG")) {
1092 _DBG("[__SUSPEND__] allowed background");
1093 __context.allowed_bg = true;
1094 __remove_suspend_timer();
1099 _DBG("[APP %d] AUL event: AUL_TERMINATE", getpid());
1100 aul_status_update(STATUS_DYING);
1101 if (!__context.allowed_bg)
1102 __remove_suspend_timer();
1104 if (__context.ops.exit)
1105 __context.ops.exit(__context.data);
1107 case AUL_TERMINATE_BGAPP:
1108 _DBG("[APP %d] AUL event: AUL_TERMINATE_BGAPP", getpid());
1109 if (!__context.allowed_bg)
1110 __remove_suspend_timer();
1113 _DBG("[APP %d] AUL event: AUL_WAKE", getpid());
1114 if (TIZEN_FEATURE_BACKGROUND_MANAGEMENT) {
1115 if (!__context.allowed_bg &&
1116 __context.suspended_state) {
1117 int suspend = APPCORE_BASE_SUSPENDED_STATE_DID_EXIT_FROM_SUSPEND;
1118 __remove_suspend_timer();
1119 __invoke_callback((void *)&suspend, APPCORE_BASE_EVENT_SUSPENDED_STATE_CHANGE);
1120 __context.suspended_state = false;
1125 _DBG("[APP %d] AUL event: AUL_SUSPEND", getpid());
1126 if (TIZEN_FEATURE_BACKGROUND_MANAGEMENT) {
1127 if (!__context.allowed_bg &&
1128 !__context.suspended_state) {
1129 __remove_suspend_timer();
1130 __flush_memory(NULL);
1134 case AUL_UPDATE_REQUESTED:
1135 _DBG("[APP %d] AUL event: AUL_UPDATE_REQUESTED", getpid());
1136 __invoke_callback((void *)&dummy, APPCORE_BASE_EVENT_UPDATE_REQUESTED);
1139 _DBG("[APP %d] AUL event: %d", getpid(), type);
1147 EXPORT_API int appcore_base_on_create(void)
1150 r = aul_launch_init(__context.ops.receive, NULL);
1152 _ERR("Aul init failed: %d", r);
1156 r = aul_launch_argv_handler(__context.argc, __context.argv);
1158 _ERR("Aul argv handler failed: %d", r);
1165 EXPORT_API int appcore_base_on_control(bundle *b)
1170 EXPORT_API int appcore_base_on_terminate()
1177 EXPORT_API void appcore_base_on_set_event(enum appcore_base_event event)
1182 case APPCORE_BASE_EVENT_LOW_MEMORY:
1183 vconf_notify_key_changed(VCONFKEY_SYSMAN_LOW_MEMORY, __on_low_memory, NULL);
1185 case APPCORE_BASE_EVENT_LOW_BATTERY:
1186 vconf_notify_key_changed(VCONFKEY_SYSMAN_BATTERY_STATUS_LOW, __on_low_battery, NULL);
1188 case APPCORE_BASE_EVENT_LANG_CHANGE:
1189 vconf_notify_key_changed(VCONFKEY_LANGSET, __on_language_change, NULL);
1191 case APPCORE_BASE_EVENT_DEVICE_ORIENTATION_CHANGED:
1192 __register_rotation_changed_event();
1194 case APPCORE_BASE_EVENT_REGION_CHANGE:
1195 r = vconf_notify_key_changed(VCONFKEY_REGIONFORMAT, __on_region_change, NULL);
1199 vconf_notify_key_changed(VCONFKEY_REGIONFORMAT_TIME1224, __on_region_change, NULL);
1201 case APPCORE_BASE_EVENT_SUSPENDED_STATE_CHANGE:
1210 EXPORT_API void appcore_base_on_unset_event(enum appcore_base_event event)
1215 case APPCORE_BASE_EVENT_LOW_MEMORY:
1216 vconf_ignore_key_changed(VCONFKEY_SYSMAN_LOW_MEMORY, __on_low_memory);
1218 case APPCORE_BASE_EVENT_LOW_BATTERY:
1219 vconf_ignore_key_changed(VCONFKEY_SYSMAN_BATTERY_STATUS_LOW, __on_low_battery);
1221 case APPCORE_BASE_EVENT_LANG_CHANGE:
1222 vconf_ignore_key_changed(VCONFKEY_LANGSET, __on_language_change);
1224 case APPCORE_BASE_EVENT_DEVICE_ORIENTATION_CHANGED:
1225 __unregister_rotation_changed_event();
1227 case APPCORE_BASE_EVENT_REGION_CHANGE:
1228 r = vconf_ignore_key_changed(VCONFKEY_REGIONFORMAT, __on_region_change);
1231 vconf_ignore_key_changed(VCONFKEY_REGIONFORMAT_TIME1224, __on_region_change);
1233 case APPCORE_BASE_EVENT_SUSPENDED_STATE_CHANGE:
1240 EXPORT_API appcore_base_event_h appcore_base_add_event(enum appcore_base_event event,
1241 appcore_base_event_cb cb, void *data)
1243 appcore_base_event_node *node;
1245 if (__context.dirty && !__exist_callback(event)) {
1246 if (__context.ops.set_event)
1247 __context.ops.set_event(event, __context.data);
1250 node = malloc(sizeof(appcore_base_event_node));
1258 __events = g_list_append(__events, node);
1263 EXPORT_API int appcore_base_remove_event(appcore_base_event_h handle)
1265 appcore_base_event_node *node = handle;
1266 enum appcore_base_event event;
1268 if (!node || !g_list_find(__events, node))
1272 __events = g_list_remove(__events, node);
1274 if (__context.dirty && !__exist_callback(event)) {
1275 if (__context.ops.unset_event)
1276 __context.ops.unset_event(event, __context.data);
1282 EXPORT_API int appcore_base_raise_event(void *event, enum appcore_base_event type)
1284 __invoke_callback(event, type);
1288 EXPORT_API int appcore_base_get_rotation_state(enum appcore_base_rm *curr)
1293 if (!__rotation.ref)
1296 *curr = __rotation.rm;
1300 EXPORT_API bool appcore_base_is_bg_allowed(void)
1302 return __context.allowed_bg;
1305 EXPORT_API bool appcore_base_is_suspended(void)
1307 return __context.suspended_state;
1310 EXPORT_API void appcore_base_toggle_suspended_state(void)
1312 __context.suspended_state ^= __context.suspended_state;
1315 EXPORT_API void appcore_base_exit(void)
1317 if (__context.ops.exit)
1318 __context.ops.exit(__context.data);
1321 static int __on_receive(aul_type type, bundle *b, void *data)
1323 return appcore_base_on_receive(type, b);
1326 static int __on_create(void *data)
1328 return appcore_base_on_create();
1331 static int __on_control(bundle *b, void *data)
1333 return appcore_base_on_control(b);
1336 static int __on_terminate(void *data)
1338 return appcore_base_on_terminate();
1341 static int __on_set_i18n(void *data)
1343 return appcore_base_on_set_i18n();
1346 static void __on_set_event(enum appcore_base_event event, void *data)
1348 return appcore_base_on_set_event(event);
1351 static void __on_unset_event(enum appcore_base_event event, void *data)
1353 return appcore_base_on_unset_event(event);
1356 EXPORT_API appcore_base_ops appcore_base_get_default_ops(void)
1358 appcore_base_ops ops;
1360 ops.create = __on_create;
1361 ops.control = __on_control;
1362 ops.terminate = __on_terminate;
1363 ops.receive = __on_receive;
1364 ops.set_i18n = __on_set_i18n;
1369 ops.set_event = __on_set_event;
1370 ops.unset_event = __on_unset_event;