[tracker/busy-notifications-for-master: 3/4] tracker-store: Starting and stopping the DBus service during backup restore



commit a87bb17dfa258986f8a5d6773c706c6ff062e38e
Author: Philip Van Hoof <philip codeminded be>
Date:   Mon Mar 29 15:38:18 2010 +0200

    tracker-store: Starting and stopping the DBus service during backup restore

 src/libtracker-data/tracker-data-backup.c   |    7 ++-
 src/libtracker-data/tracker-data-backup.h   |    6 ++-
 src/libtracker-data/tracker-data-update.c   |  105 +++++++++++++++++++++++++++
 src/libtracker-data/tracker-data-update.h   |   24 ++++--
 src/tracker-store/tracker-backup.c          |   17 ++++-
 src/tracker-store/tracker-dbus.c            |   97 +++++++++++++++++--------
 src/tracker-store/tracker-dbus.h            |    1 +
 src/tracker-store/tracker-resources.c       |   31 +++++---
 src/tracker-store/tracker-resources.h       |    2 +
 tests/libtracker-data/tracker-backup-test.c |    2 +-
 10 files changed, 236 insertions(+), 56 deletions(-)
---
diff --git a/src/libtracker-data/tracker-data-backup.c b/src/libtracker-data/tracker-data-backup.c
index bbec7dd..0eb72c1 100644
--- a/src/libtracker-data/tracker-data-backup.c
+++ b/src/libtracker-data/tracker-data-backup.c
@@ -127,7 +127,9 @@ tracker_data_backup_restore (GFile *journal,
                              TrackerDataBackupFinished callback,
                              gpointer user_data,
                              GDestroyNotify destroy,
-                             const gchar **test_schemas)
+                             const gchar **test_schemas,
+                             TrackerBusyCallback busy_callback,
+                             gpointer busy_user_data)
 {
 	BackupSaveInfo *info;
 
@@ -165,7 +167,8 @@ tracker_data_backup_restore (GFile *journal,
 		tracker_db_journal_shutdown ();
 
 		tracker_data_manager_init (flags, test_schemas, &is_first, TRUE,
-		                           NULL, NULL, "Restoring backup");
+		                           busy_callback, busy_user_data,
+		                           "Restoring backup");
 
 	} else {
 		g_set_error (&info->error, TRACKER_DATA_BACKUP_ERROR, 0, 
diff --git a/src/libtracker-data/tracker-data-backup.h b/src/libtracker-data/tracker-data-backup.h
index b64dc64..5442feb 100644
--- a/src/libtracker-data/tracker-data-backup.h
+++ b/src/libtracker-data/tracker-data-backup.h
@@ -24,6 +24,8 @@
 #include <glib.h>
 #include <gio/gio.h>
 
+#include <libtracker-data/tracker-data-update.h>
+
 G_BEGIN_DECLS
 
 #if !defined (__LIBTRACKER_DATA_INSIDE__) && !defined (TRACKER_COMPILATION)
@@ -44,7 +46,9 @@ void   tracker_data_backup_restore     (GFile                     *journal,
                                         TrackerDataBackupFinished  callback,
                                         gpointer                   user_data,
                                         GDestroyNotify             destroy,
-                                        const gchar              **test_schema);
+                                        const gchar              **test_schema,
+                                        TrackerBusyCallback        busy_callback,
+                                        gpointer                   busy_user_data);
 
 G_END_DECLS
 
diff --git a/src/libtracker-data/tracker-data-update.c b/src/libtracker-data/tracker-data-update.c
index f17b4a8..32d449c 100644
--- a/src/libtracker-data/tracker-data-update.c
+++ b/src/libtracker-data/tracker-data-update.c
@@ -171,6 +171,32 @@ tracker_data_add_commit_statement_callback (TrackerCommitCallback    callback,
 }
 
 void
+tracker_data_remove_commit_statement_callback (TrackerCommitCallback callback,
+                                               gpointer              user_data)
+{
+	TrackerCommitDelegate *delegate;
+	guint i;
+	gboolean found = FALSE;
+
+	if (!commit_callbacks) {
+		return;
+	}
+
+	for (i = 0; i < commit_callbacks->len; i++) {
+		delegate = g_ptr_array_index (commit_callbacks, i);
+		if (delegate->callback == callback && delegate->user_data == user_data) {
+			found = TRUE;
+			break;
+		}
+	}
+
+	if (found) {
+		g_free (delegate);
+		g_ptr_array_remove_index (commit_callbacks, i);
+	}
+}
+
+void
 tracker_data_add_rollback_statement_callback (TrackerCommitCallback    callback,
                                               gpointer                 user_data)
 {
@@ -186,6 +212,33 @@ tracker_data_add_rollback_statement_callback (TrackerCommitCallback    callback,
 	g_ptr_array_add (rollback_callbacks, delegate);
 }
 
+
+void
+tracker_data_remove_rollback_statement_callback (TrackerCommitCallback callback,
+                                                 gpointer              user_data)
+{
+	TrackerCommitDelegate *delegate;
+	guint i;
+	gboolean found = FALSE;
+
+	if (!rollback_callbacks) {
+		return;
+	}
+
+	for (i = 0; i < rollback_callbacks->len; i++) {
+		delegate = g_ptr_array_index (rollback_callbacks, i);
+		if (delegate->callback == callback && delegate->user_data == user_data) {
+			found = TRUE;
+			break;
+		}
+	}
+
+	if (found) {
+		g_free (delegate);
+		g_ptr_array_remove_index (rollback_callbacks, i);
+	}
+}
+
 void
 tracker_data_add_insert_statement_callback (TrackerStatementCallback callback,
                                             gpointer                 user_data)
@@ -203,6 +256,32 @@ tracker_data_add_insert_statement_callback (TrackerStatementCallback callback,
 }
 
 void
+tracker_data_remove_insert_statement_callback (TrackerStatementCallback callback,
+                                               gpointer                 user_data)
+{
+	TrackerStatementDelegate *delegate;
+	guint i;
+	gboolean found = FALSE;
+
+	if (!insert_callbacks) {
+		return;
+	}
+
+	for (i = 0; i < insert_callbacks->len; i++) {
+		delegate = g_ptr_array_index (insert_callbacks, i);
+		if (delegate->callback == callback && delegate->user_data == user_data) {
+			found = TRUE;
+			break;
+		}
+	}
+
+	if (found) {
+		g_free (delegate);
+		g_ptr_array_remove_index (insert_callbacks, i);
+	}
+}
+
+void
 tracker_data_add_delete_statement_callback (TrackerStatementCallback callback,
                                             gpointer                 user_data)
 {
@@ -218,6 +297,32 @@ tracker_data_add_delete_statement_callback (TrackerStatementCallback callback,
 	g_ptr_array_add (delete_callbacks, delegate);
 }
 
+void
+tracker_data_remove_delete_statement_callback (TrackerStatementCallback callback,
+                                               gpointer                 user_data)
+{
+	TrackerStatementDelegate *delegate;
+	guint i;
+	gboolean found = FALSE;
+
+	if (!delete_callbacks) {
+		return;
+	}
+
+	for (i = 0; i < delete_callbacks->len; i++) {
+		delegate = g_ptr_array_index (delete_callbacks, i);
+		if (delegate->callback == callback && delegate->user_data == user_data) {
+			found = TRUE;
+			break;
+		}
+	}
+
+	if (found) {
+		g_free (delegate);
+		g_ptr_array_remove_index (delete_callbacks, i);
+	}
+}
+
 GQuark tracker_data_error_quark (void) {
 	return g_quark_from_static_string ("tracker_data_error-quark");
 }
diff --git a/src/libtracker-data/tracker-data-update.h b/src/libtracker-data/tracker-data-update.h
index ecdf6dd..b1f9c62 100644
--- a/src/libtracker-data/tracker-data-update.h
+++ b/src/libtracker-data/tracker-data-update.h
@@ -103,14 +103,22 @@ void     tracker_data_replay_journal                (GHashTable                *
                                                      const gchar               *busy_status);
 
 /* Calling back */
-void     tracker_data_add_insert_statement_callback   (TrackerStatementCallback   callback,
-                                                       gpointer                   user_data);
-void     tracker_data_add_delete_statement_callback   (TrackerStatementCallback   callback,
-                                                       gpointer                   user_data);
-void     tracker_data_add_commit_statement_callback   (TrackerCommitCallback      callback,
-                                                       gpointer                   user_data);
-void     tracker_data_add_rollback_statement_callback (TrackerCommitCallback      callback,
-                                                       gpointer                   user_data);
+void     tracker_data_add_insert_statement_callback      (TrackerStatementCallback   callback,
+                                                          gpointer                   user_data);
+void     tracker_data_add_delete_statement_callback      (TrackerStatementCallback   callback,
+                                                          gpointer                   user_data);
+void     tracker_data_add_commit_statement_callback      (TrackerCommitCallback      callback,
+                                                          gpointer                   user_data);
+void     tracker_data_add_rollback_statement_callback    (TrackerCommitCallback      callback,
+                                                          gpointer                   user_data);
+void     tracker_data_remove_insert_statement_callback   (TrackerStatementCallback   callback,
+                                                          gpointer                   user_data);
+void     tracker_data_remove_delete_statement_callback   (TrackerStatementCallback   callback,
+                                                          gpointer                   user_data);
+void     tracker_data_remove_commit_statement_callback   (TrackerCommitCallback      callback,
+                                                          gpointer                   user_data);
+void     tracker_data_remove_rollback_statement_callback (TrackerCommitCallback      callback,
+                                                          gpointer                   user_data);
 
 void     tracker_data_update_shutdown                 (void);
 #define  tracker_data_update_init                     tracker_data_update_shutdown
diff --git a/src/tracker-store/tracker-backup.c b/src/tracker-store/tracker-backup.c
index c64e14e..64d56f5 100644
--- a/src/tracker-store/tracker-backup.c
+++ b/src/tracker-store/tracker-backup.c
@@ -30,6 +30,7 @@
 #include "tracker-dbus.h"
 #include "tracker-backup.h"
 #include "tracker-store.h"
+#include "tracker-resources.h"
 
 typedef struct {
 	DBusGMethodInvocation *context;
@@ -114,6 +115,9 @@ tracker_backup_restore (TrackerBackup          *object,
 	guint request_id;
 	TrackerDBusMethodInfo *info;
 	GFile *journal;
+	TrackerBusyNotifier *notifier;
+	TrackerBusyCallback busy_callback;
+	gpointer busy_user_data;
 
 	request_id = tracker_dbus_get_next_request_id ();
 
@@ -127,11 +131,22 @@ tracker_backup_restore (TrackerBackup          *object,
 	info->context = context;
 	journal = g_file_new_for_uri (journal_uri);
 
+	tracker_dbus_set_available (FALSE);
+
+	notifier = TRACKER_BUSY_NOTIFIER (tracker_dbus_get_object (TRACKER_TYPE_BUSY_NOTIFIER));
+
+	busy_callback = tracker_busy_notifier_get_callback (notifier, 
+	                                                    &busy_user_data);
+
 	tracker_data_backup_restore (journal,
 	                             backup_callback,
 	                             info, 
 	                             (GDestroyNotify) g_free,
-	                             NULL);
+	                             NULL,
+	                             busy_callback,
+	                             busy_user_data);
+
+	tracker_dbus_set_available (TRUE);
 
 	g_object_unref (journal);
 }
diff --git a/src/tracker-store/tracker-dbus.c b/src/tracker-store/tracker-dbus.c
index dfb39ab..856e132 100644
--- a/src/tracker-store/tracker-dbus.c
+++ b/src/tracker-store/tracker-dbus.c
@@ -46,6 +46,8 @@
 static DBusGConnection *connection;
 static DBusGProxy      *gproxy;
 static GSList          *objects;
+TrackerBusyNotifier    *notifier = NULL;
+TrackerBackup          *backup = NULL;
 
 static gboolean
 dbus_register_service (DBusGProxy  *proxy,
@@ -148,16 +150,26 @@ tracker_dbus_init (void)
 		return FALSE;
 	}
 
+	dbus_g_proxy_add_signal (gproxy, "NameOwnerChanged",
+	                         G_TYPE_STRING,
+	                         G_TYPE_STRING,
+	                         G_TYPE_STRING,
+	                         G_TYPE_INVALID);
+
 	return TRUE;
 }
 
 void
 tracker_dbus_shutdown (void)
 {
-	if (objects) {
-		g_slist_foreach (objects, (GFunc) g_object_unref, NULL);
-		g_slist_free (objects);
-		objects = NULL;
+	tracker_dbus_set_available (FALSE);
+
+	if (backup) {
+		g_object_unref (backup);
+	}
+
+	if (notifier) {
+		g_object_unref (notifier);
 	}
 
 	if (gproxy) {
@@ -181,6 +193,26 @@ name_owner_changed_cb (DBusGProxy *proxy,
 	}
 }
 
+void
+tracker_dbus_set_available (gboolean available)
+{
+	if (available) {
+		if (!objects) {
+			tracker_dbus_register_objects ();
+		}
+	} else {
+		if (objects) {
+			dbus_g_proxy_disconnect_signal (gproxy,
+			                                "NameOwnerChanged",
+			                                G_CALLBACK (name_owner_changed_cb),
+			                                tracker_dbus_get_object (TRACKER_TYPE_RESOURCES));
+			g_slist_foreach (objects, (GFunc) g_object_unref, NULL);
+			g_slist_free (objects);
+			objects = NULL;
+		}
+	}
+}
+
 static void
 name_owner_changed_closure (gpointer  data,
                             GClosure *closure)
@@ -190,28 +222,25 @@ name_owner_changed_closure (gpointer  data,
 TrackerBusyNotifier*
 tracker_dbus_register_busy_notifier (void)
 {
-	gpointer object;
-
 	if (!connection || !gproxy) {
 		g_critical ("D-Bus support must be initialized before registering objects!");
 		return FALSE;
 	}
 
 	/* Add org.freedesktop.Tracker */
-	object = tracker_busy_notifier_new ();
-	if (!object) {
+	notifier = tracker_busy_notifier_new ();
+	if (!notifier) {
 		g_critical ("Could not create TrackerBusyNotifier object to register");
 		return FALSE;
 	}
 
 	dbus_register_object (connection,
 	                      gproxy,
-	                      G_OBJECT (object),
+	                      G_OBJECT (notifier),
 	                      &dbus_glib_tracker_busy_notifier_object_info,
 	                      TRACKER_BUSY_NOTIFIER_PATH);
-	objects = g_slist_prepend (objects, object);
 
-	return g_object_ref (object);
+	return g_object_ref (notifier);
 }
 
 gboolean
@@ -248,12 +277,6 @@ tracker_dbus_register_objects (void)
 		return FALSE;
 	}
 
-	dbus_g_proxy_add_signal (gproxy, "NameOwnerChanged",
-	                         G_TYPE_STRING,
-	                         G_TYPE_STRING,
-	                         G_TYPE_STRING,
-	                         G_TYPE_INVALID);
-
 	dbus_g_proxy_connect_signal (gproxy, "NameOwnerChanged",
 	                             G_CALLBACK (name_owner_changed_cb),
 	                             object,
@@ -266,23 +289,27 @@ tracker_dbus_register_objects (void)
 	                      TRACKER_RESOURCES_PATH);
 	objects = g_slist_prepend (objects, object);
 
-	/* Add org.freedesktop.Tracker1.Backup */
-	object = tracker_backup_new ();
-	if (!object) {
-		g_critical ("Could not create TrackerBackup object to register");
-		return FALSE;
-	}
-
-	dbus_register_object (connection,
-	                      gproxy,
-	                      G_OBJECT (object),
-	                      &dbus_glib_tracker_backup_object_info,
-	                      TRACKER_BACKUP_PATH);
-	objects = g_slist_prepend (objects, object);
-
 	/* Reverse list since we added objects at the top each time */
 	objects = g_slist_reverse (objects);
 
+	if (backup == NULL) {
+		/* Add org.freedesktop.Tracker1.Backup */
+		backup = tracker_backup_new ();
+
+		if (!object) {
+			g_critical ("Could not create TrackerBackup object to register");
+			return FALSE;
+		}
+
+		dbus_register_object (connection,
+		                      gproxy,
+		                      G_OBJECT (backup),
+		                      &dbus_glib_tracker_backup_object_info,
+		                      TRACKER_BACKUP_PATH);
+		/* Backup object isn't part of the linked list, set_available wouldn't
+		 * work correctly from the dbus call otherwise */
+	}
+
 	result_set = tracker_data_query_sparql ("SELECT ?class WHERE { ?class tracker:notify true }", NULL);
 
 	if (!result_set) {
@@ -380,6 +407,14 @@ tracker_dbus_get_object (GType type)
 		}
 	}
 
+	if (notifier && type == TRACKER_TYPE_BUSY_NOTIFIER) {
+		return G_OBJECT (notifier);
+	}
+
+	if (backup && type == TRACKER_TYPE_BACKUP) {
+		return G_OBJECT (backup);
+	}
+
 	return NULL;
 }
 
diff --git a/src/tracker-store/tracker-dbus.h b/src/tracker-store/tracker-dbus.h
index fef8af9..633f315 100644
--- a/src/tracker-store/tracker-dbus.h
+++ b/src/tracker-store/tracker-dbus.h
@@ -34,6 +34,7 @@ void                 tracker_dbus_shutdown                (void);
 gboolean             tracker_dbus_register_objects        (void);
 GObject             *tracker_dbus_get_object              (GType type);
 TrackerBusyNotifier *tracker_dbus_register_busy_notifier  (void);
+void                 tracker_dbus_set_available           (gboolean available);
 
 G_END_DECLS
 
diff --git a/src/tracker-store/tracker-resources.c b/src/tracker-store/tracker-resources.c
index c54fac2..1b92687 100644
--- a/src/tracker-store/tracker-resources.c
+++ b/src/tracker-store/tracker-resources.c
@@ -66,6 +66,8 @@ typedef struct {
 } TrackerDBusMethodInfo;
 
 
+static void tracker_resources_finalize (GObject *object);
+
 static guint signals[LAST_SIGNAL] = { 0 };
 
 static void
@@ -81,18 +83,6 @@ free_event_sources (TrackerResourcesPrivate *priv)
 }
 
 static void
-tracker_resources_finalize (GObject      *object)
-{
-	TrackerResourcesPrivate *priv;
-
-	priv = TRACKER_RESOURCES_GET_PRIVATE (object);
-
-	free_event_sources (priv);
-
-	G_OBJECT_CLASS (tracker_resources_parent_class)->finalize (object);
-}
-
-static void
 tracker_resources_class_init (TrackerResourcesClass *klass)
 {
 	GObjectClass *object_class;
@@ -573,6 +563,23 @@ tracker_resources_prepare (TrackerResources *object,
 	priv->event_sources = event_sources;
 }
 
+static void
+tracker_resources_finalize (GObject      *object)
+{
+	TrackerResourcesPrivate *priv;
+
+	priv = TRACKER_RESOURCES_GET_PRIVATE (object);
+
+	tracker_data_remove_insert_statement_callback (on_statement_inserted, object);
+	tracker_data_remove_delete_statement_callback (on_statement_deleted, object);
+	tracker_data_remove_commit_statement_callback (on_statements_committed, object);
+	tracker_data_remove_rollback_statement_callback (on_statements_rolled_back, object);
+
+	free_event_sources (priv);
+
+	G_OBJECT_CLASS (tracker_resources_parent_class)->finalize (object);
+}
+
 void
 tracker_resources_unreg_batches (TrackerResources *object,
                                  const gchar      *old_owner)
diff --git a/src/tracker-store/tracker-resources.h b/src/tracker-store/tracker-resources.h
index 11a4ec5..0ccec61 100644
--- a/src/tracker-store/tracker-resources.h
+++ b/src/tracker-store/tracker-resources.h
@@ -54,6 +54,8 @@ GType             tracker_resources_get_type            (void);
 TrackerResources *tracker_resources_new                 (void);
 void              tracker_resources_prepare             (TrackerResources       *object,
                                                          GSList                 *event_sources);
+void              tracker_resources_unprepare           (TrackerResources       *object);
+
 void              tracker_resources_unreg_batches       (TrackerResources       *object,
                                                          const gchar            *old_owner);
 
diff --git a/tests/libtracker-data/tracker-backup-test.c b/tests/libtracker-data/tracker-backup-test.c
index d312bae..006b953 100644
--- a/tests/libtracker-data/tracker-backup-test.c
+++ b/tests/libtracker-data/tracker-backup-test.c
@@ -160,7 +160,7 @@ test_backup_and_restore (void)
 	check_content_in_db (0, 0);
 
 	test_schemas[0] = data_prefix;
-	tracker_data_backup_restore (backup_file, backup_finished_cb, NULL, NULL, (const gchar **) test_schemas);
+	tracker_data_backup_restore (backup_file, backup_finished_cb, NULL, NULL, (const gchar **) test_schemas, NULL, NULL);
 	check_content_in_db (3, 1);
 
 	g_free (test_schemas[0]);



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