Commit | Line | Data |
---|---|---|
8c18d80b PP |
1 | #ifndef BABELTRACE_CTF_WRITER_STREAM_H |
2 | #define BABELTRACE_CTF_WRITER_STREAM_H | |
3 | ||
46bd0f2b JG |
4 | /* |
5 | * BabelTrace - CTF Writer: Stream | |
6 | * | |
de9dd397 | 7 | * Copyright 2013, 2014 Jérémie Galarneau <jeremie.galarneau@efficios.com> |
46bd0f2b JG |
8 | * |
9 | * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com> | |
10 | * | |
11 | * Permission is hereby granted, free of charge, to any person obtaining a copy | |
12 | * of this software and associated documentation files (the "Software"), to deal | |
13 | * in the Software without restriction, including without limitation the rights | |
14 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
15 | * copies of the Software, and to permit persons to whom the Software is | |
16 | * furnished to do so, subject to the following conditions: | |
17 | * | |
18 | * The above copyright notice and this permission notice shall be included in | |
19 | * all copies or substantial portions of the Software. | |
20 | * | |
21 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
22 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
23 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
24 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
25 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
26 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
27 | * SOFTWARE. | |
28 | * | |
29 | * The Common Trace Format (CTF) Specification is available at | |
30 | * http://www.efficios.com/ctf | |
31 | */ | |
32 | ||
50842bdc | 33 | #include <babeltrace/ctf-ir/event.h> |
3f043b05 | 34 | #include <babeltrace/ctf-ir/stream.h> |
8c18d80b PP |
35 | #include <babeltrace/ctf-writer/stream-class.h> |
36 | ||
37 | #ifdef __cplusplus | |
38 | extern "C" { | |
39 | #endif | |
40 | ||
41 | /* | |
50842bdc | 42 | * bt_stream_get_discarded_events_count: get the number of discarded |
8c18d80b PP |
43 | * events associated with this stream. |
44 | * | |
45 | * Note that discarded events are not stored if the stream's packet | |
46 | * context has no "events_discarded" field. An error will be returned | |
47 | * in that case. | |
48 | * | |
49 | * @param stream Stream instance. | |
50 | * | |
51 | * Returns the number of discarded events, a negative value on error. | |
52 | */ | |
50842bdc PP |
53 | extern int bt_stream_get_discarded_events_count( |
54 | struct bt_stream *stream, uint64_t *count); | |
8c18d80b PP |
55 | |
56 | /* | |
50842bdc | 57 | * bt_stream_append_discarded_events: increment discarded events count. |
8c18d80b PP |
58 | * |
59 | * Increase the current packet's discarded event count. Has no effect if the | |
60 | * stream class' packet context has no "events_discarded" field. | |
61 | * | |
62 | * @param stream Stream instance. | |
63 | * @param event_count Number of discarded events to add to the stream's current | |
64 | * packet. | |
65 | */ | |
50842bdc | 66 | extern void bt_stream_append_discarded_events(struct bt_stream *stream, |
8c18d80b PP |
67 | uint64_t event_count); |
68 | ||
69 | /* | |
50842bdc | 70 | * bt_stream_append_event: append an event to the stream. |
8c18d80b PP |
71 | * |
72 | * Append "event" to the stream's current packet. The stream's associated clock | |
73 | * will be sampled during this call. The event shall not be modified after | |
74 | * being appended to a stream. The stream will share the event's ownership by | |
75 | * incrementing its reference count. The current packet is not flushed to disk | |
50842bdc | 76 | * until the next call to bt_stream_flush. |
8c18d80b PP |
77 | * |
78 | * The stream event context will be sampled for every appended event if | |
79 | * a stream event context was defined. | |
80 | * | |
81 | * @param stream Stream instance. | |
82 | * @param event Event instance to append to the stream's current packet. | |
83 | * | |
84 | * Returns 0 on success, a negative value on error. | |
85 | */ | |
50842bdc PP |
86 | extern int bt_stream_append_event(struct bt_stream *stream, |
87 | struct bt_event *event); | |
8c18d80b PP |
88 | |
89 | /* | |
50842bdc | 90 | * bt_stream_get_packet_header: get a stream's packet header. |
8c18d80b PP |
91 | * |
92 | * @param stream Stream instance. | |
93 | * | |
94 | * Returns a field instance on success, NULL on error. | |
95 | */ | |
50842bdc PP |
96 | extern struct bt_field *bt_stream_get_packet_header( |
97 | struct bt_stream *stream); | |
8c18d80b PP |
98 | |
99 | /* | |
50842bdc | 100 | * bt_stream_set_packet_header: set a stream's packet header. |
8c18d80b PP |
101 | * |
102 | * The packet header's type must match the trace's packet header | |
103 | * type. | |
104 | * | |
105 | * @param stream Stream instance. | |
106 | * @param packet_header Packet header instance. | |
107 | * | |
108 | * Returns a field instance on success, NULL on error. | |
109 | */ | |
50842bdc PP |
110 | extern int bt_stream_set_packet_header( |
111 | struct bt_stream *stream, | |
112 | struct bt_field *packet_header); | |
8c18d80b PP |
113 | |
114 | /* | |
50842bdc | 115 | * bt_stream_get_packet_context: get a stream's packet context. |
8c18d80b PP |
116 | * |
117 | * @param stream Stream instance. | |
118 | * | |
119 | * Returns a field instance on success, NULL on error. | |
120 | */ | |
50842bdc PP |
121 | extern struct bt_field *bt_stream_get_packet_context( |
122 | struct bt_stream *stream); | |
8c18d80b PP |
123 | |
124 | /* | |
50842bdc | 125 | * bt_stream_set_packet_context: set a stream's packet context. |
8c18d80b PP |
126 | * |
127 | * The packet context's type must match the stream class' packet | |
128 | * context type. | |
129 | * | |
130 | * @param stream Stream instance. | |
131 | * @param packet_context Packet context field instance. | |
132 | * | |
133 | * Returns a field instance on success, NULL on error. | |
134 | */ | |
50842bdc PP |
135 | extern int bt_stream_set_packet_context( |
136 | struct bt_stream *stream, | |
137 | struct bt_field *packet_context); | |
8c18d80b PP |
138 | |
139 | /* | |
50842bdc | 140 | * bt_stream_flush: flush a stream. |
8c18d80b PP |
141 | * |
142 | * The stream's current packet's events will be flushed, thus closing the | |
143 | * current packet. Events subsequently appended to the stream will be | |
144 | * added to a new packet. | |
145 | * | |
146 | * Flushing will also set the packet context's default attributes if | |
147 | * they remained unset while populating the current packet. These default | |
148 | * attributes, along with their expected types, are detailed in stream-class.h. | |
149 | * | |
150 | * @param stream Stream instance. | |
151 | * | |
152 | * Returns 0 on success, a negative value on error. | |
153 | */ | |
50842bdc | 154 | extern int bt_stream_flush(struct bt_stream *stream); |
8c18d80b | 155 | |
50842bdc | 156 | extern int bt_stream_is_writer(struct bt_stream *stream); |
98a4cbef | 157 | |
50842bdc PP |
158 | /* Pre-2.0 CTF writer compatibility */ |
159 | #define bt_ctf_stream_get_discarded_events_count bt_stream_get_discarded_events_count | |
160 | #define bt_ctf_stream_append_discarded_events bt_stream_append_discarded_events | |
161 | #define bt_ctf_stream_append_event bt_stream_append_event | |
162 | #define bt_ctf_stream_get_packet_context bt_stream_get_packet_context | |
163 | #define bt_ctf_stream_flush bt_stream_flush | |
164 | ||
165 | extern void bt_ctf_stream_get(struct bt_stream *stream); | |
166 | extern void bt_ctf_stream_put(struct bt_stream *stream); | |
8c18d80b PP |
167 | |
168 | #ifdef __cplusplus | |
169 | } | |
170 | #endif | |
171 | ||
172 | #endif /* BABELTRACE_CTF_WRITER_STREAM_H */ |