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> | |
22 | ||
6204d33c | 23 | /* Forward declarations */ |
e8c92a62 | 24 | struct bt_iter; |
e8c92a62 | 25 | struct bt_saved_pos; |
6204d33c | 26 | |
31265d84 JD |
27 | /* |
28 | * bt_iter is an abstract class, each format has to implement its own | |
29 | * iterator derived from this parent class. | |
30 | */ | |
31 | ||
32 | /* | |
33 | * bt_iter_pos | |
34 | * | |
35 | * This structure represents the position where to set an iterator. | |
36 | * | |
37 | * type represents the type of seek to use. | |
38 | * u is the argument of the seek if necessary : | |
03798a93 | 39 | * - seek_time is the real timestamp to seek to when using BT_SEEK_TIME, it |
836c4dd8 | 40 | * is expressed in nanoseconds |
31265d84 JD |
41 | * - restore is a position saved with bt_iter_get_pos, it is used with |
42 | * BT_SEEK_RESTORE. | |
f7ed6563 MD |
43 | * |
44 | * Note about BT_SEEK_LAST: if many events happen to be at the last | |
45 | * timestamp, it is implementation-defined which event will be the last, | |
46 | * and the order of events with the same timestamp may not be the same | |
47 | * as normal iteration on the trace. Therefore, it is recommended to | |
48 | * only use BT_SEEK_LAST to get the timestamp of the last event(s) in | |
49 | * the trace. | |
31265d84 | 50 | */ |
e8c92a62 | 51 | struct bt_iter_pos { |
6204d33c JD |
52 | enum { |
53 | BT_SEEK_TIME, /* uses u.seek_time */ | |
54 | BT_SEEK_RESTORE, /* uses u.restore */ | |
55 | BT_SEEK_CUR, | |
56 | BT_SEEK_BEGIN, | |
f7ed6563 | 57 | BT_SEEK_LAST, |
6204d33c JD |
58 | } type; |
59 | union { | |
60 | uint64_t seek_time; | |
e8c92a62 | 61 | struct bt_saved_pos *restore; |
6204d33c JD |
62 | } u; |
63 | }; | |
64 | ||
6204d33c | 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 | */ |
5a23202c | 78 | struct bt_iter_pos *bt_iter_get_pos(struct bt_iter *iter); |
6204d33c JD |
79 | |
80 | /* | |
e8c92a62 | 81 | * bt_iter_free_pos - Free the position. |
6204d33c | 82 | */ |
e8c92a62 | 83 | void bt_iter_free_pos(struct bt_iter_pos *pos); |
6204d33c JD |
84 | |
85 | /* | |
90fcbacc | 86 | * bt_iter_set_pos: move the iterator to a given position. |
6204d33c | 87 | * |
dc81689e JD |
88 | * On error, the stream_heap is reinitialized and returned empty. |
89 | * | |
6204d33c | 90 | * Return 0 for success. |
dc81689e JD |
91 | * |
92 | * Return EOF if the position requested is after the last event of the | |
93 | * trace collection. | |
94 | * Return -EINVAL when called with invalid parameter. | |
95 | * Return -ENOMEM if the stream_heap could not be properly initialized. | |
96 | */ | |
97 | int bt_iter_set_pos(struct bt_iter *iter, const struct bt_iter_pos *pos); | |
98 | ||
99 | /* | |
100 | * bt_iter_create_time_pos: create a position based on time | |
101 | * | |
102 | * This function allocates and returns a new bt_iter_pos (which must be freed | |
103 | * with bt_iter_free_pos) to be able to restore an iterator position based on a | |
03798a93 | 104 | * real timestamp. |
6204d33c | 105 | */ |
dc81689e JD |
106 | struct bt_iter_pos *bt_iter_create_time_pos(struct bt_iter *iter, |
107 | uint64_t timestamp); | |
6204d33c | 108 | |
6204d33c | 109 | #endif /* _BABELTRACE_ITERATOR_H */ |