[tracker/libtracker-sparql-porting: 6/45] libtracker-miner: Port to libtracker-sparql



commit 8a58ffaf9ae3ab629eb91598c9aa70ac67b222f4
Author: Jürg Billeter <j bitron ch>
Date:   Mon Jul 19 16:45:10 2010 +0200

    libtracker-miner: Port to libtracker-sparql
    
    This also drops the query API in libtracker-miner as this is now
    redundant.

 src/libtracker-miner/Makefile.am            |    3 +-
 src/libtracker-miner/tracker-miner-fs.c     |  108 +++---
 src/libtracker-miner/tracker-miner-fs.h     |    2 +-
 src/libtracker-miner/tracker-miner-object.c |  498 +--------------------------
 src/libtracker-miner/tracker-miner-object.h |   42 +--
 src/miners/fs/tracker-main.c                |    1 -
 src/miners/fs/tracker-miner-files.c         |   42 ++--
 7 files changed, 91 insertions(+), 605 deletions(-)
---
diff --git a/src/libtracker-miner/Makefile.am b/src/libtracker-miner/Makefile.am
index ca3b003..e71f8cd 100644
--- a/src/libtracker-miner/Makefile.am
+++ b/src/libtracker-miner/Makefile.am
@@ -13,7 +13,6 @@ INCLUDES =						\
 	-DTRACKER_MINERS_DIR=\""$(datadir)/tracker/miners"\" 	\
 	-I$(top_srcdir)/src				\
 	-I$(top_builddir)/src				\
-	-I$(top_builddir)/src/libtracker-client		\
 	$(WARN_CFLAGS)					\
 	$(GLIB2_CFLAGS)					\
 	$(GCOV_CFLAGS)					\
@@ -62,7 +61,7 @@ libtracker_miner_ TRACKER_API_VERSION@_la_LDFLAGS = 	\
 
 libtracker_miner_ TRACKER_API_VERSION@_la_LIBADD = 	\
 	$(top_builddir)/src/libtracker-common/libtracker-common.la \
-	$(top_builddir)/src/libtracker-client/libtracker-client- TRACKER_API_VERSION@.la \
+	$(top_builddir)/src/libtracker-sparql/libtracker-sparql- TRACKER_API_VERSION@.la \
 	$(DBUS_LIBS)					\
 	$(GIO_LIBS)					\
 	$(GCOV_LIBS)					\
diff --git a/src/libtracker-miner/tracker-miner-fs.c b/src/libtracker-miner/tracker-miner-fs.c
index cd29579..9a24993 100644
--- a/src/libtracker-miner/tracker-miner-fs.c
+++ b/src/libtracker-miner/tracker-miner-fs.c
@@ -68,6 +68,7 @@ typedef struct {
 	gchar *parent_urn;
 	GCancellable *cancellable;
 	TrackerSparqlBuilder *builder;
+	TrackerMiner *miner;
 } ProcessData;
 
 typedef struct {
@@ -446,7 +447,7 @@ tracker_miner_fs_class_init (TrackerMinerFSClass *klass)
 		              NULL, NULL,
 		              tracker_marshal_BOOLEAN__OBJECT_OBJECT_OBJECT,
 		              G_TYPE_BOOLEAN,
-		              3, G_TYPE_FILE, TRACKER_TYPE_SPARQL_BUILDER, G_TYPE_CANCELLABLE);
+		              3, G_TYPE_FILE, TRACKER_SPARQL_TYPE_BUILDER, G_TYPE_CANCELLABLE);
 
 	/**
 	 * TrackerMinerFS::ignore-next-update-file:
@@ -472,7 +473,7 @@ tracker_miner_fs_class_init (TrackerMinerFSClass *klass)
 			      NULL, NULL,
 			      tracker_marshal_BOOLEAN__OBJECT_OBJECT_OBJECT,
 			      G_TYPE_BOOLEAN,
-			      3, G_TYPE_FILE, TRACKER_TYPE_SPARQL_BUILDER, G_TYPE_CANCELLABLE);
+			      3, G_TYPE_FILE, TRACKER_SPARQL_TYPE_BUILDER, G_TYPE_CANCELLABLE);
 
 	/**
 	 * TrackerMinerFS::finished:
@@ -575,7 +576,8 @@ tracker_miner_fs_init (TrackerMinerFS *object)
 }
 
 static ProcessData *
-process_data_new (GFile                *file,
+process_data_new (TrackerMiner         *miner,
+                  GFile                *file,
 		  const gchar          *urn,
 		  const gchar          *parent_urn,
                   GCancellable         *cancellable,
@@ -584,6 +586,7 @@ process_data_new (GFile                *file,
 	ProcessData *data;
 
 	data = g_slice_new0 (ProcessData);
+	data->miner = miner;
 	data->file = g_object_ref (file);
 	data->urn = g_strdup (urn);
 	data->parent_urn = g_strdup (parent_urn);
@@ -951,10 +954,9 @@ commit_cb (GObject      *object,
            GAsyncResult *result,
            gpointer      user_data)
 {
-	TrackerMiner *miner = TRACKER_MINER (object);
 	GError *error = NULL;
 
-	tracker_miner_commit_finish (miner, result, &error);
+	tracker_sparql_connection_update_commit_finish (TRACKER_SPARQL_CONNECTION (object), result, &error);
 
 	if (error) {
 		g_critical ("Could not commit: %s", error->message);
@@ -968,7 +970,7 @@ process_stop (TrackerMinerFS *fs)
 	/* Now we have finished crawling, print stats and enable monitor events */
 	process_print_stats (fs);
 
-	tracker_miner_commit (TRACKER_MINER (fs), NULL, commit_cb, NULL);
+	tracker_sparql_connection_update_commit_async (tracker_miner_get_connection (TRACKER_MINER (fs)), NULL, commit_cb, NULL);
 
 	g_message ("Idle");
 
@@ -1028,11 +1030,11 @@ sparql_update_cb (GObject      *object,
 	ProcessData *data;
 	GError *error = NULL;
 
-	tracker_miner_execute_update_finish (TRACKER_MINER (object), result, &error);
+	tracker_sparql_connection_update_finish (TRACKER_SPARQL_CONNECTION (object), result, &error);
 
-	fs = TRACKER_MINER_FS (object);
-	priv = fs->private;
 	data = user_data;
+	fs = TRACKER_MINER_FS (data->miner);
+	priv = fs->private;
 
 	if (error) {
 		g_critical ("Could not execute sparql: %s", error->message);
@@ -1043,7 +1045,7 @@ sparql_update_cb (GObject      *object,
 			/* Only commit immediately for
 			 * changes after initial crawling.
 			 */
-			tracker_miner_commit (TRACKER_MINER (fs), NULL, commit_cb, NULL);
+			tracker_sparql_connection_update_commit_async (TRACKER_SPARQL_CONNECTION (object), NULL, commit_cb, NULL);
 		}
 
 		if (fs->private->current_iri_cache_parent) {
@@ -1082,13 +1084,11 @@ item_query_exists_cb (GObject      *object,
                       gpointer      user_data)
 {
 	ItemQueryExistsData *data = user_data;
-	TrackerResultIterator *iterator;
-	TrackerMiner *miner;
+	TrackerSparqlCursor *cursor;
 	GError *error = NULL;
 	guint n_results;
 
-	miner = TRACKER_MINER (object);
-	iterator = tracker_miner_execute_sparql_finish (miner, result, &error);
+	cursor = tracker_sparql_connection_query_finish (TRACKER_SPARQL_CONNECTION (object), result, &error);
 
 	g_main_loop_quit (data->main_loop);
 
@@ -1098,17 +1098,16 @@ item_query_exists_cb (GObject      *object,
 		return;
 	}
 
-	if (!iterator ||
-	    !tracker_result_iterator_next (iterator))
+	if (!tracker_sparql_cursor_next (cursor, NULL, NULL))
 		return;
 
 	n_results = 1;
-	data->iri = g_strdup (tracker_result_iterator_value (iterator, 0));
+	data->iri = g_strdup (tracker_sparql_cursor_get_string (cursor, 0, NULL));
 	if (data->get_mime)
-		data->mime = g_strdup (tracker_result_iterator_value (iterator, 1));
+		data->mime = g_strdup (tracker_sparql_cursor_get_string (cursor, 1, NULL));
 
 	/* Any additional result must be logged as critical */
-	while (tracker_result_iterator_next (iterator)) {
+	while (tracker_sparql_cursor_next (cursor, NULL, NULL)) {
 		if (n_results == 1) {
 			/* If first duplicate found, log initial critical */
 			g_critical ("More than one URNs have been found for uri \"%s\"...",
@@ -1120,8 +1119,8 @@ item_query_exists_cb (GObject      *object,
 		n_results++;
 		g_critical ("  (%d) urn:'%s', mime:'%s'",
 		            n_results,
-		            tracker_result_iterator_value (iterator, 0),
-		            data->get_mime ? tracker_result_iterator_value (iterator, 1) : "unneeded");
+		            tracker_sparql_cursor_get_string (cursor, 0, NULL),
+		            data->get_mime ? tracker_sparql_cursor_get_string (cursor, 1, NULL) : "unneeded");
 	}
 }
 
@@ -1148,7 +1147,7 @@ item_query_exists (TrackerMinerFS  *miner,
 	data.main_loop = g_main_loop_new (NULL, FALSE);
 	data.uri = uri;
 
-	tracker_miner_execute_sparql (TRACKER_MINER (miner),
+	tracker_sparql_connection_query_async (tracker_miner_get_connection (TRACKER_MINER (miner)),
 	                              sparql,
 	                              NULL,
 	                              item_query_exists_cb,
@@ -1182,14 +1181,12 @@ cache_query_cb (GObject	     *object,
 		GAsyncResult *result,
 		gpointer      user_data)
 {
-	TrackerResultIterator *iterator;
-	TrackerMiner *miner;
+	TrackerSparqlCursor *cursor;
 	CacheQueryData *data;
 	GError *error = NULL;
 
 	data = user_data;
-	miner = TRACKER_MINER (object);
-	iterator = tracker_miner_execute_sparql_finish (miner, result, &error);
+	cursor = tracker_sparql_connection_query_finish (TRACKER_SPARQL_CONNECTION (object), result, &error);
 
 	g_main_loop_quit (data->main_loop);
 
@@ -1199,14 +1196,14 @@ cache_query_cb (GObject	     *object,
 		return;
 	}
 
-	while (tracker_result_iterator_next (iterator)) {
+	while (tracker_sparql_cursor_next (cursor, NULL, NULL)) {
 		GFile *file;
 
-		file = g_file_new_for_uri (tracker_result_iterator_value (iterator, 0));
+		file = g_file_new_for_uri (tracker_sparql_cursor_get_string (cursor, 0, NULL));
 
 		g_hash_table_insert (data->values,
 		                     file,
-		                     g_strdup (tracker_result_iterator_value (iterator, 1)));
+		                     g_strdup (tracker_sparql_cursor_get_string (cursor, 1, NULL)));
 	}
 }
 
@@ -1267,7 +1264,7 @@ ensure_iri_cache (TrackerMinerFS *fs,
 	data.main_loop = g_main_loop_new (NULL, FALSE);
 	data.values = g_hash_table_ref (fs->private->iri_cache);
 
-	tracker_miner_execute_sparql (TRACKER_MINER (fs),
+	tracker_sparql_connection_query_async (tracker_miner_get_connection (TRACKER_MINER (fs)),
 	                              query,
 	                              NULL,
 	                              cache_query_cb,
@@ -1495,11 +1492,10 @@ item_add_or_update_cb (TrackerMinerFS *fs,
 			full_sparql = g_strdup (tracker_sparql_builder_get_result (data->builder));
 		}
 
-		tracker_miner_execute_batch_update (TRACKER_MINER (fs),
+		tracker_sparql_connection_update_async (tracker_miner_get_connection (TRACKER_MINER (fs)),
 		                                    full_sparql,
-		                                    NULL,
-		                                    sparql_update_cb,
-		                                    data);
+		                                    NULL, NULL,
+		                                    sparql_update_cb, data);
 		g_free (full_sparql);
 	}
 
@@ -1560,7 +1556,7 @@ item_add_or_update (TrackerMinerFS *fs,
 
 	urn = iri_cache_lookup (fs, file);
 
-	data = process_data_new (file, urn, parent_urn, cancellable, sparql);
+	data = process_data_new (TRACKER_MINER (fs), file, urn, parent_urn, cancellable, sparql);
 	priv->processing_pool = g_list_prepend (priv->processing_pool, data);
 
 	if (do_process_file (fs, data)) {
@@ -1629,14 +1625,13 @@ item_remove (TrackerMinerFS *fs,
 	                        "}",
 	                        uri);
 
-	data = process_data_new (file, NULL, NULL, NULL, NULL);
+	data = process_data_new (TRACKER_MINER (fs), file, NULL, NULL, NULL, NULL);
 	fs->private->processing_pool = g_list_prepend (fs->private->processing_pool, data);
 
-	tracker_miner_execute_batch_update (TRACKER_MINER (fs),
+	tracker_sparql_connection_update_async (tracker_miner_get_connection (TRACKER_MINER (fs)),
 	                                    sparql->str,
-	                                    NULL,
-	                                    sparql_update_cb,
-	                                    data);
+	                                    NULL, NULL,
+	                                    sparql_update_cb, data);
 
 	g_string_free (sparql, TRUE);
 	g_free (uri);
@@ -1715,8 +1710,8 @@ item_ignore_next_update (TrackerMinerFS *fs,
 		                         "} %s",
 		                         uri, tracker_sparql_builder_get_result (sparql));
 
-		tracker_miner_execute_batch_update (TRACKER_MINER (fs),
-		                                    query,
+		tracker_sparql_connection_update_async (tracker_miner_get_connection (TRACKER_MINER (fs)),
+		                                    query, NULL,
 		                                    NULL, NULL, NULL);
 
 		g_free (query);
@@ -1741,19 +1736,19 @@ item_update_children_uri_cb (GObject      *object,
 	RecursiveMoveData *data = user_data;
 	GError *error = NULL;
 
-	TrackerResultIterator *iterator = tracker_miner_execute_sparql_finish (TRACKER_MINER (object), result, &error);
+	TrackerSparqlCursor *cursor = tracker_sparql_connection_query_finish (TRACKER_SPARQL_CONNECTION (object), result, &error);
 
 	if (error) {
 		g_critical ("Could not query children: %s", error->message);
 		g_error_free (error);
-	} else if (iterator) {
-		while (tracker_result_iterator_next (iterator)) {
+	} else {
+		while (tracker_sparql_cursor_next (cursor, NULL, NULL)) {
 			const gchar *child_source_uri, *child_mime, *child_urn;
 			gchar *child_uri;
 
-			child_urn = tracker_result_iterator_value (iterator, 0);
-			child_source_uri = tracker_result_iterator_value (iterator, 1);
-			child_mime = tracker_result_iterator_value (iterator, 2);
+			child_urn = tracker_sparql_cursor_get_string (cursor, 0, NULL);
+			child_source_uri = tracker_sparql_cursor_get_string (cursor, 1, NULL);
+			child_mime = tracker_sparql_cursor_get_string (cursor, 2, NULL);
 
 			if (!g_str_has_prefix (child_source_uri, data->source_uri)) {
 				g_warning ("Child URI '%s' does not start with parent URI '%s'",
@@ -1801,7 +1796,7 @@ item_update_children_uri (TrackerMinerFS    *fs,
 				  "}",
 				  source_uri);
 
-	tracker_miner_execute_sparql (TRACKER_MINER (fs),
+	tracker_sparql_connection_query_async (tracker_miner_get_connection (TRACKER_MINER (fs)),
 	                              sparql,
 	                              NULL,
 	                              item_update_children_uri_cb,
@@ -1911,7 +1906,7 @@ item_move (TrackerMinerFS *fs,
 	                        "} ",
 	                        source_iri, source_iri, source_iri);
 
-	display_name = tracker_sparql_escape (g_file_info_get_display_name (file_info));
+	display_name = tracker_sparql_escape_string (g_file_info_get_display_name (file_info));
 
 	g_string_append_printf (sparql,
 	                        "INSERT INTO <%s> {"
@@ -1936,14 +1931,13 @@ item_move (TrackerMinerFS *fs,
 
 	g_main_loop_unref (move_data.main_loop);
 
-	data = process_data_new (file, NULL, NULL, NULL, NULL);
+	data = process_data_new (TRACKER_MINER (fs), file, NULL, NULL, NULL, NULL);
 	fs->private->processing_pool = g_list_prepend (fs->private->processing_pool, data);
 
-	tracker_miner_execute_batch_update (TRACKER_MINER (fs),
+	tracker_sparql_connection_update_async (tracker_miner_get_connection (TRACKER_MINER (fs)),
 	                                    sparql->str,
-	                                    NULL,
-	                                    sparql_update_cb,
-	                                    data);
+	                                    NULL, NULL,
+	                                    sparql_update_cb, data);
 
 	g_free (uri);
 	g_free (source_uri);
@@ -2382,7 +2376,7 @@ item_queue_handlers_cb (gpointer user_data)
 			/* Only commit immediately for
 			 * changes after initial crawling.
 			 */
-			tracker_miner_commit (TRACKER_MINER (fs), NULL, commit_cb, NULL);
+			tracker_sparql_connection_update_commit_async (tracker_miner_get_connection (TRACKER_MINER (fs)), NULL, commit_cb, NULL);
 		}
 
 		return TRUE;
@@ -2557,7 +2551,7 @@ ensure_mtime_cache (TrackerMinerFS *fs,
 	}
 
 	if (query) {
-		tracker_miner_execute_sparql (TRACKER_MINER (fs),
+		tracker_sparql_connection_query_async (tracker_miner_get_connection (TRACKER_MINER (fs)),
 		                              query,
 		                              NULL,
 		                              cache_query_cb,
diff --git a/src/libtracker-miner/tracker-miner-fs.h b/src/libtracker-miner/tracker-miner-fs.h
index b30be4b..2188d63 100644
--- a/src/libtracker-miner/tracker-miner-fs.h
+++ b/src/libtracker-miner/tracker-miner-fs.h
@@ -27,7 +27,7 @@
 #include <glib-object.h>
 #include <gio/gio.h>
 
-#include <libtracker-client/tracker-sparql-builder.h>
+#include <libtracker-sparql/tracker-sparql.h>
 
 #include "tracker-miner-object.h"
 
diff --git a/src/libtracker-miner/tracker-miner-object.c b/src/libtracker-miner/tracker-miner-object.c
index 96a8d94..e2c3c9f 100644
--- a/src/libtracker-miner/tracker-miner-object.c
+++ b/src/libtracker-miner/tracker-miner-object.c
@@ -45,7 +45,7 @@
 static GQuark miner_error_quark = 0;
 
 struct TrackerMinerPrivate {
-	TrackerClient *client;
+	TrackerSparqlConnection *connection;
 
 	GHashTable *pauses;
 
@@ -66,17 +66,6 @@ typedef struct {
 	gchar *reason;
 } PauseData;
 
-typedef struct {
-	TrackerMiner *miner;
-	GCancellable *cancellable;
-	gpointer callback;
-	gpointer user_data;
-	gpointer source_function;
-
-	guint id;
-	guint signal_id;
-} AsyncCallData;
-
 enum {
 	PROP_0,
 	PROP_NAME,
@@ -105,18 +94,10 @@ static void       miner_get_property           (GObject       *object,
                                                 GValue        *value,
                                                 GParamSpec    *pspec);
 static void       miner_finalize               (GObject       *object);
-static void       miner_dispose                (GObject       *object);
 static void       miner_constructed            (GObject       *object);
 static void       pause_data_destroy           (gpointer       data);
 static PauseData *pause_data_new               (const gchar   *application,
                                                 const gchar   *reason);
-static void       async_call_data_notify_error (AsyncCallData *data,
-                                                gint           code,
-                                                const gchar   *message);
-static void       async_call_data_destroy      (AsyncCallData *data,
-                                                gboolean       remove);
-static void       sparql_cancelled_cb          (GCancellable  *cancellable,
-                                                AsyncCallData *data);
 static void       store_name_monitor_cb (TrackerMiner *miner,
                                          const gchar  *name,
                                          gboolean      available);
@@ -132,7 +113,6 @@ tracker_miner_class_init (TrackerMinerClass *klass)
 	object_class->get_property = miner_get_property;
 	object_class->finalize     = miner_finalize;
 	object_class->constructed  = miner_constructed;
-	object_class->dispose      = miner_dispose;
 
 	/**
 	 * TrackerMiner::started:
@@ -273,11 +253,12 @@ static void
 tracker_miner_init (TrackerMiner *miner)
 {
 	TrackerMinerPrivate *priv;
+	GError *error = NULL;
 
 	miner->private = priv = TRACKER_MINER_GET_PRIVATE (miner);
 
-	/* Set the timeout to 0 so we don't have one */
-	priv->client = tracker_client_new (TRACKER_CLIENT_ENABLE_WARNINGS, G_MAXINT);
+	priv->connection = tracker_sparql_connection_get (&error);
+	g_assert_no_error (error);
 
 	priv->pauses = g_hash_table_new_full (g_direct_hash,
 	                                      g_direct_equal,
@@ -368,24 +349,6 @@ miner_get_property (GObject    *object,
 }
 
 static void
-async_call_finalize_foreach (AsyncCallData *data,
-                             gpointer       user_data)
-{
-	async_call_data_notify_error (data, 0, "Miner is being finalized");
-	async_call_data_destroy (data, TRUE);
-}
-
-static void
-miner_dispose (GObject *object)
-{
-	TrackerMiner *miner = TRACKER_MINER (object);
-
-	g_ptr_array_foreach (miner->private->async_calls,
-	                     (GFunc) async_call_finalize_foreach,
-	                     object);
-}
-
-static void
 miner_finalize (GObject *object)
 {
 	TrackerMiner *miner = TRACKER_MINER (object);
@@ -393,12 +356,11 @@ miner_finalize (GObject *object)
 	g_free (miner->private->status);
 	g_free (miner->private->name);
 
-	if (miner->private->client) {
-		g_object_unref (miner->private->client);
+	if (miner->private->connection) {
+		g_object_unref (miner->private->connection);
 	}
 
 	g_hash_table_unref (miner->private->pauses);
-	g_ptr_array_free (miner->private->async_calls, TRUE);
 
 	_tracker_miner_dbus_shutdown (miner);
 
@@ -481,179 +443,6 @@ pause_data_destroy (gpointer data)
 	g_slice_free (PauseData, pd);
 }
 
-static void
-async_call_data_destroy (AsyncCallData *data,
-                         gboolean       remove)
-{
-	TrackerMiner *miner = data->miner;
-
-	if (data->cancellable) {
-		if (data->signal_id) {
-			g_signal_handler_disconnect (data->cancellable, data->signal_id);
-		}
-
-		g_object_unref (data->cancellable);
-	}
-
-	if (data->id != 0) {
-		tracker_cancel_call (miner->private->client, data->id);
-		data->id = 0;
-	}
-
-	if (remove) {
-		g_ptr_array_remove_fast (miner->private->async_calls, data);
-	}
-
-	g_slice_free (AsyncCallData, data);
-}
-
-static AsyncCallData *
-async_call_data_new (TrackerMiner *miner,
-                     GCancellable *cancellable,
-                     gpointer      callback,
-                     gpointer      user_data,
-                     gpointer      source_function)
-{
-	AsyncCallData *data;
-
-	data = g_slice_new0 (AsyncCallData);
-	data->miner = miner;
-	data->callback = callback;
-	data->user_data = user_data;
-	data->source_function = source_function;
-
-	if (cancellable) {
-		data->cancellable = g_object_ref (cancellable);
-
-		data->signal_id = g_signal_connect (cancellable, "cancelled",
-		                                    G_CALLBACK (sparql_cancelled_cb), data);
-	}
-
-	g_ptr_array_add (miner->private->async_calls, data);
-
-	return data;
-}
-
-static void
-async_call_data_update_callback (AsyncCallData *data,
-                                 GError        *error)
-{
-	GAsyncReadyCallback callback;
-	GSimpleAsyncResult *result;
-
-	callback = data->callback;
-
-	if (error) {
-		result = g_simple_async_result_new_from_error (G_OBJECT (data->miner),
-		                                               callback,
-		                                               data->user_data,
-		                                               (GError *) error);
-	} else {
-		result = g_simple_async_result_new (G_OBJECT (data->miner),
-		                                    callback,
-		                                    data->user_data,
-		                                    data->source_function);
-	}
-
-	g_simple_async_result_complete (result);
-	g_object_unref (result);
-}
-
-static void
-async_call_data_query_callback (AsyncCallData         *data,
-                                TrackerResultIterator *iterator,
-                                GError                *error)
-{
-	GAsyncReadyCallback callback;
-	GSimpleAsyncResult *result;
-
-	callback = data->callback;
-
-	if (error) {
-		result = g_simple_async_result_new_from_error (G_OBJECT (data->miner),
-		                                               callback,
-		                                               data->user_data,
-		                                               error);
-	} else {
-		result = g_simple_async_result_new (G_OBJECT (data->miner),
-		                                    callback,
-		                                    data->user_data,
-		                                    data->source_function);
-	}
-
-	g_simple_async_result_set_op_res_gpointer (result, (gpointer) iterator, NULL);
-	g_simple_async_result_complete (result);
-	g_object_unref (result);
-}
-
-static void
-async_call_data_notify_error (AsyncCallData *data,
-                              gint           code,
-                              const gchar   *message)
-{
-	TrackerMiner *miner;
-	GError *error;
-
-	miner = data->miner;
-
-	if (data->id != 0) {
-		tracker_cancel_call (miner->private->client, data->id);
-		data->id = 0;
-	}
-
-	if (data->callback) {
-		error = g_error_new_literal (miner_error_quark, code, message);
-
-		if (data->source_function == tracker_miner_execute_update ||
-		    data->source_function == tracker_miner_execute_batch_update ||
-		    data->source_function == tracker_miner_commit) {
-			async_call_data_update_callback (data, error);
-		} else {
-			async_call_data_query_callback (data, NULL, error);
-		}
-
-		g_error_free (error);
-	}
-}
-
-static void
-sparql_update_cb (GError   *error,
-                  gpointer  user_data)
-{
-	AsyncCallData *data = user_data;
-
-	async_call_data_update_callback (data, error);
-	async_call_data_destroy (data, TRUE);
-
-	if (error) {
-		g_error_free (error);
-	}
-}
-
-static void
-sparql_query_cb (TrackerResultIterator *iterator,
-                 GError    *error,
-                 gpointer   user_data)
-{
-	AsyncCallData *data = user_data;
-
-	async_call_data_query_callback (data, iterator, error);
-
-	if (error) {
-		g_error_free (error);
-	}
-
-	async_call_data_destroy (data, TRUE);
-}
-
-static void
-sparql_cancelled_cb (GCancellable  *cancellable,
-                     AsyncCallData *data)
-{
-	async_call_data_notify_error (data, 0, "SPARQL operation was cancelled");
-	async_call_data_destroy (data, TRUE);
-}
-
 /**
  * tracker_miner_error_quark:
  *
@@ -733,275 +522,6 @@ tracker_miner_is_started (TrackerMiner *miner)
 	return miner->private->started;
 }
 
-/**
- * tracker_miner_execute_update:
- * @miner: a #TrackerMiner
- * @sparql: a SPARQL query
- * @cancellable: a #GCancellable to control the operation
- * @callback: a #GAsyncReadyCallback to call when the operation is finished
- * @user_data: data to pass to @callback
- *
- * Executes an update SPARQL query on tracker-store, use this
- * whenever you want to perform data insertions or modifications.
- *
- * When the operation is finished, @callback will be called, providing a #GAsyncResult
- * object. Call tracker_miner_execute_sparql_finish on it to get the returned #GError,
- * if there is one.
- *
- * If the operation is cancelled, @callback will be called anyway, with the #GAsyncResult
- * object containing an error.
- **/
-void
-tracker_miner_execute_update (TrackerMiner        *miner,
-                              const gchar         *sparql,
-                              GCancellable        *cancellable,
-                              GAsyncReadyCallback  callback,
-                              gpointer             user_data)
-{
-	AsyncCallData *data;
-
-	g_return_if_fail (TRACKER_IS_MINER (miner));
-	g_return_if_fail (sparql != NULL);
-	g_return_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable));
-
-	data = async_call_data_new (miner,
-	                            cancellable,
-	                            callback,
-	                            user_data,
-	                            tracker_miner_execute_sparql);
-
-	data->id = tracker_resources_sparql_update_async (miner->private->client,
-	                                                  sparql,
-	                                                  sparql_update_cb,
-	                                                  data);
-}
-
-/**
- * tracker_miner_execute_update_finish:
- * @miner: a #TrackerMiner
- * @result: a #GAsyncResult
- * @error: a #GError
- *
- * Finishes the async update operation. If an error occured during the update,
- * @error will be set.
- *
- **/
-void
-tracker_miner_execute_update_finish (TrackerMiner  *miner,
-                                     GAsyncResult  *result,
-                                     GError       **error)
-{
-	GSimpleAsyncResult *r = G_SIMPLE_ASYNC_RESULT (result);
-
-	g_simple_async_result_propagate_error (r, error);
-}
-
-/**
- * tracker_miner_execute_sparql:
- * @miner: a #TrackerMiner
- * @sparql: a SPARQL query
- * @cancellable: a #GCancellable to control the operation
- * @callback: a #GAsyncReadyCallback to call when the operation is finished
- * @user_data: data to pass to @callback
- *
- * Executes the SPARQL query on tracker-store and returns asynchronously
- * the queried data. Use this whenever you need to get data from
- * already stored information.
- *
- * When the operation is finished, @callback will be called, providing a #GAsyncResult
- * object. Call tracker_miner_execute_sparql_finish on it to get the query results, or
- * the GError object if an error occured.
- *
- * If the operation is cancelled, @callback will be called anyway, with the #GAsyncResult
- * object containing an error.
- **/
-void
-tracker_miner_execute_sparql (TrackerMiner        *miner,
-                              const gchar         *sparql,
-                              GCancellable        *cancellable,
-                              GAsyncReadyCallback  callback,
-                              gpointer             user_data)
-{
-	AsyncCallData *data;
-
-	g_return_if_fail (TRACKER_IS_MINER (miner));
-	g_return_if_fail (sparql != NULL);
-	g_return_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable));
-	g_return_if_fail (callback != NULL);
-
-	data = async_call_data_new (miner, cancellable, callback, user_data, tracker_miner_execute_sparql);
-
-	data->id = tracker_resources_sparql_query_iterate_async (miner->private->client,
-	                                                         sparql, sparql_query_cb,
-	                                                         data);
-}
-
-/**
- * tracker_miner_execute_sparql_finish:
- * @miner: a #TrackerMiner
- * @result: a #GAsyncResult object holding the result of the query
- * @error: a #GError
- *
- * Finishes the async operation and returns the query results. If an error
- * occured during the query, @error will be set.
- *
- * Returns: a #TrackerResultIterator with the sparql results which should not be freed.
- **/
-TrackerResultIterator *
-tracker_miner_execute_sparql_finish (TrackerMiner  *miner,
-                                     GAsyncResult  *result,
-                                     GError       **error)
-{
-	GSimpleAsyncResult *r = G_SIMPLE_ASYNC_RESULT (result);
-
-	if (g_simple_async_result_propagate_error (r, error)) {
-		return NULL;
-	}
-
-	return (TrackerResultIterator*) g_simple_async_result_get_op_res_gpointer (r);
-}
-
-/**
- * tracker_miner_execute_sparql_sync:
- * @miner: a #TrackerMiner
- * @sparql: a SPARQL query
- * @error: a #GError
- *
- * Executes the SPARQL query on tracker-store and blocks until reply arrives.
- * If an error occured during the query, @error will be set.
- * Returns: A #TrackerResultIterator pointing before the first result row. This
- * iterator must be disposed when done using tracker_result_iterator_free().
- *
- * Since: 0.9
- **/
-TrackerResultIterator *
-tracker_miner_execute_sparql_sync (TrackerMiner  *miner,
-                                   const gchar   *sparql,
-                                   GError       **error)
-{
-	g_return_val_if_fail (TRACKER_IS_MINER (miner), NULL);
-	g_return_val_if_fail (sparql != NULL, NULL);
-
-	return tracker_resources_sparql_query_iterate (miner->private->client,
-	                                               sparql,
-	                                               error);
-}
-
-/**
- * tracker_miner_execute_batch_update:
- * @miner: a #TrackerMiner
- * @sparql: a set of SPARQL updates
- * @cancellable: a #GCancellable to control the operation
- * @callback: a #GAsyncReadyCallback to call when the operation is finished
- * @user_data: data to pass to @callback
- *
- * Executes a batch of update SPARQL queries on tracker-store, use this
- * whenever you want to perform data insertions or modifications in
- * batches.
- *
- * When the operation is finished, @callback will be called, providing a #GAsyncResult
- * object. Call tracker_miner_execute_batch_update_finish on it to get the returned #GError,
- * if there is one.
- *
- * If the operation is cancelled, @callback will be called anyway, with the #GAsyncResult
- * object containing an error.
- **/
-void
-tracker_miner_execute_batch_update (TrackerMiner        *miner,
-                                    const gchar         *sparql,
-                                    GCancellable        *cancellable,
-                                    GAsyncReadyCallback  callback,
-                                    gpointer             user_data)
-{
-	AsyncCallData *data;
-
-	g_return_if_fail (TRACKER_IS_MINER (miner));
-	g_return_if_fail (sparql != NULL);
-	g_return_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable));
-
-	data = async_call_data_new (miner, cancellable, callback, user_data, tracker_miner_execute_batch_update);
-
-	data->id = tracker_resources_batch_sparql_update_async (miner->private->client,
-	                                                        sparql, sparql_update_cb,
-	                                                        data);
-}
-
-/**
- * tracker_miner_execute_batch_update_finish:
- * @miner: a #TrackerMiner
- * @result: a #GAsyncResult
- * @error: a #GError
- *
- * Finishes the async batch update operation. If an error occured during the update,
- * @error will be set.
- *
- **/
-void
-tracker_miner_execute_batch_update_finish (TrackerMiner *miner,
-                                           GAsyncResult *result,
-                                           GError      **error)
-{
-	GSimpleAsyncResult *r = G_SIMPLE_ASYNC_RESULT (result);
-
-	g_simple_async_result_propagate_error (r, error);
-}
-
-/**
- * tracker_miner_commit:
- * @miner: a #TrackerMiner
- * @cancellable: a #GCancellable to control the operation
- * @callback: a #GAsyncReadyCallback to call when the operation is finished
- * @user_data: data to pass to @callback
- *
- * Commits all pending batch updates. See tracker_miner_execute_batch_update().
- *
- * When the operation is finished, @callback will be called, providing a #GAsyncResult
- * object. Call tracker_miner_commit_finish on it to get the returned #GError,
- * if there is one.
- *
- * If the operation is cancelled, @callback will be called anyway, with the #GAsyncResult
- * object containing an error.
- **/
-
-void
-tracker_miner_commit (TrackerMiner        *miner,
-                      GCancellable        *cancellable,
-                      GAsyncReadyCallback  callback,
-                      gpointer             user_data)
-
-{
-	AsyncCallData *data;
-
-	g_return_if_fail (TRACKER_IS_MINER (miner));
-	g_return_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable));
-
-	data = async_call_data_new (miner, cancellable, callback, user_data, tracker_miner_commit);
-
-	data->id = tracker_resources_batch_commit_async (miner->private->client,
-	                                                 sparql_update_cb,
-	                                                 data);
-}
-
-/**
- * tracker_miner_commit_finish:
- * @miner: a #TrackerMiner
- * @result: a #GAsyncResult
- * @error: a #GError
- *
- * Finishes the async comit operation. If an error occured during the commit,
- * @error will be set.
- *
- **/
-void
-tracker_miner_commit_finish (TrackerMiner  *miner,
-                             GAsyncResult  *result,
-                             GError       **error)
-{
-	GSimpleAsyncResult *r = G_SIMPLE_ASYNC_RESULT (result);
-
-	g_simple_async_result_propagate_error (r, error);
-}
-
 static gint
 tracker_miner_pause_internal (TrackerMiner  *miner,
                               const gchar   *application,
@@ -1106,6 +626,12 @@ tracker_miner_resume (TrackerMiner  *miner,
 	return TRUE;
 }
 
+TrackerSparqlConnection *
+tracker_miner_get_connection (TrackerMiner *miner)
+{
+	return miner->private->connection;
+}
+
 /* DBus methods */
 void
 _tracker_miner_dbus_get_status (TrackerMiner           *miner,
diff --git a/src/libtracker-miner/tracker-miner-object.h b/src/libtracker-miner/tracker-miner-object.h
index 677936f..ae1292d 100644
--- a/src/libtracker-miner/tracker-miner-object.h
+++ b/src/libtracker-miner/tracker-miner-object.h
@@ -26,7 +26,8 @@
 
 #include <glib-object.h>
 #include <gio/gio.h>
-#include <libtracker-client/tracker-client.h>
+
+#include <libtracker-sparql/tracker-sparql.h>
 
 G_BEGIN_DECLS
 
@@ -98,42 +99,9 @@ gint             tracker_miner_pause                       (TrackerMiner
 gboolean         tracker_miner_resume                      (TrackerMiner         *miner,
                                                             gint                  cookie,
                                                             GError              **error);
-void             tracker_miner_execute_update              (TrackerMiner         *miner,
-                                                            const gchar          *sparql,
-                                                            GCancellable         *cancellable,
-                                                            GAsyncReadyCallback   callback,
-                                                            gpointer              user_data);
-void             tracker_miner_execute_update_finish       (TrackerMiner         *miner,
-                                                            GAsyncResult         *result,
-                                                            GError              **error);
-void             tracker_miner_execute_sparql              (TrackerMiner         *miner,
-                                                            const gchar          *sparql,
-                                                            GCancellable         *cancellable,
-                                                            GAsyncReadyCallback   callback,
-                                                            gpointer              user_data);
-TrackerResultIterator *
-                 tracker_miner_execute_sparql_finish       (TrackerMiner         *miner,
-                                                            GAsyncResult         *result,
-                                                            GError              **error);
-TrackerResultIterator *
-                 tracker_miner_execute_sparql_sync         (TrackerMiner         *miner,
-                                                            const gchar          *sparql,
-                                                            GError              **error);
-void             tracker_miner_execute_batch_update        (TrackerMiner         *miner,
-                                                            const gchar          *sparql,
-                                                            GCancellable         *cancellable,
-                                                            GAsyncReadyCallback   callback,
-                                                            gpointer              user_data);
-void             tracker_miner_execute_batch_update_finish (TrackerMiner         *miner,
-                                                            GAsyncResult         *result,
-                                                            GError              **error);
-void             tracker_miner_commit                      (TrackerMiner         *miner,
-                                                            GCancellable         *cancellable,
-                                                            GAsyncReadyCallback   callback,
-                                                            gpointer              user_data);
-void             tracker_miner_commit_finish               (TrackerMiner         *miner,
-                                                            GAsyncResult         *result,
-                                                            GError              **error);
+
+TrackerSparqlConnection *
+                 tracker_miner_get_connection              (TrackerMiner         *miner);
 
 G_END_DECLS
 
diff --git a/src/miners/fs/tracker-main.c b/src/miners/fs/tracker-main.c
index 2b6fe83..7f6cce6 100644
--- a/src/miners/fs/tracker-main.c
+++ b/src/miners/fs/tracker-main.c
@@ -291,7 +291,6 @@ miner_finished_cb (TrackerMinerFS *fs,
 static void
 finalize_miner (TrackerMiner *miner)
 {
-	g_object_run_dispose (G_OBJECT (miner));
 	g_object_unref (G_OBJECT (miner));
 }
 
diff --git a/src/miners/fs/tracker-miner-files.c b/src/miners/fs/tracker-miner-files.c
index b8d83eb..8bc4ded 100644
--- a/src/miners/fs/tracker-miner-files.c
+++ b/src/miners/fs/tracker-miner-files.c
@@ -661,7 +661,7 @@ set_up_mount_point_cb (GObject      *source,
 	gchar *removable_device_urn = user_data;
 	GError *error = NULL;
 
-	tracker_miner_execute_update_finish (TRACKER_MINER (source),
+	tracker_sparql_connection_update_finish (tracker_miner_get_connection (TRACKER_MINER (source)),
 	                                     result,
 	                                     &error);
 
@@ -801,9 +801,9 @@ set_up_mount_point (TrackerMinerFiles *miner,
 	if (accumulator) {
 		g_string_append_printf (accumulator, "%s ", queries->str);
 	} else {
-		tracker_miner_execute_update (TRACKER_MINER (miner),
+		tracker_sparql_connection_update_async (tracker_miner_get_connection (TRACKER_MINER (miner)),
 		                              queries->str,
-		                              NULL,
+		                              NULL, NULL,
 		                              set_up_mount_point_cb,
 		                              g_strdup (removable_device_urn));
 	}
@@ -818,7 +818,7 @@ init_mount_points_cb (GObject      *source,
 {
 	GError *error = NULL;
 
-	tracker_miner_execute_update_finish (TRACKER_MINER (source),
+	tracker_sparql_connection_update_finish (TRACKER_SPARQL_CONNECTION (source),
 	                                     result,
 	                                     &error);
 
@@ -831,7 +831,7 @@ init_mount_points_cb (GObject      *source,
 		 * the mount points, as we need the correct tracker:isMounted value
 		 * for all currently mounted volumes
 		 */
-		init_stale_volume_removal (TRACKER_MINER_FILES (source));
+		init_stale_volume_removal (TRACKER_MINER_FILES (user_data));
 	}
 }
 
@@ -845,15 +845,15 @@ init_mount_points (TrackerMinerFiles *miner_files)
 	gpointer key, value;
 	GString *accumulator;
 	GError *error = NULL;
-	TrackerResultIterator *iterator;
+	TrackerSparqlCursor *cursor;
 	GSList *uuids, *u;
 
 	g_debug ("Initializing mount points...");
 
 	/* First, get all mounted volumes, according to tracker-store (SYNC!) */
-	iterator = tracker_miner_execute_sparql_sync (TRACKER_MINER (miner),
-	                                              "SELECT ?v WHERE { ?v a tracker:Volume ; tracker:isMounted true }",
-	                                              &error);
+	cursor = tracker_sparql_connection_query (tracker_miner_get_connection (miner),
+	                                          "SELECT ?v WHERE { ?v a tracker:Volume ; tracker:isMounted true }",
+	                                          &error);
 	if (error) {
 		g_critical ("Could not obtain the mounted volumes: %s", error->message);
 		g_error_free (error);
@@ -875,13 +875,13 @@ init_mount_points (TrackerMinerFiles *miner_files)
                              g_strdup (TRACKER_NON_REMOVABLE_MEDIA_DATASOURCE_URN),
                              GINT_TO_POINTER (VOLUME_MOUNTED));
 
-	while (tracker_result_iterator_next (iterator)) {
+	while (tracker_sparql_cursor_next (cursor, NULL, NULL)) {
 		gint state;
 		const gchar *urn;
 
 		state = VOLUME_MOUNTED_IN_STORE;
 
-		urn = tracker_result_iterator_value (iterator, 0);
+		urn = tracker_sparql_cursor_get_string (cursor, 0, NULL);
 
 		if (strcmp (urn, TRACKER_NON_REMOVABLE_MEDIA_DATASOURCE_URN) == 0) {
 			/* Report non-removable media to be mounted by HAL as well */
@@ -994,11 +994,11 @@ init_mount_points (TrackerMinerFiles *miner_files)
 	}
 
 	if (accumulator->str[0] != '\0') {
-		tracker_miner_execute_update (miner,
+		tracker_sparql_connection_update_async (tracker_miner_get_connection (miner),
 		                              accumulator->str,
-		                              NULL,
+		                              NULL, NULL,
 		                              init_mount_points_cb,
-		                              NULL);
+		                              miner);
 	} else {
 		/* If no further mount point initialization was needed,
 		 * initialize stale volume removal here. */
@@ -1158,9 +1158,9 @@ mount_point_added_cb (TrackerStorage *storage,
 	queries = g_string_new ("");
 	set_up_mount_point (miner, urn, mount_point, TRUE, queries);
 	set_up_mount_point_type (miner, urn, removable, optical, queries);
-	tracker_miner_execute_update (TRACKER_MINER (miner),
+	tracker_sparql_connection_update_async (tracker_miner_get_connection (TRACKER_MINER (miner)),
 	                              queries->str,
-	                              NULL,
+	                              NULL, NULL,
 	                              set_up_mount_point_cb,
 	                              g_strdup (urn));
 	g_string_free (queries, TRUE);
@@ -2576,7 +2576,7 @@ remove_files_in_removable_media_cb (GObject      *object,
 {
 	GError *error = NULL;
 
-	tracker_miner_execute_update_finish (TRACKER_MINER (object), result, &error);
+	tracker_sparql_connection_update_finish (TRACKER_SPARQL_CONNECTION (object), result, &error);
 
 	if (error) {
 		g_critical ("Could not remove files in volumes: %s", error->message);
@@ -2617,9 +2617,9 @@ miner_files_in_removable_media_remove_by_type (TrackerMinerFiles  *miner,
 		                        removable ? "true" : "false",
 		                        optical ? "true" : "false");
 
-		tracker_miner_execute_batch_update (TRACKER_MINER (miner),
+		tracker_sparql_connection_update_async (tracker_miner_get_connection (TRACKER_MINER (miner)),
 		                                    queries->str,
-		                                    NULL,
+		                                    NULL, NULL,
 		                                    remove_files_in_removable_media_cb,
 		                                    NULL);
 
@@ -2658,9 +2658,9 @@ miner_files_in_removable_media_remove_by_date (TrackerMinerFiles  *miner,
 	                        "}",
 	                        date);
 
-	tracker_miner_execute_batch_update (TRACKER_MINER (miner),
+	tracker_sparql_connection_update_async (tracker_miner_get_connection (TRACKER_MINER (miner)),
 	                                    queries->str,
-	                                    NULL,
+	                                    NULL, NULL,
 	                                    remove_files_in_removable_media_cb,
 	                                    NULL);
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]