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 {
58 } appcore_base_context;
60 typedef struct _appcore_base_event_node {
62 appcore_base_event_cb cb;
64 } appcore_base_event_node;
66 typedef struct _appcore_base_rotation {
70 enum appcore_base_rm rm;
71 } appcore_base_rotation;
78 static appcore_base_context __context;
79 static GList *__events;
80 static GDBusConnection *__bus;
81 static guint __suspend_dbus_handler_initialized;
82 static char *__locale_dir;
83 static appcore_base_rotation __rotation;
85 appcore_base_tizen_profile_t appcore_base_get_tizen_profile(void)
87 static appcore_base_tizen_profile_t profile = TIZEN_PROFILE_UNKNOWN;
88 char *profile_name = NULL;
90 if (__builtin_expect(profile != TIZEN_PROFILE_UNKNOWN, 1))
93 system_info_get_platform_string("http://tizen.org/feature/profile",
95 if (profile_name == NULL)
98 switch (*profile_name) {
101 profile = TIZEN_PROFILE_MOBILE;
105 profile = TIZEN_PROFILE_WEARABLE;
109 profile = TIZEN_PROFILE_TV;
113 profile = TIZEN_PROFILE_IVI;
116 profile = TIZEN_PROFILE_COMMON;
125 static void __invoke_callback(void *event, int type)
127 GList *iter = __events;
130 appcore_base_event_node *node = iter->data;
132 if (node->type == type)
133 node->cb(event, node->data);
134 iter = g_list_next(iter);
138 static bool __exist_callback(int type)
140 GList *iter = __events;
143 appcore_base_event_node *node = iter->data;
145 if (node->type == type)
148 iter = g_list_next(iter);
154 static enum appcore_base_rm __get_rm(sensor_data_t data)
157 enum appcore_base_rm rm;
159 if (data.value_count <= 0) {
160 _ERR("Failed to get sensor data");
161 return APPCORE_BASE_RM_UNKNOWN;
164 event = data.values[0];
166 case AUTO_ROTATION_DEGREE_0:
167 rm = APPCORE_BASE_RM_PORTRAIT_NORMAL;
169 case AUTO_ROTATION_DEGREE_90:
170 rm = APPCORE_BASE_RM_LANDSCAPE_NORMAL;
172 case AUTO_ROTATION_DEGREE_180:
173 rm = APPCORE_BASE_RM_PORTRAIT_REVERSE;
175 case AUTO_ROTATION_DEGREE_270:
176 rm = APPCORE_BASE_RM_LANDSCAPE_REVERSE;
179 rm = APPCORE_BASE_RM_UNKNOWN;
186 static void __lock_cb(keynode_t *node, void *user_data)
190 enum appcore_base_rm rm;
192 __rotation.lock = !vconf_keynode_get_bool(node);
193 if (__rotation.lock) {
194 _DBG("Rotation locked");
195 rm = APPCORE_BASE_RM_PORTRAIT_NORMAL;
197 _DBG("Rotation unlocked");
198 r = sensord_get_data(__rotation.conn, AUTO_ROTATION_SENSOR, &data);
200 _ERR("Failed to get sensor data");
205 if (rm == APPCORE_BASE_RM_UNKNOWN) {
206 _ERR("Unknown mode");
211 if (__rotation.rm == rm)
214 _DBG("Rotation: %d -> %d", __rotation.rm, rm);
216 __invoke_callback((void *)&__rotation.rm, APPCORE_BASE_EVENT_DEVICE_ORIENTATION_CHANGED);
219 static void __auto_rotation_changed_cb(sensor_t sensor, unsigned int event_type,
220 sensor_data_t *data, void *user_data)
222 enum appcore_base_rm rm;
230 if (event_type != AUTO_ROTATION_CHANGE_STATE_EVENT)
233 rm = __get_rm(*data);
234 if (rm == APPCORE_BASE_RM_UNKNOWN) {
235 _ERR("Unknown mode");
239 _DBG("Rotation: %d -> %d", __rotation.rm, rm);
241 __invoke_callback((void *)&__rotation.rm, APPCORE_BASE_EVENT_DEVICE_ORIENTATION_CHANGED);
244 static void __unregister_rotation_changed_event(void)
250 if (__rotation.ref > 1)
253 vconf_ignore_key_changed(VCONFKEY_SETAPPL_AUTO_ROTATE_SCREEN_BOOL, __lock_cb);
254 sensord_unregister_event(__rotation.conn, AUTO_ROTATION_CHANGE_STATE_EVENT);
255 sensord_stop(__rotation.conn);
256 sensord_disconnect(__rotation.conn);
262 static void __register_rotation_changed_event(void)
268 if (__rotation.ref) {
273 sensor = sensord_get_sensor(AUTO_ROTATION_SENSOR);
274 __rotation.conn = sensord_connect(sensor);
275 if (__rotation.conn < 0) {
276 _ERR("Failed to connect sensord");
280 r = sensord_register_event(__rotation.conn, AUTO_ROTATION_CHANGE_STATE_EVENT,
281 SENSOR_INTERVAL_NORMAL, 0, __auto_rotation_changed_cb, NULL);
283 _ERR("Failed to register auto rotation change event");
284 sensord_disconnect(__rotation.conn);
288 r = sensord_start(__rotation.conn, 0);
290 _ERR("Failed to start sensord");
291 sensord_unregister_event(__rotation.conn, AUTO_ROTATION_CHANGE_STATE_EVENT);
292 sensord_disconnect(__rotation.conn);
297 vconf_get_bool(VCONFKEY_SETAPPL_AUTO_ROTATE_SCREEN_BOOL, &lock);
298 vconf_notify_key_changed(VCONFKEY_SETAPPL_AUTO_ROTATE_SCREEN_BOOL, __lock_cb, NULL);
300 __rotation.lock = !lock;
304 static void __on_low_memory(keynode_t *key, void *data)
308 val = vconf_keynode_get_int(key);
310 if (val >= VCONFKEY_SYSMAN_LOW_MEMORY_SOFT_WARNING) {
311 __invoke_callback(&val, APPCORE_BASE_EVENT_LOW_MEMORY);
316 static void __on_low_battery(keynode_t *key, void *data)
320 val = vconf_keynode_get_int(key);
322 if (val <= VCONFKEY_SYSMAN_BAT_CRITICAL_LOW)
323 __invoke_callback(&val, APPCORE_BASE_EVENT_LOW_BATTERY);
326 static void __destroy_lang_info(gpointer data)
328 struct lang_info_s *info = (struct lang_info_s *)data;
334 g_list_free_full(info->list, free);
340 static struct lang_info_s *__create_lang_info(const char *lang)
342 struct lang_info_s *info;
344 info = calloc(1, sizeof(struct lang_info_s));
346 _ERR("Out of memory");
350 info->parent = strdup(lang);
351 if (info->parent == NULL) {
352 _ERR("Out of memory");
360 static gint __compare_langs(gconstpointer a, gconstpointer b)
368 static char *__get_string_before(const char *str, const char *delim)
374 dup_str = strdup(str);
378 token = strtok(dup_str, delim);
384 new_str = strdup(token);
390 static GHashTable *__get_lang_table(void)
394 struct dirent *dentry;
396 struct stat stat_buf;
399 struct lang_info_s *info;
401 if (__locale_dir == NULL || __locale_dir[0] == '\0')
404 table = g_hash_table_new_full(g_str_hash, g_str_equal,
405 NULL, __destroy_lang_info);
407 _ERR("Out of memory");
411 dp = opendir(__locale_dir);
413 g_hash_table_destroy(table);
417 while ((dentry = readdir(dp)) != NULL) {
418 if (!strcmp(dentry->d_name, ".") ||
419 !strcmp(dentry->d_name, ".."))
422 snprintf(buf, sizeof(buf), "%s/%s",
423 __locale_dir, dentry->d_name);
424 ret = stat(buf, &stat_buf);
425 if (ret != 0 || !S_ISDIR(stat_buf.st_mode))
428 parent_lang = __get_string_before(dentry->d_name, "_");
429 if (parent_lang == NULL) {
430 _ERR("Out of memory");
434 info = g_hash_table_lookup(table, parent_lang);
436 info = __create_lang_info(parent_lang);
441 g_hash_table_insert(table, info->parent, info);
443 info->list = g_list_append(info->list, strdup(dentry->d_name));
451 static GList *__append_langs(const char *lang, GList *list, GHashTable *table)
453 struct lang_info_s *info;
455 char *parent_lang = NULL;
461 list = g_list_append(list, strdup(lang));
463 extract_lang = __get_string_before(lang, ".");
464 if (extract_lang == NULL)
467 found = g_list_find_custom(list, extract_lang, __compare_langs);
469 list = g_list_remove_link(list, found);
470 list = g_list_concat(list, found);
474 parent_lang = __get_string_before(extract_lang, "_");
475 if (parent_lang == NULL)
478 info = g_hash_table_lookup(table, parent_lang);
482 found = g_list_find_custom(info->list, extract_lang, __compare_langs);
484 info->list = g_list_remove_link(info->list, found);
485 list = g_list_concat(list, found);
489 found = g_list_find_custom(info->list, parent_lang, __compare_langs);
491 info->list = g_list_remove_link(info->list, found);
492 list = g_list_concat(list, found);
496 found = g_list_first(info->list);
498 info->list = g_list_remove_link(info->list, found);
499 list = g_list_concat(list, found);
511 static GList *__split_language(const char *lang)
517 dup_lang = strdup(lang);
518 if (dup_lang == NULL) {
519 _ERR("Out of memory");
523 token = strtok(dup_lang, ":");
524 while (token != NULL) {
525 list = g_list_append(list, strdup(token));
526 token = strtok(NULL, ":");
533 static GList *__append_default_langs(GList *list)
535 const char *langs[] = {"en_US", "en_GB", "en"};
539 for (i = 0; i < (sizeof(langs) / sizeof(langs[0])); i++) {
540 found = g_list_find_custom(list, langs[i], __compare_langs);
542 list = g_list_append(list, strdup(langs[i]));
548 static char *__get_language(const char *lang)
552 GList *lang_list = NULL;
555 char buf[LINE_MAX] = {'\0'};
558 list = __split_language(lang);
562 table = __get_lang_table();
564 g_list_free_full(list, free);
568 iter = g_list_first(list);
570 language = (char *)iter->data;
571 lang_list = __append_langs(language, lang_list, table);
572 iter = g_list_next(iter);
574 g_list_free_full(list, free);
575 g_hash_table_destroy(table);
577 lang_list = __append_default_langs(lang_list);
578 iter = g_list_first(lang_list);
580 language = (char *)iter->data;
582 if (buf[0] == '\0') {
583 snprintf(buf, sizeof(buf), "%s", language);
585 n = sizeof(buf) - strlen(buf) - 1;
586 strncat(buf, ":", n);
587 n = sizeof(buf) - strlen(buf) - 1;
588 strncat(buf, language, n);
591 iter = g_list_next(iter);
593 g_list_free_full(lang_list, free);
598 static void __update_lang(void)
604 lang = vconf_get_str(VCONFKEY_LANGSET);
606 /* TODO: Use VCONFKEY_SETAPPL_LANGUAGES key */
607 language = __get_language(lang);
609 _DBG("*****language(%s)", language);
610 setenv("LANGUAGE", language, 1);
613 setenv("LANGUAGE", lang, 1);
615 setenv("LANG", lang, 1);
616 setenv("LC_MESSAGES", lang, 1);
617 r = setlocale(LC_ALL, "");
619 r = setlocale(LC_ALL, "en_US.UTF-8");
621 _DBG("*****appcore setlocale=%s\n", r);
627 static void __update_region(void)
632 region = vconf_get_str(VCONFKEY_REGIONFORMAT);
634 setenv("LC_CTYPE", region, 1);
635 setenv("LC_NUMERIC", region, 1);
636 setenv("LC_TIME", region, 1);
637 setenv("LC_COLLATE", region, 1);
638 setenv("LC_MONETARY", region, 1);
639 setenv("LC_PAPER", region, 1);
640 setenv("LC_NAME", region, 1);
641 setenv("LC_ADDRESS", region, 1);
642 setenv("LC_TELEPHONE", region, 1);
643 setenv("LC_MEASUREMENT", region, 1);
644 setenv("LC_IDENTIFICATION", region, 1);
645 r = setlocale(LC_ALL, "");
647 _DBG("*****appcore setlocale=%s\n", r);
653 static void __on_language_change(keynode_t *key, void *data)
657 val = vconf_keynode_get_str(key);
660 __invoke_callback((void *)val, APPCORE_BASE_EVENT_LANG_CHANGE);
663 static void __on_region_change(keynode_t *key, void *data)
668 name = vconf_keynode_get_name(key);
672 if (strcmp(name, VCONFKEY_REGIONFORMAT) &&
673 strcmp(name, VCONFKEY_REGIONFORMAT_TIME1224))
676 val = vconf_get_str(VCONFKEY_REGIONFORMAT);
679 __invoke_callback((void *)val, APPCORE_BASE_EVENT_REGION_CHANGE);
683 static gboolean __flush_memory(gpointer data)
685 int suspend = APPCORE_BASE_SUSPENDED_STATE_WILL_ENTER_SUSPEND;
687 appcore_base_flush_memory();
690 if (!__context.allowed_bg && !__context.suspended_state) {
691 _DBG("[__SUSPEND__] flush case");
692 __invoke_callback((void *)&suspend, APPCORE_BASE_EVENT_SUSPENDED_STATE_CHANGE);
693 __context.suspended_state = true;
699 static void __add_suspend_timer(void)
701 __context.tid = g_timeout_add_seconds(5, __flush_memory, NULL);
704 static void __remove_suspend_timer(void)
706 if (__context.tid > 0) {
707 g_source_remove(__context.tid);
712 static void __on_receive_suspend_signal(GDBusConnection *connection,
713 const gchar *sender_name,
714 const gchar *object_path,
715 const gchar *interface_name,
716 const gchar *signal_name,
717 GVariant *parameters,
720 gint suspend = APPCORE_BASE_SUSPENDED_STATE_DID_EXIT_FROM_SUSPEND;
724 if (g_strcmp0(signal_name, RESOURCED_FREEZER_SIGNAL) == 0) {
725 g_variant_get(parameters, "(ii)", &status, &pid);
726 if (pid == getpid() && status == 0) {
727 if (!__context.allowed_bg && __context.suspended_state) {
728 __remove_suspend_timer();
729 __invoke_callback((void *)&suspend, APPCORE_BASE_EVENT_SUSPENDED_STATE_CHANGE);
730 __context.suspended_state = false;
731 __add_suspend_timer();
737 static int __init_suspend_dbus_handler(void)
741 if (__suspend_dbus_handler_initialized)
745 __bus = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &err);
747 _ERR("Failed to connect to the D-BUS daemon: %s",
754 __suspend_dbus_handler_initialized = g_dbus_connection_signal_subscribe(
757 RESOURCED_FREEZER_INTERFACE,
758 RESOURCED_FREEZER_SIGNAL,
759 RESOURCED_FREEZER_PATH,
761 G_DBUS_SIGNAL_FLAGS_NONE,
762 __on_receive_suspend_signal,
765 if (__suspend_dbus_handler_initialized == 0) {
766 _ERR("g_dbus_connection_signal_subscribe() is failed.");
770 _DBG("[__SUSPEND__] suspend signal initialized");
775 static void __fini_suspend_dbus_handler(void)
780 if (__suspend_dbus_handler_initialized) {
781 g_dbus_connection_signal_unsubscribe(__bus,
782 __suspend_dbus_handler_initialized);
783 __suspend_dbus_handler_initialized = 0;
786 g_object_unref(__bus);
790 static int __get_locale_resource_dir(char *locale_dir, int size)
792 const char *res_path;
794 res_path = aul_get_app_resource_path();
795 if (res_path == NULL) {
796 _ERR("Failed to get resource path");
800 snprintf(locale_dir, size, "%s" PATH_LOCALE, res_path);
801 if (access(locale_dir, R_OK) != 0)
802 _DBG("%s does not exist", locale_dir);
807 static int __get_app_name(const char *appid, char **name)
809 char *name_token = NULL;
814 /* com.vendor.name -> name */
815 name_token = strrchr(appid, '.');
816 if (name_token == NULL)
821 *name = strdup(name_token);
828 static int __set_i18n(const char *domain, const char *dir)
832 if (domain == NULL) {
840 __locale_dir = strdup(dir);
846 r = setlocale(LC_ALL, "");
847 /* if locale is not set properly, try to set "en_US" again */
849 r = setlocale(LC_ALL, "en_US.UTF-8");
850 _DBG("*****appcore setlocale=%s\n", r);
853 _ERR("appcore: setlocale() error");
855 r = bindtextdomain(domain, dir);
857 _ERR("appcore: bindtextdomain() error");
859 r = textdomain(domain);
861 _ERR("appcore: textdomain() error");
866 EXPORT_API int appcore_base_on_set_i18n(void)
869 char locale_dir[PATH_MAX];
870 char appid[PATH_MAX];
873 r = aul_app_get_appid_bypid(getpid(), appid, PATH_MAX);
875 _ERR("Failed to get application ID - pid(%d)", getpid());
879 r = __get_app_name(appid, &name);
883 r = __get_locale_resource_dir(locale_dir, sizeof(locale_dir));
889 r = __set_i18n(name, locale_dir);
900 EXPORT_API int appcore_base_set_i18n(const char *domain_name, const char *dir_name)
902 return __set_i18n(domain_name, dir_name);
905 EXPORT_API int appcore_base_init(appcore_base_ops ops, int argc, char **argv, void *data)
911 __context.argc = argc;
912 __context.argv = argv;
913 __context.data = data;
915 __context.suspended_state = false;
916 __context.allowed_bg = false;
918 if (__context.ops.init)
919 __context.ops.init(argc, argv, data);
921 if (__context.ops.set_i18n)
922 __context.ops.set_i18n(__context.data);
924 if (TIZEN_FEATURE_BACKGROUND_MANAGEMENT)
925 __init_suspend_dbus_handler();
927 if (!__context.dirty) {
928 __context.dirty = true;
930 for (i = APPCORE_BASE_EVENT_START + 1; i < APPCORE_BASE_EVENT_MAX; i++) {
931 if (__exist_callback(i)) {
932 if (__context.ops.set_event)
933 __context.ops.set_event(i, __context.data);
938 if (__context.ops.create) {
939 traceBegin(TTRACE_TAG_APPLICATION_MANAGER, "APPCORE:CREATE");
940 r = __context.ops.create(__context.data);
941 traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
943 aul_status_update(STATUS_DYING);
948 if (__context.ops.run)
949 __context.ops.run(__context.data);
954 EXPORT_API void appcore_base_fini(void)
958 aul_status_update(STATUS_DYING);
959 if (__context.ops.terminate) {
960 traceBegin(TTRACE_TAG_APPLICATION_MANAGER, "APPCORE:TERMINATE");
961 __context.ops.terminate(__context.data);
962 traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
965 for (i = APPCORE_BASE_EVENT_START + 1; i < APPCORE_BASE_EVENT_MAX; i++) {
966 if (__exist_callback(i)) {
967 if (__context.ops.unset_event)
968 __context.ops.unset_event(i, __context.data);
972 g_list_free_full(__events, free);
975 if (TIZEN_FEATURE_BACKGROUND_MANAGEMENT)
976 __fini_suspend_dbus_handler();
983 __context.dirty = false;
985 if (__context.ops.finish)
986 __context.ops.finish();
989 EXPORT_API int appcore_base_flush_memory(void)
995 EXPORT_API int appcore_base_on_receive(aul_type type, bundle *b)
998 const char **tep_path;
1006 _DBG("[APP %d] AUL event: AUL_START", getpid());
1007 tep_path = bundle_get_str_array(b, AUL_TEP_PATH, &len);
1009 for (i = 0; i < len; i++) {
1010 ret = aul_check_tep_mount(tep_path[i]);
1012 _ERR("mount request not completed within 1 sec");
1018 if (TIZEN_FEATURE_BACKGROUND_MANAGEMENT) {
1019 bg = bundle_get_val(b, AUL_K_ALLOWED_BG);
1020 if (bg && !strcmp(bg, "ALLOWED_BG")) {
1021 _DBG("[__SUSPEND__] allowed background");
1022 __context.allowed_bg = true;
1023 __remove_suspend_timer();
1027 if (__context.ops.control) {
1028 traceBegin(TTRACE_TAG_APPLICATION_MANAGER, "APPCORE:RESET");
1029 __context.ops.control(b, __context.data);
1030 traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
1034 _DBG("[APP %d] AUL event: AUL_RESUME", getpid());
1035 if (TIZEN_FEATURE_BACKGROUND_MANAGEMENT) {
1036 bg = bundle_get_val(b, AUL_K_ALLOWED_BG);
1037 if (bg && !strcmp(bg, "ALLOWED_BG")) {
1038 _DBG("[__SUSPEND__] allowed background");
1039 __context.allowed_bg = true;
1040 __remove_suspend_timer();
1045 _DBG("[APP %d] AUL event: AUL_TERMINATE", getpid());
1046 aul_status_update(STATUS_DYING);
1047 if (!__context.allowed_bg)
1048 __remove_suspend_timer();
1050 if (__context.ops.exit)
1051 __context.ops.exit(__context.data);
1053 case AUL_TERMINATE_BGAPP:
1054 _DBG("[APP %d] AUL event: AUL_TERMINATE_BGAPP", getpid());
1055 if (!__context.allowed_bg)
1056 __remove_suspend_timer();
1059 _DBG("[APP %d] AUL event: AUL_WAKE", getpid());
1060 if (TIZEN_FEATURE_BACKGROUND_MANAGEMENT) {
1061 if (!__context.allowed_bg &&
1062 __context.suspended_state) {
1063 int suspend = APPCORE_BASE_SUSPENDED_STATE_DID_EXIT_FROM_SUSPEND;
1064 __remove_suspend_timer();
1065 __invoke_callback((void *)&suspend, APPCORE_BASE_EVENT_SUSPENDED_STATE_CHANGE);
1066 __context.suspended_state = false;
1071 _DBG("[APP %d] AUL event: AUL_SUSPEND", getpid());
1072 if (TIZEN_FEATURE_BACKGROUND_MANAGEMENT) {
1073 if (!__context.allowed_bg &&
1074 !__context.suspended_state) {
1075 __remove_suspend_timer();
1076 __flush_memory(NULL);
1080 case AUL_UPDATE_REQUESTED:
1081 _DBG("[APP %d] AUL event: AUL_UPDATE_REQUESTED", getpid());
1082 __invoke_callback((void *)&dummy, APPCORE_BASE_EVENT_UPDATE_REQUESTED);
1085 _DBG("[APP %d] AUL event: %d", getpid(), type);
1093 EXPORT_API int appcore_base_on_create(void)
1096 r = aul_launch_init(__context.ops.receive, NULL);
1098 _ERR("Aul init failed: %d", r);
1102 r = aul_launch_argv_handler(__context.argc, __context.argv);
1104 _ERR("Aul argv handler failed: %d", r);
1111 EXPORT_API int appcore_base_on_control(bundle *b)
1116 EXPORT_API int appcore_base_on_terminate()
1123 EXPORT_API void appcore_base_on_set_event(enum appcore_base_event event)
1128 case APPCORE_BASE_EVENT_LOW_MEMORY:
1129 vconf_notify_key_changed(VCONFKEY_SYSMAN_LOW_MEMORY, __on_low_memory, NULL);
1131 case APPCORE_BASE_EVENT_LOW_BATTERY:
1132 vconf_notify_key_changed(VCONFKEY_SYSMAN_BATTERY_STATUS_LOW, __on_low_battery, NULL);
1134 case APPCORE_BASE_EVENT_LANG_CHANGE:
1135 vconf_notify_key_changed(VCONFKEY_LANGSET, __on_language_change, NULL);
1137 case APPCORE_BASE_EVENT_DEVICE_ORIENTATION_CHANGED:
1138 __register_rotation_changed_event();
1140 case APPCORE_BASE_EVENT_REGION_CHANGE:
1141 r = vconf_notify_key_changed(VCONFKEY_REGIONFORMAT, __on_region_change, NULL);
1145 vconf_notify_key_changed(VCONFKEY_REGIONFORMAT_TIME1224, __on_region_change, NULL);
1147 case APPCORE_BASE_EVENT_SUSPENDED_STATE_CHANGE:
1156 EXPORT_API void appcore_base_on_unset_event(enum appcore_base_event event)
1161 case APPCORE_BASE_EVENT_LOW_MEMORY:
1162 vconf_ignore_key_changed(VCONFKEY_SYSMAN_LOW_MEMORY, __on_low_memory);
1164 case APPCORE_BASE_EVENT_LOW_BATTERY:
1165 vconf_ignore_key_changed(VCONFKEY_SYSMAN_BATTERY_STATUS_LOW, __on_low_battery);
1167 case APPCORE_BASE_EVENT_LANG_CHANGE:
1168 vconf_ignore_key_changed(VCONFKEY_LANGSET, __on_language_change);
1170 case APPCORE_BASE_EVENT_DEVICE_ORIENTATION_CHANGED:
1171 __unregister_rotation_changed_event();
1173 case APPCORE_BASE_EVENT_REGION_CHANGE:
1174 r = vconf_ignore_key_changed(VCONFKEY_REGIONFORMAT, __on_region_change);
1177 vconf_ignore_key_changed(VCONFKEY_REGIONFORMAT_TIME1224, __on_region_change);
1179 case APPCORE_BASE_EVENT_SUSPENDED_STATE_CHANGE:
1186 EXPORT_API appcore_base_event_h appcore_base_add_event(enum appcore_base_event event,
1187 appcore_base_event_cb cb, void *data)
1189 appcore_base_event_node *node;
1191 if (__context.dirty && !__exist_callback(event)) {
1192 if (__context.ops.set_event)
1193 __context.ops.set_event(event, __context.data);
1196 node = malloc(sizeof(appcore_base_event_node));
1204 __events = g_list_append(__events, node);
1209 EXPORT_API int appcore_base_remove_event(appcore_base_event_h handle)
1211 appcore_base_event_node *node = handle;
1212 enum appcore_base_event event;
1214 if (!node || !g_list_find(__events, node))
1218 __events = g_list_remove(__events, node);
1220 if (__context.dirty && !__exist_callback(event)) {
1221 if (__context.ops.unset_event)
1222 __context.ops.unset_event(event, __context.data);
1228 EXPORT_API int appcore_base_raise_event(void *event, enum appcore_base_event type)
1230 __invoke_callback(event, type);
1234 EXPORT_API int appcore_base_get_rotation_state(enum appcore_base_rm *curr)
1239 if (!__rotation.ref)
1242 *curr = __rotation.rm;
1246 EXPORT_API bool appcore_base_is_bg_allowed(void)
1248 return __context.allowed_bg;
1251 EXPORT_API bool appcore_base_is_suspended(void)
1253 return __context.suspended_state;
1256 EXPORT_API void appcore_base_toggle_suspended_state(void)
1258 __context.suspended_state ^= __context.suspended_state;
1261 EXPORT_API void appcore_base_exit(void)
1263 if (__context.ops.exit)
1264 __context.ops.exit(__context.data);
1267 static int __on_receive(aul_type type, bundle *b, void *data)
1269 return appcore_base_on_receive(type, b);
1272 static int __on_create(void *data)
1274 return appcore_base_on_create();
1277 static int __on_control(bundle *b, void *data)
1279 return appcore_base_on_control(b);
1282 static int __on_terminate(void *data)
1284 return appcore_base_on_terminate();
1287 static int __on_set_i18n(void *data)
1289 return appcore_base_on_set_i18n();
1292 static void __on_set_event(enum appcore_base_event event, void *data)
1294 return appcore_base_on_set_event(event);
1297 static void __on_unset_event(enum appcore_base_event event, void *data)
1299 return appcore_base_on_unset_event(event);
1302 EXPORT_API appcore_base_ops appcore_base_get_default_ops(void)
1304 appcore_base_ops ops;
1306 ops.create = __on_create;
1307 ops.control = __on_control;
1308 ops.terminate = __on_terminate;
1309 ops.receive = __on_receive;
1310 ops.set_i18n = __on_set_i18n;
1315 ops.set_event = __on_set_event;
1316 ops.unset_event = __on_unset_event;