Commit | Line | Data |
---|---|---|
b1acd2b3 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 | ||
23 | #ifdef __cplusplus | |
24 | extern "C" { | |
25 | #endif | |
26 | ||
27 | /* Forward declarations */ | |
28 | struct bt_iter; | |
29 | struct bt_saved_pos; | |
30 | ||
31 | /* | |
32 | * bt_iter is an abstract class, each format has to implement its own | |
33 | * iterator derived from this parent class. | |
34 | */ | |
35 | ||
36 | /* | |
37 | * bt_iter_pos | |
38 | * | |
39 | * This structure represents the position where to set an iterator. | |
40 | * | |
41 | * type represents the type of seek to use. | |
42 | * u is the argument of the seek if necessary : | |
43 | * - seek_time is the real timestamp to seek to when using BT_SEEK_TIME, it | |
44 | * is expressed in nanoseconds | |
45 | * - restore is a position saved with bt_iter_get_pos, it is used with | |
46 | * BT_SEEK_RESTORE. | |
47 | * | |
48 | * Note about BT_SEEK_LAST: if many events happen to be at the last | |
49 | * timestamp, it is implementation-defined which event will be the last, | |
50 | * and the order of events with the same timestamp may not be the same | |
51 | * as normal iteration on the trace. Therefore, it is recommended to | |
52 | * only use BT_SEEK_LAST to get the timestamp of the last event(s) in | |
53 | * the trace. | |
54 | */ | |
55 | struct bt_iter_pos { | |
56 | enum { | |
57 | BT_SEEK_TIME, /* uses u.seek_time */ | |
58 | BT_SEEK_RESTORE, /* uses u.restore */ | |
59 | BT_SEEK_CUR, | |
60 | BT_SEEK_BEGIN, | |
61 | BT_SEEK_LAST, | |
62 | } type; | |
63 | union { | |
64 | uint64_t seek_time; | |
65 | struct bt_saved_pos *restore; | |
66 | } u; | |
67 | }; | |
68 | ||
69 | /* | |
70 | * bt_iter_next: Move trace collection position to the next event. | |
71 | * | |
72 | * Returns 0 on success, a negative value on error | |
73 | */ | |
74 | int bt_iter_next(struct bt_iter *iter); | |
75 | ||
76 | /* | |
77 | * bt_iter_get_pos - Get the current iterator position. | |
78 | * | |
79 | * The position returned by this function needs to be freed by | |
80 | * bt_iter_free_pos after use. | |
81 | */ | |
82 | struct bt_iter_pos *bt_iter_get_pos(struct bt_iter *iter); | |
83 | ||
84 | /* | |
85 | * bt_iter_free_pos - Free the position. | |
86 | */ | |
87 | void bt_iter_free_pos(struct bt_iter_pos *pos); | |
88 | ||
89 | /* | |
90 | * bt_iter_set_pos: move the iterator to a given position. | |
91 | * | |
92 | * On error, the stream_heap is reinitialized and returned empty. | |
93 | * | |
94 | * Return 0 for success. | |
95 | * | |
96 | * Return EOF if the position requested is after the last event of the | |
97 | * trace collection. | |
98 | * Return -EINVAL when called with invalid parameter. | |
99 | * Return -ENOMEM if the stream_heap could not be properly initialized. | |
100 | */ | |
101 | int bt_iter_set_pos(struct bt_iter *iter, const struct bt_iter_pos *pos); | |
102 | ||
103 | /* | |
104 | * bt_iter_create_time_pos: create a position based on time | |
105 | * | |
106 | * This function allocates and returns a new bt_iter_pos (which must be freed | |
107 | * with bt_iter_free_pos) to be able to restore an iterator position based on a | |
108 | * real timestamp. | |
109 | */ | |
110 | struct bt_iter_pos *bt_iter_create_time_pos(struct bt_iter *iter, | |
111 | uint64_t timestamp); | |
112 | ||
113 | #ifdef __cplusplus | |
114 | } | |
115 | #endif | |
116 | ||
117 | #endif /* _BABELTRACE_ITERATOR_H */ |