#include "module-intf.h"
#define MEMORY_STATUS_TMP_PATH "/tmp"
+#define MEMORY_STATUS_OPT_PATH "/opt"
#define MEMNOTI_TMP_CRITICAL_VALUE (20)
#define MEMORY_MEGABYTE_VALUE 1048576
#define MEMNOTI_CRITICAL_VALUE (0.1) /* 0.1% under */
#define MEMNOTI_FULL_VALUE (0.0) /* 0.0% under */
+#define SIGNAL_NEED_CLEANUP "NeedCleanup"
#define SIGNAL_LOWMEM_STATE "ChangeState"
#define SIGNAL_LOWMEM_FULL "Full"
#define MEMNOTI_TIMER_INTERVAL 5000 /* milliseconds */
#define ARRAY_SIZE(name) (sizeof(name)/sizeof(name[0]))
enum memnoti_level {
- MEMNOTI_LEVEL_CRITICAL = 0,
+ MEMNOTI_LEVEL_FULL = 0,
+ MEMNOTI_LEVEL_CRITICAL,
MEMNOTI_LEVEL_WARNING,
MEMNOTI_LEVEL_NORMAL,
- MEMNOTI_LEVEL_FULL,
};
enum memnoti_status {
MEMNOTI_ENABLE,
};
+enum memory_id {
+ MEMORY_INTERNAL = 0,
+ MEMORY_TMP,
+ MEMORY_OPT,
+};
+
struct storage_config_info {
+ enum memory_id mem_id;
enum memnoti_level current_noti_level;
double warning_level;
double critical_level;
static guint id_storage_poweroff;
static struct storage_config_info storage_internal_info = {
+ .mem_id = MEMORY_INTERNAL,
.current_noti_level = MEMNOTI_LEVEL_NORMAL,
.warning_level = MEMNOTI_WARNING_VALUE,
.critical_level = MEMNOTI_CRITICAL_VALUE,
};
static struct storage_config_info storage_tmp_info = {
+ .mem_id = MEMORY_TMP,
.current_noti_level = MEMNOTI_LEVEL_NORMAL,
.warning_level = MEMNOTI_TMP_CRITICAL_VALUE,
.critical_level = MEMNOTI_TMP_CRITICAL_VALUE,
.full_level = MEMNOTI_FULL_VALUE,
};
-static void memnoti_send_broadcast(char *signal, int status)
+static struct storage_config_info storage_opt_info = {
+ .mem_id = MEMORY_OPT,
+ .current_noti_level = MEMNOTI_LEVEL_NORMAL,
+ .warning_level = MEMNOTI_WARNING_VALUE,
+ .critical_level = MEMNOTI_CRITICAL_VALUE,
+ .full_level = MEMNOTI_FULL_VALUE,
+};
+
+static void memstatus_send_broadcast(enum memory_id no, char *signal, int status)
{
+ if (no == MEMORY_OPT)
+ return;
+
_I("signal %s status %d", signal, status);
dbus_handle_broadcast_dbus_signal_var(STORAGED_PATH_LOWMEM, STORAGED_INTERFACE_LOWMEM,
signal, g_variant_new("(i)", status));
}
+static void memcleanup_send_broadcast(struct storage_config_info *info, enum memnoti_level level, enum memnoti_level prev_level)
+{
+ const char *path;
+ char *value;
+
+ if (info->mem_id == MEMORY_INTERNAL)
+ path = tzplatform_getenv(TZ_SYS_HOME);
+ else if (info->mem_id == MEMORY_TMP)
+ path = MEMORY_STATUS_TMP_PATH;
+ else if (info->mem_id == MEMORY_OPT)
+ path = MEMORY_STATUS_OPT_PATH;
+ else
+ return;
+
+ if (prev_level <= level)
+ return;
+
+ if (level == MEMNOTI_LEVEL_WARNING)
+ value = "warning";
+ else if (level == MEMNOTI_LEVEL_CRITICAL)
+ value = "critical";
+ else if (level == MEMNOTI_LEVEL_FULL)
+ value = "full";
+ else
+ return;
+
+ _I("%s level: %s", path, value);
+ dbus_handle_broadcast_dbus_signal_var(STORAGED_PATH_LOWMEM, STORAGED_INTERFACE_LOWMEM,
+ SIGNAL_NEED_CLEANUP, g_variant_new("(ss)", path, value));
+
+}
+
static int launch_memory_popup(int num, ...)
{
int ret;
{
double level = (avail/total)*100;
int status = MEMNOTI_DISABLE;
+ enum memnoti_level prev_noti_level;
+ prev_noti_level = info->current_noti_level;
if (level <= info->full_level) {
if (info->current_noti_level == MEMNOTI_LEVEL_FULL)
return;
info->current_noti_level = MEMNOTI_LEVEL_FULL;
status = MEMNOTI_ENABLE;
- memnoti_send_broadcast(SIGNAL_LOWMEM_FULL, status);
- _I("current level %4.4lf w:%4.4lf c:%4.4lf f:%4.4lf",
- level, info->warning_level, info->critical_level, info->full_level);
+ memstatus_send_broadcast(info->mem_id, SIGNAL_LOWMEM_FULL, status);
+
+ memcleanup_send_broadcast(info, info->current_noti_level, prev_noti_level);
+
+ _I("%d current level %4.4lf w:%4.4lf c:%4.4lf f:%4.4lf",
+ info->mem_id, level, info->warning_level, info->critical_level, info->full_level);
return;
}
if (info->current_noti_level == MEMNOTI_LEVEL_CRITICAL)
return;
if (info->current_noti_level == MEMNOTI_LEVEL_FULL)
- memnoti_send_broadcast(SIGNAL_LOWMEM_FULL, status);
+ memstatus_send_broadcast(info->mem_id, SIGNAL_LOWMEM_FULL, status);
info->current_noti_level = MEMNOTI_LEVEL_CRITICAL;
status = MEMNOTI_ENABLE;
- memnoti_send_broadcast(SIGNAL_LOWMEM_STATE, status);
- _I("current level %4.4lf w:%4.4lf c:%4.4lf f:%4.4lf",
- level, info->warning_level, info->critical_level, info->full_level);
+ memstatus_send_broadcast(info->mem_id, SIGNAL_LOWMEM_STATE, status);
+
+ memcleanup_send_broadcast(info, info->current_noti_level, prev_noti_level);
+
+ _I("%d current level %4.4lf w:%4.4lf c:%4.4lf f:%4.4lf",
+ info->mem_id, level, info->warning_level, info->critical_level, info->full_level);
return;
}
if (info->current_noti_level == MEMNOTI_LEVEL_FULL)
- memnoti_send_broadcast(SIGNAL_LOWMEM_FULL, status);
+ memstatus_send_broadcast(info->mem_id, SIGNAL_LOWMEM_FULL, status);
if (info->current_noti_level == MEMNOTI_LEVEL_CRITICAL)
- memnoti_send_broadcast(SIGNAL_LOWMEM_STATE, status);
- if (level <= info->warning_level)
+ memstatus_send_broadcast(info->mem_id, SIGNAL_LOWMEM_STATE, status);
+
+ if (level <= info->warning_level) {
info->current_noti_level = MEMNOTI_LEVEL_WARNING;
- else
+ _I("%d current level %4.4lf w:%4.4lf c:%4.4lf f:%4.4lf",
+ info->mem_id, level, info->warning_level, info->critical_level, info->full_level);
+
+ memcleanup_send_broadcast(info, info->current_noti_level, prev_noti_level);
+ } else
info->current_noti_level = MEMNOTI_LEVEL_NORMAL;
+
}
static int storage_get_memory_size(const char *path, struct statvfs *s)
dTotal = (double)s.f_frsize * s.f_blocks;
dAvail = (double)s.f_bsize * s.f_bavail;
storage_status_broadcast(&storage_tmp_info, dTotal, dAvail);
+ /* check opt */
+ storage_get_memory_size(MEMORY_STATUS_OPT_PATH, &s);
+ dTotal = (double)s.f_frsize * s.f_blocks;
+ dAvail = (double)s.f_bsize * s.f_bavail;
+ storage_status_broadcast(&storage_opt_info, dTotal, dAvail);
if (memnoti_timer) {
g_source_remove(memnoti_timer);
{
init_storage_config_info(tzplatform_getenv(TZ_SYS_HOME), &storage_internal_info);
init_storage_config_info(MEMORY_STATUS_TMP_PATH, &storage_tmp_info);
+ init_storage_config_info(MEMORY_STATUS_OPT_PATH, &storage_opt_info);
memnoti_timer = g_timeout_add(MEMNOTI_TIMER_INTERVAL,
check_storage_status, NULL);
if (memnoti_timer == 0)