[tracker] libtracker-data, tracker-store: Fix Writeback support for new callback API



commit 2c88a726c76cbcf91c8441896beda00a22fb23b3
Author: Philip Van Hoof <philip codeminded be>
Date:   Fri Aug 13 16:09:06 2010 +0200

    libtracker-data, tracker-store: Fix Writeback support for new callback API

 src/libtracker-data/tracker-data-update.c |   15 ++++++---
 src/libtracker-data/tracker-data-update.h |    2 +
 src/tracker-store/tracker-resources.c     |   48 +++++++++++++++-------------
 src/tracker-store/tracker-writeback.c     |   29 +++++++++++------
 src/tracker-store/tracker-writeback.h     |   14 +++++---
 5 files changed, 64 insertions(+), 44 deletions(-)
---
diff --git a/src/libtracker-data/tracker-data-update.c b/src/libtracker-data/tracker-data-update.c
index d777ace..9b60d62 100644
--- a/src/libtracker-data/tracker-data-update.c
+++ b/src/libtracker-data/tracker-data-update.c
@@ -1078,9 +1078,10 @@ cache_create_service_decomposed (TrackerClass *cl,
 			TrackerStatementDelegate *delegate;
 
 			delegate = g_ptr_array_index (insert_callbacks, n);
-			delegate->callback (final_graph_id, resource_buffer->id,
+			delegate->callback (final_graph_id, resource_buffer->id, resource_buffer->subject,
 			                    tracker_property_get_id (tracker_ontologies_get_rdf_type ()),
 			                    class_id,
+			                    tracker_class_get_uri (cl),
 			                    resource_buffer->types,
 			                    delegate->user_data);
 		}
@@ -1690,9 +1691,10 @@ cache_delete_resource_type (TrackerClass *class,
 			TrackerStatementDelegate *delegate;
 
 			delegate = g_ptr_array_index (delete_callbacks, n);
-			delegate->callback (final_graph_id, resource_buffer->id,
+			delegate->callback (final_graph_id, resource_buffer->id, resource_buffer->subject,
 			                    tracker_property_get_id (tracker_ontologies_get_rdf_type ()),
 			                    tracker_class_get_id (class),
+			                    tracker_class_get_uri (class),
 			                    resource_buffer->types,
 			                    delegate->user_data);
 		}
@@ -1863,8 +1865,9 @@ tracker_data_delete_statement (const gchar  *graph,
 				TrackerStatementDelegate *delegate;
 
 				delegate = g_ptr_array_index (delete_callbacks, n);
-				delegate->callback (graph_id, subject_id,
+				delegate->callback (graph_id, subject_id, subject,
 				                    pred_id, object_id,
+				                    object,
 				                    resource_buffer->types,
 				                    delegate->user_data);
 			}
@@ -2065,8 +2068,9 @@ tracker_data_insert_statement_with_uri (const gchar            *graph,
 					TrackerStatementDelegate *delegate;
 
 					delegate = g_ptr_array_index (insert_callbacks, n);
-					delegate->callback (graph_id, resource_buffer->id,
+					delegate->callback (graph_id, resource_buffer->id, subject,
 					                    final_prop_id, object_id,
+					                    object,
 					                    resource_buffer->types,
 					                    delegate->user_data);
 				}
@@ -2143,8 +2147,9 @@ tracker_data_insert_statement_with_string (const gchar            *graph,
 			TrackerStatementDelegate *delegate;
 
 			delegate = g_ptr_array_index (insert_callbacks, n);
-			delegate->callback (graph_id, resource_buffer->id,
+			delegate->callback (graph_id, resource_buffer->id, subject,
 			                    pred_id, 0 /* Always a literal */,
+			                    object,
 			                    resource_buffer->types,
 			                    delegate->user_data);
 		}
diff --git a/src/libtracker-data/tracker-data-update.h b/src/libtracker-data/tracker-data-update.h
index 65b42b1..085155c 100644
--- a/src/libtracker-data/tracker-data-update.h
+++ b/src/libtracker-data/tracker-data-update.h
@@ -36,8 +36,10 @@ G_BEGIN_DECLS
 
 typedef void (*TrackerStatementCallback) (gint         graph_id,
                                           gint         subject_id,
+                                          const gchar *subject,
                                           gint         predicate_id,
                                           gint         object_id,
+                                          const gchar *object,
                                           GPtrArray   *rdf_types,
                                           gpointer     user_data);
 typedef void (*TrackerCommitCallback)    (gpointer     user_data);
diff --git a/src/tracker-store/tracker-resources.c b/src/tracker-store/tracker-resources.c
index f5cf00b..8052bce 100644
--- a/src/tracker-store/tracker-resources.c
+++ b/src/tracker-store/tracker-resources.c
@@ -600,39 +600,43 @@ on_statements_rolled_back (gpointer user_data)
 }
 
 static void
-on_statement_inserted (const gchar *graph,
+on_statement_inserted (gint         graph_id,
+                       gint         subject_id,
                        const gchar *subject,
-                       const gchar *predicate,
+                       gint         pred_id,
+                       gint         object_id,
                        const gchar *object,
                        GPtrArray   *rdf_types,
-                       gpointer user_data)
+                       gpointer     user_data)
 {
-	if (g_strcmp0 (predicate, RDF_PREFIX "type") == 0) {
-		tracker_events_insert (subject, predicate, object, rdf_types, TRACKER_DBUS_EVENTS_TYPE_ADD);
-	} else {
-		tracker_events_insert (subject, predicate, object, rdf_types, TRACKER_DBUS_EVENTS_TYPE_UPDATE);
-	}
+	//if (g_strcmp0 (predicate, RDF_PREFIX "type") == 0) {
+		//tracker_events_insert (subject, predicate, object, rdf_types, TRACKER_DBUS_EVENTS_TYPE_ADD);
+	//} else {
+		//tracker_events_insert (subject, predicate, object, rdf_types, TRACKER_DBUS_EVENTS_TYPE_UPDATE);
+	//}
 
 	/* For predicates it's always update here */
-	tracker_writeback_check (graph, subject, predicate, object, rdf_types);
+	tracker_writeback_check (graph_id, subject_id, subject, pred_id, object_id, object, rdf_types);
 }
 
 static void
-on_statement_deleted (const gchar *graph,
+on_statement_deleted (gint         graph_id,
+                      gint         subject_id,
                       const gchar *subject,
-                      const gchar *predicate,
+                      gint         pred_id,
+                      gint         object_id,
                       const gchar *object,
                       GPtrArray   *rdf_types,
-                      gpointer user_data)
+                      gpointer     user_data)
 {
-	if (g_strcmp0 (predicate, RDF_PREFIX "type") == 0) {
-		tracker_events_insert (subject, predicate, object, rdf_types, TRACKER_DBUS_EVENTS_TYPE_DELETE);
-	} else {
-		tracker_events_insert (subject, predicate, object, rdf_types, TRACKER_DBUS_EVENTS_TYPE_UPDATE);
-	}
+	//if (g_strcmp0 (predicate, RDF_PREFIX "type") == 0) {
+		//tracker_events_insert (subject, predicate, object, rdf_types, TRACKER_DBUS_EVENTS_TYPE_DELETE);
+	//} else {
+		//tracker_events_insert (subject, predicate, object, rdf_types, TRACKER_DBUS_EVENTS_TYPE_UPDATE);
+	//}
 
 	/* For predicates it's always delete here */
-	tracker_writeback_check (graph, subject, predicate, object, rdf_types);
+	tracker_writeback_check (graph_id, subject_id, subject, pred_id, object_id, object, rdf_types);
 }
 
 void
@@ -645,8 +649,8 @@ tracker_resources_prepare (TrackerResources *object,
 
 	free_event_sources (priv);
 
-//	tracker_data_add_insert_statement_callback (on_statement_inserted, object);
-//	tracker_data_add_delete_statement_callback (on_statement_deleted, object);
+	tracker_data_add_insert_statement_callback (on_statement_inserted, object);
+	tracker_data_add_delete_statement_callback (on_statement_deleted, object);
 	tracker_data_add_commit_statement_callback (on_statements_committed, object);
 	tracker_data_add_rollback_statement_callback (on_statements_rolled_back, object);
 
@@ -660,8 +664,8 @@ tracker_resources_finalize (GObject      *object)
 
 	priv = TRACKER_RESOURCES_GET_PRIVATE (object);
 
-//	tracker_data_remove_insert_statement_callback (on_statement_inserted, object);
-//	tracker_data_remove_delete_statement_callback (on_statement_deleted, object);
+	tracker_data_remove_insert_statement_callback (on_statement_inserted, object);
+	tracker_data_remove_delete_statement_callback (on_statement_deleted, object);
 	tracker_data_remove_commit_statement_callback (on_statements_committed, object);
 	tracker_data_remove_rollback_statement_callback (on_statements_rolled_back, object);
 
diff --git a/src/tracker-store/tracker-writeback.c b/src/tracker-store/tracker-writeback.c
index 62646b3..16a3c0b 100644
--- a/src/tracker-store/tracker-writeback.c
+++ b/src/tracker-store/tracker-writeback.c
@@ -49,9 +49,11 @@ copy_rdf_types (GPtrArray *rdf_types)
 }
 
 void
-tracker_writeback_check (const gchar *graph,
+tracker_writeback_check (gint         graph_id,
+                         gint         subject_id,
                          const gchar *subject,
-                         const gchar *predicate,
+                         gint         pred_id,
+                         gint         object_id,
                          const gchar *object,
                          GPtrArray   *rdf_types)
 {
@@ -60,14 +62,14 @@ tracker_writeback_check (const gchar *graph,
 	 * aren't coming from the miner)
 	 */
 
-	if (graph != NULL) {
+	if (graph_id != 0) {
 		/* g_debug ("Not doing writeback check, no graph"); */
 		return;
 	}
 
 	g_return_if_fail (private != NULL);
 
-	if (g_hash_table_lookup (private->allowances, predicate)) {
+	if (g_hash_table_lookup (private->allowances, GINT_TO_POINTER (pred_id))) {
 		if (!private->events) {
 			private->events = g_hash_table_new_full (g_str_hash, g_str_equal,
 			                                         (GDestroyNotify) g_free,
@@ -119,9 +121,9 @@ tracker_writeback_init (TrackerWritebackGetPredicatesFunc func)
 
 	private = g_new0 (WritebackPrivate, 1);
 
-	private->allowances = g_hash_table_new_full (g_str_hash,
-	                                             g_str_equal,
-	                                             (GDestroyNotify) g_free,
+	private->allowances = g_hash_table_new_full (g_direct_hash,
+	                                             g_direct_equal,
+	                                             NULL,
 	                                             NULL);
 
 	g_message ("Setting up predicates for writeback notification...");
@@ -139,11 +141,16 @@ tracker_writeback_init (TrackerWritebackGetPredicatesFunc func)
 	}
 
 	count = g_strv_length (predicates_to_signal);
+
 	for (i = 0; i < count; i++) {
-		g_message ("  Adding:'%s'", predicates_to_signal[i]);
-		g_hash_table_insert (private->allowances,
-		                     g_strdup (predicates_to_signal[i]),
-		                     GINT_TO_POINTER (TRUE));
+		TrackerProperty *predicate = tracker_ontologies_get_property_by_uri (predicates_to_signal[i]);
+		if (predicate) {
+			gint id = tracker_property_get_id (predicate);
+			g_message ("  Adding:'%s'", predicates_to_signal[i]);
+			g_hash_table_insert (private->allowances,
+			                     GINT_TO_POINTER (id),
+			                     GINT_TO_POINTER (TRUE));
+		}
 	}
 
 	g_strfreev (predicates_to_signal);
diff --git a/src/tracker-store/tracker-writeback.h b/src/tracker-store/tracker-writeback.h
index a9b456c..fb0df6c 100644
--- a/src/tracker-store/tracker-writeback.h
+++ b/src/tracker-store/tracker-writeback.h
@@ -29,13 +29,15 @@ G_BEGIN_DECLS
 
 typedef GStrv (*TrackerWritebackGetPredicatesFunc) (void);
 
-void        tracker_writeback_init        (TrackerWritebackGetPredicatesFunc  callback);
+void        tracker_writeback_init        (TrackerWritebackGetPredicatesFunc callback);
 void        tracker_writeback_shutdown    (void);
-void        tracker_writeback_check       (const gchar                       *graph,
-                                           const gchar                       *subject,
-                                           const gchar                       *predicate,
-                                           const gchar                       *object,
-                                           GPtrArray                         *rdf_types);
+void        tracker_writeback_check       (gint         graph_id,
+                                           gint         subject_id,
+                                           const gchar *subject,
+                                           gint         pred_id,
+                                           gint         object_id,
+                                           const gchar *object,
+                                           GPtrArray   *rdf_types);
 GHashTable* tracker_writeback_get_pending (void);
 void        tracker_writeback_reset       (void);
 



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