hal/hald/linux ieee1394_class_device.c, NONE, 1.1 ieee1394_host_class_device.c, NONE, 1.1 ieee1394_node_class_device.c, NONE, 1.1 block_class_device.c, 1.23, 1.24 bus_device.c, 1.9, 1.10 bus_device.h, 1.5, 1.6 class_device.c, 1.14, 1.15 class_device.h, 1.7, 1.8 net_class_device.c, 1.5, 1.6 osspec.c, 1.18, 1.19

Joe Shaw joe at pdx.freedesktop.org
Tue May 25 13:09:31 PDT 2004


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

Modified Files:
	block_class_device.c bus_device.c bus_device.h class_device.c 
	class_device.h net_class_device.c osspec.c 
Added Files:
	ieee1394_class_device.c ieee1394_host_class_device.c 
	ieee1394_node_class_device.c 
Log Message:
2004-05-25  Joe Shaw <joeshaw at novell.com>

	* hald/Makefile.am: Add the ieee1394 class devices.

	* hald/linux/block_class_device.c: Replace use of locally defined
	AsyncInfo with ClassAsyncData.

	* hald/linux/bus_device.c: Replace use of locally defined
	AsyncInfo with BusAsyncData.

	* hald/linux/class_device.c: Replace use of locally defined
	AsyncInfo with ClassAsyncData.
	(class_device_accept): Check here if the class device has a
	sysdevice and reject it if it doesn't.
	(class_device_visit): Don't check for it here.  If it is NULL, set
	merge_or_add to FALSE so that we don't try to merge it onto a fake
	device.  If the sysdevice is NULL, set the parent sysfs path to
	"(none)", which will match our fake parent device.
	(class_device_final): Take a third argument for merge_or_add and
	check it instead of the ClassDeviceHandler's default behavior.

	* hald/linux/ieee1394_class_device.c,
	hald/linux/ieee1394_host_class_device.c,
	hald/linux/ieee1394_node_class_device.c: New IEEE1394 class device
	implementation.  Seems to even work somewhat on some small subset
	of the world's computers.

	* hald/linux/net_class_device.c (net_class_pre_process): If there
	is an address, set the net.address property to it, regardless of
	what type of net device it is.
	(net_class_accept): Added.  Allows us to have net class devices
	without an associated sysdevice.  Only allow it if it's an
	ethernet device for now.
	(net_class_compute_udi): Added.  Needed in situations where the
	class device has no sysdevice, we need to generate a UDI since we
	aren't merging onto a parent device.

	* hald/linux/osspec.c: Reenable the ieee1394 class device
	handlers.
	(osspec_probe): Create a fake root device to be the parent for all
	of our sysdevice-less devices.  It's a virtual device, has the UDI
	"/org/freedesktop/Hal/devices/fakeroot", and the sysfs path device
	of "(none)".

	* tools/device-manager/Const.py.in (BUS_NAMES): Add "unknown" to
	the list of known bus names.
	

--- NEW FILE: ieee1394_class_device.c ---
/***************************************************************************
 * CVSID: $Id: ieee1394_class_device.c,v 1.1 2004/05/25 20:09:29 joe Exp $
 *
 * IEEE1394 class device
 *
 * 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 "../logger.h"
#include "../device_store.h"
#include "../hald.h"

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

static char *
ieee1394_class_compute_udi (HalDevice *d, int append_num)
{
	static int counter = 0;
	const char *format;
	static char buf[256];

	if (append_num == -1)
		format = "/org/freedesktop/Hal/devices/ieee1394_%d";
	else
		format = "/org/freedesktop/Hal/devices/ieee1394_%d-%d";

	snprintf (buf, 256, format, counter, append_num);

	return buf;
}

static void
ieee1394_class_pre_process (ClassDeviceHandler *self,
			    HalDevice *d,
			    const char *sysfs_path,
			    struct sysfs_class_device *class_device)
{
	struct sysfs_attribute *cur;
	char attr_name[SYSFS_NAME_LEN];
	int tmp;
	int model_id = -1;
	char *model_name = NULL;

	dlist_for_each_data (sysfs_get_device_attributes (class_device->sysdevice),
			     cur, struct sysfs_attribute) {
		int len, i;

		if (sysfs_get_name_from_path (cur->path,
					      attr_name,
					      SYSFS_NAME_LEN) != 0)
			continue;

		/* strip whitespace */
		len = strlen (cur->value);
		for (i = len - 1; i >= 0 && isspace (cur->value[i]); --i)
			cur->value[i] = '\0';

		if (strcmp (attr_name, "model_id") == 0) {
			model_id = parse_hex (cur->value);
		} else if (strcmp (attr_name, "model_name_kv") == 0) {
			model_name = cur->value;
		} else if (strcmp (attr_name, "specifier_id") == 0) {
			tmp = parse_hex (cur->value);

			hal_device_property_set_int (d,
						     "ieee1394.specifier_id",
						     tmp);
		}
	}

	if (model_name) {
		hal_device_property_set_string (d, "ieee1394.product",
						model_name);
		hal_device_property_set_string (d, "info.product", model_name);
	} else if (model_id != -1) {
		char numeric_name[32];

		snprintf (numeric_name, sizeof (numeric_name),
			  "Unknown (0x%04x)", model_id);

		hal_device_property_set_string (d, "ieee1394.product",
						numeric_name);
		hal_device_property_set_string (d, "info.product",
						numeric_name);
	}
}
		  
/** Method specialisations for ieee1394 device class */
ClassDeviceHandler ieee1394_class_handler = {
	class_device_init,                  /**< init function */
	class_device_shutdown,              /**< shutdown function */
	class_device_tick,                  /**< timer function */
	class_device_accept,                /**< accept 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 */
	ieee1394_class_pre_process,         /**< add more properties */
	class_device_post_merge,            /**< post merge function */
	class_device_got_udi,               /**< got UDI */
	ieee1394_class_compute_udi,         /**< No UDI computation */
	"ieee1394",                         /**< sysfs class name */
	"ieee1394",                         /**< hal class name */
	FALSE,                              /**< don't require device file */
	FALSE                               /**< add as child to parent */
};

--- NEW FILE: ieee1394_host_class_device.c ---
/***************************************************************************
 * CVSID: $Id: ieee1394_host_class_device.c,v 1.1 2004/05/25 20:09:29 joe Exp $
 *
 * IEEE1394 host class device
 *
 * 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 "../logger.h"
#include "../device_store.h"
#include "../hald.h"

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

static char *
ieee1394_host_class_compute_udi (HalDevice *d, int append_num)
{
	static int counter = 0;
	const char *format;
	static char buf[256];

	if (append_num == -1)
		format = "/org/freedesktop/Hal/devices/ieee1394_host_%d";
	else
		format = "/org/freedesktop/Hal/devices/ieee1394_host_%d-%d";

	snprintf (buf, 256, format, counter, append_num);

	return buf;
}

static void
ieee1394_host_class_pre_process (ClassDeviceHandler *self,
				 HalDevice *d,
				 const char *sysfs_path,
				 struct sysfs_class_device *class_device)
{
	struct sysfs_attribute *cur;
	char attr_name[SYSFS_NAME_LEN];
	int tmp;

	dlist_for_each_data (sysfs_get_device_attributes (class_device->sysdevice),
			     cur, struct sysfs_attribute) {
		int len, i;

		if (sysfs_get_name_from_path (cur->path,
					      attr_name,
					      SYSFS_NAME_LEN) != 0)
			continue;

		/* strip whitespace */
		len = strlen (cur->value);
		for (i = len - 1; i >= 0 && isspace (cur->value[i]); --i)
			cur->value[i] = '\0';

		if (strcmp (attr_name, "is_busmgr") == 0) {
			tmp = parse_dec (cur->value);

			hal_device_property_set_bool (d, "ieee1394.is_busmgr",
						      tmp);
		} else if (strcmp (attr_name, "is_irm") == 0) {
			tmp = parse_dec (cur->value);

			hal_device_property_set_bool (d, "ieee1394.is_irn",
						      tmp);
		} else if (strcmp (attr_name, "is_root") == 0) {
			tmp = parse_dec (cur->value);

			hal_device_property_set_bool (d, "ieee1394.is_root",
						      tmp);
		} else if (strcmp (attr_name, "node_count") == 0) {
			tmp = parse_dec (cur->value);
			
			hal_device_property_set_int (d, "ieee1394.node_count",
						     tmp);
		} else if (strcmp (attr_name, "nodes_active") == 0) {
			tmp = parse_dec (cur->value);

			hal_device_property_set_int (d, "ieee1394.nodes_active",
						     tmp);
		}
	}

	hal_device_property_set_bool (d, "info.virtual", TRUE);
}
		  
/** Method specialisations for ieee1394_host device class */
ClassDeviceHandler ieee1394_host_class_handler = {
	class_device_init,                  /**< init function */
	class_device_shutdown,              /**< shutdown function */
	class_device_tick,                  /**< timer function */
	class_device_accept,                /**< accept 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 */
	ieee1394_host_class_pre_process,    /**< add more properties */
	class_device_post_merge,            /**< post merge function */
	class_device_got_udi,               /**< got UDI */
	ieee1394_host_class_compute_udi,    /**< No UDI computation */
	"ieee1394_host",                    /**< sysfs class name */
	"ieee1394_host",                    /**< hal class name */
	FALSE,                              /**< don't require device file */
	FALSE                               /**< add as child to parent */
};

--- NEW FILE: ieee1394_node_class_device.c ---
/***************************************************************************
 * CVSID: $Id: ieee1394_node_class_device.c,v 1.1 2004/05/25 20:09:29 joe Exp $
 *
 * IEEE1394 node class device
 *
 * 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 "../logger.h"
#include "../device_store.h"
#include "../hald.h"

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

static char *
ieee1394_node_class_compute_udi (HalDevice *d, int append_num)
{
	static int counter = 0;
	const char *format;
	static char buf[256];

	if (append_num == -1)
		format = "/org/freedesktop/Hal/devices/ieee1394_node_%d";
	else
		format = "/org/freedesktop/Hal/devices/ieee1394_node_%d-%d";

	snprintf (buf, 256, format, counter, append_num);

	return buf;
}

static void
ieee1394_node_class_pre_process (ClassDeviceHandler *self,
				 HalDevice *d,
				 const char *sysfs_path,
				 struct sysfs_class_device *class_device)
{
	struct sysfs_attribute *cur;
	char attr_name[SYSFS_NAME_LEN];
	int tmp;
	const char *vendor_name = NULL;
	int vendor_id;

	dlist_for_each_data (sysfs_get_device_attributes (class_device->sysdevice),
			     cur, struct sysfs_attribute) {
		int len, i;

		if (sysfs_get_name_from_path (cur->path,
					      attr_name,
					      SYSFS_NAME_LEN) != 0)
			continue;

		/* strip whitespace */
		len = strlen (cur->value);
		for (i = len - 1; i >= 0 && isspace (cur->value[i]); --i)
			cur->value[i] = '\0';

		if (strcmp (attr_name, "capabilities") == 0) {
			tmp = parse_hex (cur->value);

			hal_device_property_set_int (d,
						     "ieee1394.capabilities",
						     tmp);
		} else if (strcmp (attr_name, "guid") == 0) {
			tmp = parse_hex (cur->value);

			hal_device_property_set_int (d, "ieee1394.guid", tmp);
		} else if (strcmp (attr_name, "nodeid") == 0) {
			tmp = parse_hex (cur->value);

			hal_device_property_set_int (d, "ieee1394.nodeid",
						     tmp);
		} else if (strcmp (attr_name, "vendor_id") == 0) {
			vendor_id = parse_hex (cur->value);
		} else if (strcmp (attr_name, "vendor_name_kv") == 0) {
			vendor_name = cur->value;
		}
	}

	hal_device_property_set_int (d, "ieee1394.vendor_id", vendor_id);

	if (vendor_name) {
		hal_device_property_set_string (d, "ieee1394.vendor",
						vendor_name);
		hal_device_property_set_string (d, "info.vendor", vendor_name);
	} else {
		char numeric_name[32];

		snprintf (numeric_name, sizeof (numeric_name),
			  "Unknown (0x%04x)", vendor_id);

		hal_device_property_set_string (d, "ieee1394.vendor",
						numeric_name);
		hal_device_property_set_string (d, "info.vendor",
						numeric_name);
	}

	hal_device_property_set_bool (d, "info.virtual", TRUE);
}
		  
/** Method specialisations for ieee1394_node device class */
ClassDeviceHandler ieee1394_node_class_handler = {
	class_device_init,                  /**< init function */
	class_device_shutdown,              /**< shutdown function */
	class_device_tick,                  /**< timer function */
	class_device_accept,                /**< accept 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 */
	ieee1394_node_class_pre_process,    /**< add more properties */
	class_device_post_merge,            /**< post merge function */
	class_device_got_udi,               /**< got UDI */
	ieee1394_node_class_compute_udi,    /**< No UDI computation */
	"ieee1394_node",                    /**< sysfs class name */
	"ieee1394_node",                    /**< hal class name */
	FALSE,                              /**< don't require device file */
	FALSE                               /**< add as child to parent */
};

Index: block_class_device.c
===================================================================
RCS file: /cvs/hal/hal/hald/linux/block_class_device.c,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -d -r1.23 -r1.24
--- a/block_class_device.c	25 May 2004 17:15:41 -0000	1.23
+++ b/block_class_device.c	25 May 2004 20:09:29 -0000	1.24
@@ -71,11 +71,6 @@
 
 static void detect_fs (HalDevice *d);
 
-typedef struct {
-	HalDevice *device;
-	ClassDeviceHandler *handler;
-} AsyncInfo;
-
 static void
 block_class_visit (ClassDeviceHandler *self,
 		   const char *path,
@@ -83,7 +78,7 @@
 {
 	HalDevice *d;
 	char *parent_sysfs_path;
-	AsyncInfo *ai;
+	ClassAsyncData *cad;
 
 	/* only care about given sysfs class name */
 	if (strcmp (class_device->classname, "block") != 0)
@@ -128,15 +123,15 @@
 
 	/* Now find the parent device; this happens asynchronously as it
 	 * might be added later. */
-	ai = g_new0 (AsyncInfo, 1);
-	ai->device = d;
-	ai->handler = self;
+	cad = g_new0 (ClassAsyncData, 1);
+	cad->device = d;
+	cad->handler = self;
 
 	hal_device_store_match_key_value_string_async (
 		hald_get_gdl (),
 		"linux.sysfs_path_device",
 		parent_sysfs_path,
-		class_device_got_parent_device, ai,
+		class_device_got_parent_device, cad,
 		HAL_LINUX_HOTPLUG_TIMEOUT);
 }
 

Index: bus_device.c
===================================================================
RCS file: /cvs/hal/hal/hald/linux/bus_device.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- a/bus_device.c	1 May 2004 19:29:17 -0000	1.9
+++ b/bus_device.c	25 May 2004 20:09:29 -0000	1.10
@@ -52,11 +52,6 @@
  * @{
  */
 
-typedef struct {
-	HalDevice *device;
-	BusDeviceHandler *handler;
-} AsyncInfo;
-
 /* fwd decl */
 static void bus_device_got_parent (HalDeviceStore *store, HalDevice *parent,
 				   gpointer user_data);
@@ -89,7 +84,7 @@
 bus_device_visit (BusDeviceHandler *self, const char *path, 
 		  struct sysfs_device *device)
 {
-	AsyncInfo *ai;
+	BusAsyncData *bad;
 	HalDevice *d;
 	char *parent_sysfs_path;
 	char buf[256];
@@ -110,15 +105,15 @@
 
 	parent_sysfs_path = get_parent_sysfs_path (path);
 
-	ai = g_new0 (AsyncInfo, 1);
-	ai->device = d;
-	ai->handler = self;
+	bad = g_new0 (BusAsyncData, 1);
+	bad->device = d;
+	bad->handler = self;
 
 	if (!got_parent(path)) {
 		/* no need to find parent; we have none; just add directly 
 		 * with parent set to NULL 
 		 */
-		bus_device_got_parent (hald_get_gdl(), NULL, ai);
+		bus_device_got_parent (hald_get_gdl(), NULL, bad);
 	} else {
 		/* Find parent; this happens asynchronously as our parent might
 		 * be added later. If we are probing this can't happen so the
@@ -128,7 +123,7 @@
 			hald_get_gdl (),
 			"linux.sysfs_path_device",
 			parent_sysfs_path,
-			bus_device_got_parent, ai,
+			bus_device_got_parent, bad,
 			HAL_LINUX_HOTPLUG_TIMEOUT);
 	}
 
@@ -149,12 +144,12 @@
 	const char *sysfs_path = NULL;
 	char *new_udi = NULL;
 	HalDevice *new_d = NULL;
-	AsyncInfo *ai = (AsyncInfo*) user_data;
-	HalDevice *d = (HalDevice *) ai->device;
-	BusDeviceHandler *self = (BusDeviceHandler *) ai->handler;
+	BusAsyncData *bad = (BusAsyncData*) user_data;
+	HalDevice *d = (HalDevice *) bad->device;
+	BusDeviceHandler *self = (BusDeviceHandler *) bad->handler;
 	struct sysfs_device *device;
 
-	g_free (ai);
+	g_free (bad);
 
 	/* set parent, if any */
 	if (parent != NULL) {

Index: bus_device.h
===================================================================
RCS file: /cvs/hal/hal/hald/linux/bus_device.h,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- a/bus_device.h	30 Apr 2004 20:59:08 -0000	1.5
+++ b/bus_device.h	25 May 2004 20:09:29 -0000	1.6
@@ -174,4 +174,11 @@
 			 HalDevice *d,
 			 const char *udi);
 
+/* Convenience structure for passing around multiple pieces of data to
+   the got_parent_device() functions */
+typedef struct {
+	HalDevice *device;
+	BusDeviceHandler *handler;
+} BusAsyncData;
+
 #endif /* BUS_DEVICE_H */

Index: class_device.c
===================================================================
RCS file: /cvs/hal/hal/hald/linux/class_device.c,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -d -r1.14 -r1.15
--- a/class_device.c	1 May 2004 19:48:15 -0000	1.14
+++ b/class_device.c	25 May 2004 20:09:29 -0000	1.15
@@ -52,17 +52,13 @@
  * @{
  */
 
-typedef struct {
-	HalDevice *device;
-	ClassDeviceHandler *handler;
-} AsyncInfo;
-
 static void
 class_device_got_device_file (HalDevice *d, gpointer user_data, 
 			      gboolean prop_exists);
 
 static void
-class_device_final (ClassDeviceHandler* self, HalDevice *d);
+class_device_final (ClassDeviceHandler* self, HalDevice *d,
+		    gboolean merge_or_add);
 
 
 /** Generic accept function that accepts the device if and only if
@@ -81,6 +77,10 @@
 	/*HAL_INFO (("path = %s, classname = %s", 
 	  path, self->sysfs_class_name));*/
 
+	/* Don't care if there's no sysdevice */
+	if (class_device->sysdevice == NULL)
+		return FALSE;
+
 	/* only care about given sysfs class name */
 	if (strcmp (class_device->classname, self->sysfs_class_name) == 0) {
 		return TRUE;
@@ -106,10 +106,12 @@
 	HalDevice *d;
 	char dev_file[SYSFS_PATH_MAX];
 	char dev_file_prop_name[SYSFS_PATH_MAX];
+	gboolean merge_or_add;
 
-	/* don't care if there is no sysdevice */
 	if (class_device->sysdevice == NULL) {
-		return;
+		merge_or_add = FALSE;
+	} else {
+		merge_or_add = self->merge_or_add;
 	}
 
 	/* Construct a new device and add to temporary device list */
@@ -117,12 +119,26 @@
 	hal_device_store_add (hald_get_tdl (), d);
 
 	/* Need some properties if we are to appear in the tree on our own */
-	if (!self->merge_or_add) {
-		hal_device_property_set_string (d, "info.bus", 
-						self->hal_class_name);
+	if (!merge_or_add) {
+	        /* 
+		 * Kind of a hack... we only want to set the bus if
+		 * our handler's merge_or_add is normally false.  Otherwise
+		 * we want the bus to just be "unknown"
+		 */
+	        if (!self->merge_or_add) {
+		        hal_device_property_set_string (d, "info.bus", 
+							self->hal_class_name);
+		} else {
+		        hal_device_property_set_string (d, "info.bus",
+							"unknown");
+		}
+
 		hal_device_property_set_string (d, "linux.sysfs_path", path);
-		hal_device_property_set_string (d, "linux.sysfs_path_device", 
-					class_device->sysdevice->path);
+
+		if (class_device->sysdevice != NULL) {
+			hal_device_property_set_string (d, "linux.sysfs_path_device", 
+							class_device->sysdevice->path);
+		}
 	} 
 
 	/* Temporary property used for _udev_event() */
@@ -157,34 +173,40 @@
 
 	/* Now find the physical device; this happens asynchronously as it
 	 * might be added later. */
-	if (self->merge_or_add) {
-		AsyncInfo *ai = g_new0 (AsyncInfo, 1);
-		ai->device = d;
-		ai->handler = self;
+	if (merge_or_add) {
+		ClassAsyncData *cad = g_new0 (ClassAsyncData, 1);
+		cad->device = d;
+		cad->handler = self;
+		cad->merge_or_add = merge_or_add;
 
 		/* find the sysdevice */
 		hal_device_store_match_key_value_string_async (
 			hald_get_gdl (),
 			"linux.sysfs_path_device",
 			class_device->sysdevice->path,
-			class_device_got_sysdevice, ai,
+			class_device_got_sysdevice, cad,
 			HAL_LINUX_HOTPLUG_TIMEOUT);
 	} else {
 		char *parent_sysfs_path;
-		AsyncInfo *ai = g_new0 (AsyncInfo, 1);
+		ClassAsyncData *cad = g_new0 (ClassAsyncData, 1);
 
-		parent_sysfs_path = 
-			get_parent_sysfs_path (class_device->sysdevice->path);
+		if (class_device->sysdevice != NULL) {
+			parent_sysfs_path = 
+				get_parent_sysfs_path (class_device->sysdevice->path);
+		} else {
+			parent_sysfs_path = "(none)";
+		}
 
-		ai->device = d;
-		ai->handler = self;
+		cad->device = d;
+		cad->handler = self;
+		cad->merge_or_add = merge_or_add;
 
 		/* find the parent */
 		hal_device_store_match_key_value_string_async (
 			hald_get_gdl (),
 			"linux.sysfs_path_device",
 			parent_sysfs_path,
-			class_device_got_parent_device, ai,
+			class_device_got_parent_device, cad,
 			HAL_LINUX_HOTPLUG_TIMEOUT);
 	}
 }
@@ -246,11 +268,10 @@
 class_device_got_parent_device (HalDeviceStore *store, HalDevice *parent, 
 				gpointer user_data)
 {
-	AsyncInfo *ai = user_data;
-	HalDevice *d = (HalDevice *) ai->device;
-	ClassDeviceHandler *self = ai->handler;
-
-	g_free (ai);
+	ClassAsyncData *cad = user_data;
+	HalDevice *d = (HalDevice *) cad->device;
+	ClassDeviceHandler *self = cad->handler;
+	gboolean merge_or_add = cad->merge_or_add;
 
 	if (parent == NULL) {
 		HAL_WARNING (("No parent for class device at sysfs path %s",
@@ -273,10 +294,12 @@
 		hal_device_async_wait_property (
 			d, target_dev, 
 			class_device_got_device_file,
-			(gpointer) self,
+			(gpointer) cad,
 			HAL_LINUX_HOTPLUG_TIMEOUT);
 	} else {
-		class_device_final (self, d);
+		class_device_final (self, d, merge_or_add);
+
+		g_free (cad);
 	}
 }
 
@@ -294,9 +317,10 @@
 			    HalDevice *sysdevice, 
 			    gpointer user_data)
 {
-	AsyncInfo *ai = user_data;
-	HalDevice *d = (HalDevice *) ai->device;
-	ClassDeviceHandler *self = ai->handler;
+	ClassAsyncData *cad = user_data;
+	HalDevice *d = (HalDevice *) cad->device;
+	ClassDeviceHandler *self = cad->handler;
+	gboolean merge_or_add = cad->merge_or_add;
 
 	HAL_INFO (("Entering d=0x%0x, sysdevice=0x%0x!", d, sysdevice));
 
@@ -337,10 +361,12 @@
 		hal_device_async_wait_property (
 			d, target_dev, 
 			class_device_got_device_file,
-			(gpointer) self,
+			(gpointer) cad,
 			HAL_LINUX_HOTPLUG_TIMEOUT);
 	} else {
-		class_device_final (self, d);
+		class_device_final (self, d, merge_or_add);
+		
+		g_free (cad);
 	}
 }
 
@@ -348,10 +374,14 @@
 class_device_got_device_file (HalDevice *d, gpointer user_data, 
 			      gboolean prop_exists)
 {
-	ClassDeviceHandler *self = (ClassDeviceHandler *) user_data;
+	ClassAsyncData *cad = (ClassAsyncData *) user_data;
+	ClassDeviceHandler *self = cad->handler;
+	gboolean merge_or_add = cad->merge_or_add;
 
 	/*HAL_INFO (("entering"));*/
 
+	g_free (cad);
+
 	if (!prop_exists) {
 		HAL_WARNING (("Never got device file for class device at %s", 
 			      hal_device_property_get_string (d, ".udev.sysfs_path")));
@@ -360,11 +390,12 @@
 		return;
 	}
 
-	class_device_final (self, d);
+	class_device_final (self, d, merge_or_add);
 }
 
 static void
-class_device_final (ClassDeviceHandler* self, HalDevice *d)
+class_device_final (ClassDeviceHandler* self, HalDevice *d,
+		    gboolean merge_or_add)
 {
 	const char *sysfs_path = NULL;
 	struct sysfs_class_device *class_device;
@@ -380,7 +411,7 @@
 	self->pre_process (self, d, sysfs_path, class_device);
 	sysfs_close_class_device (class_device);
 
-	if (self->merge_or_add) {
+	if (merge_or_add) {
 		const char *sysdevice_udi;
 		HalDevice *sysdevice;
 

Index: class_device.h
===================================================================
RCS file: /cvs/hal/hal/hald/linux/class_device.h,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- a/class_device.h	30 Apr 2004 20:59:08 -0000	1.7
+++ b/class_device.h	25 May 2004 20:09:29 -0000	1.8
@@ -276,4 +276,12 @@
 				     gpointer user_data);
 
 
+/* Convenience structure for passing around multiple pieces of data
+   to the got_parent_device() functions */
+typedef struct {
+	HalDevice *device;
+	ClassDeviceHandler *handler;
+	gboolean merge_or_add;
+} ClassAsyncData;
+
 #endif /* CLASS_DEVICE_H */

Index: net_class_device.c
===================================================================
RCS file: /cvs/hal/hal/hald/linux/net_class_device.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- a/net_class_device.c	13 May 2004 17:27:16 -0000	1.5
+++ b/net_class_device.c	25 May 2004 20:09:29 -0000	1.6
@@ -431,8 +431,10 @@
 
 	attr = sysfs_get_classdev_attr (class_device, "address");
 
-	if (attr != NULL)
+	if (attr != NULL) {
 		address = g_strstrip (g_strdup (attr->value));
+		hal_device_property_set_string (d, "net.address", address);
+	}
 
 	attr = sysfs_get_classdev_attr (class_device, "type");
 
@@ -477,6 +479,36 @@
 	hal_device_property_set_string (d, "info.category", "net.ethernet");
 }
 
+static dbus_bool_t
+net_class_accept (ClassDeviceHandler *self, const char *path,
+		  struct sysfs_class_device *class_device)
+{
+	struct sysfs_attribute *attr;
+
+	/* If the class name isn't 'net', deny it. */
+	if (strcmp (class_device->classname, self->sysfs_class_name) != 0)
+		return FALSE;
+
+	/* If we have a sysdevice, allow it. */
+	if (class_device->sysdevice != NULL)
+		return TRUE;
+
+	/*
+	 * Get the "type" attribute from sysfs to see if this is a
+	 * network device we're interested in.
+	 */
+	attr = sysfs_get_classdev_attr (class_device, "type");
+
+	if (attr == NULL || attr->value == NULL)
+		return FALSE;
+
+	/* 1 is the type for ethernet (incl. wireless) devices */
+	if (attr->value[0] == '1')
+		return TRUE;
+	else
+		return FALSE;
+}
+
 static void
 net_class_post_merge (ClassDeviceHandler *self, HalDevice *d)
 {
@@ -484,12 +516,32 @@
 		link_detection_init (d);
 }
 
+static char *
+net_class_compute_udi (HalDevice *d, int append_num)
+{
+	const char *format;
+	static char buf[256];
+
+	hal_device_print (d);
+
+	if (append_num == -1)
+		format = "/org/freedesktop/Hal/devices/net-%s";
+	else
+		format = "/org/freedesktop/Hal/devices_net-%s-%d";
+
+	snprintf (buf, 256, format,
+		  hal_device_property_get_string (d, "net.address"),
+		  append_num);
+
+	return buf;
+}
+
 /** Method specialisations for input device class */
 ClassDeviceHandler net_class_handler = {
 	class_device_init,                  /**< init function */
 	class_device_shutdown,              /**< shutdown function */
 	class_device_tick,                  /**< timer function */
-	class_device_accept,                /**< accept function */
+	net_class_accept,                   /**< accept function */
 	class_device_visit,                 /**< visitor function */
 	class_device_removed,               /**< class device is removed */
 	class_device_udev_event,            /**< handle udev event */
@@ -497,7 +549,7 @@
 	net_class_pre_process,              /**< add more properties */
 	net_class_post_merge,               /**< post merge function */
 	class_device_got_udi,               /**< got UDI */
-	NULL,                               /**< No UDI computation */
+	net_class_compute_udi,              /**< compute UDI */
 	"net",                              /**< sysfs class name */
 	"net",                              /**< hal class name */
 	FALSE,                              /**< require device file */

Index: osspec.c
===================================================================
RCS file: /cvs/hal/hal/hald/linux/osspec.c,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -d -r1.18 -r1.19
--- a/osspec.c	30 Apr 2004 20:59:08 -0000	1.18
+++ b/osspec.c	25 May 2004 20:09:29 -0000	1.19
@@ -58,11 +58,9 @@
 extern ClassDeviceHandler scsi_generic_class_handler;
 extern ClassDeviceHandler block_class_handler;
 extern ClassDeviceHandler pcmcia_socket_class_handler;
-
-/*
-extern ClassDeviceHandler ieee1394_host_class_handler;
+extern ClassDeviceHandler ieee1394_class_handler;
 extern ClassDeviceHandler ieee1394_node_class_handler;
-*/
+extern ClassDeviceHandler ieee1394_host_class_handler;
 
 extern BusDeviceHandler pci_bus_handler;
 extern BusDeviceHandler usb_bus_handler;
@@ -86,8 +84,9 @@
 	&scsi_generic_class_handler,
 	&block_class_handler,
 	&pcmcia_socket_class_handler,
-	/*&ieee1394_host_class_handler,
-	  &ieee1394_node_class_handler,*/
+	&ieee1394_host_class_handler,
+	&ieee1394_node_class_handler,
+	&ieee1394_class_handler,
 	NULL
 };
 
@@ -370,10 +369,26 @@
 void
 osspec_probe ()
 {
+	HalDevice *fakeroot;
 	int i;
 
 	hald_is_initialising = TRUE;
 
+	/*
+	 * Create the "fakeroot" device for all the devices which don't
+	 * have sysdevices in sysfs.
+	 */
+	fakeroot = hal_device_new ();
+	hal_device_property_set_string (fakeroot, "info.bus", "unknown");
+	hal_device_property_set_string (fakeroot,
+					"linux.sysfs_path_device",
+					"(none)");
+	hal_device_property_set_string (fakeroot, "info.product",
+					"City of Lost Devices");
+	hal_device_property_set_bool (fakeroot, "info.virtual", TRUE);
+	hal_device_set_udi (fakeroot, "/org/freedesktop/Hal/devices/fakeroot");
+	hal_device_store_add (hald_get_gdl (), fakeroot);
+
 	/** @todo When the kernel has all devices in /sys/devices
 	 *        under either /sys/bus or /sys/class then we can
 	 *        have code like this





More information about the hal-commit mailing list