stream.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. #ifndef BABELTRACE_CTF_WRITER_STREAM_H
  2. #define BABELTRACE_CTF_WRITER_STREAM_H
  3. /*
  4. * BabelTrace - CTF Writer: Stream
  5. *
  6. * Copyright 2013, 2014 Jérémie Galarneau <jeremie.galarneau@efficios.com>
  7. *
  8. * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com>
  9. *
  10. * Permission is hereby granted, free of charge, to any person obtaining a copy
  11. * of this software and associated documentation files (the "Software"), to deal
  12. * in the Software without restriction, including without limitation the rights
  13. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  14. * copies of the Software, and to permit persons to whom the Software is
  15. * furnished to do so, subject to the following conditions:
  16. *
  17. * The above copyright notice and this permission notice shall be included in
  18. * all copies or substantial portions of the Software.
  19. *
  20. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  21. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  22. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  23. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  24. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  25. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  26. * SOFTWARE.
  27. *
  28. * The Common Trace Format (CTF) Specification is available at
  29. * http://www.efficios.com/ctf
  30. */
  31. #include <babeltrace/ctf-writer/stream-class.h>
  32. struct bt_ctf_stream;
  33. #ifdef __cplusplus
  34. extern "C" {
  35. #endif
  36. /*
  37. * bt_ctf_stream_append_discarded_events: increment discarded events count.
  38. *
  39. * Increase the current packet's discarded event count. Has no effect if the
  40. * stream class' packet context has no "events_discarded" field.
  41. *
  42. * @param stream Stream instance.
  43. * @param event_count Number of discarded events to add to the stream's current
  44. * packet.
  45. */
  46. extern void bt_ctf_stream_append_discarded_events(struct bt_ctf_stream *stream,
  47. uint64_t event_count);
  48. /*
  49. * bt_ctf_stream_append_event: append an event to the stream.
  50. *
  51. * Append "event" to the stream's current packet. The stream's associated clock
  52. * will be sampled during this call. The event shall not be modified after
  53. * being appended to a stream. The stream will share the event's ownership by
  54. * incrementing its reference count. The current packet is not flushed to disk
  55. * until the next call to bt_ctf_stream_flush.
  56. *
  57. * The stream event context will be sampled for every appended event if
  58. * a stream event context was defined.
  59. *
  60. * @param stream Stream instance.
  61. * @param event Event instance to append to the stream's current packet.
  62. *
  63. * Returns 0 on success, a negative value on error.
  64. */
  65. extern int bt_ctf_stream_append_event(struct bt_ctf_stream *stream,
  66. struct bt_ctf_event *event);
  67. /*
  68. * bt_ctf_stream_get_packet_context: get a stream's packet context.
  69. *
  70. * @param stream Stream instance.
  71. *
  72. * Returns a field instance on success, NULL on error.
  73. */
  74. extern struct bt_ctf_field *bt_ctf_stream_get_packet_context(
  75. struct bt_ctf_stream *stream);
  76. /*
  77. * bt_ctf_stream_flush: flush a stream.
  78. *
  79. * The stream's current packet's events will be flushed, thus closing the
  80. * current packet. Events subsequently appended to the stream will be
  81. * added to a new packet.
  82. *
  83. * Flushing will also set the packet context's default attributes if
  84. * they remained unset while populating the current packet. These default
  85. * attributes, along with their expected types, are detailed in stream-class.h.
  86. *
  87. * @param stream Stream instance.
  88. *
  89. * Returns 0 on success, a negative value on error.
  90. */
  91. extern int bt_ctf_stream_flush(struct bt_ctf_stream *stream);
  92. /*
  93. * bt_ctf_stream_get and bt_ctf_stream_put: increment and decrement the
  94. * stream's reference count.
  95. *
  96. * You may also use bt_ctf_get() and bt_ctf_put() with stream objects.
  97. *
  98. * These functions ensure that the stream won't be destroyed while it
  99. * is in use. The same number of get and put (plus one extra put to
  100. * release the initial reference done at creation) have to be done to
  101. * destroy a stream.
  102. *
  103. * When the stream's reference count is decremented to 0 by a
  104. * bt_ctf_stream_put, the stream is freed.
  105. *
  106. * @param stream Stream instance.
  107. */
  108. extern void bt_ctf_stream_get(struct bt_ctf_stream *stream);
  109. extern void bt_ctf_stream_put(struct bt_ctf_stream *stream);
  110. #ifdef __cplusplus
  111. }
  112. #endif
  113. #endif /* BABELTRACE_CTF_WRITER_STREAM_H */