| 1 | /* |
| 2 | * SPDX-License-Identifier: MIT |
| 3 | * |
| 4 | * Copyright 2013, 2014 Jérémie Galarneau <jeremie.galarneau@efficios.com> |
| 5 | * |
| 6 | * The Common Trace Format (CTF) Specification is available at |
| 7 | * http://www.efficios.com/ctf |
| 8 | */ |
| 9 | |
| 10 | #ifndef BABELTRACE_CTF_WRITER_STREAM_H |
| 11 | #define BABELTRACE_CTF_WRITER_STREAM_H |
| 12 | |
| 13 | #include "common/assert.h" |
| 14 | #include "common/macros.h" |
| 15 | #include <babeltrace2-ctf-writer/stream.h> |
| 16 | #include "ctfser/ctfser.h" |
| 17 | #include <stdint.h> |
| 18 | |
| 19 | #include "assert-pre.h" |
| 20 | #include "object.h" |
| 21 | #include "stream.h" |
| 22 | #include "utils.h" |
| 23 | |
| 24 | struct bt_ctf_stream_common; |
| 25 | |
| 26 | struct bt_ctf_stream_common { |
| 27 | struct bt_ctf_object base; |
| 28 | int64_t id; |
| 29 | struct bt_ctf_stream_class_common *stream_class; |
| 30 | GString *name; |
| 31 | }; |
| 32 | |
| 33 | int bt_ctf_stream_common_initialize( |
| 34 | struct bt_ctf_stream_common *stream, |
| 35 | struct bt_ctf_stream_class_common *stream_class, const char *name, |
| 36 | uint64_t id, bt_ctf_object_release_func release_func); |
| 37 | |
| 38 | void bt_ctf_stream_common_finalize(struct bt_ctf_stream_common *stream); |
| 39 | |
| 40 | static inline |
| 41 | struct bt_ctf_stream_class_common *bt_ctf_stream_common_borrow_class( |
| 42 | struct bt_ctf_stream_common *stream) |
| 43 | { |
| 44 | BT_ASSERT_DBG(stream); |
| 45 | return stream->stream_class; |
| 46 | } |
| 47 | |
| 48 | static inline |
| 49 | const char *bt_ctf_stream_common_get_name(struct bt_ctf_stream_common *stream) |
| 50 | { |
| 51 | BT_CTF_ASSERT_PRE_NON_NULL(stream, "Stream"); |
| 52 | return stream->name ? stream->name->str : NULL; |
| 53 | } |
| 54 | |
| 55 | static inline |
| 56 | int64_t bt_ctf_stream_common_get_id(struct bt_ctf_stream_common *stream) |
| 57 | { |
| 58 | int64_t ret; |
| 59 | |
| 60 | BT_CTF_ASSERT_PRE_NON_NULL(stream, "Stream"); |
| 61 | ret = stream->id; |
| 62 | if (ret < 0) { |
| 63 | BT_LOGT("Stream's ID is not set: addr=%p, name=\"%s\"", |
| 64 | stream, bt_ctf_stream_common_get_name(stream)); |
| 65 | } |
| 66 | |
| 67 | return ret; |
| 68 | } |
| 69 | |
| 70 | struct bt_ctf_stream { |
| 71 | struct bt_ctf_stream_common common; |
| 72 | struct bt_ctf_field *packet_header; |
| 73 | struct bt_ctf_field *packet_context; |
| 74 | |
| 75 | /* Array of pointers to bt_ctf_event for the current packet */ |
| 76 | GPtrArray *events; |
| 77 | struct bt_ctfser ctfser; |
| 78 | unsigned int flushed_packet_count; |
| 79 | uint64_t discarded_events; |
| 80 | uint64_t last_ts_end; |
| 81 | }; |
| 82 | |
| 83 | struct bt_ctf_stream *bt_ctf_stream_create_with_id( |
| 84 | struct bt_ctf_stream_class *stream_class, |
| 85 | const char *name, uint64_t id); |
| 86 | |
| 87 | #endif /* BABELTRACE_CTF_WRITER_STREAM_H */ |