[tracker] tracker-store: Use DBus correctly for asynchronousy



commit 456a5dd78989d2f1a07f0d5a0b7a8dd692173f5b
Author: Philip Van Hoof <philip codeminded be>
Date:   Mon Mar 29 18:40:29 2010 +0200

    tracker-store: Use DBus correctly for asynchronousy

 src/tracker-store/tracker-backup.c        |   52 +++++++++++++++++++----------
 src/tracker-store/tracker-busy-notifier.c |    6 ++-
 2 files changed, 38 insertions(+), 20 deletions(-)
---
diff --git a/src/tracker-store/tracker-backup.c b/src/tracker-store/tracker-backup.c
index 594910d..e25cc95 100644
--- a/src/tracker-store/tracker-backup.c
+++ b/src/tracker-store/tracker-backup.c
@@ -35,6 +35,7 @@
 typedef struct {
 	DBusGMethodInvocation *context;
 	guint request_id;
+	gchar *journal_uri;
 } TrackerDBusMethodInfo;
 
 G_DEFINE_TYPE (TrackerBackup, tracker_backup, G_TYPE_OBJECT)
@@ -106,30 +107,16 @@ tracker_backup_save (TrackerBackup          *object,
 	g_object_unref (destination);
 }
 
-void
-tracker_backup_restore (TrackerBackup          *object,
-                        const gchar            *journal_uri,
-                        DBusGMethodInvocation  *context,
-                        GError                **error)
+static gboolean
+backup_idle (gpointer user_data)
 {
-	guint request_id;
-	TrackerDBusMethodInfo *info;
+	TrackerDBusMethodInfo *info = user_data;
 	GFile *journal;
 	TrackerBusyNotifier *notifier;
 	TrackerBusyCallback busy_callback;
 	gpointer busy_user_data;
 
-	request_id = tracker_dbus_get_next_request_id ();
-
-	tracker_dbus_request_new (request_id,
-	                          context,
-	                          "D-Bus request to restore backup from '%s'",
-	                          journal_uri);
-
-	info = g_new0 (TrackerDBusMethodInfo, 1);
-	info->request_id = request_id;
-	info->context = context;
-	journal = g_file_new_for_uri (journal_uri);
+	journal = g_file_new_for_uri (info->journal_uri);
 
 	tracker_dbus_set_available (FALSE);
 
@@ -138,6 +125,8 @@ tracker_backup_restore (TrackerBackup          *object,
 	busy_callback = tracker_busy_notifier_get_callback (notifier, 
 	                                                    &busy_user_data);
 
+	g_free (info->journal_uri);
+
 	tracker_data_backup_restore (journal,
 	                             backup_callback,
 	                             info, 
@@ -149,5 +138,32 @@ tracker_backup_restore (TrackerBackup          *object,
 	tracker_dbus_set_available (TRUE);
 
 	g_object_unref (journal);
+
+	return FALSE;
+}
+
+void
+tracker_backup_restore (TrackerBackup          *object,
+                        const gchar            *journal_uri,
+                        DBusGMethodInvocation  *context,
+                        GError                **error)
+{
+	guint request_id;
+	TrackerDBusMethodInfo *info;
+
+	request_id = tracker_dbus_get_next_request_id ();
+
+	tracker_dbus_request_new (request_id,
+	                          context,
+	                          "D-Bus request to restore backup from '%s'",
+	                          journal_uri);
+
+	info = g_new0 (TrackerDBusMethodInfo, 1);
+	info->request_id = request_id;
+	info->context = context;
+	info->journal_uri = g_strdup (journal_uri);
+
+	g_idle_add (backup_idle, info);
+
 }
 
diff --git a/src/tracker-store/tracker-busy-notifier.c b/src/tracker-store/tracker-busy-notifier.c
index 4e1534d..2f8030b 100644
--- a/src/tracker-store/tracker-busy-notifier.c
+++ b/src/tracker-store/tracker-busy-notifier.c
@@ -98,7 +98,8 @@ static void
 tracker_busy_notifier_finalize (GObject *object)
 {
 	TrackerBusyNotifierPrivate *priv = TRACKER_BUSY_NOTIFIER_GET_PRIVATE (object);
-	g_source_remove (priv->timer_id);
+	if (priv->timer_id != 0)
+		g_source_remove (priv->timer_id);
 	g_free (priv->status);
 }
 
@@ -162,7 +163,8 @@ tracker_busy_notifier_callback (const gchar *status,
 		}
 	}
 
-	g_main_context_iteration (NULL, FALSE);
+	while (g_main_context_iteration (NULL, FALSE))
+		;
 }
 
 TrackerBusyCallback



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