[patch] HAL support



Hi,

This patch uses hal/dbus to receive notification of attached USB (Visor) 
Pilot's, when configured with --enable-hal --enable-visor.

If it can't connect to the hal, it falls back to polling the usb device
file list.

Regards
Simon

-- 
Simon Hart - simon sphart uklinux net

--- gnome-pilot-2.0.12/gpilotd/gpilotd.c	2004-09-03 17:18:35.000000000 +0100
+++ gnome-pilot-2.0.12-hal/gpilotd/gpilotd.c	2004-12-08 23:16:34.000000000 +0000
@@ -51,6 +51,12 @@
 #include <libxml/xmlmemory.h>
 #include <libxml/entities.h>
 
+#ifdef WITH_HAL
+#include <dbus/dbus.h>
+#include <dbus/dbus-glib-lowlevel.h>
+#include <libhal.h>
+#endif
+
 #include <libgnome/libgnome.h>
 
 #include <pi-source.h>
@@ -930,6 +936,90 @@
 #endif
 #endif
 
+#ifdef WITH_HAL
+/* copied more-or-less verbatim from gnome-volume-manager */
+
+/* invoked by libhal for integration with our mainloop */
+static void
+hal_mainloop_integration (LibHalContext *ctx __attribute__((__unused__)),
+			  DBusConnection * dbus_connection)
+{
+	dbus_connection_setup_with_g_main (dbus_connection, NULL);
+}
+
+/* invoked by libhal when a new device is added */
+static void
+hal_device_added (LibHalContext *ctx, const char *udi)
+{
+	// g_warning ("Device added: %s\n", udi);
+
+	GPilotContext *gpilot_context = (GPilotContext *) hal_ctx_get_user_data(ctx);
+
+	/* since visor_devices_timeout already exists to find which (if any 
+	 * pilot was connected, let it do all the hard work, rather than 
+	 * querying HAL to see the the new device is interesting to us 
+	 * - might at least check it is a USB device ...
+	 */
+	
+	visor_devices_timeout (gpilot_context);
+}
+
+static void
+hal_device_removed (LibHalContext *ctx __attribute__((__unused__)), 
+		    const char *udi)
+{
+	// g_warning ("Device removed: %s\n", udi);
+}
+
+static LibHalContext *
+gpilot_do_hal_init (GPilotContext *gpilot_context)
+{
+	static LibHalFunctions hal_functions = { 
+		hal_mainloop_integration,
+		hal_device_added,
+		hal_device_removed,
+		NULL, /* New Cap */
+		NULL, /* lost cap */
+		NULL, /* prop changed */
+		NULL  /* non continuous event */
+	};
+	LibHalContext *ctx;
+	char **devices;
+	int nr;
+
+	ctx = hal_initialize (&hal_functions, FALSE);
+	if (!ctx) {
+		g_warning ("failed to initialize HAL");
+		return NULL;
+	}
+
+	hal_ctx_set_user_data (ctx, (void *)gpilot_context);
+	
+	if (hal_device_property_watch_all (ctx)) {
+		g_warning ("failed to watch all HAL properties");
+		hal_shutdown (ctx);
+		return NULL;
+	}
+
+	/*
+	 * Do something to ping the HAL daemon - the above functions will
+	 * succeed even if hald is not running, so long as DBUS is.  But we
+	 * want to exit silently if hald is not running, to behave on
+	 * pre-2.6 systems.
+	 */
+	devices = hal_get_all_devices (ctx, &nr);
+	if (!devices) {
+		g_message ("HAL not running - will fall back to polling");
+		hal_shutdown (ctx);
+		return NULL;
+	}
+	hal_free_string_array (devices);
+
+	g_message ("Using HAL to monitor for palm");
+	return ctx;
+}
+#endif 
+
 void monitor_channel (GPilotDevice *dev,GPilotContext *context) 
 {
 	g_assert (context != NULL);
@@ -960,12 +1050,20 @@
 	} if (dev->type == PILOT_DEVICE_USB_VISOR) {
 #ifdef WITH_USB_VISOR
 #ifdef linux
-		/* We want to watch the /proc/bus/usb/devices file once 
+#ifdef WITH_HAL
+		if (!gpilot_do_hal_init(context)) {
+			if (visor_timeout_id == -1) {
+				visor_timeout_id = g_timeout_add (2000, visor_devices_timeout, context);
+			}
+		}
+#else /* WITH_HAL */
+		/* We want to watch the /proc/bus/usb/devices file once
 		 * per context, and then check all devices each time it is
 		 * woken up. */
 		if (visor_timeout_id == -1) {
 			visor_timeout_id = g_timeout_add (2000, visor_devices_timeout, context);
 		}
+#endif /* WITH_HAL */
 #else /* linux*/
 		g_assert_not_reached ();
 #endif /* linux */
@@ -1115,6 +1213,9 @@
 #ifdef WITH_USB_VISOR
 	str = g_string_append (str, "[USB] ");
 #endif
+#ifdef WITH_HAL
+	str = g_string_append (str, "[HAL] ");
+#endif
 #ifdef WITH_IRDA
 	str = g_string_append (str, "[IrDA] ");
 #endif
--- gnome-pilot-2.0.12/configure.in	2004-09-03 17:18:35.000000000 +0100
+++ gnome-pilot-2.0.12-hal/configure.in	2004-12-08 22:05:47.000000000 +0000
@@ -75,6 +75,21 @@
 	AC_DEFINE(WITH_USB_VISOR,, "With USB Visor Support")
 fi
 
+AC_ARG_ENABLE([hal],[  --enable-hal         Enable support for HAL USB device addition.],[
+	do_hal=$enableval
+],[
+	do_hal=yes
+])
+
+if test x"$do_hal" = xyes ; then
+	if test x"$do_usb" != xyes ; then
+		AC_MSG_ERROR([HAL support requires USB visor support])
+	fi
+	AC_DEFINE(WITH_HAL,, "With HAL Support")
+	DBUS_GLIB_REQUIRED="dbus-glib-1 >= 0.22.3"
+	HAL_REQUIRED="hal > 0.4.2"
+fi
+
 AC_DEFINE(WITH_IRDA,,"With IrDA Support")
 
 AC_ARG_ENABLE([network], [  --enable-network     Enable support for network synchronization],[
@@ -120,8 +135,11 @@
 	$BONOBO_ACTIVATION_REQUIRED
 	$GNOMEVFS_REQUIRED
 	$GCONF_REQUIRED
+	$DBUS_GLIB_REQUIRED
+	$HAL_REQUIRED
 ])
 
+
 GNOME_PILOT_CFLAGS="$GNOME_PILOT_CFLAGS $PISOCK_CFLAGS"
 GNOME_PILOT_LIBS="$GNOME_PILOT_LIBS $PISOCK_LIBS"
 
@@ -241,6 +259,11 @@
 else
 	echo "          usb          : no"
 fi
+if test x"$do_hal" = xyes; then
+	echo "          hal          : yes"
+else
+	echo "          hal          : no"
+fi
 if test x"$GOB" = xno; then
 	echo "          gob          : no"
 else
--- gnome-pilot-2.0.12/config.h.in	2004-08-23 19:17:17.000000000 +0100
+++ gnome-pilot-2.0.12-hal/config.h.in	2004-12-08 21:25:20.000000000 +0000
@@ -93,5 +93,8 @@
 /* "With USB Visor Support" */
 #undef WITH_USB_VISOR
 
+/* "With HAL Support" */
+#undef WITH_HAL
+
 /* "With GNOME VFS Support" */
 #undef WITH_VFS
--- gnome-pilot-2.0.12/ChangeLog	2004-09-03 17:21:17.000000000 +0100
+++ gnome-pilot-2.0.12-hal/ChangeLog	2004-12-08 21:25:37.000000000 +0000
@@ -1,3 +1,9 @@
+2004-12-08  SP Hart  <sphart uklinux net>
+	
+	* gpilotd/gpilotd.c: 
+	* configure.in: 
+	* config.h.in: Support for HAL for USB devices
+	
 2004-09-03  JP Rosevear  <jpr novell com>
 
 	* configure.in: bump version


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]