hal/hald/linux2 acpi.c, 1.15, 1.16 classdev.c, 1.21, 1.22 pmu.c, 1.7, 1.8

David Zeuthen david at freedesktop.org
Mon Mar 7 11:08:43 PST 2005


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

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

	* doc/TODO: Updated this to reflect reality

	* hald/linux2/pmu.c (battery_refresh): Pass reuse=FALSE
	(ac_adapter_refresh): Pass reuse=FALSE

	* hald/linux2/classdev.c (sound_add): pass reuse=FALSE

	* hald/linux2/acpi.c: Poll every five secs instead of every two secs
	as this actually is a very expensive operation - someone needs to
	optimize hald/util.c:hal_util_grep_file before we can change this -
	see the TODO in that function
	(battery_refresh): Use the hal_util_grep_discard_existing_data() since
	we are passing reuse=TRUE. Minimize amount of reads.
	(fan_refresh): Don't set processor.number here (!)

	* hald/util.c (hal_util_grep_discard_existing_data): New function to
	purge "reused" data
	(hal_util_grep_file): Take the reuse parameter
	(hal_util_grep_string_elem_from_file): Take and pass reuse param
	(hal_util_grep_int_elem_from_file): Take and pass reuse param
	(hal_util_set_string_elem_from_file): Take and pass reuse param
	(hal_util_set_int_elem_from_file): Take and pass reuse param
	(hal_util_set_bool_elem_from_file): Take and pass reuse param

	* hald/util.h: Fixup prototypes for functions above and add prototype
	for hal_util_grep_discard_existing_data



Index: acpi.c
===================================================================
RCS file: /cvs/hal/hal/hald/linux2/acpi.c,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -d -r1.15 -r1.16
--- acpi.c	4 Mar 2005 21:44:49 -0000	1.15
+++ acpi.c	7 Mar 2005 19:08:41 -0000	1.16
@@ -44,7 +44,7 @@
 	ACPI_TYPE_BUTTON
 };
 
-#define ACPI_POLL_INTERVAL 2000
+#define ACPI_POLL_INTERVAL 5000
 
 static gboolean
 acpi_poll (gpointer data)
@@ -90,7 +90,10 @@
 	hal_device_property_set_string (d, "info.category", "battery");
 	hal_device_add_capability (d, "battery");
 
-	hal_util_set_bool_elem_from_file (d, "battery.present", path, "info", "present", 0, "yes");
+	/* Since we're using reuse==TRUE make sure we get fresh data for first read */
+	hal_util_grep_discard_existing_data ();
+
+	hal_util_set_bool_elem_from_file (d, "battery.present", path, "info", "present", 0, "yes", TRUE);
 	if (!hal_device_property_get_bool (d, "battery.present")) {
 		device_property_atomic_update_begin ();
 		hal_device_property_remove (d, "battery.is_rechargeable");
@@ -110,25 +113,33 @@
 		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");
-
+						  "state", "charging state", 0, "charging", TRUE);
 		hal_util_set_bool_elem_from_file (d, "battery.rechargeable.is_discharging", path, 
-						  "state", "charging state", 0, "discharging");
-		
-		hal_util_set_string_elem_from_file (d, "battery.vendor", path, "info", "OEM info", 0);
-		hal_util_set_string_elem_from_file (d, "battery.model", path, "info", "model number", 0);
-		hal_util_set_string_elem_from_file (d, "battery.serial", path, "info", "serial number", 0);
-		hal_util_set_string_elem_from_file (d, "battery.technology", path, "info", "battery type", 0);
-		hal_util_set_string_elem_from_file (d, "battery.vendor", path, "info", "OEM info", 0);
-		hal_util_set_string_elem_from_file (d, "battery.charge_level.unit", path, "info", "design capacity", 1);
-		
+						  "state", "charging state", 0, "discharging", TRUE);
 		hal_util_set_int_elem_from_file (d, "battery.charge_level.current", path, 
-						 "state", "remaining capacity", 0, 10);
+						 "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
+		 * static data that don't change
+		 */
+		if (!hal_device_has_property (d, "battery.vendor")) {
+			hal_util_set_string_elem_from_file (d, "battery.vendor", path, "info", "OEM info", 0, TRUE);
+			hal_util_set_string_elem_from_file (d, "battery.model", path, "info", "model number", 0, TRUE);
+			hal_util_set_string_elem_from_file (d, "battery.serial", path, "info", 
+							    "serial number", 0, TRUE);
+			hal_util_set_string_elem_from_file (d, "battery.technology", path, "info", 
+							    "battery type", 0, TRUE);
+			hal_util_set_string_elem_from_file (d, "battery.vendor", path, "info", "OEM info", 0, TRUE);
+			hal_util_set_string_elem_from_file (d, "battery.charge_level.unit", path, "info", 
+							    "design capacity", 1, TRUE);
+			
+			hal_util_set_int_elem_from_file (d, "battery.charge_level.last_full", path, 
+							 "info", "last full capacity", 0, 10, TRUE);
+			hal_util_set_int_elem_from_file (d, "battery.charge_level.design", path, 
+							 "info", "design capacity", 0, 10, TRUE);
+		}
 
-		hal_util_set_int_elem_from_file (d, "battery.charge_level.last_full", path, 
-						 "info", "last full capacity", 0, 10);
-		hal_util_set_int_elem_from_file (d, "battery.charge_level.design", path, 
-						 "info", "design capacity", 0, 10);
 		device_property_atomic_update_end ();
 	}
 
@@ -148,9 +159,9 @@
 	hal_device_property_set_string (d, "info.category", "processor");
 	hal_device_add_capability (d, "processor");
 	hal_util_set_int_elem_from_file (d, "processor.number", path, 
-					 "info", "processor id", 0, 10);
+					 "info", "processor id", 0, 10, FALSE);
 	hal_util_set_bool_elem_from_file (d, "processor.can_throttle", path, 
-					  "info", "throttling control", 0, "yes");
+					  "info", "throttling control", 0, "yes", FALSE);
 	return TRUE;
 }
 
@@ -166,10 +177,8 @@
 	hal_device_property_set_string (d, "info.product", "Fan");
 	hal_device_property_set_string (d, "info.category", "fan");
 	hal_device_add_capability (d, "fan");
-	hal_util_set_int_elem_from_file (d, "processor.number", path, 
-					 "info", "processor id", 0, 10);
 	hal_util_set_bool_elem_from_file (d, "fan.enabled", path, 
-					  "state", "status", 0, "on");
+					  "state", "status", 0, "on", FALSE);
 	return TRUE;
 }
 
@@ -185,7 +194,7 @@
 	hal_device_property_set_string (d, "info.product", "AC Adapter");
 	hal_device_property_set_string (d, "info.category", "ac_adapter");
 	hal_device_add_capability (d, "ac_adapter");
-	hal_util_set_bool_elem_from_file (d, "ac_adapter.present", path, "state", "state", 0, "on-line");
+	hal_util_set_bool_elem_from_file (d, "ac_adapter.present", path, "state", "state", 0, "on-line", FALSE);
 
 	return TRUE;
 }
@@ -215,7 +224,7 @@
 
 	hal_device_property_set_string (d, "info.category", "button");
 	hal_device_add_capability (d, "button");
-	if (!hal_util_set_bool_elem_from_file (d, "button.state.value", path, "state", "state", 0, "closed")) {
+	if (!hal_util_set_bool_elem_from_file (d, "button.state.value", path, "state", "state", 0, "closed", FALSE)) {
 		hal_device_property_set_bool (d, "button.has_state", FALSE);
 	} else {
 		hal_device_property_set_bool (d, "button.has_state", TRUE);
@@ -294,7 +303,7 @@
 	hal_device_property_set_bool (computer, "power_management.is_enabled", TRUE);
 	hal_device_property_set_string (computer, "power_management.type", "acpi");
 	hal_util_set_string_elem_from_file (computer, "power_management.acpi.linux.version", 
-					    "/proc/acpi", "info", "version", 0);
+					    "/proc/acpi", "info", "version", 0, FALSE);
 
 	/* collect batteries */
 	snprintf (path, sizeof (path), "%s/acpi/battery", get_hal_proc_path ());

Index: classdev.c
===================================================================
RCS file: /cvs/hal/hal/hald/linux2/classdev.c,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -d -r1.21 -r1.22
--- classdev.c	3 Mar 2005 19:46:42 -0000	1.21
+++ classdev.c	7 Mar 2005 19:08:41 -0000	1.22
@@ -487,7 +487,7 @@
 
 		snprintf (aprocdir, sizeof (aprocdir), "%s/asound/card%d/pcm%d%c", 
 			  get_hal_proc_path (), cardnum, devicenum, type);
-		device_id = hal_util_grep_file (aprocdir, "info", "name: ");
+		device_id = hal_util_grep_file (aprocdir, "info", "name: ", FALSE);
 		if (device_id != NULL) {
 			hal_device_property_set_string (d, "alsa.device_id", device_id);
 		}

Index: pmu.c
===================================================================
RCS file: /cvs/hal/hal/hald/linux2/pmu.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- pmu.c	2 Mar 2005 21:51:55 -0000	1.7
+++ pmu.c	7 Mar 2005 19:08:41 -0000	1.8
@@ -75,7 +75,7 @@
 	hal_device_property_set_string (d, "info.category", "battery");
 	hal_device_add_capability (d, "battery");
 
-	flags = hal_util_grep_int_elem_from_file (path, "", "flags", 0, 16);
+	flags = hal_util_grep_int_elem_from_file (path, "", "flags", 0, 16, FALSE);
 
 	hal_device_property_set_bool (d, "battery.present", flags & PMU_BATT_PRESENT);
 
@@ -92,12 +92,15 @@
 			char buf[HAL_PATH_MAX];
 			snprintf (buf, sizeof (buf), "%s/pmu/info", get_hal_proc_path ());
 			hal_util_set_bool_elem_from_file (d, "battery.rechargeable.is_discharging", buf, "", 
-							  "AC Power", 0, "0");
+							  "AC Power", 0, "0", FALSE);
 		}
 
-		hal_util_set_int_elem_from_file (d, "battery.charge_level.current", path, "", "charge", 0, 10);
-		hal_util_set_int_elem_from_file (d, "battery.charge_level.last_full", path, "", "max_charge", 0, 10);
-		hal_util_set_int_elem_from_file (d, "battery.charge_level.design", path, "", "max_charge", 0, 10);
+		hal_util_set_int_elem_from_file (d, "battery.charge_level.current", 
+						 path, "", "charge", 0, 10, FALSE);
+		hal_util_set_int_elem_from_file (d, "battery.charge_level.last_full", 
+						 path, "", "max_charge", 0, 10, FALSE);
+		hal_util_set_int_elem_from_file (d, "battery.charge_level.design", 
+						 path, "", "max_charge", 0, 10, FALSE);
 
 		device_property_atomic_update_end ();
 	} else {
@@ -128,7 +131,7 @@
 	hal_device_property_set_string (d, "info.category", "ac_adapter");
 	hal_device_add_capability (d, "ac_adapter");
 
-	hal_util_set_bool_elem_from_file (d, "ac_adapter.present", path, "", "AC Power", 0, "1");	
+	hal_util_set_bool_elem_from_file (d, "ac_adapter.present", path, "", "AC Power", 0, "1", FALSE);
 
 	return TRUE;
 }




More information about the hal-commit mailing list