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. | |
c462e188 MD |
18 | * |
19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
20 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
21 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
22 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
23 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
24 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
25 | * SOFTWARE. | |
6204d33c JD |
26 | */ |
27 | ||
28 | #include <babeltrace/format.h> | |
29 | #include <babeltrace/context.h> | |
30 | ||
6946751f JD |
31 | #ifdef __cplusplus |
32 | extern "C" { | |
33 | #endif | |
34 | ||
f60efc0e JD |
35 | /* Flags for the iterator read_event */ |
36 | enum { | |
37 | BT_ITER_FLAG_LOST_EVENTS = (1 << 0), | |
38 | }; | |
39 | ||
6204d33c | 40 | /* Forward declarations */ |
e8c92a62 | 41 | struct bt_iter; |
e8c92a62 | 42 | struct bt_saved_pos; |
6204d33c | 43 | |
31265d84 JD |
44 | /* |
45 | * bt_iter is an abstract class, each format has to implement its own | |
46 | * iterator derived from this parent class. | |
47 | */ | |
48 | ||
49 | /* | |
50 | * bt_iter_pos | |
51 | * | |
52 | * This structure represents the position where to set an iterator. | |
53 | * | |
54 | * type represents the type of seek to use. | |
55 | * u is the argument of the seek if necessary : | |
03798a93 | 56 | * - seek_time is the real timestamp to seek to when using BT_SEEK_TIME, it |
836c4dd8 | 57 | * is expressed in nanoseconds |
31265d84 JD |
58 | * - restore is a position saved with bt_iter_get_pos, it is used with |
59 | * BT_SEEK_RESTORE. | |
f7ed6563 MD |
60 | * |
61 | * Note about BT_SEEK_LAST: if many events happen to be at the last | |
62 | * timestamp, it is implementation-defined which event will be the last, | |
63 | * and the order of events with the same timestamp may not be the same | |
64 | * as normal iteration on the trace. Therefore, it is recommended to | |
65 | * only use BT_SEEK_LAST to get the timestamp of the last event(s) in | |
66 | * the trace. | |
31265d84 | 67 | */ |
8b8dcf93 FG |
68 | enum bt_iter_pos_type { |
69 | BT_SEEK_TIME, /* uses u.seek_time */ | |
70 | BT_SEEK_RESTORE, /* uses u.restore */ | |
71 | BT_SEEK_CUR, | |
72 | BT_SEEK_BEGIN, | |
73 | BT_SEEK_LAST, | |
74 | }; | |
75 | ||
e8c92a62 | 76 | struct bt_iter_pos { |
8b8dcf93 | 77 | enum bt_iter_pos_type type; |
6204d33c JD |
78 | union { |
79 | uint64_t seek_time; | |
e8c92a62 | 80 | struct bt_saved_pos *restore; |
6204d33c JD |
81 | } u; |
82 | }; | |
83 | ||
6204d33c | 84 | /* |
e8c92a62 | 85 | * bt_iter_next: Move trace collection position to the next event. |
6204d33c JD |
86 | * |
87 | * Returns 0 on success, a negative value on error | |
88 | */ | |
e8c92a62 | 89 | int bt_iter_next(struct bt_iter *iter); |
6204d33c JD |
90 | |
91 | /* | |
90fcbacc | 92 | * bt_iter_get_pos - Get the current iterator position. |
6204d33c JD |
93 | * |
94 | * The position returned by this function needs to be freed by | |
e8c92a62 | 95 | * bt_iter_free_pos after use. |
6204d33c | 96 | */ |
5a23202c | 97 | struct bt_iter_pos *bt_iter_get_pos(struct bt_iter *iter); |
6204d33c JD |
98 | |
99 | /* | |
e8c92a62 | 100 | * bt_iter_free_pos - Free the position. |
6204d33c | 101 | */ |
e8c92a62 | 102 | void bt_iter_free_pos(struct bt_iter_pos *pos); |
6204d33c JD |
103 | |
104 | /* | |
90fcbacc | 105 | * bt_iter_set_pos: move the iterator to a given position. |
6204d33c | 106 | * |
dc81689e JD |
107 | * On error, the stream_heap is reinitialized and returned empty. |
108 | * | |
6204d33c | 109 | * Return 0 for success. |
dc81689e JD |
110 | * |
111 | * Return EOF if the position requested is after the last event of the | |
112 | * trace collection. | |
113 | * Return -EINVAL when called with invalid parameter. | |
114 | * Return -ENOMEM if the stream_heap could not be properly initialized. | |
115 | */ | |
116 | int bt_iter_set_pos(struct bt_iter *iter, const struct bt_iter_pos *pos); | |
117 | ||
118 | /* | |
119 | * bt_iter_create_time_pos: create a position based on time | |
120 | * | |
121 | * This function allocates and returns a new bt_iter_pos (which must be freed | |
122 | * with bt_iter_free_pos) to be able to restore an iterator position based on a | |
03798a93 | 123 | * real timestamp. |
6204d33c | 124 | */ |
dc81689e JD |
125 | struct bt_iter_pos *bt_iter_create_time_pos(struct bt_iter *iter, |
126 | uint64_t timestamp); | |
6204d33c | 127 | |
6946751f JD |
128 | #ifdef __cplusplus |
129 | } | |
130 | #endif | |
131 | ||
6204d33c | 132 | #endif /* _BABELTRACE_ITERATOR_H */ |