00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifdef HAVE_CONFIG_H
00028 # include <config.h>
00029 #endif
00030
00031 #include <ctype.h>
00032 #include <stdio.h>
00033 #include <stdlib.h>
00034 #include <string.h>
00035 #include <getopt.h>
00036 #include <assert.h>
00037 #include <unistd.h>
00038 #include <stdarg.h>
00039 #include <limits.h>
00040 #include <sys/types.h>
00041 #include <sys/stat.h>
00042 #include <sys/ioctl.h>
00043 #include <fcntl.h>
00044
00045 #include "../logger.h"
00046 #include "../device_store.h"
00047 #include "../hald.h"
00048
00049 #include "class_device.h"
00050 #include "common.h"
00051
00052
00053 #define IOCNR_GET_DEVICE_ID 1
00054 #define LPIOC_GET_DEVICE_ID(len) _IOC(_IOC_READ, 'P', IOCNR_GET_DEVICE_ID, len)
00055
00063 static dbus_bool_t
00064 printer_class_device_accept (ClassDeviceHandler *self,
00065 const char *path,
00066 struct sysfs_class_device *class_device,
00067 dbus_bool_t is_probing)
00068 {
00069 int lp_number;
00070
00071 if (sscanf (class_device->name, "lp%d", &lp_number) == 1)
00072 return TRUE;
00073
00074 return FALSE;
00075 }
00076
00091 static void
00092 printer_class_pre_process (ClassDeviceHandler *self,
00093 HalDevice *d,
00094 const char *sysfs_path,
00095 struct sysfs_class_device *class_device)
00096 {
00097 int fd;
00098 char device_id[1024];
00099 char **props, **iter;
00100 char *mfg = NULL, *model = NULL, *serial = NULL, *desc = NULL;
00101
00102
00103 hal_device_property_set_string (d, "info.category", "printer");
00104 hal_device_add_capability (d, "printer");
00105
00106 fd = open (hal_device_property_get_string (d, "printer.device"),
00107 O_RDWR | O_EXCL);
00108
00109 if (fd < 0)
00110 return;
00111
00112 if (ioctl (fd, LPIOC_GET_DEVICE_ID (sizeof (device_id)),
00113 device_id) < 0) {
00114 close (fd);
00115 return;
00116 }
00117
00118 close (fd);
00119
00120 HAL_TRACE (("printer IEEE-1284 device_id: %s", device_id+2));
00121
00122 props = g_strsplit (device_id+2, ";", 0);
00123 for (iter = props; *iter != NULL; iter++) {
00124 if (strncmp (*iter, "MANUFACTURER:", 13) == 0)
00125 mfg = *iter + 13;
00126 else if (strncmp (*iter, "MFG:", 4) == 0)
00127 mfg = *iter + 4;
00128 else if (strncmp (*iter, "MODEL:", 6) == 0)
00129 model = *iter + 6;
00130 else if (strncmp (*iter, "MDL:", 4) == 0)
00131 model = *iter + 4;
00132 else if (strncmp (*iter, "SN:", 3) == 0)
00133 serial = *iter + 3;
00134 else if (strncmp (*iter, "SERN:", 5) == 0)
00135 serial = *iter + 5;
00136 else if (strncmp (*iter, "SERIALNUMBER:", 13) == 0)
00137 serial = *iter + 13;
00138 else if (strncmp (*iter, "DES:", 4) == 0)
00139 desc = *iter + 4;
00140 else if (strncmp (*iter, "DESCRIPTION:", 12) == 0)
00141 desc = *iter + 12;
00142 }
00143
00144 if (mfg != NULL) {
00145 hal_device_property_set_string (d, "info.vendor", mfg);
00146 hal_device_property_set_string (d, "printer.vendor", mfg);
00147 }
00148
00149 if (model != NULL) {
00150 hal_device_property_set_string (d, "info.product", model);
00151 hal_device_property_set_string (d, "printer.product", model);
00152 }
00153
00154 if (serial != NULL)
00155 hal_device_property_set_string (d, "printer.serial", serial);
00156
00157 if (desc != NULL) {
00158 hal_device_property_set_string (d, "printer.description",
00159 desc);
00160 }
00161
00162 g_strfreev (props);
00163 }
00164
00166 ClassDeviceHandler printer_class_handler = {
00167 class_device_init,
00168 class_device_detection_done,
00169 class_device_shutdown,
00170 class_device_tick,
00171 printer_class_device_accept,
00172 class_device_visit,
00173 class_device_removed,
00174 class_device_udev_event,
00175 class_device_get_device_file_target,
00176 printer_class_pre_process,
00177 class_device_post_merge,
00178 class_device_got_udi,
00179 NULL,
00180 "usb",
00181 "printer",
00182 TRUE,
00183 TRUE
00184 };
00185