hal: Branch 'master'

David Zeuthen david at kemper.freedesktop.org
Sun Feb 25 17:50:31 PST 2007


 fdi/policy/10osvendor/10-keyboard-policy.fdi |   12 -
 hald/linux/acpi.c                            |   27 +++
 hald/linux/addons/addon-acpi.c               |   26 +--
 hald/linux/addons/addon-keyboard.c           |   88 ++++++++++-
 hald/linux/device.c                          |  208 ++++++++++++++++++++++++++-
 hald/linux/device.h                          |    4 
 hald/linux/probing/probe-input.c             |  161 +++-----------------
 7 files changed, 362 insertions(+), 164 deletions(-)

New commits:
diff-tree f30d5efd1458cc43ec90563ea4028a26fdef7689 (from 942966555df78b10577d2d6b4368c23efc98de59)
Author: David Zeuthen <davidz at redhat.com>
Date:   Sun Feb 25 20:50:28 2007 -0500

    fix input probing and discard /proc/acpi events if ACPI sysfs sources are used
    
    In fact, move a lot of input device probing to be in the main hald
    process; we only use the helper for switches.

diff --git a/fdi/policy/10osvendor/10-keyboard-policy.fdi b/fdi/policy/10osvendor/10-keyboard-policy.fdi
index 4bae7c6..9cdf34e 100644
--- a/fdi/policy/10osvendor/10-keyboard-policy.fdi
+++ b/fdi/policy/10osvendor/10-keyboard-policy.fdi
@@ -3,11 +3,13 @@
 <deviceinfo version="0.2">
 
   <device>
-    <match key="info.capabilities" contains="input.keyboard">
-      <append key="info.addons" type="strlist">hald-addon-keyboard</append>
-      <append key="info.capabilities" type="strlist">button</append>
-      <merge key="button.type" type="string"></merge>
-      <merge key="button.has_state" type="bool">false</merge>
+    <match key="info.capabilities" contains="input">
+      <match key="info.capabilities" contains="button">
+	<append key="info.addons" type="strlist">hald-addon-keyboard</append>
+      </match>
+      <match key="info.capabilities" contains="input.keyboard">
+	<append key="info.addons" type="strlist">hald-addon-keyboard</append>
+      </match>
     </match>
   </device>
 
diff --git a/hald/linux/acpi.c b/hald/linux/acpi.c
index 5ff403c..30e5fdf 100644
--- a/hald/linux/acpi.c
+++ b/hald/linux/acpi.c
@@ -36,6 +36,7 @@
 #include "osspec_linux.h"
 
 #include "acpi.h"
+#include "device.h"
 
 enum {
 	ACPI_TYPE_BATTERY,
@@ -947,6 +948,8 @@ acpi_synthesize (const gchar *path, int 
 				snprintf (_path, sizeof (_path), "%s/acpi/button/lid", get_hal_proc_path ());
 				if ( strcmp (path, _path) == 0 )
 					is_laptop = TRUE;
+			} else if (_have_sysfs_lid_button) {
+				is_laptop = TRUE;
 			}
 		}
 		/* if there is a battery bay or LID, this is a laptop -> set the formfactor */
@@ -1137,6 +1140,28 @@ acpi_generic_add (const gchar *acpi_path
 	return d;
 }
 
+static HalDevice *
+acpi_button_add (const gchar *acpi_path, HalDevice *parent, ACPIDevHandler *handler)
+{
+	char *parent_path;
+	const char *button_type;
+
+	parent_path = hal_util_get_parent_path (acpi_path);
+	button_type = hal_util_get_last_element (parent_path);
+	if (strcmp (button_type, "lid") == 0 && _have_sysfs_lid_button)
+		goto out;
+	else if (strcmp (button_type, "power") == 0 && _have_sysfs_power_button)
+		goto out;
+	else if (strcmp (button_type, "sleep") == 0 && _have_sysfs_sleep_button)
+		goto out;
+
+	g_free (parent_path);
+	return acpi_generic_add (acpi_path, parent, handler);
+
+out:
+	return NULL;
+}
+
 static gboolean
 acpi_generic_compute_udi (HalDevice *d, ACPIDevHandler *handler)
 {
@@ -1238,7 +1263,7 @@ static ACPIDevHandler acpidev_handler_la
 
 static ACPIDevHandler acpidev_handler_button = {
 	.acpi_type   = ACPI_TYPE_BUTTON,
-	.add         = acpi_generic_add,
+	.add         = acpi_button_add,
 	.compute_udi = acpi_generic_compute_udi,
 	.refresh     = button_refresh,
 	.remove      = acpi_generic_remove
diff --git a/hald/linux/addons/addon-acpi.c b/hald/linux/addons/addon-acpi.c
index ac84a9e..a18bc9f 100644
--- a/hald/linux/addons/addon-acpi.c
+++ b/hald/linux/addons/addon-acpi.c
@@ -100,8 +100,6 @@ main_loop (LibHalContext *ctx, FILE *eve
 	DBusError error;
 	char event[256];
 
-	dbus_error_init (&error);
-
 	while (fgets (event, sizeof event, eventfp))
 	{
 		HAL_DEBUG (("event is '%s'", event));
@@ -117,17 +115,19 @@ main_loop (LibHalContext *ctx, FILE *eve
 				HAL_DEBUG (("button event"));
 
 				/* TODO: only rescan if button got state */
-				libhal_device_rescan (ctx, udi, &error);
-
-				type = libhal_device_get_property_string(ctx, udi, 
-									 "button.type",
-									 &error);
-				if (type != NULL) {
-					libhal_device_emit_condition (ctx, udi, "ButtonPressed",
-								      type, &error);
-					libhal_free_string(type);
-				} else {
-					libhal_device_emit_condition (ctx, udi, "ButtonPressed", "", &error);
+				dbus_error_init (&error);
+				if (libhal_device_rescan (ctx, udi, &error)) {
+					dbus_error_init (&error);
+					type = libhal_device_get_property_string(ctx, udi, 
+										 "button.type",
+										 &error);
+					if (type != NULL) {
+						libhal_device_emit_condition (ctx, udi, "ButtonPressed",
+									      type, &error);
+						libhal_free_string(type);
+					} else {
+						libhal_device_emit_condition (ctx, udi, "ButtonPressed", "", &error);
+					}
 				}
 			} else if (strncmp (acpi_path, "ac_adapter", sizeof ("ac_adapter") - 1) == 0) {
 				HAL_DEBUG (("ac_adapter event"));
diff --git a/hald/linux/addons/addon-keyboard.c b/hald/linux/addons/addon-keyboard.c
index 644da4f..30f989e 100644
--- a/hald/linux/addons/addon-keyboard.c
+++ b/hald/linux/addons/addon-keyboard.c
@@ -40,6 +40,8 @@
 #include "../../util_helper.h"
 
 static char *udi;
+static int button_state = FALSE;
+static int button_has_state = FALSE;
 
 static char *key_name[KEY_MAX + 1] = {
 	[0 ... KEY_MAX] = NULL,
@@ -168,17 +170,82 @@ static char *key_name[KEY_MAX + 1] = {
 	[KEY_WLAN] = "wlan"
 };
 
+
+/* we must use this kernel-compatible implementation */
+#define BITS_PER_LONG (sizeof(long) * 8)
+#define NBITS(x) ((((x)-1)/BITS_PER_LONG)+1)
+#define OFF(x)  ((x)%BITS_PER_LONG)
+#define BIT(x)  (1UL<<OFF(x))
+#define LONG(x) ((x)/BITS_PER_LONG)
+#define test_bit(bit, array)    ((array[LONG(bit)] >> OFF(bit)) & 1)
+
 static void
 main_loop (LibHalContext *ctx, FILE* eventfp)
 {
 	DBusError error;
 	struct input_event event;
 
-	dbus_error_init (&error);
 
 	while (fread (&event, sizeof(event), 1, eventfp)) {
-		/* dbg ("event.code = %d (0x%02x)", event.code); */
-		if (key_name[event.code] && event.value == 1) {
+
+		if (button_has_state && event.type == EV_SW) {
+			char *name = NULL;
+
+			HAL_INFO (("%s: event.value=%d ; event.code=%d (0x%02x)", 
+				   udi, event.value, event.code, event.code));
+
+
+			switch (event.code) {
+			case SW_LID:
+				name = "lid";
+				break;
+			case SW_TABLET_MODE:
+				name = "tablet_mode";
+				break;
+			case SW_HEADPHONE_INSERT:
+				name = "headphone_insert";
+				break;
+			}
+			if (name != NULL) {
+				long bitmask[NBITS(SW_MAX)];
+
+				/* check switch state - cuz apparently we get spurious events (or I don't know
+				 * how to use the input layer correctly)
+				 *
+				 * Lid close:
+				 * 19:08:22.911 [I] event.value=1 ; event.code=0 (0x00)
+				 * 19:08:22.914 [I] event.value=0 ; event.code=0 (0x00)
+				 *
+				 * Lid open:
+				 * 19:08:26.772 [I] event.value=0 ; event.code=0 (0x00)
+				 * 19:08:26.776 [I] event.value=0 ; event.code=0 (0x00)
+				 * 19:08:26.863 [I] event.value=1 ; event.code=0 (0x00)
+				 * 19:08:26.868 [I] event.value=0 ; event.code=0 (0x00)
+				 * 19:08:26.955 [I] event.value=0 ; event.code=0 (0x00)
+				 * 19:08:26.960 [I] event.value=0 ; event.code=0 (0x00)
+				 */
+
+				if (ioctl (fileno (eventfp), EVIOCGSW(sizeof (bitmask)), bitmask) < 0) {
+					HAL_DEBUG (("ioctl EVIOCGSW failed"));
+				} else {
+					int new_state = test_bit (event.code, bitmask);
+					if (new_state != button_state) {
+						button_state = new_state;
+						
+						dbus_error_init (&error);
+						libhal_device_set_property_bool (ctx, udi, "button.state.value", 
+										 button_state, &error);
+						
+						dbus_error_init (&error);
+						libhal_device_emit_condition (ctx, udi, 
+									      "ButtonPressed",
+									      name,
+									      &error);
+					}
+				}
+			}
+		} else if (event.type == EV_KEY && key_name[event.code] != NULL && event.value == 1) {
+			dbus_error_init (&error);
 			libhal_device_emit_condition (ctx, udi, 
 						      "ButtonPressed",
 						      key_name[event.code],
@@ -196,6 +263,7 @@ main (int argc, char **argv)
 	DBusError error;
 	char *device_file;
 	FILE *eventfp;
+	char *s;
 
 	hal_set_proc_title_init (argc, argv);
 
@@ -209,6 +277,14 @@ main (int argc, char **argv)
 	if ((device_file = getenv ("HAL_PROP_INPUT_DEVICE")) == NULL)
 		goto out;
 
+	s = getenv ("HAL_PROP_BUTTON_HAS_STATE");
+	if (s != NULL && strcmp (s, "true") == 0) {
+		button_has_state = TRUE;
+		if ((s = getenv ("HAL_PROP_BUTTON_STATE_VALUE")) == NULL)
+			goto out;
+		button_state = (strcmp (s, "true") == 0);
+	}
+
 	if ((ctx = libhal_ctx_init_direct (&error)) == NULL)
                 goto out;
 
@@ -217,7 +293,6 @@ main (int argc, char **argv)
 		goto out;
 	}
 
-
 	eventfp = fopen(device_file, "r");	
 
 	if (!eventfp)
@@ -231,11 +306,10 @@ main (int argc, char **argv)
 	{
 		main_loop (ctx, eventfp);
 		
-		/* If main_loop exits sleep for 5s and try to reconnect (
-		   again). */
+		/* If main_loop exits sleep for 5s and try to reconnect (again). */
 		sleep (5);
 	}
-
+	
 	return 0;
 
  out:
diff --git a/hald/linux/device.c b/hald/linux/device.c
index 909d74c..1db5432 100644
--- a/hald/linux/device.c
+++ b/hald/linux/device.c
@@ -38,6 +38,7 @@
 #include <unistd.h>
 #include <asm/byteorder.h>
 #include <fcntl.h>
+#include <linux/input.h>
 
 #include <dbus/dbus.h>
 #include <dbus/dbus-glib.h>
@@ -59,10 +60,186 @@
 
 /*--------------------------------------------------------------------------------------------------------------*/
 
+/* this is kinda messy... but acpi.c + friends use this */
+gboolean _have_sysfs_lid_button = FALSE;
+gboolean _have_sysfs_power_button = FALSE;
+gboolean _have_sysfs_sleep_button = FALSE;
+
+/* we must use this kernel-compatible implementation */
+#define BITS_PER_LONG (sizeof(long) * 8)
+#define NBITS(x) ((((x)-1)/BITS_PER_LONG)+1)
+#define OFF(x)  ((x)%BITS_PER_LONG)
+#define BIT(x)  (1UL<<OFF(x))
+#define LONG(x) ((x)/BITS_PER_LONG)
+#define test_bit(bit, array)    ((array[LONG(bit)] >> OFF(bit)) & 1)
+
+static int
+input_str_to_bitmask (const char *s, long *bitmask, size_t max_size)
+{
+	int i, j;
+	char **v;
+	int num_bits_set = 0;
+
+	memset (bitmask, 0, max_size);
+	v = g_strsplit (s, " ", max_size);
+	for (i = g_strv_length (v) - 1, j = 0; i >= 0; i--, j++) {
+		unsigned long val;
+
+		val = strtoul (v[i], NULL, 16);
+		bitmask[j] = val;
+
+		while (val != 0) {
+			num_bits_set++;
+			val &= (val - 1);
+		}
+	}
+
+	return num_bits_set;
+}
+
+static void
+input_test_rel (HalDevice *d, const char *sysfs_path)
+{
+	char *s;
+	long bitmask[NBITS(REL_MAX)];
+	int num_bits;
+
+	s = hal_util_get_string_from_file (sysfs_path, "../capabilities/rel");
+	if (s == NULL)
+		goto out;
+
+	num_bits = input_str_to_bitmask (s, bitmask, sizeof (bitmask));
+
+	/* TODO: this test can be improved */
+	if (test_bit (REL_X, bitmask) && test_bit (REL_Y, bitmask)) {
+		hal_device_add_capability (d, "input.mouse");
+	}
+out:
+	;
+}
+
+static void
+input_test_key (HalDevice *d, const char *sysfs_path)
+{
+	int i;
+	char *s;
+	long bitmask[NBITS(KEY_MAX)];
+	int num_bits;
+
+	s = hal_util_get_string_from_file (sysfs_path, "../capabilities/key");
+	if (s == NULL)
+		goto out;
+
+	num_bits = input_str_to_bitmask (s, bitmask, sizeof (bitmask));
+
+	if (num_bits == 1) {
+		/* this is for input devices originating from the ACPI layer et. al. */
+
+		/* TODO: potentially test for BUS_HOST */
+
+		hal_device_add_capability (d, "button");
+		hal_device_property_set_bool (d, "button.has_state", FALSE);
+		if (test_bit (KEY_POWER, bitmask)) {
+			hal_device_property_set_string (d, "button.type", "power");
+			_have_sysfs_power_button = TRUE;
+		} else if (test_bit (KEY_SLEEP, bitmask)) {
+			hal_device_property_set_string (d, "button.type", "sleep");
+			_have_sysfs_sleep_button = TRUE;
+		} else if (test_bit (KEY_SUSPEND, bitmask)) {
+			hal_device_property_set_string (d, "button.type", "hibernate");
+		}
+	} else {
+		/* TODO: we probably should require lots of bits set to classify as keyboard. Oh well */
+
+		/* All keys that are not buttons are less than BTN_MISC */
+		for (i = KEY_RESERVED + 1; i < BTN_MISC; i++) {
+			if (test_bit (i, bitmask)) {
+				hal_device_add_capability (d, "input.keyboard");
+				break;
+			}
+		}
+	}
+out:
+	;
+}
+
+static void
+input_test_switch (HalDevice *d, const char *sysfs_path)
+{
+	char *s;
+	long bitmask[NBITS(SW_MAX)];
+	int num_bits;
+
+	s = hal_util_get_string_from_file (sysfs_path, "../capabilities/sw");
+	if (s == NULL)
+		goto out;
+
+	num_bits = input_str_to_bitmask (s, bitmask, sizeof (bitmask));
+	if (num_bits <= 0)
+		goto out;
+
+	hal_device_add_capability (d, "input.switch");
+	if (num_bits == 1) {
+		hal_device_add_capability (d, "button");
+		hal_device_property_set_bool (d, "button.has_state", TRUE);
+		/* NOTE: button.state.value will be set from our prober in hald/linux/probing/probe-input.c */
+		hal_device_property_set_bool (d, "button.state.value", FALSE);
+		if (test_bit (SW_LID, bitmask)) {
+			hal_device_property_set_string (d, "button.type", "lid");
+			_have_sysfs_lid_button = TRUE;
+		} else if (test_bit (SW_TABLET_MODE, bitmask)) {
+			hal_device_property_set_string (d, "button.type", "tablet_mode");
+		} else if (test_bit (SW_HEADPHONE_INSERT, bitmask)) {
+			hal_device_property_set_string (d, "button.type", "headphone_insert");
+		}
+	}
+
+out:
+	;
+}
+
+static void
+input_test_abs (HalDevice *d, const char *sysfs_path)
+{
+	char *s;
+	long bitmask[NBITS(ABS_MAX)];
+	int num_bits;
+
+	s = hal_util_get_string_from_file (sysfs_path, "../capabilities/abs");
+	if (s == NULL)
+		goto out;
+	num_bits = input_str_to_bitmask (s, bitmask, sizeof (bitmask));
+
+	if (test_bit(ABS_X, bitmask) && !test_bit(ABS_Y, bitmask)) {
+		long bitmask_touch[NBITS(KEY_MAX)];
+
+		hal_device_add_capability (d, "input.joystick");
+
+		s = hal_util_get_string_from_file (sysfs_path, "../capabilities/key");
+		if (s == NULL)
+			goto out;
+		input_str_to_bitmask (s, bitmask_touch, sizeof (bitmask_touch));
+
+		if (test_bit(BTN_TOUCH, bitmask_touch)) {
+			hal_device_add_capability (d, "input.tablet");
+		}
+	}
+out:
+	;
+}
+
 static HalDevice *
 input_add (const gchar *sysfs_path, const gchar *device_file, HalDevice *parent_dev, const gchar *parent_path)
 {
-	HalDevice *d;
+	int eventdev_num;
+	HalDevice *d = NULL;
+
+	if (device_file == NULL)
+		goto out;
+
+	/* only care about evdev input devices */
+	if (sscanf (hal_util_get_last_element (sysfs_path), "event%d", &eventdev_num) != 1)
+		goto out;
 
 	d = hal_device_new ();
 	hal_device_property_set_string (d, "linux.sysfs_path", sysfs_path);
@@ -78,13 +255,36 @@ input_add (const gchar *sysfs_path, cons
 
 	hal_device_property_set_string (d, "input.device", device_file);
 
+	hal_util_set_string_from_file (d, "info.product", sysfs_path, "../name");
+	hal_util_set_string_from_file (d, "input.product", sysfs_path, "../name");
+
+	/* check for keys */
+	input_test_key (d, sysfs_path);
+
+	/* check for mice etc. */
+	input_test_rel (d, sysfs_path);
+
+	/* check for joysticks etc. */
+	input_test_abs (d, sysfs_path);
+
+	/* check for switches */
+	input_test_switch (d, sysfs_path);
+
+out:
 	return d;
 }
 
 static const gchar *
 input_get_prober (HalDevice *d)
 {
-	return "hald-probe-input";
+	const char *prober = NULL;
+
+	/* need privileges to check state of switch */
+	if (hal_device_property_get_bool (d, "button.has_state")) {
+		prober = "hald-probe-input";
+	}
+
+	return prober;
 }
 
 static gboolean
@@ -2482,7 +2682,7 @@ ccwgroup_add_qeth_properties (HalDevice 
 	hal_util_set_string_from_file (d, "ccwgroup.qeth.checksumming",
 				       sysfs_path, "checksumming");
 	if (!is_layer2) {
-		//CH: the next two are only valid for token ring devices
+		/* CH: the next two are only valid for token ring devices */
 		hal_util_set_int_from_file (d,
 					    "ccwgroup.qeth.canonical_macaddr",
 					    sysfs_path, "canonical_macaddr", 2);
@@ -2518,7 +2718,7 @@ ccwgroup_add_qeth_properties (HalDevice 
 static inline void
 ccwgroup_add_ctc_properties (HalDevice *d, const gchar *sysfs_path)
 {
-	//CH: use protocol descriptions?
+	/* CH: use protocol descriptions? */
 	hal_util_set_int_from_file (d, "ccwgroup.ctc.protocol", sysfs_path,
 				    "protocol", 2);
 	hal_util_set_string_from_file (d, "ccwgroup.ctc.type", sysfs_path,
diff --git a/hald/linux/device.h b/hald/linux/device.h
index 7545dcd..8ec9412 100644
--- a/hald/linux/device.h
+++ b/hald/linux/device.h
@@ -48,4 +48,8 @@ HotplugEvent *dev_generate_add_hotplug_e
 
 HotplugEvent *dev_generate_remove_hotplug_event (HalDevice *d);
 
+extern gboolean _have_sysfs_lid_button;
+extern gboolean _have_sysfs_power_button;
+extern gboolean _have_sysfs_sleep_button;
+
 #endif
diff --git a/hald/linux/probing/probe-input.c b/hald/linux/probing/probe-input.c
index aff12d8..6a107fb 100644
--- a/hald/linux/probing/probe-input.c
+++ b/hald/linux/probing/probe-input.c
@@ -37,7 +37,6 @@
 #include <unistd.h>
 
 #include "libhal/libhal.h"
-
 #include "../../logger.h"
 
 /* we must use this kernel-compatible implementation */
@@ -48,94 +47,6 @@
 #define LONG(x) ((x)/BITS_PER_LONG)
 #define test_bit(bit, array)    ((array[LONG(bit)] >> OFF(bit)) & 1)
 
-static void 
-check_abs (int fd, LibHalContext *ctx, const char *udi)
-{
-	long bitmask[NBITS(ABS_MAX)];
-	long bitmask_touch[NBITS(KEY_MAX)];
-	DBusError error;
-
-	if (ioctl (fd, EVIOCGBIT(EV_ABS, sizeof (bitmask)), bitmask) < 0) {
-		HAL_DEBUG (("ioctl EVIOCGBIT for EV_ABS failed"));
-		goto out;
-	}
-
-	if (ioctl (fd, EVIOCGBIT(EV_KEY, sizeof (bitmask_touch)), bitmask_touch) < 0) {
-		HAL_DEBUG (("ioctl EVIOCGBIT for EV_KEY failed"));
-		goto out;
-	}
-	
-	if (!test_bit(ABS_X, bitmask) || !test_bit(ABS_Y, bitmask)) {
-		HAL_DEBUG (("missing x or y absolute axes"));
-		goto out;
-	}
-
-	dbus_error_init (&error);
-	if (test_bit(BTN_TOUCH, bitmask_touch) != 0) {
-		libhal_device_add_capability (ctx, udi, "input.tablet", &error);
-		goto out;
-	}
-	libhal_device_add_capability (ctx, udi, "input.joystick", &error);
-
-out:
-	;
-}
-
-static void 
-check_key (int fd, LibHalContext *ctx, const char *udi)
-{
-	unsigned int i;
-	long bitmask[NBITS(KEY_MAX)];
-	int is_keyboard;
-	DBusError error;
-
-	if (ioctl (fd, EVIOCGBIT(EV_KEY, sizeof (bitmask)), bitmask) < 0) {
-		HAL_DEBUG (("ioctl EVIOCGBIT for EV_KEY failed"));
-		goto out;
-	}
-
-	is_keyboard = FALSE;
-
-	/* All keys that are not buttons are less than BTN_MISC */
-	for (i = KEY_RESERVED + 1; i < BTN_MISC; i++) {
-		if (test_bit (i, bitmask)) {
-			is_keyboard = TRUE;
-			break;
-		}
-	}
-
-	if (is_keyboard) {
-		dbus_error_init (&error);
-		libhal_device_add_capability (ctx, udi, "input.keyboard", &error);
-	}
-
-out:
-	;
-}
-
-static void 
-check_rel (int fd, LibHalContext *ctx, const char *udi)
-{
-	long bitmask[NBITS(REL_MAX)];
-	DBusError error;
-
-	if (ioctl (fd, EVIOCGBIT(EV_REL, sizeof (bitmask)), bitmask) < 0) {
-		HAL_DEBUG (("ioctl EVIOCGBIT for EV_REL failed"));
-		goto out;
-	}
-
-	if (!test_bit (REL_X, bitmask) || !test_bit (REL_Y, bitmask)) {
-		HAL_DEBUG (("missing x or y relative axes"));
-		goto out;
-	}
-
-	dbus_error_init (&error);
-	libhal_device_add_capability (ctx, udi, "input.mouse", &error);
-
-out:
-	;
-}
-
 int 
 main (int argc, char *argv[])
 {
@@ -143,18 +54,34 @@ main (int argc, char *argv[])
 	int ret;
 	char *udi;
 	char *device_file;
-	char *physical_device;
+	char *button_type;
+	int sw;
 	LibHalContext *ctx = NULL;
 	DBusError error;
-	char name[128];
-	struct input_id id;
+	long bitmask[NBITS(SW_MAX)];
+
+	/* assume failure */
+	ret = 1;
+	fd = -1;
 
 	setup_logger ();
 
-	fd = -1;
+	button_type = getenv ("HAL_PROP_BUTTON_TYPE");
+	if (button_type == NULL)
+		goto out;
 
-	/* assume failure */
-	ret = 1;
+	if (strcmp (button_type, "lid") == 0)
+		sw = SW_LID;
+	else if (strcmp (button_type, "tablet_mode") == 0)
+		sw = SW_TABLET_MODE;
+	else if (strcmp (button_type, "headphone_insert") == 0)
+		sw = SW_HEADPHONE_INSERT;
+	else
+		goto out;
+
+	device_file = getenv ("HAL_PROP_INPUT_DEVICE");
+	if (device_file == NULL)
+		goto out;
 
 	udi = getenv ("UDI");
 	if (udi == NULL)
@@ -164,10 +91,6 @@ main (int argc, char *argv[])
 	if ((ctx = libhal_ctx_init_direct (&error)) == NULL)
 		goto out;
 
-	device_file = getenv ("HAL_PROP_INPUT_DEVICE");
-	if (device_file == NULL)
-		goto out;
-
 	HAL_DEBUG (("Doing probe-input for %s (udi=%s)", device_file, udi));
 
 	fd = open (device_file, O_RDONLY);
@@ -176,44 +99,14 @@ main (int argc, char *argv[])
 		goto out;
 	}
 
-	/* if we don't have a physical device then only accept input buses
-	 * that we now aren't hotpluggable
-	 */
-	if (ioctl (fd, EVIOCGID, &id) < 0) {
-		HAL_ERROR (("Error: EVIOCGID failed: %s\n", strerror(errno)));
+	if (ioctl (fd, EVIOCGSW(sizeof (bitmask)), bitmask) < 0) {
+		HAL_DEBUG (("ioctl EVIOCGSW failed"));
 		goto out;
 	}
-	physical_device = getenv ("HAL_PROP_INPUT_ORIGINATING_DEVICE");
 
-	HAL_DEBUG (("probe-input: id.bustype=%i", id.bustype));
-	if (physical_device == NULL) {
-		switch (id.bustype) {
-		case BUS_I8042: /* x86 legacy port */
-		case BUS_HOST: /* not hotpluggable */
-		case BUS_PARPORT: /* XXX: really needed? */
-		case BUS_ADB: /* ADB on Apple computers */
-			break;
-
-		default:
-			goto out;
-		}
-	}
-
-	/* only consider devices with the event interface */
-	if (ioctl (fd, EVIOCGNAME(sizeof (name)), name) < 0) {
-		HAL_ERROR (("Error: EVIOCGNAME failed: %s\n", strerror(errno)));
-		goto out;
-	}
-	if (!libhal_device_set_property_string (ctx, udi, "info.product", name, &error))
-		goto out;
-	if (!libhal_device_set_property_string (ctx, udi, "input.product", name, &error))
-		goto out;
-
-	check_abs (fd, ctx, udi);
-	check_rel (fd, ctx, udi);
-	check_key (fd, ctx, udi);
-
-	/* success */
+	dbus_error_init (&error);
+	libhal_device_set_property_bool (ctx, udi, "button.state.value", test_bit (sw, bitmask), &error);
+	
 	ret = 0;
 
 out:


More information about the hal-commit mailing list