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>
39 #include "appcore_base.h"
40 #include "appcore_base_private.h"
42 #define PATH_LOCALE "locale"
43 #define RESOURCED_FREEZER_PATH "/Org/Tizen/Resourced/Freezer"
44 #define RESOURCED_FREEZER_INTERFACE "org.tizen.resourced.freezer"
45 #define RESOURCED_FREEZER_SIGNAL "FreezerState"
47 typedef struct _appcore_base_context {
56 } appcore_base_context;
58 typedef struct _appcore_base_event_node {
60 appcore_base_event_cb cb;
62 } appcore_base_event_node;
64 typedef struct _appcore_base_rotation {
68 enum appcore_base_rm rm;
69 } appcore_base_rotation;
76 static appcore_base_context __context;
77 static GList *__events;
78 static GDBusConnection *__bus;
79 static guint __suspend_dbus_handler_initialized;
80 static char *__locale_dir;
81 static appcore_base_rotation __rotation;
83 static void __invoke_callback(void *event, int type)
85 GList *iter = __events;
88 appcore_base_event_node *node = iter->data;
90 if (node->type == type)
91 node->cb(event, node->data);
92 iter = g_list_next(iter);
96 static bool __exist_callback(int type)
98 GList *iter = __events;
101 appcore_base_event_node *node = iter->data;
103 if (node->type == type)
106 iter = g_list_next(iter);
112 static enum appcore_base_rm __get_rm(sensor_data_t data)
115 enum appcore_base_rm rm;
117 if (data.value_count <= 0) {
118 _ERR("Failed to get sensor data");
119 return APPCORE_BASE_RM_UNKNOWN;
122 event = data.values[0];
124 case AUTO_ROTATION_DEGREE_0:
125 rm = APPCORE_BASE_RM_PORTRAIT_NORMAL;
127 case AUTO_ROTATION_DEGREE_90:
128 rm = APPCORE_BASE_RM_LANDSCAPE_NORMAL;
130 case AUTO_ROTATION_DEGREE_180:
131 rm = APPCORE_BASE_RM_PORTRAIT_REVERSE;
133 case AUTO_ROTATION_DEGREE_270:
134 rm = APPCORE_BASE_RM_LANDSCAPE_REVERSE;
137 rm = APPCORE_BASE_RM_UNKNOWN;
144 static void __lock_cb(keynode_t *node, void *user_data)
148 enum appcore_base_rm rm;
150 __rotation.lock = !vconf_keynode_get_bool(node);
151 if (__rotation.lock) {
152 _DBG("Rotation locked");
153 rm = APPCORE_BASE_RM_PORTRAIT_NORMAL;
155 _DBG("Rotation unlocked");
156 r = sensord_get_data(__rotation.conn, AUTO_ROTATION_SENSOR, &data);
158 _ERR("Failed to get sensor data");
163 if (rm == APPCORE_BASE_RM_UNKNOWN) {
164 _ERR("Unknown mode");
169 if (__rotation.rm == rm)
172 _DBG("Rotation: %d -> %d", __rotation.rm, rm);
174 __invoke_callback((void *)&__rotation.rm, APPCORE_BASE_EVENT_DEVICE_ORIENTATION_CHANGED);
177 static void __auto_rotation_changed_cb(sensor_t sensor, unsigned int event_type,
178 sensor_data_t *data, void *user_data)
180 enum appcore_base_rm rm;
188 if (event_type != AUTO_ROTATION_CHANGE_STATE_EVENT)
191 rm = __get_rm(*data);
192 if (rm == APPCORE_BASE_RM_UNKNOWN) {
193 _ERR("Unknown mode");
197 _DBG("Rotation: %d -> %d", __rotation.rm, rm);
199 __invoke_callback((void *)&__rotation.rm, APPCORE_BASE_EVENT_DEVICE_ORIENTATION_CHANGED);
202 static void __unregister_rotation_changed_event(void)
208 if (__rotation.ref > 1)
211 vconf_ignore_key_changed(VCONFKEY_SETAPPL_AUTO_ROTATE_SCREEN_BOOL, __lock_cb);
212 sensord_unregister_event(__rotation.conn, AUTO_ROTATION_CHANGE_STATE_EVENT);
213 sensord_stop(__rotation.conn);
214 sensord_disconnect(__rotation.conn);
220 static void __register_rotation_changed_event(void)
226 if (__rotation.ref) {
231 sensor = sensord_get_sensor(AUTO_ROTATION_SENSOR);
232 __rotation.conn = sensord_connect(sensor);
233 if (__rotation.conn < 0) {
234 _ERR("Failed to connect sensord");
238 r = sensord_register_event(__rotation.conn, AUTO_ROTATION_CHANGE_STATE_EVENT,
239 SENSOR_INTERVAL_NORMAL, 0, __auto_rotation_changed_cb, NULL);
241 _ERR("Failed to register auto rotation change event");
242 sensord_disconnect(__rotation.conn);
246 r = sensord_start(__rotation.conn, 0);
248 _ERR("Failed to start sensord");
249 sensord_unregister_event(__rotation.conn, AUTO_ROTATION_CHANGE_STATE_EVENT);
250 sensord_disconnect(__rotation.conn);
255 vconf_get_bool(VCONFKEY_SETAPPL_AUTO_ROTATE_SCREEN_BOOL, &lock);
256 vconf_notify_key_changed(VCONFKEY_SETAPPL_AUTO_ROTATE_SCREEN_BOOL, __lock_cb, NULL);
258 __rotation.lock = !lock;
262 static void __on_low_memory(keynode_t *key, void *data)
266 val = vconf_keynode_get_int(key);
268 if (val >= VCONFKEY_SYSMAN_LOW_MEMORY_SOFT_WARNING) {
269 __invoke_callback(&val, APPCORE_BASE_EVENT_LOW_MEMORY);
274 static void __on_low_battery(keynode_t *key, void *data)
278 val = vconf_keynode_get_int(key);
280 if (val <= VCONFKEY_SYSMAN_BAT_CRITICAL_LOW)
281 __invoke_callback(&val, APPCORE_BASE_EVENT_LOW_BATTERY);
284 static void __destroy_lang_info(gpointer data)
286 struct lang_info_s *info = (struct lang_info_s *)data;
292 g_list_free_full(info->list, free);
298 static struct lang_info_s *__create_lang_info(const char *lang)
300 struct lang_info_s *info;
302 info = calloc(1, sizeof(struct lang_info_s));
304 _ERR("Out of memory");
308 info->parent = strdup(lang);
309 if (info->parent == NULL) {
310 _ERR("Out of memory");
318 static gint __compare_langs(gconstpointer a, gconstpointer b)
326 static char *__get_string_before(const char *str, const char *delim)
332 dup_str = strdup(str);
336 token = strtok(dup_str, delim);
342 new_str = strdup(token);
348 static GHashTable *__get_lang_table(void)
352 struct dirent *dentry;
354 struct stat stat_buf;
357 struct lang_info_s *info;
359 if (__locale_dir == NULL || __locale_dir[0] == '\0')
362 table = g_hash_table_new_full(g_str_hash, g_str_equal,
363 NULL, __destroy_lang_info);
365 _ERR("Out of memory");
369 dp = opendir(__locale_dir);
371 g_hash_table_destroy(table);
375 while ((dentry = readdir(dp)) != NULL) {
376 if (!strcmp(dentry->d_name, ".") ||
377 !strcmp(dentry->d_name, ".."))
380 snprintf(buf, sizeof(buf), "%s/%s",
381 __locale_dir, dentry->d_name);
382 ret = stat(buf, &stat_buf);
383 if (ret != 0 || !S_ISDIR(stat_buf.st_mode))
386 parent_lang = __get_string_before(dentry->d_name, "_");
387 if (parent_lang == NULL) {
388 _ERR("Out of memory");
392 info = g_hash_table_lookup(table, parent_lang);
394 info = __create_lang_info(parent_lang);
399 g_hash_table_insert(table, info->parent, info);
401 info->list = g_list_append(info->list, strdup(dentry->d_name));
409 static GList *__append_langs(const char *lang, GList *list, GHashTable *table)
411 struct lang_info_s *info;
413 char *parent_lang = NULL;
419 extract_lang = __get_string_before(lang, ".");
420 if (extract_lang == NULL)
423 found = g_list_find_custom(list, extract_lang, __compare_langs);
425 list = g_list_remove_link(list, found);
426 list = g_list_concat(list, found);
430 parent_lang = __get_string_before(extract_lang, "_");
431 if (parent_lang == NULL)
434 info = g_hash_table_lookup(table, parent_lang);
438 found = g_list_find_custom(info->list, extract_lang, __compare_langs);
440 info->list = g_list_remove_link(info->list, found);
441 list = g_list_concat(list, found);
445 found = g_list_find_custom(info->list, parent_lang, __compare_langs);
447 info->list = g_list_remove_link(info->list, found);
448 list = g_list_concat(list, found);
452 found = g_list_first(info->list);
454 info->list = g_list_remove_link(info->list, found);
455 list = g_list_concat(list, found);
467 static GList *__split_language(const char *lang)
473 dup_lang = strdup(lang);
474 if (dup_lang == NULL) {
475 _ERR("Out of memory");
479 token = strtok(dup_lang, ":");
480 while (token != NULL) {
481 list = g_list_append(list, strdup(token));
482 token = strtok(NULL, ":");
489 static GList *__append_default_langs(GList *list)
491 const char *langs[] = {"en_US", "en_GB", "en"};
495 for (i = 0; i < (sizeof(langs) / sizeof(langs[0])); i++) {
496 found = g_list_find_custom(list, langs[i], __compare_langs);
498 list = g_list_append(list, strdup(langs[i]));
504 static char *__get_language(const char *lang)
508 GList *lang_list = NULL;
511 char buf[LINE_MAX] = {'\0'};
514 list = __split_language(lang);
518 table = __get_lang_table();
520 g_list_free_full(list, free);
524 iter = g_list_first(list);
526 language = (char *)iter->data;
527 lang_list = __append_langs(language, lang_list, table);
528 iter = g_list_next(iter);
530 g_list_free_full(list, free);
531 g_hash_table_destroy(table);
533 lang_list = __append_default_langs(lang_list);
534 iter = g_list_first(lang_list);
536 language = (char *)iter->data;
538 if (buf[0] == '\0') {
539 snprintf(buf, sizeof(buf), "%s", language);
541 n = sizeof(buf) - strlen(buf) - 1;
542 strncat(buf, ":", n);
543 n = sizeof(buf) - strlen(buf) - 1;
544 strncat(buf, language, n);
547 iter = g_list_next(iter);
549 g_list_free_full(lang_list, free);
554 static void __update_lang(void)
560 lang = vconf_get_str(VCONFKEY_LANGSET);
562 /* TODO: Use VCONFKEY_SETAPPL_LANGUAGES key */
563 language = __get_language(lang);
565 _DBG("*****language(%s)", language);
566 setenv("LANGUAGE", language, 1);
569 setenv("LANGUAGE", lang, 1);
571 setenv("LANG", lang, 1);
572 setenv("LC_MESSAGES", lang, 1);
573 r = setlocale(LC_ALL, "");
575 r = setlocale(LC_ALL, lang);
577 _DBG("*****appcore setlocale=%s\n", r);
583 static void __update_region(void)
588 region = vconf_get_str(VCONFKEY_REGIONFORMAT);
590 setenv("LC_CTYPE", region, 1);
591 setenv("LC_NUMERIC", region, 1);
592 setenv("LC_TIME", region, 1);
593 setenv("LC_COLLATE", region, 1);
594 setenv("LC_MONETARY", region, 1);
595 setenv("LC_PAPER", region, 1);
596 setenv("LC_NAME", region, 1);
597 setenv("LC_ADDRESS", region, 1);
598 setenv("LC_TELEPHONE", region, 1);
599 setenv("LC_MEASUREMENT", region, 1);
600 setenv("LC_IDENTIFICATION", region, 1);
601 r = setlocale(LC_ALL, "");
603 _DBG("*****appcore setlocale=%s\n", r);
609 static void __on_language_change(keynode_t *key, void *data)
613 val = vconf_keynode_get_str(key);
616 __invoke_callback((void *)val, APPCORE_BASE_EVENT_LANG_CHANGE);
619 static void __on_region_change(keynode_t *key, void *data)
624 name = vconf_keynode_get_name(key);
625 if (name && !strcmp(name, VCONFKEY_REGIONFORMAT))
626 val = vconf_keynode_get_str(key);
629 __invoke_callback((void *)val, APPCORE_BASE_EVENT_REGION_CHANGE);
632 static gboolean __flush_memory(gpointer data)
634 int suspend = APPCORE_BASE_SUSPENDED_STATE_WILL_ENTER_SUSPEND;
636 appcore_base_flush_memory();
639 if (!__context.allowed_bg && !__context.suspended_state) {
640 _DBG("[__SUSPEND__] flush case");
641 __invoke_callback((void *)&suspend, APPCORE_BASE_EVENT_SUSPENDED_STATE_CHANGE);
642 __context.suspended_state = true;
648 static void __add_suspend_timer(void)
650 __context.tid = g_timeout_add_seconds(5, __flush_memory, NULL);
653 static void __remove_suspend_timer(void)
655 if (__context.tid > 0) {
656 g_source_remove(__context.tid);
661 static void __on_receive_suspend_signal(GDBusConnection *connection,
662 const gchar *sender_name,
663 const gchar *object_path,
664 const gchar *interface_name,
665 const gchar *signal_name,
666 GVariant *parameters,
669 gint suspend = APPCORE_BASE_SUSPENDED_STATE_DID_EXIT_FROM_SUSPEND;
673 if (g_strcmp0(signal_name, RESOURCED_FREEZER_SIGNAL) == 0) {
674 g_variant_get(parameters, "(ii)", &status, &pid);
675 if (pid == getpid() && status == 0) {
676 if (!__context.allowed_bg && __context.suspended_state) {
677 __remove_suspend_timer();
678 __invoke_callback((void *)&suspend, APPCORE_BASE_EVENT_SUSPENDED_STATE_CHANGE);
679 __context.suspended_state = false;
680 __add_suspend_timer();
686 static int __init_suspend_dbus_handler(void)
690 if (__suspend_dbus_handler_initialized)
694 __bus = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &err);
696 _ERR("Failed to connect to the D-BUS daemon: %s",
703 __suspend_dbus_handler_initialized = g_dbus_connection_signal_subscribe(
706 RESOURCED_FREEZER_INTERFACE,
707 RESOURCED_FREEZER_SIGNAL,
708 RESOURCED_FREEZER_PATH,
710 G_DBUS_SIGNAL_FLAGS_NONE,
711 __on_receive_suspend_signal,
714 if (__suspend_dbus_handler_initialized == 0) {
715 _ERR("g_dbus_connection_signal_subscribe() is failed.");
719 _DBG("[__SUSPEND__] suspend signal initialized");
724 static void __fini_suspend_dbus_handler(void)
729 if (__suspend_dbus_handler_initialized) {
730 g_dbus_connection_signal_unsubscribe(__bus,
731 __suspend_dbus_handler_initialized);
732 __suspend_dbus_handler_initialized = 0;
735 g_object_unref(__bus);
739 static int __get_locale_resource_dir(char *locale_dir, int size)
741 const char *res_path;
743 res_path = aul_get_app_resource_path();
744 if (res_path == NULL) {
745 _ERR("Failed to get resource path");
749 snprintf(locale_dir, size, "%s" PATH_LOCALE, res_path);
750 if (access(locale_dir, R_OK) != 0)
751 _DBG("%s does not exist", locale_dir);
756 static int __get_app_name(const char *appid, char **name)
758 char *name_token = NULL;
763 /* com.vendor.name -> name */
764 name_token = strrchr(appid, '.');
765 if (name_token == NULL)
770 *name = strdup(name_token);
777 static int __set_i18n(const char *domain, const char *dir)
782 if (domain == NULL) {
790 __locale_dir = strdup(dir);
796 r = setlocale(LC_ALL, "");
797 /* if locale is not set properly, try again to set as language base */
799 lan = vconf_get_str(VCONFKEY_LANGSET);
801 r = setlocale(LC_ALL, lan);
802 _DBG("*****appcore setlocale=%s\n", r);
807 _ERR("appcore: setlocale() error");
809 r = bindtextdomain(domain, dir);
811 _ERR("appcore: bindtextdomain() error");
813 r = textdomain(domain);
815 _ERR("appcore: textdomain() error");
820 EXPORT_API int appcore_base_on_set_i18n(void)
823 char locale_dir[PATH_MAX];
824 char appid[PATH_MAX];
827 r = aul_app_get_appid_bypid(getpid(), appid, PATH_MAX);
831 r = __get_app_name(appid, &name);
835 r = __get_locale_resource_dir(locale_dir, sizeof(locale_dir));
841 r = __set_i18n(name, locale_dir);
852 EXPORT_API int appcore_base_set_i18n(const char *domain_name, const char *dir_name)
854 return __set_i18n(domain_name, dir_name);
857 EXPORT_API int appcore_base_init(appcore_base_ops ops, int argc, char **argv, void *data)
862 __context.argc = argc;
863 __context.argv = argv;
864 __context.data = data;
866 __context.suspended_state = false;
867 __context.allowed_bg = false;
869 if (__context.ops.set_i18n)
870 __context.ops.set_i18n(__context.data);
872 __init_suspend_dbus_handler();
874 if (!__context.dirty) {
875 __context.dirty = true;
877 for (i = APPCORE_BASE_EVENT_START + 1; i < APPCORE_BASE_EVENT_MAX; i++) {
878 if (__exist_callback(i)) {
879 if (__context.ops.set_event)
880 __context.ops.set_event(i, __context.data);
885 if (__context.ops.create && __context.ops.create(__context.data) < 0) {
886 aul_status_update(STATUS_DYING);
890 if (__context.ops.run)
891 __context.ops.run(__context.data);
896 EXPORT_API void appcore_base_fini(void)
900 aul_status_update(STATUS_DYING);
901 if (__context.ops.terminate)
902 __context.ops.terminate(__context.data);
904 for (i = APPCORE_BASE_EVENT_START + 1; i < APPCORE_BASE_EVENT_MAX; i++) {
905 if (__exist_callback(i)) {
906 if (__context.ops.unset_event)
907 __context.ops.unset_event(i, __context.data);
911 g_list_free_full(__events, free);
913 __fini_suspend_dbus_handler();
920 __context.dirty = false;
923 EXPORT_API int appcore_base_flush_memory(void)
929 EXPORT_API int appcore_base_on_receive(aul_type type, bundle *b)
932 const char **tep_path;
940 _DBG("[APP %d] AUL event: AUL_START", getpid());
941 tep_path = bundle_get_str_array(b, AUL_TEP_PATH, &len);
943 for (i = 0; i < len; i++) {
944 ret = aul_check_tep_mount(tep_path[i]);
946 _ERR("mount request not completed within 1 sec");
952 bg = bundle_get_val(b, AUL_K_ALLOWED_BG);
953 if (bg && strncmp(bg, "ALLOWED_BG", strlen("ALLOWED_BG")) == 0) {
954 _DBG("[__SUSPEND__] allowed background");
955 __context.allowed_bg = true;
956 __remove_suspend_timer();
959 if (__context.ops.control)
960 __context.ops.control(b, __context.data);
963 _DBG("[APP %d] AUL event: AUL_RESUME", getpid());
964 bg = bundle_get_val(b, AUL_K_ALLOWED_BG);
965 if (bg && strncmp(bg, "ALLOWED_BG", strlen("ALLOWED_BG")) == 0) {
966 _DBG("[__SUSPEND__] allowed background");
967 __context.allowed_bg = true;
968 __remove_suspend_timer();
972 _DBG("[APP %d] AUL event: AUL_TERMINATE", getpid());
973 aul_status_update(STATUS_DYING);
974 if (!__context.allowed_bg)
975 __remove_suspend_timer();
977 if (__context.ops.exit)
978 __context.ops.exit(__context.data);
980 case AUL_TERMINATE_BGAPP:
981 _DBG("[APP %d] AUL event: AUL_TERMINATE_BGAPP", getpid());
982 if (!__context.allowed_bg)
983 __remove_suspend_timer();
986 _DBG("[APP %d] AUL event: AUL_WAKE", getpid());
987 if (!__context.allowed_bg && __context.suspended_state) {
988 int suspend = APPCORE_BASE_SUSPENDED_STATE_DID_EXIT_FROM_SUSPEND;
989 __remove_suspend_timer();
990 __invoke_callback((void *)&suspend, APPCORE_BASE_EVENT_SUSPENDED_STATE_CHANGE);
991 __context.suspended_state = false;
995 _DBG("[APP %d] AUL event: AUL_SUSPEND", getpid());
996 if (!__context.allowed_bg && !__context.suspended_state) {
997 __remove_suspend_timer();
998 __flush_memory(NULL);
1001 case AUL_UPDATE_REQUESTED:
1002 _DBG("[APP %d] AUL event: AUL_UPDATE_REQUESTED", getpid());
1003 __invoke_callback((void *)&dummy, APPCORE_BASE_EVENT_UPDATE_REQUESTED);
1006 _DBG("[APP %d] AUL event: %d", getpid(), type);
1014 EXPORT_API int appcore_base_on_create(void)
1017 r = aul_launch_init(__context.ops.receive, NULL);
1019 _ERR("Aul init failed: %d", r);
1023 r = aul_launch_argv_handler(__context.argc, __context.argv);
1025 _ERR("Aul argv handler failed: %d", r);
1032 EXPORT_API int appcore_base_on_control(bundle *b)
1037 EXPORT_API int appcore_base_on_terminate()
1040 if (__context.ops.exit)
1041 __context.ops.exit(__context.data);
1046 EXPORT_API void appcore_base_on_set_event(enum appcore_base_event event)
1051 case APPCORE_BASE_EVENT_LOW_MEMORY:
1052 vconf_notify_key_changed(VCONFKEY_SYSMAN_LOW_MEMORY, __on_low_memory, NULL);
1054 case APPCORE_BASE_EVENT_LOW_BATTERY:
1055 vconf_notify_key_changed(VCONFKEY_SYSMAN_BATTERY_STATUS_LOW, __on_low_battery, NULL);
1057 case APPCORE_BASE_EVENT_LANG_CHANGE:
1058 vconf_notify_key_changed(VCONFKEY_LANGSET, __on_language_change, NULL);
1060 case APPCORE_BASE_EVENT_DEVICE_ORIENTATION_CHANGED:
1061 __register_rotation_changed_event();
1063 case APPCORE_BASE_EVENT_REGION_CHANGE:
1064 r = vconf_notify_key_changed(VCONFKEY_REGIONFORMAT, __on_region_change, NULL);
1068 vconf_notify_key_changed(VCONFKEY_REGIONFORMAT_TIME1224, __on_region_change, NULL);
1070 case APPCORE_BASE_EVENT_SUSPENDED_STATE_CHANGE:
1079 EXPORT_API void appcore_base_on_unset_event(enum appcore_base_event event)
1084 case APPCORE_BASE_EVENT_LOW_MEMORY:
1085 vconf_ignore_key_changed(VCONFKEY_SYSMAN_LOW_MEMORY, __on_low_memory);
1087 case APPCORE_BASE_EVENT_LOW_BATTERY:
1088 vconf_ignore_key_changed(VCONFKEY_SYSMAN_BATTERY_STATUS_LOW, __on_low_battery);
1090 case APPCORE_BASE_EVENT_LANG_CHANGE:
1091 vconf_ignore_key_changed(VCONFKEY_LANGSET, __on_language_change);
1093 case APPCORE_BASE_EVENT_DEVICE_ORIENTATION_CHANGED:
1094 __unregister_rotation_changed_event();
1096 case APPCORE_BASE_EVENT_REGION_CHANGE:
1097 r = vconf_ignore_key_changed(VCONFKEY_REGIONFORMAT, __on_region_change);
1100 vconf_ignore_key_changed(VCONFKEY_REGIONFORMAT_TIME1224, __on_region_change);
1102 case APPCORE_BASE_EVENT_SUSPENDED_STATE_CHANGE:
1109 EXPORT_API appcore_base_event_h appcore_base_add_event(enum appcore_base_event event,
1110 appcore_base_event_cb cb, void *data)
1112 appcore_base_event_node *node;
1114 if (__context.dirty && !__exist_callback(event)) {
1115 if (__context.ops.set_event)
1116 __context.ops.set_event(event, __context.data);
1119 node = malloc(sizeof(appcore_base_event_node));
1127 __events = g_list_append(__events, node);
1132 EXPORT_API int appcore_base_remove_event(appcore_base_event_h handle)
1134 appcore_base_event_node *node = handle;
1135 enum appcore_base_event event;
1138 __events = g_list_remove(__events, node);
1140 if (__context.dirty && !__exist_callback(event)) {
1141 if (__context.ops.unset_event)
1142 __context.ops.unset_event(event, __context.data);
1148 EXPORT_API int appcore_base_raise_event(void *event, enum appcore_base_event type)
1150 __invoke_callback(event, type);
1154 EXPORT_API int appcore_base_get_rotation_state(enum appcore_base_rm *curr)
1159 if (!__rotation.ref)
1162 *curr = __rotation.rm;
1166 EXPORT_API bool appcore_base_is_bg_allowed(void)
1168 return __context.allowed_bg;
1171 EXPORT_API bool appcore_base_is_suspended(void)
1173 return __context.suspended_state;
1176 EXPORT_API void appcore_base_toggle_suspended_state(void)
1178 __context.suspended_state ^= __context.suspended_state;
1181 static int __on_receive(aul_type type, bundle *b, void *data)
1183 return appcore_base_on_receive(type, b);
1186 static int __on_create(void *data)
1188 return appcore_base_on_create();
1191 static int __on_control(bundle *b, void *data)
1193 return appcore_base_on_control(b);
1196 static int __on_terminate(void *data)
1198 return appcore_base_on_terminate();
1201 static int __on_set_i18n(void *data)
1203 return appcore_base_on_set_i18n();
1206 static void __on_set_event(enum appcore_base_event event, void *data)
1208 return appcore_base_on_set_event(event);
1211 static void __on_unset_event(enum appcore_base_event event, void *data)
1213 return appcore_base_on_unset_event(event);
1216 EXPORT_API appcore_base_ops appcore_base_get_default_ops(void)
1218 appcore_base_ops ops;
1220 ops.create = __on_create;
1221 ops.control = __on_control;
1222 ops.terminate = __on_terminate;
1223 ops.receive = __on_receive;
1224 ops.set_i18n = __on_set_i18n;
1227 ops.set_event = __on_set_event;
1228 ops.unset_event = __on_unset_event;