tracker r2518 - in trunk: . data/dbus src/libtracker-common src/tracker-extract src/tracker-indexer src/trackerd



Author: mr
Date: Tue Nov 18 16:01:44 2008
New Revision: 2518
URL: http://svn.gnome.org/viewvc/tracker?rev=2518&view=rev

Log:
	* src/libtracker-common/tracker-hal.[ch]: Added API to get all
	* src/tracker-extract/tracker-albumart.c: 
	* src/trackerd/tracker-processor.c:
	UDIs for removable media and then to get the mount point and
	mounted state of those UDIs too. Also changed the API to use GList
	instead of GSList since we want to be consistent.

	* data/dbus/tracker-indexer.xml: 
	* src/tracker-indexer/tracker-indexer.[ch]:
	* src/trackerd/tracker-main.c: Added VolumeDisableAll API so the
	daemon can tell the indexer to disable all volumes in the Volumes
	table. This is proceded shortly with Enable for volumes which
	actually exist at the time we start the daemon.


Modified:
   trunk/ChangeLog
   trunk/data/dbus/tracker-indexer.xml
   trunk/src/libtracker-common/tracker-hal.c
   trunk/src/libtracker-common/tracker-hal.h
   trunk/src/tracker-extract/tracker-albumart.c
   trunk/src/tracker-indexer/tracker-indexer.c
   trunk/src/tracker-indexer/tracker-indexer.h
   trunk/src/trackerd/tracker-main.c
   trunk/src/trackerd/tracker-processor.c

Modified: trunk/data/dbus/tracker-indexer.xml
==============================================================================
--- trunk/data/dbus/tracker-indexer.xml	(original)
+++ trunk/data/dbus/tracker-indexer.xml	Tue Nov 18 16:01:44 2008
@@ -33,6 +33,10 @@
       <arg type="s" name="file_to" direction="in" />
     </method>
 
+    <method name="VolumeDisableAll">
+      <annotation name="org.freedesktop.DBus.GLib.Async"
+      value="true"/>
+    </method>
     <method name="VolumeUpdateState">
       <annotation name="org.freedesktop.DBus.GLib.Async" value="true"/>
       <arg type="s" name="volume_id" direction="in" />

Modified: trunk/src/libtracker-common/tracker-hal.c
==============================================================================
--- trunk/src/libtracker-common/tracker-hal.c	(original)
+++ trunk/src/libtracker-common/tracker-hal.c	Tue Nov 18 16:01:44 2008
@@ -60,7 +60,7 @@
 
 typedef struct {
 	LibHalContext *context;
-	GSList	      *roots;
+	GList	      *roots;
 } GetRoots;
 
 static void	tracker_hal_class_init		(TrackerHalClass *klass);
@@ -1068,7 +1068,7 @@
 	is_mounted = libhal_volume_is_mounted (volume);
 
 	if (is_mounted && mount_point) {
-		gr->roots = g_slist_prepend (gr->roots, g_strdup (mount_point));
+		gr->roots = g_list_prepend (gr->roots, g_strdup (mount_point));
 	}
 
 	libhal_volume_free (volume);
@@ -1078,12 +1078,12 @@
  * tracker_hal_get_mounted_directory_roots:
  * @hal: A #TrackerHal
  *
- * Returns a #GSlist of strings containing the root directories for mounted devices.
- * Each element must be freed using g_free() and the list itself using g_slist_free().
+ * Returns a #Glist of strings containing the root directories for mounted devices.
+ * Each element must be freed using g_free() and the list itself using g_list_free().
  *
  * Returns: The list of root directories.
  **/
-GSList *
+GList *
 tracker_hal_get_mounted_directory_roots (TrackerHal *hal)
 {
 	TrackerHalPriv *priv;
@@ -1107,12 +1107,12 @@
  * tracker_hal_get_removable_device_roots:
  * @hal: A #TrackerHal
  *
- * Returns a #GSList of strings containing the root directories for removable devices.
- * Each element must be freed using g_free() and the list itself through g_slist_free().
+ * Returns a #GList of strings containing the root directories for removable devices.
+ * Each element must be freed using g_free() and the list itself through g_list_free().
  *
  * Returns: The list of root directories.
  **/
-GSList *
+GList *
 tracker_hal_get_removable_device_roots (TrackerHal *hal)
 {
 	TrackerHalPriv *priv;
@@ -1132,4 +1132,85 @@
 	return gr.roots;
 }
 
+/**
+ * tracker_hal_get_removable_device_udis:
+ * @hal: A #TrackerHal
+ *
+ * Returns a #GList of strings containing the UDI for removable devices.
+ * Each element is owned by the #GHashTable internally, the list
+ * itself through should be freed using g_list_free().
+ *
+ * Returns: The list of UDIs.
+ **/
+GList *
+tracker_hal_get_removable_device_udis (TrackerHal *hal)
+{
+	TrackerHalPriv *priv;
+
+	g_return_val_if_fail (TRACKER_IS_HAL (hal), NULL);
+
+	priv = GET_PRIV (hal);
+	
+	return g_hash_table_get_keys (priv->removable_devices);
+}
+
+/**
+ * tracker_hal_udi_get_mount_point:
+ * @hal: A #TrackerHal
+ * @udi: A string pointer to the UDI for the device.
+ *
+ * Returns: The mount point for @udi, this should not be freed.
+ **/
+const gchar *
+tracker_hal_udi_get_mount_point (TrackerHal  *hal,
+				 const gchar *udi)
+{
+	TrackerHalPriv *priv;
+
+	g_return_val_if_fail (TRACKER_IS_HAL (hal), NULL);
+	g_return_val_if_fail (udi != NULL, NULL);
+
+	priv = GET_PRIV (hal);
+	
+	return g_hash_table_lookup (priv->removable_devices, udi);
+}
+
+/**
+ * tracker_hal_udi_get_mount_point:
+ * @hal: A #TrackerHal
+ * @udi: A #gboolean
+ *
+ * Returns: The %TRUE if @udi is mounted or %FALSE if it isn't.
+ **/
+gboolean    
+tracker_hal_udi_get_is_mounted (TrackerHal  *hal,
+				const gchar *udi)
+{
+	TrackerHalPriv *priv;
+	LibHalVolume   *volume;
+	const gchar    *mount_point;
+	gboolean        is_mounted;
+
+	g_return_val_if_fail (TRACKER_IS_HAL (hal), FALSE);
+	g_return_val_if_fail (udi != NULL, FALSE);
+
+	priv = GET_PRIV (hal);
+
+	volume = libhal_volume_from_udi (priv->context, udi);
+	if (!volume) {
+		g_message ("HAL device with udi:'%s' has no volume, "
+			   "should we delete?",
+			   udi);
+		return;
+	}
+
+	mount_point = libhal_volume_get_mount_point (volume);
+	is_mounted = libhal_volume_is_mounted (volume);
+
+	libhal_volume_free (volume);
+
+	return is_mounted && mount_point;
+
+}
+
 #endif /* HAVE_HAL */

Modified: trunk/src/libtracker-common/tracker-hal.h
==============================================================================
--- trunk/src/libtracker-common/tracker-hal.h	(original)
+++ trunk/src/libtracker-common/tracker-hal.h	Tue Nov 18 16:01:44 2008
@@ -50,14 +50,22 @@
 
 #ifdef HAVE_HAL
 
-GType	    tracker_hal_get_type		    (void) G_GNUC_CONST;
+GType	     tracker_hal_get_type		     (void) G_GNUC_CONST;
 
-TrackerHal *tracker_hal_new			    (void);
-gboolean    tracker_hal_get_battery_in_use	    (TrackerHal *hal);
-gboolean    tracker_hal_get_battery_exists	    (TrackerHal *hal);
-gdouble     tracker_hal_get_battery_percentage      (TrackerHal *hal);
-GSList *    tracker_hal_get_mounted_directory_roots (TrackerHal *hal);
-GSList *    tracker_hal_get_removable_device_roots  (TrackerHal *hal);
+TrackerHal * tracker_hal_new                         (void);
+
+gboolean     tracker_hal_get_battery_in_use          (TrackerHal  *hal);
+gboolean     tracker_hal_get_battery_exists          (TrackerHal  *hal);
+gdouble      tracker_hal_get_battery_percentage      (TrackerHal  *hal);
+
+GList *      tracker_hal_get_mounted_directory_roots (TrackerHal  *hal);
+GList *      tracker_hal_get_removable_device_roots  (TrackerHal  *hal);
+GList *      tracker_hal_get_removable_device_udis   (TrackerHal  *hal);
+
+const gchar *tracker_hal_udi_get_mount_point         (TrackerHal  *hal,
+						      const gchar *udi);
+gboolean     tracker_hal_udi_get_is_mounted          (TrackerHal  *hal,
+						      const gchar *udi);
 
 #endif /* HAVE_HAL */
 

Modified: trunk/src/tracker-extract/tracker-albumart.c
==============================================================================
--- trunk/src/tracker-extract/tracker-albumart.c	(original)
+++ trunk/src/tracker-extract/tracker-albumart.c	Tue Nov 18 16:01:44 2008
@@ -227,7 +227,10 @@
 static void
 perhaps_copy_to_local (const gchar *filename, const gchar *local_uri)
 {
-	GSList *removableroots, *copy = NULL;
+#ifdef HAVE_HAL
+	TrackerHal *hal;
+#endif
+	GList *removable_roots, *l;
 	gboolean on_removable_device = FALSE;
 	guint flen;
 
@@ -239,30 +242,30 @@
 	/* Determining if we are on a removable device */
 
 #ifdef HAVE_HAL
-	TrackerHal *hal = tracker_hal_new ();
-	removableroots = tracker_hal_get_removable_device_roots (hal);
+	hal = tracker_hal_new ();
+	removable_roots = tracker_hal_get_removable_device_roots (hal);
 	g_object_unref (hal);
 #else
-	removableroots = g_slist_append (removableroots, "/media");
-	removableroots = g_slist_append (removableroots, "/mnt");
+	removable_roots = g_list_append (removable_roots, "/media");
+	removable_roots = g_list_append (removable_roots, "/mnt");
 #endif
 
-	copy = removableroots;
+	for (l = removable_roots; l; l = l->next) {
+		guint len;
+		
+		len = strlen (l->data);
 
-	while (copy) {
-		guint len = strlen (copy->data);
-		if (flen >= len && strncmp (filename, copy->data, len)) {
+		if (flen >= len && strncmp (filename, l->data, len)) {
 			on_removable_device = TRUE;
 			break;
 		}
-		copy = g_slist_next (copy);
 	}
 
 #ifdef HAVE_HAL
-	g_slist_foreach (removableroots, (GFunc) g_free, NULL);
+	g_list_foreach (removable_roots, (GFunc) g_free, NULL);
 #endif
 
-	g_slist_free (removableroots);
+	g_list_free (removable_roots);
 
 	if (on_removable_device) {
 		GFile *local_file, *from;
@@ -270,7 +273,6 @@
 		from = g_file_new_for_path (filename);
 		local_file = g_file_new_for_uri (local_uri);
 
-
 		/* We don't try to overwrite, but we also ignore all errors.
 		 * Such an error could be that the removable device is 
 		 * read-only. Well that's fine then ... ignore */

Modified: trunk/src/tracker-indexer/tracker-indexer.c
==============================================================================
--- trunk/src/tracker-indexer/tracker-indexer.c	(original)
+++ trunk/src/tracker-indexer/tracker-indexer.c	Tue Nov 18 16:01:44 2008
@@ -2561,12 +2561,12 @@
 	GError *actual_error;
 	PathInfo *info;
 
+	request_id = tracker_dbus_get_next_request_id ();
+
 	tracker_dbus_async_return_if_fail (TRACKER_IS_INDEXER (indexer), context);
 	tracker_dbus_async_return_if_fail (from != NULL, context);
 	tracker_dbus_async_return_if_fail (to != NULL, context);
 
-	request_id = tracker_dbus_get_next_request_id ();
-
 	tracker_dbus_request_new (request_id,
 				  "DBus request to move '%s' to '%s'",
 				  from, to);
@@ -2591,6 +2591,25 @@
 	tracker_dbus_request_success (request_id);
 }
 
+void            
+tracker_indexer_volume_disable_all (TrackerIndexer         *indexer,
+				    DBusGMethodInvocation  *context,
+				    GError                **error)
+{
+	guint request_id;
+
+	request_id = tracker_dbus_get_next_request_id ();
+
+	tracker_dbus_async_return_if_fail (TRACKER_IS_INDEXER (indexer), context);
+
+	tracker_dbus_request_new (request_id,
+				  "DBus request to disable all volumes");
+
+
+	dbus_g_method_return (context);
+	tracker_dbus_request_success (request_id);
+}
+
 void
 tracker_indexer_volume_update_state (TrackerIndexer         *indexer,
 				     const gchar            *volume_uuid,
@@ -2601,12 +2620,12 @@
 {
 	guint request_id;
 
+	request_id = tracker_dbus_get_next_request_id ();
+
 	tracker_dbus_async_return_if_fail (TRACKER_IS_INDEXER (indexer), context);
 	tracker_dbus_async_return_if_fail (volume_uuid != NULL, context);
 	tracker_dbus_async_return_if_fail (path != NULL, context);
 
-	request_id = tracker_dbus_get_next_request_id ();
-
 	tracker_dbus_request_new (request_id,
 				  "DBus request to update volume "
 				  "UUID:'%s', path:'%s', enabled:%s",

Modified: trunk/src/tracker-indexer/tracker-indexer.h
==============================================================================
--- trunk/src/tracker-indexer/tracker-indexer.h	(original)
+++ trunk/src/tracker-indexer/tracker-indexer.h	Tue Nov 18 16:01:44 2008
@@ -113,6 +113,9 @@
 						     gchar                  *to,
 						     DBusGMethodInvocation  *context,
 						     GError                **error);
+void            tracker_indexer_volume_disable_all  (TrackerIndexer         *indexer,
+						     DBusGMethodInvocation  *context,
+						     GError                **error);
 void            tracker_indexer_volume_update_state (TrackerIndexer         *indexer,
 						     const gchar            *volume_uuid,
 						     const gchar            *path,

Modified: trunk/src/trackerd/tracker-main.c
==============================================================================
--- trunk/src/trackerd/tracker-main.c	(original)
+++ trunk/src/trackerd/tracker-main.c	Tue Nov 18 16:01:44 2008
@@ -295,14 +295,18 @@
 		    GError     *error, 
 		    gpointer    user_data)
 {
-	switch (GPOINTER_TO_INT (user_data)) {
-	case 1:
-		g_message ("Indexer now knows about mount point addition");
-		break;
-	case 2:
-		g_message ("Indexer now knows about mount point removal");
-		break;
+	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);
+
+	g_free (user_data);
 }
 
 static void
@@ -316,15 +320,15 @@
 	
 	private = g_static_private_get (&private_key);
 
-	g_message ("Indexer is being notified about added mount point:'%s'", 
-		   mount_point);
+	g_message ("Indexer is being notified about added UDI:");
+	g_message ("  %s", udi);
 
 	org_freedesktop_Tracker_Indexer_volume_update_state_async (tracker_dbus_indexer_get_proxy (), 
 								   udi,
 								   mount_point,
 								   TRUE,
 								   mount_point_set_cb,
-								   GINT_TO_POINTER (1));
+								   g_strdup (udi));
 }
 
 static void
@@ -338,15 +342,15 @@
 	
 	private = g_static_private_get (&private_key);
 
-	g_message ("Indexer is being notified about removed mount point:'%s'", 
-		   mount_point);
+	g_message ("Indexer is being notified about removed UDI:");
+	g_message ("  %s", udi);
 
 	org_freedesktop_Tracker_Indexer_volume_update_state_async (tracker_dbus_indexer_get_proxy (), 
 								   udi,
 								   mount_point,
 								   FALSE,
 								   mount_point_set_cb,
-								   GINT_TO_POINTER (2));
+								   g_strdup (udi));
 }
 
 #endif /* HAVE_HAL */
@@ -622,6 +626,57 @@
 #ifdef HAVE_HAL
 
 static void
+set_up_mount_points_cb (DBusGProxy *proxy, 
+			GError     *error,
+			gpointer    user_data)
+{
+	TrackerHal *hal;
+	GList *roots, *l;
+
+	if (error) {
+		g_critical ("Couldn't disable all volumes, %s", 
+			    error->message);
+		g_error_free (error);
+		return;
+	}
+
+	g_message ("Indexer is being notified about ALL UDIs");
+
+	hal = user_data;
+	roots = tracker_hal_get_removable_device_udis (hal);
+	
+	for (l = roots; l; l = l->next) {
+		gchar       *udi;
+		const gchar *mount_point;
+		gboolean     is_mounted;
+
+		udi = l->data;
+		mount_point = tracker_hal_udi_get_mount_point (hal, udi);
+		is_mounted = tracker_hal_udi_get_is_mounted (hal, udi);
+
+		g_message ("  %s", udi);
+
+		org_freedesktop_Tracker_Indexer_volume_update_state_async (tracker_dbus_indexer_get_proxy (), 
+									   udi,
+									   mount_point,
+									   is_mounted,
+									   mount_point_set_cb,
+									   g_strdup (udi));
+	}
+
+	g_list_free (roots);
+}
+
+static void
+set_up_mount_points (TrackerHal *hal)
+{
+	g_message ("Indexer is being notified to disable all volumes");
+	org_freedesktop_Tracker_Indexer_volume_disable_all_async (tracker_dbus_indexer_get_proxy (), 
+								  set_up_mount_points_cb,
+								  hal);
+}
+
+static void
 set_up_throttle (TrackerHal    *hal,
 		 TrackerConfig *config)
 {
@@ -663,9 +718,9 @@
 }
 
 static void
-notify_battery_in_use_cb (GObject *gobject,
+notify_battery_in_use_cb (GObject    *gobject,
 			  GParamSpec *arg1,
-			  gpointer user_data)
+			  gpointer    user_data)
 {
 	set_up_throttle (TRACKER_HAL (gobject),
 			 TRACKER_CONFIG (user_data));
@@ -803,22 +858,6 @@
 	config = tracker_config_new ();
 	language = tracker_language_new (config);
 
-#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);
-
-	set_up_throttle (hal, config);
-#endif /* HAVE_HAL */
-
 	/* Daemon command line arguments */
 	if (verbosity > -1) {
 		tracker_config_set_verbosity (config, verbosity);
@@ -896,6 +935,20 @@
 		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
 	 */
@@ -932,6 +985,16 @@
 	tracker_data_manager_init (config, language, file_index, email_index);
 	tracker_xesam_manager_init ();
 
+#ifdef HAVE_HAL
+	/* We set up the throttle and mount points here. For the mount
+	 * points, this means contacting the Indexer. This means that
+	 * 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 */
+
 	private->processor = tracker_processor_new (config, hal);
 
 	/* Make Tracker available for introspection */

Modified: trunk/src/trackerd/tracker-processor.c
==============================================================================
--- trunk/src/trackerd/tracker-processor.c	(original)
+++ trunk/src/trackerd/tracker-processor.c	Tue Nov 18 16:01:44 2008
@@ -337,11 +337,11 @@
 
 static void
 get_remote_roots (TrackerProcessor  *processor,
-		  GSList	   **mounted_directory_roots,
-		  GSList	   **removable_device_roots)
+		  GList	           **mounted_directory_roots,
+		  GList	           **removable_device_roots)
 {
-	GSList *l1;
-	GSList *l2;
+	GList *l1;
+	GList *l2;
 
 #ifdef HAVE_HAL
 	l1 = tracker_hal_get_mounted_directory_roots (processor->private->hal);
@@ -359,33 +359,33 @@
 	 * remove those which are removable device roots.
 	 */
 	if (l2) {
-		GSList *l;
-		GSList *list = NULL;
+		GList *l;
+		GList *list = NULL;
 
 		for (l = l1; l; l = l->next) {
-			if (g_slist_find_custom (l2, l->data, (GCompareFunc) strcmp)) {
+			if (g_list_find_custom (l2, l->data, (GCompareFunc) strcmp)) {
 				continue;
 			}
 
-			list = g_slist_prepend (list, l->data);
+			list = g_list_prepend (list, l->data);
 		}
 
-		*mounted_directory_roots = g_slist_reverse (list);
+		*mounted_directory_roots = g_list_reverse (list);
 	} else {
 		*mounted_directory_roots = NULL;
 	}
 
-	*removable_device_roots = g_slist_copy (l2);
+	*removable_device_roots = g_list_copy (l2);
 }
 
 static gboolean
 path_should_be_ignored_for_media (TrackerProcessor *processor,
 				  const gchar	   *path)
 {
-	GSList	 *roots = NULL;
-	GSList	 *mounted_directory_roots = NULL;
-	GSList	 *removable_device_roots = NULL;
-	GSList	 *l;
+	GList	 *roots = NULL;
+	GList	 *mounted_directory_roots = NULL;
+	GList	 *removable_device_roots = NULL;
+	GList	 *l;
 	gboolean  ignore_mounted_directories;
 	gboolean  ignore_removable_devices;
 	gboolean  ignore = FALSE;
@@ -402,11 +402,11 @@
 	}
 
 	if (ignore_mounted_directories) {
-		roots = g_slist_concat (roots, mounted_directory_roots);
+		roots = g_list_concat (roots, mounted_directory_roots);
 	}
 
 	if (ignore_removable_devices) {
-		roots = g_slist_concat (roots, removable_device_roots);
+		roots = g_list_concat (roots, removable_device_roots);
 	}
 
 	for (l = roots; l && !ignore; l = l->next) {
@@ -426,7 +426,7 @@
 		}
 	}
 
-	g_slist_free (roots);
+	g_list_free (roots);
 
 	return ignore;
 }
@@ -758,8 +758,8 @@
 process_module_files_add_removable_media (TrackerProcessor *processor)
 {
 	TrackerCrawler *crawler;
-	GSList	       *roots;
-	GSList	       *l;
+	GList	       *roots;
+	GList	       *l;
 	const gchar    *module_name = "files";
 
 	crawler = g_hash_table_lookup (processor->private->crawlers, module_name);
@@ -791,7 +791,7 @@
 		g_object_unref (file);
 	}
 
-	if (g_slist_length (roots) == 0) {
+	if (g_list_length (roots) == 0) {
 		g_message ("    NONE");
 	}
 
@@ -808,7 +808,7 @@
 		tracker_crawler_special_paths_add (crawler, l->data);
 	}
 
-	if (g_slist_length (roots) == 0) {
+	if (g_list_length (roots) == 0) {
 		g_message ("    NONE");
 	}
 }



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