diff options
author | Bastien Nocera <hadess@hadess.net> | 2013-10-18 15:59:59 +0200 |
---|---|---|
committer | Bastien Nocera <hadess@hadess.net> | 2013-10-18 16:16:54 +0200 |
commit | a1a91e7e5d3338bc649119d8c462f9c32135d971 (patch) | |
tree | e76150f2f1df969d1b897981132d1cf8f90f0a9e /src | |
parent | 2e4ed0c64445885d6842b64078d922036d9b7a43 (diff) | |
download | upower-a1a91e7e5d3338bc649119d8c462f9c32135d971.tar.gz |
linux: Add a simpler, quicker path for devices
When refreshing the state of device batteries, no need
to get data that won't be there anyway, such as voltage, temperature,
or consumption rate.
This avoids warnings about voltage being unknown for devices, and
cuts down on the properties churn.
Diffstat (limited to 'src')
-rw-r--r-- | src/linux/up-device-supply.c | 67 |
1 files changed, 66 insertions, 1 deletions
diff --git a/src/linux/up-device-supply.c b/src/linux/up-device-supply.c index c4553cd..0b8a0eb 100644 --- a/src/linux/up-device-supply.c +++ b/src/linux/up-device-supply.c @@ -807,6 +807,68 @@ out: } /** + * up_device_supply_refresh_device: + * + * Return %TRUE on success, %FALSE if we failed to refresh or no data + **/ +static gboolean +up_device_supply_refresh_device (UpDeviceSupply *supply) +{ + gboolean ret = TRUE; + UpDeviceState state; + UpDevice *device = UP_DEVICE (supply); + const gchar *native_path; + GUdevDevice *native; + gdouble percentage = 0.0f; + + native = G_UDEV_DEVICE (up_device_get_native (device)); + native_path = g_udev_device_get_sysfs_path (native); + + /* initial values */ + if (!supply->priv->has_coldplug_values) { + gchar *model_name; + + /* get values which may be blank */ + model_name = up_device_supply_get_string (native_path, "model_name"); + + /* some vendors fill this with binary garbage */ + up_device_supply_make_safe_string (model_name); + + g_object_set (device, + "is-present", TRUE, + "model", model_name, + "is-rechargeable", TRUE, + "has-history", TRUE, + "has-statistics", TRUE, + "power-supply", supply->priv->is_power_supply, /* always FALSE */ + NULL); + + /* we only coldplug once, as these values will never change */ + supply->priv->has_coldplug_values = TRUE; + + g_free (model_name); + } + + /* get a precise percentage */ + percentage = sysfs_get_double (native_path, "capacity"); + + state = up_device_supply_get_state (native_path); + + /* reset unknown counter */ + if (state != UP_DEVICE_STATE_UNKNOWN) { + g_debug ("resetting unknown timeout after %i retries", supply->priv->unknown_retries); + supply->priv->unknown_retries = 0; + } + + g_object_set (device, + "percentage", percentage, + "state", state, + NULL); + + return ret; +} + +/** * up_device_supply_poll_battery: **/ static gboolean @@ -1017,7 +1079,10 @@ up_device_supply_refresh (UpDevice *device) ret = up_device_supply_refresh_line_power (supply); break; default: - ret = up_device_supply_refresh_battery (supply); + if (supply->priv->is_power_supply) + ret = up_device_supply_refresh_battery (supply); + else + ret = up_device_supply_refresh_device (supply); /* Seems that we don't get change uevents from the * kernel on some BIOS types */ |