summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDebarshi Ray <debarshir@freedesktop.org>2012-06-29 17:00:53 (GMT)
committerDebarshi Ray <debarshir@freedesktop.org>2012-08-28 17:35:24 (GMT)
commit649a5a1e59c0f29424b08e36af20bf9338c586c5 (patch)
tree52a74b58bf207df5ed5b435a4306d98a0f7223fd
parent72d7913032531e3c1094a06a3535a313309f4c7f (diff)
downloadtelepathy-logger-649a5a1e59c0f29424b08e36af20bf9338c586c5.tar.gz
telepathy-logger-649a5a1e59c0f29424b08e36af20bf9338c586c5.tar.xz
log-walker: Add get_events skeleton
Fixes: https://bugs.freedesktop.org/41772
-rw-r--r--telepathy-logger/log-walker.c143
-rw-r--r--telepathy-logger/log-walker.h11
2 files changed, 154 insertions, 0 deletions
diff --git a/telepathy-logger/log-walker.c b/telepathy-logger/log-walker.c
index a22b614..6bc4a58 100644
--- a/telepathy-logger/log-walker.c
+++ b/telepathy-logger/log-walker.c
@@ -48,6 +48,77 @@ struct _TplLogWalkerPriv
G_DEFINE_TYPE (TplLogWalker, tpl_log_walker, G_TYPE_OBJECT);
+typedef struct
+{
+ GAsyncReadyCallback cb;
+ gpointer user_data;
+ guint num_events;
+} TplLogWalkerAsyncData;
+
+
+static TplLogWalkerAsyncData *
+tpl_log_walker_async_data_new (void)
+{
+ return g_slice_new0 (TplLogWalkerAsyncData);
+}
+
+
+static void
+tpl_log_walker_async_data_free (TplLogWalkerAsyncData *data)
+{
+ g_slice_free (TplLogWalkerAsyncData, data);
+}
+
+
+static void
+tpl_log_walker_async_operation_cb (GObject *source_object,
+ GAsyncResult *result,
+ gpointer user_data)
+{
+ TplLogWalkerAsyncData *async_data = (TplLogWalkerAsyncData *) user_data;
+
+ if (async_data->cb)
+ async_data->cb (source_object, result, async_data->user_data);
+
+ tpl_log_walker_async_data_free (async_data);
+}
+
+
+static GList *
+tpl_log_walker_get_events (TplLogWalker *walker,
+ guint num_events,
+ GError **error)
+{
+ g_return_val_if_fail (TPL_IS_LOG_WALKER (walker), NULL);
+ return NULL;
+}
+
+
+static void
+tpl_log_walker_get_events_async_thread (GSimpleAsyncResult *simple,
+ GObject *object,
+ GCancellable *cancellable)
+{
+ GError *error = NULL;
+ GList *events;
+ TplLogWalkerAsyncData *async_data;
+
+ async_data = (TplLogWalkerAsyncData *) g_async_result_get_user_data (
+ G_ASYNC_RESULT (simple));
+
+ events = tpl_log_walker_get_events (TPL_LOG_WALKER (object),
+ async_data->num_events, &error);
+
+ if (error != NULL)
+ {
+ g_simple_async_result_set_from_error (simple, error);
+ g_error_free (error);
+ }
+
+ g_simple_async_result_set_op_res_gpointer (simple, events, NULL);
+}
+
+
static void
tpl_log_walker_dispose (GObject *object)
{
@@ -108,3 +179,75 @@ tpl_log_walker_add_iter (TplLogWalker *walker, TplLogIter *iter)
priv->iters = g_list_prepend (priv->iters, g_object_ref (iter));
}
+
+
+/**
+ * tpl_log_walker_get_events_async:
+ * @walker: a #TplLogWalker
+ * @num_events: number of maximum events to fetch
+ * @callback: (scope async) (allow-none): a callback to call when
+ * the request is satisfied
+ * @user_data: data to pass to @callback
+ *
+ * Walk the logs to retrieve the next most recent @num_event events.
+ */
+void
+tpl_log_walker_get_events_async (TplLogWalker *walker,
+ guint num_events,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ GSimpleAsyncResult *simple;
+ TplLogWalkerAsyncData *async_data;
+
+ g_return_if_fail (TPL_IS_LOG_WALKER (walker));
+
+ async_data = tpl_log_walker_async_data_new ();
+ async_data->cb = callback;
+ async_data->user_data = user_data;
+ async_data->num_events = num_events;
+
+ simple = g_simple_async_result_new (G_OBJECT (walker),
+ tpl_log_walker_async_operation_cb, async_data,
+ tpl_log_walker_get_events_async);
+
+ g_simple_async_result_run_in_thread (simple,
+ tpl_log_walker_get_events_async_thread, G_PRIORITY_DEFAULT,
+ NULL);
+
+ g_object_unref (simple);
+}
+
+
+/**
+ * tpl_log_walker_get_events_finish:
+ * @walker: a #TplLogWalker
+ * @result: a #GAsyncResult
+ * @events: (out) (transfer full) (element-type TelepathyLogger.Event):
+ * a pointer to a #GList used to return the list #TplEvent
+ * @error: a #GError to fill
+ *
+ * Returns: #TRUE if the operation was successful, otherwise #FALSE.
+ */
+gboolean
+tpl_log_walker_get_events_finish (TplLogWalker *walker,
+ GAsyncResult *result,
+ GList **events,
+ GError **error)
+{
+ GSimpleAsyncResult *simple;
+
+ g_return_val_if_fail (TPL_IS_LOG_WALKER (walker), FALSE);
+ g_return_val_if_fail (g_simple_async_result_is_valid (result,
+ G_OBJECT (walker), tpl_log_walker_get_events_async), FALSE);
+
+ simple = G_SIMPLE_ASYNC_RESULT (result);
+
+ if (g_simple_async_result_propagate_error (simple, error))
+ return FALSE;
+
+ if (events != NULL)
+ *events = (GList *) g_simple_async_result_get_op_res_gpointer (simple);
+
+ return TRUE;
+}
diff --git a/telepathy-logger/log-walker.h b/telepathy-logger/log-walker.h
index e10fdca..b26b5dd 100644
--- a/telepathy-logger/log-walker.h
+++ b/telepathy-logger/log-walker.h
@@ -22,6 +22,7 @@
#define __TPL_LOG_WALKER_H__
#include <glib-object.h>
+#include <gio/gio.h>
G_BEGIN_DECLS
@@ -64,6 +65,16 @@ struct _TplLogWalkerClass
GType tpl_log_walker_get_type (void) G_GNUC_CONST;
+void tpl_log_walker_get_events_async (TplLogWalker *walker,
+ guint num_events,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
+
+gboolean tpl_log_walker_get_events_finish (TplLogWalker *walker,
+ GAsyncResult *result,
+ GList **events,
+ GError **error);
+
G_END_DECLS
#endif /* __TPL_LOG_WALKER_H__ */