Commit c9703295 authored by Martyn James Russell's avatar Martyn James Russell

Added new state (PAUSED) and add to the tooltip when paused so it is known

	* src/tracker-applet/tracker-applet.c: (set_status_hint),
	(can_auto_pause), (index_state_changed): Added new state (PAUSED)
	and add to the tooltip when paused so it is known that it can also
	be because of heave disk IO OR low disk space. Also uncommented
	the code for the tooltip when we are paused due to low battery.

	* src/tracker-indexer/tracker-indexer.c: Make low disk space
	warning a g_message() instead. Also added a state_to_string()
	function so we can see state changes a bit more clearly in the
	logs.

	* src/trackerd/tracker-daemon.c:
	* src/trackerd/tracker-dbus.c:
	* src/trackerd/tracker-main.c: 
	* src/trackerd/tracker-monitor.c:
	* src/trackerd/tracker-processor.c:
	* src/trackerd/tracker-status.[ch]: Moved all indexer state
	monitoring (paused/continued) to the tracker-status module. Now
	when we use APIs like tracker_status_set_is_paused_manually() it
	will now: 
	  - Tell the indexer to pause/continue
	  - Signal the applet that we are in a new state
	  - Set the state internally.

svn path=/trunk/; revision=2884
parent d2538bc3
2009-02-05 Martyn Russell <martyn@imendio.com>
* src/tracker-applet/tracker-applet.c: (set_status_hint),
(can_auto_pause), (index_state_changed): Added new state (PAUSED)
and add to the tooltip when paused so it is known that it can also
be because of heave disk IO OR low disk space. Also uncommented
the code for the tooltip when we are paused due to low battery.
* src/tracker-indexer/tracker-indexer.c: Make low disk space
warning a g_message() instead. Also added a state_to_string()
function so we can see state changes a bit more clearly in the
logs.
* src/trackerd/tracker-daemon.c:
* src/trackerd/tracker-dbus.c:
* src/trackerd/tracker-main.c:
* src/trackerd/tracker-monitor.c:
* src/trackerd/tracker-processor.c:
* src/trackerd/tracker-status.[ch]: Moved all indexer state
monitoring (paused/continued) to the tracker-status module. Now
when we use APIs like tracker_status_set_is_paused_manually() it
will now:
- Tell the indexer to pause/continue
- Signal the applet that we are in a new state
- Set the state internally.
All pausing/continuing is now handled collectively in the same
places and some bugs were fixed here.
We now don't send queued files to the indexer when we are paused
for *ANY* reason (before it was just when paused for IO or
manually).
2009-02-05 Martyn Russell <martyn@imendio.com>
* src/libinotify/inotify-monitor.c: (inotify_watch_func), Add main
......
......@@ -99,6 +99,7 @@ typedef enum {
typedef enum {
INDEX_INITIALIZING,
INDEX_IDLE,
INDEX_PAUSED,
INDEX_BUSY,
INDEX_MERGING
} IndexStateEnum;
......@@ -281,6 +282,12 @@ set_status_hint (TrayIcon *icon)
*/
index_status = _("Idle");
break;
case INDEX_PAUSED:
/* Translators: this will be a status hint like:
* Tracker: Idle
*/
index_status = _("Paused");
break;
case INDEX_BUSY:
/* Translators: this will be a status hint like:
* Tracker: Indexing
......@@ -293,29 +300,26 @@ set_status_hint (TrayIcon *icon)
*/
index_status = _("Merging");
break;
default:
g_critical ("Unreachable status.");
}
if (priv->user_pause) {
/* Translators: this will be a status hint like:
* Tracker: Initializing/Idle/Indexing/Merging (paused by user)
*/
pause_status = _("paused by user");
pause_status = _("by user");
} else if (priv->auto_pause) {
/* Translators: this will be a status hint like:
* Tracker: Initializing/Idle/Indexing/Merging (paused by system)
*/
pause_status = _("paused by system");
pause_status = _("by system");
} else {
switch (priv->pause_state) {
case PAUSE_INTERNAL:
/* Translators: this will be a status hint like:
* Tracker: Initializing/Idle/Indexing/Merging (paused by system)
*/
pause_status = _("paused by system");
/* Translators: this will be a status hint like:
* Tracker: Initializing/Idle/Indexing/Merging (paused by system)
*/
pause_status = _("low disk space or heavy disk use");
break;
#if 0
case PAUSE_BATTERY:
/* FIXME: We need to check if we are on the
* battery first, this state purely means we
......@@ -324,9 +328,8 @@ set_status_hint (TrayIcon *icon)
/* Translators: this will be a status hint like:
* Tracker: Initializing/Idle/Indexing/Merging (paused by battery)
*/
pause_status = _("paused by battery");
pause_status = _("low battery");
break;
#endif
default:
case PAUSE_NONE:
pause_status = NULL;
......@@ -412,8 +415,6 @@ can_auto_pause (TrayIcon *icon)
return priv->index_state != INDEX_IDLE;
case AUTO_PAUSE_MERGING:
return priv->index_state == INDEX_MERGING;
default:
g_critical ("Unreachable state in auto pause.");
}
return TRUE;
......@@ -1667,14 +1668,14 @@ index_state_changed (DBusGProxy *proxy,
if (is_manual_paused) {
stop_watching_events (icon);
paused = TRUE;
if (!priv->auto_pause) {
priv->user_pause = TRUE;
}
paused = TRUE;
} else if (is_battery_paused) {
priv->pause_state = PAUSE_BATTERY;
paused = TRUE;
priv->pause_state = PAUSE_BATTERY;
} else if (is_io_paused) {
paused = TRUE;
priv->pause_state = PAUSE_INTERNAL;
......@@ -1687,6 +1688,8 @@ index_state_changed (DBusGProxy *proxy,
priv->index_state = INDEX_INITIALIZING;
} else if (g_ascii_strcasecmp (state, "Idle") == 0) {
priv->index_state = INDEX_IDLE;
} else if (g_ascii_strcasecmp (state, "Paused") == 0) {
priv->index_state = INDEX_PAUSED;
} else {
priv->index_state = INDEX_BUSY;
priv->animated = TRUE;
......
......@@ -751,7 +751,7 @@ check_is_disk_space_low (TrackerIndexer *indexer)
}
if (((long long) st.f_bavail * 100 / st.f_blocks) <= limit) {
g_warning ("Disk space is low");
g_message ("Disk space is low");
return TRUE;
}
......@@ -2605,6 +2605,34 @@ state_check (TrackerIndexer *indexer)
}
}
static gchar *
state_to_string (TrackerIndexerState state)
{
GString *s;
s = g_string_new ("");
if (state & TRACKER_INDEXER_STATE_FLUSHING) {
s = g_string_append (s, "FLUSHING | ");
}
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';
return g_string_free (s, FALSE);
}
static void
state_set_flags (TrackerIndexer *indexer,
TrackerIndexerState state)
......@@ -2624,14 +2652,29 @@ state_set_flags (TrackerIndexer *indexer,
(state & TRACKER_INDEXER_STATE_PAUSED ||
state & TRACKER_INDEXER_STATE_DISK_FULL ||
state & TRACKER_INDEXER_STATE_LOW_BATT)) {
const gchar *reason = NULL;
const gchar *reason;
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')",
old_state_str,
state_str,
reason ? reason : "None");
g_free (state_str);
g_free (old_state_str);
g_signal_emit (indexer, signals[PAUSED], 0, reason);
}
}
......@@ -2653,6 +2696,19 @@ state_unset_flags (TrackerIndexer *indexer,
(! (new_state & TRACKER_INDEXER_STATE_PAUSED)) &&
(! (new_state & TRACKER_INDEXER_STATE_DISK_FULL)) &&
(! (new_state & TRACKER_INDEXER_STATE_LOW_BATT))) {
gchar *old_state_str;
gchar *state_str;
old_state_str = state_to_string (old_state);
state_str = state_to_string (indexer->private->state);
g_message ("State change from '%s' --> '%s'",
old_state_str,
state_str);
g_free (state_str);
g_free (old_state_str);
g_signal_emit (indexer, signals[CONTINUED], 0);
}
}
......
......@@ -59,17 +59,6 @@ enum {
};
static void tracker_daemon_finalize (GObject *object);
static void indexer_pause_cb (DBusGProxy *proxy,
GError *error,
gpointer user_data);
static void indexer_continue_cb (DBusGProxy *proxy,
GError *error,
gpointer user_data);
static void indexer_paused_cb (DBusGProxy *proxy,
const gchar *reason,
gpointer user_data);
static void indexer_continued_cb (DBusGProxy *proxy,
gpointer user_data);
static guint signals[LAST_SIGNAL] = {0};
......@@ -240,21 +229,13 @@ tracker_daemon_init (TrackerDaemon *object)
TrackerDaemonPrivate *priv;
TrackerDBInterface *iface;
TrackerDBResultSet *result_set;
DBusGProxy *proxy;
DBusGProxy *proxy;
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, "Paused",
G_CALLBACK (indexer_paused_cb),
object,
NULL);
dbus_g_proxy_connect_signal (proxy, "Continued",
G_CALLBACK (indexer_continued_cb),
object,
NULL);
dbus_g_proxy_connect_signal (proxy, "Finished",
G_CALLBACK (indexer_finished_cb),
object,
......@@ -281,14 +262,8 @@ tracker_daemon_finalize (GObject *object)
clean_last_stats (priv);
dbus_g_proxy_disconnect_signal (priv->indexer_proxy, "Continued",
G_CALLBACK (indexer_continued_cb),
NULL);
dbus_g_proxy_disconnect_signal (priv->indexer_proxy, "Paused",
G_CALLBACK (indexer_paused_cb),
NULL);
dbus_g_proxy_disconnect_signal (priv->indexer_proxy, "Finished",
G_CALLBACK (indexer_continued_cb),
G_CALLBACK (indexer_finished_cb),
NULL);
g_object_unref (priv->indexer_proxy);
......@@ -319,52 +294,6 @@ tracker_daemon_new (TrackerConfig *config,
return object;
}
static void
indexer_pause_cb (DBusGProxy *proxy,
GError *error,
gpointer user_data)
{
if (error) {
g_message ("Could not pause the indexer, %s",
error->message);
}
}
static void
indexer_continue_cb (DBusGProxy *proxy,
GError *error,
gpointer user_data)
{
if (error) {
g_message ("Could not continue the indexer, %s",
error->message);
}
}
static void
indexer_paused_cb (DBusGProxy *proxy,
const gchar *reason,
gpointer user_data)
{
g_message ("The indexer has paused (Reason: %s)", reason);
if (reason) {
if (strcmp (reason, "Disk full") == 0) {
tracker_status_set_and_signal (TRACKER_STATUS_DISK_FULL);
} else if (strcmp (reason, "Battery low") == 0) {
tracker_status_set_and_signal (TRACKER_STATUS_LOW_BATT);
}
}
}
static void
indexer_continued_cb (DBusGProxy *proxy,
gpointer user_data)
{
g_message ("The indexer has continued");
tracker_status_set_and_signal (TRACKER_STATUS_INDEXING);
}
/*
* Functions
*/
......@@ -537,19 +466,6 @@ tracker_daemon_set_bool_option (TrackerDaemon *object,
* was the signal from our request.
*/
tracker_status_set_is_paused_manually (value);
if (value) {
org_freedesktop_Tracker_Indexer_pause_async (priv->indexer_proxy,
indexer_pause_cb,
NULL);
} else {
/* Don't continue if we are paused from IO */
if (!tracker_status_get_is_paused_for_io ()) {
org_freedesktop_Tracker_Indexer_continue_async (priv->indexer_proxy,
indexer_continue_cb,
NULL);
}
}
} else if (strcasecmp (option, "FastMerges") == 0) {
tracker_config_set_fast_merges (priv->config, value);
g_message ("Fast merges set to %d", value);
......
......@@ -180,7 +180,9 @@ indexer_resume_cb (gpointer user_data)
proxy = user_data;
if (!tracker_status_get_is_paused_manually () &&
!tracker_status_get_is_paused_for_io ()) {
!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);
......@@ -200,16 +202,20 @@ static void
dbus_request_new_cb (guint request_id,
gpointer user_data)
{
DBusGProxy *proxy;
GError *error = NULL;
gboolean set_paused = TRUE;
TrackerStatus status;
DBusGProxy *proxy;
GError *error = NULL;
gboolean set_paused = TRUE;
TrackerStatus status;
status = tracker_status_get ();
if (status != TRACKER_STATUS_INDEXING &&
status != TRACKER_STATUS_DISK_FULL &&
status != TRACKER_STATUS_LOW_BATT) {
/* Don't pause if already paused */
if (status == TRACKER_STATUS_PAUSED) {
return;
}
/* Don't try to pause unless we are in particular states */
if (status != TRACKER_STATUS_INDEXING) {
return;
}
......@@ -234,14 +240,6 @@ dbus_request_new_cb (guint request_id,
g_object_ref (proxy),
indexer_resume_destroy_notify_cb);
/* Third check if we are already paused, if we are there is
* no need to tell the indexer.
*/
if (tracker_status_get_is_paused_manually ()) {
g_message ("Tracker is already manually paused, doing nothing");
return;
}
/* 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,
......
......@@ -846,7 +846,7 @@ start_cb (gpointer user_data)
{
TrackerMainPrivate *private;
if (!tracker_status_get_is_running ()) {
if (!tracker_status_get_is_ready ()) {
return FALSE;
}
......@@ -1012,8 +1012,6 @@ main (gint argc, gchar *argv[])
initialize_directories ();
/* Initialize other subsystems */
tracker_status_init (config);
tracker_log_init (private->log_filename, tracker_config_get_verbosity (config));
g_print ("Starting log:\n File:'%s'\n", private->log_filename);
......@@ -1025,6 +1023,8 @@ main (gint argc, gchar *argv[])
return EXIT_FAILURE;
}
tracker_status_init (config);
tracker_module_config_init ();
tracker_turtle_init ();
......@@ -1136,7 +1136,7 @@ main (gint argc, gchar *argv[])
/* Set our status as running, if this is FALSE, threads stop
* doing what they do and shutdown.
*/
tracker_status_set_is_running (TRUE);
tracker_status_set_is_ready (TRUE);
if (!tracker_status_get_is_readonly ()) {
gint seconds;
......@@ -1163,7 +1163,7 @@ main (gint argc, gchar *argv[])
backup_restore_on_crawling_finished (private->processor);
}
if (tracker_status_get_is_running ()) {
if (tracker_status_get_is_ready ()) {
private->main_loop = g_main_loop_new (NULL, FALSE);
g_main_loop_run (private->main_loop);
}
......@@ -1250,7 +1250,7 @@ tracker_shutdown (void)
private = g_static_private_get (&private_key);
tracker_status_set_is_running (FALSE);
tracker_status_set_is_ready (FALSE);
tracker_processor_stop (private->processor);
......
......@@ -35,7 +35,6 @@
#include "tracker-monitor.h"
#include "tracker-dbus.h"
#include "tracker-indexer-client.h"
#include "tracker-marshal.h"
#include "tracker-status.h"
......@@ -580,28 +579,6 @@ get_module_name_from_gfile (TrackerMonitor *monitor,
#ifdef PAUSE_ON_IO
static void
indexer_pause_cb (DBusGProxy *proxy,
GError *error,
gpointer user_data)
{
if (error) {
g_message ("Could not pause the indexer, %s",
error->message);
}
}
static void
indexer_continue_cb (DBusGProxy *proxy,
GError *error,
gpointer user_data)
{
if (error) {
g_message ("Could not continue the indexer, %s",
error->message);
}
}
static gboolean
unpause_cb (gpointer data)
{
......@@ -609,18 +586,12 @@ unpause_cb (gpointer data)
monitor = data;
monitor->private->unpause_timeout_id = 0;
tracker_status_set_is_paused_for_io (FALSE);
g_message ("Resuming indexing now we have stopped "
"receiving monitor events for %d seconds",
PAUSE_ON_IO_SECONDS);
if (!tracker_status_get_is_paused_manually ()) {
org_freedesktop_Tracker_Indexer_continue_async (tracker_dbus_indexer_get_proxy (),
indexer_continue_cb,
NULL);
}
monitor->private->unpause_timeout_id = 0;
tracker_status_set_is_paused_for_io (FALSE);
return FALSE;
}
......@@ -1087,10 +1058,6 @@ libinotify_monitor_event_cb (INotifyHandle *handle,
"receiving monitor events");
tracker_status_set_is_paused_for_io (TRUE);
org_freedesktop_Tracker_Indexer_pause_async (tracker_dbus_indexer_get_proxy (),
indexer_pause_cb,
NULL);
}
monitor->private->unpause_timeout_id =
......@@ -1397,10 +1364,6 @@ monitor_event_cb (GFileMonitor *file_monitor,
"receiving monitor events");
tracker_status_set_is_paused_for_io (TRUE);
org_freedesktop_Tracker_Indexer_pause_async (tracker_dbus_indexer_get_proxy (),
indexer_pause_cb,
NULL);
}
monitor->private->unpause_timeout_id =
......
......@@ -600,8 +600,7 @@ item_queue_handlers_cb (gpointer user_data)
* events but we still queue them ready to send when we are
* unpaused.
*/
if (tracker_status_get_is_paused_manually () ||
tracker_status_get_is_paused_for_io ()) {
if (tracker_status_get () == TRACKER_STATUS_PAUSED) {
g_message ("We are paused, sending nothing to the index until we are unpaused");
return TRUE;
}
......
......@@ -25,21 +25,37 @@
#include "tracker-dbus.h"
#include "tracker-daemon.h"
#include "tracker-main.h"
#include "tracker-indexer-client.h"
typedef struct {
TrackerStatus status;
TrackerStatus status_before_paused;
gpointer type_class;
TrackerConfig *config;
gboolean is_running;
DBusGProxy *indexer_proxy;
gboolean is_readonly;
gboolean is_ready;
gboolean is_running;
gboolean is_first_time_index;
gboolean is_paused_manually;
gboolean is_paused_for_batt;
gboolean is_paused_for_io;
gboolean is_paused_for_space;
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 GStaticPrivate private_key = G_STATIC_PRIVATE_INIT;
static void
......@@ -57,13 +73,225 @@ private_free (gpointer data)
g_type_class_unref (private->type_class);
}
dbus_g_proxy_disconnect_signal (private->indexer_proxy, "Continued",
G_CALLBACK (indexer_continued_cb),
NULL);
dbus_g_proxy_disconnect_signal (private->indexer_proxy, "Paused",
G_CALLBACK (indexer_paused_cb),
NULL);
dbus_g_proxy_disconnect_signal (private->indexer_proxy, "Finished",
G_CALLBACK (indexer_continued_cb),
NULL);
g_object_unref (private->indexer_proxy);
g_free (private);
}
/*
* Handle Indexer pausing/continuation
*/
static void
indexer_recheck (gboolean should_inform_indexer)
{
TrackerStatusPrivate *private;
private = g_static_private_get (&private_key);
g_return_if_fail (private != NULL);
/* Are we paused in any way? */
if (private->is_paused_manually ||
private->is_paused_for_batt ||
private->is_paused_for_io ||
private->is_paused_for_space) {
/* We are paused, but our status is NOT paused? */
if (private->status != TRACKER_STATUS_PAUSED) {
private->status_before_paused = private->status;
private->status = TRACKER_STATUS_PAUSED;
if (G_LIKELY (should_inform_indexer)) {
indexer_pause ();
}
}
} else {
/* We are not paused, but our status is paused */
if (private->status == TRACKER_STATUS_PAUSED) {
private->status = private->status_before_paused;
if (G_LIKELY (should_inform_indexer)) {
indexer_continue (0);
}
}
}
}
static void
indexer_paused_cb (DBusGProxy *proxy,
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 ();
}
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;
/* Set state to what it was before the pause. */
private->status = private->status_before_paused;
/* 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);
}
static void
indexer_continue_cb (DBusGProxy *proxy,
GError *error,
gpointer user_data)
{
if (error) {
g_message ("Could not continue the indexer, %s",
error->message);
/* Return state to paused */
tracker_status_set_and_signal (TRACKER_STATUS_PAUSED);
/* 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
*/
}
}
static void
indexer_continue (guint seconds)
{