[tracker/api-cleanup: 2/16] libtracker-miner: Turn thumbnailer into an object
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/api-cleanup: 2/16] libtracker-miner: Turn thumbnailer into an object
- Date: Thu, 20 Feb 2014 01:08:08 +0000 (UTC)
commit 8d7f66d2e0cf85b237957ca037cef0e199ab14f3
Author: Carlos Garnacho <carlosg gnome org>
Date: Sat Jan 25 23:36:04 2014 +0100
libtracker-miner: Turn thumbnailer into an object
TrackerMinerFS in libtracker-miner was already doing most of the
tracker_thumbnailer_* calls necessary. The only API required on
callers only was tracker_thumbnailer_init/shutdown(). So just
turn this into an object so all usage is kept private to
libtracker-miner, and we can remove these headers out of the
public.
.../libtracker-miner/libtracker-miner-docs.sgml | 1 -
.../libtracker-miner/libtracker-miner-sections.txt | 10 --
src/libtracker-miner/Makefile.am | 11 +-
src/libtracker-miner/tracker-miner-fs.c | 19 ++-
src/libtracker-miner/tracker-miner.h | 1 -
src/libtracker-miner/tracker-miner.vapi | 12 --
src/libtracker-miner/tracker-thumbnailer.c | 161 ++++++++++----------
src/libtracker-miner/tracker-thumbnailer.h | 44 +++++-
src/miners/fs/tracker-main.c | 4 -
9 files changed, 132 insertions(+), 131 deletions(-)
---
diff --git a/docs/reference/libtracker-miner/libtracker-miner-docs.sgml
b/docs/reference/libtracker-miner/libtracker-miner-docs.sgml
index 1bcca34..0330411 100644
--- a/docs/reference/libtracker-miner/libtracker-miner-docs.sgml
+++ b/docs/reference/libtracker-miner/libtracker-miner-docs.sgml
@@ -58,7 +58,6 @@
<xi:include href="xml/tracker-miner-enums.xml"/>
<xi:include href="xml/tracker-storage.xml"/>
<xi:include href="xml/tracker-media-art.xml"/>
- <xi:include href="xml/tracker-thumbnailer.xml"/>
</chapter>
</part>
diff --git a/docs/reference/libtracker-miner/libtracker-miner-sections.txt
b/docs/reference/libtracker-miner/libtracker-miner-sections.txt
index 2dd3b89..3428a00 100644
--- a/docs/reference/libtracker-miner/libtracker-miner-sections.txt
+++ b/docs/reference/libtracker-miner/libtracker-miner-sections.txt
@@ -259,16 +259,6 @@ tracker_storage_get_type
</SECTION>
<SECTION>
-<FILE>tracker-thumbnailer</FILE>
-tracker_thumbnailer_cleanup
-tracker_thumbnailer_init
-tracker_thumbnailer_move_add
-tracker_thumbnailer_remove_add
-tracker_thumbnailer_send
-tracker_thumbnailer_shutdown
-</SECTION>
-
-<SECTION>
<FILE>tracker-decorator</FILE>
<TITLE>TrackerDecorator</TITLE>
TrackerDecorator
diff --git a/src/libtracker-miner/Makefile.am b/src/libtracker-miner/Makefile.am
index 7a5b457..e91a2fe 100644
--- a/src/libtracker-miner/Makefile.am
+++ b/src/libtracker-miner/Makefile.am
@@ -50,7 +50,9 @@ private_sources = \
tracker-sparql-buffer.h \
tracker-sparql-buffer.c \
tracker-storage.c \
- tracker-storage.h
+ tracker-storage.h \
+ tracker-thumbnailer.c \
+ tracker-thumbnailer.h
miner_sources = \
$(libtracker_miner_monitor_sources) \
@@ -85,8 +87,6 @@ libtracker_miner_ TRACKER_API_VERSION@_la_SOURCES = \
tracker-indexing-tree.h \
tracker-network-provider.c \
tracker-password-provider.c \
- tracker-thumbnailer.c \
- tracker-thumbnailer.h \
tracker-media-art.c \
tracker-media-art.h
@@ -106,8 +106,7 @@ libtracker_minerinclude_HEADERS = \
tracker-miner-web.h \
tracker-network-provider.h \
tracker-password-provider.h \
- tracker-storage.h \
- tracker-thumbnailer.h
+ tracker-storage.h
libtracker_miner_ TRACKER_API_VERSION@_la_LDFLAGS = \
-version-info $(LT_CURRENT):$(LT_REVISION):$(LT_AGE)
@@ -115,7 +114,7 @@ if !ENABLE_GCOV
# Using enable_gcov instead of have_unit_test because when doing a release
# we disable gcov but NOT the unit tests
libtracker_miner_ TRACKER_API_VERSION@_la_LDFLAGS += \
- -export-symbols-regex
'^tracker_(miner|thumbnailer|crawler|storage|password_provider|network_provider|indexing_tree|file_system|file_notifier|directory_flags|filter_type|filter_policy|decorator)_.*'
+ -export-symbols-regex
'^tracker_(miner|crawler|storage|password_provider|network_provider|indexing_tree|file_system|file_notifier|directory_flags|filter_type|filter_policy|decorator)_.*'
endif
libtracker_miner_ TRACKER_API_VERSION@_la_LIBADD = \
diff --git a/src/libtracker-miner/tracker-miner-fs.c b/src/libtracker-miner/tracker-miner-fs.c
index 1bf742e..23f72e9 100644
--- a/src/libtracker-miner/tracker-miner-fs.c
+++ b/src/libtracker-miner/tracker-miner-fs.c
@@ -144,6 +144,7 @@ typedef struct {
GString *sparql;
const gchar *source_uri;
const gchar *uri;
+ TrackerMiner *miner;
} RecursiveMoveData;
struct _TrackerMinerFSPrivate {
@@ -186,6 +187,8 @@ struct _TrackerMinerFSPrivate {
TrackerIndexingTree *indexing_tree;
+ TrackerThumbnailer *thumbnailer;
+
/* Status */
guint been_started : 1; /* TRUE if miner has been started */
guint been_crawled : 1; /* TRUE if initial crawling has been
@@ -637,6 +640,8 @@ miner_fs_initable_init (GInitable *initable,
G_CALLBACK (task_pool_limit_reached_notify_cb),
initable);
+ priv->thumbnailer = tracker_thumbnailer_new ();
+
return TRUE;
}
@@ -710,6 +715,9 @@ fs_finalize (GObject *object)
g_object_unref (priv->indexing_tree);
g_object_unref (priv->file_notifier);
+ if (priv->thumbnailer)
+ g_object_unref (priv->thumbnailer);
+
#ifdef EVENT_QUEUE_ENABLE_TRACE
if (priv->queue_status_timeout_id)
g_source_remove (priv->queue_status_timeout_id);
@@ -1352,7 +1360,7 @@ item_remove (TrackerMinerFS *fs,
if (!only_children) {
flags = TRACKER_BULK_MATCH_EQUALS;
} else {
- tracker_thumbnailer_remove_add (uri, NULL);
+ tracker_thumbnailer_remove_add (fs->priv->thumbnailer, uri, NULL);
tracker_media_art_queue_remove (uri, NULL);
}
@@ -1505,6 +1513,7 @@ item_update_children_uri_cb (GObject *object,
gpointer user_data)
{
RecursiveMoveData *data = user_data;
+ TrackerMinerFS *fs = TRACKER_MINER_FS (data->miner);
GError *error = NULL;
TrackerSparqlCursor *cursor = tracker_sparql_connection_query_finish (TRACKER_SPARQL_CONNECTION
(object), result, &error);
@@ -1547,7 +1556,8 @@ item_update_children_uri_cb (GObject *object,
"} ",
child_urn, child_urn, child_uri);
- tracker_thumbnailer_move_add (child_source_uri, child_mime, child_uri);
+ tracker_thumbnailer_move_add (fs->priv->thumbnailer,
+ child_source_uri, child_mime, child_uri);
g_free (child_uri);
}
@@ -1634,7 +1644,7 @@ item_move (TrackerMinerFS *fs,
source_uri,
uri);
- tracker_thumbnailer_move_add (source_uri,
+ tracker_thumbnailer_move_add (fs->priv->thumbnailer, source_uri,
g_file_info_get_content_type (file_info),
uri);
@@ -1712,6 +1722,7 @@ item_move (TrackerMinerFS *fs,
move_data.sparql = sparql;
move_data.source_uri = source_uri;
move_data.uri = uri;
+ move_data.miner = TRACKER_MINER (fs);
item_update_children_uri (fs, &move_data, source_uri, uri);
@@ -2270,7 +2281,7 @@ item_queue_handlers_cb (gpointer user_data)
/* Print stats and signal finished */
process_stop (fs);
- tracker_thumbnailer_send ();
+ tracker_thumbnailer_send (fs->priv->thumbnailer);
tracker_media_art_queue_empty (tracker_miner_get_connection (TRACKER_MINER
(fs)));
} else {
/* Flush any possible pending update here */
diff --git a/src/libtracker-miner/tracker-miner.h b/src/libtracker-miner/tracker-miner.h
index 386f21d..ab4ea10 100644
--- a/src/libtracker-miner/tracker-miner.h
+++ b/src/libtracker-miner/tracker-miner.h
@@ -26,7 +26,6 @@
#include <libtracker-miner/tracker-decorator.h>
#include <libtracker-miner/tracker-decorator-fs.h>
#include <libtracker-miner/tracker-storage.h>
-#include <libtracker-miner/tracker-thumbnailer.h>
#include <libtracker-miner/tracker-media-art.h>
#include <libtracker-miner/tracker-network-provider.h>
#include <libtracker-miner/tracker-password-provider.h>
diff --git a/src/libtracker-miner/tracker-miner.vapi b/src/libtracker-miner/tracker-miner.vapi
index 92db951..096e38e 100644
--- a/src/libtracker-miner/tracker-miner.vapi
+++ b/src/libtracker-miner/tracker-miner.vapi
@@ -134,16 +134,4 @@ namespace Tracker {
}
[CCode (cheader_filename = "libtracker-miner/tracker-miner.h")]
public const string MINER_WEB_DBUS_INTERFACE;
- [CCode (cheader_filename = "libtracker-miner/tracker-miner.h")]
- public static bool thumbnailer_cleanup (string uri_prefix);
- [CCode (cheader_filename = "libtracker-miner/tracker-miner.h")]
- public static bool thumbnailer_init ();
- [CCode (cheader_filename = "libtracker-miner/tracker-miner.h")]
- public static bool thumbnailer_move_add (string from_uri, string mime_type, string to_uri);
- [CCode (cheader_filename = "libtracker-miner/tracker-miner.h")]
- public static bool thumbnailer_remove_add (string uri, string mime_type);
- [CCode (cheader_filename = "libtracker-miner/tracker-miner.h")]
- public static void thumbnailer_send ();
- [CCode (cheader_filename = "libtracker-miner/tracker-miner.h")]
- public static void thumbnailer_shutdown ();
}
diff --git a/src/libtracker-miner/tracker-thumbnailer.c b/src/libtracker-miner/tracker-thumbnailer.c
index 3ad5a2d..ee80999 100644
--- a/src/libtracker-miner/tracker-thumbnailer.c
+++ b/src/libtracker-miner/tracker-thumbnailer.c
@@ -63,15 +63,21 @@ typedef struct {
gboolean service_is_available;
} TrackerThumbnailerPrivate;
-static void private_free (gpointer data);
-static GPrivate private_key = G_PRIVATE_INIT (private_free);
+static void tracker_thumbnailer_initable_iface_init (GInitableIface *iface);
+
+G_DEFINE_TYPE_WITH_CODE (TrackerThumbnailer, tracker_thumbnailer, G_TYPE_OBJECT,
+ G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE,
+ tracker_thumbnailer_initable_iface_init)
+ G_ADD_PRIVATE (TrackerThumbnailer))
static void
-private_free (gpointer data)
+tracker_thumbnailer_finalize (GObject *object)
{
TrackerThumbnailerPrivate *private;
+ TrackerThumbnailer *thumbnailer;
- private = data;
+ thumbnailer = TRACKER_THUMBNAILER (object);
+ private = tracker_thumbnailer_get_instance_private (thumbnailer);
if (private->cache_proxy) {
g_object_unref (private->cache_proxy);
@@ -96,7 +102,7 @@ private_free (gpointer data)
g_slist_foreach (private->moves_from, (GFunc) g_free, NULL);
g_slist_free (private->moves_from);
- g_free (private);
+ G_OBJECT_CLASS (tracker_thumbnailer_parent_class)->finalize (object);
}
inline static gboolean
@@ -121,42 +127,28 @@ should_be_thumbnailed (GStrv list,
return should_thumbnail;
}
-/**
- * tracker_thumbnailer_init:
- *
- * Initializes the thumbnailer connection.
- *
- * Returns: #TRUE if connection was successfully initialized, #FALSE otherwise.
- *
- * Since: 0.8
- */
-gboolean
-tracker_thumbnailer_init (void)
+static gboolean
+tracker_thumbnailer_initable_init (GInitable *initable,
+ GCancellable *cancellable,
+ GError **error)
{
TrackerThumbnailerPrivate *private;
- GError *error = NULL;
+ TrackerThumbnailer *thumbnailer;
GVariant *v;
- private = g_new0 (TrackerThumbnailerPrivate, 1);
+ thumbnailer = TRACKER_THUMBNAILER (initable);
+ private = tracker_thumbnailer_get_instance_private (thumbnailer);
/* Don't start at 0, start at 1. */
private->request_id = 1;
-
- g_private_replace (&private_key, private);
+ private->service_is_available = FALSE;
g_message ("Thumbnailer connections being set up...");
- private->connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
-
- if (!private->connection) {
- g_critical ("Could not connect to the D-Bus session bus, %s",
- error ? error->message : "no error given.");
- g_clear_error (&error);
-
- private->service_is_available = FALSE;
+ private->connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, error);
+ if (!private->connection)
return FALSE;
- }
private->cache_proxy = g_dbus_proxy_new_sync (private->connection,
G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES,
@@ -165,10 +157,10 @@ tracker_thumbnailer_init (void)
THUMBCACHE_PATH,
THUMBCACHE_INTERFACE,
NULL,
- &error);
-
- if (error) {
- goto error_handler;
+ error);
+ if (!private->cache_proxy) {
+ g_object_unref (private->connection);
+ return FALSE;
}
private->manager_proxy = g_dbus_proxy_new_sync (private->connection,
@@ -178,10 +170,12 @@ tracker_thumbnailer_init (void)
THUMBMAN_PATH,
THUMBMAN_INTERFACE,
NULL,
- &error);
+ error);
- if (error) {
- goto error_handler;
+ if (!private->manager_proxy) {
+ g_object_unref (private->connection);
+ g_object_unref (private->cache_proxy);
+ return FALSE;
}
v = g_dbus_proxy_call_sync (private->manager_proxy,
@@ -190,28 +184,14 @@ tracker_thumbnailer_init (void)
G_DBUS_CALL_FLAGS_NONE,
-1,
NULL,
- &error);
-
-error_handler:
-
- if (error) {
- g_message ("Thumbnailer service did not return supported mime types, %s",
- error->message);
-
- g_error_free (error);
-
- if (private->cache_proxy) {
- g_object_unref (private->cache_proxy);
- private->cache_proxy = NULL;
- }
-
- if (private->manager_proxy) {
- g_object_unref (private->manager_proxy);
- private->manager_proxy = NULL;
- }
+ error);
+ if (!v) {
+ g_object_unref (private->connection);
+ g_object_unref (private->cache_proxy);
+ g_object_unref (private->manager_proxy);
return FALSE;
- } else if (v) {
+ } else {
GStrv mime_types = NULL;
GStrv uri_schemes = NULL;
@@ -258,17 +238,29 @@ error_handler:
return TRUE;
}
-/**
- * tracker_thumbnailer_shutdown:
- *
- * Shuts down the thumbnailer connection.
- *
- * Since: 0.8
- */
-void
-tracker_thumbnailer_shutdown (void)
+static void
+tracker_thumbnailer_initable_iface_init (GInitableIface *iface)
{
- g_private_replace (&private_key, NULL);
+ iface->init = tracker_thumbnailer_initable_init;
+}
+
+static void
+tracker_thumbnailer_class_init (TrackerThumbnailerClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->finalize = tracker_thumbnailer_finalize;
+}
+
+static void
+tracker_thumbnailer_init (TrackerThumbnailer *thumbnailer)
+{
+}
+
+TrackerThumbnailer *
+tracker_thumbnailer_new (void)
+{
+ return g_initable_new (TRACKER_TYPE_THUMBNAILER, NULL, NULL, NULL);
}
/**
@@ -285,20 +277,19 @@ tracker_thumbnailer_shutdown (void)
* Since: 0.8
*/
gboolean
-tracker_thumbnailer_move_add (const gchar *from_uri,
- const gchar *mime_type,
- const gchar *to_uri)
+tracker_thumbnailer_move_add (TrackerThumbnailer *thumbnailer,
+ const gchar *from_uri,
+ const gchar *mime_type,
+ const gchar *to_uri)
{
-
TrackerThumbnailerPrivate *private;
/* mime_type can be NULL */
-
+ g_return_val_if_fail (TRACKER_IS_THUMBNAILER (thumbnailer), FALSE);
g_return_val_if_fail (from_uri != NULL, FALSE);
g_return_val_if_fail (to_uri != NULL, FALSE);
- private = g_private_get (&private_key);
- g_return_val_if_fail (private != NULL, FALSE);
+ private = tracker_thumbnailer_get_instance_private (thumbnailer);
if (!private->service_is_available) {
return FALSE;
@@ -331,17 +322,17 @@ tracker_thumbnailer_move_add (const gchar *from_uri,
* Since: 0.8
*/
gboolean
-tracker_thumbnailer_remove_add (const gchar *uri,
- const gchar *mime_type)
+tracker_thumbnailer_remove_add (TrackerThumbnailer *thumbnailer,
+ const gchar *uri,
+ const gchar *mime_type)
{
TrackerThumbnailerPrivate *private;
+ g_return_val_if_fail (TRACKER_IS_THUMBNAILER (thumbnailer), FALSE);
/* mime_type can be NULL */
-
g_return_val_if_fail (uri != NULL, FALSE);
- private = g_private_get (&private_key);
- g_return_val_if_fail (private != NULL, FALSE);
+ private = tracker_thumbnailer_get_instance_private (thumbnailer);
if (!private->service_is_available) {
return FALSE;
@@ -369,14 +360,15 @@ tracker_thumbnailer_remove_add (const gchar *uri,
* Since: 0.8
*/
gboolean
-tracker_thumbnailer_cleanup (const gchar *uri_prefix)
+tracker_thumbnailer_cleanup (TrackerThumbnailer *thumbnailer,
+ const gchar *uri_prefix)
{
TrackerThumbnailerPrivate *private;
+ g_return_val_if_fail (TRACKER_IS_THUMBNAILER (thumbnailer), FALSE);
g_return_val_if_fail (uri_prefix != NULL, FALSE);
- private = g_private_get (&private_key);
- g_return_val_if_fail (private != NULL, FALSE);
+ private = tracker_thumbnailer_get_instance_private (thumbnailer);
if (!private->service_is_available) {
return FALSE;
@@ -408,13 +400,14 @@ tracker_thumbnailer_cleanup (const gchar *uri_prefix)
* Since: 0.8
*/
void
-tracker_thumbnailer_send (void)
+tracker_thumbnailer_send (TrackerThumbnailer *thumbnailer)
{
TrackerThumbnailerPrivate *private;
guint list_len;
- private = g_private_get (&private_key);
- g_return_if_fail (private != NULL);
+ g_return_if_fail (TRACKER_IS_THUMBNAILER (thumbnailer));
+
+ private = tracker_thumbnailer_get_instance_private (thumbnailer);
if (!private->service_is_available) {
return;
diff --git a/src/libtracker-miner/tracker-thumbnailer.h b/src/libtracker-miner/tracker-thumbnailer.h
index d6fc5b0..c7b2f08 100644
--- a/src/libtracker-miner/tracker-thumbnailer.h
+++ b/src/libtracker-miner/tracker-thumbnailer.h
@@ -24,17 +24,43 @@
#error "Only <libtracker-miner/tracker-miner.h> can be included directly."
#endif
+#include <glib-object.h>
+
G_BEGIN_DECLS
-gboolean tracker_thumbnailer_init (void);
-void tracker_thumbnailer_shutdown (void);
-void tracker_thumbnailer_send (void);
-gboolean tracker_thumbnailer_move_add (const gchar *from_uri,
- const gchar *mime_type,
- const gchar *to_uri);
-gboolean tracker_thumbnailer_remove_add (const gchar *uri,
- const gchar *mime_type);
-gboolean tracker_thumbnailer_cleanup (const gchar *uri_prefix);
+#define TRACKER_TYPE_THUMBNAILER (tracker_thumbnailer_get_type())
+#define TRACKER_THUMBNAILER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), TRACKER_TYPE_THUMBNAILER,
TrackerThumbnailer))
+#define TRACKER_THUMBNAILER_CLASS(c) (G_TYPE_CHECK_CLASS_CAST ((c), TRACKER_TYPE_THUMBNAILER,
TrackerThumbnailerClass))
+#define TRACKER_IS_THUMBNAILER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), TRACKER_TYPE_THUMBNAILER))
+#define TRACKER_IS_THUMBNAILER_CLASS(c) (G_TYPE_CHECK_CLASS_TYPE ((c), TRACKER_TYPE_THUMBNAILER))
+#define TRACKER_THUMBNAILER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), TRACKER_TYPE_THUMBNAILER,
TrackerThumbnailerClass))
+
+typedef struct _TrackerThumbnailer TrackerThumbnailer;
+typedef struct _TrackerThumbnailerClass TrackerThumbnailerClass;
+
+struct _TrackerThumbnailer {
+ GObject parent_instance;
+};
+
+struct _TrackerThumbnailerClass {
+ GObjectClass parent_class;
+};
+
+
+GType tracker_thumbnailer_get_type (void) G_GNUC_CONST;
+TrackerThumbnailer *
+ tracker_thumbnailer_new (void);
+
+void tracker_thumbnailer_send (TrackerThumbnailer *thumbnailer);
+gboolean tracker_thumbnailer_move_add (TrackerThumbnailer *thumbnailer,
+ const gchar *from_uri,
+ const gchar *mime_type,
+ const gchar *to_uri);
+gboolean tracker_thumbnailer_remove_add (TrackerThumbnailer *thumbnailer,
+ const gchar *uri,
+ const gchar *mime_type);
+gboolean tracker_thumbnailer_cleanup (TrackerThumbnailer *thumbnailer,
+ const gchar *uri_prefix);
G_END_DECLS
diff --git a/src/miners/fs/tracker-main.c b/src/miners/fs/tracker-main.c
index 41305c0..1204044 100644
--- a/src/miners/fs/tracker-main.c
+++ b/src/miners/fs/tracker-main.c
@@ -1081,8 +1081,6 @@ main (gint argc, gchar *argv[])
miners = g_slist_prepend (miners, miner_files);
miners = g_slist_prepend (miners, miner_applications);
- tracker_thumbnailer_init ();
-
miner_handle_first (config, do_mtime_checking);
/* Go, go, go! */
@@ -1105,8 +1103,6 @@ main (gint argc, gchar *argv[])
g_object_unref (config);
g_object_unref (miner_files_index);
- tracker_thumbnailer_shutdown ();
-
g_slist_foreach (miners, (GFunc) finalize_miner, NULL);
g_slist_free (miners);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]