API : seek by timestamp
[babeltrace.git] / include / babeltrace / iterator.h
CommitLineData
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 24struct bt_iter;
6204d33c
JD
25struct ctf_stream_event;
26struct ctf_stream;
e8c92a62 27struct bt_saved_pos;
6204d33c 28
e8c92a62 29struct bt_iter_pos {
6204d33c
JD
30 enum {
31 BT_SEEK_TIME, /* uses u.seek_time */
32 BT_SEEK_RESTORE, /* uses u.restore */
33 BT_SEEK_CUR,
34 BT_SEEK_BEGIN,
35 BT_SEEK_END,
36 } type;
37 union {
38 uint64_t seek_time;
e8c92a62 39 struct bt_saved_pos *restore;
6204d33c
JD
40 } u;
41};
42
43/*
e8c92a62 44 * bt_iter_create - Allocate a trace collection iterator.
6204d33c
JD
45 *
46 * begin_pos and end_pos are optional parameters to specify the position
47 * at which the trace collection should be seeked upon iterator
48 * creation, and the position at which iteration will start returning
49 * "EOF".
50 *
51 * By default, if begin_pos is NULL, a BT_SEEK_CUR is performed at
52 * creation. By default, if end_pos is NULL, a BT_SEEK_END (end of
53 * trace) is the EOF criterion.
54 */
e8c92a62
JD
55struct bt_iter *bt_iter_create(struct bt_context *ctx,
56 struct bt_iter_pos *begin_pos,
57 struct bt_iter_pos *end_pos);
6204d33c
JD
58
59/*
e8c92a62 60 * bt_iter_destroy - Free a trace collection iterator.
6204d33c 61 */
e8c92a62 62void bt_iter_destroy(struct bt_iter *iter);
6204d33c
JD
63
64/*
e8c92a62 65 * bt_iter_next: Move trace collection position to the next event.
6204d33c
JD
66 *
67 * Returns 0 on success, a negative value on error
68 */
e8c92a62 69int bt_iter_next(struct bt_iter *iter);
6204d33c
JD
70
71/*
90fcbacc 72 * bt_iter_get_pos - Get the current iterator position.
6204d33c
JD
73 *
74 * The position returned by this function needs to be freed by
e8c92a62 75 * bt_iter_free_pos after use.
6204d33c 76 */
e8c92a62 77struct bt_iter_pos *
90fcbacc 78 bt_iter_get_pos(struct bt_iter *iter);
6204d33c
JD
79
80/*
e8c92a62 81 * bt_iter_free_pos - Free the position.
6204d33c 82 */
e8c92a62 83void 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 */
97int 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
104 * timestamp.
6204d33c 105 */
dc81689e
JD
106struct bt_iter_pos *bt_iter_create_time_pos(struct bt_iter *iter,
107 uint64_t timestamp);
6204d33c
JD
108
109/*
e8c92a62 110 * bt_iter_read_event: Read the iterator's current event data.
6204d33c
JD
111 *
112 * @iter: trace collection iterator (input)
113 * @stream: stream containing event at current position (output)
114 * @event: current event (output)
115 * Return 0 on success, negative error value on error.
116 */
e8c92a62 117int bt_iter_read_event(struct bt_iter *iter,
6204d33c
JD
118 struct ctf_stream **stream,
119 struct ctf_stream_event **event);
120
121#endif /* _BABELTRACE_ITERATOR_H */
This page took 0.027735 seconds and 4 git commands to generate.