Initialize default multiwindow base class
[platform/core/appfw/app-core.git] / src / base / appcore_base.c
index ddc952b..5c495f5 100644 (file)
@@ -36,6 +36,7 @@
 #include <aul.h>
 #include <bundle_internal.h>
 #include <sensor_internal.h>
+#include <ttrace.h>
 #include "appcore_base.h"
 #include "appcore_base_private.h"
 
@@ -416,6 +417,8 @@ static GList *__append_langs(const char *lang, GList *list, GHashTable *table)
        if (lang == NULL)
                return list;
 
+       list = g_list_append(list, strdup(lang));
+
        extract_lang = __get_string_before(lang, ".");
        if (extract_lang == NULL)
                return list;
@@ -825,8 +828,10 @@ EXPORT_API int appcore_base_on_set_i18n(void)
        char *name = NULL;
 
        r = aul_app_get_appid_bypid(getpid(), appid, PATH_MAX);
-       if (r < 0)
+       if (r < 0) {
+               _ERR("Failed to get application ID - pid(%d)", getpid());
                return -1;
+       }
 
        r = __get_app_name(appid, &name);
        if (r < 0)
@@ -857,6 +862,7 @@ EXPORT_API int appcore_base_set_i18n(const char *domain_name, const char *dir_na
 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;
@@ -866,6 +872,9 @@ EXPORT_API int appcore_base_init(appcore_base_ops ops, int argc, char **argv, vo
        __context.suspended_state = false;
        __context.allowed_bg = false;
 
+       if (__context.ops.init)
+               __context.ops.init(argc, argv, data);
+
        if (__context.ops.set_i18n)
                __context.ops.set_i18n(__context.data);
 
@@ -882,9 +891,14 @@ EXPORT_API int appcore_base_init(appcore_base_ops ops, int argc, char **argv, vo
                }
        }
 
-       if (__context.ops.create && __context.ops.create(__context.data) < 0) {
-               aul_status_update(STATUS_DYING);
-               return 0;
+       if (__context.ops.create) {
+               traceBegin(TTRACE_TAG_APPLICATION_MANAGER, "APPCORE:CREATE");
+               r = __context.ops.create(__context.data);
+               traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
+               if (r < 0) {
+                       aul_status_update(STATUS_DYING);
+                       return 0;
+               }
        }
 
        if (__context.ops.run)
@@ -898,8 +912,11 @@ EXPORT_API void appcore_base_fini(void)
        int i;
 
        aul_status_update(STATUS_DYING);
-       if (__context.ops.terminate)
+       if (__context.ops.terminate) {
+               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)) {
@@ -918,6 +935,9 @@ EXPORT_API void appcore_base_fini(void)
        }
 
        __context.dirty = false;
+
+       if (__context.ops.finish)
+               __context.ops.finish();
 }
 
 EXPORT_API int appcore_base_flush_memory(void)
@@ -956,8 +976,11 @@ EXPORT_API int appcore_base_on_receive(aul_type type, bundle *b)
                        __remove_suspend_timer();
                }
 
-               if (__context.ops.control)
-                      __context.ops.control(b, __context.data);
+               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());
@@ -1037,8 +1060,6 @@ EXPORT_API int appcore_base_on_control(bundle *b)
 EXPORT_API int appcore_base_on_terminate()
 {
        aul_finalize();
-       if (__context.ops.exit)
-               __context.ops.exit(__context.data);
 
        return 0;
 }
@@ -1134,6 +1155,9 @@ 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);
        free(node);
@@ -1178,6 +1202,12 @@ EXPORT_API void appcore_base_toggle_suspended_state(void)
        __context.suspended_state ^= __context.suspended_state;
 }
 
+EXPORT_API void appcore_base_exit(void)
+{
+       if (__context.ops.exit)
+               __context.ops.exit(__context.data);
+}
+
 static int __on_receive(aul_type type, bundle *b, void *data)
 {
        return appcore_base_on_receive(type, b);
@@ -1222,6 +1252,8 @@ EXPORT_API appcore_base_ops appcore_base_get_default_ops(void)
        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;