hal: Branch 'master'

Danny Kukawka dkukawka at kemper.freedesktop.org
Tue Jan 29 14:23:12 PST 2008


 hald/linux/device.c |   42 ++++++++++++++++++++++++++++++++++++++----
 1 file changed, 38 insertions(+), 4 deletions(-)

New commits:
commit 7430beeb6c6fd6c8e51c24df20fd53c526aed6e8
Author: Danny Kukawka <danny.kukawka at web.de>
Date:   Tue Jan 29 23:21:04 2008 +0100

    fixed power_supply primary batteries to update values
    
    Fixed power_supply primary batteries to update values, since there are
    no events about changes via ACPI or from udev/kernel. Added function
    to poll for changes similar to the ACPI battery poll. Limited the poll
    to power_supply primary batteries for now. If this is also needed for
    ups/ubs/mains batteries, we can add them later. The poll interval
    is 30 seconds.
    
    TODO: differ in refresh_battery_fast between ACPI and other batteries
          since there are several files which are currently not provided
          by the sysfs interface for ACPI batteries in the power_supply
          subsystem.

diff --git a/hald/linux/device.c b/hald/linux/device.c
index f82585f..23ab347 100644
--- a/hald/linux/device.c
+++ b/hald/linux/device.c
@@ -72,6 +72,9 @@
 gboolean _have_sysfs_lid_button = FALSE;
 gboolean _have_sysfs_power_button = FALSE;
 gboolean _have_sysfs_sleep_button = FALSE;
+gboolean _have_sysfs_power_supply = FALSE; 
+
+#define POWER_SUPPLY_BATTERY_POLL_INTERVAL 30000
 
 /* we must use this kernel-compatible implementation */
 #define BITS_PER_LONG (sizeof(long) * 8)
@@ -3237,10 +3240,36 @@ power_supply_refresh (HalDevice *d)
 	return TRUE;
 }
 
-/* don't bother looking for /proc/acpi batteries if they're in
- * sysfs.
- */
-gboolean _have_sysfs_power_supply = FALSE;
+
+static gboolean 
+power_supply_battery_poll (gpointer data) {
+
+	GSList *i;
+	GSList *battery_devices;
+	HalDevice *d;
+
+	/* for now do it only for primary batteries and extend if neede for the other types */
+	battery_devices = hal_device_store_match_multiple_key_value_string (hald_get_gdl (),
+                                                                    	    "battery.type",
+ 	                                                                    "primary");
+
+	if (battery_devices) {
+		for (i = battery_devices; i != NULL; i = g_slist_next (i)) {
+			const char *subsys;
+
+			d = HAL_DEVICE (i->data);
+			subsys = hal_device_property_get_string (d, "linux.subsystem");
+			if (subsys && (strcmp(subsys, "power_supply") == 0)) {
+				hal_util_grep_discard_existing_data();
+				device_property_atomic_update_begin ();
+				refresh_battery_fast(d);
+				device_property_atomic_update_end ();
+			}
+		}		
+	}
+	g_slist_free (battery_devices);
+	return TRUE;
+}
 
 static HalDevice *
 power_supply_add (const gchar *sysfs_path, const gchar *device_file, HalDevice *physdev,
@@ -3284,6 +3313,11 @@ power_supply_add (const gchar *sysfs_path, const gchar *device_file, HalDevice *
 			hal_device_property_set_string (d, "battery.type", battery_type);
 		refresh_battery_slow (d);
 		hal_device_add_capability (d, "battery");
+
+		/* setup timer for things that we need to poll */
+		g_timeout_add ( POWER_SUPPLY_BATTERY_POLL_INTERVAL,
+				power_supply_battery_poll,
+				NULL);
 	}
 
 	if (is_ac_adapter == TRUE) {


More information about the hal-commit mailing list