tracker r2937 - in trunk: . data/dbus src/tracker-indexer src/tracker-utils src/trackerd



Author: mr
Date: Tue Feb 17 17:40:31 2009
New Revision: 2937
URL: http://svn.gnome.org/viewvc/tracker?rev=2937&view=rev

Log:
	* data/dbus/tracker-indexer.xml: 
	* src/tracker-indexer/tracker-indexer.c: Removed the "Reason" from
	the Paused signal since we don't have a reason any more. We are
	paused when we are told. All battery monitoring and disk space
	monitoring has been moved to the daemon status module and removed
	from the indexer so state is more centrally observed.

	* src/tracker-utils/tracker-status.c: Added a couple of command
	line options to "follow" the status of Tracker using --follow
	(instead of just returning to the command line after the initial
	query) and also to get more details using --detailed.

	* src/trackerd/tracker-dbus.c: 
	* src/trackerd/tracker-status.[ch]:  Added APIs to deal with
	pausing during DBus calls. Fixed a bunch of issues found here
	where we just weren't returning to the correct state after being
	paused due to DBus requests from apps or pausing manually from the
	user.


Modified:
   trunk/ChangeLog
   trunk/data/dbus/tracker-indexer.xml
   trunk/src/tracker-indexer/tracker-indexer.c
   trunk/src/tracker-utils/tracker-status.c
   trunk/src/trackerd/tracker-dbus.c
   trunk/src/trackerd/tracker-main.c
   trunk/src/trackerd/tracker-main.h
   trunk/src/trackerd/tracker-status.c
   trunk/src/trackerd/tracker-status.h

Modified: trunk/data/dbus/tracker-indexer.xml
==============================================================================
--- trunk/data/dbus/tracker-indexer.xml	(original)
+++ trunk/data/dbus/tracker-indexer.xml	Tue Feb 17 17:40:31 2009
@@ -88,9 +88,7 @@
       <arg type="u" name="items_remaining" />
     </signal>
     <signal name="Started" />
-    <signal name="Paused">
-      <arg type="s" name="reason" />
-    </signal>
+    <signal name="Paused" />
     <signal name="Continued" />
     <signal name="Finished">
       <arg type="d" name="elapsed_time" />

Modified: trunk/src/tracker-indexer/tracker-indexer.c
==============================================================================
--- trunk/src/tracker-indexer/tracker-indexer.c	(original)
+++ trunk/src/tracker-indexer/tracker-indexer.c	Tue Feb 17 17:40:31 2009
@@ -48,7 +48,6 @@
 
 #include <stdlib.h>
 #include <string.h>
-#include <sys/statvfs.h>
 
 #include <glib/gstdio.h>
 #include <gio/gio.h>
@@ -85,14 +84,13 @@
 /* Flush every 'x' seconds */
 #define FLUSH_FREQUENCY		    60
 
-#define LOW_DISK_CHECK_FREQUENCY    10
 #define SIGNAL_STATUS_FREQUENCY     10
 
 /* Throttle defaults */
 #define THROTTLE_DEFAULT	    0
 #define THROTTLE_DEFAULT_ON_BATTERY 5
 
-#define TRACKER_INDEXER_ERROR	   "tracker-indexer-error-domain"
+#define TRACKER_INDEXER_ERROR	    "tracker-indexer-error-domain"
 #define TRACKER_INDEXER_ERROR_CODE  0
 
 /* Properties that change in move event */
@@ -137,7 +135,6 @@
 
 	guint idle_id;
 	guint pause_for_duration_id;
-	guint disk_space_check_id;
 	guint signal_status_id;
 	guint flush_id;
 
@@ -176,9 +173,7 @@
 enum TrackerIndexerState {
 	TRACKER_INDEXER_STATE_FLUSHING	= 1 << 0,
 	TRACKER_INDEXER_STATE_PAUSED	= 1 << 1,
-	TRACKER_INDEXER_STATE_DISK_FULL = 1 << 2,
-	TRACKER_INDEXER_STATE_STOPPED	= 1 << 3,
-	TRACKER_INDEXER_STATE_LOW_BATT  = 1 << 4
+	TRACKER_INDEXER_STATE_STOPPED	= 1 << 2,
 };
 
 enum {
@@ -198,7 +193,6 @@
 };
 
 static gboolean process_func	       (gpointer	     data);
-static void	check_disk_space_start (TrackerIndexer	    *indexer);
 static void	state_set_flags        (TrackerIndexer	    *indexer,
 					TrackerIndexerState  state);
 static void	state_unset_flags      (TrackerIndexer	    *indexer,
@@ -457,8 +451,6 @@
 			g_message ("Not setting throttle, it is currently set to %d",
 				   throttle);
 		}
-
-		state_unset_flags (indexer, TRACKER_INDEXER_STATE_LOW_BATT);
 	}
 }
 
@@ -470,31 +462,6 @@
 	set_up_throttle (TRACKER_INDEXER (user_data));
 }
 
-static void
-notify_battery_percentage_cb (GObject    *object,
-			      GParamSpec *pspec,
-			      gpointer    user_data)
-{
-	TrackerIndexer *indexer;
-	gdouble percentage;
-	gboolean battery_in_use;
-
-	indexer = user_data;
-
-	percentage = tracker_hal_get_battery_percentage (TRACKER_HAL (object));
-	battery_in_use = tracker_hal_get_battery_in_use (TRACKER_HAL (object));
-
-	/* FIXME: This could be a configuration option */
-	if (battery_in_use && percentage <= 0.05) {
-		/* Running on low batteries, stop indexing for now */
-		state_set_flags (indexer, TRACKER_INDEXER_STATE_LOW_BATT);
-	} else {
-		state_unset_flags (indexer, TRACKER_INDEXER_STATE_LOW_BATT);
-	}
-
-	set_up_throttle (TRACKER_INDEXER (user_data));
-}
-
 #endif /* HAVE_HAL */
 
 static void
@@ -517,10 +484,6 @@
 		g_source_remove (priv->idle_id);
 	}
 
-	if (priv->disk_space_check_id) {
-		g_source_remove (priv->disk_space_check_id);
-	}
-
 	if (priv->signal_status_id) {
 		g_source_remove (priv->signal_status_id);
 	}
@@ -533,9 +496,6 @@
 	g_signal_handlers_disconnect_by_func (priv->hal,
 					      notify_battery_in_use_cb,
 					      TRACKER_INDEXER (object));
-	g_signal_handlers_disconnect_by_func (priv->hal,
-					      notify_battery_percentage_cb,
-					      TRACKER_INDEXER (object));
 
 	g_object_unref (priv->hal);
 #endif /* HAVE_HAL */
@@ -624,7 +584,7 @@
 			      NULL, NULL,
 			      g_cclosure_marshal_VOID__STRING,
 			      G_TYPE_NONE,
-			      1, G_TYPE_STRING);
+			      0);
 	signals[CONTINUED] =
 		g_signal_new ("continued",
 			      G_OBJECT_CLASS_TYPE (object_class),
@@ -740,83 +700,6 @@
 }
 
 static gboolean
-check_is_disk_space_low (TrackerIndexer *indexer)
-{
-	const gchar *path;
-	struct statvfs st;
-	gint limit;
-
-	limit = tracker_config_get_low_disk_space_limit (indexer->private->config);
-	path = indexer->private->db_dir;
-
-	if (limit < 1) {
-		return FALSE;
-	}
-
-	if (statvfs (path, &st) == -1) {
-		g_warning ("Could not statvfs '%s'", path);
-		return FALSE;
-	}
-
-	if (((long long) st.f_bavail * 100 / st.f_blocks) <= limit) {
-		g_message ("Disk space is low");
-		return TRUE;
-	}
-
-	return FALSE;
-}
-
-static gboolean
-check_disk_space_cb (TrackerIndexer *indexer)
-{
-	gboolean disk_space_low;
-
-	disk_space_low = check_is_disk_space_low (indexer);
-
-	if (disk_space_low) {
-		state_set_flags (indexer, TRACKER_INDEXER_STATE_DISK_FULL);
-	} else {
-		state_unset_flags (indexer, TRACKER_INDEXER_STATE_DISK_FULL);
-	}
-
-	return TRUE;
-}
-
-static void
-check_disk_space_start (TrackerIndexer *indexer)
-{
-	TrackerIndexerPrivate *priv;
-	gint low_disk_space_limit;
-
-	priv = indexer->private;
-
-	if (priv->disk_space_check_id != 0) {
-		return;
-	}
-
-	low_disk_space_limit = tracker_config_get_low_disk_space_limit (priv->config);
-
-	if (low_disk_space_limit != -1) {
-		priv->disk_space_check_id = g_timeout_add_seconds (LOW_DISK_CHECK_FREQUENCY,
-								   (GSourceFunc) check_disk_space_cb,
-								   indexer);
-	}
-}
-
-static void
-check_disk_space_stop (TrackerIndexer *indexer)
-{
-	TrackerIndexerPrivate *priv;
-
-	priv = indexer->private;
-
-	if (priv->disk_space_check_id != 0) {
-		g_source_remove (priv->disk_space_check_id);
-		priv->disk_space_check_id = 0;
-	}
-}
-
-static gboolean
 signal_status_cb (TrackerIndexer *indexer)
 {
 	signal_status (indexer, "status update");
@@ -920,9 +803,6 @@
 	g_signal_connect (priv->hal, "notify::battery-in-use",
 			  G_CALLBACK (notify_battery_in_use_cb),
 			  indexer);
-	g_signal_connect (priv->hal, "notify::battery-percentage",
-			  G_CALLBACK (notify_battery_percentage_cb),
-			  indexer);
 
 	set_up_throttle (indexer);
 #endif /* HAVE_HAL */
@@ -2543,7 +2423,6 @@
 
 			/* Signal stopped and clean up */
 			check_stopped (indexer, FALSE);
-			check_disk_space_stop (indexer);
 			
 			return FALSE;
 		}
@@ -2610,7 +2489,6 @@
 			indexer->private->idle_id = 0;
 		}
 	} else {
-		check_disk_space_start (indexer);
 		signal_status_timeout_start (indexer);
 
 		if (indexer->private->idle_id == 0) {
@@ -2632,15 +2510,9 @@
 	if (state & TRACKER_INDEXER_STATE_PAUSED) {
 		s = g_string_append (s, "PAUSED | ");
 	}
-	if (state & TRACKER_INDEXER_STATE_DISK_FULL) {
-		s = g_string_append (s, "DISK FULL | ");
-	}
 	if (state & TRACKER_INDEXER_STATE_STOPPED) {
 		s = g_string_append (s, "STOPPED | ");
 	}
-	if (state & TRACKER_INDEXER_STATE_LOW_BATT) {
-		s = g_string_append (s, "LOW BATTERY | ");
-	}
 
 	s->str[s->len - 3] = '\0';
 
@@ -2661,35 +2533,21 @@
 	 * could be relevant outside the indexer
 	 */
 	if ((! (old_state & TRACKER_INDEXER_STATE_PAUSED)) &&
-	    (! (old_state & TRACKER_INDEXER_STATE_DISK_FULL)) &&
-	    (! (old_state & TRACKER_INDEXER_STATE_LOW_BATT)) &&
-	    (state & TRACKER_INDEXER_STATE_PAUSED ||
-	     state & TRACKER_INDEXER_STATE_DISK_FULL ||
-	     state & TRACKER_INDEXER_STATE_LOW_BATT)) {
-		const gchar *reason;
+	    (state & TRACKER_INDEXER_STATE_PAUSED)) {
 		gchar *old_state_str;
 		gchar *state_str;
 
-		if (state & TRACKER_INDEXER_STATE_DISK_FULL) {
-			reason = "Disk full";
-		} else if (state & TRACKER_INDEXER_STATE_LOW_BATT) {
-			reason = "Battery low";
-		} else {
-			reason = NULL;
-		}
-
 		old_state_str = state_to_string (old_state);
 		state_str = state_to_string (indexer->private->state);
 
-		g_message ("State change from '%s' --> '%s' (reason:'%s')",
+		g_message ("State change from '%s' --> '%s'",
 			   old_state_str,
-			   state_str,
-			   reason ? reason : "None");
+			   state_str);
 
 		g_free (state_str);
 		g_free (old_state_str);
 
-		g_signal_emit (indexer, signals[PAUSED], 0, reason);
+		g_signal_emit (indexer, signals[PAUSED], 0);
 	}
 }
 
@@ -2704,12 +2562,8 @@
 	new_state = indexer->private->state;
 	state_check (indexer);
 
-	if ((old_state & TRACKER_INDEXER_STATE_PAUSED ||
-	     old_state & TRACKER_INDEXER_STATE_DISK_FULL ||
-	     old_state & TRACKER_INDEXER_STATE_LOW_BATT) &&
-	    (! (new_state & TRACKER_INDEXER_STATE_PAUSED)) &&
-	    (! (new_state & TRACKER_INDEXER_STATE_DISK_FULL)) &&
-	    (! (new_state & TRACKER_INDEXER_STATE_LOW_BATT))) {
+	if ((old_state & TRACKER_INDEXER_STATE_PAUSED) &&
+	    (! (new_state & TRACKER_INDEXER_STATE_PAUSED))) {
 		gchar *old_state_str;
 		gchar *state_str;
 

Modified: trunk/src/tracker-utils/tracker-status.c
==============================================================================
--- trunk/src/tracker-utils/tracker-status.c	(original)
+++ trunk/src/tracker-utils/tracker-status.c	Tue Feb 17 17:40:31 2009
@@ -38,6 +38,12 @@
 
 static GMainLoop *main_loop;
 static gchar     *last_state;   
+static gboolean   last_initial_index;
+static gboolean   last_in_merge;
+static gboolean   last_is_paused_manually;
+static gboolean   last_is_paused_for_bat;
+static gboolean   last_is_paused_for_io;
+static gboolean   last_is_indexing_enabled;
 
 static gboolean   follow;
 static gboolean   detailed;
@@ -59,14 +65,15 @@
 		     const gchar *state,
 		     gboolean	  initial_index,
 		     gboolean	  in_merge,
-		     gboolean	  is_manual_paused,
-		     gboolean	  is_battery_paused,
-		     gboolean	  is_io_paused,
+		     gboolean	  is_paused_manually,
+		     gboolean	  is_paused_for_bat,
+		     gboolean	  is_paused_for_io,
 		     gboolean	  is_indexing_enabled,
 		     gpointer     user_data)
 {
+	static gboolean first_change = TRUE;
 	gchar *str;
-
+	
 	str = g_strdup_printf (_( "Tracker status changed from '%s' --> '%s'"), 
 			       last_state ? last_state : _("None"), 
 			       state);
@@ -74,36 +81,63 @@
 	g_free (str);
 
 	if (detailed) {
-		g_print ("  %-*.*s: %s\n"
-			 "  %-*.*s: %s\n"
-			 "  %-*.*s: %s\n"
-			 "  %-*.*s: %s\n"
-			 "  %-*.*s: %s\n"
-			 "  %-*.*s: %s\n"
-			 "\n",
-			 DETAIL_MAX_WIDTH, DETAIL_MAX_WIDTH,
-			 _("Initial index"),
-			 initial_index ? _("yes") : _("no"),
-			 DETAIL_MAX_WIDTH, DETAIL_MAX_WIDTH,
-			 _("In merge"),
-			 in_merge ? _("yes") : _("no"),
-			 DETAIL_MAX_WIDTH, DETAIL_MAX_WIDTH,
-			 _("Is paused manually"),
-			 is_manual_paused ? _("yes") : _("no"),
-			 DETAIL_MAX_WIDTH, DETAIL_MAX_WIDTH,
-			 _("Is paused for low battery"),
-			 is_battery_paused ? _("yes") : _("no"),
-			 DETAIL_MAX_WIDTH, DETAIL_MAX_WIDTH,
-			 _("Is paused for IO"),
-			 is_io_paused ? _("yes") : _("no"),
-			 DETAIL_MAX_WIDTH, DETAIL_MAX_WIDTH,
-			 _("Is indexing enabled"),
-			 is_indexing_enabled ? _("yes") : _("no"));
+		if (first_change || last_initial_index != initial_index) {
+			g_print ("  %-*.*s: %s\n",
+				 DETAIL_MAX_WIDTH, DETAIL_MAX_WIDTH,
+				 _("Initial index"),
+				 initial_index ? _("yes") : _("no"));			
+		}
+		
+		if (first_change || last_in_merge != in_merge) {
+			g_print ("  %-*.*s: %s\n",
+				 DETAIL_MAX_WIDTH, DETAIL_MAX_WIDTH,
+				 _("In merge"),
+				 in_merge ? _("yes") : _("no"));
+		}
+
+		if (first_change || last_is_paused_manually != is_paused_manually) {
+			g_print ("  %-*.*s: %s\n",
+				 DETAIL_MAX_WIDTH, DETAIL_MAX_WIDTH,
+				 _("Is paused manually"),
+				 is_paused_manually ? _("yes") : _("no"));
+		}
+
+		if (first_change || last_is_paused_for_bat != is_paused_for_bat) {
+			g_print ("  %-*.*s: %s\n",
+				 DETAIL_MAX_WIDTH, DETAIL_MAX_WIDTH,
+				 _("Is paused for low battery"),
+				 is_paused_for_bat ? _("yes") : _("no"));
+		}
+
+		if (first_change || last_is_paused_for_io != is_paused_for_io) {
+			g_print ("  %-*.*s: %s\n",
+				 DETAIL_MAX_WIDTH, DETAIL_MAX_WIDTH,
+				 _("Is paused for IO"),
+				 is_paused_for_io ? _("yes") : _("no"));
+		}
+
+		if (first_change || last_is_indexing_enabled != is_indexing_enabled) {
+			g_print ("  %-*.*s: %s\n",
+				 DETAIL_MAX_WIDTH, DETAIL_MAX_WIDTH,
+				 _("Is indexing enabled"),
+				 is_indexing_enabled ? _("yes") : _("no"));
+		}
 	}
 
-	/* Remember last state */
+	/* Remember last details so we don't spam the same crap each
+	 * time to console, only updates.
+	 */
 	g_free (last_state);
 	last_state = g_strdup (state);
+
+	last_initial_index = initial_index;
+	last_in_merge = in_merge;
+	last_is_paused_manually = is_paused_manually;
+	last_is_paused_for_bat = is_paused_for_bat;
+	last_is_paused_for_io = is_paused_for_io;
+	last_is_indexing_enabled = is_indexing_enabled;
+	
+	first_change = FALSE;
 }
 
 /* Taken from tracker-applet */

Modified: trunk/src/trackerd/tracker-dbus.c
==============================================================================
--- trunk/src/trackerd/tracker-dbus.c	(original)
+++ trunk/src/trackerd/tracker-dbus.c	Tue Feb 17 17:40:31 2009
@@ -175,18 +175,7 @@
 static gboolean
 indexer_resume_cb (gpointer user_data)
 {
-	DBusGProxy *proxy;
-
-	proxy = user_data;
-
-	if (!tracker_status_get_is_paused_manually () &&
-	    !tracker_status_get_is_paused_for_batt () && 
-	    !tracker_status_get_is_paused_for_io () && 
-	    !tracker_status_get_is_paused_for_space ()) {
-		org_freedesktop_Tracker_Indexer_continue_async (g_object_ref (proxy),
-								indexer_continue_async_cb,
-								NULL);
-	}
+	tracker_status_set_is_paused_for_dbus (FALSE);
 
 	return FALSE;
 }
@@ -208,31 +197,42 @@
 	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;
 	}
 
 	/* Don't try to pause unless we are in particular states */
 	if (status != TRACKER_STATUS_INDEXING) {
+		g_message ("New DBus request, not pausing indexer, not in indexing state");
 		return;
 	}
 
-	g_message ("New DBus request, checking indexer is paused...");
-
 	/* First remove the timeout */
 	if (indexer_resume_timeout_id != 0) {
 		set_paused = FALSE;
 
 		g_source_remove (indexer_resume_timeout_id);
-		indexer_resume_timeout_id = 0;
 	}
 
 	/* Second reset it so we have another 10 seconds before
 	 * continuing.
 	 */
-	proxy = tracker_dbus_indexer_get_proxy ();
 	indexer_resume_timeout_id =
 		g_timeout_add_seconds_full (G_PRIORITY_DEFAULT,
 					    INDEXER_PAUSE_TIME_FOR_REQUESTS,
@@ -246,21 +246,12 @@
 	 * tracker_get_is_paused_manually() returns TRUE.
 	 */
 	if (!set_paused) {
+		g_message ("New DBus request, not pausing indexer, already requested a pause");
 		return;
 	}
 
-	/* We use the blocking call here because this function
-	 * proceeds a call which needs the database to be available.
-	 * Therefore the indexer must reply to tell us it has paused
-	 * so we can actually use the database.
-	 */
-	org_freedesktop_Tracker_Indexer_pause (proxy, &error);
-
-	if (error) {
-		g_message ("Couldn't pause the indexer, "
-			   "we may have to wait for it to finish");
-		g_error_free (error);
-	}
+	g_message ("New DBus request, pausing indexer");
+	tracker_status_set_is_paused_for_dbus (TRUE);
 }
 
 gboolean

Modified: trunk/src/trackerd/tracker-main.c
==============================================================================
--- trunk/src/trackerd/tracker-main.c	(original)
+++ trunk/src/trackerd/tracker-main.c	Tue Feb 17 17:40:31 2009
@@ -846,56 +846,6 @@
 								  hal);
 }
 
-static void
-set_up_throttle (TrackerHal    *hal,
-		 TrackerConfig *config)
-{
-	gint throttle;
-
-	/* If on a laptop battery and the throttling is default (i.e.
-	 * 0), then set the throttle to be higher so we don't kill
-	 * the laptop battery.
-	 */
-	throttle = tracker_config_get_throttle (config);
-
-	if (tracker_hal_get_battery_in_use (hal)) {
-		g_message ("We are running on battery");
-
-		if (throttle == THROTTLE_DEFAULT) {
-			tracker_config_set_throttle (config,
-						     THROTTLE_DEFAULT_ON_BATTERY);
-			g_message ("Setting throttle from %d to %d",
-				   throttle,
-				   THROTTLE_DEFAULT_ON_BATTERY);
-		} else {
-			g_message ("Not setting throttle, it is currently set to %d",
-				   throttle);
-		}
-	} else {
-		g_message ("We are not running on battery");
-
-		if (throttle == THROTTLE_DEFAULT_ON_BATTERY) {
-			tracker_config_set_throttle (config,
-						     THROTTLE_DEFAULT);
-			g_message ("Setting throttle from %d to %d",
-				   throttle,
-				   THROTTLE_DEFAULT);
-		} else {
-			g_message ("Not setting throttle, it is currently set to %d",
-				   throttle);
-		}
-	}
-}
-
-static void
-notify_battery_in_use_cb (GObject    *gobject,
-			  GParamSpec *arg1,
-			  gpointer    user_data)
-{
-	set_up_throttle (TRACKER_HAL (gobject),
-			 TRACKER_CONFIG (user_data));
-}
-
 #endif /* HAVE_HAL */
 
 static gboolean
@@ -1067,7 +1017,18 @@
 		return EXIT_FAILURE;
 	}
 
-	tracker_status_init (config);
+#ifdef HAVE_HAL
+	hal = tracker_hal_new ();
+
+	g_signal_connect (hal, "mount-point-added",
+			  G_CALLBACK (mount_point_added_cb),
+			  NULL);
+	g_signal_connect (hal, "mount-point-removed",
+			  G_CALLBACK (mount_point_removed_cb),
+			  NULL);
+#endif /* HAVE_HAL */
+
+	tracker_status_init (config, hal);
 
 	tracker_module_config_init ();
 
@@ -1097,20 +1058,6 @@
 		return EXIT_FAILURE;
 	}
 
-#ifdef HAVE_HAL
-	hal = tracker_hal_new ();
-
-	g_signal_connect (hal, "notify::battery-in-use",
-			  G_CALLBACK (notify_battery_in_use_cb),
-			  config);
-	g_signal_connect (hal, "mount-point-added",
-			  G_CALLBACK (mount_point_added_cb),
-			  NULL);
-	g_signal_connect (hal, "mount-point-removed",
-			  G_CALLBACK (mount_point_removed_cb),
-			  NULL);
-#endif /* HAVE_HAL */
-
 	/*
 	 * Check instances running
 	 */
@@ -1156,7 +1103,6 @@
 	 * we have to have already initialised the databases if we
 	 * are going to do that.
 	 */
-	set_up_throttle (hal, config);
 	set_up_mount_points (hal);
 #endif /* HAVE_HAL */
 
@@ -1261,9 +1207,6 @@
 
 #ifdef HAVE_HAL
 	g_signal_handlers_disconnect_by_func (hal,
-					      notify_battery_in_use_cb,
-					      config);
-	g_signal_handlers_disconnect_by_func (hal,
 					      mount_point_added_cb,
 					      NULL);
 	g_signal_handlers_disconnect_by_func (hal,
@@ -1298,6 +1241,16 @@
 }
 
 const gchar *
+tracker_get_data_dir (void)
+{
+	TrackerMainPrivate *private;
+
+	private = g_static_private_get (&private_key);
+
+	return private->data_dir;
+}
+
+const gchar *
 tracker_get_sys_tmp_dir (void)
 {
 	TrackerMainPrivate *private;

Modified: trunk/src/trackerd/tracker-main.h
==============================================================================
--- trunk/src/trackerd/tracker-main.h	(original)
+++ trunk/src/trackerd/tracker-main.h	Tue Feb 17 17:40:31 2009
@@ -29,6 +29,7 @@
 
 void	     tracker_shutdown		     (void);
 
+const gchar *tracker_get_data_dir	     (void);
 const gchar *tracker_get_sys_tmp_dir	     (void);
 
 void	     tracker_set_reindex_on_shutdown (gboolean value);

Modified: trunk/src/trackerd/tracker-status.c
==============================================================================
--- trunk/src/trackerd/tracker-status.c	(original)
+++ trunk/src/trackerd/tracker-status.c	Tue Feb 17 17:40:31 2009
@@ -21,18 +21,28 @@
 
 #include "config.h"
 
+#include <sys/statvfs.h>
+
 #include "tracker-status.h"
 #include "tracker-dbus.h"
 #include "tracker-daemon.h"
 #include "tracker-main.h"
 #include "tracker-indexer-client.h"
 
+#define DISK_SPACE_CHECK_FREQUENCY 10
+
+#define THROTTLE_DEFAULT	    0
+#define THROTTLE_DEFAULT_ON_BATTERY 5
+
 typedef struct {
 	TrackerStatus  status;
 	TrackerStatus  status_before_paused;
 	gpointer       type_class;
 
+	guint          disk_space_check_id;
+
 	TrackerConfig *config;
+	TrackerHal    *hal;
 
 	DBusGProxy    *indexer_proxy;
 
@@ -44,17 +54,24 @@
 	gboolean       is_paused_for_batt;
 	gboolean       is_paused_for_io;
 	gboolean       is_paused_for_space;
+	gboolean       is_paused_for_dbus;
 	gboolean       is_paused_for_unknown;
 	gboolean       in_merge;
 } TrackerStatusPrivate;
 
-static void indexer_continued_cb (DBusGProxy  *proxy,
-				  gpointer     user_data);
-static void indexer_paused_cb    (DBusGProxy  *proxy,
-				  const gchar *reason,
-				  gpointer     user_data);
-static void indexer_continue     (guint        seconds);
-static void indexer_pause        (void);
+static void indexer_continued_cb  (DBusGProxy  *proxy,
+				   gpointer     user_data);
+static void indexer_paused_cb     (DBusGProxy  *proxy,
+				   const gchar *reason,
+				   gpointer     user_data);
+static void indexer_continue      (gboolean     should_block);
+static void indexer_pause         (gboolean     should_block);
+static void battery_in_use_cb     (GObject     *gobject,
+				   GParamSpec  *arg1,
+				   gpointer     user_data);
+static void battery_percentage_cb (GObject     *object,
+				   GParamSpec  *pspec,
+				   gpointer     user_data);
 
 static GStaticPrivate private_key = G_STATIC_PRIVATE_INIT;
 
@@ -65,10 +82,23 @@
 
 	private = data;
 
-	if (private->config) {
-		g_object_unref (private->config);
+	if (private->disk_space_check_id) {
+		g_source_remove (private->disk_space_check_id);
 	}
 
+	g_object_unref (private->config);
+
+#ifdef HAVE_HAL
+	g_signal_handlers_disconnect_by_func (private->hal,
+					      battery_in_use_cb,
+					      NULL);
+	g_signal_handlers_disconnect_by_func (private->hal,
+					      battery_percentage_cb,
+					      NULL);
+
+	g_object_unref (private->hal);
+#endif
+
 	if (private->type_class) {
 		g_type_class_unref (private->type_class);
 	}
@@ -93,7 +123,9 @@
  */
 
 static void
-indexer_recheck (gboolean should_inform_indexer)
+indexer_recheck (gboolean should_inform_indexer,
+		 gboolean should_block,
+		 gboolean should_signal_small_changes)
 {
 	TrackerStatusPrivate *private;
 
@@ -104,27 +136,40 @@
 	if (private->is_paused_manually ||
 	    private->is_paused_for_batt || 
 	    private->is_paused_for_io ||
-	    private->is_paused_for_space) {
+	    private->is_paused_for_space ||
+	    private->is_paused_for_dbus ||
+	    private->is_paused_for_unknown) {
 		/* We are paused, but our status is NOT paused? */
 		if (private->status != TRACKER_STATUS_PAUSED) {
-			private->status_before_paused = private->status;
-
-			tracker_status_set (TRACKER_STATUS_PAUSED);
-
 			if (G_LIKELY (should_inform_indexer)) {
-				indexer_pause ();
+				/* We set state after confirmation*/
+				indexer_pause (should_block);
+			} else {
+				tracker_status_set_and_signal (TRACKER_STATUS_PAUSED);
 			}
+			
+			return;
 		}
 	} else {
 		/* We are not paused, but our status is paused */
 		if (private->status == TRACKER_STATUS_PAUSED) {
-			tracker_status_set (private->status_before_paused);
-
 			if (G_LIKELY (should_inform_indexer)) {
-				indexer_continue (0);
+				/* We set state after confirmation*/
+				indexer_continue (should_block);
+			} else {
+				tracker_status_set_and_signal (private->status_before_paused);
 			}
+
+			return;
 		}
 	}
+
+	/* Simply signal because in this case, state hasn't changed
+	 * but one of the reasons for being paused has changed. 
+	 */
+	if (should_signal_small_changes) {
+		tracker_status_signal ();
+	}
 }
 
 static void
@@ -132,68 +177,14 @@
 		   const gchar *reason,
 		   gpointer     user_data)
 {
-	TrackerStatusPrivate *private;
-
-	private = g_static_private_get (&private_key);
-	g_return_if_fail (private != NULL);
-
-	/* NOTE: This is when we are told by the indexer, so we don't
-	 * know without checking with the status module if we sent
-	 * this or not - we certainly should not inform the indexer
-	 * again.
-	 */
-	g_message ("The indexer has paused (Reason: %s)", 
-		   reason ? reason : "None");
-
-	if (reason) {
-		if (strcmp (reason, "Disk full") == 0) {
-			private->is_paused_for_space = TRUE;
-			indexer_recheck (FALSE);
-			tracker_status_signal ();
-		} else if (strcmp (reason, "Battery low") == 0) {
-			private->is_paused_for_batt = TRUE;
-		} else {
-			private->is_paused_for_unknown = TRUE;
-		}
-	} else {
-		private->is_paused_for_unknown = TRUE;
-	}
-
-	indexer_recheck (FALSE);
-	tracker_status_signal ();
+	g_message ("The indexer has paused");
 }
 
 static void
 indexer_continued_cb (DBusGProxy *proxy,
 		      gpointer	  user_data)
 {
-	TrackerStatusPrivate *private;
-
-	private = g_static_private_get (&private_key);
-	g_return_if_fail (private != NULL);
-
-	/* NOTE: This is when we are told by the indexer, so we don't
-	 * know without checking with the status module if we sent
-	 * this or not - we certainly should not inform the indexer
-	 * again.
-	 */
-	
 	g_message ("The indexer has continued");
-
-	/* So now the indexer has told us it has continued, we make
-	 * sure that none of the pause states are TRUE.
-	 */
-	private->is_paused_manually = FALSE;
-	private->is_paused_for_batt = FALSE;
-	private->is_paused_for_io = FALSE;
-	private->is_paused_for_space = FALSE;
-	private->is_paused_for_unknown = FALSE;
-
-	/* We signal this to listening apps, but we don't call
-	 * indexer_recheck() because we don't want to tell the indexer
-	 * what it just told us :)
-	 */
-	tracker_status_set_and_signal (private->status_before_paused);
 }
 
 static void
@@ -201,27 +192,22 @@
 		     GError     *error,
 		     gpointer    user_data)
 {
-	if (error) {
-		g_message ("Could not continue the indexer, %s",
-			   error->message);
+	TrackerStatusPrivate *private;
 
-		/* Return state to paused */
-		tracker_status_set_and_signal (TRACKER_STATUS_PAUSED);
+	private = g_static_private_get (&private_key);
+	g_return_if_fail (private != NULL);
 
-		/* FIXME: Should we set some sort of boolean here for:
-		 * [I couldn't resume because the indexer b0rked]? 
-		 * 
-		 * This is a potential deadlock, since we won't check
-		 * again until we get another dbus request or
-		 * something else sets this off. 
-		 *
-		 * -mr
-		 */
+	if (G_UNLIKELY (error)) {
+		g_message ("Could not continue the indexer, %s",
+			   error->message);
+		return;
 	}
+
+	tracker_status_set_and_signal (private->status_before_paused);
 }
 
 static void
-indexer_continue (guint seconds)
+indexer_continue (gboolean should_block)
 {
 	TrackerStatusPrivate *private;
 
@@ -231,12 +217,14 @@
 	private = g_static_private_get (&private_key);
 	g_return_if_fail (private != NULL);
 
-	if (seconds < 1) {
+	if (G_LIKELY (!should_block)) {
 		org_freedesktop_Tracker_Indexer_continue_async (private->indexer_proxy,
 								indexer_continue_cb,
 								NULL);
 	} else {
-		/* FIXME: Finish */
+		org_freedesktop_Tracker_Indexer_continue (private->indexer_proxy, 
+							  NULL);
+		tracker_status_set_and_signal (private->status_before_paused);
 	}
 }
 
@@ -245,48 +233,217 @@
 		  GError     *error,
 		  gpointer    user_data)
 {
-	if (error) {
-		TrackerStatusPrivate *private;
-		
-		private = g_static_private_get (&private_key);
-		g_return_if_fail (private != NULL);
-
+	if (G_UNLIKELY (error)) {
 		g_message ("Could not pause the indexer, %s",
 			   error->message);
+		return;
+	}
+	
+	tracker_status_set_and_signal (TRACKER_STATUS_PAUSED);
+}
 
-		/* Return state to before paused */
-		tracker_status_set_and_signal (private->status_before_paused);
+static void
+indexer_pause (gboolean should_block)
+{
+	TrackerStatusPrivate *private;
+
+	/* NOTE: We don't need private, but we do this to check we
+	 * are initialised before calling continue.
+	 */
+	private = g_static_private_get (&private_key);
+	g_return_if_fail (private != NULL);
+
+	if (G_LIKELY (!should_block)) {
+		org_freedesktop_Tracker_Indexer_pause_async (private->indexer_proxy,
+							     indexer_pause_cb,
+							     NULL);
+	} else {
+		org_freedesktop_Tracker_Indexer_pause (private->indexer_proxy, 
+						       NULL);
+		tracker_status_set_and_signal (TRACKER_STATUS_PAUSED);
+	}
+}
+
+
+static gboolean
+disk_space_check (void)
+{
+	TrackerStatusPrivate *private;
+	struct statvfs        st;
+	gint                  limit;
+
+	private = g_static_private_get (&private_key);
+	g_return_if_fail (private != NULL);
+
+	limit = tracker_config_get_low_disk_space_limit (private->config);
+
+	if (limit < 1) {
+		return FALSE;
+	}
+
+	if (statvfs (tracker_get_data_dir (), &st) == -1) {
+		g_warning ("Could not statvfs() '%s'", tracker_get_data_dir ());
+		return FALSE;
+	}
+
+	if (((long long) st.f_bavail * 100 / st.f_blocks) <= limit) {
+		g_message ("Disk space is low");
+		return TRUE;
+	}
+
+	return FALSE;
+}
+
+static gboolean
+disk_space_check_cb (gpointer user_data)
+{
+	if (disk_space_check ()) {
+		tracker_status_set_is_paused_for_space (TRUE);
+	} else {
+		tracker_status_set_is_paused_for_space (FALSE);
+	}
+
+	return TRUE;
+}
+
+static void
+disk_space_check_start (void)
+{
+	TrackerStatusPrivate *private;
+	gint limit;
+
+	private = g_static_private_get (&private_key);
+	g_return_if_fail (private != NULL);
+
+	if (private->disk_space_check_id != 0) {
+		return;
+	}
+
+	limit = tracker_config_get_low_disk_space_limit (private->config);
+
+	if (limit != -1) {
+		g_message ("Setting disk space check for every %d seconds",
+			   DISK_SPACE_CHECK_FREQUENCY);
+		private->disk_space_check_id = 
+			g_timeout_add_seconds (DISK_SPACE_CHECK_FREQUENCY,
+					       disk_space_check_cb,
+					       NULL);
 
-		/* FIXME: Should we set some sort of boolean here for:
-		 * [I couldn't resume because the indexer b0rked]? 
-		 * 
-		 * This is a potential deadlock, since we won't check
-		 * again until we get another dbus request or
-		 * something else sets this off. 
-		 *
-		 * -mr
+		/* Call the function now too to make sure we have an
+		 * initial value too!
 		 */
+		disk_space_check_cb (NULL);
+	} else {
+		g_message ("Not setting disk space, configuration is set to -1 (disabled)");
 	}
 }
 
 static void
-indexer_pause (void)
+disk_space_check_stop (void)
 {
 	TrackerStatusPrivate *private;
 
-	/* NOTE: We don't need private, but we do this to check we
-	 * are initialised before calling continue.
+	private = g_static_private_get (&private_key);
+	g_return_if_fail (private != NULL);
+
+	if (private->disk_space_check_id != 0) {
+		g_source_remove (private->disk_space_check_id);
+		private->disk_space_check_id = 0;
+	}
+}
+
+#ifdef HAVE_HAL
+
+static void
+set_up_throttle (void)
+{
+	TrackerStatusPrivate *private;
+	gint                  throttle;
+
+	private = g_static_private_get (&private_key);
+	g_return_if_fail (private != NULL);
+
+	/* If on a laptop battery and the throttling is default (i.e.
+	 * 0), then set the throttle to be higher so we don't kill
+	 * the laptop battery.
 	 */
+	throttle = tracker_config_get_throttle (private->config);
+
+	if (tracker_hal_get_battery_in_use (private->hal)) {
+		g_message ("We are running on battery");
+
+		if (throttle == THROTTLE_DEFAULT) {
+			tracker_config_set_throttle (private->config,
+						     THROTTLE_DEFAULT_ON_BATTERY);
+			g_message ("Setting throttle from %d to %d",
+				   throttle,
+				   THROTTLE_DEFAULT_ON_BATTERY);
+		} else {
+			g_message ("Not setting throttle, it is currently set to %d",
+				   throttle);
+		}
+	} else {
+		g_message ("We are not running on battery");
+
+		if (throttle == THROTTLE_DEFAULT_ON_BATTERY) {
+			tracker_config_set_throttle (private->config,
+						     THROTTLE_DEFAULT);
+			g_message ("Setting throttle from %d to %d",
+				   throttle,
+				   THROTTLE_DEFAULT);
+		} else {
+			g_message ("Not setting throttle, it is currently set to %d",
+				   throttle);
+		}
+	}
+}
+
+static void
+battery_in_use_cb (GObject *gobject,
+		   GParamSpec *arg1,
+		   gpointer user_data)
+{
+	set_up_throttle ();
+}
+
+static void
+battery_percentage_cb (GObject    *object,
+		       GParamSpec *pspec,
+		       gpointer    user_data)
+{
+	TrackerStatusPrivate *private;
+	gdouble               percentage;
+	gboolean              battery_in_use;
+
 	private = g_static_private_get (&private_key);
 	g_return_if_fail (private != NULL);
 
-	org_freedesktop_Tracker_Indexer_pause_async (private->indexer_proxy,
-						     indexer_pause_cb,
-						     NULL);
+	percentage = tracker_hal_get_battery_percentage (private->hal);
+	battery_in_use = tracker_hal_get_battery_in_use (private->hal);
+
+	/* FIXME: This could be a configuration option */
+	if (battery_in_use) {
+		g_message ("Battery percentage is now %d%%",
+			   (gint) percentage * 100);
+		
+		if (percentage <= 0.05) {
+			/* Running on low batteries, stop indexing for now */
+			tracker_status_set_is_paused_for_batt (TRUE);
+		} else {
+			tracker_status_set_is_paused_for_batt (FALSE);
+		}
+	} else {
+		tracker_status_set_is_paused_for_batt (FALSE);
+	}
+
+	set_up_throttle ();
 }
 
+#endif /* HAVE_HAL */
+
 gboolean
-tracker_status_init (TrackerConfig *config)
+tracker_status_init (TrackerConfig *config,
+		     TrackerHal    *hal)
 {
 	GType		      type;
 	DBusGProxy           *proxy;
@@ -320,6 +477,15 @@
 
 	private->config = g_object_ref (config);
 
+#ifdef HAVE_HAL 
+	private->hal = g_object_ref (hal);
+
+	g_message ("Setting battery percentage checking");
+	g_signal_connect (private->hal, "notify::battery-percentage",
+			  G_CALLBACK (battery_percentage_cb),
+			  NULL);
+#endif
+
 	private->is_readonly = FALSE;
 	private->is_ready = FALSE;
 	private->is_running = FALSE;
@@ -328,6 +494,7 @@
 	private->is_paused_for_batt = FALSE;
 	private->is_paused_for_io = FALSE;
 	private->is_paused_for_space = FALSE;
+	private->is_paused_for_dbus = FALSE;
 	private->is_paused_for_unknown = FALSE;
 	private->in_merge = FALSE;
 
@@ -348,6 +515,11 @@
 				     NULL,
 				     NULL);
 	
+	/* Start monitoring system for low disk space, low battery
+	 * power, etc. 
+	 */
+	disk_space_check_start ();
+
 	return TRUE;
 }
 
@@ -458,6 +630,14 @@
 		   tracker_status_to_string (private->status),
 		   tracker_status_to_string (new_status));
 
+	/* Don't set previous status to the same as we are now,
+	 * otherwise we could end up setting PAUSED and our old state
+	 * to return to is also PAUSED.
+	 */
+	if (private->status_before_paused != new_status) {
+		private->status_before_paused = private->status;
+	}
+
 	private->status = new_status;
 }
 
@@ -487,6 +667,7 @@
 	pause_for_io = 
 		private->is_paused_for_io || 
 		private->is_paused_for_space || 
+		private->is_paused_for_dbus ||
 		private->is_paused_for_unknown;
 	
 	g_signal_emit_by_name (object,
@@ -699,24 +880,17 @@
 tracker_status_set_is_paused_manually (gboolean value)
 {
 	TrackerStatusPrivate *private;
-	gboolean	      emit;
+	gboolean              emit;
 
 	private = g_static_private_get (&private_key);
 	g_return_if_fail (private != NULL);
 
-	emit  = TRUE;
-	emit |= private->is_paused_manually != value;
-	emit |= private->status != TRACKER_STATUS_PAUSED;
-
 	/* Set value */
+	emit = private->is_paused_manually != value;
 	private->is_paused_manually = value;
 
 	/* Set indexer state and our state to paused or not */ 
-	indexer_recheck (TRUE);
-
-	if (emit) {
-		tracker_status_signal ();
-	}
+	indexer_recheck (TRUE, FALSE, emit);
 }
 
 gboolean
@@ -734,24 +908,17 @@
 tracker_status_set_is_paused_for_batt (gboolean value)
 {
 	TrackerStatusPrivate *private;
-	gboolean	      emit;
+	gboolean              emit;
 
 	private = g_static_private_get (&private_key);
 	g_return_if_fail (private != NULL);
 
-	emit  = TRUE;
-	emit |= private->is_paused_for_batt != value;
-	emit |= private->status != TRACKER_STATUS_PAUSED;
-
 	/* Set value */
+	emit = private->is_paused_for_batt != value;
 	private->is_paused_for_batt = value;
 
 	/* Set indexer state and our state to paused or not */ 
-	indexer_recheck (TRUE);
-
-	if (emit) {
-		tracker_status_signal ();
-	}
+	indexer_recheck (TRUE, FALSE, emit);
 }
 
 gboolean
@@ -774,22 +941,12 @@
 	private = g_static_private_get (&private_key);
 	g_return_if_fail (private != NULL);
 
-	emit = private->is_paused_for_io != value;
-
-	emit  = TRUE;
-	emit |= private->is_paused_for_batt != value;
-	emit |= private->status != TRACKER_STATUS_PAUSED;
-
 	/* Set value */
+	emit = private->is_paused_for_io != value;
 	private->is_paused_for_io = value;
 
 	/* Set indexer state and our state to paused or not */ 
-	indexer_recheck (TRUE);
-
-	/* Tell the world */
-	if (emit) {
-		tracker_status_signal ();
-	}
+	indexer_recheck (TRUE, FALSE, emit);
 }
 
 gboolean
@@ -807,25 +964,44 @@
 tracker_status_set_is_paused_for_space (gboolean value)
 {
 	TrackerStatusPrivate *private;
-	gboolean	      emit;
+	gboolean              emit;
 
 	private = g_static_private_get (&private_key);
 	g_return_if_fail (private != NULL);
 
+	/* Set value */
 	emit = private->is_paused_for_space != value;
+	private->is_paused_for_space = value;
+
+	/* Set indexer state and our state to paused or not */ 
+	indexer_recheck (TRUE, FALSE, emit);
+}
+
+gboolean
+tracker_status_get_is_paused_for_dbus (void)
+{
+	TrackerStatusPrivate *private;
+
+	private = g_static_private_get (&private_key);
+	g_return_val_if_fail (private != NULL, FALSE);
 
-	emit  = TRUE;
-	emit |= private->is_paused_for_batt != value;
-	emit |= private->status != TRACKER_STATUS_PAUSED;
+	return private->is_paused_for_space;
+}
+
+void
+tracker_status_set_is_paused_for_dbus (gboolean value)
+{
+	TrackerStatusPrivate *private;
+	gboolean              emit;
+
+	private = g_static_private_get (&private_key);
+	g_return_if_fail (private != NULL);
 
 	/* Set value */
-	private->is_paused_for_space = value;
+	emit = private->is_paused_for_dbus != value;
+	private->is_paused_for_dbus = value;
 
 	/* Set indexer state and our state to paused or not */ 
-	indexer_recheck (TRUE);
-
-	if (emit) {
-		tracker_status_signal ();
-	}
+	indexer_recheck (TRUE, TRUE, emit);
 }
 

Modified: trunk/src/trackerd/tracker-status.h
==============================================================================
--- trunk/src/trackerd/tracker-status.h	(original)
+++ trunk/src/trackerd/tracker-status.h	Tue Feb 17 17:40:31 2009
@@ -25,6 +25,7 @@
 #include <glib-object.h>
 
 #include <libtracker-common/tracker-config.h>
+#include <libtracker-common/tracker-hal.h>
 
 G_BEGIN_DECLS
 
@@ -42,7 +43,8 @@
 } TrackerStatus;
 
 
-gboolean      tracker_status_init		     (TrackerConfig *config);
+gboolean      tracker_status_init		     (TrackerConfig *config,
+						      TrackerHal    *hal);
 void	      tracker_status_shutdown		     (void);
 
 GType	      tracker_status_get_type		     (void) G_GNUC_CONST;
@@ -80,6 +82,9 @@
 gboolean      tracker_status_get_is_paused_for_space (void);
 void	      tracker_status_set_is_paused_for_space (gboolean	     value);
 
+gboolean      tracker_status_get_is_paused_for_dbus  (void);
+void	      tracker_status_set_is_paused_for_dbus  (gboolean	     value);
+
 G_END_DECLS
 
 #endif /* __TRACKERD_STATUS_H__ */



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