[tracker/writeback: 9/16] Pass the known list of rdf:types to the Writeback signal



commit 555a7048f748e955210403057a238f628bb52928
Author: Philip Van Hoof <philip codeminded be>
Date:   Tue Nov 17 11:31:17 2009 +0100

    Pass the known list of rdf:types to the Writeback signal

 data/dbus/tracker-resources.xml                    |    2 +-
 src/tracker-store/tracker-resources.c              |   10 ++--
 src/tracker-store/tracker-writeback.c              |   41 +++++++++++---------
 src/tracker-store/tracker-writeback.h              |    5 +-
 .../tracker-writeback-dispatcher.c                 |   16 +++++--
 5 files changed, 43 insertions(+), 31 deletions(-)
---
diff --git a/data/dbus/tracker-resources.xml b/data/dbus/tracker-resources.xml
index 39aa927..d5503a6 100644
--- a/data/dbus/tracker-resources.xml
+++ b/data/dbus/tracker-resources.xml
@@ -38,7 +38,7 @@
     </method>
 
    <signal name="Writeback">
-      <arg type="as" name="subjects" />
+      <arg type="a{sas}" name="subjects" />
    </signal>
 
   </interface>
diff --git a/src/tracker-store/tracker-resources.c b/src/tracker-store/tracker-resources.c
index 6636f22..b9d37f5 100644
--- a/src/tracker-store/tracker-resources.c
+++ b/src/tracker-store/tracker-resources.c
@@ -108,7 +108,7 @@ tracker_resources_class_init (TrackerResourcesClass *klass)
 			      G_SIGNAL_RUN_LAST,
 			      G_STRUCT_OFFSET (TrackerResourcesClass, writeback),
 			      NULL, NULL,
-			      tracker_marshal_VOID__BOXED,
+			      g_cclosure_marshal_VOID__BOXED,
 			      G_TYPE_NONE, 1,
 			      TRACKER_TYPE_STR_STRV_MAP);
 
@@ -366,7 +366,7 @@ on_statements_committed (gpointer user_data)
 {
 	TrackerResources *resources = user_data;
 	GPtrArray *events;
-	const gchar **writebacks;
+	GHashTable *writebacks;
 	TrackerResourcesPrivate *priv;
 
 	priv = TRACKER_RESOURCES_GET_PRIVATE (resources);
@@ -426,7 +426,7 @@ on_statements_committed (gpointer user_data)
 
 	if (writebacks) {
 		g_signal_emit (resources, signals[WRITEBACK], 0, writebacks);
-		g_free (writebacks);
+		g_hash_table_unref (writebacks);
 
 	}
 
@@ -456,7 +456,7 @@ on_statement_inserted (const gchar *graph,
 	}
 
 	/* For predicates it's always update here */
-	tracker_writeback_check (graph, subject, predicate, object);
+	tracker_writeback_check (graph, subject, predicate, object, rdf_types);
 }
 
 static void
@@ -474,7 +474,7 @@ on_statement_deleted (const gchar *graph,
 	}
 
 	/* For predicates it's always delete here */
-	tracker_writeback_check (graph, subject, predicate, object);
+	tracker_writeback_check (graph, subject, predicate, object, rdf_types);
 }
 
 void 
diff --git a/src/tracker-store/tracker-writeback.c b/src/tracker-store/tracker-writeback.c
index 5ad598b..5b19796 100644
--- a/src/tracker-store/tracker-writeback.c
+++ b/src/tracker-store/tracker-writeback.c
@@ -52,11 +52,27 @@ is_allowed (WritebackPrivate *private, const gchar *rdf_predicate)
 	return (g_hash_table_lookup (private->allowances, rdf_predicate) != NULL) ? TRUE : FALSE;
 }
 
+
+static GStrv
+copy_rdf_types (GPtrArray *rdf_types)
+{
+	GStrv new_types = g_new0 (gchar*, rdf_types->len + 1);
+	guint n;
+
+	for (n = 0; n < rdf_types->len; n++) {
+		new_types[n] = g_strdup (rdf_types->pdata[n]);
+	}
+
+	return new_types;
+}
+
+
 void 
 tracker_writeback_check (const gchar *graph,
                          const gchar *subject, 
                          const gchar *predicate,
-                         const gchar *object)
+                         const gchar *object,
+                         GPtrArray *rdf_types)
 {
 	WritebackPrivate *private;
 
@@ -72,13 +88,15 @@ tracker_writeback_check (const gchar *graph,
 	g_return_if_fail (private != NULL);
 
 	if (is_allowed (private, predicate)) {
+
 		if (!private->events) {
 			private->events = g_hash_table_new_full (g_str_hash, g_str_equal,
 			                                         (GDestroyNotify) g_free,
-			                                         NULL);
+			                                         (GDestroyNotify) g_strfreev);
 		}
+
 		g_hash_table_insert (private->events, g_strdup (subject),
-		                     GINT_TO_POINTER (TRUE));
+		                     copy_rdf_types (rdf_types));
 	}
 }
 
@@ -96,28 +114,15 @@ tracker_writeback_reset (void)
 	}
 }
 
-const gchar **
+GHashTable *
 tracker_writeback_get_pending (void)
 {
 	WritebackPrivate *private;
-	GHashTableIter iter;
-	gpointer key, value;
-	const gchar **writebacks = NULL;
-	guint i = 0;
 
 	private = g_static_private_get (&private_key);
 	g_return_val_if_fail (private != NULL, NULL);
 
-	if (private->events) {
-		writebacks = g_new0 (const gchar *, g_hash_table_size (private->events) + 1);
-		g_hash_table_iter_init (&iter, private->events);
-
-		while (g_hash_table_iter_next (&iter, &key, &value)) {
-			writebacks[i++] = (gchar *) key;
-		}
-	}
-
-	return writebacks;
+	return private->events ? g_hash_table_ref (private->events) : NULL;
 }
 
 static void
diff --git a/src/tracker-store/tracker-writeback.h b/src/tracker-store/tracker-writeback.h
index 6e7ac6f..31c2f00 100644
--- a/src/tracker-store/tracker-writeback.h
+++ b/src/tracker-store/tracker-writeback.h
@@ -35,8 +35,9 @@ void            tracker_writeback_shutdown    (void);
 void            tracker_writeback_check       (const gchar              *graph,
                                                const gchar              *subject,
                                                const gchar              *predicate,
-                                               const gchar              *object);
-const gchar **  tracker_writeback_get_pending (void);
+                                               const gchar              *object,
+                                               GPtrArray                *rdf_types);
+GHashTable*     tracker_writeback_get_pending (void);
 void            tracker_writeback_reset       (void);
 
 G_END_DECLS
diff --git a/src/tracker-writeback/tracker-writeback-dispatcher.c b/src/tracker-writeback/tracker-writeback-dispatcher.c
index 0c1cdf9..652ed81 100644
--- a/src/tracker-writeback/tracker-writeback-dispatcher.c
+++ b/src/tracker-writeback/tracker-writeback-dispatcher.c
@@ -51,7 +51,7 @@ typedef struct {
 static void tracker_writeback_dispatcher_finalize    (GObject                    *object);
 static void tracker_writeback_dispatcher_constructed (GObject                    *object);
 static void on_writeback_cb                          (DBusGProxy                 *proxy,
-                                                      const gchar *const         *subjects,
+                                                      GHashTable                 *subjects,
                                                       TrackerWritebackDispatcher *object);
 
 
@@ -200,7 +200,7 @@ tracker_writeback_dispatcher_init (TrackerWritebackDispatcher *dispatcher)
 	                                                     TRACKER_INTERFACE_RESOURCES);
 
 	dbus_g_proxy_add_signal (priv->dbus_data->tproxy, "Writeback",
-	                         G_TYPE_STRV,
+	                         TRACKER_TYPE_STR_STRV_MAP,
 	                         G_TYPE_INVALID);
 
 	dbus_g_proxy_connect_signal (priv->dbus_data->tproxy, "Writeback",
@@ -287,23 +287,29 @@ on_sparql_result_received (GPtrArray *result,
 
 static void
 on_writeback_cb (DBusGProxy                 *proxy,
-                 const gchar *const         *subjects,
+                 GHashTable                 *subjects,
                  TrackerWritebackDispatcher *object)
 {
 	TrackerWritebackDispatcherPrivate *priv;
 	QueryData *data;
 	guint n;
+	GHashTableIter iter;
+	gpointer key, value;
 
 	priv = TRACKER_WRITEBACK_DISPATCHER_GET_PRIVATE (object);
 
-	for (n = 0; subjects[n] != NULL; n++) {
+	g_hash_table_iter_init (&iter, subjects);
+
+	while (g_hash_table_iter_next (&iter, &key, &value)) {
+		const gchar *subject = key;
+		const GStrv rdf_types = value;
 		gchar *query;
 
 		query = g_strdup_printf ("SELECT ?url ?predicate ?object { "
 		                                "<%s> ?predicate ?object ; "
 		                                     "nie:isStoredAs ?url . "
 		                                "?predicate tracker:writeback true "
-		                         "}", subjects[n]);
+		                         "}", subject);
 
 		data = g_slice_new (QueryData);
 		data->dispatcher = object;



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