hal/hald/linux2 classdev.c,1.1,1.2

David Zeuthen david at freedesktop.org
Wed Jan 19 14:26:49 PST 2005


Update of /cvs/hal/hal/hald/linux2
In directory gabe:/tmp/cvs-serv2403/hald/linux2

Modified Files:
	classdev.c 
Log Message:
2005-01-19  David Zeuthen  <davidz at redhat.com>

	Some more refactoring... You want to redo 'make install' to
	get h-d-m working after this...

	* hald/linux2/classdev.c:
	(input_add): Don't set info.bus as it doesn't really make sense
	since it is a class device
	(input_post_probing): New function
	(input_compute_udi): New function
	(bluetooth_add): New function
	(bluetooth_compute_udi): New function
	(add_classdev_after_probing): New function
	(add_classdev_probing_helper_done): New function
	(hotplug_event_begin_add_classdev): Create and use a framework
	where we don't have to think about asynchronous issues per
	logical device class.
	(hotplug_event_begin_remove_classdev): -do-
	(input_helper_done): Deleted due to new framework

	* tools/device-manager/DeviceManager.py: Do not assume that
	info.bus is available

	* tools/device-manager/Representation.py: Do not assume that
	info.bus is available



Index: classdev.c
===================================================================
RCS file: /cvs/hal/hal/hald/linux2/classdev.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- classdev.c	18 Jan 2005 19:48:13 -0000	1.1
+++ classdev.c	19 Jan 2005 22:26:47 -0000	1.2
@@ -56,118 +56,271 @@
 #include "hotplug.h"
 #include "classdev.h"
 
+/*--------------------------------------------------------------------------------------------------------------*/
 
-static void 
-input_helper_done(HalDevice *d, gboolean timed_out, gint return_code, gpointer data1, gpointer data2)
+static HalDevice *
+input_add (const gchar *sysfs_path, const gchar *device_file, HalDevice *physdev)
 {
-	gchar udi[256];
-	void *end_token = (void *) data1;
-
-	HAL_INFO (("entering; timed_out=%d, return_code=%d", timed_out, return_code));
+	HalDevice *d;
 
-	/* Discard device if probing reports failure */
-	if (return_code != 0) {
-		hal_device_store_remove (hald_get_tdl (), d);
-		goto out;
+	d = hal_device_new ();
+	hal_device_property_set_string (d, "linux.sysfs_path_device", sysfs_path);
+	if (physdev != NULL) {
+		hal_device_property_set_string (d, "input.physical_device", physdev->udi);
+		hal_device_property_set_string (d, "info.parent", physdev->udi);
+	} else {
+		hal_device_property_set_string (d, "info.parent", "/org/freedesktop/Hal/devices/computer");
 	}
+	hal_device_property_set_string (d, "info.category", "input");
+	hal_device_add_capability (d, "input");
+
+	hal_device_property_set_string (d, "input.device", device_file);
+
+	return d;
+}
+
+static gboolean
+input_post_probing (HalDevice *d)
+{
+	return TRUE;
+}
+
+static gboolean
+input_compute_udi (HalDevice *d)
+{
+	gchar udi[256];
 
-	/* Merge properties from .fdi files */
-	di_search_and_merge (d);
-	
-	/* TODO: Run callouts */
-	
-	/* Compute UDI */
 	hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi),
 			      "%s_logicaldev_input",
 			      hal_device_property_get_string (d, "info.parent"));
 	hal_device_set_udi (d, udi);
 	hal_device_property_set_string (d, "info.udi", udi);
-	
-	/* Move from temporary to global device store */
-	hal_device_store_remove (hald_get_tdl (), d);
-	hal_device_store_add (hald_get_gdl (), d);
-
-	/* TODO: adjust capabilities on physdev */
 
-out:
-	hotplug_event_end (end_token);
+	return TRUE;
 }
 
+/*--------------------------------------------------------------------------------------------------------------*/
 
-static gboolean
-input_add (const gchar *sysfs_path, const gchar *device_file, HalDevice *physdev, void *end_token)
+static HalDevice *
+bluetooth_add (const gchar *sysfs_path, const gchar *device_file, HalDevice *physdev)
 {
 	HalDevice *d;
 
+	d = NULL;
+
+	if (physdev == NULL) {
+		goto out;
+	}
+
 	d = hal_device_new ();
 	hal_device_property_set_string (d, "linux.sysfs_path_device", sysfs_path);
-	if (physdev != NULL) {
-		hal_device_property_set_string (d, "input.physical_device", physdev->udi);
-		hal_device_property_set_string (d, "info.parent", physdev->udi);
-	} else {
-		hal_device_property_set_string (d, "info.parent", "/org/freedesktop/Hal/devices/computer");
-	}
-	hal_device_property_set_string (d, "info.category", "input");
-	hal_device_add_capability (d, "input");
-	hal_device_property_set_string (d, "info.bus", "unknown");
+	hal_device_property_set_string (d, "info.parent", physdev->udi);
 
-	hal_device_property_set_string (d, "input.device", device_file);
+	hal_device_property_set_string (d, "info.category", "bluetooth_hci");
+	hal_device_add_capability (d, "bluetooth_hci");
 
-	/* Add to temporary device store */
-	hal_device_store_add (hald_get_tdl (), d);
+	hal_device_property_set_string (d, "bluetooth_hci.physical_device", physdev->udi);
+	hal_util_set_string_from_file (d, "bluetooth_hci.interface_name", sysfs_path, "name");
 
-	/* probe the actual device node */
-	if (!helper_invoke ("hald-probe-input", d, (gpointer) end_token, NULL, input_helper_done, HAL_HELPER_TIMEOUT)) {
-		hal_device_store_remove (hald_get_tdl (), d);
-		goto out;
+out:
+	return d;
+}
+
+static gboolean
+bluetooth_compute_udi (HalDevice *d)
+{
+	gchar udi[256];
+
+	hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi),
+			      "%s_bluetooth_hci",
+			      hal_device_property_get_string (d, "info.parent"));
+	hal_device_set_udi (d, udi);
+	hal_device_property_set_string (d, "info.udi", udi);
+	return TRUE;
+}
+
+/*--------------------------------------------------------------------------------------------------------------*/
+
+static gboolean
+classdev_remove (HalDevice *d)
+{
+	if (!hal_device_store_remove (hald_get_gdl (), d)) {
+		HAL_WARNING (("Error removing device"));
 	}
 
 	return TRUE;
+}
+
+/*--------------------------------------------------------------------------------------------------------------*/
+
+struct ClassDevHandler_s;
+typedef struct ClassDevHandler_s ClassDevHandler;
+
+struct ClassDevHandler_s
+{
+	const gchar *subsystem;
+	HalDevice *(*add) (const gchar *sysfs_path, const gchar *device_file, HalDevice *parent);
+	const gchar *prober;
+	gboolean (*post_probing) (HalDevice *d);
+	gboolean (*compute_udi) (HalDevice *d);
+	gboolean (*remove) (HalDevice *d);
+}; 
+
+/*--------------------------------------------------------------------------------------------------------------*/
+
+static ClassDevHandler classdev_handler_input = 
+{ 
+	.subsystem    = "input",
+	.add          = input_add,
+	.prober       = "hald-probe-input",
+	.post_probing = input_post_probing,
+	.compute_udi  = input_compute_udi,
+	.remove       = classdev_remove
+};
+
+static ClassDevHandler classdev_handler_bluetooth = 
+{ 
+	.subsystem    = "bluetooth",
+	.add          = bluetooth_add,
+	.prober       = NULL,
+	.post_probing = NULL,
+	.compute_udi  = bluetooth_compute_udi,
+	.remove       = classdev_remove
+};
+
+static ClassDevHandler *classdev_handlers[] = {
+	&classdev_handler_input,
+	&classdev_handler_bluetooth,
+	NULL
+};
+
+/*--------------------------------------------------------------------------------------------------------------*/
+
+static void 
+add_classdev_after_probing (HalDevice *d, ClassDevHandler *handler, void *end_token)
+{
+	/* Merge properties from .fdi files */
+	di_search_and_merge (d);
+
+	/* Compute UDI */
+	if (!handler->compute_udi (d))
+		goto out;
+	
+	/* TODO: Merge persistent properties */
+
+	/* TODO: Run callouts */
+
+	/* Move from temporary to global device store */
+	hal_device_store_remove (hald_get_tdl (), d);
+	hal_device_store_add (hald_get_gdl (), d);
+
 out:
 	hotplug_event_end (end_token);
-	return TRUE;
 }
 
+static void 
+add_classdev_probing_helper_done(HalDevice *d, gboolean timed_out, gint return_code, gpointer data1, gpointer data2)
+{
+	void *end_token = (void *) data1;
+	ClassDevHandler *handler = (ClassDevHandler *) data2;
+
+	HAL_INFO (("entering; timed_out=%d, return_code=%d", timed_out, return_code));
+
+	/* Discard device if probing reports failure */
+	if (return_code != 0) {
+		hal_device_store_remove (hald_get_tdl (), d);
+		hotplug_event_end (end_token);
+		goto out;
+	}
+
+	/* Do things post probing */
+	if (!handler->post_probing (d)) {
+		hotplug_event_end (end_token);
+		goto out;
+	}
 
+	add_classdev_after_probing (d, handler, end_token);
+
+out:
+	;
+}
 
 void
 hotplug_event_begin_add_classdev (const gchar *subsystem, const gchar *sysfs_path, const gchar *device_file, 
 				  HalDevice *physdev, void *end_token)
 {
+	guint i;
+
 	HAL_INFO (("class_add: subsys=%s sysfs_path=%s dev=%s physdev=0x%08x", subsystem, sysfs_path, device_file, physdev));
 
-	if (strcmp (subsystem, "input") == 0)
-		input_add (sysfs_path, device_file, physdev, end_token);
-	else
-		hotplug_event_end (end_token);
+	for (i = 0; classdev_handlers [i] != NULL; i++) {
+		ClassDevHandler *handler;
+
+		handler = classdev_handlers[i];
+		if (strcmp (handler->subsystem, subsystem) == 0) {
+			HalDevice *d;
+
+			/* attempt to add the device */
+			d = handler->add (sysfs_path, device_file, physdev);
+			if (d == NULL) {
+				/* didn't find anything - thus, ignore this hotplug event */
+				hotplug_event_end (end_token);
+				goto out;
+			}
+
+			/* Add to temporary device store */
+			hal_device_store_add (hald_get_tdl (), d);
+
+			if (handler->prober != NULL) {
+				/* probe the device */
+				if (!helper_invoke (handler->prober, d, (gpointer) end_token, (gpointer) handler, add_classdev_probing_helper_done, HAL_HELPER_TIMEOUT)) {
+					hal_device_store_remove (hald_get_tdl (), d);
+					hotplug_event_end (end_token);
+				}
+				goto out;
+			} else {
+				add_classdev_after_probing (d, handler, end_token);
+				goto out;
+			}				
+		}
+	}
+
+	/* didn't find anything - thus, ignore this hotplug event */
+	hotplug_event_end (end_token);
+out:
+	;
 }
 
 void
 hotplug_event_begin_remove_classdev (const gchar *subsystem, const gchar *sysfs_path, void *end_token)
 {
+	guint i;
 	HalDevice *d;
 
+
 	HAL_INFO (("class_rem: subsys=%s sysfs_path=%s", subsystem, sysfs_path));
 
 	d = hal_device_store_match_key_value_string (hald_get_gdl (), "linux.sysfs_path_device", sysfs_path);
 	if (d == NULL) {
 		HAL_WARNING (("Error removing device"));
 	} else {
-		const gchar *physdev_udi;
-		HalDevice *physdev;
 
-		physdev_udi = hal_device_property_get_string (d, "info.physical_device");
-
-		if (!hal_device_store_remove (hald_get_gdl (), d)) {
-			HAL_WARNING (("Error removing device"));
-		}
-
-		if (physdev_udi != NULL) {
-			physdev = hal_device_store_find (hald_get_gdl (), physdev_udi);
-			/* TODO: adjust capabilities on physdev */
+		for (i = 0; classdev_handlers [i] != NULL; i++) {
+			ClassDevHandler *handler;
+			
+			handler = classdev_handlers[i];
+			if (strcmp (handler->subsystem, subsystem) == 0) {
+				if (handler->remove (d)) {
+					/* let the handler end the event */
+					hotplug_event_end (end_token);
+					goto out;
+				}
+			}
 		}
-
 	}
 
+	/* didn't find anything - thus, ignore this hotplug event */
 	hotplug_event_end (end_token);
+out:
+	;
 }




More information about the hal-commit mailing list