[tracker/writeback] Compress the Writeback signal to mention subjects only once
- From: Philip Van Hoof <pvanhoof src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [tracker/writeback] Compress the Writeback signal to mention subjects only once
- Date: Mon, 9 Nov 2009 10:02:25 +0000 (UTC)
commit 85ac48f8727dc3651b239afafa0131d1680f4859
Author: Philip Van Hoof <philip codeminded be>
Date: Mon Nov 9 11:00:42 2009 +0100
Compress the Writeback signal to mention subjects only once
src/tracker-store/tracker-resources.c | 17 ++++-----------
src/tracker-store/tracker-writeback.c | 34 +++++++++++++++++++++-----------
src/tracker-store/tracker-writeback.h | 16 +++++++-------
3 files changed, 35 insertions(+), 32 deletions(-)
---
diff --git a/src/tracker-store/tracker-resources.c b/src/tracker-store/tracker-resources.c
index e5f2cf7..90bf674 100644
--- a/src/tracker-store/tracker-resources.c
+++ b/src/tracker-store/tracker-resources.c
@@ -366,6 +366,7 @@ on_statements_committed (gpointer user_data)
{
TrackerResources *resources = user_data;
GPtrArray *events;
+ gchar * const *writebacks;
TrackerResourcesPrivate *priv;
priv = TRACKER_RESOURCES_GET_PRIVATE (resources);
@@ -421,19 +422,11 @@ on_statements_committed (gpointer user_data)
tracker_events_reset ();
/* Writeback feature */
- events = tracker_writeback_get_pending ();
+ writebacks = tracker_writeback_get_pending ();
- if (events) {
- guint t;
-
- GStrv events_strv = g_new0 (gchar *, events->len + 1);
-
- for (t = 0; t < events->len; t++)
- events_strv[t] = events->pdata[t];
-
- g_signal_emit (resources, signals[WRITEBACK], 0, events_strv);
-
- g_free (events_strv);
+ if (writebacks) {
+ g_signal_emit (resources, signals[WRITEBACK], 0, writebacks);
+ g_free (writebacks);
}
diff --git a/src/tracker-store/tracker-writeback.c b/src/tracker-store/tracker-writeback.c
index dcbae14..3640a76 100644
--- a/src/tracker-store/tracker-writeback.c
+++ b/src/tracker-store/tracker-writeback.c
@@ -29,7 +29,7 @@
typedef struct {
GHashTable *allowances;
- GPtrArray *events;
+ GHashTable *events;
} WritebackPrivate;
static GStaticPrivate private_key = G_STATIC_PRIVATE_INIT;
@@ -64,9 +64,13 @@ tracker_writeback_check (const gchar *graph,
g_return_if_fail (private != NULL);
if (is_allowed (private, predicate)) {
- if (!private->events)
- private->events = g_ptr_array_new ();
- g_ptr_array_add (private->events, g_strdup (subject));
+ if (!private->events) {
+ private->events = g_hash_table_new_full (g_str_hash, g_str_equal,
+ (GDestroyNotify) g_free,
+ NULL);
+ }
+ g_hash_table_insert (private->events, g_strdup (subject),
+ GINT_TO_POINTER (TRUE));
}
}
@@ -74,30 +78,36 @@ void
tracker_writeback_reset (void)
{
WritebackPrivate *private;
- guint i;
private = g_static_private_get (&private_key);
g_return_if_fail (private != NULL);
if (private->events) {
- for (i = 0; i < private->events->len; i++) {
- g_free (private->events->pdata[i]);
- }
- g_ptr_array_free (private->events, TRUE);
-
+ g_hash_table_unref (private->events);
private->events = NULL;
}
}
-GPtrArray *
+gchar * const *
tracker_writeback_get_pending (void)
{
WritebackPrivate *private;
+ GHashTableIter iter;
+ gpointer key, value;
+ gchar **writebacks;
+ guint i = 0;
private = g_static_private_get (&private_key);
g_return_val_if_fail (private != NULL, NULL);
- return private->events;
+ writebacks = g_new0 (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 (gchar * const *) writebacks;
}
static void
diff --git a/src/tracker-store/tracker-writeback.h b/src/tracker-store/tracker-writeback.h
index 4934f06..05faa94 100644
--- a/src/tracker-store/tracker-writeback.h
+++ b/src/tracker-store/tracker-writeback.h
@@ -30,14 +30,14 @@ G_BEGIN_DECLS
typedef GStrv (*TrackerWritebackPredicateGetter) (void);
-void tracker_writeback_init (TrackerWritebackPredicateGetter callback);
-void tracker_writeback_shutdown (void);
-void tracker_writeback_check (const gchar *graph,
- const gchar *subject,
- const gchar *predicate,
- const gchar *object);
-GPtrArray *tracker_writeback_get_pending (void);
-void tracker_writeback_reset (void);
+void tracker_writeback_init (TrackerWritebackPredicateGetter callback);
+void tracker_writeback_shutdown (void);
+void tracker_writeback_check (const gchar *graph,
+ const gchar *subject,
+ const gchar *predicate,
+ const gchar *object);
+gchar * const * tracker_writeback_get_pending (void);
+void tracker_writeback_reset (void);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]