summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKate Hsuan <hpa@redhat.com>2024-02-26 16:42:01 +0800
committerKate Hsuan <hpa@redhat.com>2024-02-26 16:42:01 +0800
commit138c241981d94baff538b43506f56c36a8bab72f (patch)
treec08a422d2a4021b33bc93a678660c8bf2b88cac7
parent85eed3e20344a3f29e9d02bfc8cfd308070ba38e (diff)
add an unknown event filter and don't delete UpHistory when device_is is found.wip/kate/history-filter
-rw-r--r--src/up-device.c33
1 files changed, 28 insertions, 5 deletions
diff --git a/src/up-device.c b/src/up-device.c
index 9ee01db..fff9e3e 100644
--- a/src/up-device.c
+++ b/src/up-device.c
@@ -173,16 +173,30 @@ ensure_history (UpDevice *device)
{
UpDevicePrivate *priv = up_device_get_instance_private (device);
g_autofree char *id = NULL;
-
+ g_warning ("ensure a history for device %s",up_device_get_id (device));
if (priv->history)
return;
-
+ g_warning ("New a history for device %s",up_device_get_id (device));
priv->history = up_history_new ();
id = up_device_get_id (device);
if (id)
up_history_set_id (priv->history, id);
}
+static gboolean
+up_device_history_filter (UpDevice *device, UpHistory *history)
+{
+ UpDevicePrivate *priv = up_device_get_instance_private (device);
+ UpExportedDevice *skeleton = UP_EXPORTED_DEVICE (device);
+
+ if (up_exported_device_get_state (skeleton) == UP_DEVICE_STATE_UNKNOWN) {
+ g_debug ("device %s has unknown state, not saving history",
+ up_exported_device_get_native_path (skeleton));
+ return FALSE;
+ }
+ return TRUE;
+}
+
static void
update_history (UpDevice *device)
{
@@ -191,6 +205,9 @@ update_history (UpDevice *device)
ensure_history (device);
+ if (!up_device_history_filter (device, priv->history))
+ return;
+
/* save new history */
up_history_set_state (priv->history, up_exported_device_get_state (skeleton));
up_history_set_charge_data (priv->history, up_exported_device_get_percentage (skeleton));
@@ -208,18 +225,22 @@ up_device_notify (GObject *object, GParamSpec *pspec)
/* Not finished setting up the object? */
if (priv->daemon == NULL)
return;
-
+ g_warning ("REceived notify %s -> %s",pspec->name, up_device_get_id(device));
G_OBJECT_CLASS (up_device_parent_class)->notify (object, pspec);
if (g_strcmp0 (pspec->name, "type") == 0 ||
g_strcmp0 (pspec->name, "is-present") == 0) {
update_icon_name (device);
/* Clearing the history object will force lazily loading. */
- g_clear_object (&priv->history);
+ if (!up_history_is_device_id (priv->history, up_device_get_id(device)))
+ g_clear_object (&priv->history);
+ g_warning ("REceived notify 'is-present");
} else if (g_strcmp0 (pspec->name, "vendor") == 0 ||
g_strcmp0 (pspec->name, "model") == 0 ||
g_strcmp0 (pspec->name, "serial") == 0) {
- g_clear_object (&priv->history);
+ if (!up_history_is_device_id (priv->history, up_device_get_id(device)))
+ g_clear_object (&priv->history);
+ g_warning ("REceived notify 'vendor' or 'model' or 'serial'");
} else if (g_strcmp0 (pspec->name, "power-supply") == 0 ||
g_strcmp0 (pspec->name, "time-to-empty") == 0) {
update_warning_level (device);
@@ -734,6 +755,8 @@ up_device_finalize (GObject *object)
{
UpDevicePrivate *priv = up_device_get_instance_private (UP_DEVICE (object));
+ g_warning ("finalize device %s", up_device_get_id (UP_DEVICE (object)));
+
g_clear_object (&priv->native);
g_clear_object (&priv->daemon);
g_clear_object (&priv->history);