Commit | Line | Data |
---|---|---|
6204d33c JD |
1 | #ifndef _BABELTRACE_ITERATOR_H |
2 | #define _BABELTRACE_ITERATOR_H | |
3 | ||
4 | /* | |
5 | * BabelTrace API Iterators | |
6 | * | |
7 | * Copyright 2010-2011 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com> | |
8 | * | |
9 | * Permission is hereby granted, free of charge, to any person obtaining a copy | |
10 | * of this software and associated documentation files (the "Software"), to deal | |
11 | * in the Software without restriction, including without limitation the rights | |
12 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
13 | * copies of the Software, and to permit persons to whom the Software is | |
14 | * furnished to do so, subject to the following conditions: | |
15 | * | |
16 | * The above copyright notice and this permission notice shall be included in | |
17 | * all copies or substantial portions of the Software. | |
18 | */ | |
19 | ||
20 | #include <babeltrace/format.h> | |
21 | #include <babeltrace/context.h> | |
9843982d | 22 | #include <babeltrace/ctf/events.h> |
6204d33c | 23 | |
6204d33c | 24 | /* Forward declarations */ |
e8c92a62 | 25 | struct bt_iter; |
6204d33c JD |
26 | struct ctf_stream_event; |
27 | struct ctf_stream; | |
e8c92a62 | 28 | struct bt_saved_pos; |
6204d33c | 29 | |
e8c92a62 | 30 | struct bt_iter_pos { |
6204d33c JD |
31 | enum { |
32 | BT_SEEK_TIME, /* uses u.seek_time */ | |
33 | BT_SEEK_RESTORE, /* uses u.restore */ | |
34 | BT_SEEK_CUR, | |
35 | BT_SEEK_BEGIN, | |
36 | BT_SEEK_END, | |
37 | } type; | |
38 | union { | |
39 | uint64_t seek_time; | |
e8c92a62 | 40 | struct bt_saved_pos *restore; |
6204d33c JD |
41 | } u; |
42 | }; | |
43 | ||
44 | /* | |
e8c92a62 | 45 | * bt_iter_create - Allocate a trace collection iterator. |
6204d33c JD |
46 | * |
47 | * begin_pos and end_pos are optional parameters to specify the position | |
48 | * at which the trace collection should be seeked upon iterator | |
49 | * creation, and the position at which iteration will start returning | |
50 | * "EOF". | |
51 | * | |
52 | * By default, if begin_pos is NULL, a BT_SEEK_CUR is performed at | |
53 | * creation. By default, if end_pos is NULL, a BT_SEEK_END (end of | |
54 | * trace) is the EOF criterion. | |
55 | */ | |
e8c92a62 JD |
56 | struct bt_iter *bt_iter_create(struct bt_context *ctx, |
57 | struct bt_iter_pos *begin_pos, | |
58 | struct bt_iter_pos *end_pos); | |
6204d33c JD |
59 | |
60 | /* | |
e8c92a62 | 61 | * bt_iter_destroy - Free a trace collection iterator. |
6204d33c | 62 | */ |
e8c92a62 | 63 | void bt_iter_destroy(struct bt_iter *iter); |
6204d33c JD |
64 | |
65 | /* | |
e8c92a62 | 66 | * bt_iter_next: Move trace collection position to the next event. |
6204d33c JD |
67 | * |
68 | * Returns 0 on success, a negative value on error | |
69 | */ | |
e8c92a62 | 70 | int bt_iter_next(struct bt_iter *iter); |
6204d33c JD |
71 | |
72 | /* | |
90fcbacc | 73 | * bt_iter_get_pos - Get the current iterator position. |
6204d33c JD |
74 | * |
75 | * The position returned by this function needs to be freed by | |
e8c92a62 | 76 | * bt_iter_free_pos after use. |
6204d33c | 77 | */ |
e8c92a62 | 78 | struct bt_iter_pos * |
90fcbacc | 79 | bt_iter_get_pos(struct bt_iter *iter); |
6204d33c JD |
80 | |
81 | /* | |
e8c92a62 | 82 | * bt_iter_free_pos - Free the position. |
6204d33c | 83 | */ |
e8c92a62 | 84 | void bt_iter_free_pos(struct bt_iter_pos *pos); |
6204d33c JD |
85 | |
86 | /* | |
90fcbacc | 87 | * bt_iter_set_pos: move the iterator to a given position. |
6204d33c | 88 | * |
dc81689e JD |
89 | * On error, the stream_heap is reinitialized and returned empty. |
90 | * | |
6204d33c | 91 | * Return 0 for success. |
dc81689e JD |
92 | * |
93 | * Return EOF if the position requested is after the last event of the | |
94 | * trace collection. | |
95 | * Return -EINVAL when called with invalid parameter. | |
96 | * Return -ENOMEM if the stream_heap could not be properly initialized. | |
97 | */ | |
98 | int bt_iter_set_pos(struct bt_iter *iter, const struct bt_iter_pos *pos); | |
99 | ||
100 | /* | |
101 | * bt_iter_create_time_pos: create a position based on time | |
102 | * | |
103 | * This function allocates and returns a new bt_iter_pos (which must be freed | |
104 | * with bt_iter_free_pos) to be able to restore an iterator position based on a | |
105 | * timestamp. | |
6204d33c | 106 | */ |
dc81689e JD |
107 | struct bt_iter_pos *bt_iter_create_time_pos(struct bt_iter *iter, |
108 | uint64_t timestamp); | |
6204d33c JD |
109 | |
110 | /* | |
9843982d | 111 | * bt_iter_read_ctf_event: Read the iterator's current event data. |
6204d33c JD |
112 | * |
113 | * @iter: trace collection iterator (input) | |
114 | * @stream: stream containing event at current position (output) | |
115 | * @event: current event (output) | |
116 | * Return 0 on success, negative error value on error. | |
117 | */ | |
9843982d | 118 | struct bt_ctf_event *bt_iter_read_ctf_event(struct bt_iter *iter); |
6204d33c JD |
119 | |
120 | #endif /* _BABELTRACE_ITERATOR_H */ |