tracker r1662 - in branches/indexer-split: . src/libtracker-common src/trackerd



Author: mr
Date: Thu Jun 12 15:43:24 2008
New Revision: 1662
URL: http://svn.gnome.org/viewvc/tracker?rev=1662&view=rev

Log:
	* src/trackerd/tracker-crawler.c: Use the new
	tracker_dbus_async_queue_to_strv() API to generate the GStrv
	instead of using a GPtrArray.

	* src/trackerd/tracker-monitor.c: Save the config variable on
	initialisation.


Modified:
   branches/indexer-split/ChangeLog
   branches/indexer-split/src/libtracker-common/tracker-dbus.c
   branches/indexer-split/src/libtracker-common/tracker-dbus.h
   branches/indexer-split/src/trackerd/tracker-crawler.c
   branches/indexer-split/src/trackerd/tracker-monitor.c

Modified: branches/indexer-split/src/libtracker-common/tracker-dbus.c
==============================================================================
--- branches/indexer-split/src/libtracker-common/tracker-dbus.c	(original)
+++ branches/indexer-split/src/libtracker-common/tracker-dbus.c	Thu Jun 12 15:43:24 2008
@@ -79,6 +79,44 @@
 	return strv;
 }
 
+gchar **
+tracker_dbus_async_queue_to_strv (GAsyncQueue *queue, 
+				  gint         max)
+{
+	gchar **strv;
+	gint    i = 0;
+	gint    length;
+
+	length = g_async_queue_length (queue);
+		
+	if (max > 0) {
+		length = MIN (max, length);
+	}
+
+	strv = g_new0 (gchar*, length + 1);
+	
+	while (i <= length) {
+		GTimeVal  t;
+		gchar    *str;
+		
+		g_get_current_time (&t);
+		g_time_val_add (&t, 100000);
+
+		/* Get next item and wait 0.1 seconds max per try */
+		str = g_async_queue_timed_pop (queue, &t);
+		if (str) {
+			strv[i++] = str;
+		} else {
+			/* We don't expect this */
+			break;
+		}
+	}
+
+        strv[i] = NULL;
+
+	return strv;
+}
+
 guint
 tracker_dbus_get_next_request_id (void)
 {

Modified: branches/indexer-split/src/libtracker-common/tracker-dbus.h
==============================================================================
--- branches/indexer-split/src/libtracker-common/tracker-dbus.h	(original)
+++ branches/indexer-split/src/libtracker-common/tracker-dbus.h	Thu Jun 12 15:43:24 2008
@@ -83,6 +83,8 @@
 GValue *         tracker_dbus_g_value_slice_new   (GType            type);
 void             tracker_dbus_g_value_slice_free  (GValue          *value);
 gchar **         tracker_dbus_slist_to_strv       (GSList          *list);
+gchar **         tracker_dbus_async_queue_to_strv (GAsyncQueue     *queue, 
+						   gint             max);
 
 /* Requests */
 guint            tracker_dbus_get_next_request_id (void);

Modified: branches/indexer-split/src/trackerd/tracker-crawler.c
==============================================================================
--- branches/indexer-split/src/trackerd/tracker-crawler.c	(original)
+++ branches/indexer-split/src/trackerd/tracker-crawler.c	Thu Jun 12 15:43:24 2008
@@ -25,6 +25,7 @@
 #include <gio/gio.h>
 
 #include <libtracker-common/tracker-utils.h>
+#include <libtracker-common/tracker-dbus.h>
 
 #include "tracker-crawler.h"
 #include "tracker-dbus.h"
@@ -731,13 +732,15 @@
 {
 	TrackerCrawler *crawler;
 	DBusGProxy     *proxy;
-	GPtrArray      *ptr_array;
 	GError         *error;
 	gchar **        files;
 	gboolean        running;
 	gint            length;
+#if 0
 	gint            items;
+	GPtrArray      *ptr_array;
 	gint            i;
+#endif
 
 	crawler = user_data;
 
@@ -762,35 +765,10 @@
 	}
 
 	g_debug ("Processing file queue...");
-        ptr_array = g_ptr_array_new ();
-
-	/* Throttle files we send over to the indexer */
-	items = MIN (FILES_QUEUE_PROCESS_MAX, length);
-	g_debug ("Processing %d/%d items in the queue", 
-		 items,
-		 length);
-
-	while (items > 0) {
-		GTimeVal  t;
-		gchar    *filename;
-		
-		g_get_current_time (&t);
-		g_time_val_add (&t, 100000);
-
-		/* Get next filename and wait 0.1 seconds max per try */
-		filename = g_async_queue_timed_pop (crawler->priv->files, &t);
-		if (filename) {
-			g_ptr_array_add (ptr_array, filename);
-			items--;
-		}
-	}
-
-	length = ptr_array->len;
-	g_ptr_array_add (ptr_array, NULL);
-	files = (gchar **) g_ptr_array_free (ptr_array, FALSE);
-
-	g_debug ("Sending %d files to indexer to process", length);
+	files = tracker_dbus_async_queue_to_strv (crawler->priv->files,
+						  FILES_QUEUE_PROCESS_MAX);
 
+	g_debug ("Sending %d files to indexer to process", g_strv_length (files));
 	org_freedesktop_Tracker_Indexer_process_files (proxy, 
 						       (const gchar **) files,
 						       &error);
@@ -804,12 +782,8 @@
 		g_debug ("Sent!");
 	}
 
-	for (i = 0; files[i] != NULL; i++) {
-		g_free (files[i]);
-	}
+	g_strfreev (files);
 
-	g_free (files);
-							     
 	return TRUE;
 }
 

Modified: branches/indexer-split/src/trackerd/tracker-monitor.c
==============================================================================
--- branches/indexer-split/src/trackerd/tracker-monitor.c	(original)
+++ branches/indexer-split/src/trackerd/tracker-monitor.c	Thu Jun 12 15:43:24 2008
@@ -31,79 +31,40 @@
  */
 #define MAX_MONITORS (guint) ((2 ^ 13) - 500)   
 
-static GHashTable *monitors;
-
-#if 0
-static void
-get_monitor_roots (GSList **included,
-		   GSList **excluded)
-{
-        GSList *watch_directory_roots;
-        GSList *no_watch_directory_roots;
-        GSList *mounted_directory_roots;
-        GSList *removable_device_roots;
-
-        *included = NULL;
-        *excluded = NULL;
-
-        get_remote_roots (&mounted_directory_roots, 
-			  &removable_device_roots);        
-        
-        /* Delete all stuff in the no watch dirs */
-        watch_directory_roots = 
-                tracker_config_get_watch_directory_roots (config);
-        
-        no_watch_directory_roots = 
-                tracker_config_get_no_watch_directory_roots (config);
-
-        /* Create list for enabled roots based on config */
-        *included = g_slist_concat (*included, g_slist_copy (watch_directory_roots));
-        
-        /* Create list for disabled roots based on config */
-        *excluded = g_slist_concat (*excluded, g_slist_copy (no_watch_directory_roots));
-
-        /* Add or remove roots which pertain to removable media */
-        if (tracker_config_get_index_removable_devices (config)) {
-                *included = g_slist_concat (*included, g_slist_copy (removable_device_roots));
-        } else {
-                *excluded = g_slist_concat (*excluded, g_slist_copy (removable_device_roots));
-        }
-
-        /* Add or remove roots which pertain to mounted directories */
-        if (tracker_config_get_index_mounted_directories (config)) {
-                *included = g_slist_concat (*included, g_slist_copy (mounted_directory_roots));
-        } else {
-                *excluded = g_slist_concat (*excluded, g_slist_copy (mounted_directory_roots));
-        }
-}
-
-#endif
+static GHashTable    *monitors;
+static TrackerConfig *config;
 
 gboolean 
-tracker_monitor_init (TrackerConfig *config) 
+tracker_monitor_init (TrackerConfig *_config) 
 {
-	g_return_val_if_fail (TRACKER_IS_CONFIG (config), FALSE);
-
-	if (monitors) {
-		return TRUE;
+	g_return_val_if_fail (TRACKER_IS_CONFIG (_config), FALSE);
+	
+	if (!config) {
+		config = g_object_ref (_config);
+	}
+	
+	if (!monitors) {
+		monitors = g_hash_table_new_full (g_str_hash,
+						  g_str_equal,
+						  g_free,
+						  (GDestroyNotify) g_file_monitor_cancel);
 	}
 
-	monitors = g_hash_table_new_full (g_str_hash,
-					  g_str_equal,
-					  g_free,
-					  (GDestroyNotify) g_file_monitor_cancel);
 	return TRUE;
 }
 
 void
 tracker_monitor_shutdown (void)
 {
-	if (!monitors) {
-		return;
+	if (monitors) {
+		g_hash_table_unref (monitors);
+		monitors = NULL;
+	}
+	
+	if (config) {
+		g_object_unref (config);
+		config = NULL;
 	}
-
-	g_hash_table_unref (monitors);
-	monitors = NULL;
 }
 
 gboolean



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