summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDanny Kukawka <danny.kukawka@web.de>2006-08-17 12:53:29 +0200
committerDanny Kukawka <danny.kukawka@web.de>2006-08-17 12:53:29 +0200
commit27050b659a63c9ffe79f997a2d562a56821e49c3 (patch)
treefebaa82e10d71467e16a1ba9562bf9fc53538db2
parent189b452798f9441dd59d90d806b417f1a7725006 (diff)
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.
-rw-r--r--hald/linux2/apm.c23
1 files changed, 19 insertions, 4 deletions
diff --git a/hald/linux2/apm.c b/hald/linux2/apm.c
index 4d74d86a..fc417ae3 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, APMDevHandler *handler)
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);