summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoe Shaw <joeshaw@novell.com>2004-04-05 18:14:20 +0000
committerJoe Shaw <joeshaw@novell.com>2004-04-05 18:14:20 +0000
commita6437167cda65ff8a005a8194f07bdca26bdc4e9 (patch)
treedf337a1c328c0bab13472bfcb7bedfd16046d5c1
parent71ca5f83cd3256d6bf81c5bdf9e4f67ab37566fa (diff)
Added. New printer class.
Build linux/printer_class_device.c Add the printer class handler.
-rw-r--r--ChangeLog8
-rw-r--r--hald/Makefile.am1
-rw-r--r--hald/linux/osspec.c2
-rw-r--r--hald/linux/printer_class_device.c161
4 files changed, 172 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index e1f1c86c..2ee23783 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2004-04-05 Joe Shaw <joe@ximian.com>
+
+ * hald/linux/printer_class_device.c: Added. New printer class.
+
+ * hald/linux/Makefile.am: Build linux/printer_class_device.c
+
+ * hald/linux/osspec.c: Add the printer class handler.
+
2004-04-03 David Zeuthen <david@fubar.dk>
* hald/main.c : Removed file
diff --git a/hald/Makefile.am b/hald/Makefile.am
index 3190d479..eaa5e5e5 100644
--- a/hald/Makefile.am
+++ b/hald/Makefile.am
@@ -35,6 +35,7 @@ hald_SOURCES += \
linux/usb_bus_device.c \
linux/usbif_bus_device.c \
linux/input_class_device.c \
+ linux/printer_class_device.c \
linux/scsi_host_class_device.c \
linux/scsi_device_class_device.c \
linux/block_class_device.c \
diff --git a/hald/linux/osspec.c b/hald/linux/osspec.c
index f5e34e0a..0b7a0f4e 100644
--- a/hald/linux/osspec.c
+++ b/hald/linux/osspec.c
@@ -50,6 +50,7 @@
#include "libsysfs/libsysfs.h"
extern ClassDeviceHandler input_class_handler;
+extern ClassDeviceHandler printer_class_handler;
extern ClassDeviceHandler scsi_host_class_handler;
extern ClassDeviceHandler scsi_device_class_handler;
extern ClassDeviceHandler block_class_handler;
@@ -62,6 +63,7 @@ extern BusDeviceHandler ide_bus_handler;
static ClassDeviceHandler* class_device_handlers[] = {
&input_class_handler,
+ &printer_class_handler,
&scsi_host_class_handler,
&scsi_device_class_handler,
&block_class_handler,
diff --git a/hald/linux/printer_class_device.c b/hald/linux/printer_class_device.c
new file mode 100644
index 00000000..e043f39c
--- /dev/null
+++ b/hald/linux/printer_class_device.c
@@ -0,0 +1,161 @@
+/***************************************************************************
+ * CVSID: $Id$
+ *
+ * Printer device class
+ *
+ * Copyright (C) 2003 David Zeuthen, <david@fubar.dk>
+ * Copyright (C) 2004 Novell, Inc.
+ *
+ * Licensed under the Academic Free License version 2.0
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ **************************************************************************/
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <ctype.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <getopt.h>
+#include <assert.h>
+#include <unistd.h>
+#include <stdarg.h>
+#include <limits.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/ioctl.h>
+#include <fcntl.h>
+
+#include "../logger.h"
+#include "../device_store.h"
+#include "../hald.h"
+
+#include "class_device.h"
+#include "common.h"
+
+/* Stolen from kernel 2.6.4, drivers/usb/class/usblp.c */
+#define IOCNR_GET_DEVICE_ID 1
+#define LPIOC_GET_DEVICE_ID(len) _IOC(_IOC_READ, 'P', IOCNR_GET_DEVICE_ID, len)
+
+/**
+ * @defgroup HalDaemonLinuxPrinter Printer class
+ * @ingroup HalDaemonLinux
+ * @brief Printer class
+ * @{
+ */
+
+
+/** 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
+ * through e.g. ioctl's using the device file property and also
+ * for setting info.category|capability.
+ *
+ * @param self Pointer to class members
+ * @param d The HalDevice object of the instance of
+ * this device class
+ * @param sysfs_path The path in sysfs (including mount point) of
+ * the class device in sysfs
+ * @param class_device Libsysfs object representing class device
+ * instance
+ */
+static void
+printer_class_post_process (ClassDeviceHandler *self,
+ HalDevice *d,
+ const char *sysfs_path,
+ struct sysfs_class_device *class_device)
+{
+ int fd;
+ char device_id[1024];
+ char **props, **iter;
+ char *mfg = NULL, *model = NULL, *serial = NULL;
+
+ /* add capabilities for device */
+ hal_device_property_set_string (d, "info.category", "printer");
+ hal_device_add_capability (d, "printer");
+
+ fd = open (hal_device_property_get_string (d, "printer.device"),
+ O_RDWR | O_EXCL);
+
+ if (fd < 0)
+ return;
+
+ if (ioctl (fd, LPIOC_GET_DEVICE_ID (sizeof (device_id)),
+ device_id) < 0) {
+ close (fd);
+ return;
+ }
+
+ close (fd);
+
+ HAL_TRACE (("device_id: %s", device_id+2));
+
+ props = g_strsplit (device_id+2, ";", 0);
+ for (iter = props; *iter != NULL; iter++) {
+ if (strncmp (*iter, "MANUFACTURER:", 13) == 0)
+ mfg = *iter + 13;
+ else if (strncmp (*iter, "MFG:", 4) == 0)
+ mfg = *iter + 4;
+ else if (strncmp (*iter, "MODEL:", 6) == 0)
+ model = *iter + 6;
+ else if (strncmp (*iter, "MDL:", 4) == 0)
+ model = *iter + 4;
+ else if (strncmp (*iter, "SN:", 3) == 0)
+ serial = *iter + 3;
+ else if (strncmp (*iter, "SERN:", 5) == 0)
+ serial = *iter + 5;
+ else if (strncmp (*iter, "SERIALNUMBER:", 13) == 0)
+ serial = *iter + 13;
+ }
+
+ if (mfg != NULL) {
+ hal_device_property_set_string (d, "info.vendor", mfg);
+ hal_device_property_set_string (d, "printer.vendor", mfg);
+ }
+
+ if (model != NULL) {
+ hal_device_property_set_string (d, "info.product", model);
+ hal_device_property_set_string (d, "printer.product", model);
+ }
+
+ if (serial != NULL)
+ hal_device_property_set_string (d, "printer.serial", serial);
+
+ g_strfreev (props);
+}
+
+/** Method specialisations for input device class */
+ClassDeviceHandler printer_class_handler = {
+ class_device_init, /**< init function */
+ class_device_detection_done, /**< detection is done */
+ class_device_shutdown, /**< shutdown function */
+ class_device_tick, /**< timer function */
+ class_device_visit, /**< visitor function */
+ class_device_removed, /**< class device is removed */
+ class_device_udev_event, /**< handle udev event */
+ class_device_get_device_file_target,/**< where to store devfile name */
+ printer_class_post_process, /**< add more properties */
+ NULL, /**< No UDI computation */
+ "usb", /**< sysfs class name */
+ "printer", /**< hal class name */
+ TRUE, /**< require device file */
+ TRUE /**< merge onto sysdevice */
+};
+
+/** @} */