hal/hald/linux osspec.c, 1.43, 1.44 serial_class_device.c, NONE, 1.1 usb_bus_device.c, 1.13, 1.14 usb_serial_bus_device.c, NONE, 1.1

Kay Sievers kay at freedesktop.org
Mon Sep 20 11:31:17 PDT 2004


Update of /cvs/hal/hal/hald/linux
In directory gabe:/tmp/cvs-serv31151/hald/linux

Modified Files:
	osspec.c usb_bus_device.c 
Added Files:
	serial_class_device.c usb_serial_bus_device.c 
Log Message:
2004-09-20  Kay Sievers  <kay.sievers at vrfy.org>

        Add support for usb-serial devices:

        * hald/Makefile.am: add serial_class_device.c,
        usb_serial_bus_device.c

        * hald/linux/osspec.c: (hald_helper_data): plug serial_class_handler,
        usb_serial_bus_handler into the device processing

        * hald/linux/serial_class_device.c: (serial_class_device_accept),
        (serial_class_pre_process): new file to support serial ports

        * hald/linux/usb_serial_bus_device.c:
        (usb_serial_device_compute_udi), (usb_serial_device_pre_process):
        support for bus devices from the usb-serial subsystem

        * tools/device-manager/Const.py.in: add the new busses

        * tools/device-manager/Makefile.am: add the new icon

        * tools/device-manager/Representation.py: support the new serial
        port icon

        * tools/device-manager/hal-serial-port.png: picture of serial port



Index: osspec.c
===================================================================
RCS file: /cvs/hal/hal/hald/linux/osspec.c,v
retrieving revision 1.43
retrieving revision 1.44
diff -u -d -r1.43 -r1.44
--- osspec.c	16 Sep 2004 22:04:15 -0000	1.43
+++ osspec.c	20 Sep 2004 18:31:15 -0000	1.44
@@ -69,6 +69,7 @@
 extern ClassDeviceHandler ieee1394_class_handler;
 extern ClassDeviceHandler ieee1394_node_class_handler;
 extern ClassDeviceHandler ieee1394_host_class_handler;
+extern ClassDeviceHandler serial_class_handler;
 extern ClassDeviceHandler multimedia_class_handler;
 
 extern BusDeviceHandler pci_bus_handler;
@@ -79,6 +80,7 @@
 extern BusDeviceHandler scsi_bus_handler;
 extern BusDeviceHandler macio_bus_handler;
 extern BusDeviceHandler platform_bus_handler;
+extern BusDeviceHandler usb_serial_bus_handler;
 
 /*
  * NOTE!  Order can be significant here, especially at startup time
@@ -98,6 +100,7 @@
 	&ieee1394_host_class_handler,
 	&ieee1394_node_class_handler,
 	&ieee1394_class_handler,
+	&serial_class_handler,
 	&multimedia_class_handler,
 	NULL
 };
@@ -107,10 +110,11 @@
 	&usb_bus_handler,
 	&usbif_bus_handler,
 	&ide_host_bus_handler,
-        &ide_bus_handler,
+	&ide_bus_handler,
 	&macio_bus_handler,
 	&platform_bus_handler,
 	&scsi_bus_handler,
+	&usb_serial_bus_handler,
 	NULL
 };
 
@@ -1491,7 +1495,7 @@
 
 		if (msg.seqnum < last_hotplug_seqnum) {
 			/* yikes, this means were started during a hotplug */
-			HAL_WARNING (("Got SEQNUM=%d, but last_hotplug_seqnum=%llu", msg.seqnum, last_hotplug_seqnum));
+			HAL_WARNING (("Got SEQNUM=%llu, but last_hotplug_seqnum=%llu", msg.seqnum, last_hotplug_seqnum));
 
 			/* have to process immediately other we may deadlock due to
 			 * the hotplug semaphore */

--- NEW FILE: serial_class_device.c ---
/***************************************************************************
 * CVSID: $Id: serial_class_device.c,v 1.1 2004/09/20 18:31:15 kay Exp $
 *
 * serial port device class
 *
 * Copyright (C) 2004 Kay Sievers, <kay.sievers at vrfy.org>
 *
 * 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 "../logger.h"
#include "../device_store.h"
#include "../hald.h"

#include "class_device.h"
#include "common.h"

/**
 * @defgroup HalDaemonLinuxSerial Serial class
 * @ingroup HalDaemonLinux
 * @brief Serial class
 * @{
 */

static dbus_bool_t
serial_class_device_accept (ClassDeviceHandler *self,
			     const char *path,
			     struct sysfs_class_device *class_device)
{
	int serial_number;

	if (class_device->sysdevice == NULL)
		return FALSE;

	if (sscanf (class_device->name, "ttyUSB%d", &serial_number) == 1)
		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
 *  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
serial_class_pre_process (ClassDeviceHandler *self,
			  HalDevice *d,
			  const char *sysfs_path,
			  struct sysfs_class_device *class_device)
{
	hal_device_property_set_string (d, "info.product", "Serial Port");
	hal_device_property_set_string (d, "info.category", "serial");
	hal_device_property_set_string (d, "info.capabilities", "serial");
}

/** methods for device class */
ClassDeviceHandler serial_class_handler = {
	.init			= class_device_init,
	.shutdown		= class_device_shutdown,
	.tick			= class_device_tick,
	.accept			= serial_class_device_accept,
	.visit			= class_device_visit,
	.removed		= class_device_removed,
	.udev_event		= class_device_udev_event,
	.get_device_file_target = class_device_get_device_file_target,
	.pre_process		= serial_class_pre_process ,
	.post_merge		= class_device_post_merge,
	.got_udi		= class_device_got_udi,
	.compute_udi		= NULL,
	.in_gdl			= class_device_in_gdl,
	.sysfs_class_name	= "tty",
	.hal_class_name		= "serial",
	.require_device_file	= TRUE,
	.merge_or_add		= TRUE
};

/** @} */

Index: usb_bus_device.c
===================================================================
RCS file: /cvs/hal/hal/hald/linux/usb_bus_device.c,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -d -r1.13 -r1.14
--- usb_bus_device.c	19 Sep 2004 14:47:28 -0000	1.13
+++ usb_bus_device.c	20 Sep 2004 18:31:15 -0000	1.14
@@ -704,8 +704,7 @@
 
 			/* This is quite a hack */
 			port_number = 0;
-			for (i = len - 1; i > 0 && isdigit (bus_id[i]);
-			     --i) {
+			for (i = len - 1; i > 0 && isdigit (bus_id[i]); --i) {
 				digit = (int) (bus_id[i] - '0');
 				port_number *= 10;
 				port_number += digit;
@@ -944,7 +943,7 @@
 	usb_device_shutdown,       /**< shutdown function */
 	bus_device_tick,           /**< timer function */
 	usb_device_accept,         /**< accept function */
- 	bus_device_visit,          /**< visitor function */
+	bus_device_visit,          /**< visitor function */
 	bus_device_removed,        /**< device is removed */
 	usb_device_compute_udi,    /**< UDI computing function */
 	usb_device_pre_process,    /**< add more properties */

--- NEW FILE: usb_serial_bus_device.c ---
/***************************************************************************
 * CVSID: $Id: usb_serial_bus_device.c,v 1.1 2004/09/20 18:31:15 kay Exp $
 *
 * USB serial
 *
 * Copyright (C) 2004 Kay Sievers <kay.sievers at vrfy.org>
 *
 * 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 "../logger.h"
#include "../device_store.h"
#include "bus_device.h"
#include "common.h"

static char *
usb_serial_device_compute_udi (HalDevice *d, int append_num)
{
	const char *format;
	static char buf[256];

	if (append_num == -1)
		format = "%s_usb-serial";
	else
		format = "%s_usb-serial-%d";

	snprintf (buf, 255, format,
		  hal_device_property_get_string (d, "info.parent"), append_num);
	buf[255] = '\0';

	return buf;
}

static void
usb_serial_device_pre_process (BusDeviceHandler *self,
			       HalDevice *d,
			       const char *sysfs_path,
			       struct sysfs_device *device)
{
	/* a class/tty device is expected to overide this by merging into this device */
	hal_device_property_set_string (d, "info.product", "USB Serial Device");
}

/** Method specialisations */
BusDeviceHandler usb_serial_bus_handler = {
	.init		= bus_device_init,
	.shutdown	= bus_device_shutdown,
	.tick		= bus_device_tick,
	.accept		= bus_device_accept,
	.visit		= bus_device_visit,
	.removed	= bus_device_removed,
	.compute_udi	= usb_serial_device_compute_udi,
	.pre_process	= usb_serial_device_pre_process,
	.got_udi	= bus_device_got_udi,
	.in_gdl		= bus_device_in_gdl,
	.sysfs_bus_name	= "usb-serial",
	.hal_bus_name	= "usb-serial"
};

/** @} */




More information about the hal-commit mailing list