Replace com.samsung with org.tizen
[platform/framework/web/data-provider-master.git] / src / setting.c
index f8d41a5..a21e549 100644 (file)
@@ -15,6 +15,7 @@
  */
 
 #include <stdio.h>
+#include <malloc.h>
 #include <unistd.h>
 #include <stdlib.h>
 #include <string.h>
 
 int errno;
 
+static struct {
+       int deactivated;
+} s_info = {
+       .deactivated = 0,
+};
+
 static void lcd_state_cb(keynode_t *node, void *user_data)
 {
        if (!node) {
@@ -78,16 +85,7 @@ static void power_off_cb(keynode_t *node, void *user_data)
        }
 
        if (val == VCONFKEY_SYSMAN_POWER_OFF_DIRECT || val == VCONFKEY_SYSMAN_POWER_OFF_RESTART) {
-               int fd;
-
-               fd = creat("/tmp/.stop.provider", 0644);
-               if (fd < 0 || close(fd) < 0) {
-                       ErrPrint("stop.provider [%s]\n", strerror(errno));
-               }
-
-               vconf_set_bool(VCONFKEY_MASTER_STARTED, 0);
-               //exit(0);
-               ecore_main_loop_quit();
+               DbgPrint("Power off requested: Ignored\n");
        } else {
                ErrPrint("Unknown power state: %d\n", val);
        }
@@ -145,70 +143,28 @@ static void lang_changed_cb(keynode_t *node, void *user_data)
        DbgFree(lang);
 }
 
-static void ail_info_cb(keynode_t *node, void *user_data)
+static void low_mem_cb(keynode_t *node, void *user_data)
 {
-       Eina_List *inst_list;
-       Eina_List *pkg_list;
-       struct inst_info *inst;
-       Eina_List *l;
-       Eina_List *n;
-       Eina_List *j;
-       struct pkg_info *info;
-       char *event;
-       char *appid;
-       char *pkgname;
-       int len;
-       int enabled;
-
-       event = vconf_get_str(VCONFKEY_AIL_INFO_STATE);
-       if (!event) {
-               return;
-       }
+       int val;
 
-       len = strlen("update:");
-       if (!strncasecmp(event, "update:", len)) {
-               goto out;
-       }
+       val = vconf_keynode_get_int(node);
 
-       appid = event + len;
-       DbgPrint("AppId: [%s]\n", appid);
-
-       enabled = package_is_enabled(appid);
-
-       DbgPrint("AppId: %s, %d\n", appid, enabled);
-       if (enabled != 0) {
-               /*
-                * \note
-                * reload?
-                */
-               goto out;
-       }
-
-       len = strlen(appid);
-
-       pkg_list = (Eina_List *)package_list();
-       EINA_LIST_FOREACH(pkg_list, l, info) {
-               inst_list = NULL;
-               pkgname = livebox_service_mainappid(package_name(info));
-               if (!pkgname) {
-                       continue;
+       if (val >= VCONFKEY_SYSMAN_LOW_MEMORY_SOFT_WARNING)     {
+               CRITICAL_LOG("Low memory: level %d\n", val);
+               if (s_info.deactivated == 0) {
+                       s_info.deactivated = 1;
+                       //slave_deactivate_all(0, 1);
+                       malloc_trim(0);
+                       ErrPrint("Fall into the low mem status\n");
                }
-
-               if (strcmp(appid, pkgname)) {
-                       DbgFree(pkgname);
-                       continue;
-               }
-               DbgPrint("Package disabled: %s (%s)\n", pkgname, appid);
-               DbgFree(pkgname);
-
-               inst_list = package_instance_list(info);
-               EINA_LIST_FOREACH_SAFE(inst_list, j, n, inst) {
-                       instance_destroy(inst);
+       } else {
+               CRITICAL_LOG("Normal memory: level %d\n", val);
+               if (s_info.deactivated == 1) {
+                       s_info.deactivated = 0;
+                       //slave_activate_all();
+                       ErrPrint("Recover from the low mem status\n");
                }
        }
-
-out:
-       DbgFree(event);
 }
 
 HAPI int setting_init(void)
@@ -235,9 +191,9 @@ HAPI int setting_init(void)
                ErrPrint("Failed to add vconf for region change: %d\n", ret);
        }
 
-       ret = vconf_notify_key_changed(VCONFKEY_AIL_INFO_STATE, ail_info_cb, NULL);
+       ret = vconf_notify_key_changed(VCONFKEY_SYSMAN_LOW_MEMORY, low_mem_cb, NULL);
        if (ret < 0) {
-               ErrPrint("Failed to add vconf for ail info state: %d\n", ret);
+               ErrPrint("Failed to add vconf for low mem monitor: %d\n", ret);
        }
 
        lang_changed_cb(NULL, NULL);
@@ -249,27 +205,27 @@ HAPI int setting_fini(void)
 {
        int ret;
 
-       ret = vconf_ignore_key_changed(VCONFKEY_REGIONFORMAT, region_changed_cb);
+       ret = vconf_ignore_key_changed(VCONFKEY_SYSMAN_LOW_MEMORY, low_mem_cb);
        if (ret < 0) {
                ErrPrint("Failed to ignore vconf key (%d)\n", ret);
        }
 
-       ret = vconf_ignore_key_changed(VCONFKEY_LANGSET, lang_changed_cb);
+       ret = vconf_ignore_key_changed(VCONFKEY_REGIONFORMAT, region_changed_cb);
        if (ret < 0) {
                ErrPrint("Failed to ignore vconf key (%d)\n", ret);
        }
 
-       ret = vconf_ignore_key_changed(VCONFKEY_PM_STATE, lcd_state_cb);
+       ret = vconf_ignore_key_changed(VCONFKEY_LANGSET, lang_changed_cb);
        if (ret < 0) {
                ErrPrint("Failed to ignore vconf key (%d)\n", ret);
        }
 
-       ret = vconf_ignore_key_changed(VCONFKEY_SYSMAN_POWER_OFF_STATUS, power_off_cb);
+       ret = vconf_ignore_key_changed(VCONFKEY_PM_STATE, lcd_state_cb);
        if (ret < 0) {
                ErrPrint("Failed to ignore vconf key (%d)\n", ret);
        }
 
-       ret = vconf_ignore_key_changed(VCONFKEY_AIL_INFO_STATE, ail_info_cb);
+       ret = vconf_ignore_key_changed(VCONFKEY_SYSMAN_POWER_OFF_STATUS, power_off_cb);
        if (ret < 0) {
                ErrPrint("Failed to ignore vconf key (%d)\n", ret);
        }