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

From: subversion at stage.maemo.org subversion at stage.maemo.org
Date: Wed Sep 3 12:17:26 EEST 2008
Author: pvanhoof
Date: 2008-09-03 12:17:24 +0300 (Wed, 03 Sep 2008)
New Revision: 15977

Added:
   projects/haf/branches/hildon-thumbnail/daemonize/daemon/thumbnailer-marshal.list
Modified:
   projects/haf/branches/hildon-thumbnail/daemonize/ChangeLog
   projects/haf/branches/hildon-thumbnail/daemonize/daemon/
   projects/haf/branches/hildon-thumbnail/daemonize/daemon/Makefile.am
   projects/haf/branches/hildon-thumbnail/daemonize/daemon/thumbnailer.c
   projects/haf/branches/hildon-thumbnail/daemonize/daemon/thumbnailer.h
   projects/haf/branches/hildon-thumbnail/daemonize/daemon/thumbnailer.xml
Log:
2008-09-03  Philip Van Hoof  <philip at codeminded.be>

        * daemon/thumbnailer.c
        * daemon/thumbnailer.h
        * daemon/thumbnailer-marshal.list
        * daemon/Makefile.am
        * daemon/thumbnailer.xml: Slightly different protocol, with queuing
        and unqueueing and added a few signals



Modified: projects/haf/branches/hildon-thumbnail/daemonize/ChangeLog
===================================================================
--- projects/haf/branches/hildon-thumbnail/daemonize/ChangeLog	2008-09-03 08:46:24 UTC (rev 15976)
+++ projects/haf/branches/hildon-thumbnail/daemonize/ChangeLog	2008-09-03 09:17:24 UTC (rev 15977)
@@ -1,3 +1,12 @@
+2008-09-03  Philip Van Hoof  <philip at codeminded.be>
+
+	* daemon/thumbnailer.c
+	* daemon/thumbnailer.h
+	* daemon/thumbnailer-marshal.list
+	* daemon/Makefile.am
+	* daemon/thumbnailer.xml: Slightly different protocol, with queuing
+	and unqueueing and added a few signals
+
 2008-09-02  Philip Van Hoof  <philip at codeminded.be>
 
 	* daemon/thumbnailer.c: Made the threadpool a LIFO


Property changes on: projects/haf/branches/hildon-thumbnail/daemonize/daemon
___________________________________________________________________
Name: svn:ignore
   - Makefile.in
hildon-thumbnailerd
.libs
.deps
org.freedesktop.thumbnailer.service
Makefile
*-glue.h


   + Makefile.in
hildon-thumbnailerd
.libs
.deps
org.freedesktop.thumbnailer.service
Makefile
*-glue.h
*-marshal.c
*-marshal.h


Modified: projects/haf/branches/hildon-thumbnail/daemonize/daemon/Makefile.am
===================================================================
--- projects/haf/branches/hildon-thumbnail/daemonize/daemon/Makefile.am	2008-09-03 08:46:24 UTC (rev 15976)
+++ projects/haf/branches/hildon-thumbnail/daemonize/daemon/Makefile.am	2008-09-03 09:17:24 UTC (rev 15977)
@@ -13,12 +13,21 @@
 
 include_HEADERS = hildon-thumbnail-plugin.h
 
+
+thumbnailer-marshal.h: thumbnailer-marshal.list
+	$(GLIB_GENMARSHAL) $< --prefix=thumbnailer_marshal --header > $@
+
+thumbnailer-marshal.c: thumbnailer-marshal.list
+	$(GLIB_GENMARSHAL) $< --prefix=thumbnailer_marshal --body > $@
+
 hildon_thumbnailerd_SOURCES = \
 	$(include_HEADERS) \
 	hildon-thumbnail-plugin.c \
 	hildon-thumbnail-daemon.c \
 	thumbnailer.c \
 	thumbnailer.h \
+	thumbnailer-marshal.c \
+	thumbnailer-marshal.h \
 	manager.c \
 	manager.h \
 	dbus-utils.h \
@@ -41,12 +50,14 @@
 %-glue.h: $(top_srcdir)/daemon/%.xml
 	$(DBUSBINDINGTOOL) --mode=glib-server --output=$@ --prefix=$(subst -,_,$*) $^
 
-BUILT_SOURCES = manager-glue.h thumbnailer-glue.h
+BUILT_SOURCES = manager-glue.h thumbnailer-glue.h \
+	thumbnailer-marshal.c thumbnailer-marshal.h
 configdir = $(datadir)/hildon-thumbnail
 config_DATA = manager.xml thumbnailer.xml
 
 EXTRA_DIST = $(BUILT_SOURCES) $(config_DATA) \
-	$(org.freedesktop.thumbnailer_service_DATA)
+	$(org.freedesktop.thumbnailer_service_DATA) \
+	thumbnailer-marshal.list
 
 
 CLEANFILES = $(BUILT_SOURCES) \

Added: projects/haf/branches/hildon-thumbnail/daemonize/daemon/thumbnailer-marshal.list
===================================================================
--- projects/haf/branches/hildon-thumbnail/daemonize/daemon/thumbnailer-marshal.list	2008-09-03 08:46:24 UTC (rev 15976)
+++ projects/haf/branches/hildon-thumbnail/daemonize/daemon/thumbnailer-marshal.list	2008-09-03 09:17:24 UTC (rev 15977)
@@ -0,0 +1 @@
+VOID:UINT,STRING

Modified: projects/haf/branches/hildon-thumbnail/daemonize/daemon/thumbnailer.c
===================================================================
--- projects/haf/branches/hildon-thumbnail/daemonize/daemon/thumbnailer.c	2008-09-03 08:46:24 UTC (rev 15976)
+++ projects/haf/branches/hildon-thumbnail/daemonize/daemon/thumbnailer.c	2008-09-03 09:17:24 UTC (rev 15977)
@@ -14,6 +14,7 @@
 
 #include "manager.h"
 #include "thumbnailer.h"
+#include "thumbnailer-marshal.h"
 #include "thumbnailer-glue.h"
 #include "hildon-thumbnail-plugin.h"
 #include "dbus-utils.h"
@@ -26,6 +27,8 @@
 	Manager *manager;
 	GHashTable *plugins;
 	GThreadPool *pool;
+	GMutex *mutex;
+	GList *tasks;
 } ThumbnailerPrivate;
 
 enum {
@@ -33,7 +36,15 @@
 	PROP_MANAGER
 };
 
+enum {
+	STARTED_SIGNAL,
+	READY_SIGNAL,
+	ERROR_SIGNAL,
+	LAST_SIGNAL
+};
 
+static guint signals[LAST_SIGNAL] = { 0, };
+
 void 
 thumbnailer_register_plugin (Thumbnailer *object, const gchar *mime_type, GModule *plugin)
 {
@@ -111,8 +122,8 @@
 typedef struct {
 	Thumbnailer *object;
 	GStrv urls;
-	DBusGMethodInvocation *context;
 	guint num;
+	gboolean unqueued;
 } WorkTask;
 
 
@@ -127,16 +138,34 @@
 	return task_b->num - task_a->num;
 }
 
+static void 
+mark_unqueued (WorkTask *task, guint handle)
+{
+	if (task->num == handle)
+		task->unqueued = TRUE;
+}
+
 void
-thumbnailer_create (Thumbnailer *object, GStrv urls, DBusGMethodInvocation *context)
+thumbnailer_unqueue (Thumbnailer *object, guint handle, DBusGMethodInvocation *context)
 {
 	ThumbnailerPrivate *priv = THUMBNAILER_GET_PRIVATE (object);
+
+	g_mutex_lock (priv->mutex);
+	g_list_foreach (priv->tasks, (GFunc) mark_unqueued, (gpointer) handle);
+	g_mutex_unlock (priv->mutex);
+}
+
+void
+thumbnailer_queue (Thumbnailer *object, GStrv urls, DBusGMethodInvocation *context)
+{
+	ThumbnailerPrivate *priv = THUMBNAILER_GET_PRIVATE (object);
 	WorkTask *task = g_slice_new (WorkTask);
 	guint urls_size = g_strv_length (urls), i = 0;
 	static guint num = 0;
 
 	dbus_async_return_if_fail (urls != NULL, context);
 
+	task->unqueued = FALSE;
 	task->num = num++;
 	task->object = g_object_ref (object);
 	task->urls = (GStrv) g_malloc0 (sizeof (gchar *) * (urls_size + 1));
@@ -147,9 +176,13 @@
 	}
 
 	task->urls[i] = NULL;
-	task->context = context;
 
+	g_mutex_lock (priv->mutex);
+	priv->tasks = g_list_prepend (priv->tasks, task);
 	g_thread_pool_push (priv->pool, task, NULL);
+	g_mutex_unlock (priv->mutex);
+
+	dbus_g_method_return (context, num);
 }
 
 /* This is the threadpool's function. This means that everything we do is 
@@ -164,16 +197,28 @@
 do_the_work (WorkTask *task, gpointer user_data)
 {
 	ThumbnailerPrivate *priv = THUMBNAILER_GET_PRIVATE (task->object);
-	GHashTable *hash = g_hash_table_new (g_str_hash, g_str_equal);
+	GHashTable *hash;
 	GStrv urls = task->urls;
-	DBusGMethodInvocation *context = task->context;
 	guint i = 0;
 	GHashTableIter iter;
 	gpointer key, value;
 	gboolean had_error = FALSE;
 
+	g_mutex_lock (priv->mutex);
+	priv->tasks = g_list_remove (priv->tasks, task);
+	if (task->unqueued) {
+		g_mutex_unlock (priv->mutex);
+		goto unqueued;
+	}
+	g_mutex_unlock (priv->mutex);
+
 	/* We split the request into groups that have items with the same mime-type */
 
+	g_signal_emit (task->object, signals[STARTED_SIGNAL], 0,
+			task->num);
+
+	hash = g_hash_table_new (g_str_hash, g_str_equal);
+
 	while (urls[i] != NULL) {
 		GList *urls_for_mime;
 		gchar *mime_type = get_mime_type (urls[i]);
@@ -219,7 +264,8 @@
 
 			if (error) {
 				had_error = TRUE;
-				dbus_g_method_return_error (context, error);
+				g_signal_emit (task->object, signals[ERROR_SIGNAL], 0,
+					       task->num, error->message);
 				g_clear_error (&error);
 				g_strfreev (urlss);
 				break;
@@ -237,7 +283,8 @@
 
 				if (error) {
 					had_error = TRUE;
-					dbus_g_method_return_error (context, error);
+					g_signal_emit (task->object, signals[ERROR_SIGNAL], 0,
+						       task->num, error->message);
 					g_clear_error (&error);
 					g_strfreev (urlss);
 					break;
@@ -253,12 +300,15 @@
 	}
 
 	if (!had_error)
-		dbus_g_method_return (context);
+		g_signal_emit (task->object, signals[READY_SIGNAL], 0,
+			       task->num);
 	else
 		g_hash_table_foreach (hash, cleanup_hash, NULL);
 
 	g_hash_table_unref (hash);
 
+unqueued:
+
 	/* task->context will always be returned by now */
 
 	g_object_unref (task->object);
@@ -273,12 +323,31 @@
 {
 	dbus_async_return_if_fail (from_urls != NULL, context);
 	dbus_async_return_if_fail (to_urls != NULL, context);
+	
+	// TODO
+	
+	dbus_g_method_return (context);
 }
 
 void
+thumbnailer_copy (Thumbnailer *object, GStrv from_urls, GStrv to_urls, DBusGMethodInvocation *context)
+{
+	dbus_async_return_if_fail (from_urls != NULL, context);
+	dbus_async_return_if_fail (to_urls != NULL, context);
+	
+	// TODO
+	
+	dbus_g_method_return (context);
+}
+
+void
 thumbnailer_delete (Thumbnailer *object, GStrv urls, DBusGMethodInvocation *context)
 {
 	dbus_async_return_if_fail (urls != NULL, context);
+	
+	// TODO
+	
+	dbus_g_method_return (context);
 }
 
 static void
@@ -290,8 +359,8 @@
 
 	g_object_unref (priv->manager);
 	g_hash_table_unref (priv->plugins);
+	g_mutex_free (priv->mutex);
 
-
 	G_OBJECT_CLASS (thumbnailer_parent_class)->finalize (object);
 }
 
@@ -358,6 +427,40 @@
 							      G_PARAM_READWRITE |
 							      G_PARAM_CONSTRUCT));
 
+	signals[READY_SIGNAL] =
+		g_signal_new ("Ready",
+			      G_OBJECT_CLASS_TYPE (object_class),
+			      G_SIGNAL_RUN_LAST,
+			      G_STRUCT_OFFSET (ThumbnailerClass, ready),
+			      NULL, NULL,
+			      g_cclosure_marshal_VOID__UINT,
+			      G_TYPE_NONE,
+			      1,
+			      G_TYPE_UINT);
+
+	signals[STARTED_SIGNAL] =
+		g_signal_new ("Started",
+			      G_OBJECT_CLASS_TYPE (object_class),
+			      G_SIGNAL_RUN_LAST,
+			      G_STRUCT_OFFSET (ThumbnailerClass, ready),
+			      NULL, NULL,
+			      g_cclosure_marshal_VOID__UINT,
+			      G_TYPE_NONE,
+			      1,
+			      G_TYPE_UINT);
+
+	signals[ERROR_SIGNAL] =
+		g_signal_new ("Error",
+			      G_OBJECT_CLASS_TYPE (object_class),
+			      G_SIGNAL_RUN_LAST,
+			      G_STRUCT_OFFSET (ThumbnailerClass, error),
+			      NULL, NULL,
+			      thumbnailer_marshal_VOID__UINT_STRING,
+			      G_TYPE_NONE,
+			      2,
+			      G_TYPE_UINT,
+			      G_TYPE_STRING);
+
 	g_type_class_add_private (object_class, sizeof (ThumbnailerPrivate));
 }
 
@@ -366,6 +469,8 @@
 {
 	ThumbnailerPrivate *priv = THUMBNAILER_GET_PRIVATE (object);
 
+	priv->mutex = g_mutex_new ();
+
 	priv->plugins = g_hash_table_new_full (g_str_hash, g_str_equal,
 					       (GDestroyNotify) g_free,
 					       NULL);

Modified: projects/haf/branches/hildon-thumbnail/daemonize/daemon/thumbnailer.h
===================================================================
--- projects/haf/branches/hildon-thumbnail/daemonize/daemon/thumbnailer.h	2008-09-03 08:46:24 UTC (rev 15976)
+++ projects/haf/branches/hildon-thumbnail/daemonize/daemon/thumbnailer.h	2008-09-03 09:17:24 UTC (rev 15977)
@@ -23,12 +23,18 @@
 
 struct ThumbnailerClass {
 	GObjectClass parent;
+
+	void (*started) (Thumbnailer *object, guint handle);
+	void (*ready) (Thumbnailer *object, guint handle);
+	void (*error) (Thumbnailer *object, guint handle, gchar *reason);
 };
 
 GType thumbnailer_get_type (void);
 
-void thumbnailer_create (Thumbnailer *object, GStrv urls, DBusGMethodInvocation *context);
+void thumbnailer_queue (Thumbnailer *object, GStrv urls, DBusGMethodInvocation *context);
+void thumbnailer_unqueue (Thumbnailer *object, guint handle, DBusGMethodInvocation *context);
 void thumbnailer_move (Thumbnailer *object, GStrv from_urls, GStrv to_urls, DBusGMethodInvocation *context);
+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);

Modified: projects/haf/branches/hildon-thumbnail/daemonize/daemon/thumbnailer.xml
===================================================================
--- projects/haf/branches/hildon-thumbnail/daemonize/daemon/thumbnailer.xml	2008-09-03 08:46:24 UTC (rev 15976)
+++ projects/haf/branches/hildon-thumbnail/daemonize/daemon/thumbnailer.xml	2008-09-03 09:17:24 UTC (rev 15977)
@@ -1,18 +1,47 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <node name="/">
   <interface name="org.freedesktop.thumbnailer">  
-    <method name="Create">
+
+    <method name="Queue">
       <annotation name="org.freedesktop.DBus.GLib.Async" value="true"/>
       <arg type="as" name="uris" direction="in" />
+      <arg type="u" name="handle" direction="out" />
     </method>
+
+    <method name="Unqueue">
+      <annotation name="org.freedesktop.DBus.GLib.Async" value="true"/>
+      <arg type="u" name="handle" direction="out" />
+    </method>
+
+    <signal name="Started">
+      <arg type="u" name="handle" />
+    </signal>
+
+    <signal name="Ready">
+      <arg type="u" name="handle" />
+    </signal>
+
+    <signal name="Error">
+      <arg type="u" name="handle" />
+      <arg type="s" name="reason" />
+    </signal>
+
     <method name="Move">
       <annotation name="org.freedesktop.DBus.GLib.Async" value="true"/>
       <arg type="as" name="from_uris" direction="in" />
       <arg type="as" name="to_uris" direction="in" />
     </method>
+
+    <method name="Copy">
+      <annotation name="org.freedesktop.DBus.GLib.Async" value="true"/>
+      <arg type="as" name="from_uris" direction="in" />
+      <arg type="as" name="to_uris" direction="in" />
+    </method>
+
     <method name="Delete">
       <annotation name="org.freedesktop.DBus.GLib.Async" value="true"/>
       <arg type="as" name="uris" direction="in" />
     </method>
+
   </interface>
 </node>


More information about the maemo-commits mailing list