[tracker] libtracker-miner: add an async version of tracker_miner_manager_index_file
- From: Martyn James Russell <mr src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker] libtracker-miner: add an async version of tracker_miner_manager_index_file
- Date: Tue, 5 Mar 2013 20:42:43 +0000 (UTC)
commit 033b64f7f15b8551b0d5433baa0377bbf615aebc
Author: Cosimo Cecchi <cosimoc gnome org>
Date: Mon Mar 4 16:42:24 2013 -0500
libtracker-miner: add an async version of tracker_miner_manager_index_file
tracker_miner_manager_index_file is synchronous. This commit adds an
asynchronous and cancellable version of the same function.
https://bugzilla.gnome.org/show_bug.cgi?id=695157
--
This also bumps the GLib requirement up to 2.35.1 from 2.28.0 for GTask use.
GLib 2.35.x should be available in Ubuntu Raring and Fedora 19.
configure.ac | 2 +-
.../libtracker-miner/libtracker-miner-sections.txt | 2 +
src/libtracker-miner/tracker-miner-manager.c | 122 ++++++++++++++++----
src/libtracker-miner/tracker-miner-manager.h | 8 ++
4 files changed, 110 insertions(+), 24 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index b37983c..ba7fdee 100644
--- a/configure.ac
+++ b/configure.ac
@@ -162,7 +162,7 @@ PYTHON_REQUIRED=2.6
# Library required versions
DBUS_REQUIRED=1.3.1
-GLIB_REQUIRED=2.28.0
+GLIB_REQUIRED=2.35.1
PANGO_REQUIRED=1.0.0
GTK_REQUIRED=3.0.0
LIBXML2_REQUIRED=2.6
diff --git a/docs/reference/libtracker-miner/libtracker-miner-sections.txt
b/docs/reference/libtracker-miner/libtracker-miner-sections.txt
index 8187902..80cb5da 100644
--- a/docs/reference/libtracker-miner/libtracker-miner-sections.txt
+++ b/docs/reference/libtracker-miner/libtracker-miner-sections.txt
@@ -117,6 +117,8 @@ tracker_miner_manager_get_running
tracker_miner_manager_get_status
tracker_miner_manager_ignore_next_update
tracker_miner_manager_index_file
+tracker_miner_manager_index_file_async
+tracker_miner_manager_index_file_finish
tracker_miner_manager_is_active
tracker_miner_manager_is_paused
tracker_miner_manager_new
diff --git a/src/libtracker-miner/tracker-miner-manager.c b/src/libtracker-miner/tracker-miner-manager.c
index e22cb28..006e54f 100644
--- a/src/libtracker-miner/tracker-miner-manager.c
+++ b/src/libtracker-miner/tracker-miner-manager.c
@@ -1481,34 +1481,18 @@ tracker_miner_manager_reindex_by_mimetype (TrackerMinerManager *manager,
return FALSE;
}
-/**
- * tracker_miner_manager_index_file:
- * @manager: a #TrackerMinerManager
- * @file: a URL valid in GIO of a file to give to the miner for processing
- * @error: (out callee-allocates) (transfer full) (allow-none): return location for errors
- *
- * Tells the filesystem miner to index the @file.
- *
- * On failure @error will be set.
- *
- * Returns: %TRUE on success, otherwise %FALSE.
- *
- * Since: 0.10
- **/
-gboolean
-tracker_miner_manager_index_file (TrackerMinerManager *manager,
- GFile *file,
- GError **error)
+static gboolean
+miner_manager_index_file_sync (TrackerMinerManager *manager,
+ GFile *file,
+ GCancellable *cancellable,
+ GError **error)
{
TrackerMinerManagerPrivate *priv;
gchar *uri;
GVariant *v;
GError *new_error = NULL;
- g_return_val_if_fail (TRACKER_IS_MINER_MANAGER (manager), FALSE);
- g_return_val_if_fail (G_IS_FILE (file), FALSE);
-
- if (!g_file_query_exists (file, NULL)) {
+ if (!g_file_query_exists (file, cancellable)) {
g_set_error_literal (error,
TRACKER_MINER_MANAGER_ERROR,
TRACKER_MINER_MANAGER_ERROR_NOENT,
@@ -1538,7 +1522,7 @@ tracker_miner_manager_index_file (TrackerMinerManager *manager,
NULL,
G_DBUS_CALL_FLAGS_NONE,
-1,
- NULL,
+ cancellable,
&new_error);
g_free (uri);
@@ -1552,3 +1536,95 @@ tracker_miner_manager_index_file (TrackerMinerManager *manager,
return FALSE;
}
+
+static void
+miner_manager_index_file_thread (GTask *task,
+ gpointer source_object,
+ gpointer task_data,
+ GCancellable *cancellable)
+{
+ TrackerMinerManager *manager = source_object;
+ GFile *file = task_data;
+ GError *error = NULL;
+
+ miner_manager_index_file_sync (manager, file, cancellable, &error);
+ if (error != NULL) {
+ g_task_return_error (task, error);
+ } else {
+ g_task_return_boolean (task, TRUE);
+ }
+}
+
+/**
+ * tracker_miner_manager_index_file:
+ * @manager: a #TrackerMinerManager
+ * @file: a URL valid in GIO of a file to give to the miner for processing
+ * @error: (out callee-allocates) (transfer full) (allow-none): return location for errors
+ *
+ * Tells the filesystem miner to index the @file.
+ *
+ * On failure @error will be set.
+ *
+ * Returns: %TRUE on success, otherwise %FALSE.
+ *
+ * Since: 0.10
+ **/
+gboolean
+tracker_miner_manager_index_file (TrackerMinerManager *manager,
+ GFile *file,
+ GError **error)
+{
+ g_return_val_if_fail (TRACKER_IS_MINER_MANAGER (manager), FALSE);
+ g_return_val_if_fail (G_IS_FILE (file), FALSE);
+
+ return miner_manager_index_file_sync (manager, file, NULL, error);
+}
+
+/**
+ * tracker_miner_manager_index_file_async:
+ * @manager: a #TrackerMinerManager
+ * @file: a URL valid in GIO of a file to give to the miner for processing
+ * @cancellable: (allow-none): a #GCancellable, or %NULL
+ * @callback: (scope async): a #GAsyncReadyCallback to call when the request is satisfied
+ * @user_data: the data to pass to the callback function
+ *
+ * Tells the filesystem miner to index the @file. When the operation is called,
+ * @callback will be called. You can then call tracker_miner_manager_index_file_finish()
+ * to get the result of the operation.
+ *
+ * Since: 0.16
+ **/
+void
+tracker_miner_manager_index_file_async (TrackerMinerManager *manager,
+ GFile *file,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ GTask *task = g_task_new (manager, cancellable, callback, user_data);
+ g_task_set_task_data (task, g_object_ref (file), (GDestroyNotify) g_object_unref);
+ g_task_run_in_thread (task, miner_manager_index_file_thread);
+ g_object_unref (task);
+}
+
+/**
+ * tracker_miner_manager_index_file_finish:
+ * @manager: a #TrackerMinerManager
+ * @result: a #GAsyncResult
+ * @error: (out callee-allocates) (transfer full) (allow-none): return location for errors
+ *
+ * Finishes a request to index a file. See tracker_miner_manager_index_file_async()
+ *
+ * On failure @error will be set.
+ *
+ * Returns: %TRUE on success, otherwise %FALSE.
+ *
+ * Since: 0.16
+ **/
+gboolean
+tracker_miner_manager_index_file_finish (TrackerMinerManager *manager,
+ GAsyncResult *result,
+ GError **error)
+{
+ return g_task_propagate_boolean (G_TASK (result), error);
+}
diff --git a/src/libtracker-miner/tracker-miner-manager.h b/src/libtracker-miner/tracker-miner-manager.h
index 1e94344..69c841b 100644
--- a/src/libtracker-miner/tracker-miner-manager.h
+++ b/src/libtracker-miner/tracker-miner-manager.h
@@ -134,6 +134,14 @@ gboolean tracker_miner_manager_reindex_by_mimetype (TrackerMinerMana
gboolean tracker_miner_manager_index_file (TrackerMinerManager *manager,
GFile *file,
GError **error);
+void tracker_miner_manager_index_file_async (TrackerMinerManager *manager,
+ GFile *file,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
+gboolean tracker_miner_manager_index_file_finish (TrackerMinerManager *manager,
+ GAsyncResult *result,
+ GError **error);
#ifndef TRACKER_DISABLE_DEPRECATED
gboolean tracker_miner_manager_ignore_next_update (TrackerMinerManager *manager,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]