Fix: split ctf/event.c
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Mon, 12 Mar 2012 14:21:26 +0000 (10:21 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Mon, 12 Mar 2012 14:21:26 +0000 (10:21 -0400)
Ensure the implementation follows the API event.h/iterator.h split.

closes #161

Reported-by: Yannick Brosseau <yannick.brosseau@gmail.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
formats/ctf/Makefile.am
formats/ctf/events.c
formats/ctf/iterator.c [new file with mode: 0644]

index 497b35332e19924a4973d0c9f51bcdf7f29b26a8..d803b69a2205340ee490b28ee8501bac5e143ca0 100644 (file)
@@ -7,6 +7,7 @@ lib_LTLIBRARIES = libbabeltrace-ctf.la
 libbabeltrace_ctf_la_SOURCES = \
        ctf.c \
        events.c \
+       iterator.c \
        callbacks.c \
        events-private.h \
        memstream.h
index b35f54a8ecba9cee1f5000323b47b3c082462c7a..0e32d21e3542b72bee804c6eba37a39527e0c9ea 100644 (file)
  */
 __thread int bt_ctf_last_field_error = 0;
 
-struct bt_ctf_iter *bt_ctf_iter_create(struct bt_context *ctx,
-               struct bt_iter_pos *begin_pos,
-               struct bt_iter_pos *end_pos)
-{
-       struct bt_ctf_iter *iter;
-       int ret;
-
-       iter = g_new0(struct bt_ctf_iter, 1);
-       ret = bt_iter_init(&iter->parent, ctx, begin_pos, end_pos);
-       if (ret) {
-               g_free(iter);
-               return NULL;
-       }
-       iter->callbacks = g_array_new(0, 1, sizeof(struct bt_stream_callbacks));
-       iter->recalculate_dep_graph = 0;
-       iter->main_callbacks.callback = NULL;
-       iter->dep_gc = g_ptr_array_new();
-       return iter;
-}
-
-void bt_ctf_iter_destroy(struct bt_ctf_iter *iter)
-{
-       struct bt_stream_callbacks *bt_stream_cb;
-       struct bt_callback_chain *bt_chain;
-       int i, j;
-
-       /* free all events callbacks */
-       if (iter->main_callbacks.callback)
-               g_array_free(iter->main_callbacks.callback, TRUE);
-
-       /* free per-event callbacks */
-       for (i = 0; i < iter->callbacks->len; i++) {
-               bt_stream_cb = &g_array_index(iter->callbacks,
-                               struct bt_stream_callbacks, i);
-               if (!bt_stream_cb || !bt_stream_cb->per_id_callbacks)
-                       continue;
-               for (j = 0; j < bt_stream_cb->per_id_callbacks->len; j++) {
-                       bt_chain = &g_array_index(bt_stream_cb->per_id_callbacks,
-                                       struct bt_callback_chain, j);
-                       if (bt_chain->callback) {
-                               g_array_free(bt_chain->callback, TRUE);
-                       }
-               }
-               g_array_free(bt_stream_cb->per_id_callbacks, TRUE);
-       }
-
-       bt_iter_fini(&iter->parent);
-       g_free(iter);
-}
-
-struct bt_iter *bt_ctf_get_iter(struct bt_ctf_iter *iter)
-{
-       return &iter->parent;
-}
-
-struct bt_ctf_event *bt_ctf_iter_read_event(struct bt_ctf_iter *iter)
-{
-       struct ctf_file_stream *file_stream;
-       struct bt_ctf_event *ret = &iter->current_ctf_event;
-
-       file_stream = heap_maximum(iter->parent.stream_heap);
-       if (!file_stream) {
-               /* end of file for all streams */
-               goto stop;
-       }
-       ret->stream = &file_stream->parent;
-       ret->event = g_ptr_array_index(ret->stream->events_by_id,
-                       ret->stream->event_id);
-
-       if (ret->stream->stream_id > iter->callbacks->len)
-               goto end;
-
-       process_callbacks(iter, ret->stream);
-
-end:
-       return ret;
-stop:
-       return NULL;
-}
-
 struct definition *bt_ctf_get_top_level_scope(struct bt_ctf_event *event,
                enum bt_ctf_scope scope)
 {
diff --git a/formats/ctf/iterator.c b/formats/ctf/iterator.c
new file mode 100644 (file)
index 0000000..3413dbb
--- /dev/null
@@ -0,0 +1,112 @@
+/*
+ * ctf/iterator.c
+ *
+ * Babeltrace Library
+ *
+ * Copyright 2011-2012 EfficiOS Inc. and Linux Foundation
+ *
+ * Author: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+ *         Julien Desfossez <julien.desfossez@efficios.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ */
+
+#include <babeltrace/babeltrace.h>
+#include <babeltrace/format.h>
+#include <babeltrace/ctf/events.h>
+#include <babeltrace/ctf-ir/metadata.h>
+#include <babeltrace/prio_heap.h>
+#include <babeltrace/iterator-internal.h>
+#include <babeltrace/ctf/events-internal.h>
+#include <babeltrace/ctf/metadata.h>
+#include <glib.h>
+
+#include "events-private.h"
+
+struct bt_ctf_iter *bt_ctf_iter_create(struct bt_context *ctx,
+               struct bt_iter_pos *begin_pos,
+               struct bt_iter_pos *end_pos)
+{
+       struct bt_ctf_iter *iter;
+       int ret;
+
+       iter = g_new0(struct bt_ctf_iter, 1);
+       ret = bt_iter_init(&iter->parent, ctx, begin_pos, end_pos);
+       if (ret) {
+               g_free(iter);
+               return NULL;
+       }
+       iter->callbacks = g_array_new(0, 1, sizeof(struct bt_stream_callbacks));
+       iter->recalculate_dep_graph = 0;
+       iter->main_callbacks.callback = NULL;
+       iter->dep_gc = g_ptr_array_new();
+       return iter;
+}
+
+void bt_ctf_iter_destroy(struct bt_ctf_iter *iter)
+{
+       struct bt_stream_callbacks *bt_stream_cb;
+       struct bt_callback_chain *bt_chain;
+       int i, j;
+
+       /* free all events callbacks */
+       if (iter->main_callbacks.callback)
+               g_array_free(iter->main_callbacks.callback, TRUE);
+
+       /* free per-event callbacks */
+       for (i = 0; i < iter->callbacks->len; i++) {
+               bt_stream_cb = &g_array_index(iter->callbacks,
+                               struct bt_stream_callbacks, i);
+               if (!bt_stream_cb || !bt_stream_cb->per_id_callbacks)
+                       continue;
+               for (j = 0; j < bt_stream_cb->per_id_callbacks->len; j++) {
+                       bt_chain = &g_array_index(bt_stream_cb->per_id_callbacks,
+                                       struct bt_callback_chain, j);
+                       if (bt_chain->callback) {
+                               g_array_free(bt_chain->callback, TRUE);
+                       }
+               }
+               g_array_free(bt_stream_cb->per_id_callbacks, TRUE);
+       }
+
+       bt_iter_fini(&iter->parent);
+       g_free(iter);
+}
+
+struct bt_iter *bt_ctf_get_iter(struct bt_ctf_iter *iter)
+{
+       return &iter->parent;
+}
+
+struct bt_ctf_event *bt_ctf_iter_read_event(struct bt_ctf_iter *iter)
+{
+       struct ctf_file_stream *file_stream;
+       struct bt_ctf_event *ret = &iter->current_ctf_event;
+
+       file_stream = heap_maximum(iter->parent.stream_heap);
+       if (!file_stream) {
+               /* end of file for all streams */
+               goto stop;
+       }
+       ret->stream = &file_stream->parent;
+       ret->event = g_ptr_array_index(ret->stream->events_by_id,
+                       ret->stream->event_id);
+
+       if (ret->stream->stream_id > iter->callbacks->len)
+               goto end;
+
+       process_callbacks(iter, ret->stream);
+
+end:
+       return ret;
+stop:
+       return NULL;
+}
This page took 0.037403 seconds and 4 git commands to generate.