callbacks.h 4.1 KB

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