[maemo-commits] [maemo-commits] r15961 - in projects/haf/branches/hildon-thumbnail/daemonize/daemon: . plugins
From: subversion at stage.maemo.org subversion at stage.maemo.orgDate: Tue Sep 2 18:22:54 EEST 2008
- Previous message: [maemo-commits] r15960 - projects/haf/branches/hildon-thumbnail/daemonize/daemon
- Next message: [maemo-commits] r15962 - in projects/haf/branches/hildon-thumbnail/daemonize: . daemon
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Author: pvanhoof Date: 2008-09-02 18:22:52 +0300 (Tue, 02 Sep 2008) New Revision: 15961 Modified: projects/haf/branches/hildon-thumbnail/daemonize/daemon/hildon-thumbnail-plugin.c projects/haf/branches/hildon-thumbnail/daemonize/daemon/hildon-thumbnail-plugin.h projects/haf/branches/hildon-thumbnail/daemonize/daemon/plugins/default.c projects/haf/branches/hildon-thumbnail/daemonize/daemon/thumbnailer.c Log: Trying to make up my mind about async plugins Modified: projects/haf/branches/hildon-thumbnail/daemonize/daemon/hildon-thumbnail-plugin.c =================================================================== --- projects/haf/branches/hildon-thumbnail/daemonize/daemon/hildon-thumbnail-plugin.c 2008-09-02 15:01:04 UTC (rev 15960) +++ projects/haf/branches/hildon-thumbnail/daemonize/daemon/hildon-thumbnail-plugin.c 2008-09-02 15:22:52 UTC (rev 15961) @@ -61,14 +61,14 @@ } } -typedef void (*CreateFunc) (GStrv uris, create_cb callback, gpointer user_data); +typedef void (*CreateFunc) (GStrv uris, GError **error); void -hildon_thumbnail_plugin_do_create (GModule *module, GStrv uris, create_cb callback, gpointer user_data) +hildon_thumbnail_plugin_do_create (GModule *module, GStrv uris, GError **error) { CreateFunc func; if (g_module_symbol (module, "hildon_thumbnail_plugin_create", (gpointer *) &func)) { - (func) (uris, callback, user_data); + (func) (uris, error); } } Modified: projects/haf/branches/hildon-thumbnail/daemonize/daemon/hildon-thumbnail-plugin.h =================================================================== --- projects/haf/branches/hildon-thumbnail/daemonize/daemon/hildon-thumbnail-plugin.h 2008-09-02 15:01:04 UTC (rev 15960) +++ projects/haf/branches/hildon-thumbnail/daemonize/daemon/hildon-thumbnail-plugin.h 2008-09-02 15:22:52 UTC (rev 15961) @@ -40,9 +40,9 @@ void hildon_thumbnail_plugin_do_init (GModule *module, Thumbnailer *thumbnailer, GError **error); -void hildon_thumbnail_plugin_do_create (GModule *module, GStrv uris, - create_cb callback, - gpointer user_data); +void hildon_thumbnail_plugin_do_create (GModule *module, + GStrv uris, + GError **error); void hildon_thumbnail_plugin_do_stop (GModule *module, Thumbnailer *thumbnailer); Modified: projects/haf/branches/hildon-thumbnail/daemonize/daemon/plugins/default.c =================================================================== --- projects/haf/branches/hildon-thumbnail/daemonize/daemon/plugins/default.c 2008-09-02 15:01:04 UTC (rev 15960) +++ projects/haf/branches/hildon-thumbnail/daemonize/daemon/plugins/default.c 2008-09-02 15:22:52 UTC (rev 15961) @@ -14,49 +14,12 @@ return supported; } -typedef struct { - GStrv uris; - create_cb cb; - gpointer user_data; -} CreateInfo; - - -static gboolean -on_finished (CreateInfo *info) -{ - // Returning back the same uris is of course not right :). The first - // param should be set with the uris made for the uris in info->uris, - // else the second parameter, the error, must be set - - info->cb (info->uris, NULL, info->user_data); - - return FALSE; -} - -static void -on_destroy (CreateInfo *info) -{ - g_slice_free (CreateInfo, info); -} - void -hildon_thumbnail_plugin_create (GStrv uris, create_cb callback, gpointer user_data) +hildon_thumbnail_plugin_create (GStrv uris, GError **error) { - CreateInfo *info = g_slice_new (CreateInfo); - - info->uris = uris; - info->cb = callback; - info->user_data = user_data; - - // This is of course a dummy implementation - - g_idle_add_full (G_PRIORITY_DEFAULT, - (GSourceFunc) on_finished, - info, - (GDestroyNotify) on_destroy); + return; } - void hildon_thumbnail_plugin_stop (void) { Modified: projects/haf/branches/hildon-thumbnail/daemonize/daemon/thumbnailer.c =================================================================== --- projects/haf/branches/hildon-thumbnail/daemonize/daemon/thumbnailer.c 2008-09-02 15:01:04 UTC (rev 15960) +++ projects/haf/branches/hildon-thumbnail/daemonize/daemon/thumbnailer.c 2008-09-02 15:22:52 UTC (rev 15961) @@ -66,50 +66,7 @@ plugin); } -typedef struct { - DBusGProxy *proxy; - DBusGMethodInvocation *context; -} ProxyCallInfo; - -static void -on_create_finished (DBusGProxy *proxy, DBusGProxyCall *call_id, ProxyCallInfo *info) -{ - GError *error = NULL; - GStrv thumb_urls = NULL; - - dbus_g_proxy_end_call (proxy, call_id, - &error, - G_TYPE_STRV, - &thumb_urls); - - if (error) { - dbus_g_method_return_error (info->context, error); - g_clear_error (&error); - } else - dbus_g_method_return (info->context, thumb_urls); - - g_strfreev (thumb_urls); -} - -static void -on_create_destroy (ProxyCallInfo *info) -{ - g_object_unref (info->proxy); - g_slice_free (ProxyCallInfo, info); -} - -static void -on_plugin_finished (const GStrv thumb_urls, GError *error, DBusGMethodInvocation *context) -{ - if (error) { - dbus_g_method_return_error (context, error); - g_clear_error (&error); - } else - dbus_g_method_return (context, thumb_urls); -} - - static gchar * get_mime_type (const gchar *path) { @@ -148,6 +105,13 @@ return content_type; } +static void +cleanup_hash (gpointer key, gpointer value, gpointer user_data) +{ + if (value) + g_list_free (value); +} + void thumbnailer_create (Thumbnailer *object, GStrv urls, DBusGMethodInvocation *context) { @@ -156,9 +120,10 @@ guint i = 0; GHashTableIter iter; gpointer key, value; + gboolean had_error = FALSE; // TODO: dispatch this to an asynchronous handler that deals with items - // in a LIFO way + // in a LIFO way. For example a GThreadPool while (urls[i] != NULL) { GList *urls_for_mime; @@ -170,7 +135,7 @@ g_hash_table_iter_init (&iter, hash); - while (g_hash_table_iter_next (&iter, &key, &value)) { + while (g_hash_table_iter_next (&iter, &key, &value) && !had_error) { GList *urlm = value, *copy = urlm; GStrv urlss = (GStrv) g_malloc0 (sizeof (gchar *) * (g_list_length (urlm) + 1)); DBusGProxy *proxy; @@ -184,47 +149,61 @@ } g_list_free (urlm); + g_hash_table_iter_remove (&iter); proxy = manager_get_handler (priv->manager, key); - if (proxy) { - ProxyCallInfo *info = g_slice_new (ProxyCallInfo); + GError *error = NULL; + dbus_g_proxy_call (proxy, "Create", &error, + G_TYPE_STRV, urlss, + G_TYPE_INVALID, + G_TYPE_INVALID); - info->context = context; - info->proxy = proxy; + if (error) { + had_error = TRUE; + dbus_g_method_return_error (context, error); + g_clear_error (&error); + g_strfreev (urlss); + break; + } - // This shouldn't return per group (it will in the callback) - - dbus_g_proxy_begin_call (proxy, "Create", - (DBusGProxyCallNotify) on_create_finished, - info, - (GDestroyNotify) on_create_destroy, - G_TYPE_STRV, - urlss); - } else { GModule *module = g_hash_table_lookup (priv->plugins, key); if (module) { - // This shouldn't return per group (it will in the callback) + GError *error = NULL; - hildon_thumbnail_plugin_do_create (module, urlss, - (create_cb) on_plugin_finished, - context); + hildon_thumbnail_plugin_do_create (module, urlss, &error); + + if (error) { + had_error = TRUE; + dbus_g_method_return_error (context, error); + g_clear_error (&error); + g_strfreev (urlss); + break; + } + } else { - // This shouldn't return per group GError *error = NULL; - g_set_error (&error, - DBUS_ERROR, 0, - "No handler"); + had_error = TRUE; + g_set_error (&error, DBUS_ERROR, 0, + "No handler for %s", (gchar*) key); dbus_g_method_return_error (context, error); g_clear_error (&error); + g_strfreev (urlss); + break; } } g_strfreev (urlss); } + if (!had_error) + dbus_g_method_return (context); + else + g_hash_table_foreach (hash, cleanup_hash, NULL); + g_hash_table_unref (hash); + } void
- Previous message: [maemo-commits] r15960 - projects/haf/branches/hildon-thumbnail/daemonize/daemon
- Next message: [maemo-commits] r15962 - in projects/haf/branches/hildon-thumbnail/daemonize: . daemon
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]