Fix bug about setting event handler 82/116282/4
authorJunghoon Park <jh9216.park@samsung.com>
Thu, 23 Feb 2017 13:09:38 +0000 (22:09 +0900)
committerJunghoon Park <jh9216.park@samsung.com>
Fri, 24 Feb 2017 02:28:37 +0000 (11:28 +0900)
Change-Id: I5fd868f5bf41ec3b1e1e380686d4bad7e122092b
Signed-off-by: Junghoon Park <jh9216.park@samsung.com>
src/base/appcore_base.c

index 93e2f56..7a15b33 100644 (file)
@@ -51,6 +51,7 @@ typedef struct _appcore_base_context {
        unsigned int tid;
        bool suspended_state;
        bool allowed_bg;
+       bool dirty;
 } appcore_base_context;
 
 typedef struct _appcore_base_event_node {
@@ -683,6 +684,8 @@ EXPORT_API int appcore_base_on_set_i18n(void)
 
 EXPORT_API int appcore_base_init(appcore_base_ops ops, int argc, char **argv, void *data)
 {
+       int i;
+
        __context.ops = ops;
        __context.argc = argc;
        __context.argv = argv;
@@ -696,6 +699,17 @@ EXPORT_API int appcore_base_init(appcore_base_ops ops, int argc, char **argv, vo
 
        __init_suspend_dbus_handler();
 
+       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);
+                       }
+               }
+       }
+
        if (__context.ops.create && __context.ops.create(__context.data) < 0) {
                aul_status_update(STATUS_DYING);
                return 0;
@@ -711,6 +725,10 @@ EXPORT_API void appcore_base_fini(void)
 {
        int i;
 
+       aul_status_update(STATUS_DYING);
+       if (__context.ops.terminate)
+               __context.ops.terminate(__context.data);
+
        for (i = APPCORE_BASE_EVENT_START + 1; i < APPCORE_BASE_EVENT_MAX; i++) {
                if (__exist_callback(i)) {
                        if (__context.ops.unset_event)
@@ -722,14 +740,12 @@ EXPORT_API void appcore_base_fini(void)
        __events = NULL;
        __fini_suspend_dbus_handler();
 
-       aul_status_update(STATUS_DYING);
-       if (__context.ops.terminate)
-               __context.ops.terminate(__context.data);
-
        if (__locale_dir) {
                free(__locale_dir);
                __locale_dir = NULL;
        }
+
+       __context.dirty = false;
 }
 
 EXPORT_API int appcore_base_flush_memory(void)
@@ -917,7 +933,7 @@ EXPORT_API appcore_base_event_h appcore_base_add_event(enum appcore_base_event e
 {
        appcore_base_event_node *node;
 
-       if (!__exist_callback(event)) {
+       if (__context.dirty && !__exist_callback(event)) {
                if (__context.ops.set_event)
                        __context.ops.set_event(event, __context.data);
        }
@@ -943,7 +959,7 @@ EXPORT_API int appcore_base_remove_event(appcore_base_event_h handle)
        event = node->type;
        __events = g_list_remove(__events, node);
        free(node);
-       if (!__exist_callback(event)) {
+       if (__context.dirty && !__exist_callback(event)) {
                if (__context.ops.unset_event)
                        __context.ops.unset_event(event, __context.data);
        }