[tracker/miner-fs-refactor: 85/127] libtracker-miner: Make filesystem properties registration global



commit 74d20884c870c2f54d93d3c01824b0994629c5d3
Author: Carlos Garnacho <carlos lanedo com>
Date:   Wed Oct 5 15:43:18 2011 +0200

    libtracker-miner: Make filesystem properties registration global
    
    This is so GDestroyNotify for set properties is available at the
    time of destructing a file node.

 src/libtracker-miner/tracker-file-notifier.c      |   27 +++++-------
 src/libtracker-miner/tracker-file-system.c        |   46 +++++++++++++--------
 src/libtracker-miner/tracker-file-system.h        |    3 +-
 tests/libtracker-miner/tracker-file-system-test.c |    6 +--
 4 files changed, 43 insertions(+), 39 deletions(-)
---
diff --git a/src/libtracker-miner/tracker-file-notifier.c b/src/libtracker-miner/tracker-file-notifier.c
index a60c104..787f884 100644
--- a/src/libtracker-miner/tracker-file-notifier.c
+++ b/src/libtracker-miner/tracker-file-notifier.c
@@ -1124,10 +1124,21 @@ tracker_file_notifier_class_init (TrackerFileNotifierClass *klass)
 
 	/* Initialize property quarks */
 	quark_property_crawled = g_quark_from_static_string ("tracker-property-crawled");
+	tracker_file_system_register_property (quark_property_crawled, NULL);
+
 	quark_property_queried = g_quark_from_static_string ("tracker-property-queried");
+	tracker_file_system_register_property (quark_property_queried, NULL);
+
 	quark_property_iri = g_quark_from_static_string ("tracker-property-iri");
+	tracker_file_system_register_property (quark_property_iri, g_free);
+
 	quark_property_store_mtime = g_quark_from_static_string ("tracker-property-store-mtime");
+	tracker_file_system_register_property (quark_property_store_mtime,
+	                                       g_free);
+
 	quark_property_filesystem_mtime = g_quark_from_static_string ("tracker-property-filesystem-mtime");
+	tracker_file_system_register_property (quark_property_filesystem_mtime,
+	                                       g_free);
 }
 
 static void
@@ -1154,22 +1165,6 @@ tracker_file_notifier_init (TrackerFileNotifier *notifier)
 	/* Initialize filesystem and register properties */
 	priv->file_system = tracker_file_system_new ();
 
-	/* booleans */
-	tracker_file_system_register_property (priv->file_system,
-					       quark_property_crawled, NULL);
-	tracker_file_system_register_property (priv->file_system,
-	                                       quark_property_queried, NULL);
-
-	/* strings */
-	tracker_file_system_register_property (priv->file_system,
-					       quark_property_iri, g_free);
-	tracker_file_system_register_property (priv->file_system,
-	                                       quark_property_store_mtime,
-	                                       g_free);
-	tracker_file_system_register_property (priv->file_system,
-	                                       quark_property_filesystem_mtime,
-	                                       g_free);
-
 	priv->timer = g_timer_new ();
 	priv->stopped = TRUE;
 
diff --git a/src/libtracker-miner/tracker-file-system.c b/src/libtracker-miner/tracker-file-system.c
index 529fa53..e5b8ebd 100644
--- a/src/libtracker-miner/tracker-file-system.c
+++ b/src/libtracker-miner/tracker-file-system.c
@@ -28,9 +28,10 @@ typedef struct _TrackerFileSystemPrivate TrackerFileSystemPrivate;
 typedef struct _FileNodeProperty FileNodeProperty;
 typedef struct _FileNodeData FileNodeData;
 
+static GHashTable *properties = NULL;
+
 struct _TrackerFileSystemPrivate {
 	GNode *file_tree;
-	GHashTable *properties;
 };
 
 struct _FileNodeProperty {
@@ -66,6 +67,8 @@ static void
 file_node_data_free (FileNodeData *data,
                      GNode        *node)
 {
+	guint i;
+
 	if (data->shallow) {
 		/* Shallow nodes own the reference to the file */
 		g_object_unref (data->file);
@@ -76,8 +79,23 @@ file_node_data_free (FileNodeData *data,
 	}
 
 	g_free (data->uri_suffix);
-	g_array_free (data->properties, TRUE);
 
+	for (i = 0; i < data->properties->len; i++) {
+		FileNodeProperty *property;
+		GDestroyNotify destroy_notify;
+
+		property = &g_array_index (data->properties,
+					   FileNodeProperty, i);
+
+		destroy_notify = g_hash_table_lookup (properties,
+						      GUINT_TO_POINTER (property->prop_quark));
+
+		if (destroy_notify) {
+			(destroy_notify) (property->value);
+		}
+	}
+
+	g_array_free (data->properties, TRUE);
 	g_slice_free (FileNodeData, data);
 }
 
@@ -554,28 +572,22 @@ tracker_file_system_traverse (TrackerFileSystem             *file_system,
 }
 
 void
-tracker_file_system_register_property (TrackerFileSystem *file_system,
-                                       GQuark             prop,
+tracker_file_system_register_property (GQuark             prop,
                                        GDestroyNotify     destroy_notify)
 {
-	TrackerFileSystemPrivate *priv;
-
-	g_return_if_fail (TRACKER_IS_FILE_SYSTEM (file_system));
 	g_return_if_fail (prop != 0);
 
-	priv = file_system->priv;
-
-	if (!priv->properties) {
-		priv->properties = g_hash_table_new (NULL, NULL);
+	if (!properties) {
+		properties = g_hash_table_new (NULL, NULL);
 	}
 
-	if (g_hash_table_lookup (priv->properties, GUINT_TO_POINTER (prop))) {
+	if (g_hash_table_lookup (properties, GUINT_TO_POINTER (prop))) {
 		g_warning ("FileSystem: property '%s' has been already registered",
 		           g_quark_to_string (prop));
 		return;
 	}
 
-	g_hash_table_insert (priv->properties,
+	g_hash_table_insert (properties,
 	                     GUINT_TO_POINTER (prop),
 	                     destroy_notify);
 }
@@ -615,8 +627,8 @@ tracker_file_system_set_property (TrackerFileSystem *file_system,
 
 	priv = file_system->priv;
 
-	if (!priv->properties ||
-	    !g_hash_table_lookup_extended (priv->properties,
+	if (!properties ||
+	    !g_hash_table_lookup_extended (properties,
 	                                   GUINT_TO_POINTER (prop),
 	                                   NULL, (gpointer *) &destroy_notify)) {
 		g_warning ("FileSystem: property '%s' is not registered",
@@ -708,8 +720,8 @@ tracker_file_system_unset_property (TrackerFileSystem *file_system,
 
 	priv = file_system->priv;
 
-	if (!priv->properties ||
-	    !g_hash_table_lookup_extended (priv->properties,
+	if (!properties ||
+	    !g_hash_table_lookup_extended (properties,
 	                                   GUINT_TO_POINTER (prop),
 	                                   NULL,
 	                                   (gpointer *) &destroy_notify)) {
diff --git a/src/libtracker-miner/tracker-file-system.h b/src/libtracker-miner/tracker-file-system.h
index d247d8c..a8b064a 100644
--- a/src/libtracker-miner/tracker-file-system.h
+++ b/src/libtracker-miner/tracker-file-system.h
@@ -72,8 +72,7 @@ void          tracker_file_system_traverse       (TrackerFileSystem
                                                   gpointer                       user_data);
 
 /* properties */
-void      tracker_file_system_register_property (TrackerFileSystem *file_system,
-                                                 GQuark             prop,
+void      tracker_file_system_register_property (GQuark             prop,
                                                  GDestroyNotify     destroy_notify);
 
 void      tracker_file_system_set_property   (TrackerFileSystem  *file_system,
diff --git a/tests/libtracker-miner/tracker-file-system-test.c b/tests/libtracker-miner/tracker-file-system-test.c
index 31b9ebd..3b22e03 100644
--- a/tests/libtracker-miner/tracker-file-system-test.c
+++ b/tests/libtracker-miner/tracker-file-system-test.c
@@ -189,12 +189,10 @@ test_file_system_properties (TestCommonContext *fixture,
 	GFile *file, *f;
 
 	property1_quark = g_quark_from_string ("file-system-test-property1");
-	tracker_file_system_register_property (fixture->file_system,
-					       property1_quark,
+	tracker_file_system_register_property (property1_quark,
 					       NULL);
 	property2_quark = g_quark_from_string ("file-system-test-property2");
-	tracker_file_system_register_property (fixture->file_system,
-					       property2_quark,
+	tracker_file_system_register_property (property2_quark,
 					       NULL);
 
 	f = g_file_new_for_uri ("file:///aaa/");



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