[maemo-commits] [maemo-commits] r16122 - in projects/haf/branches/hildon-thumbnail/daemonize: . daemon

From: subversion at stage.maemo.org subversion at stage.maemo.org
Date: Mon Sep 15 20:19:05 EEST 2008
Author: pvanhoof
Date: 2008-09-15 20:18:47 +0300 (Mon, 15 Sep 2008)
New Revision: 16122

Modified:
   projects/haf/branches/hildon-thumbnail/daemonize/ChangeLog
   projects/haf/branches/hildon-thumbnail/daemonize/daemon/hildon-thumbnail-daemon.c
   projects/haf/branches/hildon-thumbnail/daemonize/daemon/manager.c
   projects/haf/branches/hildon-thumbnail/daemonize/daemon/thumbnailer.c
Log:
2008-09-15  Philip Van Hoof  <pvanhoof at gnome.org>

	* daemon/hildon-thumbnail-daemon.c: Memory leak fix

	* daemon/hildon-thumbnail-daemon.c:
	* daemon/manager.c:
	* daemon/thumbnailer.c: Keep alive for ten minutes



Modified: projects/haf/branches/hildon-thumbnail/daemonize/ChangeLog
===================================================================
--- projects/haf/branches/hildon-thumbnail/daemonize/ChangeLog	2008-09-15 17:17:35 UTC (rev 16121)
+++ projects/haf/branches/hildon-thumbnail/daemonize/ChangeLog	2008-09-15 17:18:47 UTC (rev 16122)
@@ -1,4 +1,13 @@
+2008-09-15  Philip Van Hoof  <pvanhoof at gnome.org>
+
+	* daemon/hildon-thumbnail-daemon.c: Memory leak fix
+
+	* daemon/hildon-thumbnail-daemon.c:
+	* daemon/manager.c:
+	* daemon/thumbnailer.c: Keep alive for ten minutes
+
 2008-09-15  Mikael Ottela    <mikael.ottela at ixonos.com>
+
 	* configure.ac:
 	* daemon/hildon-thumbnail-daemon.c:
 	* daemon/plugins/gstreamer-video-plugin.h:

Modified: projects/haf/branches/hildon-thumbnail/daemonize/daemon/hildon-thumbnail-daemon.c
===================================================================
--- projects/haf/branches/hildon-thumbnail/daemonize/daemon/hildon-thumbnail-daemon.c	2008-09-15 17:17:35 UTC (rev 16121)
+++ projects/haf/branches/hildon-thumbnail/daemonize/daemon/hildon-thumbnail-daemon.c	2008-09-15 17:18:47 UTC (rev 16122)
@@ -31,6 +31,29 @@
 #include "thumbnailer.h"
 #include "manager.h"
 
+static gboolean do_shut_down_next_time = TRUE;
+
+void
+keep_alive (void) 
+{
+	do_shut_down_next_time = FALSE;
+}
+
+static gboolean
+shut_down_after_timeout (gpointer user_data)
+{
+	GMainLoop *main_loop =  user_data;
+	gboolean shut = FALSE;
+
+	if (do_shut_down_next_time) {
+		g_main_loop_quit (main_loop);
+		shut = TRUE;
+	} else
+		do_shut_down_next_time = TRUE;
+
+	return shut;
+}
+
 int 
 main (int argc, char **argv) 
 {
@@ -56,8 +79,11 @@
 		DBusGProxy *manager_proxy;
 		guint y = 0;
 		gboolean cropping;
-		GDir        *dir;
+		GDir *dir;
 		const gchar *plugin;
+		GHashTable *registrations;
+		GHashTableIter iter;
+		gpointer key, value;
 
 		manager_do_init (connection, &manager, &error);
 		thumbnailer_do_init (connection, manager, &thumbnailer, &error);
@@ -67,37 +93,47 @@
 					   MANAGER_PATH,
 					   MANAGER_INTERFACE);
 
+		registrations = g_hash_table_new_full (g_str_hash, g_str_equal,
+						       (GDestroyNotify) g_free, 
+						       (GDestroyNotify) NULL);
+
 		dir = g_dir_open (PLUGINS_DIR, 0, &error);
 
-		if (!dir) {
-			g_error ("Error opening modules directory: %s", error->message);
-			g_error_free (error);
-			return;
-		}
+		if (dir) {
+		  while ((plugin = g_dir_read_name (dir)) != NULL) {
 
-		while ((plugin = g_dir_read_name (dir)) != NULL) {
-
 			if (!g_str_has_suffix (plugin, "." G_MODULE_SUFFIX)) {
 				continue;
 			}
 			
 			module = hildon_thumbnail_plugin_load (plugin);
-
 			hildon_thumbnail_plugin_do_init (module, &cropping,
 							 (register_func) thumbnailer_register_plugin,
 							 thumbnailer,
 							 &error);
+			g_hash_table_replace (registrations, g_strdup (plugin),
+					      module);
 			y++;
+		  }
+		  g_dir_close (dir);
 		}
 
-		g_dir_close (dir);
+		g_timeout_add_seconds (600, 
+				       shut_down_after_timeout,
+				       main_loop);
 
 		main_loop = g_main_loop_new (NULL, FALSE);
 		g_main_loop_run (main_loop);
 
-		thumbnailer_unregister_plugin (thumbnailer, module);
-		hildon_thumbnail_plugin_do_stop (module);
+		g_hash_table_iter_init (&iter, registrations);
 
+		while (g_hash_table_iter_next (&iter, &key, &value))  {
+			thumbnailer_unregister_plugin (thumbnailer, value);
+			hildon_thumbnail_plugin_do_stop (module);
+		}
+
+		g_hash_table_unref (registrations);
+
 		manager_do_stop ();
 		thumbnailer_do_stop ();
 

Modified: projects/haf/branches/hildon-thumbnail/daemonize/daemon/manager.c
===================================================================
--- projects/haf/branches/hildon-thumbnail/daemonize/daemon/manager.c	2008-09-15 17:17:35 UTC (rev 16121)
+++ projects/haf/branches/hildon-thumbnail/daemonize/daemon/manager.c	2008-09-15 17:18:47 UTC (rev 16122)
@@ -40,6 +40,8 @@
 gchar* dbus_g_method_get_sender (DBusGMethodInvocation *context);
 #endif
 
+void keep_alive (void);
+
 typedef struct {
 	DBusGConnection *connection;
 	GHashTable *handlers;
@@ -312,6 +314,8 @@
 
 	dbus_async_return_if_fail (mime_type != NULL, context);
 
+	keep_alive ();
+
 	g_mutex_lock (priv->mutex);
 
 	mime_proxy = g_hash_table_lookup (priv->handlers, 
@@ -357,6 +361,8 @@
 	GList *copy;
 	guint y;
 
+	keep_alive ();
+
 	supported_h = g_hash_table_new_full (g_str_hash, g_str_equal,
 					     (GDestroyNotify) g_free, 
 					     (GDestroyNotify) NULL);

Modified: projects/haf/branches/hildon-thumbnail/daemonize/daemon/thumbnailer.c
===================================================================
--- projects/haf/branches/hildon-thumbnail/daemonize/daemon/thumbnailer.c	2008-09-15 17:17:35 UTC (rev 16121)
+++ projects/haf/branches/hildon-thumbnail/daemonize/daemon/thumbnailer.c	2008-09-15 17:18:47 UTC (rev 16122)
@@ -43,6 +43,9 @@
 
 G_DEFINE_TYPE (Thumbnailer, thumbnailer, G_TYPE_OBJECT)
 
+void keep_alive (void);
+
+
 typedef struct {
 	Manager *manager;
 	GHashTable *plugins;
@@ -164,6 +167,8 @@
 {
 	ThumbnailerPrivate *priv = THUMBNAILER_GET_PRIVATE (object);
 
+	keep_alive ();
+
 	g_mutex_lock (priv->mutex);
 	g_list_foreach (priv->tasks, (GFunc) mark_unqueued, (gpointer) handle);
 	g_mutex_unlock (priv->mutex);
@@ -178,6 +183,8 @@
 
 	dbus_async_return_if_fail (urls != NULL, context);
 
+	keep_alive ();
+
 	task->unqueued = FALSE;
 	task->num = ++num;
 	task->object = g_object_ref (object);
@@ -312,11 +319,15 @@
 		if (proxy) {
 			GError *error = NULL;
 
+			keep_alive ();
+
 			dbus_g_proxy_call (proxy, "Create", &error, 
 					   G_TYPE_STRV, urlss,
 					   G_TYPE_INVALID, 
 					   G_TYPE_INVALID);
 
+			keep_alive ();
+
 			g_object_unref (proxy);
 
 			if (error) {
@@ -336,8 +347,12 @@
 			if (module) {
 				GError *error = NULL;
 
+				keep_alive ();
+
 				hildon_thumbnail_plugin_do_create (module, urlss, &error);
 
+				keep_alive ();
+
 				if (error) {
 					g_signal_emit (task->object, signals[ERROR_SIGNAL],
 						       0, task->num, 1, error->message);
@@ -381,7 +396,9 @@
 {
 	dbus_async_return_if_fail (from_urls != NULL, context);
 	dbus_async_return_if_fail (to_urls != NULL, context);
-	
+
+	keep_alive ();
+
 	// TODO
 	
 	dbus_g_method_return (context);
@@ -392,7 +409,9 @@
 {
 	dbus_async_return_if_fail (from_urls != NULL, context);
 	dbus_async_return_if_fail (to_urls != NULL, context);
-	
+
+	keep_alive ();
+
 	// TODO
 	
 	dbus_g_method_return (context);
@@ -402,7 +421,9 @@
 thumbnailer_delete (Thumbnailer *object, GStrv urls, DBusGMethodInvocation *context)
 {
 	dbus_async_return_if_fail (urls != NULL, context);
-	
+
+	keep_alive ();
+
 	// TODO
 	
 	dbus_g_method_return (context);


More information about the maemo-commits mailing list