Support watchdog timer
[platform/core/appfw/app-core.git] / src / base / appcore_base.c
index 1754f07..4507e23 100644 (file)
 #include <sensor_internal.h>
 #include <ttrace.h>
 #include <system_info.h>
+
 #include "appcore_base.h"
 #include "appcore_base_private.h"
+#include "appcore_watchdog.h"
 
 #define PATH_LOCALE "locale"
-#define RESOURCED_FREEZER_PATH "/Org/Tizen/Resourced/Freezer"
+#define RESOURCED_FREEZER_PATH "/Org/Tizen/ResourceD/Freezer"
 #define RESOURCED_FREEZER_INTERFACE "org.tizen.resourced.freezer"
 #define RESOURCED_FREEZER_SIGNAL "FreezerState"
 #define SQLITE_FLUSH_MAX (1024 * 1024)
@@ -791,7 +793,9 @@ static gboolean __flush_memory(gpointer data)
 {
        int suspend = APPCORE_BASE_SUSPENDED_STATE_WILL_ENTER_SUSPEND;
 
-       appcore_base_flush_memory();
+       if (__context.ops.trim_memory)
+               __context.ops.trim_memory(__context.data);
+
        __context.tid = 0;
 
        if (!__context.allowed_bg && !__context.suspended_state) {
@@ -1079,6 +1083,8 @@ EXPORT_API int appcore_base_init(appcore_base_ops ops, int argc, char **argv, vo
        if (__context.ops.set_i18n)
                __context.ops.set_i18n(__context.data);
 
+       appcore_watchdog_enable();
+
        if (__context.ops.create) {
                traceBegin(TTRACE_TAG_APPLICATION_MANAGER, "APPCORE:CREATE");
                r = __context.ops.create(__context.data);
@@ -1100,6 +1106,7 @@ EXPORT_API void appcore_base_fini(void)
        int i;
 
        aul_status_update(STATUS_DYING);
+       appcore_watchdog_disable();
        if (__context.ops.terminate) {
                traceBegin(TTRACE_TAG_APPLICATION_MANAGER, "APPCORE:TERMINATE");
                __context.ops.terminate(__context.data);
@@ -1139,19 +1146,9 @@ EXPORT_API void appcore_base_fini(void)
 
 EXPORT_API int appcore_base_flush_memory(void)
 {
-       int (*sqlite3_free_heap_memory)(int);
-       void (*elm_free_all_cache)(void);
-
-       elm_free_all_cache = dlsym(RTLD_DEFAULT, "elm_cache_all_flush");
-       if (elm_free_all_cache)
-               elm_free_all_cache();
-
-       sqlite3_free_heap_memory = dlsym(RTLD_DEFAULT,
-                       "sqlite3_release_memory");
-       if (sqlite3_free_heap_memory)
-               sqlite3_free_heap_memory(SQLITE_FLUSH_MAX);
+       if (__context.ops.trim_memory)
+               __context.ops.trim_memory(__context.data);
 
-       malloc_trim(0);
        return 0;
 }
 
@@ -1303,6 +1300,20 @@ EXPORT_API void appcore_base_on_unset_event(enum appcore_base_event event)
        }
 }
 
+EXPORT_API int appcore_base_on_trim_memory(void)
+{
+       int (*sqlite3_free_heap_memory)(int);
+
+       sqlite3_free_heap_memory = dlsym(RTLD_DEFAULT,
+                       "sqlite3_release_memory");
+       if (sqlite3_free_heap_memory)
+               sqlite3_free_heap_memory(SQLITE_FLUSH_MAX);
+
+       malloc_trim(0);
+
+       return 0;
+}
+
 EXPORT_API appcore_base_event_h appcore_base_add_event(enum appcore_base_event event,
                appcore_base_event_cb cb, void *data)
 {
@@ -1421,12 +1432,17 @@ static int __on_set_i18n(void *data)
 
 static void __on_set_event(enum appcore_base_event event, void *data)
 {
-       return appcore_base_on_set_event(event);
+       appcore_base_on_set_event(event);
 }
 
 static void __on_unset_event(enum appcore_base_event event, void *data)
 {
-       return appcore_base_on_unset_event(event);
+       appcore_base_on_unset_event(event);
+}
+
+static void __on_trim_memory(void *data)
+{
+       appcore_base_on_trim_memory();
 }
 
 EXPORT_API appcore_base_ops appcore_base_get_default_ops(void)
@@ -1444,6 +1460,7 @@ EXPORT_API appcore_base_ops appcore_base_get_default_ops(void)
        ops.exit = NULL;
        ops.set_event = __on_set_event;
        ops.unset_event = __on_unset_event;
+       ops.trim_memory = __on_trim_memory;
 
        return ops;
 }