hal: Branch 'master'

Danny Kukawka dkukawka at kemper.freedesktop.org
Thu Aug 17 03:54:51 PDT 2006


 hald/linux2/apm.c |   23 +++++++++++++++++++----
 1 files changed, 19 insertions(+), 4 deletions(-)

New commits:
diff-tree 27050b659a63c9ffe79f997a2d562a56821e49c3 (from 189b452798f9441dd59d90d806b417f1a7725006)
Author: Danny Kukawka <danny.kukawka at web.de>
Date:   Thu Aug 17 12:53:29 2006 +0200

    reduce useless changes on APM battery.remaining_time
    
    Changed update property battery.remaining_time on APM to avoid change the
    value every 2 seconds. APM calculate with each poll a new value for
    remaining battery time, which could result in high dbus load if a application
    listen for the event and check do something over the bus. On the other side
    the remaining time from the APM interface is not trustworthy on the most
    machines if you poll to often, increase the poll intervall (and emit a new
    value to HAL) should smooth the time curve and reduce back and forth jumping
    values.
    
    Now the value is updated ever 30 seconds, this should preduce the needless
    events.

diff --git a/hald/linux2/apm.c b/hald/linux2/apm.c
index 4d74d86..fc417ae 100644
--- a/hald/linux2/apm.c
+++ b/hald/linux2/apm.c
@@ -40,6 +40,7 @@ enum {
 	APM_TYPE_AC_ADAPTER
 };
 
+int interval_poll_round = 0;
 
 typedef struct APMDevHandler_s
 {
@@ -201,11 +202,25 @@ battery_refresh (HalDevice *d, APMDevHan
 			remaining_time = i.battery_time * 60;
 		}
 
-		/* set the time on discharge, and remove property on charging because unknown on APM */
-		if (remaining_time > 0)
-			hal_device_property_set_int (d, "battery.remaining_time", remaining_time);
-		else
+		/* set the time to discharge, or remove key for charging */
+		if (remaining_time > 0) {
+			/* switched from charging to discharging, set key */
+			if (!is_charging && is_discharging && !hal_device_has_property(d,"battery.remaining_time")) {
+				hal_device_property_set_int (d, "battery.remaining_time", remaining_time);
+				interval_poll_round = 0;
+			}
+			/* after 30 seconds (15*APM_POLL_INTERVAL) set key */
+			else if (interval_poll_round == 15) {
+				hal_device_property_set_int (d, "battery.remaining_time", remaining_time);
+				interval_poll_round = 0;
+			}
+			/* else: only increment counter and set no key to avoid needless events/changes
+			   because APM produce with each read a new value for remaining time */
+			else
+				interval_poll_round++;
+		} else {
 			hal_device_property_remove (d, "battery.remaining_time");
+		}
 
 		/* set the correct charge states */
 		hal_device_property_set_bool (d, "battery.rechargeable.is_charging", is_charging);



More information about the hal-commit mailing list