Fix: iterator.c BT_SEEK_RESTORE: check return value
[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 /* Forward declarations */
24 struct bt_iter;
25 struct bt_saved_pos;
26
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 :
39 * - seek_time is the real timestamp to seek to when using BT_SEEK_TIME, it
40 * is expressed in nanoseconds
41 * - restore is a position saved with bt_iter_get_pos, it is used with
42 * BT_SEEK_RESTORE.
43 */
44 struct bt_iter_pos {
45 enum {
46 BT_SEEK_TIME, /* uses u.seek_time */
47 BT_SEEK_RESTORE, /* uses u.restore */
48 BT_SEEK_CUR,
49 BT_SEEK_BEGIN,
50 BT_SEEK_END,
51 } type;
52 union {
53 uint64_t seek_time;
54 struct bt_saved_pos *restore;
55 } u;
56 };
57
58 /*
59 * bt_iter_next: Move trace collection position to the next event.
60 *
61 * Returns 0 on success, a negative value on error
62 */
63 int bt_iter_next(struct bt_iter *iter);
64
65 /*
66 * bt_iter_get_pos - Get the current iterator position.
67 *
68 * The position returned by this function needs to be freed by
69 * bt_iter_free_pos after use.
70 */
71 struct bt_iter_pos *bt_iter_get_pos(struct bt_iter *iter);
72
73 /*
74 * bt_iter_free_pos - Free the position.
75 */
76 void bt_iter_free_pos(struct bt_iter_pos *pos);
77
78 /*
79 * bt_iter_set_pos: move the iterator to a given position.
80 *
81 * On error, the stream_heap is reinitialized and returned empty.
82 *
83 * Return 0 for success.
84 *
85 * Return EOF if the position requested is after the last event of the
86 * trace collection.
87 * Return -EINVAL when called with invalid parameter.
88 * Return -ENOMEM if the stream_heap could not be properly initialized.
89 */
90 int bt_iter_set_pos(struct bt_iter *iter, const struct bt_iter_pos *pos);
91
92 /*
93 * bt_iter_create_time_pos: create a position based on time
94 *
95 * This function allocates and returns a new bt_iter_pos (which must be freed
96 * with bt_iter_free_pos) to be able to restore an iterator position based on a
97 * real timestamp.
98 */
99 struct bt_iter_pos *bt_iter_create_time_pos(struct bt_iter *iter,
100 uint64_t timestamp);
101
102 #endif /* _BABELTRACE_ITERATOR_H */
This page took 0.034457 seconds and 5 git commands to generate.