[PATCH] Adds reporting the CPU flags for each processor interrogated.

Darryl L. Pierce dpierce at redhat.com
Mon Feb 2 10:10:55 PST 2009


Adds a new method, get_processor_attribute. It takes as input the cpu
number and attribute name to report and returns either the attribute
value or a null value.

Two reporting methods, get_processor_model_name and get_processor_flags,
call this new method to report their specific values.
---
 hald/linux/acpi.c |   65 +++++++++++++++++++++++++++++++++++++++--------------
 1 files changed, 48 insertions(+), 17 deletions(-)

diff --git a/hald/linux/acpi.c b/hald/linux/acpi.c
index 6f76af6..de5826f 100644
--- a/hald/linux/acpi.c
+++ b/hald/linux/acpi.c
@@ -479,30 +479,27 @@ battery_refresh (HalDevice *d, ACPIDevHandler *handler, gboolean force_full_refr
 	return TRUE;
 }
 
-/** 
- *  get_processor_model_name:
- *  @proc_num:	Number of processor
- *  
- *  Returns:    Name of the processor model
+/**
+ * get_processor_attribute:
+ * @proc_num: The processor number
  *
- *  Give the model name of the processor. 
+ * Returns: the specified attribute
  */
 static gchar *
-get_processor_model_name (gint proc_num)
+get_processor_attribute (gint proc_num, gchar *attribute)
 {
-	gchar *model_name;
+	gchar *result;
 
 	gchar  *contents = NULL;
 	GError *error    = NULL;
 
-	gchar **lines;
+	gchar **lines    = NULL;
 
 	gint proc_num_i;
 
 	gchar *cursor;
 	gint   i;
 
-
 	if (g_file_get_contents ("/proc/cpuinfo", & contents, NULL, & error)) {
 		lines = g_strsplit (contents, "\n", 0);
 
@@ -514,17 +511,17 @@ get_processor_model_name (gint proc_num)
 
 				if (proc_num_i == proc_num) {
 					for (; lines [i]; ++i) {
-						if (strstr (lines [i], "model name\t:")) {
+						if (strstr (lines [i], attribute)) {
 							cursor = strstr (lines [i], ":");
 
 							g_strstrip (++ cursor);
 
-							model_name = g_strdup (cursor);
+							result = g_strdup (cursor);
 
 							g_strfreev (lines);
 							g_free     (contents);
 
-							return model_name;
+							return result;
 						}
 					}
 				}
@@ -544,12 +541,38 @@ get_processor_model_name (gint proc_num)
 	return NULL;
 }
 
+/**
+ *  get_processor_model_name:
+ *  @proc_num:	The processor number
+ *
+ *  Returns:    Name of the processor model
+ *
+ *  Give the model name of the processor.
+ */
+static gchar *
+get_processor_model_name (gint proc_num)
+{
+        return get_processor_attribute(proc_num, "model name\t:");
+}
+
+/**
+ * get_processor_flags:
+ * @proc_num: The processor number
+ *
+ * Returns:   The set of CPU flags for the given processor.
+ */
+static gchar *
+get_processor_flags (gint proc_num)
+{
+        return get_processor_attribute(proc_num, "flags\t\t:");
+}
+
 static gboolean
 processor_refresh (HalDevice *d, ACPIDevHandler *handler, gboolean force_full_refresh)
 {
 	const char *path;
 
-	gchar *model_name;
+	gchar *attribute;
 	gint   proc_num;
 
 	path = hal_device_property_get_string (d, "linux.acpi_path");
@@ -560,14 +583,22 @@ processor_refresh (HalDevice *d, ACPIDevHandler *handler, gboolean force_full_re
 		path, "info", "processor id", 0, 10, FALSE
 	);
 
-	if ((model_name = get_processor_model_name (proc_num))) {
-		hal_device_property_set_string (d, "info.product", model_name);
+	if ((attribute = get_processor_model_name (proc_num))) {
+		hal_device_property_set_string (d, "info.product", attribute);
 
-		g_free (model_name);
+		g_free (attribute);
 	}
 	else
 		hal_device_property_set_string (d, "info.product", "Unknown Processor");
 
+	attribute = get_processor_flags(proc_num);
+	printf("!!!!!attribute=%ld\n", attribute);
+	if (attribute) {
+	        hal_device_property_set_string (d, "processor.flags", attribute);
+
+		g_free (attribute);
+	}
+
 	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,
-- 
1.6.0.6



More information about the hal mailing list