context.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. #ifndef _BABELTRACE_CONTEXT_H
  2. #define _BABELTRACE_CONTEXT_H
  3. /*
  4. * BabelTrace
  5. *
  6. * context header
  7. *
  8. * Copyright 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 <unistd.h>
  33. #include <babeltrace/format.h>
  34. #ifdef __cplusplus
  35. extern "C" {
  36. #endif
  37. /* struct bt_context is opaque to the user */
  38. struct bt_context;
  39. struct bt_stream_pos;
  40. struct bt_ctf_event;
  41. /*
  42. * bt_context_create : create a Babeltrace context
  43. *
  44. * Allocate a new context. The creation of the context sets the refcount
  45. * to 1.
  46. *
  47. * Returns an allocated context on success and NULL on error
  48. */
  49. struct bt_context *bt_context_create(void);
  50. /*
  51. * bt_context_add_trace : Add a trace by path to the context
  52. *
  53. * Open a trace.
  54. *
  55. * path is the path to the trace, it is not recursive. If "path" is NULL,
  56. * stream_list is used instead as a list of mmap streams to open for the trace.
  57. *
  58. * format is a string containing the format name in which the trace was
  59. * produced.
  60. *
  61. * packet_seek can be NULL to use the default packet_seek handler provided by
  62. * the trace format. If non-NULL, it is used as an override of the handler for
  63. * seeks across packets. It takes as parameter a stream position, the packet
  64. * index it needs to seek to (for SEEK_SET), and a "whence" parameter (either
  65. * SEEK_CUR: seek to next packet, or SEEK_SET: seek to packet at packet index).
  66. *
  67. * stream_list is a linked list of streams, it is used to open a trace where
  68. * the trace data is located in memory mapped areas instead of trace files,
  69. * this argument should be non-NULL when path is NULL.
  70. *
  71. * The metadata parameter acts as a metadata override when not NULL, otherwise
  72. * the format handles the metadata opening.
  73. *
  74. * Return: the trace handle id (>= 0) on success, a negative
  75. * value on error.
  76. */
  77. int bt_context_add_trace(struct bt_context *ctx, const char *path,
  78. const char *format,
  79. void (*packet_seek)(struct bt_stream_pos *pos,
  80. size_t index, int whence),
  81. struct bt_mmap_stream_list *stream_list,
  82. FILE *metadata);
  83. /*
  84. * bt_context_remove_trace: Remove a trace from the context.
  85. *
  86. * Effectively closing the trace. Return negative error value if trace
  87. * is not in context.
  88. */
  89. int bt_context_remove_trace(struct bt_context *ctx, int trace_id);
  90. /*
  91. * bt_context_get and bt_context_put : increments and decrement the
  92. * refcount of the context
  93. *
  94. * These functions ensures that the context won't be destroyed when it
  95. * is in use. The same number of get and put (plus one extra put to
  96. * release the initial reference done at creation) has to be done to
  97. * destroy a context.
  98. *
  99. * When the context refcount is decremented to 0 by a bt_context_put,
  100. * the context is freed.
  101. */
  102. void bt_context_get(struct bt_context *ctx);
  103. void bt_context_put(struct bt_context *ctx);
  104. /*
  105. * bt_ctf_get_context : get the context associated with an event
  106. *
  107. * Returns NULL on error
  108. */
  109. struct bt_context *bt_ctf_event_get_context(const struct bt_ctf_event *event);
  110. #ifdef __cplusplus
  111. }
  112. #endif
  113. #endif /* _BABELTRACE_CONTEXT_H */