[Xfce4-commits] <tumbler:master> Switch to a plugin API that only allows one cache backend at a time.

Jannis Pohlmann noreply at xfce.org
Tue Oct 27 03:22:02 CET 2009


Updating branch refs/heads/master
         to 7a1e43d0806ec976eb2872209affb3d8a0dad7d0 (commit)
       from 8258763e662bc2345051f230f2afc4b6da699726 (commit)

commit 7a1e43d0806ec976eb2872209affb3d8a0dad7d0
Author: Jannis Pohlmann <jannis at xfce.org>
Date:   Mon Oct 26 22:36:08 2009 +0100

    Switch to a plugin API that only allows one cache backend at a time.
    
    Tumbler will now only check for the file
    
      $(libdir)/tumbler-1/plugins/cache/tumbler-cache-plugin.so
    
    which is supposed to link to the cache backend that is being used. If
    the XDG cache is built, tumbler-cache-plugin.so is set up to link to
    this plugin.
    
    The fact that we only have a singleton cache makes things much less
    ambiguous.

 plugins/xdg-cache/Makefile.am           |   10 +++-
 plugins/xdg-cache/xdg-cache-cache.c     |    2 +-
 plugins/xdg-cache/xdg-cache-cache.h     |    2 +-
 plugins/xdg-cache/xdg-cache-plugin.c    |   26 +++-------
 plugins/xdg-cache/xdg-cache-thumbnail.c |    2 +-
 plugins/xdg-cache/xdg-cache-thumbnail.h |    2 +-
 tumbler/Makefile.am                     |    4 +-
 tumbler/tumbler-cache.c                 |   28 ++++++++++
 tumbler/tumbler-cache.h                 |   34 +++++++------
 tumbler/tumbler-file-info.c             |   84 +++++++++++-------------------
 tumbler/tumbler-provider-plugin.c       |    4 +-
 tumbler/tumbler.h                       |    2 +-
 tumblerd/tumbler-cache-service.c        |   43 ++++++----------
 13 files changed, 115 insertions(+), 128 deletions(-)

diff --git a/plugins/xdg-cache/Makefile.am b/plugins/xdg-cache/Makefile.am
index 14cb770..0073196 100644
--- a/plugins/xdg-cache/Makefile.am
+++ b/plugins/xdg-cache/Makefile.am
@@ -19,7 +19,7 @@
 
 if TUMBLER_XDG_CACHE
 
-tumbler_plugindir = $(libdir)/tumbler-$(TUMBLER_VERSION_API)/plugins
+tumbler_plugindir = $(libdir)/tumbler-$(TUMBLER_VERSION_API)/plugins/cache
 tumbler_plugin_LTLIBRARIES =						\
 	tumbler-xdg-cache.la
 
@@ -27,8 +27,6 @@ tumbler_xdg_cache_la_SOURCES =						\
 	xdg-cache-cache.c						\
 	xdg-cache-cache.h						\
 	xdg-cache-plugin.c						\
-	xdg-cache-provider.c						\
-	xdg-cache-provider.h						\
 	xdg-cache-thumbnail.c						\
 	xdg-cache-thumbnail.h
 
@@ -57,4 +55,10 @@ tumbler_xdg_cache_la_LIBADD =						\
 	$(GLIB_LIBS)							\
 	$(PNG_LIBS)
 
+# install symlink to 'tumbler-cache-plugin.so'
+install-data-local:
+	$(mkinstalldirs) $(DESTDIR)$(tumbler_plugindir)
+	-( cd $(DESTDIR)$(tumbler_plugindir) ; \
+		test -x tumbler-xdg-cache.so || \
+		ln -sf tumbler-xdg-cache.so tumbler-cache-plugin.so )
 endif
diff --git a/plugins/xdg-cache/xdg-cache-cache.c b/plugins/xdg-cache/xdg-cache-cache.c
index 7ee6518..add9a16 100644
--- a/plugins/xdg-cache/xdg-cache-cache.c
+++ b/plugins/xdg-cache/xdg-cache-cache.c
@@ -102,7 +102,7 @@ static const FlavorInfo flavor_infos[] =
 
 
 void
-xdg_cache_cache_register (TumblerProviderPlugin *plugin)
+xdg_cache_cache_register (TumblerCachePlugin *plugin)
 {
   xdg_cache_cache_register_type (G_TYPE_MODULE (plugin));
 }
diff --git a/plugins/xdg-cache/xdg-cache-cache.h b/plugins/xdg-cache/xdg-cache-cache.h
index dbabeac..2e32641 100644
--- a/plugins/xdg-cache/xdg-cache-cache.h
+++ b/plugins/xdg-cache/xdg-cache-cache.h
@@ -38,7 +38,7 @@ typedef struct _XDGCacheCacheClass XDGCacheCacheClass;
 typedef struct _XDGCacheCache      XDGCacheCache;
 
 GType    xdg_cache_cache_get_type             (void) G_GNUC_CONST;
-void     xdg_cache_cache_register             (TumblerProviderPlugin *plugin);
+void     xdg_cache_cache_register             (TumblerCachePlugin    *plugin);
 
 GFile   *xdg_cache_cache_get_file             (const gchar           *uri,
                                                TumblerThumbnailFlavor flavor) G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT;
diff --git a/plugins/xdg-cache/xdg-cache-plugin.c b/plugins/xdg-cache/xdg-cache-plugin.c
index 93afd9c..8faba4e 100644
--- a/plugins/xdg-cache/xdg-cache-plugin.c
+++ b/plugins/xdg-cache/xdg-cache-plugin.c
@@ -29,24 +29,18 @@
 #include <tumbler/tumbler.h>
 
 #include <xdg-cache/xdg-cache-cache.h>
-#include <xdg-cache/xdg-cache-provider.h>
 #include <xdg-cache/xdg-cache-thumbnail.h>
 
 
 
-G_MODULE_EXPORT void tumbler_plugin_initialize (TumblerProviderPlugin *plugin);
-G_MODULE_EXPORT void tumbler_plugin_shutdown   (void);
-G_MODULE_EXPORT void tumbler_plugin_get_types  (const GType          **types,
-                                                gint                  *n_types);
-
-
-
-static GType type_list[1];
+G_MODULE_EXPORT void          tumbler_plugin_initialize (TumblerCachePlugin *plugin);
+G_MODULE_EXPORT void          tumbler_plugin_shutdown   (void);
+G_MODULE_EXPORT TumblerCache *tumbler_plugin_get_types  (void);
 
 
 
 void
-tumbler_plugin_initialize (TumblerProviderPlugin *plugin)
+tumbler_plugin_initialize (TumblerCachePlugin *plugin)
 {
   const gchar *mismatch;
 
@@ -65,11 +59,7 @@ tumbler_plugin_initialize (TumblerProviderPlugin *plugin)
 
   /* register the types provided by this plugin */
   xdg_cache_cache_register (plugin);
-  xdg_cache_provider_register (plugin);
   xdg_cache_thumbnail_register (plugin);
-
-  /* set up the plugin provider type list */
-  type_list[0] = XDG_CACHE_TYPE_PROVIDER;
 }
 
 
@@ -84,10 +74,8 @@ tumbler_plugin_shutdown (void)
 
 
 
-void
-tumbler_plugin_get_types (const GType **types,
-                          gint         *n_types)
+TumblerCache *
+tumbler_plugin_get_cache (void)
 {
-  *types = type_list;
-  *n_types = G_N_ELEMENTS (type_list);
+  return g_object_new (XDG_CACHE_TYPE_CACHE, NULL);
 }
diff --git a/plugins/xdg-cache/xdg-cache-thumbnail.c b/plugins/xdg-cache/xdg-cache-thumbnail.c
index 40100aa..d07a8ce 100644
--- a/plugins/xdg-cache/xdg-cache-thumbnail.c
+++ b/plugins/xdg-cache/xdg-cache-thumbnail.c
@@ -102,7 +102,7 @@ G_DEFINE_DYNAMIC_TYPE_EXTENDED (XDGCacheThumbnail,
 
 
 void
-xdg_cache_thumbnail_register (TumblerProviderPlugin *plugin)
+xdg_cache_thumbnail_register (TumblerCachePlugin *plugin)
 {
   xdg_cache_thumbnail_register_type (G_TYPE_MODULE (plugin));
 }
diff --git a/plugins/xdg-cache/xdg-cache-thumbnail.h b/plugins/xdg-cache/xdg-cache-thumbnail.h
index ed77103..c5698b2 100644
--- a/plugins/xdg-cache/xdg-cache-thumbnail.h
+++ b/plugins/xdg-cache/xdg-cache-thumbnail.h
@@ -38,7 +38,7 @@ typedef struct _XDGCacheThumbnailClass XDGCacheThumbnailClass;
 typedef struct _XDGCacheThumbnail      XDGCacheThumbnail;
 
 GType xdg_cache_thumbnail_get_type (void) G_GNUC_CONST;
-void  xdg_cache_thumbnail_register (TumblerProviderPlugin *plugin);
+void  xdg_cache_thumbnail_register (TumblerCachePlugin *plugin);
 
 G_END_DECLS;
 
diff --git a/tumbler/Makefile.am b/tumbler/Makefile.am
index 3d32f4d..12f8d0b 100644
--- a/tumbler/Makefile.am
+++ b/tumbler/Makefile.am
@@ -30,7 +30,7 @@ libtumbler_built_sources =						\
 libtumbler_headers =							\
 	tumbler-abstract-thumbnailer.h					\
 	tumbler-cache.h							\
-	tumbler-cache-provider.h					\
+	tumbler-cache-plugin.h						\
 	tumbler-config.h						\
 	tumbler-enum-types.h						\
 	tumbler-error.h							\
@@ -48,7 +48,7 @@ libtumbler_headers =							\
 libtumbler_sources =							\
 	tumbler-abstract-thumbnailer.c					\
 	tumbler-cache.c							\
-	tumbler-cache-provider.c					\
+	tumbler-cache-plugin.c						\
 	tumbler-config.c						\
 	tumbler-enum-types.c						\
 	tumbler-file-info.c						\
diff --git a/tumbler/tumbler-cache.c b/tumbler/tumbler-cache.c
index d1232b1..cdb5156 100644
--- a/tumbler/tumbler-cache.c
+++ b/tumbler/tumbler-cache.c
@@ -25,6 +25,7 @@
 #include <glib-object.h>
 
 #include <tumbler/tumbler-cache.h>
+#include <tumbler/tumbler-cache-plugin.h>
 
 
 
@@ -54,6 +55,33 @@ tumbler_cache_get_type (void)
 
 
 
+TumblerCache *
+tumbler_cache_get_default (void)
+{
+  static TumblerCache *cache = NULL;
+  GTypeModule         *plugin;
+
+  if (cache == NULL)
+    {
+      plugin = tumbler_cache_plugin_get_default ();
+
+      if (plugin != NULL)
+        {
+          cache = tumbler_cache_plugin_get_cache (TUMBLER_CACHE_PLUGIN (plugin));
+          g_object_add_weak_pointer (G_OBJECT (cache), (gpointer) &cache);
+          g_type_module_unuse (plugin);
+        }
+    }
+  else
+    {
+      g_object_ref (cache);
+    }
+     
+  return cache;
+}
+
+
+
 GList *
 tumbler_cache_get_thumbnails (TumblerCache *cache,
                               const gchar  *uri)
diff --git a/tumbler/tumbler-cache.h b/tumbler/tumbler-cache.h
index c1a1e42..7e42539 100644
--- a/tumbler/tumbler-cache.h
+++ b/tumbler/tumbler-cache.h
@@ -61,23 +61,25 @@ struct _TumblerCacheIface
                               const gchar  *uri);
 };
 
-GType    tumbler_cache_get_type (void) G_GNUC_CONST;
+GType         tumbler_cache_get_type (void) G_GNUC_CONST;
 
-GList   *tumbler_cache_get_thumbnails (TumblerCache *cache,
-                                       const gchar  *uri) G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT;
-void     tumbler_cache_cleanup        (TumblerCache *cache,
-                                       const gchar  *uri_prefix,
-                                       guint64       since);
-void     tumbler_cache_delete         (TumblerCache *cache,
-                                       const GStrv   uris);
-void     tumbler_cache_copy           (TumblerCache *cache,
-                                       const GStrv   from_uris,
-                                       const GStrv   to_uris);
-void     tumbler_cache_move           (TumblerCache *cache,
-                                       const GStrv   from_uris,
-                                       const GStrv   to_uris);
-gboolean tumbler_cache_is_thumbnail   (TumblerCache *cache,
-                                       const gchar  *uri);
+TumblerCache *tumbler_cache_get_default    (void) G_GNUC_WARN_UNUSED_RESULT;
+
+GList        *tumbler_cache_get_thumbnails (TumblerCache *cache,
+                                            const gchar  *uri) G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT;
+void          tumbler_cache_cleanup        (TumblerCache *cache,
+                                            const gchar  *uri_prefix,
+                                            guint64       since);
+void          tumbler_cache_delete         (TumblerCache *cache,
+                                            const GStrv   uris);
+void          tumbler_cache_copy           (TumblerCache *cache,
+                                            const GStrv   from_uris,
+                                            const GStrv   to_uris);
+void          tumbler_cache_move           (TumblerCache *cache,
+                                            const GStrv   from_uris,
+                                            const GStrv   to_uris);
+gboolean      tumbler_cache_is_thumbnail   (TumblerCache *cache,
+                                            const gchar  *uri);
 
 G_END_DECLS
 
diff --git a/tumbler/tumbler-file-info.c b/tumbler/tumbler-file-info.c
index 80b8d69..c2cbde8 100644
--- a/tumbler/tumbler-file-info.c
+++ b/tumbler/tumbler-file-info.c
@@ -193,15 +193,14 @@ tumbler_file_info_load (TumblerFileInfo *info,
                         GError         **error)
 {
   TumblerProviderFactory *provider_factory;
-  GFileInfo *file_info;
-  GError    *err = NULL;
-  GFile     *file;
-  GList     *caches;
-  GList     *cp;
-  GList     *lp;
-  GList     *providers;
-  GList     *thumbnails;
-  GList     *tp;
+  TumblerCache           *cache;
+  GFileInfo              *file_info;
+  GError                 *err = NULL;
+  GFile                  *file;
+  GList                  *cp;
+  GList                  *lp;
+  GList                  *thumbnails;
+  GList                  *tp;
 
   g_return_val_if_fail (TUMBLER_IS_FILE_INFO (info), FALSE);
   g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), FALSE);
@@ -237,57 +236,36 @@ tumbler_file_info_load (TumblerFileInfo *info,
   g_list_free (info->thumbnails);
   info->thumbnails = NULL;
 
-  /* get the provider factory */
-  provider_factory = tumbler_provider_factory_get_default ();
-
-  /* query a list of cache providers */
-  providers = tumbler_provider_factory_get_providers (provider_factory, 
-                                                      TUMBLER_TYPE_CACHE_PROVIDER);
-
-  /* iterate over all available cache providers */
-  for (lp = providers; err == NULL && lp != NULL; lp = lp->next)
+  /* query the default cache implementation */
+  cache = tumbler_cache_get_default ();
+  if (cache != NULL)
     {
-      /* query a list of cache implementations from the current provider */
-      caches = tumbler_cache_provider_get_caches (lp->data);
+      /* check if the file itself is a thumbnail */
+      if (!tumbler_cache_is_thumbnail (cache, info->uri))
+        {
+          /* query thumbnail infos for this URI from the current cache */
+          thumbnails = tumbler_cache_get_thumbnails (cache, info->uri);
+
+          /* try to load thumbnail infos. the loop will terminate if 
+           * one of them fails */
+          for (tp = thumbnails; err == NULL && tp != NULL; tp = tp->next)
+            tumbler_thumbnail_load (tp->data, cancellable, &err);
 
-      /* iterate over all available cache implementations */
-      for (cp = caches; err == NULL && cp != NULL; cp = cp->next)
+          /* add all queried thumbnails to the list */
+          info->thumbnails = g_list_concat (info->thumbnails, 
+                                                  thumbnails);
+        }
+      else
         {
-          /* check if the file itself is a thumbnail */
-          if (!tumbler_cache_is_thumbnail (cp->data, info->uri))
-            {
-              /* query thumbnail infos for this URI from the current cache */
-              thumbnails = tumbler_cache_get_thumbnails (cp->data, info->uri);
-
-              /* try to load thumbnail infos. the loop will terminate if 
-               * one of them fails */
-              for (tp = thumbnails; err == NULL && tp != NULL; tp = tp->next)
-                tumbler_thumbnail_load (tp->data, cancellable, &err);
-
-              /* add all queried thumbnails to the list */
-              info->thumbnails = g_list_concat (info->thumbnails, 
-                                                      thumbnails);
-            }
-          else
-            {
-              /* we don't allow the generation of thumbnails for thumbnails */
-              g_set_error (&err, TUMBLER_ERROR, TUMBLER_ERROR_IS_THUMBNAIL,
-                           _("The file \"%s\" is a thumbnail itself"), info->uri);
-            }
+          /* we don't allow the generation of thumbnails for thumbnails */
+          g_set_error (&err, TUMBLER_ERROR, TUMBLER_ERROR_IS_THUMBNAIL,
+                       _("The file \"%s\" is a thumbnail itself"), info->uri);
         }
 
-      /* release cache references */
-      g_list_foreach (caches, (GFunc) g_object_unref, NULL);
-      g_list_free (caches);
+      /* release the cache */
+      g_object_unref (cache);
     }
 
-  /* release provider references */
-  g_list_foreach (providers, (GFunc) g_object_unref, NULL);
-  g_list_free (providers);
-
-  /* release the provider factory */
-  g_object_unref (provider_factory);
-
   if (err != NULL)
     {
       /* propagate errors */
diff --git a/tumbler/tumbler-provider-plugin.c b/tumbler/tumbler-provider-plugin.c
index f22babd..5e759da 100644
--- a/tumbler/tumbler-provider-plugin.c
+++ b/tumbler/tumbler-provider-plugin.c
@@ -116,7 +116,7 @@ tumbler_provider_plugin_load (GTypeModule *type_module)
   g_free (path);
 
   /* check if the load operation was successful */
-  if (G_UNLIKELY (plugin->library != NULL))
+  if (G_LIKELY (plugin->library != NULL))
     {
       /* verify that all required public symbols are present in the plugin */
       if (g_module_symbol (plugin->library, "tumbler_plugin_initialize", 
@@ -134,6 +134,7 @@ tumbler_provider_plugin_load (GTypeModule *type_module)
         {
           g_warning (_("Plugin \"%s\" lacks required symbols."), type_module->name);
           g_module_close (plugin->library);
+          plugin->library = NULL;
           return FALSE;
         }
     }
@@ -160,7 +161,6 @@ tumbler_provider_plugin_unload (GTypeModule *type_module)
   plugin->library = NULL;
 
   /* reset plugin state */
-  plugin->library = NULL;
   plugin->initialize = NULL;
   plugin->shutdown = NULL;
   plugin->get_types = NULL;
diff --git a/tumbler/tumbler.h b/tumbler/tumbler.h
index 98661a5..3f086bf 100644
--- a/tumbler/tumbler.h
+++ b/tumbler/tumbler.h
@@ -25,7 +25,7 @@
 
 #include <tumbler/tumbler-abstract-thumbnailer.h>
 #include <tumbler/tumbler-cache.h>
-#include <tumbler/tumbler-cache-provider.h>
+#include <tumbler/tumbler-cache-plugin.h>
 #include <tumbler/tumbler-config.h>
 #include <tumbler/tumbler-enum-types.h>
 #include <tumbler/tumbler-error.h>
diff --git a/tumblerd/tumbler-cache-service.c b/tumblerd/tumbler-cache-service.c
index 4961fcd..069c910 100644
--- a/tumblerd/tumbler-cache-service.c
+++ b/tumblerd/tumbler-cache-service.c
@@ -85,12 +85,15 @@ struct _TumblerCacheService
   GObject __parent__;
 
   DBusGConnection *connection;
+
+  TumblerCache    *cache;
+
   GThreadPool     *move_pool;
   GThreadPool     *copy_pool;
   GThreadPool     *delete_pool;
   GThreadPool     *cleanup_pool;
+
   GMutex          *mutex;
-  GList           *caches;
 };
 
 struct _MoveRequest
@@ -156,29 +159,13 @@ tumbler_cache_service_constructed (GObject *object)
 {
   TumblerProviderFactory *factory;
   TumblerCacheService    *service = TUMBLER_CACHE_SERVICE (object);
-  GList                  *caches;
   GList                  *lp;
-  GList                  *providers;
 
   /* chain up to parent classes */
   if (G_OBJECT_CLASS (tumbler_cache_service_parent_class)->constructed != NULL)
     (G_OBJECT_CLASS (tumbler_cache_service_parent_class)->constructed) (object);
 
-  factory = tumbler_provider_factory_get_default ();
-  providers = tumbler_provider_factory_get_providers (factory, 
-                                                      TUMBLER_TYPE_CACHE_PROVIDER);
-  g_object_unref (factory);
-
-  service->caches = NULL;
-
-  for (lp = providers; lp != NULL; lp = lp->next)
-    {
-      caches = tumbler_cache_provider_get_caches (lp->data);
-      service->caches = g_list_concat (service->caches, caches);
-    }
-
-  g_list_foreach (providers, (GFunc) g_object_unref, NULL);
-  g_list_free (providers);
+  service->cache = tumbler_cache_get_default ();
 
   service->move_pool = g_thread_pool_new (tumbler_cache_service_move_thread, 
                                           service, 1, FALSE, NULL);
@@ -202,8 +189,8 @@ tumbler_cache_service_finalize (GObject *object)
   g_thread_pool_free (service->delete_pool, TRUE, TRUE);
   g_thread_pool_free (service->cleanup_pool, TRUE, TRUE);
 
-  g_list_foreach (service->caches, (GFunc) g_object_unref, NULL);
-  g_list_free (service->caches);
+  if (service->cache != NULL)
+    g_object_unref (service->cache);
 
   dbus_g_connection_unref (service->connection);
 
@@ -269,8 +256,8 @@ tumbler_cache_service_move_thread (gpointer data,
 
   g_mutex_lock (service->mutex);
 
-  for (lp = service->caches; lp != NULL; lp = lp->next)
-    tumbler_cache_move (lp->data, request->from_uris, request->to_uris);
+  if (service->cache != NULL)
+    tumbler_cache_move (service->cache, request->from_uris, request->to_uris);
 
   g_strfreev (request->from_uris);
   g_strfreev (request->to_uris);
@@ -294,8 +281,8 @@ tumbler_cache_service_copy_thread (gpointer data,
 
   g_mutex_lock (service->mutex);
 
-  for (lp = service->caches; lp != NULL; lp = lp->next)
-    tumbler_cache_copy (lp->data, request->from_uris, request->to_uris);
+  if (service->cache != NULL)
+    tumbler_cache_copy (service->cache, request->from_uris, request->to_uris);
 
   g_strfreev (request->from_uris);
   g_strfreev (request->to_uris);
@@ -319,8 +306,8 @@ tumbler_cache_service_delete_thread (gpointer data,
 
   g_mutex_lock (service->mutex);
 
-  for (lp = service->caches; lp != NULL; lp = lp->next)
-    tumbler_cache_delete (lp->data, request->uris);
+  if (service->cache != NULL)
+    tumbler_cache_delete (service->cache, request->uris);
 
   g_strfreev (request->uris);
   g_slice_free (DeleteRequest, request);
@@ -343,8 +330,8 @@ tumbler_cache_service_cleanup_thread (gpointer data,
 
   g_mutex_lock (service->mutex);
 
-  for (lp = service->caches; lp != NULL; lp = lp->next)
-    tumbler_cache_cleanup (lp->data, request->uri_prefix, request->since);
+  if (service->cache != NULL)
+    tumbler_cache_cleanup (service->cache, request->uri_prefix, request->since);
 
   g_free (request->uri_prefix);
   g_slice_free (CleanupRequest, request);



More information about the Xfce4-commits mailing list