hal/hald/linux block_class_device.c, 1.15, 1.16 bus_device.c, 1.6, 1.7 class_device.c, 1.11, 1.12 common.c, 1.5, 1.6 common.h, 1.2, 1.3

Joe Shaw joe at pdx.freedesktop.org
Mon Apr 26 13:09:00 PDT 2004


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

Modified Files:
	block_class_device.c bus_device.c class_device.c common.c 
	common.h 
Log Message:
2004-04-26  David Zeuthen  <david at fubar.dk>

	* hald/device.c (hal_device_print): Print out to stderr instead of
	stdout.

	* hald/device_store.c (hal_device_store_print): Print out the
	contents of a HalDeviceStore.

	* hald/linux/common.c (rename_and_merge): Check to see if the UDI
	exists in the TDL and try again if it is.

2004-04-26  Joe Shaw  <joe at ximian.com>

	* hald/callout.c: Make pending callouts a hash table of lists, so
	we can execute all the callouts for the devices in order.
	(add_pending_callout, pop_pending_callout): New convenience
	functions.
	(wait_for_callout): If this is the last callout for a device, fire
	off the callouts_finished signal on the device.
	(hal_callout_device, hal_callout_capability,
	hal_callout_property): Use the new convenience functions, call
	process_callouts() in an idle function.

	* hald/device.c: Add a "callouts_finished" signal.

	* hald/hald.c (gdl_store_changed): Don't call hal_callout_device()
	here anymore... we call it in the backend before we get added to
	the GDL.

	* hald/hald_dbus.c (manager_device_exists,
	device_get_all_properties, device_get_property,
	device_get_property_type, device_set_property,
	device_add_capability, device_remove_property,
	device_property_exists, device_query_capability,
	agent_merge_properties, agent_device_matches): Search the TDL for
	the provided UDI if it's not found in the GDL.

	* hald/linux/block_class_device.c (detect_media): Instead of
	adding the device to the GDL immediately, connect to the
	callouts_finished signal and add the device then.  Call
	hal_callout_device() here, though.

	* hald/linux/bus_device.c (bus_device_got_parent): Ditto.

	* hald/linux/class_device.c (class_device_final): Ditto.

	* hald/linux/common.c (device_move_from_tdl_to_gdl): Remove the
	device from the TDL and add it to the GDL.  Remove the signal
	handler and unref the device.  Used as a callback from
	bus_device.c and class_device.c.

Index: block_class_device.c
===================================================================
RCS file: /cvs/hal/hal/hald/linux/block_class_device.c,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -d -r1.15 -r1.16
--- a/block_class_device.c	25 Apr 2004 17:24:44 -0000	1.15
+++ b/block_class_device.c	26 Apr 2004 20:08:58 -0000	1.16
@@ -53,6 +53,7 @@
 #include "../hald_dbus.h"
 #include "../logger.h"
 #include "../device_store.h"
+#include "../callout.h"
 #include "class_device.h"
 #include "common.h"
  
@@ -358,6 +359,13 @@
 	}			/* childs!=NULL */
 }
 
+static void
+add_to_gdl (HalDevice *device, gpointer user_data)
+{
+	hal_device_store_add (hald_get_gdl (), device);
+
+	g_signal_handlers_disconnect_by_func (device, add_to_gdl, user_data);
+}
 
 /** Check for media on a block device that is not a volume
  *
@@ -544,8 +552,9 @@
 
 
 			/* add new device */
-			hal_device_store_add (hald_get_gdl (), child);
-			g_object_unref (child);
+			g_signal_connect (child, "callouts_finished",
+					  G_CALLBACK (add_to_gdl), NULL);
+			hal_callout_device (child, TRUE);
 
 			/* GDL was modified */
 			return TRUE;

Index: bus_device.c
===================================================================
RCS file: /cvs/hal/hal/hald/linux/bus_device.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- a/bus_device.c	25 Apr 2004 17:24:44 -0000	1.6
+++ b/bus_device.c	26 Apr 2004 20:08:58 -0000	1.7
@@ -39,6 +39,7 @@
 #include <glib.h>
 
 #include "../logger.h"
+#include "../callout.h"
 #include "../device_store.h"
 #include "../hald.h"
 #include "common.h"
@@ -176,15 +177,24 @@
 	 */
 	new_udi = rename_and_merge (d, self->compute_udi, self->hal_bus_name);
 	if (new_udi != NULL) {
+		HalDevice *device_to_add;
+
 		new_d = hal_device_store_find (hald_get_gdl (), new_udi);
 
-		self->got_udi (self, new_d != NULL ? new_d : d, new_udi);
+		device_to_add = new_d != NULL ? new_d : d;
 
-		hal_device_store_add (hald_get_gdl (),
-				      new_d != NULL ? new_d : d);
+		self->got_udi (self, device_to_add, new_udi);
+
+		g_signal_connect (g_object_ref (device_to_add),
+				  "callouts_finished",
+				  G_CALLBACK (device_move_from_tdl_to_gdl),
+				  NULL);
+
+		hal_callout_device (device_to_add, TRUE);
+	} else {
+		hal_device_store_remove (hald_get_tdl (), d);
+		g_object_unref (d);
 	}
-	hal_device_store_remove (hald_get_tdl (), d);
-	g_object_unref (d);
 }
 
 /** This function is called when all device detection on startup is done

Index: class_device.c
===================================================================
RCS file: /cvs/hal/hal/hald/linux/class_device.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- a/class_device.c	25 Apr 2004 17:24:44 -0000	1.11
+++ b/class_device.c	26 Apr 2004 20:08:58 -0000	1.12
@@ -37,6 +37,7 @@
 #include <stdarg.h>
 #include <limits.h>
 
+#include "../callout.h"
 #include "../logger.h"
 #include "../device_store.h"
 #include "../hald.h"
@@ -424,16 +425,25 @@
 		 */
 		new_udi = rename_and_merge (d, self->compute_udi, self->hal_class_name);
 		if (new_udi != NULL) {
+			HalDevice *device_to_add;
+
 			new_d = hal_device_store_find (hald_get_gdl (),
 						       new_udi);
 
-			self->got_udi (self, new_d!=NULL ? new_d : d, new_udi);
+			device_to_add = new_d != NULL ? new_d : d;
 
-			hal_device_store_add (hald_get_gdl (),
-					      new_d != NULL ? new_d : d);
+			self->got_udi (self, device_to_add, new_udi);
+
+			g_signal_connect (g_object_ref (device_to_add),
+					  "callouts_finished",
+					  G_CALLBACK (device_move_from_tdl_to_gdl),
+					  NULL);
+
+			hal_callout_device (device_to_add, TRUE);
+		} else {
+			hal_device_store_remove (hald_get_tdl (), d);
+			g_object_unref (d);
 		}
-		hal_device_store_remove (hald_get_tdl (), d);
-		g_object_unref (d);
 	}
 }
 

Index: common.c
===================================================================
RCS file: /cvs/hal/hal/hald/linux/common.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- a/common.c	25 Apr 2004 17:24:44 -0000	1.5
+++ b/common.c	26 Apr 2004 20:08:58 -0000	1.6
@@ -407,6 +407,13 @@
 	 * because the device-list is (can be) persistent across invocations 
 	 * of hald.
 	 *
+	 * The name can also be taken already as the UDI computation methods
+	 * may not yield perfectly unique names; an interesting example is
+	 * multiple USB adapters - they show up as multiple PCI devices with
+	 * exactly the same characteristics expect slot location. And the
+	 * UDI computation method cannot depend on things like slot location
+	 * etc. 
+	 *
 	 * If it does exist, note that it's udi is computed from only the same 
 	 * information as our just computed udi.. So if we match, and it's
 	 * unplugged, it's the same device!
@@ -416,6 +423,17 @@
 	 *  for it to be practical)
 	 */
 	computed_d = hal_device_store_find (hald_get_gdl (), computed_udi);
+
+	/* Ok, see if it's in the TDL as we may process several identical
+	 * devices at the same time (see above example with multiple USB
+	 * adapters)
+	 */
+	if (computed_d == NULL) {
+
+		computed_d = hal_device_store_find (hald_get_tdl (), 
+						    computed_udi);
+	}
+
 	if (computed_d != NULL) {
 
 		if ((!hal_device_has_property
@@ -485,7 +503,7 @@
 		/* Device is not in list... */
 
 		/* assign the computed device name */
-		/*HAL_INFO ((" ##### computed_udi=%s", computed_udi));*/
+		HAL_INFO ((" ##### computed_udi=%s", computed_udi));
 		hal_device_set_udi (d, computed_udi);
 		hal_device_property_set_string (d, "info.udi", computed_udi);
 
@@ -807,4 +825,25 @@
 		sysfs_close_directory (dir);
 }
 
+/** Removes the device from the TDL and adds it to the GDL when all
+ *  all of the device's callouts have finished.  This is a gobject
+ *  signal callback.  NOTE!  The device must be reffed, since this
+ *  callback unrefs it, to ensure lifetime safety.
+ *
+ *  @param  device              The device being moved
+ *  @param  user_data           User data provided when connecting the signal
+ *
+ */
+void
+device_move_from_tdl_to_gdl (HalDevice *device, gpointer user_data)
+{
+	hal_device_store_remove (hald_get_tdl (), device);
+	hal_device_store_add (hald_get_gdl (), device);
+	g_signal_handlers_disconnect_by_func (device,
+					      device_move_from_tdl_to_gdl,
+					      user_data);
+	g_object_unref (device);
+}
+
+
 /** @} */

Index: common.h
===================================================================
RCS file: /cvs/hal/hal/hald/linux/common.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- a/common.h	25 Apr 2004 17:24:44 -0000	1.2
+++ b/common.h	26 Apr 2004 20:08:58 -0000	1.3
@@ -98,6 +98,9 @@
 
 extern char sysfs_mount_path[SYSFS_PATH_MAX];
 
+void device_move_from_tdl_to_gdl (HalDevice *device, gpointer user_data);
+
+
 /* @} */
 
 #endif				/* COMMON_H */





More information about the hal-commit mailing list