| 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 ctf_stream_event; |
| 26 | struct ctf_stream; |
| 27 | struct bt_saved_pos; |
| 28 | |
| 29 | struct bt_iter_pos { |
| 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; |
| 39 | struct bt_saved_pos *restore; |
| 40 | } u; |
| 41 | }; |
| 42 | |
| 43 | /* |
| 44 | * bt_iter_create - Allocate a trace collection iterator. |
| 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 | */ |
| 55 | struct bt_iter *bt_iter_create(struct bt_context *ctx, |
| 56 | struct bt_iter_pos *begin_pos, |
| 57 | struct bt_iter_pos *end_pos); |
| 58 | |
| 59 | /* |
| 60 | * bt_iter_destroy - Free a trace collection iterator. |
| 61 | */ |
| 62 | void bt_iter_destroy(struct bt_iter *iter); |
| 63 | |
| 64 | /* |
| 65 | * bt_iter_next: Move trace collection position to the next event. |
| 66 | * |
| 67 | * Returns 0 on success, a negative value on error |
| 68 | */ |
| 69 | int bt_iter_next(struct bt_iter *iter); |
| 70 | |
| 71 | /* |
| 72 | * bt_iter_save_pos - Save the current trace collection position. |
| 73 | * |
| 74 | * The position returned by this function needs to be freed by |
| 75 | * bt_iter_free_pos after use. |
| 76 | */ |
| 77 | struct bt_iter_pos * |
| 78 | bt_iter_save_pos(struct bt_iter *iter); |
| 79 | |
| 80 | /* |
| 81 | * bt_iter_free_pos - Free the position. |
| 82 | */ |
| 83 | void bt_iter_free_pos(struct bt_iter_pos *pos); |
| 84 | |
| 85 | /* |
| 86 | * bt_iter_seek: seek iterator to given position. |
| 87 | * |
| 88 | * Return EOF if position is after the last event of the trace collection. |
| 89 | * Return other negative value for other errors. |
| 90 | * Return 0 for success. |
| 91 | */ |
| 92 | int bt_iter_seek(struct bt_iter *iter, |
| 93 | const struct bt_iter_pos *pos); |
| 94 | |
| 95 | /* |
| 96 | * bt_iter_read_event: Read the iterator's current event data. |
| 97 | * |
| 98 | * @iter: trace collection iterator (input) |
| 99 | * @stream: stream containing event at current position (output) |
| 100 | * @event: current event (output) |
| 101 | * Return 0 on success, negative error value on error. |
| 102 | */ |
| 103 | int bt_iter_read_event(struct bt_iter *iter, |
| 104 | struct ctf_stream **stream, |
| 105 | struct ctf_stream_event **event); |
| 106 | |
| 107 | #endif /* _BABELTRACE_ITERATOR_H */ |