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