[tracker/tracker-0.6] Fixes: NB#109891, If deleting last music track or last video...



commit 8e310f681c6b54a6c0897fd392b57ec783234baa
Author: Martyn Russell <martyn imendio com>
Date:   Wed Apr 15 11:36:56 2009 +0100

    Fixes: NB#109891, If deleting last music track or last video...
---
 src/libtracker-common/tracker-dbus.c |   23 ++-
 src/libtracker-common/tracker-dbus.h |    2 +
 src/trackerd/tracker-daemon.c        |  398 +++++++++++++++++++++-------------
 src/trackerd/tracker-dbus.c          |  126 ++++++-----
 src/trackerd/tracker-dbus.h          |   21 +-
 5 files changed, 350 insertions(+), 220 deletions(-)

diff --git a/src/libtracker-common/tracker-dbus.c b/src/libtracker-common/tracker-dbus.c
index 0878332..4f17cf1 100644
--- a/src/libtracker-common/tracker-dbus.c
+++ b/src/libtracker-common/tracker-dbus.c
@@ -29,13 +29,18 @@ struct TrackerDBusRequestHandler {
 	gpointer	       user_data;
 };
 
-static GSList *hooks;
+static GSList   *hooks;
+static gboolean  block_hooks;
 
 static void
 request_handler_call_for_new (guint request_id)
 {
 	GSList *l;
 
+	if (block_hooks) {
+		return;
+	}
+
 	for (l = hooks; l; l = l->next) {
 		TrackerDBusRequestHandler *handler;
 
@@ -52,6 +57,10 @@ request_handler_call_for_done (guint request_id)
 {
 	GSList *l;
 
+	if (block_hooks) {
+		return;
+	}
+
 	for (l = hooks; l; l = l->next) {
 		TrackerDBusRequestHandler *handler;
 
@@ -360,3 +369,15 @@ tracker_dbus_request_debug (gint	 request_id,
 		 str);
 	g_free (str);
 }
+
+void
+tracker_dbus_request_block_hooks (void)
+{
+	block_hooks = TRUE;
+}
+
+void
+tracker_dbus_request_unblock_hooks (void)
+{
+	block_hooks = FALSE;
+}
diff --git a/src/libtracker-common/tracker-dbus.h b/src/libtracker-common/tracker-dbus.h
index 9bed4f4..8f44f30 100644
--- a/src/libtracker-common/tracker-dbus.h
+++ b/src/libtracker-common/tracker-dbus.h
@@ -121,6 +121,8 @@ void		 tracker_dbus_request_comment	     (gint			  request_id,
 void		 tracker_dbus_request_debug	     (gint			  request_id,
 						      const gchar		 *format,
 						      ...);
+void             tracker_dbus_request_block_hooks    (void);
+void             tracker_dbus_request_unblock_hooks  (void);
 
 G_END_DECLS
 
diff --git a/src/trackerd/tracker-daemon.c b/src/trackerd/tracker-daemon.c
index e5e4bf9..2670a87 100644
--- a/src/trackerd/tracker-daemon.c
+++ b/src/trackerd/tracker-daemon.c
@@ -45,13 +45,16 @@
 
 #define TRACKER_TYPE_G_STRV_ARRAY  (dbus_g_type_get_collection ("GPtrArray", G_TYPE_STRV))
 
+/* Seconds */
+#define STATS_CACHE_LIFETIME 60
+
 typedef struct {
 	TrackerConfig	 *config;
 	TrackerProcessor *processor;
 	DBusGProxy	 *indexer_proxy;
 
-	GTimeVal          last_stats_time;
-	GHashTable       *last_stats;
+	GHashTable       *stats_cache;
+	guint             stats_cache_timeout_id;
 } TrackerDaemonPrivate;
 
 enum {
@@ -63,7 +66,9 @@ enum {
 	LAST_SIGNAL
 };
 
-static void tracker_daemon_finalize (GObject *object);
+static void     tracker_daemon_finalize (GObject       *object);
+static gboolean stats_cache_timeout     (gpointer       user_data);
+static void     stats_cache_update      (TrackerDaemon *object);
 
 static guint signals[LAST_SIGNAL] = {0};
 
@@ -142,13 +147,46 @@ tracker_daemon_class_init (TrackerDaemonClass *klass)
 }
 
 static void
+indexer_started_cb (DBusGProxy *proxy,
+		    gpointer    user_data)
+{
+	TrackerDaemonPrivate *priv;
+
+	priv = TRACKER_DAEMON_GET_PRIVATE (user_data);
+
+	/* Make sure we have the cache timeout set up */
+	if (priv->stats_cache_timeout_id != 0) {
+		return;
+	}
+
+	g_message ("Starting statistics cache timeout");
+	priv->stats_cache_timeout_id = 
+		g_timeout_add_seconds (STATS_CACHE_LIFETIME,
+				       stats_cache_timeout,
+				       user_data);
+}
+
+static void
 indexer_finished_cb (DBusGProxy *proxy,
 		     gdouble	 seconds_elapsed,
+		     guint	 items_processed,
 		     guint	 items_done,
 		     gboolean	 interrupted,
 		     gpointer	 user_data)
 {
+	TrackerDaemonPrivate *priv;
+
 	tracker_daemon_signal_statistics ();
+
+	priv = TRACKER_DAEMON_GET_PRIVATE (user_data);
+
+	if (priv->stats_cache_timeout_id == 0) {
+		return;
+	}
+
+	g_message ("Stopping statistics cache timeout");
+	g_source_remove (priv->stats_cache_timeout_id);
+	priv->stats_cache_timeout_id = 0;
 }
 
 static void
@@ -166,13 +204,21 @@ tracker_daemon_init (TrackerDaemon *object)
 {
 	TrackerDaemonPrivate *priv;
 	TrackerDBInterface   *iface;
+	TrackerDBResultSet   *result_set;
 	DBusGProxy           *proxy;
+	GHashTable           *values;
+	GHashTableIter        iter;
+	gpointer              key, value;
 
 	priv = TRACKER_DAEMON_GET_PRIVATE (object);
 
 	proxy = tracker_dbus_indexer_get_proxy ();
 	priv->indexer_proxy = g_object_ref (proxy);
 
+	dbus_g_proxy_connect_signal (proxy, "Started",
+				     G_CALLBACK (indexer_started_cb),
+				     object,
+				     NULL);
 	dbus_g_proxy_connect_signal (proxy, "Finished",
 				     G_CALLBACK (indexer_finished_cb),
 				     object,
@@ -182,12 +228,39 @@ tracker_daemon_init (TrackerDaemon *object)
 				     object,
 				     NULL);
 
-	iface = tracker_db_manager_get_db_interface_by_service (TRACKER_DB_FOR_FILE_SERVICE);
+	iface = tracker_db_manager_get_db_interface (TRACKER_DB_COMMON);
 
-	priv->last_stats = g_hash_table_new_full (g_str_hash,
-						  g_str_equal,
-						  g_free, 
-						  NULL);
+	/* Prepare cache */
+	priv->stats_cache = g_hash_table_new_full (g_str_hash,
+						   g_str_equal,
+						   g_free, 
+						   NULL);
+
+	result_set = tracker_data_manager_exec_proc (iface, "GetServices", 0);
+	values = tracker_dbus_query_result_to_hash_table (result_set);
+
+	if (result_set) {
+		g_object_unref (result_set);
+	}
+
+	g_hash_table_iter_init (&iter, values);
+
+	while (g_hash_table_iter_next (&iter, &key, &value)) {
+		g_hash_table_replace (priv->stats_cache, 
+				      g_strdup (key), 
+				      GINT_TO_POINTER (0));
+	}
+
+	g_hash_table_destroy (values);
+
+	/* First time update */
+	stats_cache_update (object);
+
+	/* Future updates */
+	priv->stats_cache_timeout_id = 
+		g_timeout_add_seconds (STATS_CACHE_LIFETIME,
+				       stats_cache_timeout,
+				       object);
 }
 
 static void
@@ -199,12 +272,22 @@ tracker_daemon_finalize (GObject *object)
 	daemon = TRACKER_DAEMON (object);
 	priv = TRACKER_DAEMON_GET_PRIVATE (daemon);
 
+	if (priv->stats_cache_timeout_id != 0) {
+		g_source_remove (priv->stats_cache_timeout_id);
+	}
+
+	dbus_g_proxy_disconnect_signal (priv->indexer_proxy, "Started",
+					G_CALLBACK (indexer_started_cb),
+					daemon);
 	dbus_g_proxy_disconnect_signal (priv->indexer_proxy, "Finished",
 					G_CALLBACK (indexer_finished_cb),
-					NULL);
+					daemon);
+	dbus_g_proxy_disconnect_signal (priv->indexer_proxy, "IndexingError",
+					G_CALLBACK (indexing_error_cb),
+					daemon);
 
-	if (priv->last_stats) {
-		g_hash_table_unref (priv->last_stats);
+	if (priv->stats_cache) {
+		g_hash_table_unref (priv->stats_cache);
 	}
 
 	g_object_unref (priv->indexer_proxy);
@@ -271,18 +354,22 @@ tracker_daemon_get_status (TrackerDaemon	  *object,
 			   DBusGMethodInvocation  *context,
 			   GError		 **error)
 {
-	TrackerDaemonPrivate *priv;
-	gchar		     *status;
+	guint  request_id;
+	gchar *status;
 
-	priv = TRACKER_DAEMON_GET_PRIVATE (object);
+	request_id = tracker_dbus_get_next_request_id ();
 
-	g_debug ("DBus request to get daemon status");
+	tracker_dbus_request_block_hooks ();
+	tracker_dbus_request_new (request_id,
+				  "DBus request to get daemon status");
 
 	status = g_strdup (tracker_status_get_as_string ());
 
 	dbus_g_method_return (context, status);
-
 	g_free (status);
+
+	tracker_dbus_request_success (request_id);
+	tracker_dbus_request_unblock_hooks ();
 }
 
 void
@@ -303,15 +390,7 @@ tracker_daemon_get_services (TrackerDaemon	    *object,
 	tracker_dbus_request_new (request_id,
 				  "DBus request to get daemon services");
 
-	/* Here it doesn't matter which one we ask, as long as it has common.db
-	 * attached. The service ones are cached connections, so we can use
-	 * those instead of asking for an individual-file connection (like what
-	 * the original code had)
-	 */
-
-	/* iface = tracker_db_manager_get_db_interfaceX (TRACKER_DB_COMMON); */
-
-	iface = tracker_db_manager_get_db_interface_by_service (TRACKER_DB_FOR_FILE_SERVICE);
+	iface = tracker_db_manager_get_db_interface (TRACKER_DB_COMMON);
 
 	result_set = tracker_data_manager_exec_proc (iface, "GetServices", 0);
 	values = tracker_dbus_query_result_to_hash_table (result_set);
@@ -327,126 +406,150 @@ tracker_daemon_get_services (TrackerDaemon	    *object,
 	tracker_dbus_request_success (request_id);
 }
 
-void
-tracker_daemon_get_stats (TrackerDaemon		 *object,
-			  DBusGMethodInvocation  *context,
-			  GError		**error)
+
+static void
+stats_cache_update (TrackerDaemon *object)
 {
 	TrackerDaemonPrivate *priv;
-	TrackerDBInterface   *iface;
 	TrackerDBResultSet   *result_set;
-	guint		      request_id;
+	GPtrArray            *stats, *parent_stats;
 	GPtrArray            *values;
-	GTimeVal	      now;
-	gboolean              use_cache;
-
-	request_id = tracker_dbus_get_next_request_id ();
-
-	tracker_dbus_request_new (request_id,
-				  "DBus request to get daemon service stats");
+	guint                 i;
+	const gchar          *services_to_fetch[3] = { 
+		TRACKER_DB_FOR_FILE_SERVICE, 
+		TRACKER_DB_FOR_EMAIL_SERVICE, 
+		NULL 
+	};
 
 	priv = TRACKER_DAEMON_GET_PRIVATE (object);
 
 	values = g_ptr_array_new ();
 
-	/* Use the cache if we have requests stats recently. */
-	g_get_current_time (&now);
-
-	if (priv->last_stats_time.tv_sec == 0) {
-		use_cache = FALSE;
-	} else {
-		use_cache = now.tv_sec - priv->last_stats_time.tv_sec < 60;
-	}
-
-	if (use_cache) {
-		GHashTableIter iter;
-		gpointer key, value;
-
-		g_message ("Using cache for stats");
-		
-		g_hash_table_iter_init (&iter, priv->last_stats);
-		while (g_hash_table_iter_next (&iter, &key, &value)) {
-			GStrv         strv;
-			const gchar  *service_type;
-			gint          count;
-			
-			service_type = key;
-			count = GPOINTER_TO_INT (value);
+	for (i = 0; services_to_fetch[i]; i++) {
+		TrackerDBInterface *iface;
+		gint                j;
 
-			strv = g_new (gchar*, 3);
-			strv[0] = g_strdup (service_type);
-			strv[1] = g_strdup_printf ("%d", count);
-			strv[2] = NULL;
+		iface = tracker_db_manager_get_db_interface_by_service (services_to_fetch[i]);
 
-			g_ptr_array_add (values, strv);
-		}
-	} else {
-		GPtrArray *stats, *parent_stats;
-		gint i;
-
-		g_message ("Using database for stats (cache is %ld seconds old)",
-			   now.tv_sec - priv->last_stats_time.tv_sec);
-
-		/* Here it doesn't matter which one we ask, as long as
-		 * it has common.db attached. The service ones are
-		 * cached connections, so we can use those instead of
-		 * asking for an individual-file connection (like what
-		 * the original code had).
-		 */
-		iface = tracker_db_manager_get_db_interface_by_service (TRACKER_DB_FOR_FILE_SERVICE);
-		
 		result_set = tracker_data_manager_exec_proc (iface, "GetStats", 0);
 		stats = tracker_dbus_query_result_to_ptr_array (result_set);
-		
+
 		if (result_set) {
 			g_object_unref (result_set);
 		}
-		
+
 		result_set = tracker_data_manager_exec_proc (iface, "GetStatsForParents", 0);
 		parent_stats = tracker_dbus_query_result_to_ptr_array (result_set);
-		
+
 		if (result_set) {
 			g_object_unref (result_set);
 		}
 
 		/* Concatenate stats */
-		for (i = 0; i < stats->len; i++) {
-			g_ptr_array_add (values, g_ptr_array_index (stats, i));
+		for (j = 0; j < stats->len; j++) {
+			g_ptr_array_add (values, g_ptr_array_index (stats, j));
 		}
 		
-		for (i = 0; i < parent_stats->len; i++) {
-			g_ptr_array_add (values, g_ptr_array_index (parent_stats, i));
+		for (j = 0; j < parent_stats->len; j++) {
+			g_ptr_array_add (values, g_ptr_array_index (parent_stats, j));
 		}
 
-		/* Update local cache */
-		for (i = 0; i < values->len; i++) {
-			gchar       **p;
-			const gchar  *service_type = NULL;
-			gint          new_count;
+		g_ptr_array_free (parent_stats, TRUE);
+		g_ptr_array_free (stats, TRUE);
+	}
 
-			p = g_ptr_array_index (values, i);
-			service_type = p[0];
-			new_count = atoi (p[1]);
+	/* Update local cache */
+	for (i = 0; i < values->len; i++) {
+		gchar       **p;
+		const gchar  *service_type = NULL;
+		gint          new_count;
 
-			g_hash_table_replace (priv->last_stats, 
-					      g_strdup (service_type), 
-					      GINT_TO_POINTER (new_count));
-		}
+		p = g_ptr_array_index (values, i);
+		service_type = p[0];
+		new_count = atoi (p[1]);
 
-		g_ptr_array_free (parent_stats, TRUE);
-		g_ptr_array_free (stats, TRUE);
+		g_hash_table_replace (priv->stats_cache, 
+				      g_strdup (service_type), 
+				      GINT_TO_POINTER (new_count));
+	}
+
+	g_ptr_array_foreach (values, (GFunc) g_strfreev, NULL);
+	g_ptr_array_free (values, TRUE);
+}
+
+static gboolean 
+stats_cache_timeout (gpointer user_data)
+{
+	g_message ("Statistics cache has expired, updating...");
+
+	tracker_dbus_indexer_check_is_paused ();
+	stats_cache_update (user_data);
+
+	return TRUE;
+}
+
+static gint
+stats_cache_sort_func (gconstpointer a,
+		       gconstpointer b)
+{
+	
+	const GStrv *strv_a = (GStrv *) a;
+	const GStrv *strv_b = (GStrv *) b;
+
+	g_return_val_if_fail (strv_a != NULL, 0);
+	g_return_val_if_fail (strv_b != NULL, 0);
+
+	return g_strcmp0 (*strv_a[0], *strv_b[0]);
+}
 
-		priv->last_stats_time = now;
+void
+tracker_daemon_get_stats (TrackerDaemon		 *object,
+			  DBusGMethodInvocation  *context,
+			  GError		**error)
+{
+	TrackerDaemonPrivate *priv;
+	guint		      request_id;
+	GPtrArray            *values;
+	GHashTableIter        iter;
+	gpointer              key, value;
+
+	request_id = tracker_dbus_get_next_request_id ();
+
+	tracker_dbus_request_block_hooks ();
+	tracker_dbus_request_new (request_id,
+				  "DBus request to get daemon service stats");
+
+	priv = TRACKER_DAEMON_GET_PRIVATE (object);
+
+	values = g_ptr_array_new ();
 
-		g_message ("Updated stats cache time to now");
+	g_hash_table_iter_init (&iter, priv->stats_cache);
+	while (g_hash_table_iter_next (&iter, &key, &value)) {
+		GStrv         strv;
+		const gchar  *service_type;
+		gint          count;
+
+		service_type = key;
+		count = GPOINTER_TO_INT (value);
+
+		strv = g_new (gchar*, 3);
+		strv[0] = g_strdup (service_type);
+		strv[1] = g_strdup_printf ("%d", count);
+		strv[2] = NULL;
+
+		g_ptr_array_add (values, strv);
 	}
 
+	/* Sort result so it is alphabetical */
+	g_ptr_array_sort (values, stats_cache_sort_func);
+
 	dbus_g_method_return (context, values);
 
 	g_ptr_array_foreach (values, (GFunc) g_strfreev, NULL);
 	g_ptr_array_free (values, TRUE);
 
 	tracker_dbus_request_success (request_id);
+	tracker_dbus_request_unblock_hooks ();
 }
 
 void
@@ -672,51 +775,58 @@ tracker_daemon_signal_statistics (void)
 {
 	GObject		     *daemon;
 	TrackerDaemonPrivate *priv;
-	TrackerDBInterface   *iface;
 	TrackerDBResultSet   *result_set;
 	GPtrArray	     *stats, *parent_stats;
 	GPtrArray            *values;
-	GTimeVal              now;
 	gint                  i;
+	const gchar          *services_to_fetch[3] = {
+		TRACKER_DB_FOR_FILE_SERVICE, 
+		TRACKER_DB_FOR_EMAIL_SERVICE, 
+		NULL
+	};
 
 	daemon = tracker_dbus_get_object (TRACKER_TYPE_DAEMON);
 	priv = TRACKER_DAEMON_GET_PRIVATE (daemon);
 
-	iface = tracker_db_manager_get_db_interface_by_service (TRACKER_DB_FOR_FILE_SERVICE);
+	values = g_ptr_array_new ();
 
-	/* GetStats has asc in its query. Therefore we don't have to
-	 * lookup the in a to compare in b, just compare index based.
-	 * Maybe we want to change this nonetheless later?
-	 */
-	g_message ("Using database for stats for accurate signal");
+	g_message ("Requesting statistics from database for an accurate signal");
 
-	result_set = tracker_data_manager_exec_proc (iface, "GetStats", 0);
-	stats = tracker_dbus_query_result_to_ptr_array (result_set);
+	for (i = 0; services_to_fetch[i]; i++) {		
+		TrackerDBInterface *iface;
+		gint                j;
 
-	if (result_set) {
-		g_object_unref (result_set);
-	}
+		iface = tracker_db_manager_get_db_interface_by_service (services_to_fetch[i]);
 
-	result_set = tracker_data_manager_exec_proc (iface, "GetStatsForParents", 0);
-	parent_stats = tracker_dbus_query_result_to_ptr_array (result_set);
+		/* GetStats has asc in its query. Therefore we don't have to
+		 * lookup the in a to compare in b, just compare index based.
+		 * Maybe we want to change this nonetheless later?
+		 */
+		result_set = tracker_data_manager_exec_proc (iface, "GetStats", 0);
+		stats = tracker_dbus_query_result_to_ptr_array (result_set);
 
-	if (result_set) {
-		g_object_unref (result_set);
-	}
-	
-	/* Concatenate stats */
-	values = g_ptr_array_new ();
-	
-	for (i = 0; i < stats->len; i++) {
-		g_ptr_array_add (values, g_ptr_array_index (stats, i));
-	}
+		if (result_set) {
+			g_object_unref (result_set);
+		}
 
-	for (i = 0; i < parent_stats->len; i++) {
-		g_ptr_array_add (values, g_ptr_array_index (parent_stats, i));
-	}
+		result_set = tracker_data_manager_exec_proc (iface, "GetStatsForParents", 0);
+		parent_stats = tracker_dbus_query_result_to_ptr_array (result_set);
+
+		if (result_set) {
+			g_object_unref (result_set);
+		}
+		
+		for (j = 0; j < stats->len; j++) {
+			g_ptr_array_add (values, g_ptr_array_index (stats, j));
+		}
+
+		for (j = 0; j < parent_stats->len; j++) {
+			g_ptr_array_add (values, g_ptr_array_index (parent_stats, j));
+		}
 
-	g_ptr_array_free (parent_stats, TRUE);
-	g_ptr_array_free (stats, TRUE);
+		g_ptr_array_free (parent_stats, TRUE);
+		g_ptr_array_free (stats, TRUE);
+	}
 
 	/* There are 3 situations here:
 	 *  - 1. No new stats
@@ -735,9 +845,7 @@ tracker_daemon_signal_statistics (void)
 		return;
 	}
 
-	if (g_hash_table_size (priv->last_stats) < 1) {
-		gint i;
-
+	if (g_hash_table_size (priv->stats_cache) < 1) {
 		/* Situation #2 */
 		g_message ("  No previous statistics");
 
@@ -758,7 +866,7 @@ tracker_daemon_signal_statistics (void)
 			g_message ("  Adding '%s' with count:%d", 
 				   service_type,
 				   new_count);
-			g_hash_table_insert (priv->last_stats, 
+			g_hash_table_insert (priv->stats_cache, 
 					     g_strdup (service_type), 
 					     GINT_TO_POINTER (new_count));
 		}
@@ -766,8 +874,6 @@ tracker_daemon_signal_statistics (void)
 		/* Emit signal */
 		g_signal_emit (daemon, signals[SERVICE_STATISTICS_UPDATED], 0, values);
 	} else {
-		gint i;
-
 		/* Situation #3 */
 		for (i = 0; i < values->len; i++) {
 			gchar       **p;
@@ -783,7 +889,7 @@ tracker_daemon_signal_statistics (void)
 				continue;
 			}
 
-			data = g_hash_table_lookup (priv->last_stats, service_type);
+			data = g_hash_table_lookup (priv->stats_cache, service_type);
 			old_count = GPOINTER_TO_INT (data);
 
 			if (old_count != new_count) {
@@ -793,7 +899,7 @@ tracker_daemon_signal_statistics (void)
 					   old_count,
 					   new_count - old_count);
 
-				g_hash_table_replace (priv->last_stats, 
+				g_hash_table_replace (priv->stats_cache, 
 						      g_strdup (service_type), 
 						      GINT_TO_POINTER (new_count));
 			} else {
@@ -816,12 +922,6 @@ tracker_daemon_signal_statistics (void)
 		}
 	}
 
-	/* Update time for last stats */
-	g_get_current_time (&now);
-	priv->last_stats_time = now;
-
-	g_message ("Updated stats cache time to now");
-
 	g_ptr_array_foreach (values, (GFunc) g_strfreev, NULL);
 	g_ptr_array_free (values, TRUE);
 }
diff --git a/src/trackerd/tracker-dbus.c b/src/trackerd/tracker-dbus.c
index 0aa7109..43f640c 100644
--- a/src/trackerd/tracker-dbus.c
+++ b/src/trackerd/tracker-dbus.c
@@ -49,8 +49,6 @@
 #include "tracker-status.h"
 #include "tracker-main.h"
 
-#define INDEXER_PAUSE_TIME_FOR_REQUESTS 5 /* seconds */
-
 #define TRACKER_INDEXER_SERVICE   "org.freedesktop.Tracker.Indexer"
 #define TRACKER_INDEXER_PATH      "/org/freedesktop/Tracker/Indexer"
 #define TRACKER_INDEXER_INTERFACE "org.freedesktop.Tracker.Indexer"
@@ -211,65 +209,7 @@ static void
 dbus_request_new_cb (guint    request_id,
 		     gpointer user_data)
 {
-	DBusGProxy    *proxy;
-	gboolean       set_paused = TRUE;
-	TrackerStatus  status;
-
-	status = tracker_status_get ();
-	proxy = tracker_dbus_indexer_get_proxy ();
-
-	/* Don't pause if already paused */
-	if (status == TRACKER_STATUS_PAUSED) {
-		g_message ("New DBus request, not pausing indexer, already in paused state");
-
-		/* Just check if we already have a timeout, to reset it */
-		if (indexer_resume_timeout_id != 0) {
-			g_source_remove (indexer_resume_timeout_id);
-			indexer_resume_timeout_id =
-				g_timeout_add_seconds_full (G_PRIORITY_DEFAULT,
-							    INDEXER_PAUSE_TIME_FOR_REQUESTS,
-							    indexer_resume_cb,
-							    g_object_ref (proxy),
-							    indexer_resume_destroy_notify_cb);
-		}
-
-		return;
-	}
-
-	if (!indexer_available) {
-		g_message ("New DBus request, not pausing indexer, since it's not there");
-		return;
-	}
-
-	/* First remove the timeout */
-	if (indexer_resume_timeout_id != 0) {
-		set_paused = FALSE;
-
-		g_source_remove (indexer_resume_timeout_id);
-	}
-
-	/* Second reset it so we have another 10 seconds before
-	 * continuing.
-	 */
-	indexer_resume_timeout_id =
-		g_timeout_add_seconds_full (G_PRIORITY_DEFAULT,
-					    INDEXER_PAUSE_TIME_FOR_REQUESTS,
-					    indexer_resume_cb,
-					    g_object_ref (proxy),
-					    indexer_resume_destroy_notify_cb);
-
-	/* We really only do this because of the chance that we tell
-	 * the indexer to pause but don't get notified until the next
-	 * request. When we are notified of being paused,
-	 * tracker_get_is_paused_manually() returns TRUE.
-	 */
-	if (!set_paused) {
-		g_message ("New DBus request, not pausing indexer, already requested a pause");
-		return;
-	}
-
-	g_message ("New DBus request, pausing indexer");
-	tracker_status_set_is_paused_for_dbus (TRUE);
+	tracker_dbus_indexer_check_is_paused ();
 }
 
 gboolean
@@ -441,6 +381,70 @@ tracker_dbus_get_object (GType type)
 	return NULL;
 }
 
+void
+tracker_dbus_indexer_check_is_paused (void)
+{
+	DBusGProxy    *proxy;
+	gboolean       set_paused = TRUE;
+	TrackerStatus  status;
+
+	status = tracker_status_get ();
+	proxy = tracker_dbus_indexer_get_proxy ();
+
+	/* Don't pause if already paused */
+	if (status == TRACKER_STATUS_PAUSED) {
+		g_message ("New DBus request, not pausing indexer, already in paused state");
+
+		/* Just check if we already have a timeout, to reset it */
+		if (indexer_resume_timeout_id != 0) {
+			g_source_remove (indexer_resume_timeout_id);
+			indexer_resume_timeout_id =
+				g_timeout_add_seconds_full (G_PRIORITY_DEFAULT,
+							    TRACKER_INDEXER_PAUSE_TIME_FOR_REQUESTS,
+							    indexer_resume_cb,
+							    g_object_ref (proxy),
+							    indexer_resume_destroy_notify_cb);
+		}
+
+		return;
+	}
+
+	if (!indexer_available) {
+		g_message ("New DBus request, not pausing indexer, since it's not there");
+		return;
+	}
+
+	/* First remove the timeout */
+	if (indexer_resume_timeout_id != 0) {
+		set_paused = FALSE;
+
+		g_source_remove (indexer_resume_timeout_id);
+	}
+
+	/* Second reset it so we have another 10 seconds before
+	 * continuing.
+	 */
+	indexer_resume_timeout_id =
+		g_timeout_add_seconds_full (G_PRIORITY_DEFAULT,
+					    TRACKER_INDEXER_PAUSE_TIME_FOR_REQUESTS,
+					    indexer_resume_cb,
+					    g_object_ref (proxy),
+					    indexer_resume_destroy_notify_cb);
+
+	/* We really only do this because of the chance that we tell
+	 * the indexer to pause but don't get notified until the next
+	 * request. When we are notified of being paused,
+	 * tracker_get_is_paused_manually() returns TRUE.
+	 */
+	if (!set_paused) {
+		g_message ("New DBus request, not pausing indexer, already requested a pause");
+		return;
+	}
+
+	g_message ("New DBus request, pausing indexer");
+	tracker_status_set_is_paused_for_dbus (TRUE);
+}
+
 DBusGProxy *
 tracker_dbus_indexer_get_proxy (void)
 {
diff --git a/src/trackerd/tracker-dbus.h b/src/trackerd/tracker-dbus.h
index aeb4c91..45ee45e 100644
--- a/src/trackerd/tracker-dbus.h
+++ b/src/trackerd/tracker-dbus.h
@@ -35,15 +35,18 @@
 
 G_BEGIN_DECLS
 
-gboolean    tracker_dbus_init		   (TrackerConfig    *config);
-void	    tracker_dbus_shutdown	   (void);
-gboolean    tracker_dbus_register_objects  (TrackerConfig    *config,
-					    TrackerLanguage  *language,
-					    TrackerDBIndex   *file_index,
-					    TrackerDBIndex   *email_index,
-					    TrackerProcessor *processor);
-GObject    *tracker_dbus_get_object	   (GType	      type);
-DBusGProxy *tracker_dbus_indexer_get_proxy (void);
+#define TRACKER_INDEXER_PAUSE_TIME_FOR_REQUESTS 5 /* seconds */
+
+gboolean    tracker_dbus_init                    (TrackerConfig    *config);
+void        tracker_dbus_shutdown                (void);
+gboolean    tracker_dbus_register_objects        (TrackerConfig    *config,
+						  TrackerLanguage  *language,
+						  TrackerDBIndex   *file_index,
+						  TrackerDBIndex   *email_index,
+						  TrackerProcessor *processor);
+GObject    *tracker_dbus_get_object              (GType             type);
+void        tracker_dbus_indexer_check_is_paused (void);
+DBusGProxy *tracker_dbus_indexer_get_proxy       (void);
 
 G_END_DECLS
 



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