[tracker] tracker-store: Connect tracker-resources with tracker-events



commit 026540ec35eb3e98087a487624a7ba5fb5e9489c
Author: Philip Van Hoof <philip codeminded be>
Date:   Tue Aug 17 16:12:54 2010 +0200

    tracker-store: Connect tracker-resources with tracker-events
    
    Still left todo is the emit of the signal itself, of course

 src/tracker-store/tracker-events.c    |    8 +++
 src/tracker-store/tracker-events.h    |   53 +++++++++++-----------
 src/tracker-store/tracker-resources.c |   78 ++++++++++++++++++---------------
 3 files changed, 77 insertions(+), 62 deletions(-)
---
diff --git a/src/tracker-store/tracker-events.c b/src/tracker-store/tracker-events.c
index cb4bd31..c260e20 100644
--- a/src/tracker-store/tracker-events.c
+++ b/src/tracker-store/tracker-events.c
@@ -341,6 +341,14 @@ tracker_events_init (TrackerNotifyClassGetter callback)
 }
 
 void
+tracker_events_classes_iter (GHashTableIter *iter)
+{
+	g_return_if_fail (private != NULL);
+
+	g_hash_table_iter_init (iter, private->allowances);
+}
+
+void
 tracker_events_shutdown (void)
 {
 	if (private != NULL) {
diff --git a/src/tracker-store/tracker-events.h b/src/tracker-store/tracker-events.h
index 4eca381..49f2999 100644
--- a/src/tracker-store/tracker-events.h
+++ b/src/tracker-store/tracker-events.h
@@ -30,32 +30,33 @@ G_BEGIN_DECLS
 
 typedef GStrv (*TrackerNotifyClassGetter) (void);
 
-void       tracker_events_init        (TrackerNotifyClassGetter  callback);
-void       tracker_events_shutdown    (void);
-void       tracker_events_add_insert  (gint                      graph_id,
-                                       gint                      subject_id,
-                                       const gchar              *subject,
-                                       gint                      pred_id,
-                                       gint                      object_id,
-                                       const gchar              *object,
-                                       GPtrArray                *rdf_types);
-void       tracker_events_add_delete  (gint                      graph_id,
-                                       gint                      subject_id,
-                                       const gchar              *subject,
-                                       gint                      pred_id,
-                                       gint                      object_id,
-                                       const gchar              *object,
-                                       GPtrArray                *rdf_types);
-void       tracker_events_get_inserts (gint                      class_id,
-                                       GArray                   *subject_ids,
-                                       GArray                   *pred_ids,
-                                       GArray                   *object_ids);
-void       tracker_events_get_deletes (gint                      class_id,
-                                       GArray                   *subject_ids,
-                                       GArray                   *pred_ids,
-                                       GArray                   *object_ids);
-void       tracker_events_reset       (void);
-void       tracker_events_freeze      (void);
+void       tracker_events_init         (TrackerNotifyClassGetter  callback);
+void       tracker_events_shutdown     (void);
+void       tracker_events_add_insert   (gint                      graph_id,
+                                        gint                      subject_id,
+                                        const gchar              *subject,
+                                        gint                      pred_id,
+                                        gint                      object_id,
+                                        const gchar              *object,
+                                        GPtrArray                *rdf_types);
+void       tracker_events_add_delete   (gint                      graph_id,
+                                        gint                      subject_id,
+                                        const gchar              *subject,
+                                        gint                      pred_id,
+                                        gint                      object_id,
+                                        const gchar              *object,
+                                        GPtrArray                *rdf_types);
+void       tracker_events_get_inserts  (gint                      class_id,
+                                        GArray                   *subject_ids,
+                                        GArray                   *pred_ids,
+                                        GArray                   *object_ids);
+void       tracker_events_get_deletes  (gint                      class_id,
+                                        GArray                   *subject_ids,
+                                        GArray                   *pred_ids,
+                                        GArray                   *object_ids);
+void       tracker_events_classes_iter (GHashTableIter           *iter);
+void       tracker_events_reset        (void);
+void       tracker_events_freeze       (void);
 
 G_END_DECLS
 
diff --git a/src/tracker-store/tracker-resources.c b/src/tracker-store/tracker-resources.c
index a5f0461..0bd07c4 100644
--- a/src/tracker-store/tracker-resources.c
+++ b/src/tracker-store/tracker-resources.c
@@ -509,62 +509,68 @@ tracker_resources_batch_commit (TrackerResources         *self,
 	/* no longer needed */
 }
 
+static struct {
+	GArray *subject_ids;
+	GArray *pred_ids;
+	GArray *object_ids;
+} inserts_ids = { NULL, NULL, NULL };
+
+static struct {
+	GArray *subject_ids;
+	GArray *pred_ids;
+	GArray *object_ids;
+} deletes_ids = { NULL, NULL, NULL };
 
 static void
 on_statements_committed (gpointer user_data)
 {
 	TrackerResources *resources = user_data;
-	/* GArray *events; */
 	GHashTable *writebacks;
 	TrackerResourcesPrivate *priv;
+	GHashTableIter iter;
+	gpointer key, value;
 
 	priv = TRACKER_RESOURCES_GET_PRIVATE (resources);
 
-	/* Class signals feature *
-	events = tracker_events_get_pending ();
+	/* Class signal feature */
 
-	* Do not call tracker_events_reset before calling tracker_resource_class_emit_events
-	   as we're reusing the same strings without copies *
-
-	if (events) {
-		GSList *event_sources, *l;
-		guint i;
-		GHashTable *to_emit = NULL;
+	if (inserts_ids.subject_ids == NULL) {
+		inserts_ids.subject_ids = g_array_new (FALSE, FALSE, sizeof (gint));
+		inserts_ids.pred_ids = g_array_new (FALSE, FALSE, sizeof (gint));
+		inserts_ids.object_ids = g_array_new (FALSE, FALSE, sizeof (gint));
+	}
 
-		event_sources = priv->event_sources;
+	if (deletes_ids.subject_ids == NULL) {
+		deletes_ids.subject_ids = g_array_new (FALSE, FALSE, sizeof (gint));
+		deletes_ids.pred_ids = g_array_new (FALSE, FALSE, sizeof (gint));
+		deletes_ids.object_ids = g_array_new (FALSE, FALSE, sizeof (gint));
+	}
 
-		for (i = 0; i < events->len; i++) {
-			TrackerEvent *event;
+	tracker_events_classes_iter (&iter);
 
-			event = &g_array_index (events, TrackerEvent, i);
+	while (g_hash_table_iter_next (&iter, &key, &value)) {
+		TrackerClass *class = key;
 
-			for (l = event_sources; l; l = l->next) {
-				TrackerResourceClass *class_ = l->data;
-				if (g_strcmp0 (tracker_class_get_uri (event->class), tracker_resource_class_get_rdf_class (class_)) == 0) {
-					tracker_resource_class_add_event (class_, event->subject, event->predicate, event->type);
-					if (!to_emit) {
-						to_emit = g_hash_table_new (NULL, NULL);
-					}
-					g_hash_table_insert (to_emit, class_, class_);
-				}
-			}
-		}
+		g_array_set_size (deletes_ids.subject_ids, 0);
+		g_array_set_size (deletes_ids.pred_ids, 0);
+		g_array_set_size (deletes_ids.object_ids, 0);
 
-		if (to_emit) {
-			GHashTableIter iter;
-			gpointer key, value;
+		tracker_events_get_inserts (tracker_class_get_id (class),
+		                            deletes_ids.subject_ids,
+		                            deletes_ids.pred_ids,
+		                            deletes_ids.object_ids);
 
-			g_hash_table_iter_init (&iter, to_emit);
+		g_array_set_size (inserts_ids.subject_ids, 0);
+		g_array_set_size (inserts_ids.pred_ids, 0);
+		g_array_set_size (inserts_ids.object_ids, 0);
 
-			while (g_hash_table_iter_next (&iter, &key, &value)) {
-				TrackerResourceClass *class_ = key;
-				tracker_resource_class_emit_events (class_);
-			}
+		tracker_events_get_inserts (tracker_class_get_id (class),
+		                            inserts_ids.subject_ids,
+		                            inserts_ids.pred_ids,
+		                            inserts_ids.object_ids);
 
-			g_hash_table_destroy (to_emit);
-		}
+		/* TODO: Emit the signal with tracker_class_get_uri (class) */
 	}
-	*/
 
 	tracker_events_reset ();
 



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