[tracker] libtracker-miner: Make TrackerMiner use standard gio callbacks and port TrackerMinerFS



commit f34e0dadf013c9468f7208403b0af0d638335f8a
Author: Adrien Bustany <madcat mymadcat com>
Date:   Tue Nov 10 12:59:48 2009 -0300

    libtracker-miner: Make TrackerMiner use standard gio callbacks and port TrackerMinerFS
    
    TrackerMiner previously used custom callbacks for its async calls
    tracker_miner_execute_sparql, tracker_miner_execute_update etc. This commit
    changes the API to make them use the standard GLib callback pattern
    my_callback (GObject *source, GAsyncResult *result, gpointer user_data) .
    The API of TrackerMinerFS is not changed, but it's internaly ported to the
    new functions.
    The miners using the tracker_miner_* functions have to be ported to use
    the new API.
    This patch also ports the existing miners.

 src/libtracker-miner/tracker-miner-fs.c    |  107 +++++++-----
 src/libtracker-miner/tracker-miner.c       |  254 +++++++++++++++++++++-------
 src/libtracker-miner/tracker-miner.h       |   96 ++++++-----
 src/tracker-miner-fs/tracker-miner-files.c |   39 +++--
 4 files changed, 334 insertions(+), 162 deletions(-)
---
diff --git a/src/libtracker-miner/tracker-miner-fs.c b/src/libtracker-miner/tracker-miner-fs.c
index acf6d6e..d3bd1db 100644
--- a/src/libtracker-miner/tracker-miner-fs.c
+++ b/src/libtracker-miner/tracker-miner-fs.c
@@ -590,7 +590,7 @@ fs_get_property (GObject    *object,
 	}
 }
 
-static gboolean 
+static gboolean
 fs_defaults (TrackerMinerFS *fs,
 	     GFile          *file)
 {
@@ -614,8 +614,8 @@ miner_started (TrackerMiner *miner)
 
 	fs->private->been_started = TRUE;
 
-	g_object_set (miner, 
-		      "progress", 0.0, 
+	g_object_set (miner,
+		      "progress", 0.0,
 		      "status", _("Initializing"),
 		      NULL);
 
@@ -625,8 +625,8 @@ miner_started (TrackerMiner *miner)
 static void
 miner_stopped (TrackerMiner *miner)
 {
-	g_object_set (miner, 
-		      "progress", 1.0, 
+	g_object_set (miner,
+		      "progress", 1.0,
 		      "status", _("Idle"),
 		      NULL);
 }
@@ -719,17 +719,22 @@ process_print_stats (TrackerMinerFS *fs)
 }
 
 static void
-commit_cb (TrackerMiner *miner,
-	   const GError *error,
-	   gpointer      user_data)
+commit_cb (GObject      *object,
+           GAsyncResult *result,
+           gpointer      user_data)
 {
+	TrackerMiner *miner = TRACKER_MINER (object);
+	GError *error = NULL;
+
+	tracker_miner_commit_finish (miner, result, &error);
+
 	if (error) {
 		g_critical ("Could not commit: %s", error->message);
 	}
 }
 
 static void
-process_stop (TrackerMinerFS *fs) 
+process_stop (TrackerMinerFS *fs)
 {
 	/* Now we have finished crawling, print stats and enable monitor events */
 	process_print_stats (fs);
@@ -738,8 +743,8 @@ process_stop (TrackerMinerFS *fs)
 
 	g_message ("Idle");
 
-	g_object_set (fs, 
-		      "progress", 1.0, 
+	g_object_set (fs,
+		      "progress", 1.0,
 		      "status", _("Idle"),
 		      NULL);
 
@@ -785,15 +790,19 @@ item_moved_data_free (ItemMovedData *data)
 }
 
 static void
-sparql_update_cb (TrackerMiner *miner,
-		  const GError *error,
-		  gpointer      user_data)
+sparql_update_cb (GObject      *object,
+                  GAsyncResult *result,
+                  gpointer      user_data)
 {
 	TrackerMinerFS *fs;
 	TrackerMinerFSPrivate *priv;
 	ProcessData *data;
 
-	fs = TRACKER_MINER_FS (miner);
+	GError *error = NULL;
+
+	tracker_miner_execute_update_finish (TRACKER_MINER (object), result, &error);
+
+	fs = TRACKER_MINER_FS (object);
 	priv = fs->private;
 	data = user_data;
 
@@ -815,14 +824,18 @@ sparql_update_cb (TrackerMiner *miner,
 }
 
 static void
-sparql_query_cb (TrackerMiner *miner,
-		 GPtrArray    *result,
-		 const GError *error,
-		 gpointer      user_data)
+sparql_query_cb (GObject      *object,
+                 GAsyncResult *result,
+                 gpointer      user_data)
 {
 	SparqlQueryData *data = user_data;
+	TrackerMiner *miner = TRACKER_MINER (object);
+
+	GError *error = NULL;
+
+	const GPtrArray *query_results = tracker_miner_execute_sparql_finish (miner, result, &error);
 
-	data->value = result && result->len == 1;
+	data->value = query_results && query_results->len == 1;
 	g_main_loop_quit (data->main_loop);
 }
 
@@ -1012,24 +1025,26 @@ item_remove (TrackerMinerFS *fs,
 }
 
 static void
-item_update_uri_recursively_cb (TrackerMiner *miner,
-				GPtrArray    *result,
-				const GError *error,
-				gpointer      user_data)
+item_update_uri_recursively_cb (GObject      *object,
+                                GAsyncResult *result,
+                                gpointer      user_data)
 {
-	TrackerMinerFS *fs = TRACKER_MINER_FS (miner);
+	TrackerMinerFS *fs = TRACKER_MINER_FS (object);
 	RecursiveMoveData *data = user_data;
+	GError *error = NULL;
+
+	const GPtrArray *query_results = tracker_miner_execute_sparql_finish (TRACKER_MINER (object), result, &error);
 
 	if (error) {
 		g_critical ("Could not query children: %s", error->message);
 	} else {
-		if (result) {
+		if (query_results) {
 			gint i;
 
-			for (i = 0; i < result->len; i++) {
+			for (i = 0; i < query_results->len; i++) {
 				gchar **child_source_uri, *child_uri;
 
-				child_source_uri = g_ptr_array_index (result, i);
+				child_source_uri = g_ptr_array_index (query_results, i);
 
 				if (!g_str_has_prefix (*child_source_uri, data->source_uri)) {
 					g_warning ("Child URI '%s' does not start with parent URI '%s'",
@@ -1222,7 +1237,7 @@ item_queue_get_progress (TrackerMinerFS *fs)
 {
 	guint items_to_process = 0;
 	guint items_total = 0;
-	
+
 	items_to_process += g_queue_get_length (fs->private->items_deleted);
 	items_to_process += g_queue_get_length (fs->private->items_created);
 	items_to_process += g_queue_get_length (fs->private->items_updated);
@@ -1378,10 +1393,10 @@ should_change_index_for_file (TrackerMinerFS *fs,
 	gchar              *query, *uri;
 	SparqlQueryData     data;
 
-	file_info = g_file_query_info (file, 
-				       G_FILE_ATTRIBUTE_TIME_MODIFIED, 
-				       G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, 
-				       NULL, 
+	file_info = g_file_query_info (file,
+				       G_FILE_ATTRIBUTE_TIME_MODIFIED,
+				       G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
+				       NULL,
 				       NULL);
 	if (!file_info) {
 		/* NOTE: We return TRUE here because we want to update the DB
@@ -1489,7 +1504,7 @@ monitor_item_created_cb (TrackerMonitor *monitor,
 		} else {
 			g_queue_push_tail (fs->private->items_created,
 					   g_object_ref (file));
-			
+
 			item_queue_handlers_set_up (fs);
 		}
 	}
@@ -1559,17 +1574,17 @@ monitor_item_deleted_cb (TrackerMonitor *monitor,
 	/* Remove directory from list of directories we are going to
 	 * iterate if it is in there.
 	 */
-	l = g_list_find_custom (fs->private->directories, 
-				path, 
+	l = g_list_find_custom (fs->private->directories,
+				path,
 				(GCompareFunc) g_strcmp0);
 
 	/* Make sure we don't remove the current device we are
 	 * processing, this is because we do this same clean up later
-	 * in process_device_next() 
+	 * in process_device_next()
 	 */
 	if (l && l != fs->private->current_directory) {
 		directory_data_free (l->data);
-		fs->private->directories = 
+		fs->private->directories =
 			g_list_delete_link (fs->private->directories, l);
 	}
 #endif
@@ -1595,7 +1610,7 @@ monitor_item_moved_cb (TrackerMonitor *monitor,
 
 			path = g_file_get_path (other_file);
 
-			g_debug ("Not in store:'?'->'%s' (DIR) (move monitor event, source unknown)", 
+			g_debug ("Not in store:'?'->'%s' (DIR) (move monitor event, source unknown)",
 				 path);
 
 			/* If the source is not monitored, we need to crawl it. */
@@ -1632,12 +1647,12 @@ monitor_item_moved_cb (TrackerMonitor *monitor,
 		} else if (!source_stored) {
 			/* Source file was not stored, check dest file as new */
 			if (!is_directory) {
-				g_queue_push_tail (fs->private->items_created, 
+				g_queue_push_tail (fs->private->items_created,
 						   g_object_ref (other_file));
-				
+
 				item_queue_handlers_set_up (fs);
 			} else {
-				g_debug ("Not in store:'?'->'%s' (DIR) (move monitor event, source monitored)", 
+				g_debug ("Not in store:'?'->'%s' (DIR) (move monitor event, source monitored)",
 					 path);
 
 				tracker_miner_fs_add_directory (fs, other_file, TRUE);
@@ -1645,7 +1660,7 @@ monitor_item_moved_cb (TrackerMonitor *monitor,
 		} else if (!should_process_other) {
 			/* Delete old file */
 			g_queue_push_tail (fs->private->items_deleted, g_object_ref (file));
-			
+
 			item_queue_handlers_set_up (fs);
 		} else {
 			/* Move old file to new file */
@@ -1654,7 +1669,7 @@ monitor_item_moved_cb (TrackerMonitor *monitor,
 
 			item_queue_handlers_set_up (fs);
 		}
-		
+
 		g_free (other_path);
 		g_free (path);
 	}
@@ -1695,7 +1710,7 @@ crawler_check_directory_cb (TrackerCrawler *crawler,
 	g_signal_emit (fs, signals[MONITOR_DIRECTORY], 0, file, &add_monitor);
 
 	/* FIXME: Should we add here or when we process the queue in
-	 * the finished sig? 
+	 * the finished sig?
 	 */
 	if (add_monitor) {
 		tracker_monitor_add (fs->private->monitor, file);
@@ -1707,7 +1722,7 @@ crawler_check_directory_cb (TrackerCrawler *crawler,
 	 * is not done recursively.
 	 *
 	 * As such, we only use the "check" rules here, we don't do
-	 * any database comparison with mtime. 
+	 * any database comparison with mtime.
 	 */
 	return should_check;
 }
diff --git a/src/libtracker-miner/tracker-miner.c b/src/libtracker-miner/tracker-miner.c
index 5d02e46..c529035 100644
--- a/src/libtracker-miner/tracker-miner.c
+++ b/src/libtracker-miner/tracker-miner.c
@@ -48,11 +48,11 @@ static GQuark miner_error_quark = 0;
 
 struct TrackerMinerPrivate {
 	TrackerClient *client;
-	
+
 	GHashTable *pauses;
 
 	gboolean started;
-	
+
 	gchar *name;
 	gchar *status;
 	gdouble progress;
@@ -71,7 +71,7 @@ typedef struct {
 typedef struct {
 	gint cookie;
 	gchar *application;
-	gchar *reason;	
+	gchar *reason;
 } PauseData;
 
 typedef struct {
@@ -79,10 +79,10 @@ typedef struct {
 	GCancellable *cancellable;
 	gpointer callback;
 	gpointer user_data;
+	gpointer source_function;
 
 	guint id;
 	guint signal_id;
-	gboolean update;
 } AsyncCallData;
 
 enum {
@@ -667,7 +667,7 @@ static void
 pause_data_destroy (gpointer data)
 {
 	PauseData *pd;
-	
+
 	pd = data;
 
 	g_free (pd->reason);
@@ -754,29 +754,54 @@ async_call_data_destroy (AsyncCallData *data,
 
 static void
 run_update_callback (AsyncCallData *data,
-		     const GError  *error)
+                     GError        *error)
 {
-	TrackerMinerUpdateCallback callback;
-
+	GAsyncReadyCallback callback;
 	callback = data->callback;
+	GSimpleAsyncResult *result = NULL;
 
-	if (callback) {
-		(callback) (data->miner, error, data->user_data);
+	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_complete (result);
+	g_object_unref (result);
 }
 
 static void
-run_query_callback (AsyncCallData *data,
-		    GPtrArray     *result,
-		    const GError  *error)
+run_query_callback (AsyncCallData   *data,
+                    const GPtrArray *query_results,
+                    GError          *error)
 {
-	TrackerMinerQueryCallback callback;
+	GAsyncReadyCallback callback;
 
 	callback = data->callback;
 
-	if (callback) {
-		(callback) (data->miner, result, error, data->user_data);
+	GSimpleAsyncResult *result = NULL;
+
+	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, query_results, NULL);
+	g_simple_async_result_complete (result);
+	g_object_unref (result);
 }
 
 static void
@@ -832,7 +857,7 @@ async_call_data_new (TrackerMiner *miner,
 		     GCancellable *cancellable,
 		     gpointer      callback,
 		     gpointer      user_data,
-		     gboolean      update)
+             gpointer      source_function)
 {
 	AsyncCallData *data;
 
@@ -840,7 +865,7 @@ async_call_data_new (TrackerMiner *miner,
 	data->miner = miner;
 	data->callback = callback;
 	data->user_data = user_data;
-	data->update = update;
+	data->source_function = source_function;
 
 	if (cancellable) {
 		data->cancellable = g_object_ref (cancellable);
@@ -872,7 +897,9 @@ async_call_notify_error (AsyncCallData *data,
 	if (data->callback) {
 		error = g_error_new_literal (miner_error_quark, code, message);
 
-		if (data->update) {
+		if (data->source_function == tracker_miner_execute_update ||
+		    data->source_function == tracker_miner_execute_batch_update ||
+		    data->source_function == tracker_miner_commit) {
 			run_update_callback (data, error);
 		} else {
 			run_query_callback (data, NULL, error);
@@ -887,21 +914,25 @@ async_call_notify_error (AsyncCallData *data,
  * @miner: a #TrackerMiner
  * @sparql: a SPARQL query
  * @cancellable: a #GCancellable to control the operation
- * @callback: a #TrackerMinerUpdateCallback to call when the operation is finished
+ * @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 the error, if any.
- * If the operation is cancelled, @callback will be called anyways, with error filled in.
+ * 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,
-			      TrackerMinerUpdateCallback  callback,
-			      gpointer                    user_data)
+tracker_miner_execute_update (TrackerMiner        *miner,
+                              const gchar         *sparql,
+                              GCancellable        *cancellable,
+                              GAsyncReadyCallback  callback,
+                              gpointer             user_data)
 {
 	TrackerMinerPrivate *priv;
 	AsyncCallData *data;
@@ -911,11 +942,36 @@ tracker_miner_execute_update (TrackerMiner               *miner,
 	g_return_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable));
 
 	priv = TRACKER_MINER_GET_PRIVATE (miner);
-	data = async_call_data_new (miner, cancellable, callback, user_data, TRUE);
+	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);
+	                                                  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);
 }
 
 /**
@@ -923,23 +979,26 @@ tracker_miner_execute_update (TrackerMiner               *miner,
  * @miner: a #TrackerMiner
  * @sparql: a SPARQL query
  * @cancellable: a #GCancellable to control the operation
- * @callback: a #TrackerMinerQueryCallback to call when the operation is finished
+ * @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 the queried data,
- * or the error, if any. If the operation is cancelled, @callback will be called with the
- * error parameter filled in.
+ * 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,
-			      TrackerMinerQueryCallback  callback,
-			      gpointer                   user_data)
+                              const gchar               *sparql,
+                              GCancellable              *cancellable,
+                              GAsyncReadyCallback        callback,
+                              gpointer                   user_data)
 {
 	TrackerMinerPrivate *priv;
 	AsyncCallData *data;
@@ -950,7 +1009,7 @@ tracker_miner_execute_sparql (TrackerMiner              *miner,
 	g_return_if_fail (callback != NULL);
 
 	priv = TRACKER_MINER_GET_PRIVATE (miner);
-	data = async_call_data_new (miner, cancellable, callback, user_data, FALSE);
+	data = async_call_data_new (miner, cancellable, callback, user_data, tracker_miner_execute_sparql);
 
 	data->id = tracker_resources_sparql_query_async (miner->private->client,
 							 sparql, sparql_query_cb,
@@ -958,26 +1017,54 @@ tracker_miner_execute_sparql (TrackerMiner              *miner,
 }
 
 /**
+ * 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.
+ *
+ **/
+const GPtrArray*
+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 (const GPtrArray*) g_simple_async_result_get_op_res_gpointer (r);
+}
+
+/**
  * tracker_miner_execute_batch_update:
  * @miner: a #TrackerMiner
  * @sparql: a set of SPARQL updates
  * @cancellable: a #GCancellable to control the operation
- * @callback: a #TrackerMinerUpdateCallback to call when the operation is finished
+ * @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 the error, if any.
- * If the operation is cancelled, @callback will be called anyways, with error filled in.
+ * 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,
-				    TrackerMinerUpdateCallback  callback,
-				    gpointer                    user_data)
+                                    const gchar                *sparql,
+                                    GCancellable               *cancellable,
+                                    GAsyncReadyCallback         callback,
+                                    gpointer                    user_data)
 {
 	TrackerMinerPrivate *priv;
 	AsyncCallData *data;
@@ -987,7 +1074,7 @@ tracker_miner_execute_batch_update (TrackerMiner               *miner,
 	g_return_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable));
 
 	priv = TRACKER_MINER_GET_PRIVATE (miner);
-	data = async_call_data_new (miner, cancellable, callback, user_data, TRUE);
+	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,
@@ -995,22 +1082,47 @@ tracker_miner_execute_batch_update (TrackerMiner               *miner,
 }
 
 /**
+ * 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 #TrackerMinerUpdateCallback to call when the operation is finished
+ * @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, with the error parameter filled
- * in, if any. If the operation is cancelled through @cancellable, the callback will be
- * called anyways with error filled in.
+ * 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,
-		      TrackerMinerUpdateCallback  callback,
-		      gpointer                    user_data)
+                      GCancellable               *cancellable,
+                      GAsyncReadyCallback         callback,
+                      gpointer                    user_data)
 
 {
 	TrackerMinerPrivate *priv;
@@ -1020,13 +1132,33 @@ tracker_miner_commit (TrackerMiner               *miner,
 	g_return_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable));
 
 	priv = TRACKER_MINER_GET_PRIVATE (miner);
-	data = async_call_data_new (miner, cancellable, callback, user_data, TRUE);
+	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,
@@ -1042,7 +1174,7 @@ tracker_miner_pause_internal (TrackerMiner  *miner,
 	while (g_hash_table_iter_next (&iter, &key, &value)) {
 		PauseData *pd = value;
 
-		if (g_strcmp0 (application, pd->application) == 0 && 
+		if (g_strcmp0 (application, pd->application) == 0 &&
 		    g_strcmp0 (reason, pd->reason) == 0) {
 			/* Can't use duplicate pauses */
 			g_set_error_literal (error, TRACKER_MINER_ERROR, 0,
@@ -1053,7 +1185,7 @@ tracker_miner_pause_internal (TrackerMiner  *miner,
 
 	pd = pause_data_new (application, reason);
 
-	g_hash_table_insert (miner->private->pauses, 
+	g_hash_table_insert (miner->private->pauses,
 			     GINT_TO_POINTER (pd->cookie),
 			     pd);
 
@@ -1109,7 +1241,7 @@ tracker_miner_pause (TrackerMiner  *miner,
  *
  * Returns: #TRUE if the cookie was valid.
  **/
-gboolean 
+gboolean
 tracker_miner_resume (TrackerMiner  *miner,
 		      gint           cookie,
 		      GError       **error)
@@ -1208,7 +1340,7 @@ tracker_miner_dbus_get_pause_details (TrackerMiner           *miner,
 
 	g_strfreev (applications_strv);
 	g_strfreev (reasons_strv);
-	
+
 	g_slist_free (applications);
 	g_slist_free (reasons);
 }
@@ -1267,7 +1399,7 @@ tracker_miner_dbus_resume (TrackerMiner           *miner,
 
 	tracker_dbus_async_return_if_fail (miner != NULL, context);
 
-	tracker_dbus_request_new (request_id, "%s(cookie:%d)", 
+	tracker_dbus_request_new (request_id, "%s(cookie:%d)",
 				  __PRETTY_FUNCTION__,
 				  cookie);
 
diff --git a/src/libtracker-miner/tracker-miner.h b/src/libtracker-miner/tracker-miner.h
index af046e4..cecf438 100644
--- a/src/libtracker-miner/tracker-miner.h
+++ b/src/libtracker-miner/tracker-miner.h
@@ -83,49 +83,59 @@ typedef struct {
 			     GError       *error);
 } TrackerMinerClass;
 
-typedef void (* TrackerMinerUpdateCallback) (TrackerMiner *miner,
-					     const GError *error,
-					     gpointer      user_data);
-typedef void (* TrackerMinerQueryCallback)  (TrackerMiner *miner,
-					     GPtrArray    *result,
-					     const GError *error,
-					     gpointer      user_data);
-
-GType          tracker_miner_get_type       (void) G_GNUC_CONST;
-GQuark	       tracker_miner_error_quark    (void);
-
-void           tracker_miner_start          (TrackerMiner  *miner);
-void           tracker_miner_stop           (TrackerMiner  *miner);
-
-gboolean       tracker_miner_is_started     (TrackerMiner  *miner);
-
-gint           tracker_miner_pause          (TrackerMiner  *miner,
-					     const gchar   *reason,
-					     GError       **error);
-gboolean       tracker_miner_resume         (TrackerMiner  *miner,
-					     gint           cookie,
-					     GError       **error);
-
-void           tracker_miner_execute_update       (TrackerMiner               *miner,
-						   const gchar                *sparql,
-						   GCancellable               *cancellable,
-						   TrackerMinerUpdateCallback  callback,
-						   gpointer                    user_data);
-void           tracker_miner_execute_sparql       (TrackerMiner               *miner,
-						   const gchar                *sparql,
-						   GCancellable               *cancellable,
-						   TrackerMinerQueryCallback   callback,
-						   gpointer                    user_data);
-void           tracker_miner_execute_batch_update (TrackerMiner               *miner,
-						   const gchar                *sparql,
-						   GCancellable               *cancellable,
-						   TrackerMinerUpdateCallback  callback,
-						   gpointer                    user_data);
-void           tracker_miner_commit               (TrackerMiner               *miner,
-						   GCancellable               *cancellable,
-						   TrackerMinerUpdateCallback  callback,
-						   gpointer                    user_data);
-
+GType            tracker_miner_get_type       (void) G_GNUC_CONST;
+GQuark	         tracker_miner_error_quark    (void);
+
+void             tracker_miner_start          (TrackerMiner  *miner);
+void             tracker_miner_stop           (TrackerMiner  *miner);
+
+gboolean         tracker_miner_is_started     (TrackerMiner  *miner);
+
+gint             tracker_miner_pause          (TrackerMiner  *miner,
+                                               const gchar   *reason,
+                                               GError       **error);
+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);
+
+const GPtrArray* tracker_miner_execute_sparql_finish       (TrackerMiner        *miner,
+                                                            GAsyncResult        *result,
+                                                            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);
 
 G_END_DECLS
 
diff --git a/src/tracker-miner-fs/tracker-miner-files.c b/src/tracker-miner-fs/tracker-miner-files.c
index 415b97a..9ee6b7e 100644
--- a/src/tracker-miner-fs/tracker-miner-files.c
+++ b/src/tracker-miner-fs/tracker-miner-files.c
@@ -430,12 +430,17 @@ miner_files_constructed (GObject *object)
 }
 
 static void
-set_up_mount_point_cb (TrackerMiner *miner,
-		       const GError *error,
-		       gpointer      user_data)
+set_up_mount_point_cb (GObject      *source,
+                       GAsyncResult *result,
+                       gpointer      user_data)
 {
 	gchar *removable_device_urn = user_data;
 
+	GError *error = NULL;
+	tracker_miner_execute_update_finish (TRACKER_MINER (source),
+	                                     result,
+	                                     &error);
+
 	if (error) {
 		g_critical ("Could not set up mount point '%s': %s",
 			    removable_device_urn, error->message);
@@ -525,10 +530,15 @@ set_up_mount_point (TrackerMinerFiles *miner,
 }
 
 static void
-init_mount_points_cb (TrackerMiner *miner,
-		      const GError *error,
-		      gpointer      user_data)
+init_mount_points_cb (GObject      *source,
+                      GAsyncResult *result,
+                      gpointer      user_data)
 {
+	GError *error = NULL;
+	tracker_miner_execute_update_finish (TRACKER_MINER (source),
+	                                     result,
+	                                     &error);
+
 	if (error) {
 		g_critical ("Could not initialize currently active mount points: %s",
 			    error->message);
@@ -536,21 +546,26 @@ init_mount_points_cb (TrackerMiner *miner,
 }
 
 static void
-query_mount_points_cb (TrackerMiner *miner,
-		       GPtrArray    *result,
-		       const GError *error,
-		       gpointer      user_data)
+query_mount_points_cb (GObject      *source,
+                       GAsyncResult *result,
+                       gpointer      user_data)
 {
+	TrackerMiner *miner = TRACKER_MINER (source);
 	TrackerMinerFilesPrivate *priv;
 	GHashTable *volumes;
 	GHashTableIter iter;
 	gpointer key, value;
 	GString *accumulator;
 	gint i;
+	GError *error = NULL;
+	GPtrArray *query_results;
 #ifdef HAVE_HAL
 	GSList *udis, *u;
 #endif
 
+	query_results = tracker_miner_execute_sparql_finish (miner,
+	                                                     result,
+	                                                     &error);
 	if (error) {
 		g_critical ("Could not obtain the mounted volumes: %s", error->message);
 		return;
@@ -562,11 +577,11 @@ query_mount_points_cb (TrackerMiner *miner,
 	                                 (GDestroyNotify) g_free,
 	                                 NULL);
 
-	for (i = 0; i < result->len; i++) {
+	for (i = 0; i < query_results->len; i++) {
 		gchar **row;
 		gint state;
 
-		row = g_ptr_array_index (result, i);
+		row = g_ptr_array_index (query_results, i);
 		state = VOLUME_MOUNTED_IN_STORE;
 
 		if (strcmp (row[0], TRACKER_NON_REMOVABLE_MEDIA_DATASOURCE_URN) == 0) {



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