summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKate Hsuan <hpa@redhat.com>2024-02-26 16:40:21 +0800
committerKate Hsuan <hpa@redhat.com>2024-02-26 16:40:21 +0800
commit85eed3e20344a3f29e9d02bfc8cfd308070ba38e (patch)
tree9b2c6abf48f59b0e8eaabe7c7f8ab5791d205aba
parent26a1b7db3853917ee82e747a0128a97d22c0cd61 (diff)
add up_history_is_device_id() and skip unknown events
-rw-r--r--src/up-history.c31
-rw-r--r--src/up-history.h1
2 files changed, 32 insertions, 0 deletions
diff --git a/src/up-history.c b/src/up-history.c
index bed3b0e..f1f3605 100644
--- a/src/up-history.c
+++ b/src/up-history.c
@@ -424,6 +424,7 @@ static gboolean
up_history_array_to_file (UpHistory *history, GPtrArray *list, const gchar *filename)
{
guint i;
+ guint status;
UpHistoryItem *item;
gchar *part;
GString *string;
@@ -447,6 +448,19 @@ up_history_array_to_file (UpHistory *history, GPtrArray *list, const gchar *file
cull_count++;
continue;
}
+ g_warning ("history item len %d item no. %d item status %d", list->len, i, up_history_item_get_state (item));
+ g_warning ("histioy item time diff %d mac age %d", time_now.tv_sec-time_item,history->priv->max_data_age);
+ g_warning ("histioy last percentage %f", history->priv->percentage_last);
+
+ /* only save valid entries */
+ status = up_history_item_get_state (item);
+ if (status >= UP_DEVICE_STATE_LAST) {
+ ret = FALSE;
+ break;
+ } else if (status == UP_DEVICE_STATE_UNKNOWN) {
+ continue;
+ }
+
part = up_history_item_to_string (item);
if (part == NULL) {
ret = FALSE;
@@ -756,6 +770,7 @@ up_history_set_charge_data (UpHistory *history, gdouble percentage)
return FALSE;
if (history->priv->state == UP_DEVICE_STATE_UNKNOWN)
return FALSE;
+ g_warning ("Incoming percentage %lf last percentage %lf", percentage, history->priv->percentage_last);
if (history->priv->percentage_last == percentage)
return FALSE;
@@ -769,6 +784,7 @@ up_history_set_charge_data (UpHistory *history, gdouble percentage)
/* save last value */
history->priv->percentage_last = percentage;
+ g_warning ("After writing Incoming percentage %lf last percentage %lf", percentage, history->priv->percentage_last);
return TRUE;
}
@@ -870,6 +886,21 @@ up_history_set_time_empty_data (UpHistory *history, gint64 time_s)
return TRUE;
}
+gboolean
+up_history_is_device_id(UpHistory *history, const gchar *id)
+{
+ if (history!= NULL)
+ g_warning ("History id %s id %s", history->priv->id, id);
+ g_return_val_if_fail (UP_IS_HISTORY (history), FALSE);
+ g_return_val_if_fail (id != NULL, FALSE);
+ g_warning ("history id %s id %s result %d", history->priv->id, id, g_strcmp0 (history->priv->id, id));
+
+ if (!g_strcmp0 (history->priv->id, id))
+ return TRUE;
+
+ return FALSE;
+}
+
/**
* up_history_class_init:
* @klass: The UpHistoryClass
diff --git a/src/up-history.h b/src/up-history.h
index 87af5e3..c927708 100644
--- a/src/up-history.h
+++ b/src/up-history.h
@@ -59,6 +59,7 @@ typedef enum {
} UpHistoryType;
+gboolean up_history_is_device_id (UpHistory *history, const gchar *id);
GType up_history_get_type (void);
UpHistory *up_history_new (void);