tizen build
[framework/appfw/app-core.git] / src / appcore.c
index 41a1060..fa316b8 100755 (executable)
 #include <dlfcn.h>
 #include <vconf.h>
 #include <aul.h>
-#include <rua.h>
 #include "appcore-internal.h"
 
 #define SQLITE_FLUSH_MAX               (1024*1024)
 
 #define PKGNAME_MAX 256
 #define PATH_APP_ROOT "/opt/apps"
+#define PATH_RO_APP_ROOT "/usr/apps"
 #define PATH_RES "/res"
 #define PATH_LOCALE "/locale"
 
@@ -81,6 +81,13 @@ struct evt_ops {
        int (*vcb_post) (void *, void *);
 };
 
+struct open_s {
+       int (*callback) (void *);
+       void *cbdata;
+};
+
+static struct open_s open;
+
 static int __app_terminate(void *data);
 static int __app_resume(void *data);
 static int __app_reset(void *data, bundle *k);
@@ -92,6 +99,8 @@ static int __sys_langchg_pre(void *data, void *evt);
 static int __sys_langchg(void *data, void *evt);
 static int __sys_regionchg_pre(void *data, void *evt);
 static int __sys_regionchg(void *data, void *evt);
+extern void aul_finalize();
+
 
 static struct evt_ops evtops[] = {
        {
@@ -139,67 +148,11 @@ static int __get_dir_name(char *dirname)
        r = snprintf(dirname, PATH_MAX, PATH_APP_ROOT "/%s" PATH_RES PATH_LOCALE,pkg_name);
        if (r < 0)
                return -1;
-
-       return 0;
-}
-
-
-static int __get_cmd(char *buf)
-{
-       FILE *fp;
-       int r;
-       char fname[FILENAME_MAX];
-
-       r = snprintf(fname, sizeof(fname), "/proc/%d/cmdline", getpid());
+       if (access(dirname, R_OK) == 0) return 0;
+       r = snprintf(dirname, PATH_MAX, PATH_RO_APP_ROOT "/%s" PATH_RES PATH_LOCALE,pkg_name);
        if (r < 0)
                return -1;
 
-       fp = fopen(fname, "r");
-       if (fp == NULL)
-               return -1;
-
-       r = 0;
-       if (fgets(buf, PATH_MAX, fp) == NULL)
-               r = -1;
-
-       fclose(fp);
-
-       return r;
-}
-
-static int __update_rua(bundle *b)
-{
-       int r;
-       char buf[PATH_MAX];
-       struct rua_rec rec;
-
-       r = __get_cmd(buf);
-       if (r == -1)
-               return -1;
-
-       r = rua_init();
-       if (r == -1) {
-               _DBG("[APP %d] rua init error", _pid);
-               return -1;
-       }
-
-       memset(&rec, 0, sizeof(rec));
-
-       rec.pkg_name = getenv("PKG_NAME");
-       rec.app_path = buf;
-
-       if (b)
-               bundle_encode(b, (bundle_raw **)&rec.arg, NULL);
-
-       r = rua_add_history(&rec);
-       if (r == -1)
-               _DBG("[APP %d] rua add history error", _pid);
-
-       rua_fini();
-
-       if (rec.arg)
-               free(rec.arg);
-
        return 0;
 }
 
@@ -235,7 +188,6 @@ static int __app_reset(void *data, bundle * k)
        g_idle_add(__prt_ltime, ac);
 
        ac->ops->cb_app(AE_RESET, ac->ops->data, k);
-       __update_rua(k);
 
        return 0;
 }
@@ -243,15 +195,9 @@ static int __app_reset(void *data, bundle * k)
 static int __app_resume(void *data)
 {
        x_raise_win(getpid());
-       __update_rua(NULL);
        return 0;
 }
 
-static int __def_lowbatt(struct appcore *ac)
-{
-       return __app_terminate(ac);
-}
-
 static int __sys_do_default(struct appcore *ac, enum sys_event event)
 {
        int r;
@@ -419,6 +365,8 @@ static int __del_vconf(void)
 
 static int __aul_handler(aul_type type, bundle *b, void *data)
 {
+       int ret;
+
        switch (type) {
        case AUL_START:
                _DBG("[APP %d]     AUL event: AUL_START", _pid);
@@ -426,7 +374,13 @@ static int __aul_handler(aul_type type, bundle *b, void *data)
                break;
        case AUL_RESUME:
                _DBG("[APP %d]     AUL event: AUL_RESUME", _pid);
-               __app_resume(data);
+               if(open.callback) {
+                       ret = open.callback(open.cbdata);
+                       if (ret == 0)
+                               __app_resume(data);
+               } else {
+                       __app_resume(data);
+               }
                break;
        case AUL_TERMINATE:
                _DBG("[APP %d]     AUL event: AUL_TERMINATE", _pid);
@@ -447,6 +401,15 @@ static void __clear(struct appcore *ac)
        memset(ac, 0, sizeof(struct appcore));
 }
 
+EXPORT_API int appcore_set_open_cb(int (*cb) (void *),
+                                      void *data)
+{
+       open.callback = cb;
+       open.cbdata = data;
+
+       return 0;
+}
+
 EXPORT_API int appcore_set_event_callback(enum appcore_event event,
                                          int (*cb) (void *), void *data)
 {
@@ -533,6 +496,7 @@ EXPORT_API void appcore_exit(void)
                __del_vconf();
                __clear(&core);
        }
+       aul_finalize();
 }
 
 EXPORT_API int appcore_flush_memory(void)