hal/hald/linux2 acpi.c,1.16,1.17

David Zeuthen david at freedesktop.org
Thu Mar 10 11:44:14 PST 2005


Update of /cvs/hal/hal/hald/linux2
In directory gabe:/tmp/cvs-serv11128/hald/linux2

Modified Files:
	acpi.c 
Log Message:
2005-03-10  David Zeuthen  <davidz at redhat.com>

	Bah, so it turns out that crappy BIOS'es and what-have-you gets really
	upset of hald, every five seconds, accessing the state file three
	times and the info file one time (in /proc/acpi/battery/BAT%d)

	https://www.redhat.com/archives/fedora-devel-list/2005-March/msg00704.html

	So, off to read the battstat applet source - fix this up so we
	only access a single file every 30 seconds; just like battstat applet.

	I really hate hardware.

	* hald/linux2/acpi.c (ACPI_POLL_INTERVAL): Only poll every 30 seconds
	(battery_refresh_poll): New function
	(battery_refresh): Call battery_refresh_poll
	(acpi_poll): Call battery_refresh_poll instead of acpi_rescan_device

	* hald/util.c (hal_util_grep_file): Fix this so the last read buffer
	is cached for reuse



Index: acpi.c
===================================================================
RCS file: /cvs/hal/hal/hald/linux2/acpi.c,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -d -r1.16 -r1.17
--- acpi.c	7 Mar 2005 19:08:41 -0000	1.16
+++ acpi.c	10 Mar 2005 19:44:11 -0000	1.17
@@ -44,27 +44,7 @@
 	ACPI_TYPE_BUTTON
 };
 
-#define ACPI_POLL_INTERVAL 5000
-
-static gboolean
-acpi_poll (gpointer data)
-{
-	GSList *i;
-	GSList *devices;
-
-	devices = hal_device_store_match_multiple_key_value_string (hald_get_gdl (),
-								    "battery.type",
-								    "primary");
-	for (i = devices; i != NULL; i = g_slist_next (i)) {
-		HalDevice *d;
-		
-		d = HAL_DEVICE (i->data);
-		if (hal_device_has_property (d, "linux.acpi_type"))
-			acpi_rescan_device (d);
-	}
-
-	return TRUE;
-}
+#define ACPI_POLL_INTERVAL 30000
 
 
 typedef struct ACPIDevHandler_s
@@ -76,6 +56,23 @@
 	gboolean (*refresh) (HalDevice *d, struct ACPIDevHandler_s *handler);
 } ACPIDevHandler;
 
+static void
+battery_refresh_poll (HalDevice *d)
+{
+	const char *path;
+
+	path = hal_device_property_get_string (d, "linux.acpi_path");
+	if (path == NULL)
+		return;
+	
+	hal_util_set_bool_elem_from_file (d, "battery.rechargeable.is_charging", path, 
+					  "state", "charging state", 0, "charging", TRUE);
+	hal_util_set_bool_elem_from_file (d, "battery.rechargeable.is_discharging", path, 
+					  "state", "charging state", 0, "discharging", TRUE);
+	hal_util_set_int_elem_from_file (d, "battery.charge_level.current", path, 
+					 "state", "remaining capacity", 0, 10, TRUE);
+}
+
 static gboolean
 battery_refresh (HalDevice *d, ACPIDevHandler *handler)
 {
@@ -111,13 +108,6 @@
 		device_property_atomic_update_end ();		
 	} else {
 		device_property_atomic_update_begin ();
-		hal_device_property_set_bool (d, "battery.is_rechargeable", TRUE);
-		hal_util_set_bool_elem_from_file (d, "battery.rechargeable.is_charging", path, 
-						  "state", "charging state", 0, "charging", TRUE);
-		hal_util_set_bool_elem_from_file (d, "battery.rechargeable.is_discharging", path, 
-						  "state", "charging state", 0, "discharging", TRUE);
-		hal_util_set_int_elem_from_file (d, "battery.charge_level.current", path, 
-						 "state", "remaining capacity", 0, 10, TRUE);
 
 		/* So, it's pretty expensive to read from
 		 * /proc/acpi/battery/BAT%d/[info|state] so don't read
@@ -140,6 +130,10 @@
 							 "info", "design capacity", 0, 10, TRUE);
 		}
 
+		hal_device_property_set_bool (d, "battery.is_rechargeable", TRUE);
+
+		battery_refresh_poll (d);
+
 		device_property_atomic_update_end ();
 	}
 
@@ -273,6 +267,29 @@
 	;
 }
 
+
+static gboolean
+acpi_poll (gpointer data)
+{
+	GSList *i;
+	GSList *devices;
+
+	devices = hal_device_store_match_multiple_key_value_string (hald_get_gdl (),
+								    "battery.type",
+								    "primary");
+	for (i = devices; i != NULL; i = g_slist_next (i)) {
+		HalDevice *d;
+		
+		d = HAL_DEVICE (i->data);
+		if (hal_device_has_property (d, "linux.acpi_type")) {
+			hal_util_grep_discard_existing_data ();
+			battery_refresh_poll (d);
+		}
+	}
+
+	return TRUE;
+}
+
 /** Scan the data structures exported by the kernel and add hotplug
  *  events for adding ACPI objects.
  *




More information about the hal-commit mailing list