[PATCH v3] Linux: Only one warning if no valid voltage found
Timothée Ravier
siosm99 at gmail.com
Fri Aug 30 14:06:24 PDT 2013
Avoid filling the logs with repeated warning saying that no correct
voltage value was found for a power device. Improves the situation with
bugs https://bugzilla.redhat.com/show_bug.cgi?id=847874 and
https://bugzilla.redhat.com/show_bug.cgi?id=863524
Signed-off-by: Timothée Ravier <tim at siosm.fr>
---
v3: Add a debug message for this specific case as the warning is not always
displayed anymore.
v2: Removed the GHashTable and used a custom field in UpDeviceSupplyPrivate
instead as advised by Martin Pitt.
src/linux/up-device-supply.c | 16 +++++++++++++---
1 file changed, 13 insertions(+), 3 deletions(-)
diff --git a/src/linux/up-device-supply.c b/src/linux/up-device-supply.c
index a93d16a..010d017 100644
--- a/src/linux/up-device-supply.c
+++ b/src/linux/up-device-supply.c
@@ -60,6 +60,7 @@ struct UpDeviceSupplyPrivate
guint unknown_retries;
gboolean enable_poll;
gboolean is_power_supply;
+ gboolean shown_invalid_voltage_warning;
};
G_DEFINE_TYPE (UpDeviceSupply, up_device_supply, UP_TYPE_DEVICE)
@@ -372,7 +373,7 @@ out:
* up_device_supply_get_design_voltage:
**/
static gdouble
-up_device_supply_get_design_voltage (const gchar *native_path)
+up_device_supply_get_design_voltage (UpDeviceSupply *device, const gchar *native_path)
{
gdouble voltage;
gchar *device_type = NULL;
@@ -413,8 +414,15 @@ up_device_supply_get_design_voltage (const gchar *native_path)
goto out;
}
+ /* no valid value found; display a warning the first time for each
+ * device */
+ if (device->priv->shown_invalid_voltage_warning == FALSE) {
+ device->priv->shown_invalid_voltage_warning = TRUE;
+ g_warning ("no valid voltage value found for device: %s", native_path);
+ g_warning ("using 10V as an approximation for device: %s", native_path);
+ }
/* completely guess, to avoid getting zero values */
- g_warning ("no voltage values for device %s, using 10V as approximation", native_path);
+ g_debug ("no valid voltage found, assuming 10V");
voltage = 10.0f;
out:
g_free (device_type);
@@ -527,7 +535,7 @@ up_device_supply_refresh_battery (UpDeviceSupply *supply)
energy = sysfs_get_double (native_path, "energy_avg") / 1000000.0;
/* used to convert A to W later */
- voltage_design = up_device_supply_get_design_voltage (native_path);
+ voltage_design = up_device_supply_get_design_voltage (supply, native_path);
/* initial values */
if (!supply->priv->has_coldplug_values ||
@@ -1018,6 +1026,8 @@ up_device_supply_init (UpDeviceSupply *supply)
supply->priv->energy_old = g_new (gdouble, UP_DEVICE_SUPPLY_ENERGY_OLD_LENGTH);
supply->priv->energy_old_timespec = g_new (GTimeVal, UP_DEVICE_SUPPLY_ENERGY_OLD_LENGTH);
supply->priv->energy_old_first = 0;
+
+ supply->priv->shown_invalid_voltage_warning = FALSE;
}
/**
--
1.8.4
More information about the devkit-devel
mailing list