hal: Branch 'master' - 2 commits

Richard Hughes hughsient at kemper.freedesktop.org
Tue Jul 3 09:38:49 PDT 2007


 hald/linux/apm.c |    4 ++--
 hald/linux/pmu.c |   35 ++++-------------------------------
 2 files changed, 6 insertions(+), 33 deletions(-)

New commits:
diff-tree 03f1aa8e441ae189d589827b412dabbb3cd78523 (from 79dd4756c2e4ba011da3663230ebe37a7d8b67ea)
Author: Richard Hughes <richard at hughsie.com>
Date:   Tue Jul 3 17:34:36 2007 +0100

    use device_pm_* in pmu.c
    
    Use the abstract device_pm_* functions in pmu.c to reduce code duplication.

diff --git a/hald/linux/pmu.c b/hald/linux/pmu.c
index 44c0c7c..b7944c1 100644
--- a/hald/linux/pmu.c
+++ b/hald/linux/pmu.c
@@ -31,6 +31,7 @@
 #include <unistd.h>
 
 #include "../device_info.h"
+#include "../device_pm.h"
 #include "../hald_dbus.h"
 #include "../logger.h"
 #include "../util.h"
@@ -78,8 +79,6 @@ battery_refresh (HalDevice *d, PMUDevHan
 	const char *path;
 	int flags;
 	int last_full;
-	int remaining_time;
-	int remaining_percentage;
 
 	path = hal_device_property_get_string (d, "linux.pmu_path");
 	if (path == NULL)
@@ -130,39 +129,13 @@ battery_refresh (HalDevice *d, PMUDevHan
 		last_full = hal_device_property_get_int (d, "battery.charge_level.last_full");
 
 		/* TODO: could read some pmu file? */
-		remaining_time = util_compute_time_remaining (
-					hal_device_get_udi (d),
-					hal_device_property_get_int (d, "battery.charge_level.rate"),
-					current,
-					last_full,
-					hal_device_property_get_bool (d, "battery.rechargeable.is_discharging"),
-					hal_device_property_get_bool (d, "battery.rechargeable.is_charging"),
-					hal_device_property_get_bool (d, "battery.remaining_time.calculate_per_time"));
-		remaining_percentage = util_compute_percentage_charge (hal_device_get_udi (d), current, last_full);
-		/*
-		 * Only set keys if no error (signified with negative return value)
-		 * Scrict checking is needed to ensure that the values presented by HAL
-		 * are 100% acurate.
-		 */
-		if (remaining_time > 0)
-			hal_device_property_set_int (d, "battery.remaining_time", remaining_time);
-		else
-			hal_device_property_remove (d, "battery.remaining_time");
-		if (remaining_percentage > 0)
-			hal_device_property_set_int (d, "battery.charge_level.percentage", remaining_percentage);
-		else
-			hal_device_property_remove (d, "battery.charge_level.percentage");
+		device_pm_calculate_time (d);
+		device_pm_calculate_percentage (d);
 
 		device_property_atomic_update_end ();
 	} else {
 		device_property_atomic_update_begin ();
-		hal_device_property_remove (d, "battery.is_rechargeable");
-		hal_device_property_remove (d, "battery.rechargeable.is_charging");
-		hal_device_property_remove (d, "battery.rechargeable.is_discharging");
-		/*hal_device_property_remove (d, "battery.charge_level.unit");*/
-		hal_device_property_remove (d, "battery.charge_level.current");
-		hal_device_property_remove (d, "battery.charge_level.last_full");
-		hal_device_property_remove (d, "battery.charge_level.design");
+		device_pm_remove_optional_props (d);
 		device_property_atomic_update_end ();		
 	}
 
diff-tree 79dd4756c2e4ba011da3663230ebe37a7d8b67ea (from d7144f2aa1b59f9a0acfa0daada69e2a4ffd54d8)
Author: Richard Hughes <richard at hughsie.com>
Date:   Tue Jul 3 17:33:06 2007 +0100

    dont use util_compute_percentage_charge in apm
    
    Don't use util_compute_percentage_charge in apm, it's a waste of time.

diff --git a/hald/linux/apm.c b/hald/linux/apm.c
index 7e07219..8568c6a 100644
--- a/hald/linux/apm.c
+++ b/hald/linux/apm.c
@@ -229,10 +229,10 @@ battery_refresh (HalDevice *d, APMDevHan
 		hal_device_property_set_bool (d, "battery.rechargeable.is_discharging", is_discharging);
 
 		/* set the percentage charge, easy. */
-		remaining_percentage = util_compute_percentage_charge (hal_device_get_udi (d), i.battery_percentage, 100);
+		remaining_percentage = i.battery_percentage;
 	
 		/* Only set keys if no error (signified with negative return value) */
-		if (remaining_percentage > 0)
+		if (remaining_percentage >= 0 && remaining_percentage <= 100)
 			hal_device_property_set_int (d, "battery.charge_level.percentage", remaining_percentage);
 		else
 			hal_device_property_remove (d, "battery.charge_level.percentage");


More information about the hal-commit mailing list