| 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 | |
| 26 | #include <babeltrace/format.h> |
| 27 | |
| 28 | /* Forward declarations */ |
| 29 | struct bt_ctf_iter; |
| 30 | struct bt_dependencies; |
| 31 | |
| 32 | enum bt_cb_ret { |
| 33 | BT_CB_OK = 0, |
| 34 | BT_CB_OK_STOP = 1, |
| 35 | BT_CB_ERROR_STOP = 2, |
| 36 | BT_CB_ERROR_CONTINUE = 3, |
| 37 | }; |
| 38 | |
| 39 | /* |
| 40 | * Receives a variable number of strings as parameter, ended with NULL. |
| 41 | */ |
| 42 | struct bt_dependencies *babeltrace_dependencies_create(const char *first, ...); |
| 43 | |
| 44 | /* |
| 45 | * struct bt_dependencies must be destroyed explicitly if not passed as |
| 46 | * parameter to a bt_iter_add_callback(). |
| 47 | */ |
| 48 | void babeltrace_dependencies_destroy(struct bt_dependencies *dep); |
| 49 | |
| 50 | /* |
| 51 | * bt_iter_add_callback: Add a callback to iterator. |
| 52 | * |
| 53 | * @iter: trace collection iterator (input) |
| 54 | * @event: event to target. 0 for all events. |
| 55 | * @private_data: private data pointer to pass to the callback |
| 56 | * @flags: specific flags controlling the behavior of this callback |
| 57 | * (or'd). |
| 58 | * |
| 59 | * @callback: function pointer to call |
| 60 | * @depends: struct bt_dependency detailing the required computation results. |
| 61 | * Ends with 0. |
| 62 | * @weak_depends: struct bt_dependency detailing the optional computation |
| 63 | * results that can be optionally consumed by this |
| 64 | * callback. |
| 65 | * @provides: struct bt_dependency detailing the computation results |
| 66 | * provided by this callback. |
| 67 | * Ends with 0. |
| 68 | * |
| 69 | * "depends", "weak_depends" and "provides" memory is handled by the |
| 70 | * babeltrace library after this call succeeds or fails. These objects |
| 71 | * can still be used by the caller until the babeltrace iterator is |
| 72 | * destroyed, but they belong to the babeltrace library. |
| 73 | * |
| 74 | * (note to implementor: we need to keep a gptrarray of struct |
| 75 | * bt_dependencies to "garbage collect" in struct bt_iter, and |
| 76 | * dependencies need to have a refcount to handle the case where they |
| 77 | * would be passed to more than one iterator. Upon iterator detroy, we |
| 78 | * iterate on all the gc ptrarray and decrement the refcounts, freeing |
| 79 | * if we reach 0.) |
| 80 | * (note to implementor: we calculate the dependency graph when |
| 81 | * bt_iter_read_event() is executed after a |
| 82 | * bt_iter_add_callback(). Beware that it is valid to create/add |
| 83 | * callbacks/read/add more callbacks/read some more.) |
| 84 | */ |
| 85 | int bt_ctf_iter_add_callback(struct bt_ctf_iter *iter, |
| 86 | bt_intern_str event, void *private_data, int flags, |
| 87 | enum bt_cb_ret (*callback)(struct bt_ctf_event *ctf_data, |
| 88 | void *caller_data), |
| 89 | struct bt_dependencies *depends, |
| 90 | struct bt_dependencies *weak_depends, |
| 91 | struct bt_dependencies *provides); |
| 92 | |
| 93 | /* |
| 94 | * For flags parameter above. |
| 95 | */ |
| 96 | enum { |
| 97 | BT_FLAGS_FREE_PRIVATE_DATA = (1 << 0), |
| 98 | }; |
| 99 | |
| 100 | #endif /*_BABELTRACE_CTF_CALLBACKS_H */ |