[maemo-commits] [maemo-commits] r17502 - in projects/haf/trunk/hildon-thumbnail: . daemon

From: subversion at stage.maemo.org subversion at stage.maemo.org
Date: Tue Feb 24 12:44:19 EET 2009
Author: pvanhoof
Date: 2009-02-24 12:44:16 +0200 (Tue, 24 Feb 2009)
New Revision: 17502

Added:
   projects/haf/trunk/hildon-thumbnail/daemon/thumb-hal.c
   projects/haf/trunk/hildon-thumbnail/daemon/thumb-hal.h
Modified:
   projects/haf/trunk/hildon-thumbnail/ChangeLog
   projects/haf/trunk/hildon-thumbnail/config.h.in
   projects/haf/trunk/hildon-thumbnail/configure.ac
   projects/haf/trunk/hildon-thumbnail/daemon/Makefile.am
   projects/haf/trunk/hildon-thumbnail/daemon/hildon-thumbnail-daemon.c
Log:
2009-02-24  Philip Van Hoof  <pvanhoof at codeminded.be>

        * config.h.in
        * daemon/hildon-thumbnail-daemon.c
        * daemon/thumb-hal.c
        * daemon/thumb-hal.h
        * daemon/Makefile.am: Dying whenever an unmount of a removable device
        takes place, so that we ensure that we are not blocking the unmount
        from taking place whenever we are working with a file located on it.

        Although this isn't very nice, are thumbnails just cache. We are
        activatable so the next request will let us restart anyway. And caches
        should not be relied upon (consumers of the thumbnails must always
        request thumbnails if they see that their thumbnail is not already
        available).

        This drastic action might however mean that some app's thumbnail
        request will fail with a DBus timeout error.



Modified: projects/haf/trunk/hildon-thumbnail/ChangeLog
===================================================================
--- projects/haf/trunk/hildon-thumbnail/ChangeLog	2009-02-24 10:30:38 UTC (rev 17501)
+++ projects/haf/trunk/hildon-thumbnail/ChangeLog	2009-02-24 10:44:16 UTC (rev 17502)
@@ -1,3 +1,22 @@
+2009-02-24  Philip Van Hoof  <pvanhoof at codeminded.be>
+
+	* config.h.in
+	* daemon/hildon-thumbnail-daemon.c
+	* daemon/thumb-hal.c
+	* daemon/thumb-hal.h
+	* daemon/Makefile.am: Dying whenever an unmount of a removable device
+	takes place, so that we ensure that we are not blocking the unmount
+	from taking place whenever we are working with a file located on it.
+
+	Although this isn't very nice, are thumbnails just cache. We are
+	activatable so the next request will let us restart anyway. And caches
+	should not be relied upon (consumers of the thumbnails must always
+	request thumbnails if they see that their thumbnail is not already
+	available).
+
+	This drastic action might however mean that some app's thumbnail
+	request will fail with a DBus timeout error.
+
 2009-02-23  Philip Van Hoof  <pvanhoof at codeminded.be>
 
 	* debian/hildon-thumbnail.install: Re-enabled the GStreamer plugin

Modified: projects/haf/trunk/hildon-thumbnail/config.h.in
===================================================================
--- projects/haf/trunk/hildon-thumbnail/config.h.in	2009-02-24 10:30:38 UTC (rev 17501)
+++ projects/haf/trunk/hildon-thumbnail/config.h.in	2009-02-24 10:44:16 UTC (rev 17502)
@@ -3,6 +3,9 @@
 /* Define to 1 if you have the <dlfcn.h> header file. */
 #undef HAVE_DLFCN_H
 
+/* Define if we have HAL */
+#undef HAVE_HAL
+
 /* Define to 1 if you have the <inttypes.h> header file. */
 #undef HAVE_INTTYPES_H
 

Modified: projects/haf/trunk/hildon-thumbnail/configure.ac
===================================================================
--- projects/haf/trunk/hildon-thumbnail/configure.ac	2009-02-24 10:30:38 UTC (rev 17501)
+++ projects/haf/trunk/hildon-thumbnail/configure.ac	2009-02-24 10:44:16 UTC (rev 17502)
@@ -46,6 +46,41 @@
 
 AM_CONDITIONAL(HAVE_MGTK, test "$have_gtk" = "yes")
 
+
+##################################################################
+# Check for HAL
+##################################################################
+HAL_REQUIRED=0.5
+
+AC_ARG_ENABLE(hal,
+              AS_HELP_STRING([--disable-hal],
+                             [disable HAL support for AC power detection]),,
+              [enable_hal=yes])
+
+if test "x$enable_hal" = "xyes"; then
+   PKG_CHECK_MODULES(HAL,
+                     [hal >= $HAL_REQUIRED hal-storage],
+                     [have_hal=yes] ,
+                     [have_hal=no])
+   AC_SUBST(HAL_CFLAGS)
+   AC_SUBST(HAL_LIBS)
+
+   if test "x$have_hal" = "xyes"; then
+      AC_DEFINE(HAVE_HAL, [], [Define if we have HAL])
+   fi
+else
+   have_hal="no  (disabled)"
+fi
+
+if test "x$enable_hal" = "xyes"; then
+   if test "x$have_hal" != "xyes"; then
+      AC_MSG_ERROR([Couldn't find HAL >= $HAL_REQUIRED and HAL storage.])
+   fi
+fi
+
+AM_CONDITIONAL(HAVE_HAL, test "x$have_hal" = "xyes")
+
+
 ####################################################################
 # DBus Service
 ####################################################################

Modified: projects/haf/trunk/hildon-thumbnail/daemon/Makefile.am
===================================================================
--- projects/haf/trunk/hildon-thumbnail/daemon/Makefile.am	2009-02-24 10:30:38 UTC (rev 17501)
+++ projects/haf/trunk/hildon-thumbnail/daemon/Makefile.am	2009-02-24 10:44:16 UTC (rev 17502)
@@ -4,7 +4,7 @@
 	$(DBUS_CFLAGS) \
 	$(GLIB_CFLAGS) \
 	$(GMODULE_CFLAGS) \
-	$(GIO_CFLAGS) \
+	$(GIO_CFLAGS) $(HAL_CFLAGS) \
 	-DTHUMBNAILERS_DIR=\""/usr/share/thumbnailers"\" \
 	-DALBUMARTERS_DIR=\""/usr/share/albumart-providers"\" \
 	-DPLUGINS_DIR=\""$(libdir)/hildon-thumbnailer/plugins"\" \
@@ -57,6 +57,8 @@
 	dbus-utils.c \
 	albumart.c \
 	albumart.h \
+	thumb-hal.c \
+	thumb-hal.h \
 	albumart-marshal.c \
 	albumart-marshal.h \
 	albumart-manager.c \
@@ -67,7 +69,7 @@
 	$(DBUS_LIBS) \
 	$(GLIB_LIBS) \
 	$(GMODULE_LIBS) \
-	$(GIO_LIBS) 
+	$(GIO_LIBS) $(HAL_LIBS)
 
 # Services
 org.freedesktop.thumbnailer_servicedir = $(DBUS_SERVICES_DIR)

Modified: projects/haf/trunk/hildon-thumbnail/daemon/hildon-thumbnail-daemon.c
===================================================================
--- projects/haf/trunk/hildon-thumbnail/daemon/hildon-thumbnail-daemon.c	2009-02-24 10:30:38 UTC (rev 17501)
+++ projects/haf/trunk/hildon-thumbnail/daemon/hildon-thumbnail-daemon.c	2009-02-24 10:44:16 UTC (rev 17502)
@@ -40,13 +40,13 @@
 #include "albumart.h"
 #include "thumbnail-manager.h"
 #include "albumart-manager.h"
+#include "thumb-hal.h"
 
 static GHashTable *registrations;
 static GHashTable *outregistrations;
 static gboolean do_shut_down_next_time = TRUE;
 
 
-
 #ifndef __NR_ioprio_set
 
 #if defined(__i386__)
@@ -406,6 +406,9 @@
 		g_signal_connect (G_OBJECT (monitoro), "changed", 
 				  G_CALLBACK (on_outputplugin_changed), thumbnailer);
 
+
+		thumb_hal_init ();
+
 		main_loop = g_main_loop_new (NULL, FALSE);
 
 		g_timeout_add_seconds (600, 
@@ -414,6 +417,8 @@
 
 		g_main_loop_run (main_loop);
 
+		thumb_hal_shutdown ();
+
 		g_object_unref (monitor);
 		g_object_unref (file);
 		g_object_unref (monitoro);

Added: projects/haf/trunk/hildon-thumbnail/daemon/thumb-hal.c
===================================================================
--- projects/haf/trunk/hildon-thumbnail/daemon/thumb-hal.c	2009-02-24 10:30:38 UTC (rev 17501)
+++ projects/haf/trunk/hildon-thumbnail/daemon/thumb-hal.c	2009-02-24 10:44:16 UTC (rev 17502)
@@ -0,0 +1,110 @@
+#include <stdlib.h>
+
+#include "thumb-hal.h"
+#include "config.h"
+
+#ifdef HAVE_HAL
+
+#include <libhal.h>
+#include <libhal-storage.h>
+
+static LibHalContext *context;
+
+#define PROP_IS_MOUNTED        "volume.is_mounted"
+
+
+static void
+hal_device_removed_cb (LibHalContext *context, const gchar   *udi)
+{
+	/* We instantly exit the process whenever an unmount occurs. We are an 
+	 * activatable service so this is ok. The reason why we do this is to
+	 * make sure that we release all file descriptors, so that the unmount
+	 * can cleanly succeed at all times (if we were building a thumbnail for
+	 * a file on the device being unmounted, then that's bad luck for that
+	 * thumbnail). */
+
+	exit (0);
+}
+
+static void
+hal_device_property_modified_cb (LibHalContext *context,
+				 const char    *udi,
+				 const char    *key,
+				 dbus_bool_t	is_removed,
+				 dbus_bool_t	is_added)
+{
+	gboolean is_mounted;
+
+	if (strcmp (key, PROP_IS_MOUNTED) != 0) {
+			return;
+	}
+
+	is_mounted = libhal_device_get_property_bool (context,
+							      udi,
+							      key,
+							      NULL);
+
+	if (is_mounted)
+		hal_device_removed_cb (context, udi); 
+}
+
+
+#endif
+
+void
+thumb_hal_init (void)
+{
+#ifdef HAVE_HAL
+	DBusError	error;
+	DBusConnection *connection;
+
+	dbus_error_init (&error);
+
+	connection = dbus_bus_get (DBUS_BUS_SYSTEM, &error);
+	if (dbus_error_is_set (&error)) {
+		g_critical ("Could not get the system DBus connection, %s",
+			    error.message);
+		dbus_error_free (&error);
+		return;
+	}
+
+	dbus_connection_setup_with_g_main (connection, NULL);
+
+	context = libhal_ctx_new ();
+
+	if (!context) {
+		g_critical ("Could not create HAL context");
+		return;
+	}
+
+	libhal_ctx_set_user_data (context, NULL);
+	libhal_ctx_set_dbus_connection (context, connection);
+
+	if (!libhal_ctx_init (context, &error)) {
+		if (dbus_error_is_set (&error)) {
+			g_critical ("Could not initialize the HAL context, %s",
+				    error.message);
+			dbus_error_free (&error);
+		} else {
+			g_critical ("Could not initialize the HAL context, "
+				    "no error, is hald running?");
+		}
+
+		libhal_ctx_free (context);
+		return;
+	}
+
+
+	libhal_ctx_set_device_removed (context, hal_device_removed_cb);
+	libhal_ctx_set_device_property_modified (context, hal_device_property_modified_cb);
+#endif
+}
+
+void
+thumb_hal_shutdown (void)
+{
+#ifdef HAVE_HAL
+	libhal_ctx_set_user_data (context, NULL);
+	libhal_ctx_free (context);
+#endif
+}

Added: projects/haf/trunk/hildon-thumbnail/daemon/thumb-hal.h
===================================================================
--- projects/haf/trunk/hildon-thumbnail/daemon/thumb-hal.h	2009-02-24 10:30:38 UTC (rev 17501)
+++ projects/haf/trunk/hildon-thumbnail/daemon/thumb-hal.h	2009-02-24 10:44:16 UTC (rev 17502)
@@ -0,0 +1,13 @@
+#ifndef __THUMB_HAL_H__
+#define __THUMB_HAL_H__
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+void thumb_hal_init (void);
+void thumb_hal_shutdown (void);
+
+G_END_DECLS
+
+#endif


More information about the maemo-commits mailing list