Commit | Line | Data |
---|---|---|
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 | ||
34 | struct bt_ctf_iter *bt_ctf_iter_create(struct bt_context *ctx, | |
35 | struct bt_iter_pos *begin_pos, | |
36 | struct bt_iter_pos *end_pos) | |
37 | { | |
38 | struct bt_ctf_iter *iter; | |
39 | int ret; | |
40 | ||
41 | iter = g_new0(struct bt_ctf_iter, 1); | |
42 | ret = bt_iter_init(&iter->parent, ctx, begin_pos, end_pos); | |
43 | if (ret) { | |
44 | g_free(iter); | |
45 | return NULL; | |
46 | } | |
47 | iter->callbacks = g_array_new(0, 1, sizeof(struct bt_stream_callbacks)); | |
48 | iter->recalculate_dep_graph = 0; | |
49 | iter->main_callbacks.callback = NULL; | |
50 | iter->dep_gc = g_ptr_array_new(); | |
51 | return iter; | |
52 | } | |
53 | ||
54 | void bt_ctf_iter_destroy(struct bt_ctf_iter *iter) | |
55 | { | |
56 | struct bt_stream_callbacks *bt_stream_cb; | |
57 | struct bt_callback_chain *bt_chain; | |
58 | int i, j; | |
59 | ||
60 | /* free all events callbacks */ | |
61 | if (iter->main_callbacks.callback) | |
62 | g_array_free(iter->main_callbacks.callback, TRUE); | |
63 | ||
64 | /* free per-event callbacks */ | |
65 | for (i = 0; i < iter->callbacks->len; i++) { | |
66 | bt_stream_cb = &g_array_index(iter->callbacks, | |
67 | struct bt_stream_callbacks, i); | |
68 | if (!bt_stream_cb || !bt_stream_cb->per_id_callbacks) | |
69 | continue; | |
70 | for (j = 0; j < bt_stream_cb->per_id_callbacks->len; j++) { | |
71 | bt_chain = &g_array_index(bt_stream_cb->per_id_callbacks, | |
72 | struct bt_callback_chain, j); | |
73 | if (bt_chain->callback) { | |
74 | g_array_free(bt_chain->callback, TRUE); | |
75 | } | |
76 | } | |
77 | g_array_free(bt_stream_cb->per_id_callbacks, TRUE); | |
78 | } | |
79 | ||
80 | bt_iter_fini(&iter->parent); | |
81 | g_free(iter); | |
82 | } | |
83 | ||
84 | struct bt_iter *bt_ctf_get_iter(struct bt_ctf_iter *iter) | |
85 | { | |
86 | return &iter->parent; | |
87 | } | |
88 | ||
89 | struct bt_ctf_event *bt_ctf_iter_read_event(struct bt_ctf_iter *iter) | |
90 | { | |
91 | struct ctf_file_stream *file_stream; | |
92 | struct bt_ctf_event *ret = &iter->current_ctf_event; | |
93 | ||
94 | file_stream = heap_maximum(iter->parent.stream_heap); | |
95 | if (!file_stream) { | |
96 | /* end of file for all streams */ | |
97 | goto stop; | |
98 | } | |
99 | ret->stream = &file_stream->parent; | |
100 | ret->event = g_ptr_array_index(ret->stream->events_by_id, | |
101 | ret->stream->event_id); | |
102 | ||
103 | if (ret->stream->stream_id > iter->callbacks->len) | |
104 | goto end; | |
105 | ||
106 | process_callbacks(iter, ret->stream); | |
107 | ||
108 | end: | |
109 | return ret; | |
110 | stop: | |
111 | return NULL; | |
112 | } |