telepathy-logger: log-walker: Keep a list of (iter, count) tuples
Nicolas Dufresne
nicolasd at kemper.freedesktop.org
Tue Aug 28 13:01:06 PDT 2012
Module: telepathy-logger
Branch: master
Commit: 401e164871a9664de951f287d335bf58372ee4c4
URL: http://cgit.freedesktop.org/telepathy/telepathy-logger/commit/?id=401e164871a9664de951f287d335bf58372ee4c4
Author: Debarshi Ray <debarshir at freedesktop.org>
Date: Wed Jul 11 19:42:58 2012 +0200
log-walker: Keep a list of (iter, count) tuples
This represents the order in which events were handed over to the user
from each iterator. Lets say we have 10 events numbered from 0 to 9,
with 0 being the oldest and 9 the latest event, and we have 3
iterators Ia, Ib and Ic. If they were returned in batches of 5 as:
+-----+--------+
|event|iterator|
+-----+--------+
| 5 | Ia |
| 6 | Ib |
| 7 | Ia |
| 8 | Ia |
| 9 | Ic |
+ - - + - -- - +
| 0 | Ic |
| 1 | Ic |
| 2 | Ib |
| 3 | Ib |
| 4 | Ia |
+-----+--------+
Then the list would be:
(Ic, 2), (Ib, 2), (Ia, 2), (Ib, 1), (Ia, 2), (Ic, 1)
Fixes: https://bugs.freedesktop.org/41772
---
telepathy-logger/log-walker.c | 45 +++++++++++++++++++++++++++++++++++++++++
1 files changed, 45 insertions(+), 0 deletions(-)
diff --git a/telepathy-logger/log-walker.c b/telepathy-logger/log-walker.c
index 9abc2e0..d9cbf1b 100644
--- a/telepathy-logger/log-walker.c
+++ b/telepathy-logger/log-walker.c
@@ -44,6 +44,7 @@
struct _TplLogWalkerPriv
{
GList *caches;
+ GList *history;
GList *iters;
GMutex mutex;
gboolean is_begin;
@@ -63,6 +64,12 @@ typedef struct
guint num_events;
} TplLogWalkerAsyncData;
+typedef struct
+{
+ TplLogIter *iter;
+ guint count;
+} TplLogWalkerHistoryData;
+
static TplLogWalkerAsyncData *
tpl_log_walker_async_data_new (void)
@@ -78,6 +85,21 @@ tpl_log_walker_async_data_free (TplLogWalkerAsyncData *data)
}
+static TplLogWalkerHistoryData *
+tpl_log_walker_history_data_new (void)
+{
+ return g_slice_new0 (TplLogWalkerHistoryData);
+}
+
+
+static void
+tpl_log_walker_history_data_free (TplLogWalkerHistoryData *data)
+{
+ g_object_unref (data->iter);
+ g_slice_free (TplLogWalkerHistoryData, data);
+}
+
+
static void
tpl_log_walker_async_operation_cb (GObject *source_object,
GAsyncResult *result,
@@ -125,10 +147,12 @@ tpl_log_walker_get_events (TplLogWalker *walker,
GList *l;
GList **latest_cache;
GList *latest_event;
+ TplLogIter *latest_iter;
gint64 latest_timestamp;
latest_cache = NULL;
latest_event = NULL;
+ latest_iter = NULL;
latest_timestamp = 0;
for (k = priv->caches, l = priv->iters;
@@ -157,15 +181,32 @@ tpl_log_walker_get_events (TplLogWalker *walker,
{
latest_cache = cache;
latest_event = event;
+ latest_iter = iter;
latest_timestamp = timestamp;
}
}
if (latest_event != NULL)
{
+ GList *h;
+ TplLogWalkerHistoryData *data;
+
*latest_cache = g_list_remove_link (*latest_cache, latest_event);
events = g_list_prepend (events, latest_event->data);
i++;
+
+ h = priv->history;
+ if (h == NULL ||
+ ((TplLogWalkerHistoryData *) h->data)->iter != latest_iter)
+ {
+ data = tpl_log_walker_history_data_new ();
+ data->iter = g_object_ref (latest_iter);
+ priv->history = g_list_prepend (priv->history, data);
+ }
+ else
+ data = (TplLogWalkerHistoryData *) h->data;
+
+ data->count++;
}
else
priv->is_end = TRUE;
@@ -217,6 +258,10 @@ tpl_log_walker_dispose (GObject *object)
g_list_free_full (priv->caches, tpl_log_walker_caches_free_func);
priv->caches = NULL;
+ g_list_free_full (priv->history,
+ (GDestroyNotify) tpl_log_walker_history_data_free);
+ priv->history = NULL;
+
g_list_free_full (priv->iters, g_object_unref);
priv->iters = NULL;
More information about the telepathy-commits
mailing list