tracker r3065 - in trunk: . src/trackerd



Author: mr
Date: Thu Mar 12 17:29:52 2009
New Revision: 3065
URL: http://svn.gnome.org/viewvc/tracker?rev=3065&view=rev

Log:
	* src/trackerd/tracker-daemon.c: 
	* src/trackerd/tracker-main.c: Put statistics update signal in a
	separate public function. Fixed not signalling stats when we
	remove a MMC. Now clients will get updates not only when an MMC is
	inserted. 

	* src/trackerd/tracker-daemon.h: Removed tracker_daemon_backup(),
	function no longer exists.


Modified:
   trunk/ChangeLog
   trunk/src/trackerd/tracker-daemon.c
   trunk/src/trackerd/tracker-daemon.h
   trunk/src/trackerd/tracker-main.c

Modified: trunk/src/trackerd/tracker-daemon.c
==============================================================================
--- trunk/src/trackerd/tracker-daemon.c	(original)
+++ trunk/src/trackerd/tracker-daemon.c	Thu Mar 12 17:29:52 2009
@@ -135,135 +135,7 @@
 		     gboolean	 interrupted,
 		     gpointer	 user_data)
 {
-	GObject		     *daemon;
-	TrackerDaemonPrivate *priv;
-	TrackerDBInterface   *iface;
-	TrackerDBResultSet   *result_set;
-	GPtrArray	     *new_stats;
-
-	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);
-
-	/* 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);
-	new_stats = tracker_dbus_query_result_to_ptr_array (result_set);
-
-	if (result_set) {
-		g_object_unref (result_set);
-	}
-
-	/* There are 3 situations here:
-	 *  - 1. No new stats
-	 *       Action: Do nothing
-	 *  - 2. No previous stats
-	 *       Action: Emit all new stats
-	 *  - 3. New stats and old stats
-	 *       Action: Check what has changed and emit new stats
-	 */
-
-	g_message ("Checking for statistics changes and signalling clients...");
-
-	/* Situation #1 */
-	if (!new_stats) {
-		g_message ("  No new statistics, doing nothing");
-		return;
-	}
-
-	if (g_hash_table_size (priv->last_stats) < 1) {
-		GStrv strv;
-		gint i;
-
-		/* Situation #2 */
-		strv = g_new0 (gchar*, new_stats->len + 1);
-		strv[new_stats->len] = NULL;
-
-		g_message ("  No previous statistics");
-
-		for (i = 0; i < new_stats->len; i++) {
-			const gchar **p;
-			const gchar  *service_type = NULL;
-			gint          new_count;
-
-			p = g_ptr_array_index (new_stats, i);
-
-			service_type = p[1];
-			new_count = atoi (p[0]);
-			
-			if (!service_type) {
-				continue;
-			}
-
-			g_hash_table_insert (priv->last_stats, 
-					     g_strdup (service_type), 
-					     GINT_TO_POINTER (new_count));
-
-			/* GStrv for signal emission */
-			g_message ("  Adding '%s' with count:%d", 
-				   service_type,
-				   new_count);
-			strv[i] = g_strdup (service_type);
-		}
-
-		/* Emit signal */
-		g_signal_emit (daemon, signals[SERVICE_STATISTICS_UPDATED], 0, strv);
-		g_strfreev (strv);
-	} else {
-		GStrv strv = NULL;
-		GSList *l = NULL;
-		gint i;
-
-		/* Situation #3 */
-		for (i = 0; i < new_stats->len; i++) {
-			const gchar **p;
-			const gchar  *service_type = NULL;
-			gpointer      data;
-			gint          old_count, new_count;
-
-			p = g_ptr_array_index (new_stats, i);
-			service_type = p[1];
-			new_count = atoi (p[0]);
-
-			if (!service_type) {
-				continue;
-			}
-
-			data = g_hash_table_lookup (priv->last_stats, service_type);
-			old_count = GPOINTER_TO_INT (data);
-
-			if (old_count != new_count) {
-				g_message ("  Updating '%s' with new count:%d, old count:%d, diff:%d", 
-					   service_type,
-					   new_count,
-					   old_count,
-					   new_count - old_count);
-
-				l = g_slist_prepend (l, (gpointer) service_type);
-
-				g_hash_table_replace (priv->last_stats, 
-						      g_strdup (service_type), 
-						      GINT_TO_POINTER (new_count));
-			}
-		}
-
-		if (l) {
-			l = g_slist_reverse (l);
-			strv = tracker_dbus_slist_to_strv (l);
-			g_slist_free (l);
-
-			g_signal_emit (daemon, signals[SERVICE_STATISTICS_UPDATED], 0, strv);
-			g_strfreev (strv);
-		} else {
-			g_message ("  No changes in the statistics");
-
-		}
-	}
-
-	g_ptr_array_foreach (new_stats, (GFunc) g_strfreev, NULL);
-	g_ptr_array_free (new_stats, TRUE);
+	tracker_daemon_signal_statistics ();
 }
 
 static void
@@ -685,3 +557,138 @@
 
 	tracker_dbus_request_success (request_id);
 }
+
+void
+tracker_daemon_signal_statistics (void)
+{
+	GObject		     *daemon;
+	TrackerDaemonPrivate *priv;
+	TrackerDBInterface   *iface;
+	TrackerDBResultSet   *result_set;
+	GPtrArray	     *new_stats;
+
+	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);
+
+	/* 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);
+	new_stats = tracker_dbus_query_result_to_ptr_array (result_set);
+
+	if (result_set) {
+		g_object_unref (result_set);
+	}
+
+	/* There are 3 situations here:
+	 *  - 1. No new stats
+	 *       Action: Do nothing
+	 *  - 2. No previous stats
+	 *       Action: Emit all new stats
+	 *  - 3. New stats and old stats
+	 *       Action: Check what has changed and emit new stats
+	 */
+
+	g_message ("Checking for statistics changes and signalling clients...");
+
+	/* Situation #1 */
+	if (!new_stats) {
+		g_message ("  No new statistics, doing nothing");
+		return;
+	}
+
+	if (g_hash_table_size (priv->last_stats) < 1) {
+		GStrv strv;
+		gint i;
+
+		/* Situation #2 */
+		strv = g_new0 (gchar*, new_stats->len + 1);
+		strv[new_stats->len] = NULL;
+
+		g_message ("  No previous statistics");
+
+		for (i = 0; i < new_stats->len; i++) {
+			const gchar **p;
+			const gchar  *service_type = NULL;
+			gint          new_count;
+
+			p = g_ptr_array_index (new_stats, i);
+
+			service_type = p[1];
+			new_count = atoi (p[0]);
+			
+			if (!service_type) {
+				continue;
+			}
+
+			g_hash_table_insert (priv->last_stats, 
+					     g_strdup (service_type), 
+					     GINT_TO_POINTER (new_count));
+
+			/* GStrv for signal emission */
+			g_message ("  Adding '%s' with count:%d", 
+				   service_type,
+				   new_count);
+			strv[i] = g_strdup (service_type);
+		}
+
+		/* Emit signal */
+		g_signal_emit (daemon, signals[SERVICE_STATISTICS_UPDATED], 0, strv);
+		g_strfreev (strv);
+	} else {
+		GStrv strv = NULL;
+		GSList *l = NULL;
+		gint i;
+
+		/* Situation #3 */
+		for (i = 0; i < new_stats->len; i++) {
+			const gchar **p;
+			const gchar  *service_type = NULL;
+			gpointer      data;
+			gint          old_count, new_count;
+
+			p = g_ptr_array_index (new_stats, i);
+			service_type = p[1];
+			new_count = atoi (p[0]);
+
+			if (!service_type) {
+				continue;
+			}
+
+			data = g_hash_table_lookup (priv->last_stats, service_type);
+			old_count = GPOINTER_TO_INT (data);
+
+			if (old_count != new_count) {
+				g_message ("  Updating '%s' with new count:%d, old count:%d, diff:%d", 
+					   service_type,
+					   new_count,
+					   old_count,
+					   new_count - old_count);
+
+				l = g_slist_prepend (l, (gpointer) service_type);
+
+				g_hash_table_replace (priv->last_stats, 
+						      g_strdup (service_type), 
+						      GINT_TO_POINTER (new_count));
+			}
+		}
+
+		if (l) {
+			l = g_slist_reverse (l);
+			strv = tracker_dbus_slist_to_strv (l);
+			g_slist_free (l);
+
+			g_signal_emit (daemon, signals[SERVICE_STATISTICS_UPDATED], 0, strv);
+			g_strfreev (strv);
+		} else {
+			g_message ("  No changes in the statistics");
+
+		}
+	}
+
+	g_ptr_array_foreach (new_stats, (GFunc) g_strfreev, NULL);
+	g_ptr_array_free (new_stats, TRUE);
+}

Modified: trunk/src/trackerd/tracker-daemon.h
==============================================================================
--- trunk/src/trackerd/tracker-daemon.h	(original)
+++ trunk/src/trackerd/tracker-daemon.h	Thu Mar 12 17:29:52 2009
@@ -85,11 +85,9 @@
 void	       tracker_daemon_prompt_index_signals (TrackerDaemon	  *object,
 						    DBusGMethodInvocation *context,
 						    GError **error);
-void	       tracker_daemon_backup		   (TrackerDaemon	  *object,
-						    const gchar           *path,
-						    DBusGMethodInvocation *context,
-						    GError **error);
 
+/* None DBus/Object functions: should this be in tracker-status.c? -mr */
+void           tracker_daemon_signal_statistics    (void);
 
 G_END_DECLS
 

Modified: trunk/src/trackerd/tracker-main.c
==============================================================================
--- trunk/src/trackerd/tracker-main.c	(original)
+++ trunk/src/trackerd/tracker-main.c	Thu Mar 12 17:29:52 2009
@@ -70,6 +70,7 @@
 #include "tracker-status.h"
 #include "tracker-cleanup.h"
 #include "tracker-backup.h"
+#include "tracker-daemon.h"
 
 #ifdef G_OS_WIN32
 #include <windows.h>
@@ -355,6 +356,33 @@
 }
 
 static void
+mount_point_set_and_signal_cb (DBusGProxy *proxy, 
+			       GError     *error, 
+			       gpointer    user_data)
+{
+	if (error) {
+		g_critical ("Couldn't set mount point state, %s", 
+			    error->message);
+		g_error_free (error);
+		g_free (user_data);
+		return;
+	}
+
+	g_message ("Indexer now knows about UDI state:");
+	g_message ("  %s", (gchar*) user_data);
+
+
+	/* This is a special case, because we don't get the
+	 * "Finished" signal from the indexer when we set something
+	 * in the volumes table, we have to signal all clients from
+	 * here that the statistics may have changed.
+	 */
+	tracker_daemon_signal_statistics ();
+
+	g_free (user_data);
+}
+
+static void
 mount_point_removed_cb (TrackerHal  *hal,
 			const gchar *udi,
 			const gchar *mount_point,
@@ -371,7 +399,7 @@
 								   udi,
 								   mount_point,
 								   FALSE,
-								   mount_point_set_cb,
+								   mount_point_set_and_signal_cb,
 								   g_strdup (udi));
 }
 



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