mirror of
https://gitlab.freedesktop.org/upower/upower.git
synced 2025-12-20 04:20:04 +01:00
add an unknown event filter and don't delete UpHistory when device_is is found.
This commit is contained in:
parent
85eed3e203
commit
138c241981
1 changed files with 28 additions and 5 deletions
|
|
@ -173,16 +173,30 @@ ensure_history (UpDevice *device)
|
||||||
{
|
{
|
||||||
UpDevicePrivate *priv = up_device_get_instance_private (device);
|
UpDevicePrivate *priv = up_device_get_instance_private (device);
|
||||||
g_autofree char *id = NULL;
|
g_autofree char *id = NULL;
|
||||||
|
g_warning ("ensure a history for device %s",up_device_get_id (device));
|
||||||
if (priv->history)
|
if (priv->history)
|
||||||
return;
|
return;
|
||||||
|
g_warning ("New a history for device %s",up_device_get_id (device));
|
||||||
priv->history = up_history_new ();
|
priv->history = up_history_new ();
|
||||||
id = up_device_get_id (device);
|
id = up_device_get_id (device);
|
||||||
if (id)
|
if (id)
|
||||||
up_history_set_id (priv->history, 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
|
static void
|
||||||
update_history (UpDevice *device)
|
update_history (UpDevice *device)
|
||||||
{
|
{
|
||||||
|
|
@ -191,6 +205,9 @@ update_history (UpDevice *device)
|
||||||
|
|
||||||
ensure_history (device);
|
ensure_history (device);
|
||||||
|
|
||||||
|
if (!up_device_history_filter (device, priv->history))
|
||||||
|
return;
|
||||||
|
|
||||||
/* save new history */
|
/* save new history */
|
||||||
up_history_set_state (priv->history, up_exported_device_get_state (skeleton));
|
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));
|
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? */
|
/* Not finished setting up the object? */
|
||||||
if (priv->daemon == NULL)
|
if (priv->daemon == NULL)
|
||||||
return;
|
return;
|
||||||
|
g_warning ("REceived notify %s -> %s",pspec->name, up_device_get_id(device));
|
||||||
G_OBJECT_CLASS (up_device_parent_class)->notify (object, pspec);
|
G_OBJECT_CLASS (up_device_parent_class)->notify (object, pspec);
|
||||||
|
|
||||||
if (g_strcmp0 (pspec->name, "type") == 0 ||
|
if (g_strcmp0 (pspec->name, "type") == 0 ||
|
||||||
g_strcmp0 (pspec->name, "is-present") == 0) {
|
g_strcmp0 (pspec->name, "is-present") == 0) {
|
||||||
update_icon_name (device);
|
update_icon_name (device);
|
||||||
/* Clearing the history object will force lazily loading. */
|
/* 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 ||
|
} else if (g_strcmp0 (pspec->name, "vendor") == 0 ||
|
||||||
g_strcmp0 (pspec->name, "model") == 0 ||
|
g_strcmp0 (pspec->name, "model") == 0 ||
|
||||||
g_strcmp0 (pspec->name, "serial") == 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 ||
|
} else if (g_strcmp0 (pspec->name, "power-supply") == 0 ||
|
||||||
g_strcmp0 (pspec->name, "time-to-empty") == 0) {
|
g_strcmp0 (pspec->name, "time-to-empty") == 0) {
|
||||||
update_warning_level (device);
|
update_warning_level (device);
|
||||||
|
|
@ -734,6 +755,8 @@ up_device_finalize (GObject *object)
|
||||||
{
|
{
|
||||||
UpDevicePrivate *priv = up_device_get_instance_private (UP_DEVICE (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->native);
|
||||||
g_clear_object (&priv->daemon);
|
g_clear_object (&priv->daemon);
|
||||||
g_clear_object (&priv->history);
|
g_clear_object (&priv->history);
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue