[tracker/writeback-refactor-rebase] tracker-writeback: Cleaning up the cancel code
- From: Philip Van Hoof <pvanhoof src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/writeback-refactor-rebase] tracker-writeback: Cleaning up the cancel code
- Date: Thu, 14 Jul 2011 10:03:02 +0000 (UTC)
commit c630070871c2a4c7b45a5875a0ad6cb4c983ccb2
Author: Philip Van Hoof <philip codeminded be>
Date: Thu Jul 14 12:02:36 2011 +0200
tracker-writeback: Cleaning up the cancel code
src/tracker-writeback/tracker-writeback-file.c | 6 +-
src/tracker-writeback/tracker-writeback.c | 154 ++++++++++-------------
2 files changed, 71 insertions(+), 89 deletions(-)
---
diff --git a/src/tracker-writeback/tracker-writeback-file.c b/src/tracker-writeback/tracker-writeback-file.c
index edfcc99..95f7956 100644
--- a/src/tracker-writeback/tracker-writeback-file.c
+++ b/src/tracker-writeback/tracker-writeback-file.c
@@ -156,6 +156,8 @@ tracker_writeback_file_update_metadata (TrackerWriteback *writeback,
urls[0] = row[0];
+#warning Remove this after the queues are properly integrated and this isnt needed anymore
+
tracker_miner_manager_ignore_next_update (tracker_writeback_get_miner_manager (),
"org.freedesktop.Tracker1.Miner.Files",
urls);
@@ -211,8 +213,8 @@ tracker_writeback_file_update_metadata (TrackerWriteback *writeback,
/* Move back the modified file to the original location */
g_file_move (tmp_file, file,
- G_FILE_COPY_OVERWRITE,
- NULL, NULL, NULL, NULL);
+ G_FILE_COPY_OVERWRITE,
+ NULL, NULL, NULL, NULL);
g_object_unref (tmp_file);
g_object_unref (file);
diff --git a/src/tracker-writeback/tracker-writeback.c b/src/tracker-writeback/tracker-writeback.c
index 67cb160..6da5086 100644
--- a/src/tracker-writeback/tracker-writeback.c
+++ b/src/tracker-writeback/tracker-writeback.c
@@ -69,6 +69,8 @@ typedef struct {
TrackerDBusRequest *request;
gchar *subject;
GPtrArray *results;
+ TrackerSparqlConnection *connection;
+ TrackerWriteback *writeback;
} WritebackData;
#define TRACKER_WRITEBACK_SERVICE "org.freedesktop.Tracker1.Writeback"
@@ -82,12 +84,12 @@ static const gchar *introspection_xml =
" <arg type='i' name='value' direction='out' />"
" </method>"
" <method name='PerformWriteback'>"
- " <arg type='s' name='uri' direction='in' />"
+ " <arg type='s' name='subject' direction='in' />"
" <arg type='as' name='rdf_types' direction='in' />"
" <arg type='aas' name='results' direction='in' />"
" </method>"
" <method name='CancelTasks'>"
- " <arg type='as' name='uri' direction='in' />"
+ " <arg type='as' name='subjects' direction='in' />"
" </method>"
" </interface>"
"</node>";
@@ -201,20 +203,24 @@ tracker_controller_class_init (TrackerControllerClass *klass)
}
static WritebackData *
-writeback_data_new (TrackerController *controller,
- const gchar *subject,
- GPtrArray *results,
- GDBusMethodInvocation *invocation,
- TrackerDBusRequest *request)
+writeback_data_new (TrackerController *controller,
+ TrackerWriteback *writeback,
+ TrackerSparqlConnection *connection,
+ const gchar *subject,
+ GPtrArray *results,
+ GDBusMethodInvocation *invocation,
+ TrackerDBusRequest *request)
{
WritebackData *data;
data = g_slice_new (WritebackData);
data->cancellable = g_cancellable_new ();
- data->controller = controller;
+ data->controller = g_object_ref (controller);
data->subject = g_strdup (subject);
data->results = g_ptr_array_ref (results);
data->invocation = invocation;
+ data->connection = g_object_ref (connection);
+ data->writeback = g_object_ref (writeback);
data->request = request;
return data;
@@ -227,52 +233,31 @@ writeback_data_free (WritebackData *data)
* the g_dbus_method_invocation_return_* methods
*/
g_free (data->subject);
+ g_object_unref (data->connection);
+ g_object_unref (data->writeback);
g_ptr_array_unref (data->results);
g_object_unref (data->cancellable);
g_slice_free (WritebackData, data);
}
static void
-cancel_tasks_in_file (TrackerController *controller,
- GFile *file)
+cancel_tasks_in_subject (TrackerController *controller,
+ const gchar *subject)
{
-/*
TrackerControllerPrivate *priv;
GList *elem;
priv = controller->priv;
for (elem = priv->ongoing_tasks; elem; elem = elem->next) {
- GetMetadataData *data;
- GFile *task_file;
-
- data = elem->data;
-
-#warning todo here
- // todo: the GFile holds the nie:url, not the subject, so this wont work
-
- task_file = g_file_new_for_uri (data->subject);
-
- if (g_file_equal (task_file, file) ||
- g_file_has_prefix (task_file, file)) {
- / Mount path contains one of the files being processed /
- if (!elem->next) {
- * The last element in the list is
- * the one currently being processed,
- * so exit abruptly.
- *
- g_message ("Cancelled task ('%s') is currently being processed, quitting",
- data->uri);
- _exit (0);
- } else {
- g_message ("Cancelling not yet processed task ('%s')",
- data->uri);
- g_cancellable_cancel (data->cancellable);
- }
- }
+ WritebackData *data = elem->data;
- g_object_unref (task_file);
- } */
+ if (g_strcmp0 (subject, data->subject) == 0) {
+ g_message ("Cancelling not yet processed task ('%s')",
+ data->subject);
+ g_cancellable_cancel (data->cancellable);
+ }
+ }
}
static void
@@ -284,7 +269,8 @@ mount_point_removed_cb (TrackerStorage *storage,
GFile *mount_file;
mount_file = g_file_new_for_path (mount_point);
- cancel_tasks_in_file (TRACKER_CONTROLLER (user_data), mount_file);
+ /* TODO - deal with unmount vs. writeback */
+ /* cancel_tasks_in_file (TRACKER_CONTROLLER (user_data), mount_file); */
g_object_unref (mount_file);
}
@@ -379,10 +365,8 @@ handle_method_call_get_pid (TrackerController *controller,
g_variant_new ("(i)", (gint) value));
}
-static void
-perform_writeback_cb (GObject *object,
- GAsyncResult *res,
- gpointer user_data)
+static gboolean
+perform_writeback_cb (gpointer user_data)
{
TrackerControllerPrivate *priv;
WritebackData *data;
@@ -390,28 +374,11 @@ perform_writeback_cb (GObject *object,
data = user_data;
priv = data->controller->priv;
priv->ongoing_tasks = g_list_remove (priv->ongoing_tasks, data);
-// info = g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (res));
-
-// if (info) {
- if (TRUE) {
- g_dbus_method_invocation_return_value (data->invocation, NULL);
-
- tracker_dbus_request_end (data->request, NULL);
- } else {
- GError *error = NULL;
-
-#ifdef THREAD_ENABLE_TRACE
- g_debug ("Thread:%p (Controller) --> Got error back",
- g_thread_self ());
-#endif /* THREAD_ENABLE_TRACE */
-
- g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (res), &error);
- tracker_dbus_request_end (data->request, error);
- g_dbus_method_invocation_return_gerror (data->invocation, error);
- g_error_free (error);
- }
-
+ g_dbus_method_invocation_return_value (data->invocation, NULL);
+ tracker_dbus_request_end (data->request, NULL);
writeback_data_free (data);
+
+ return FALSE;
}
static gboolean
@@ -433,13 +400,26 @@ sparql_rdf_types_match (const gchar * const *module_types,
return FALSE;
}
+static gboolean
+io_writeback_job (GIOSchedulerJob *job,
+ GCancellable *cancellable,
+ gpointer user_data)
+{
+ WritebackData *data = user_data;
+
+ tracker_writeback_update_metadata (data->writeback, data->results, data->connection);
+
+ g_idle_add (perform_writeback_cb, data);
+
+ return FALSE;
+}
+
static void
handle_method_call_perform_writeback (TrackerController *controller,
GDBusMethodInvocation *invocation,
GVariant *parameters)
{
TrackerControllerPrivate *priv;
- WritebackData *data;
TrackerDBusRequest *request;
const gchar *subject;
GPtrArray *results = NULL;
@@ -467,6 +447,9 @@ handle_method_call_perform_writeback (TrackerController *controller,
GArray *row_array = g_array_new (TRUE, TRUE, sizeof (gchar *));
gchar *cell = NULL;
+ /* TODO: If it's a file, row_array[0] is the url of the file, this can be
+ * used for the on-unmount cancelling (see also tracker-writeback-file.c:157) */
+
while (g_variant_iter_loop (iter3, "&s", &cell)) {
g_array_append_val (row_array, cell);
}
@@ -483,8 +466,6 @@ handle_method_call_perform_writeback (TrackerController *controller,
g_hash_table_iter_init (&iter, priv->modules);
- data = writeback_data_new (controller, subject, results, invocation, request);
-
while (g_hash_table_iter_next (&iter, &key, &value)) {
TrackerWritebackModule *module;
const gchar * const *module_types;
@@ -493,6 +474,7 @@ handle_method_call_perform_writeback (TrackerController *controller,
module_types = tracker_writeback_module_get_rdf_types (module);
if (sparql_rdf_types_match (module_types, (const gchar * const *) rdf_types)) {
+ WritebackData *data;
TrackerWriteback *writeback;
g_message (" Updating metadata for subject:'%s' using module:'%s'",
@@ -500,19 +482,21 @@ handle_method_call_perform_writeback (TrackerController *controller,
module->name);
writeback = tracker_writeback_module_create (module);
+ data = writeback_data_new (controller,
+ writeback,
+ priv->connection,
+ subject,
+ results,
+ invocation,
+ request);
+
+ g_io_scheduler_push_job (io_writeback_job, data, NULL, 0,
+ data->cancellable);
-#warning todo here
- // todo: make this really async using ie. g_io_scheduler_push_job
- tracker_writeback_update_metadata (writeback, results, priv->connection);
g_object_unref (writeback);
}
}
- priv->ongoing_tasks = g_list_prepend (priv->ongoing_tasks, data);
-
- // todo: make this really async
- perform_writeback_cb (NULL, NULL, data);
-
g_free (rdf_types);
}
@@ -522,7 +506,7 @@ handle_method_call_cancel_tasks (TrackerController *controller,
GVariant *parameters)
{
TrackerDBusRequest *request;
- gchar **uris;
+ gchar **subjects;
gint i;
#ifdef THREAD_ENABLE_TRACE
@@ -531,19 +515,15 @@ handle_method_call_cancel_tasks (TrackerController *controller,
#endif /* THREAD_ENABLE_TRACE */
- g_variant_get (parameters, "(^as)", &uris);
-
- request = tracker_dbus_request_begin (NULL, "%s (%s, ...)", __FUNCTION__, uris[0]);
+ g_variant_get (parameters, "(^as)", &subjects);
- for (i = 0; uris[i] != NULL; i++) {
- GFile *file;
+ request = tracker_dbus_request_begin (NULL, "%s (%s, ...)", __FUNCTION__, subjects[0]);
- file = g_file_new_for_uri (uris[i]);
- cancel_tasks_in_file (controller, file);
- g_object_unref (file);
+ for (i = 0; subjects[i] != NULL; i++) {
+ cancel_tasks_in_subject (controller, subjects[i]);
}
- g_strfreev (uris);
+ g_strfreev (subjects);
tracker_dbus_request_end (request, NULL);
g_dbus_method_invocation_return_value (invocation, NULL);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]