hal/hald/linux input_class_device.c,1.7,1.8

Joe Shaw joe at pdx.freedesktop.org
Fri Jun 4 12:26:15 PDT 2004


Update of /cvs/hal/hal/hald/linux
In directory pdx:/tmp/cvs-serv30633/hald/linux

Modified Files:
	input_class_device.c 
Log Message:
2004-06-04  Joe Shaw  <joeshaw at novell.com>

	Patch from Kristian Høgsberg <krh at bitplanet.net>

	* hald/linux/input_class_device.c (input_class_accept): New
	function.  Accepts devices with no sysdevice but which begin with
	"event".  For built-in, non-sysfs input devices like PS/2 mice.
	(input_class_pre_process): Set the major and minor numbers as
	properties.  If there is no sysdevice, do an ioctl() on the device
	to try to get identifying info about it and set it in
	info.product.
	(input_class_compute_udi): Added.  Computes the UDI for devices
	that don't get merged onto parents.
	(input_class_handler): Use input-specific functions for the accept
	and compute_udi functions.

Index: input_class_device.c
===================================================================
RCS file: /cvs/hal/hal/hald/linux/input_class_device.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- a/input_class_device.c	30 Apr 2004 20:59:08 -0000	1.7
+++ b/input_class_device.c	4 Jun 2004 19:26:13 -0000	1.8
@@ -36,6 +36,8 @@
 #include <unistd.h>
 #include <stdarg.h>
 #include <limits.h>
+#include <fcntl.h>
+#include <linux/input.h>
 
 #include "../logger.h"
 #include "../device_store.h"
@@ -52,6 +54,32 @@
  */
 
 
+/** Accept function for input devices.  It's like
+ *  class_device_accept(), except we accept the device even if there
+ *  is no sysfs device
+ *
+ *  @param  self                Pointer to class members
+ *  @param  path                Sysfs-path for device
+ *  @param  class_device        libsysfs object for class device
+ */
+dbus_bool_t
+input_class_accept (ClassDeviceHandler *self,
+                    const char *path,
+                    struct sysfs_class_device *class_device)
+{
+        /* If there is no sysfs device we only accept event%d devices. */
+        if (class_device->sysdevice == NULL &&
+            strncmp (class_device->name, "event", 5) != 0)
+                return FALSE;
+
+	/* only care about given sysfs class name */
+	if (strcmp (class_device->classname, self->sysfs_class_name) == 0) {
+		return TRUE;
+	}
+
+	return FALSE;
+}
+
 /** This method is called just before the device is either merged
  *  onto the sysdevice or added to the GDL (cf. merge_or_add). 
  *  This is useful for extracting more information about the device
@@ -72,6 +100,11 @@
 			 const char *sysfs_path,
 			 struct sysfs_class_device *class_device)
 {
+        char name[64];
+        const char *device_file;
+        int major, minor;
+        int fd;
+
 	/* add capabilities for device */
 	hal_device_property_set_string (d, "info.category", "input");
 	hal_device_add_capability (d, "input");
@@ -80,6 +113,34 @@
 	 *        .target_dev) and set additional properties */
 
 	/** @todo read some data from sysfs and set additional properties */
+
+	class_device_get_major_minor (sysfs_path, &major, &minor);
+	hal_device_property_set_int (d, "input.major", major);
+	hal_device_property_set_int (d, "input.minor", minor);
+
+	/* Find out what kind of input device this is */
+	if (!hal_device_has_property (d, "input.device"))
+                /* We're being called for for a mouse%d alias device
+                 * that doesn't have the input.device property. */
+                return;
+
+        device_file = hal_device_property_get_string (d, "input.device");
+	fd = open (device_file, O_RDONLY | O_NONBLOCK);
+	if (fd < 0)
+		return;
+		
+        /* If there is no corresponding sysfs device we ask the event
+         * layer for a name for this device.*/
+        if (class_device->sysdevice == NULL) {
+                if (ioctl(fd, EVIOCGNAME(sizeof name), name) >= 0) {
+                        hal_device_property_set_string (d, "info.product",
+                                                        name);
+                }
+        }
+
+        /* @todo add more ioctl()'s here */
+
+        close(fd);
 }
 
 /** Get the name of that the property that the device file should be put in.
@@ -122,12 +183,40 @@
 	}
 }
 
+
+/** Compute the device udi for input devices that do not have a sysfs
+ *  device file.
+ *
+ *  @param  d                   HalDevice object
+ *  @param  append_num          Number to append to name if not -1
+ *  @return                     New unique device id; only good until
+ *                              the next invocation of this function
+ */
+static char *
+input_class_compute_udi (HalDevice *d, int append_num)
+{
+        char *format;
+        static char buf[256];
+
+        if (append_num == -1)
+                format = "/org/freedesktop/Hal/devices/input_%d_%d";
+        else
+                format = "/org/freedesktop/Hal/devices/input_%d_%d-%d";
+ 
+        snprintf (buf, 256, format,
+                  hal_device_property_get_int (d, "input.major"),
+                  hal_device_property_get_int (d, "input.minor"), append_num);
+ 
+        return buf;
+  
+}
+
 /** Method specialisations for input device class */
 ClassDeviceHandler input_class_handler = {
 	class_device_init,                  /**< init function */
 	class_device_shutdown,              /**< shutdown function */
 	class_device_tick,                  /**< timer function */
-	class_device_accept,                /**< accept function */
+	input_class_accept,                 /**< accept function */
 	class_device_visit,                 /**< visitor function */
 	class_device_removed,               /**< class device is removed */
 	class_device_udev_event,            /**< handle udev event */
@@ -135,7 +224,7 @@
 	input_class_pre_process,            /**< add more properties */
 	class_device_post_merge,            /**< post merge function */
 	class_device_got_udi,               /**< got UDI */
-	NULL,                               /**< No UDI computation */
+	input_class_compute_udi,            /**< UDI computation */
 	"input",                            /**< sysfs class name */
 	"input",                            /**< hal class name */
 	TRUE,                               /**< require device file */





More information about the hal-commit mailing list