Move to kernel style SPDX license identifiers
[babeltrace.git] / include / babeltrace2-ctf-writer / stream.h
CommitLineData
46bd0f2b 1/*
0235b0db 2 * SPDX-License-Identifier: MIT
46bd0f2b 3 *
0235b0db 4 * Copyright (C) 2010-2019 EfficiOS Inc. and Linux Foundation
46bd0f2b
JG
5 */
6
0235b0db
MJ
7#ifndef BABELTRACE2_CTF_WRITER_STREAM_H
8#define BABELTRACE2_CTF_WRITER_STREAM_H
9
3dca2276 10#include <stdint.h>
8c18d80b
PP
11
12#ifdef __cplusplus
13extern "C" {
14#endif
15
3dca2276
PP
16struct bt_ctf_stream;
17struct bt_ctf_event;
18
8c18d80b 19/*
3dca2276 20 * bt_ctf_stream_get_discarded_events_count: get the number of discarded
8c18d80b
PP
21 * events associated with this stream.
22 *
23 * Note that discarded events are not stored if the stream's packet
24 * context has no "events_discarded" field. An error will be returned
25 * in that case.
26 *
27 * @param stream Stream instance.
28 *
29 * Returns the number of discarded events, a negative value on error.
30 */
3dca2276
PP
31extern int bt_ctf_stream_get_discarded_events_count(
32 struct bt_ctf_stream *stream, uint64_t *count);
8c18d80b
PP
33
34/*
3dca2276 35 * bt_ctf_stream_append_discarded_events: increment discarded events count.
8c18d80b
PP
36 *
37 * Increase the current packet's discarded event count. Has no effect if the
38 * stream class' packet context has no "events_discarded" field.
39 *
40 * @param stream Stream instance.
41 * @param event_count Number of discarded events to add to the stream's current
42 * packet.
43 */
3dca2276 44extern void bt_ctf_stream_append_discarded_events(struct bt_ctf_stream *stream,
8c18d80b
PP
45 uint64_t event_count);
46
47/*
3dca2276 48 * bt_ctf_stream_append_event: append an event to the stream.
8c18d80b
PP
49 *
50 * Append "event" to the stream's current packet. The stream's associated clock
51 * will be sampled during this call. The event shall not be modified after
52 * being appended to a stream. The stream will share the event's ownership by
53 * incrementing its reference count. The current packet is not flushed to disk
3dca2276 54 * until the next call to bt_ctf_stream_flush.
8c18d80b
PP
55 *
56 * The stream event context will be sampled for every appended event if
57 * a stream event context was defined.
58 *
59 * @param stream Stream instance.
60 * @param event Event instance to append to the stream's current packet.
61 *
62 * Returns 0 on success, a negative value on error.
63 */
3dca2276
PP
64extern int bt_ctf_stream_append_event(struct bt_ctf_stream *stream,
65 struct bt_ctf_event *event);
8c18d80b
PP
66
67/*
3dca2276 68 * bt_ctf_stream_get_packet_header: get a stream's packet header.
8c18d80b
PP
69 *
70 * @param stream Stream instance.
71 *
72 * Returns a field instance on success, NULL on error.
73 */
3dca2276
PP
74extern struct bt_ctf_field *bt_ctf_stream_get_packet_header(
75 struct bt_ctf_stream *stream);
8c18d80b
PP
76
77/*
3dca2276 78 * bt_ctf_stream_set_packet_header: set a stream's packet header.
8c18d80b
PP
79 *
80 * The packet header's type must match the trace's packet header
81 * type.
82 *
83 * @param stream Stream instance.
84 * @param packet_header Packet header instance.
85 *
86 * Returns a field instance on success, NULL on error.
87 */
3dca2276
PP
88extern int bt_ctf_stream_set_packet_header(
89 struct bt_ctf_stream *stream,
90 struct bt_ctf_field *packet_header);
8c18d80b
PP
91
92/*
3dca2276 93 * bt_ctf_stream_get_packet_context: get a stream's packet context.
8c18d80b
PP
94 *
95 * @param stream Stream instance.
96 *
97 * Returns a field instance on success, NULL on error.
98 */
3dca2276
PP
99extern struct bt_ctf_field *bt_ctf_stream_get_packet_context(
100 struct bt_ctf_stream *stream);
8c18d80b
PP
101
102/*
3dca2276 103 * bt_ctf_stream_set_packet_context: set a stream's packet context.
8c18d80b
PP
104 *
105 * The packet context's type must match the stream class' packet
106 * context type.
107 *
108 * @param stream Stream instance.
109 * @param packet_context Packet context field instance.
110 *
111 * Returns a field instance on success, NULL on error.
112 */
3dca2276
PP
113extern int bt_ctf_stream_set_packet_context(
114 struct bt_ctf_stream *stream,
115 struct bt_ctf_field *packet_context);
8c18d80b
PP
116
117/*
3dca2276 118 * bt_ctf_stream_flush: flush a stream.
8c18d80b
PP
119 *
120 * The stream's current packet's events will be flushed, thus closing the
121 * current packet. Events subsequently appended to the stream will be
122 * added to a new packet.
123 *
124 * Flushing will also set the packet context's default attributes if
125 * they remained unset while populating the current packet. These default
126 * attributes, along with their expected types, are detailed in stream-class.h.
127 *
128 * @param stream Stream instance.
129 *
130 * Returns 0 on success, a negative value on error.
131 */
3dca2276
PP
132extern int bt_ctf_stream_flush(struct bt_ctf_stream *stream);
133
134extern int bt_ctf_stream_is_writer(struct bt_ctf_stream *stream);
135
136extern
137struct bt_ctf_stream *bt_ctf_stream_create(
138 struct bt_ctf_stream_class *stream_class,
139 const char *name, uint64_t id);
140
141extern struct bt_ctf_stream_class *bt_ctf_stream_get_class(
142 struct bt_ctf_stream *stream);
143
144extern const char *bt_ctf_stream_get_name(struct bt_ctf_stream *stream);
8c18d80b 145
3dca2276 146extern int64_t bt_ctf_stream_get_id(struct bt_ctf_stream *stream);
98a4cbef 147
50842bdc 148/* Pre-2.0 CTF writer compatibility */
3dca2276
PP
149static inline
150void bt_ctf_stream_get(struct bt_ctf_stream *stream)
151{
e1e02a22 152 bt_ctf_object_get_ref(stream);
3dca2276
PP
153}
154
155/* Pre-2.0 CTF writer compatibility */
156static inline
157void bt_ctf_stream_put(struct bt_ctf_stream *stream)
158{
e1e02a22 159 bt_ctf_object_put_ref(stream);
3dca2276 160}
8c18d80b
PP
161
162#ifdef __cplusplus
163}
164#endif
165
924dc299 166#endif /* BABELTRACE2_CTF_WRITER_STREAM_H */
This page took 0.073152 seconds and 4 git commands to generate.