| 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 | struct bt_iter_pos { |
| 28 | enum { |
| 29 | BT_SEEK_TIME, /* uses u.seek_time */ |
| 30 | BT_SEEK_RESTORE, /* uses u.restore */ |
| 31 | BT_SEEK_CUR, |
| 32 | BT_SEEK_BEGIN, |
| 33 | BT_SEEK_END, |
| 34 | } type; |
| 35 | union { |
| 36 | uint64_t seek_time; |
| 37 | struct bt_saved_pos *restore; |
| 38 | } u; |
| 39 | }; |
| 40 | |
| 41 | /* |
| 42 | * bt_iter_create - Allocate a trace collection iterator. |
| 43 | * |
| 44 | * begin_pos and end_pos are optional parameters to specify the position |
| 45 | * at which the trace collection should be seeked upon iterator |
| 46 | * creation, and the position at which iteration will start returning |
| 47 | * "EOF". |
| 48 | * |
| 49 | * By default, if begin_pos is NULL, a BT_SEEK_CUR is performed at |
| 50 | * creation. By default, if end_pos is NULL, a BT_SEEK_END (end of |
| 51 | * trace) is the EOF criterion. |
| 52 | */ |
| 53 | struct bt_iter *bt_iter_create(struct bt_context *ctx, |
| 54 | struct bt_iter_pos *begin_pos, |
| 55 | struct bt_iter_pos *end_pos); |
| 56 | |
| 57 | /* |
| 58 | * bt_iter_destroy - Free a trace collection iterator. |
| 59 | */ |
| 60 | void bt_iter_destroy(struct bt_iter *iter); |
| 61 | |
| 62 | /* |
| 63 | * bt_iter_next: Move trace collection position to the next event. |
| 64 | * |
| 65 | * Returns 0 on success, a negative value on error |
| 66 | */ |
| 67 | int bt_iter_next(struct bt_iter *iter); |
| 68 | |
| 69 | /* |
| 70 | * bt_iter_get_pos - Get the current iterator position. |
| 71 | * |
| 72 | * The position returned by this function needs to be freed by |
| 73 | * bt_iter_free_pos after use. |
| 74 | */ |
| 75 | struct bt_iter_pos *bt_iter_get_pos(struct bt_iter *iter); |
| 76 | |
| 77 | /* |
| 78 | * bt_iter_free_pos - Free the position. |
| 79 | */ |
| 80 | void bt_iter_free_pos(struct bt_iter_pos *pos); |
| 81 | |
| 82 | /* |
| 83 | * bt_iter_set_pos: move the iterator to a given position. |
| 84 | * |
| 85 | * On error, the stream_heap is reinitialized and returned empty. |
| 86 | * |
| 87 | * Return 0 for success. |
| 88 | * |
| 89 | * Return EOF if the position requested is after the last event of the |
| 90 | * trace collection. |
| 91 | * Return -EINVAL when called with invalid parameter. |
| 92 | * Return -ENOMEM if the stream_heap could not be properly initialized. |
| 93 | */ |
| 94 | int bt_iter_set_pos(struct bt_iter *iter, const struct bt_iter_pos *pos); |
| 95 | |
| 96 | /* |
| 97 | * bt_iter_create_time_pos: create a position based on time |
| 98 | * |
| 99 | * This function allocates and returns a new bt_iter_pos (which must be freed |
| 100 | * with bt_iter_free_pos) to be able to restore an iterator position based on a |
| 101 | * timestamp. |
| 102 | */ |
| 103 | struct bt_iter_pos *bt_iter_create_time_pos(struct bt_iter *iter, |
| 104 | uint64_t timestamp); |
| 105 | |
| 106 | #endif /* _BABELTRACE_ITERATOR_H */ |