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



Author: mr
Date: Wed May 14 14:03:29 2008
New Revision: 1433
URL: http://svn.gnome.org/viewvc/tracker?rev=1433&view=rev

Log:
	* src/libtracker-common/tracker-config.c:
	* src/libtracker-common/tracker-language.[ch]:
	* src/trackerd/tracker-dbus-search.c:
	* src/trackerd/tracker-main.c:
	* src/trackerd/tracker-query-tree.c: Use a GObject for
	TrackerLanguage so we can keep reference counts on it. It is
	becoming increasingly used now.


Modified:
   branches/indexer-split/ChangeLog
   branches/indexer-split/src/libtracker-common/tracker-config.c
   branches/indexer-split/src/libtracker-common/tracker-language.c
   branches/indexer-split/src/libtracker-common/tracker-language.h
   branches/indexer-split/src/trackerd/tracker-dbus-search.c
   branches/indexer-split/src/trackerd/tracker-main.c
   branches/indexer-split/src/trackerd/tracker-query-tree.c

Modified: branches/indexer-split/src/libtracker-common/tracker-config.c
==============================================================================
--- branches/indexer-split/src/libtracker-common/tracker-config.c	(original)
+++ branches/indexer-split/src/libtracker-common/tracker-config.c	Wed May 14 14:03:29 2008
@@ -111,7 +111,7 @@
 #define DEFAULT_PADDING				 2	  /* 1->8 */
 #define DEFAULT_THREAD_STACK_SIZE		 0	  /* 0 is the default for the platform */
 
-typedef struct _ConfigLanguages	  ConfigLanguages;
+/*typedef struct _ConfigLanguages	  ConfigLanguages;*/
 typedef struct _TrackerConfigPriv TrackerConfigPriv;
 
 struct _TrackerConfigPriv {

Modified: branches/indexer-split/src/libtracker-common/tracker-language.c
==============================================================================
--- branches/indexer-split/src/libtracker-common/tracker-language.c	(original)
+++ branches/indexer-split/src/libtracker-common/tracker-language.c	Wed May 14 14:03:29 2008
@@ -30,15 +30,18 @@
 #include "tracker-log.h" 
 #include "tracker-language.h"
 
-typedef struct _Languages Languages;
+#define GET_PRIV(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), TRACKER_TYPE_LANGUAGE, TrackerLanguagePriv))
+
+typedef struct _TrackerLanguagePriv TrackerLanguagePriv;
+typedef struct _Languages           Languages;
+
+struct _TrackerLanguagePriv {
+	TrackerConfig *config;
 
-struct _TrackerLanguage {
 	GHashTable    *stop_words;
 
 	GMutex        *stemmer_mutex;
 	gpointer       stemmer;
-
-	TrackerConfig *config;
 };
 
 struct _Languages {
@@ -63,6 +66,151 @@
         { NULL, NULL },
 };
 
+/* GObject properties */
+enum {
+	PROP_0,
+
+	PROP_CONFIG,
+	PROP_STOP_WORDS
+};
+
+static void         language_finalize          (GObject       *object);
+static void         language_get_property      (GObject       *object,
+						guint          param_id,
+						GValue        *value,
+						GParamSpec    *pspec);
+static void         language_set_property      (GObject       *object,
+						guint          param_id,
+						const GValue  *value,
+						GParamSpec    *pspec);
+static const gchar *language_get_name_for_code (const gchar   *language_code);
+static void         language_notify_cb         (TrackerConfig *config,
+						GParamSpec    *param,
+						gpointer       user_data);
+
+G_DEFINE_TYPE (TrackerLanguage, tracker_language, G_TYPE_OBJECT);
+
+static void
+tracker_language_class_init (TrackerLanguageClass *klass)
+{
+	GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+	object_class->finalize	   = language_finalize;
+	object_class->get_property = language_get_property;
+	object_class->set_property = language_set_property;
+
+	g_object_class_install_property (object_class,
+					 PROP_CONFIG,
+					 g_param_spec_object ("config",
+							      "Config",
+							      "Config",
+							      tracker_config_get_type (),
+							      G_PARAM_READWRITE));
+
+	g_object_class_install_property (object_class,
+					 PROP_STOP_WORDS,
+					 g_param_spec_boxed ("stop-words",
+							     "Stop words",
+							     "Stop words",
+							     g_hash_table_get_type (),
+							     G_PARAM_READABLE));
+
+	g_type_class_add_private (object_class, sizeof (TrackerLanguagePriv));
+}
+
+static void
+tracker_language_init (TrackerLanguage *language)
+{
+	TrackerLanguagePriv *priv;
+	const gchar         *stem_language;
+
+	priv = GET_PRIV (language);
+
+	priv->stop_words = g_hash_table_new_full (g_str_hash,
+						  g_str_equal,
+						  g_free,
+						  NULL);
+
+	priv->stemmer_mutex = g_mutex_new ();
+
+	stem_language = language_get_name_for_code (NULL);
+	priv->stemmer = sb_stemmer_new (stem_language, NULL);
+}
+
+static void
+language_finalize (GObject *object)
+{
+	TrackerLanguagePriv *priv;
+
+	priv = GET_PRIV (object);
+
+	if (priv->config) {
+		g_signal_handlers_disconnect_by_func (priv->config,
+						      language_notify_cb,
+						      TRACKER_LANGUAGE (object));
+		g_object_unref (priv->config);
+	}
+
+	if (priv->stemmer) {
+		g_mutex_lock (priv->stemmer_mutex);
+		sb_stemmer_delete (priv->stemmer);
+		g_mutex_unlock (priv->stemmer_mutex);
+	}
+
+	g_mutex_free (priv->stemmer_mutex);
+
+	if (priv->stop_words) {
+		g_hash_table_unref (priv->stop_words);
+	}
+
+	(G_OBJECT_CLASS (tracker_language_parent_class)->finalize) (object);
+}
+
+static void
+language_get_property (GObject	  *object,
+		       guint	   param_id,
+		       GValue	  *value,
+		       GParamSpec *pspec)
+{
+	TrackerLanguagePriv *priv;
+
+	priv = GET_PRIV (object);
+
+	switch (param_id) {
+	case PROP_CONFIG:
+		g_value_set_object (value, priv->config);
+		break;
+	case PROP_STOP_WORDS:
+		g_value_set_boxed (value, priv->stop_words);
+		break;
+
+	default:
+		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
+		break;
+	};
+}
+
+static void
+language_set_property (GObject	    *object,
+		       guint	     param_id,
+		       const GValue *value,
+		       GParamSpec   *pspec)
+{
+	TrackerLanguagePriv *priv;
+
+	priv = GET_PRIV (object);
+
+	switch (param_id) {
+	case PROP_CONFIG:
+		tracker_language_set_config (TRACKER_LANGUAGE (object),
+					     g_value_get_object (value));
+		break;
+	default:
+		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
+		break;
+	};
+}
+
 static gchar *
 language_get_stopword_filename (const gchar *language_code)
 {
@@ -103,10 +251,13 @@
 language_add_stopwords (TrackerLanguage *language,
 			const gchar     *filename)
 {
-	GMappedFile  *mapped_file;
-	GError       *error = NULL;
-	gchar        *content;
-	gchar       **words, **p;
+	TrackerLanguagePriv  *priv;
+	GMappedFile          *mapped_file;
+	GError               *error = NULL;
+	gchar                *content;
+	gchar               **words, **p;
+
+	priv = GET_PRIV (language);
 
 	mapped_file = g_mapped_file_new (filename, FALSE, &error);
 	if (error) {
@@ -123,7 +274,7 @@
 
 	/* FIXME: Shouldn't clear the hash table first? */
 	for (p = words; *p; p++) {
-		g_hash_table_insert (language->stop_words,
+		g_hash_table_insert (priv->stop_words,
 				     g_strdup (g_strstrip (*p)),
 				     GINT_TO_POINTER (1));
 	}
@@ -135,10 +286,13 @@
 language_set_stopword_list (TrackerLanguage *language,
 			    const gchar     *language_code)
 {
-	gchar       *stopword_filename;
-	const gchar *stem_language;
+	TrackerLanguagePriv *priv;
+	gchar               *stopword_filename;
+	const gchar         *stem_language;
 
-	g_return_if_fail (language != NULL);
+	g_return_if_fail (TRACKER_IS_LANGUAGE (language));
+
+	priv = GET_PRIV (language);
 
 	/* Set up stopwords list */
 	tracker_log ("Setting up stopword list for language code:'%s'", language_code);
@@ -157,19 +311,19 @@
 
 	stem_language = language_get_name_for_code (language_code);
 
-	g_mutex_lock (language->stemmer_mutex);
+	g_mutex_lock (priv->stemmer_mutex);
 
-	if (language->stemmer) {
-		sb_stemmer_delete (language->stemmer);
+	if (priv->stemmer) {
+		sb_stemmer_delete (priv->stemmer);
 	}
 
-	language->stemmer = sb_stemmer_new (stem_language, NULL);
-	if (!language->stemmer) {
+	priv->stemmer = sb_stemmer_new (stem_language, NULL);
+	if (!priv->stemmer) {
 		tracker_log ("No stemmer could be found for language:'%s'",
 			     stem_language);
 	}
 
-	g_mutex_unlock (language->stemmer_mutex);
+	g_mutex_unlock (priv->stemmer_mutex);
 }
 
 static void
@@ -188,55 +342,95 @@
 TrackerLanguage *
 tracker_language_new (TrackerConfig *config)
 {
-	TrackerLanguage *language;
-	const gchar     *stem_language;
-
 	g_return_val_if_fail (TRACKER_IS_CONFIG (config), NULL);
 
-	language = g_new0 (TrackerLanguage, 1);
+	return g_object_new (TRACKER_TYPE_LANGUAGE,
+			     "config", config,
+			     NULL);
+}
 
-	language->stop_words = g_hash_table_new_full (g_str_hash,
-						      g_str_equal,
-						      g_free,
-						      NULL);
+TrackerConfig *
+tracker_language_get_config (TrackerLanguage *language)
+{
+	TrackerLanguagePriv *priv;
 
-	language->stemmer_mutex = g_mutex_new ();
+	g_return_val_if_fail (TRACKER_IS_LANGUAGE (language), NULL);
 
-	stem_language = language_get_name_for_code (NULL);
-	language->stemmer = sb_stemmer_new (stem_language, NULL);
+	priv = GET_PRIV (language);
+
+	return priv->config;
+}
 
-	language->config = g_object_ref (config);
+GHashTable *
+tracker_language_get_stop_words (TrackerLanguage *language)
+{
+	TrackerLanguagePriv *priv;
+
+	g_return_val_if_fail (TRACKER_IS_LANGUAGE (language), NULL);
 
-	g_signal_connect (language->config, "notify::language",
-			  G_CALLBACK (language_notify_cb),
-			  language);
+	priv = GET_PRIV (language);
 
-	return language;
+	return priv->stop_words;
 }
 
 void
-tracker_language_free (TrackerLanguage *language)
+tracker_language_set_config (TrackerLanguage *language,
+			     TrackerConfig   *config)
 {
-	if (!language) {
-		return;
+	TrackerLanguagePriv *priv;
+
+	g_return_if_fail (TRACKER_IS_LANGUAGE (language));
+	g_return_if_fail (TRACKER_IS_CONFIG (config));
+
+	priv = GET_PRIV (language);
+
+	if (config) {
+		g_object_ref (config);
 	}
 
-	g_signal_handlers_disconnect_by_func (language->config,
-					      language_notify_cb,
-					      language);
-	g_object_unref (language->config);
+	if (priv->config) {
+		g_signal_handlers_disconnect_by_func (priv->config,
+						      G_CALLBACK (language_notify_cb),
+						      language);
+		g_object_unref (priv->config);
+	}
+
+	priv->config = config;
 
-	if (language->stemmer) {
-		g_mutex_lock (language->stemmer_mutex);
-		sb_stemmer_delete (language->stemmer);
-		g_mutex_unlock (language->stemmer_mutex);
+	if (priv->config) {
+		g_signal_connect (priv->config, "notify::language",
+				  G_CALLBACK (language_notify_cb),
+				  language);
 	}
 
-	g_mutex_free (language->stemmer_mutex);
+	g_object_notify (G_OBJECT (language), "config");
+}
+
+gchar *
+tracker_language_stem_word (TrackerLanguage *language,
+			    const gchar     *word,
+			    gint             word_length)
+{
+	TrackerLanguagePriv *priv;
+	const gchar         *stem_word;
 
-	g_hash_table_destroy (language->stop_words);
+	g_return_val_if_fail (TRACKER_IS_LANGUAGE (language), NULL);
 
-	g_free (language);
+	priv = GET_PRIV (language);
+
+	if (!tracker_config_get_enable_stemmer (priv->config)) {
+		return NULL;
+	}
+
+	g_mutex_lock (priv->stemmer_mutex);
+	
+	stem_word = (const gchar*) sb_stemmer_stem (priv->stemmer,
+						    (guchar*) word,
+						    word_length);
+
+	g_mutex_unlock (priv->stemmer_mutex);
+
+	return g_strdup (stem_word);
 }
 
 gboolean
@@ -287,29 +481,3 @@
 
 	return g_strdup ("en");
 }
-
-gchar *
-tracker_language_stem_word (TrackerLanguage *language,
-			    const gchar     *word,
-			    gint             word_length)
-{
-	const gchar *stem_word;
-
-	g_return_val_if_fail (language != NULL, NULL);
-
-	if (!tracker_config_get_enable_stemmer (language->config)) {
-		return NULL;
-	}
-
-	g_mutex_lock (language->stemmer_mutex);
-	if (!language->stemmer) {
-
-	}
-
-	stem_word = (const gchar *) sb_stemmer_stem (language->stemmer,
-						     (guchar*) word,
-						     word_length);
-	g_mutex_unlock (language->stemmer_mutex);
-
-	return g_strdup (stem_word);
-}

Modified: branches/indexer-split/src/libtracker-common/tracker-language.h
==============================================================================
--- branches/indexer-split/src/libtracker-common/tracker-language.h	(original)
+++ branches/indexer-split/src/libtracker-common/tracker-language.h	Wed May 14 14:03:29 2008
@@ -22,21 +22,45 @@
 #ifndef __LIBTRACKER_COMMON_LANGUAGE_H__
 #define __LIBTRACKER_COMMON_LANGUAGE_H__
 
+#include <glib-object.h>
+
 #include "tracker-config.h"
 
 G_BEGIN_DECLS
 
-typedef struct _TrackerLanguage TrackerLanguage;
-
-TrackerLanguage *tracker_language_new              (TrackerConfig   *config);
-void             tracker_language_free             (TrackerLanguage *language);
-
-gboolean         tracker_language_check_exists     (const gchar     *language_code);
-gchar *          tracker_language_get_default_code (void);
+#define TRACKER_TYPE_LANGUAGE         (tracker_language_get_type ())
+#define TRACKER_LANGUAGE(o)           (G_TYPE_CHECK_INSTANCE_CAST ((o), TRACKER_TYPE_LANGUAGE, TrackerLanguage))
+#define TRACKER_LANGUAGE_CLASS(k)     (G_TYPE_CHECK_CLASS_CAST ((k), TRACKER_TYPE_LANGUAGE, TrackerLanguageClass))
+#define TRACKER_IS_LANGUAGE(o)        (G_TYPE_CHECK_INSTANCE_TYPE ((o), TRACKER_TYPE_LANGUAGE))
+#define TRACKER_IS_LANGUAGE_CLASS(k)  (G_TYPE_CHECK_CLASS_TYPE ((k), TRACKER_TYPE_LANGUAGE))
+#define TRACKER_LANGUAGE_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), TRACKER_TYPE_LANGUAGE, TrackerLanguageClass))
+
+typedef struct _TrackerLanguage      TrackerLanguage;
+typedef struct _TrackerLanguageClass TrackerLanguageClass;
+
+struct _TrackerLanguage {
+	GObject      parent;
+};
+
+struct _TrackerLanguageClass {
+	GObjectClass parent_class;
+};
+
+GType            tracker_language_get_type         (void) G_GNUC_CONST;
+
+TrackerLanguage *tracker_language_new              (TrackerConfig   *language);
+TrackerConfig *  tracker_language_get_config       (TrackerLanguage *language);
+GHashTable *     tracker_language_get_stop_words   (TrackerLanguage *language);
+void             tracker_language_set_config       (TrackerLanguage *language,
+						    TrackerConfig   *config);
 gchar *          tracker_language_stem_word        (TrackerLanguage *language,
 						    const gchar     *word,
 						    gint             word_length);
 
+/* Utility functions */
+gboolean         tracker_language_check_exists     (const gchar     *language_code);
+gchar *          tracker_language_get_default_code (void);
+
 G_END_DECLS
 
 #endif /* __LIBTRACKER_COMMON_LANGUAGE_H__ */

Modified: branches/indexer-split/src/trackerd/tracker-dbus-search.c
==============================================================================
--- branches/indexer-split/src/trackerd/tracker-dbus-search.c	(original)
+++ branches/indexer-split/src/trackerd/tracker-dbus-search.c	Wed May 14 14:03:29 2008
@@ -92,10 +92,11 @@
 							      G_PARAM_WRITABLE));
 	g_object_class_install_property (object_class,
 					 PROP_LANGUAGE,
-					 g_param_spec_pointer ("language",
-							       "Language",
-							       "Language",
-							       G_PARAM_WRITABLE));
+					 g_param_spec_object ("language",
+							      "Language",
+							      "Language",
+							      tracker_language_get_type (),
+							      G_PARAM_WRITABLE));
 	g_object_class_install_property (object_class,
 					 PROP_FILE_INDEX,
 					 g_param_spec_pointer ("file-index",
@@ -152,7 +153,7 @@
 		break;
 	case PROP_LANGUAGE:
 		tracker_dbus_search_set_language (TRACKER_DBUS_SEARCH (object),
-						  g_value_get_pointer (value));
+						  g_value_get_object (value));
 		break;
 	case PROP_FILE_INDEX:
 		tracker_dbus_search_set_file_index (TRACKER_DBUS_SEARCH (object),
@@ -231,6 +232,14 @@
 
 	priv = GET_PRIV (object);
 
+	if (language) {
+		g_object_ref (language);
+	}
+
+	if (priv->language) {
+		g_object_unref (priv->language);
+	}
+
 	priv->language = language;
 	
 	g_object_notify (G_OBJECT (object), "language");

Modified: branches/indexer-split/src/trackerd/tracker-main.c
==============================================================================
--- branches/indexer-split/src/trackerd/tracker-main.c	(original)
+++ branches/indexer-split/src/trackerd/tracker-main.c	Wed May 14 14:03:29 2008
@@ -1044,7 +1044,9 @@
 	tracker_nfs_lock_term ();
 	tracker_log_term ();
 
-	tracker_language_free (tracker->language);
+	if (tracker->language) {
+		g_object_unref (tracker->language);
+	}
 
         if (tracker->config) {
                 g_object_unref (tracker->config);

Modified: branches/indexer-split/src/trackerd/tracker-query-tree.c
==============================================================================
--- branches/indexer-split/src/trackerd/tracker-query-tree.c	(original)
+++ branches/indexer-split/src/trackerd/tracker-query-tree.c	Wed May 14 14:03:29 2008
@@ -138,10 +138,11 @@
                                                               G_PARAM_READWRITE));
 	g_object_class_install_property (object_class,
 					 PROP_LANGUAGE,
-					 g_param_spec_pointer ("language",
-							       "Language",
-							       "Language",
-							       G_PARAM_READWRITE));
+					 g_param_spec_object ("language",
+                                                              "Language",
+                                                              "Language",
+                                                              tracker_language_get_type (),
+                                                              G_PARAM_READWRITE));
 	g_object_class_install_property (object_class,
 					 PROP_SERVICES,
 					 g_param_spec_pointer ("services",
@@ -230,7 +231,7 @@
 		break;
 	case PROP_LANGUAGE:
 		tracker_query_tree_set_language (TRACKER_QUERY_TREE (object),
-						 g_value_get_pointer (value));
+						 g_value_get_object (value));
 		break;
 	case PROP_SERVICES:
 		tracker_query_tree_set_services (TRACKER_QUERY_TREE (object),
@@ -262,7 +263,7 @@
 		g_value_set_object (value, priv->config);
 		break;
 	case PROP_LANGUAGE:
-		g_value_set_pointer (value, priv->language);
+		g_value_set_object (value, priv->language);
 		break;
 	case PROP_SERVICES:
 		g_value_set_pointer (value, priv->services);
@@ -550,6 +551,15 @@
 	g_return_if_fail (language != NULL);
 
 	priv = TRACKER_QUERY_TREE_GET_PRIVATE (tree);
+
+	if (language) {
+		g_object_ref (language);
+	}
+
+	if (priv->language) {
+		g_object_unref (priv->language);
+	}
+
 	priv->language = language;
 
 	g_object_notify (G_OBJECT (tree), "language");



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