hal/hald/linux2 Makefile.am,1.5,1.6 classdev.c,1.7,1.8

David Zeuthen david at freedesktop.org
Thu Feb 3 21:24:27 PST 2005


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

Modified Files:
	Makefile.am classdev.c 
Log Message:
2005-02-04  David Zeuthen  <david at fubar.dk>

	* doc/spec/hal-spec.xml.in: Added docs for battery.remaining_time

	* hald/linux2/classdev.c (input_get_prober): New function
	(usbclass_add): New function
	(usbclass_get_prober): New function
	(usbclass_compute_udi): New function
	(add_classdev_probing_helper_done): Check if post_probing is NULL
	(hotplug_event_begin_add_classdev): Use function to get prober since
	e.g. class usb covers multiple devices, e.g. hiddev, printers etc.

	* hald/linux2/probing/probe-hiddev.c: New file; probe for application
	pages a HIDDEV supports and add to hiddev.application_pages strlist

	* hald/linux2/addons/addon-hid-ups.c: Detect UPS's on USB HID
	interfaces and create plus maintain battery.* properties.

	* hald/linux2/addons/Makefile.am: New file

	* hald/linux2/Makefile.am (SUBDIRS): Add addons directory

	* configure.in: Add hald2/linux2/addons/Makefile.am to AC_OUTPUT



Index: Makefile.am
===================================================================
RCS file: /cvs/hal/hal/hald/linux2/Makefile.am,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- Makefile.am	3 Feb 2005 04:13:46 -0000	1.5
+++ Makefile.am	4 Feb 2005 05:24:25 -0000	1.6
@@ -1,5 +1,5 @@
 
-SUBDIRS = probing .
+SUBDIRS = probing addons .
 
 INCLUDES = \
 	-DPACKAGE_SYSCONF_DIR=\""$(sysconfdir)"\" \

Index: classdev.c
===================================================================
RCS file: /cvs/hal/hal/hald/linux2/classdev.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- classdev.c	3 Feb 2005 04:13:46 -0000	1.7
+++ classdev.c	4 Feb 2005 05:24:25 -0000	1.8
@@ -96,6 +96,12 @@
 	return d;
 }
 
+static const gchar *
+input_get_prober (HalDevice *d)
+{
+	return "hald-probe-input";
+}
+
 static gboolean
 input_post_probing (HalDevice *d)
 {
@@ -360,6 +366,63 @@
 
 /*--------------------------------------------------------------------------------------------------------------*/
 
+static HalDevice *
+usbclass_add (const gchar *sysfs_path, const gchar *device_file, HalDevice *physdev, const gchar *sysfs_path_in_devices)
+{
+	HalDevice *d;
+	gint host_num;
+	const gchar *last_elem;
+
+	d = NULL;
+
+	if (physdev == NULL || sysfs_path_in_devices == NULL || device_file == NULL) {
+		goto out;
+	}
+
+	last_elem = hal_util_get_last_element (sysfs_path);
+	if (sscanf (last_elem, "hiddev%d", &host_num) == 1) {
+
+		d = hal_device_new ();
+		hal_device_property_set_string (d, "linux.sysfs_path", sysfs_path);
+		hal_device_property_set_string (d, "linux.sysfs_path_device", sysfs_path_in_devices);
+		hal_device_property_set_string (d, "info.parent", physdev->udi);
+
+		hal_device_property_set_string (d, "info.category", "hiddev");
+		hal_device_add_capability (d, "hiddev");
+
+		hal_device_property_set_string (d, "info.product", "USB HID Device");
+
+		hal_device_property_set_string (d, "hiddev.device", device_file);
+	}
+
+out:
+	return d;
+}
+
+static const gchar *
+usbclass_get_prober (HalDevice *d)
+{
+	if (hal_device_has_capability (d, "hiddev"))
+		return "hald-probe-hiddev";
+	else
+		return NULL;
+}
+
+static gboolean
+usbclass_compute_udi (HalDevice *d)
+{
+	gchar udi[256];
+
+	hal_util_compute_udi (hald_get_gdl (), udi, sizeof (udi),
+			      "%s_hiddev",
+			      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)
 {
@@ -379,7 +442,7 @@
 {
 	const gchar *subsystem;
 	HalDevice *(*add) (const gchar *sysfs_path, const gchar *device_file, HalDevice *parent, const gchar *sysfs_path_in_devices);
-	const gchar *prober;
+	const gchar *(*get_prober)(HalDevice *d);
 	gboolean (*post_probing) (HalDevice *d);
 	gboolean (*compute_udi) (HalDevice *d);
 	gboolean (*remove) (HalDevice *d);
@@ -391,7 +454,7 @@
 { 
 	.subsystem    = "input",
 	.add          = input_add,
-	.prober       = "hald-probe-input",
+	.get_prober   = input_get_prober,
 	.post_probing = input_post_probing,
 	.compute_udi  = input_compute_udi,
 	.remove       = classdev_remove
@@ -401,7 +464,7 @@
 { 
 	.subsystem    = "bluetooth",
 	.add          = bluetooth_add,
-	.prober       = NULL,
+	.get_prober   = NULL,
 	.post_probing = NULL,
 	.compute_udi  = bluetooth_compute_udi,
 	.remove       = classdev_remove
@@ -411,7 +474,7 @@
 { 
 	.subsystem    = "net",
 	.add          = net_add,
-	.prober       = NULL,
+	.get_prober   = NULL,
 	.post_probing = NULL,
 	.compute_udi  = net_compute_udi,
 	.remove       = classdev_remove
@@ -421,17 +484,28 @@
 { 
 	.subsystem    = "scsi_host",
 	.add          = scsi_host_add,
-	.prober       = NULL,
+	.get_prober   = NULL,
 	.post_probing = NULL,
 	.compute_udi  = scsi_host_compute_udi,
 	.remove       = classdev_remove
 };
 
+static ClassDevHandler classdev_handler_usbclass = 
+{ 
+	.subsystem    = "usb",
+	.add          = usbclass_add,
+	.get_prober   = usbclass_get_prober,
+	.post_probing = NULL,
+	.compute_udi  = usbclass_compute_udi,
+	.remove       = classdev_remove
+};
+
 static ClassDevHandler *classdev_handlers[] = {
 	&classdev_handler_input,
 	&classdev_handler_bluetooth,
 	&classdev_handler_net,
 	&classdev_handler_scsi_host,
+	&classdev_handler_usbclass,
 	NULL
 };
 
@@ -477,9 +551,11 @@
 	}
 
 	/* Do things post probing */
-	if (!handler->post_probing (d)) {
-		hotplug_event_end (end_token);
-		goto out;
+	if (handler->post_probing != NULL) {
+		if (!handler->post_probing (d)) {
+			hotplug_event_end (end_token);
+			goto out;
+		}
 	}
 
 	add_classdev_after_probing (d, handler, end_token);
@@ -502,6 +578,7 @@
 		handler = classdev_handlers[i];
 		if (strcmp (handler->subsystem, subsystem) == 0) {
 			HalDevice *d;
+			const gchar *prober;
 
 			/* attempt to add the device */
 			d = handler->add (sysfs_path, device_file, physdev, sysfs_path_in_devices);
@@ -520,9 +597,13 @@
 			/* Add to temporary device store */
 			hal_device_store_add (hald_get_tdl (), d);
 
-			if (handler->prober != NULL) {
+			if (handler->get_prober != NULL)
+				prober = handler->get_prober (d);
+			else
+				prober = NULL;
+			if (prober != NULL) {
 				/* probe the device */
-				if (!helper_invoke (handler->prober, d, (gpointer) end_token, (gpointer) handler, add_classdev_probing_helper_done, HAL_HELPER_TIMEOUT)) {
+				if (!helper_invoke (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);
 				}




More information about the hal-commit mailing list