[maemo-commits] [maemo-commits] r16515 - in projects/haf/trunk/hildon-thumbnail: . albumart-providers/googleimages daemon daemon/plugins

From: subversion at stage.maemo.org subversion at stage.maemo.org
Date: Tue Oct 28 17:04:12 EET 2008
Author: pvanhoof
Date: 2008-10-28 17:04:09 +0200 (Tue, 28 Oct 2008)
New Revision: 16515

Modified:
   projects/haf/trunk/hildon-thumbnail/ChangeLog
   projects/haf/trunk/hildon-thumbnail/albumart-providers/googleimages/Makefile.am
   projects/haf/trunk/hildon-thumbnail/daemon/hildon-thumbnail-plugin.h
   projects/haf/trunk/hildon-thumbnail/daemon/plugin-runner.c
   projects/haf/trunk/hildon-thumbnail/daemon/plugins/epeg-plugin.c
   projects/haf/trunk/hildon-thumbnail/daemon/plugins/exec-plugin.c
   projects/haf/trunk/hildon-thumbnail/daemon/plugins/gdkpixbuf-plugin.c
   projects/haf/trunk/hildon-thumbnail/daemon/plugins/gstreamer-video-plugin.c
   projects/haf/trunk/hildon-thumbnail/daemon/thumbnailer.c
   projects/haf/trunk/hildon-thumbnail/daemon/thumbnailer.h
Log:
2008-10-28  Philip Van Hoof  <philip at codeminded.be>

	* albumart-providers/googleimages/Makefile.am: Bugfix for make 
	distcheck and make clean

	* daemon/hildon-thumbnail-plugin.h
	* daemon/plugins/gdkpixbuf-plugin.c
	* daemon/plugins/exec-plugin.c
	* daemon/plugins/gstreamer-video-plugin.c
	* daemon/plugins/epeg-plugin.c
	* daemon/plugin-runner.c
	* daemon/thumbnailer.c
	* daemon/thumbnailer.h: Refactoring for grouping per URI scheme, picking
	of plugins based on supported uri_schemes and priority



Modified: projects/haf/trunk/hildon-thumbnail/ChangeLog
===================================================================
--- projects/haf/trunk/hildon-thumbnail/ChangeLog	2008-10-28 13:33:31 UTC (rev 16514)
+++ projects/haf/trunk/hildon-thumbnail/ChangeLog	2008-10-28 15:04:09 UTC (rev 16515)
@@ -1,5 +1,20 @@
 2008-10-28  Philip Van Hoof  <philip at codeminded.be>
 
+	* albumart-providers/googleimages/Makefile.am: Bugfix for make 
+	distcheck and make clean
+
+	* daemon/hildon-thumbnail-plugin.h
+	* daemon/plugins/gdkpixbuf-plugin.c
+	* daemon/plugins/exec-plugin.c
+	* daemon/plugins/gstreamer-video-plugin.c
+	* daemon/plugins/epeg-plugin.c
+	* daemon/plugin-runner.c
+	* daemon/thumbnailer.c
+	* daemon/thumbnailer.h: Refactoring for grouping per URI scheme, picking
+	of plugins based on supported uri_schemes and priority
+
+2008-10-28  Philip Van Hoof  <philip at codeminded.be>
+
 	* daemon/thumbnail-manager.h
 	* daemon/plugins/gdkpixbuf-plugin.c
 	* daemon/plugins/exec-plugin.c

Modified: projects/haf/trunk/hildon-thumbnail/albumart-providers/googleimages/Makefile.am
===================================================================
--- projects/haf/trunk/hildon-thumbnail/albumart-providers/googleimages/Makefile.am	2008-10-28 13:33:31 UTC (rev 16514)
+++ projects/haf/trunk/hildon-thumbnail/albumart-providers/googleimages/Makefile.am	2008-10-28 15:04:09 UTC (rev 16515)
@@ -17,8 +17,7 @@
              com.nokia.albumart.GoogleImages.service.in \
              com.nokia.albumart.AlbumartProvider.GoogleImages.service
 
-CLEANFILES = $(com.nokia.albumart.GoogleImages_service_DATA) \
-	     $(albartdown_DATA)
+CLEANFILES = $(com.nokia.albumart.GoogleImages_service_DATA) 
 
 libexec_PROGRAMS = hildon-google-images-art-downloaderd
 

Modified: projects/haf/trunk/hildon-thumbnail/daemon/hildon-thumbnail-plugin.h
===================================================================
--- projects/haf/trunk/hildon-thumbnail/daemon/hildon-thumbnail-plugin.h	2008-10-28 13:33:31 UTC (rev 16514)
+++ projects/haf/trunk/hildon-thumbnail/daemon/hildon-thumbnail-plugin.h	2008-10-28 15:04:09 UTC (rev 16515)
@@ -31,7 +31,7 @@
 
 G_BEGIN_DECLS
 
-typedef void (*register_func) (gpointer self, const gchar *mime_type, GModule *module, gboolean overwrite);
+typedef void (*register_func) (gpointer self, const gchar *mime_type, GModule *module, const GStrv uri_schemes, gint priority);
 
 GModule *   hildon_thumbnail_plugin_load          (const gchar *module_name);
 GStrv       hildon_thumbnail_plugin_get_supported (GModule *module);

Modified: projects/haf/trunk/hildon-thumbnail/daemon/plugin-runner.c
===================================================================
--- projects/haf/trunk/hildon-thumbnail/daemon/plugin-runner.c	2008-10-28 13:33:31 UTC (rev 16514)
+++ projects/haf/trunk/hildon-thumbnail/daemon/plugin-runner.c	2008-10-28 15:04:09 UTC (rev 16515)
@@ -215,10 +215,12 @@
 
 
 static void 
-daemon_register_func (gpointer self, const gchar *mime_type, GModule *module, gboolean overwrite)
+daemon_register_func (gpointer self, const gchar *mime_type, GModule *module, const GStrv uri_schemes, gint priority)
 {
 	GError *nerror = NULL;
 
+	// TODO: we are neglecting uri_schemes and priority here 
+
 	dbus_g_proxy_call (self, "Register",
 			   &nerror, G_TYPE_STRING,
 			   mime_type,
@@ -248,7 +250,6 @@
 					 daemon_register_func, 
 					 manager_proxy, &error);
 
-
 	g_object_unref (manager_proxy);
 
 	if (error) {

Modified: projects/haf/trunk/hildon-thumbnail/daemon/plugins/epeg-plugin.c
===================================================================
--- projects/haf/trunk/hildon-thumbnail/daemon/plugins/epeg-plugin.c	2008-10-28 13:33:31 UTC (rev 16514)
+++ projects/haf/trunk/hildon-thumbnail/daemon/plugins/epeg-plugin.c	2008-10-28 15:04:09 UTC (rev 16515)
@@ -438,6 +438,7 @@
 	GFile *file = g_file_new_for_path (config);
 	guint i = 0;
 	const gchar **supported;
+	const gchar *uri_schemes[2] = { "file", NULL };
 
 	monitor =  g_file_monitor_file (file, G_FILE_MONITOR_NONE, NULL, NULL);
 
@@ -454,7 +455,7 @@
 		supported = hildon_thumbnail_plugin_supported ();
 		if (supported) {
 			while (supported[i] != NULL) {
-				func (thumbnailer, supported[i], module, TRUE);
+				func (thumbnailer, supported[i], module, (const GStrv) uri_schemes, 1);
 				i++;
 			}
 		}

Modified: projects/haf/trunk/hildon-thumbnail/daemon/plugins/exec-plugin.c
===================================================================
--- projects/haf/trunk/hildon-thumbnail/daemon/plugins/exec-plugin.c	2008-10-28 13:33:31 UTC (rev 16514)
+++ projects/haf/trunk/hildon-thumbnail/daemon/plugins/exec-plugin.c	2008-10-28 15:04:09 UTC (rev 16515)
@@ -405,6 +405,7 @@
 	GFile *file = g_file_new_for_path (config);
 	guint i = 0;
 	const gchar **supported;
+	const gchar *uri_schemes[2] = { "file", NULL };
 
 	monitor =  g_file_monitor_file (file, G_FILE_MONITOR_NONE, NULL, NULL);
 
@@ -421,7 +422,7 @@
 		supported = hildon_thumbnail_plugin_supported ();
 		if (supported) {
 			while (supported[i] != NULL) {
-				func (thumbnailer, supported[i], module, TRUE);
+				func (thumbnailer, supported[i], module, (const GStrv) uri_schemes, 0);
 				i++;
 			}
 		}

Modified: projects/haf/trunk/hildon-thumbnail/daemon/plugins/gdkpixbuf-plugin.c
===================================================================
--- projects/haf/trunk/hildon-thumbnail/daemon/plugins/gdkpixbuf-plugin.c	2008-10-28 13:33:31 UTC (rev 16514)
+++ projects/haf/trunk/hildon-thumbnail/daemon/plugins/gdkpixbuf-plugin.c	2008-10-28 15:04:09 UTC (rev 16515)
@@ -415,6 +415,9 @@
 	GFile *file = g_file_new_for_path (config);
 	guint i = 0;
 	const gchar **supported;
+	const gchar *uri_schemes[8] = { "file", "http", "https", 
+									"smb", "nfs", "ftp", 
+									"ftps", NULL };
 
 	monitor =  g_file_monitor_file (file, G_FILE_MONITOR_NONE, NULL, NULL);
 
@@ -431,7 +434,7 @@
 		supported = hildon_thumbnail_plugin_supported ();
 		if (supported) {
 			while (supported[i] != NULL) {
-				func (thumbnailer, supported[i], module, FALSE);
+				func (thumbnailer, supported[i], module, (const GStrv) uri_schemes, 0);
 				i++;
 			}
 		}

Modified: projects/haf/trunk/hildon-thumbnail/daemon/plugins/gstreamer-video-plugin.c
===================================================================
--- projects/haf/trunk/hildon-thumbnail/daemon/plugins/gstreamer-video-plugin.c	2008-10-28 13:33:31 UTC (rev 16514)
+++ projects/haf/trunk/hildon-thumbnail/daemon/plugins/gstreamer-video-plugin.c	2008-10-28 15:04:09 UTC (rev 16515)
@@ -545,6 +545,9 @@
 	guint i = 0;
 	const gchar **supported;
 
+	/* TODO: Perhaps we can add a few remote ones here too (streaming media) */
+	const gchar *uri_schemes[2] = { "file", NULL };
+
 	g_type_init ();
 
 	gst_init (NULL, NULL);
@@ -564,7 +567,7 @@
 		supported = hildon_thumbnail_plugin_supported ();
 		if (supported) {
 			while (supported[i] != NULL) {
-				func (thumbnailer, supported[i], module, TRUE);
+				func (thumbnailer, supported[i], module, (const GStrv) uri_schemes, 0);
 				i++;
 			}
 		}

Modified: projects/haf/trunk/hildon-thumbnail/daemon/thumbnailer.c
===================================================================
--- projects/haf/trunk/hildon-thumbnail/daemon/thumbnailer.c	2008-10-28 13:33:31 UTC (rev 16514)
+++ projects/haf/trunk/hildon-thumbnail/daemon/thumbnailer.c	2008-10-28 15:04:09 UTC (rev 16515)
@@ -52,7 +52,7 @@
 
 typedef struct {
 	ThumbnailManager *manager;
-	GHashTable *plugins;
+	GHashTable *plugins_perscheme;
 	GThreadPool *large_pool;
 	GThreadPool *normal_pool;
 	GMutex *mutex;
@@ -74,30 +74,88 @@
 
 static guint signals[LAST_SIGNAL] = { 0, };
 
+typedef struct {
+	GModule *plugin;
+	gint priority;
+} PluginRegistration;
+
+static void
+free_pluginregistration (PluginRegistration *r)
+{
+	g_slice_free (PluginRegistration, r);
+}
+
 static GModule*
-get_plugin (Thumbnailer *object, const gchar *uri_scheme, const gchar *key)
+get_plugin (Thumbnailer *object, const gchar *uri_scheme, const gchar *mime_type)
 {
 	// TODO: take into account uri_scheme
 	ThumbnailerPrivate *priv = THUMBNAILER_GET_PRIVATE (object);
-	return g_hash_table_lookup (priv->plugins, key);
+	GHashTable *hash;
+	GModule *plugin = NULL;
+
+	hash = g_hash_table_lookup (priv->plugins_perscheme, uri_scheme);
+
+	if (hash) {
+		PluginRegistration *reg = g_hash_table_lookup (hash, mime_type);
+		if (reg) {
+			plugin = reg->plugin;
+		}
+	}
+
+	return plugin;
 }
 
 void 
-thumbnailer_register_plugin (Thumbnailer *object, const gchar *mime_type, GModule *plugin, gboolean overwrite)
+thumbnailer_register_plugin (Thumbnailer *object, const gchar *mime_type, GModule *plugin, const GStrv uri_schemes, gint priority)
 {
 	ThumbnailerPrivate *priv = THUMBNAILER_GET_PRIVATE (object);
+	guint i = 0;
 
 	g_mutex_lock (priv->mutex);
 
-	if (!overwrite && g_hash_table_lookup (priv->plugins, mime_type)) {
-		g_mutex_unlock (priv->mutex);
-		return;
+	while (uri_schemes[i] != NULL) {
+		GHashTable *hash;
+
+		hash = g_hash_table_lookup (priv->plugins_perscheme, uri_schemes[i]);
+
+		if (!hash) {
+			PluginRegistration *reg = g_slice_new (PluginRegistration);
+
+			reg->plugin = plugin;
+			reg->priority = priority;
+
+			hash = g_hash_table_new_full (g_str_hash, g_str_equal, 
+					 (GDestroyNotify) g_free, 
+					 (GDestroyNotify) free_pluginregistration);
+
+			g_hash_table_replace (priv->plugins_perscheme, 
+					      g_strdup (uri_schemes[i]), 
+					      hash);
+
+			g_hash_table_replace (hash, g_strdup (mime_type), reg);
+
+			thumbnail_manager_i_have (priv->manager, mime_type);
+
+		} else {
+			PluginRegistration *o_reg = g_hash_table_lookup (hash, mime_type);
+
+			if (o_reg && o_reg->priority < priority) {
+				PluginRegistration *reg = g_slice_new (PluginRegistration);
+
+				reg->plugin = plugin;
+				reg->priority = priority;
+
+				g_hash_table_replace (hash, g_strdup (mime_type), reg);
+
+				thumbnail_manager_i_have (priv->manager, mime_type);
+			}
+		}
+
+		i++;
 	}
-	g_hash_table_replace (priv->plugins, 
-			     g_strdup (mime_type), 
-			     plugin);
-	thumbnail_manager_i_have (priv->manager, mime_type);
+
 	g_mutex_unlock (priv->mutex);
+
 }
 
 static gboolean 
@@ -108,15 +166,22 @@
 	return FALSE;
 }
 
+static void
+foreach_scheme (gpointer key, gpointer value, gpointer plugin)
+{
+	GHashTable *hash = value;
+	g_hash_table_foreach_remove (hash, do_delete_or_not, plugin);
+}
+
 void 
 thumbnailer_unregister_plugin (Thumbnailer *object, GModule *plugin)
 {
 	ThumbnailerPrivate *priv = THUMBNAILER_GET_PRIVATE (object);
 
 	g_mutex_lock (priv->mutex);
-	g_hash_table_foreach_remove (priv->plugins, 
-				     do_delete_or_not, 
-				     plugin);
+	/* This might leave an empty node in case there are no more plugins
+	 * for a specific scheme. But that's harmless. */
+	g_hash_table_foreach (priv->plugins_perscheme, foreach_scheme, plugin);
 	g_mutex_unlock (priv->mutex);
 }
 
@@ -797,7 +862,7 @@
 	g_thread_pool_free (priv->large_pool, TRUE, TRUE);
 
 	g_object_unref (priv->manager);
-	g_hash_table_unref (priv->plugins);
+	g_hash_table_unref (priv->plugins_perscheme);
 	g_mutex_free (priv->mutex);
 
 	G_OBJECT_CLASS (thumbnailer_parent_class)->finalize (object);
@@ -922,9 +987,9 @@
 
 	priv->mutex = g_mutex_new ();
 
-	priv->plugins = g_hash_table_new_full (g_str_hash, g_str_equal,
-					       (GDestroyNotify) g_free,
-					       NULL);
+	priv->plugins_perscheme = g_hash_table_new_full (g_str_hash, g_str_equal,
+							 (GDestroyNotify) g_free,
+							 (GDestroyNotify) g_hash_table_unref);
 
 	/* We could increase the amount of threads to add some parallelism */
 

Modified: projects/haf/trunk/hildon-thumbnail/daemon/thumbnailer.h
===================================================================
--- projects/haf/trunk/hildon-thumbnail/daemon/thumbnailer.h	2008-10-28 13:33:31 UTC (rev 16514)
+++ projects/haf/trunk/hildon-thumbnail/daemon/thumbnailer.h	2008-10-28 15:04:09 UTC (rev 16515)
@@ -63,7 +63,7 @@
 void thumbnailer_copy (Thumbnailer *object, GStrv from_urls, GStrv to_urls, DBusGMethodInvocation *context);
 void thumbnailer_delete (Thumbnailer *object, GStrv urls, DBusGMethodInvocation *context);
 
-void thumbnailer_register_plugin (Thumbnailer *object, const gchar *mime_type, GModule *plugin, gboolean overwrite);
+void thumbnailer_register_plugin (Thumbnailer *object, const gchar *mime_type, GModule *plugin, const GStrv uri_schemes, gint priority);
 void thumbnailer_unregister_plugin (Thumbnailer *object, GModule *plugin);
 
 void thumbnailer_do_stop (void);


More information about the maemo-commits mailing list