Cleanup: update ifdef wrapper name
[babeltrace.git] / formats / ctf / iterator.c
CommitLineData
a7765dd4
MD
1/*
2 * ctf/iterator.c
3 *
4 * Babeltrace Library
5 *
6 * Copyright 2011-2012 EfficiOS Inc. and Linux Foundation
7 *
8 * Author: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
9 * Julien Desfossez <julien.desfossez@efficios.com>
10 *
11 * Permission is hereby granted, free of charge, to any person obtaining a copy
12 * of this software and associated documentation files (the "Software"), to deal
13 * in the Software without restriction, including without limitation the rights
14 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 * copies of the Software, and to permit persons to whom the Software is
16 * furnished to do so, subject to the following conditions:
17 *
18 * The above copyright notice and this permission notice shall be included in
19 * all copies or substantial portions of the Software.
20 */
21
22#include <babeltrace/babeltrace.h>
23#include <babeltrace/format.h>
24#include <babeltrace/ctf/events.h>
25#include <babeltrace/ctf-ir/metadata.h>
26#include <babeltrace/prio_heap.h>
27#include <babeltrace/iterator-internal.h>
28#include <babeltrace/ctf/events-internal.h>
29#include <babeltrace/ctf/metadata.h>
30#include <glib.h>
31
32#include "events-private.h"
33
34struct bt_ctf_iter *bt_ctf_iter_create(struct bt_context *ctx,
04ae3991
MD
35 const struct bt_iter_pos *begin_pos,
36 const struct bt_iter_pos *end_pos)
a7765dd4
MD
37{
38 struct bt_ctf_iter *iter;
39 int ret;
40
7f89ddce
MD
41 if (!ctx)
42 return NULL;
43
a7765dd4
MD
44 iter = g_new0(struct bt_ctf_iter, 1);
45 ret = bt_iter_init(&iter->parent, ctx, begin_pos, end_pos);
46 if (ret) {
47 g_free(iter);
48 return NULL;
49 }
50 iter->callbacks = g_array_new(0, 1, sizeof(struct bt_stream_callbacks));
51 iter->recalculate_dep_graph = 0;
52 iter->main_callbacks.callback = NULL;
53 iter->dep_gc = g_ptr_array_new();
54 return iter;
55}
56
57void bt_ctf_iter_destroy(struct bt_ctf_iter *iter)
58{
59 struct bt_stream_callbacks *bt_stream_cb;
60 struct bt_callback_chain *bt_chain;
61 int i, j;
62
7f89ddce
MD
63 assert(iter);
64
a7765dd4
MD
65 /* free all events callbacks */
66 if (iter->main_callbacks.callback)
67 g_array_free(iter->main_callbacks.callback, TRUE);
68
69 /* free per-event callbacks */
70 for (i = 0; i < iter->callbacks->len; i++) {
71 bt_stream_cb = &g_array_index(iter->callbacks,
72 struct bt_stream_callbacks, i);
73 if (!bt_stream_cb || !bt_stream_cb->per_id_callbacks)
74 continue;
75 for (j = 0; j < bt_stream_cb->per_id_callbacks->len; j++) {
76 bt_chain = &g_array_index(bt_stream_cb->per_id_callbacks,
77 struct bt_callback_chain, j);
78 if (bt_chain->callback) {
79 g_array_free(bt_chain->callback, TRUE);
80 }
81 }
82 g_array_free(bt_stream_cb->per_id_callbacks, TRUE);
83 }
84
85 bt_iter_fini(&iter->parent);
86 g_free(iter);
87}
88
89struct bt_iter *bt_ctf_get_iter(struct bt_ctf_iter *iter)
90{
7f89ddce
MD
91 if (!iter)
92 return NULL;
93
a7765dd4
MD
94 return &iter->parent;
95}
96
c50d2a7a 97struct bt_ctf_event *bt_ctf_iter_read_event(struct bt_ctf_iter *iter)
a7765dd4
MD
98{
99 struct ctf_file_stream *file_stream;
7f89ddce 100 struct bt_ctf_event *ret;
8a4722b0 101 struct ctf_stream_definition *stream;
a7765dd4 102
7f89ddce
MD
103 /*
104 * We do not want to fail for any other reason than end of
105 * trace, hence the assert.
106 */
107 assert(iter);
108
109 ret = &iter->current_ctf_event;
a7765dd4
MD
110 file_stream = heap_maximum(iter->parent.stream_heap);
111 if (!file_stream) {
112 /* end of file for all streams */
113 goto stop;
114 }
8a4722b0 115 stream = &file_stream->parent;
c50d2a7a 116 ret->parent = g_ptr_array_index(stream->events_by_id,
8a4722b0 117 stream->event_id);
a7765dd4 118
c50d2a7a 119 if (ret->parent->stream->stream_id > iter->callbacks->len)
a7765dd4
MD
120 goto end;
121
c50d2a7a 122 process_callbacks(iter, ret->parent->stream);
a7765dd4
MD
123
124end:
125 return ret;
126stop:
127 return NULL;
128}
This page took 0.027958 seconds and 4 git commands to generate.