| 1 | #ifndef _BABELTRACE_CTF_CALLBACKS_H |
| 2 | #define _BABELTRACE_CTF_CALLBACKS_H |
| 3 | |
| 4 | /* |
| 5 | * BabelTrace |
| 6 | * |
| 7 | * CTF events API |
| 8 | * |
| 9 | * Copyright 2011-2012 EfficiOS Inc. and Linux Foundation |
| 10 | * |
| 11 | * Author: Mathieu Desnoyers <mathieu.desnoyers@efficios.com> |
| 12 | * Julien Desfossez <julien.desfossez@efficios.com> |
| 13 | * |
| 14 | * Permission is hereby granted, free of charge, to any person obtaining |
| 15 | * a copy of this software and associated documentation files (the |
| 16 | * "Software"), to deal in the Software without restriction, including |
| 17 | * without limitation the rights to use, copy, modify, merge, publish, |
| 18 | * distribute, sublicense, and/or sell copies of the Software, and to |
| 19 | * permit persons to whom the Software is furnished to do so, subject to |
| 20 | * the following conditions: |
| 21 | * |
| 22 | * The above copyright notice and this permission notice shall be |
| 23 | * included in all copies or substantial portions of the Software. |
| 24 | * |
| 25 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 26 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 27 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 28 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 29 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 30 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 31 | * SOFTWARE. |
| 32 | */ |
| 33 | |
| 34 | #include <babeltrace/format.h> |
| 35 | |
| 36 | #ifdef __cplusplus |
| 37 | extern "C" { |
| 38 | #endif |
| 39 | |
| 40 | /* Forward declarations */ |
| 41 | struct bt_ctf_iter; |
| 42 | struct bt_dependencies; |
| 43 | |
| 44 | enum bt_cb_ret { |
| 45 | BT_CB_OK = 0, |
| 46 | BT_CB_OK_STOP = 1, |
| 47 | BT_CB_ERROR_STOP = 2, |
| 48 | BT_CB_ERROR_CONTINUE = 3, |
| 49 | }; |
| 50 | |
| 51 | /* |
| 52 | * Receives a variable number of strings as parameter, ended with NULL. |
| 53 | */ |
| 54 | struct bt_dependencies *bt_dependencies_create(const char *first, ...); |
| 55 | |
| 56 | /* |
| 57 | * struct bt_dependencies must be destroyed explicitly if not passed as |
| 58 | * parameter to a bt_ctf_iter_add_callback(). |
| 59 | */ |
| 60 | void bt_dependencies_destroy(struct bt_dependencies *dep); |
| 61 | |
| 62 | /* |
| 63 | * bt_ctf_iter_add_callback: Add a callback to iterator. |
| 64 | * |
| 65 | * @iter: trace collection iterator (input) |
| 66 | * @event: event to target. 0 for all events. |
| 67 | * @private_data: private data pointer to pass to the callback |
| 68 | * @flags: specific flags controlling the behavior of this callback |
| 69 | * (or'd). |
| 70 | * |
| 71 | * @callback: function pointer to call |
| 72 | * @depends: struct bt_dependency detailing the required computation results. |
| 73 | * Ends with 0. NULL is accepted as empty dependency. |
| 74 | * @weak_depends: struct bt_dependency detailing the optional computation |
| 75 | * results that can be optionally consumed by this |
| 76 | * callback. NULL is accepted as empty dependency. |
| 77 | * @provides: struct bt_dependency detailing the computation results |
| 78 | * provided by this callback. |
| 79 | * Ends with 0. NULL is accepted as empty dependency. |
| 80 | * |
| 81 | * "depends", "weak_depends" and "provides" memory is handled by the |
| 82 | * babeltrace library after this call succeeds or fails. These objects |
| 83 | * can still be used by the caller until the babeltrace iterator is |
| 84 | * destroyed, but they belong to the babeltrace library. |
| 85 | * |
| 86 | * (note to implementor: we need to keep a gptrarray of struct |
| 87 | * bt_dependencies to "garbage collect" in struct bt_ctf_iter, and |
| 88 | * dependencies need to have a refcount to handle the case where they |
| 89 | * would be passed to more than one iterator. Upon iterator detroy, we |
| 90 | * iterate on all the gc ptrarray and decrement the refcounts, freeing |
| 91 | * if we reach 0.) |
| 92 | * (note to implementor: we calculate the dependency graph when |
| 93 | * bt_ctf_iter_read_event() is executed after a |
| 94 | * bt_ctf_iter_add_callback(). Beware that it is valid to create/add |
| 95 | * callbacks/read/add more callbacks/read some more.) |
| 96 | */ |
| 97 | int bt_ctf_iter_add_callback(struct bt_ctf_iter *iter, |
| 98 | bt_intern_str event, void *private_data, int flags, |
| 99 | enum bt_cb_ret (*callback)(struct bt_ctf_event *ctf_data, |
| 100 | void *caller_data), |
| 101 | struct bt_dependencies *depends, |
| 102 | struct bt_dependencies *weak_depends, |
| 103 | struct bt_dependencies *provides); |
| 104 | |
| 105 | /* |
| 106 | * For flags parameter above. |
| 107 | */ |
| 108 | enum { |
| 109 | BT_FLAGS_FREE_PRIVATE_DATA = (1 << 0), |
| 110 | }; |
| 111 | |
| 112 | #ifdef __cplusplus |
| 113 | } |
| 114 | #endif |
| 115 | |
| 116 | #endif /*_BABELTRACE_CTF_CALLBACKS_H */ |