API : split iterator headers from babeltrace.h
[babeltrace.git] / include / babeltrace / iterator.h
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 typedef GQuark bt_event_name;
24
25 /* Forward declarations */
26 struct babeltrace_iter;
27 struct ctf_stream_event;
28 struct ctf_stream;
29 struct babeltrace_saved_pos;
30
31 struct trace_collection_pos {
32 enum {
33 BT_SEEK_TIME, /* uses u.seek_time */
34 BT_SEEK_RESTORE, /* uses u.restore */
35 BT_SEEK_CUR,
36 BT_SEEK_BEGIN,
37 BT_SEEK_END,
38 } type;
39 union {
40 uint64_t seek_time;
41 struct babeltrace_saved_pos *restore;
42 } u;
43 };
44
45 /*
46 * babeltrace_iter_create - Allocate a trace collection iterator.
47 *
48 * begin_pos and end_pos are optional parameters to specify the position
49 * at which the trace collection should be seeked upon iterator
50 * creation, and the position at which iteration will start returning
51 * "EOF".
52 *
53 * By default, if begin_pos is NULL, a BT_SEEK_CUR is performed at
54 * creation. By default, if end_pos is NULL, a BT_SEEK_END (end of
55 * trace) is the EOF criterion.
56 */
57 struct babeltrace_iter *babeltrace_iter_create(struct bt_context *ctx,
58 struct trace_collection_pos *begin_pos,
59 struct trace_collection_pos *end_pos);
60
61 /*
62 * babeltrace_iter_destroy - Free a trace collection iterator.
63 */
64 void babeltrace_iter_destroy(struct babeltrace_iter *iter);
65
66 /*
67 * babeltrace_iter_next: Move trace collection position to the next event.
68 *
69 * Returns 0 on success, a negative value on error
70 */
71 int babeltrace_iter_next(struct babeltrace_iter *iter);
72
73 /*
74 * babeltrace_iter_save_pos - Save the current trace collection position.
75 *
76 * The position returned by this function needs to be freed by
77 * babeltrace_iter_free_pos after use.
78 */
79 struct trace_collection_pos *
80 babeltrace_iter_save_pos(struct babeltrace_iter *iter);
81
82 /*
83 * babeltrace_iter_free_pos - Free the position.
84 */
85 void babeltrace_iter_free_pos(struct trace_collection_pos *pos);
86
87 /*
88 * babeltrace_iter_seek: seek iterator to given position.
89 *
90 * Return EOF if position is after the last event of the trace collection.
91 * Return other negative value for other errors.
92 * Return 0 for success.
93 */
94 int babeltrace_iter_seek(struct babeltrace_iter *iter,
95 const struct trace_collection_pos *pos);
96
97 /*
98 * babeltrace_iter_read_event: Read the iterator's current event data.
99 *
100 * @iter: trace collection iterator (input)
101 * @stream: stream containing event at current position (output)
102 * @event: current event (output)
103 * Return 0 on success, negative error value on error.
104 */
105 int babeltrace_iter_read_event(struct babeltrace_iter *iter,
106 struct ctf_stream **stream,
107 struct ctf_stream_event **event);
108
109 #endif /* _BABELTRACE_ITERATOR_H */
This page took 0.031719 seconds and 4 git commands to generate.