Split CTF IR and CTF writer APIs and implementations
[babeltrace.git] / include / babeltrace / ctf-ir / stream-class.h
CommitLineData
adc315b8
JG
1#ifndef BABELTRACE_CTF_IR_STREAM_CLASS_H
2#define BABELTRACE_CTF_IR_STREAM_CLASS_H
3
4/*
5 * BabelTrace - CTF IR: Stream Class
6 *
de9dd397 7 * Copyright 2014 Jérémie Galarneau <jeremie.galarneau@efficios.com>
adc315b8
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
48d711a2 33#include <stdint.h>
9d408fca 34
50842bdc 35/* For bt_visitor */
8bf65fbd 36#include <babeltrace/ctf-ir/visitor.h>
48d711a2 37
adc315b8
JG
38#ifdef __cplusplus
39extern "C" {
40#endif
41
594a3fb7
PP
42/**
43@defgroup ctfirstreamclass CTF IR stream class
44@ingroup ctfir
45@brief CTF IR stream class.
46
6dd2bd0c
PP
47@code
48#include <babeltrace/ctf-ir/stream-class.h>
49@endcode
50
319f672c 51@note
dfeca116
PP
52See \ref ctfwriterstreamclass which documents additional CTF IR stream
53class functions exclusive to the CTF writer mode.
319f672c 54
594a3fb7
PP
55A CTF IR <strong><em>stream class</em></strong> is a template that you
56can use to create concrete \link ctfirstream CTF IR streams\endlink.
57
58A stream class has the following properties, both of which \em must
59be unique amongst all the stream classes contained in the same
60\link ctfirtraceclass CTF IR trace class\endlink:
61
62- A \b name.
63- A numeric \b ID.
64
65In the Babeltrace CTF IR system, a \link ctfirtraceclass trace class\endlink
66contains zero or more stream classes,
67and a stream class contains zero or more
68\link ctfireventclass event classes\endlink.
69You can add an event class
50842bdc 70to a stream class with bt_stream_class_add_event_class().
594a3fb7 71You can add a stream class to a trace class with
50842bdc 72bt_trace_add_stream_class().
594a3fb7
PP
73
74A stream class owns three \link ctfirfieldtypes field types\endlink:
75
76- An optional <strong>stream packet context</strong> field type, which
77 represents the \c stream.packet.context CTF scope.
78- An optional <strong>stream event header</strong> field type, which
79 represents the \c stream.event.header CTF scope.
80- An optional <strong>stream event context</strong> field type, which
81 represents the \c stream.event.context CTF scope.
82
83Those three field types \em must be structure field types as of
84Babeltrace \btversion.
85
86As per the CTF specification, the event header field type \em must
87contain a field named \c id if the stream class contains more than one
88event class.
89
90As a reminder, here's the structure of a CTF packet:
91
92@imgpacketstructure
93
94Before you can create a stream from a stream class with
50842bdc
PP
95bt_stream_create(), you \em must add the prepared stream class to a
96trace class by calling bt_trace_add_stream_class().
594a3fb7
PP
97
98As with any Babeltrace object, CTF IR stream class objects have
99<a href="https://en.wikipedia.org/wiki/Reference_counting">reference
100counts</a>. See \ref refs to learn more about the reference counting
101management of Babeltrace objects.
102
103The following functions \em freeze their stream class parameter on
104success:
105
50842bdc
PP
106- bt_trace_add_stream_class()
107- bt_event_create()
108- bt_writer_create_stream()
dfeca116 109 (\link ctfwriter CTF writer\endlink mode only)
594a3fb7
PP
110
111You cannot modify a frozen stream class: it is considered immutable,
112except for:
113
114- Adding an event class to it with
50842bdc 115 bt_stream_class_add_event_class(). If the stream class's parent
e0e2946b 116 \link ctfirtraceclass trace class\endlink is static, however,
50842bdc
PP
117 you cannot call bt_stream_class_add_event_class()
118 (see bt_trace_is_static() and bt_trace_set_is_static()).
594a3fb7
PP
119- \link refs Reference counting\endlink.
120
121@sa ctfirstream
122@sa ctfireventclass
123@sa ctfirtraceclass
dfeca116 124@sa ctfwriterstreamclass
594a3fb7
PP
125
126@file
127@brief CTF IR stream class type and functions.
128@sa ctfirstreamclass
129
130@addtogroup ctfirstreamclass
131@{
132*/
133
134/**
50842bdc 135@struct bt_stream_class
594a3fb7
PP
136@brief A CTF IR stream class.
137@sa ctfirstreamclass
138*/
50842bdc
PP
139struct bt_stream_class;
140struct bt_event_class;
141struct bt_clock;
adc315b8 142
594a3fb7
PP
143/**
144@name Creation and parent access functions
145@{
146*/
147
148/**
149@brief Creates a default CTF IR stream class named \p name­, or a
150 default unnamed stream class if \p name is \c NULL.
151
152On success, the packet context field type of the created stream class
153has the following fields:
154
155- <code>timestamp_begin</code>: a 64-bit unsigned integer field type.
156- <code>timestamp_end</code>: a 64-bit unsigned integer field type.
157- <code>content_size</code>: a 64-bit unsigned integer field type.
158- <code>packet_size</code>: a 64-bit unsigned integer field type.
159- <code>events_discarded</code>: a 64-bit unsigned integer field type.
160
161On success, the event header field type of the created stream class
162has the following fields:
163
164- <code>code</code>: a 32-bit unsigned integer field type.
165- <code>timestamp</code>: a 64-bit unsigned integer field type.
166
167You can modify those default field types after the stream class is
3dca2276
PP
168created with bt_stream_class_set_packet_context_field_type() and
169bt_stream_class_set_event_header_field_type().
594a3fb7 170
e0e2946b
PP
171@param[in] name Name of the stream class to create (copied on success),
172 or \c NULL to create an unnamed stream class.
173@returns Created default stream class, or \c NULL on error.
594a3fb7
PP
174
175@postsuccessrefcountret1
e0e2946b 176
50842bdc 177@sa bt_stream_class_create_empty(): Creates an empty stream class.
594a3fb7 178*/
50842bdc 179extern struct bt_stream_class *bt_stream_class_create(const char *name);
adc315b8 180
594a3fb7
PP
181/**
182@brief Returns the parent CTF IR trace class of the CTF IR stream
183 class \p stream_class.
184
185It is possible that the stream class was not added to a trace class
186yet, in which case this function returns \c NULL. You can add a
187stream class to a trace class with
50842bdc 188bt_trace_add_stream_class().
594a3fb7
PP
189
190@param[in] stream_class Stream class of which to get the parent
191 trace class.
192@returns Parent trace class of \p stream_class,
193 or \c NULL if \p stream_class was not
194 added to a trace class yet or on error.
195
196@prenotnull{stream_class}
c2f29fb9 197@postrefcountsame{stream_class}
594a3fb7
PP
198@postsuccessrefcountretinc
199
50842bdc 200@sa bt_trace_add_stream_class(): Add a stream class to
594a3fb7
PP
201 a trace class.
202*/
50842bdc
PP
203extern struct bt_trace *bt_stream_class_get_trace(
204 struct bt_stream_class *stream_class);
142c5610 205
594a3fb7
PP
206/** @} */
207
208/**
209@name Properties functions
210@{
211*/
212
213/**
214@brief Returns the name of the CTF IR stream class \p stream_class.
215
216On success, \p stream_class remains the sole owner of the returned
217string.
218
219@param[in] stream_class Stream class of which to get the name.
220@returns Name of stream class \p stream_class, or
221 \c NULL if \p stream_class is unnamed or
222 on error.
223
224@prenotnull{stream_class}
225@postrefcountsame{stream_class}
226
50842bdc 227@sa bt_stream_class_set_name(): Sets the name of a given
594a3fb7
PP
228 stream class.
229*/
50842bdc
PP
230extern const char *bt_stream_class_get_name(
231 struct bt_stream_class *stream_class);
69dc4535 232
594a3fb7
PP
233/**
234@brief Sets the name of the CTF IR stream class
03be3bcd
PP
235 \p stream_class to \p name, or resets the name of
236 \p stream_class.
594a3fb7 237
03be3bcd
PP
238If \p name is not \c NULL, it must be unique amongst the names of all
239the stream classes of the trace class to which you eventually add
240\p stream_class.
594a3fb7
PP
241
242@param[in] stream_class Stream class of which to set the name.
03be3bcd
PP
243@param[in] name Name of the stream class (copied on success), or
244 \c NULL to reset the name of \p stream_class
245 (make it unnamed).
594a3fb7
PP
246@returns 0 on success, or a negative value on error.
247
248@prenotnull{stream_class}
594a3fb7
PP
249@prehot{stream_class}
250@postrefcountsame{stream_class}
251
50842bdc 252@sa bt_stream_class_get_name(): Returns the name of a given
594a3fb7
PP
253 stream class.
254*/
50842bdc
PP
255extern int bt_stream_class_set_name(
256 struct bt_stream_class *stream_class, const char *name);
3ea33115 257
594a3fb7
PP
258/**
259@brief Returns the numeric ID of the CTF IR stream class \p stream_class.
2f100782 260
594a3fb7
PP
261@param[in] stream_class Stream class of which to get the numeric ID.
262@returns ID of stream class \p stream_class, or a
263 negative value on error.
264
265@prenotnull{stream_class}
266@postrefcountsame{stream_class}
267
50842bdc 268@sa bt_stream_class_set_id(): Sets the numeric ID of a given
594a3fb7
PP
269 stream class.
270*/
50842bdc
PP
271extern int64_t bt_stream_class_get_id(
272 struct bt_stream_class *stream_class);
2f100782 273
594a3fb7
PP
274/**
275@brief Sets the numeric ID of the CTF IR stream class
276 \p stream_class to \p id.
277
278\p id must be unique amongst the IDs of all the stream classes
279of the trace class to which you eventually add \p stream_class.
280
281@param[in] stream_class Stream class of which to set the numeric ID.
282@param[in] id ID of the stream class.
283@returns 0 on success, or a negative value on error.
284
285@prenotnull{stream_class}
286@prehot{stream_class}
9ac68eb1 287@pre \p id is lesser than or equal to 9223372036854775807 (\c INT64_MAX).
594a3fb7
PP
288@postrefcountsame{stream_class}
289
50842bdc 290@sa bt_stream_class_get_id(): Returns the numeric ID of a given
594a3fb7
PP
291 stream class.
292*/
50842bdc
PP
293extern int bt_stream_class_set_id(
294 struct bt_stream_class *stream_class, uint64_t id);
2f100782 295
594a3fb7 296/** @} */
adc315b8 297
594a3fb7
PP
298/**
299@name Contained field types functions
300@{
301*/
69dc4535 302
594a3fb7
PP
303/**
304@brief Returns the packet context field type of the CTF IR stream class
305 \p stream_class.
69dc4535 306
594a3fb7
PP
307@param[in] stream_class Stream class of which to get the packet
308 context field type.
309@returns Packet context field type of \p stream_class,
6b783f49
JG
310 or \c NULL if \p stream_class has no packet context
311 field type or on error.
69dc4535 312
594a3fb7 313@prenotnull{stream_class}
c2f29fb9 314@postrefcountsame{stream_class}
6b783f49
JG
315@post <strong>On success, if the return value is a field type</strong>, its
316 reference count is incremented.
0863f950 317
3dca2276 318@sa bt_stream_class_set_packet_context_field_type(): Sets the packet
594a3fb7
PP
319 context field type of a given stream class.
320*/
3dca2276 321extern struct bt_field_type *bt_stream_class_get_packet_context_field_type(
50842bdc 322 struct bt_stream_class *stream_class);
12c8a1a3 323
594a3fb7
PP
324/**
325@brief Sets the packet context field type of the CTF IR stream class
6b783f49
JG
326 \p stream_class to \p packet_context_type, or unsets the current packet
327 context field type from \p stream_class.
328
329If \p packet_context_type is \c NULL, then this function unsets the current
330packet context field type from \p stream_class, effectively making
331\p stream_class a stream class without a packet context field type.
594a3fb7 332
6b783f49
JG
333As of Babeltrace \btversion, if \p packet_context_type is not \c NULL,
334\p packet_context_type \em must be a CTF IR structure field type object.
594a3fb7
PP
335
336@param[in] stream_class Stream class of which to set the packet
337 context field type.
6b783f49
JG
338@param[in] packet_context_type Packet context field type, or \c NULL to unset
339 the current packet context field type.
594a3fb7
PP
340@returns 0 on success, or a negative value on error.
341
342@prenotnull{stream_class}
594a3fb7 343@prehot{stream_class}
6b783f49
JG
344@pre <strong>\p packet_context_type, if not \c NULL</strong>, is a CTF IR
345 structure field type.
594a3fb7 346@postrefcountsame{stream_class}
6b783f49
JG
347@post <strong>On success, if \p packet_context_type is not \c NULL</strong>,
348 the reference count of \p packet_context_type is incremented.
594a3fb7 349
3dca2276 350@sa bt_stream_class_get_packet_context_field_type(): Returns the packet
594a3fb7
PP
351 context field type of a given stream class.
352*/
3dca2276 353extern int bt_stream_class_set_packet_context_field_type(
50842bdc
PP
354 struct bt_stream_class *stream_class,
355 struct bt_field_type *packet_context_type);
12c8a1a3 356
594a3fb7
PP
357/**
358@brief Returns the event header field type of the CTF IR stream class
359 \p stream_class.
360
361@param[in] stream_class Stream class of which to get the event header
362 field type.
363@returns Event header field type of \p stream_class,
6b783f49
JG
364 or \c NULL if \p stream_class has no event header field
365 type or on error.
594a3fb7
PP
366
367@prenotnull{stream_class}
c2f29fb9 368@postrefcountsame{stream_class}
6b783f49
JG
369@post <strong>On success, if the return value is a field type</strong>, its
370 reference count is incremented.
594a3fb7 371
3dca2276 372@sa bt_stream_class_set_event_header_field_type(): Sets the event
594a3fb7
PP
373 header field type of a given stream class.
374*/
50842bdc 375extern struct bt_field_type *
3dca2276 376bt_stream_class_get_event_header_field_type(
50842bdc 377 struct bt_stream_class *stream_class);
662e778c 378
594a3fb7
PP
379/**
380@brief Sets the event header field type of the CTF IR stream class
6b783f49
JG
381 \p stream_class to \p event_header_type, or unsets the current event
382 header field type from \p stream_class.
383
384If \p event_header_type is \c NULL, then this function unsets the current
385event header field type from \p stream_class, effectively making \p stream_class
386a stream class without a event header field type.
594a3fb7 387
6b783f49
JG
388As of Babeltrace \btversion, if \p event_header_type is not \c NULL,
389\p event_header_type \em must be a CTF IR structure field type object.
594a3fb7 390
b2481397 391@param[in] stream_class Stream class of which to set the event
594a3fb7 392 header field type.
6b783f49
JG
393@param[in] event_header_type Event header field type, or \c NULL to unset
394 the current event header field type.
594a3fb7
PP
395@returns 0 on success, or a negative value on error.
396
397@prenotnull{stream_class}
594a3fb7 398@prehot{stream_class}
6b783f49
JG
399@pre <strong>\p event_header_type, if not \c NULL</strong>, is a CTF IR
400 structure field type.
594a3fb7 401@postrefcountsame{stream_class}
6b783f49
JG
402@post <strong>On success, if \p event_header_type is not \c NULL</strong>,
403 the reference count of \p event_header_type is incremented.
594a3fb7 404
3dca2276 405@sa bt_stream_class_get_event_header_field_type(): Returns the event
b2481397 406 header field type of a given stream class.
594a3fb7 407*/
3dca2276 408extern int bt_stream_class_set_event_header_field_type(
50842bdc
PP
409 struct bt_stream_class *stream_class,
410 struct bt_field_type *event_header_type);
662e778c 411
594a3fb7 412/**
6b783f49
JG
413@brief Returns the event context field type of the CTF IR stream class
414 \p stream_class.
594a3fb7 415
6b783f49
JG
416@param[in] stream_class Stream class of which to get the event context
417 field type.
418@returns Event context field type of \p stream_class,
419 or \c NULL if \p stream_class has no event context field
420 type or on error.
594a3fb7
PP
421
422@prenotnull{stream_class}
c2f29fb9 423@postrefcountsame{stream_class}
6b783f49
JG
424@post <strong>On success, if the return value is a field type</strong>,
425 its reference count is incremented.
426
594a3fb7 427
3dca2276 428@sa bt_stream_class_set_event_context_field_type(): Sets the event
6b783f49 429 context field type of a given stream class.
594a3fb7 430*/
50842bdc 431extern struct bt_field_type *
3dca2276 432bt_stream_class_get_event_context_field_type(
50842bdc 433 struct bt_stream_class *stream_class);
af181248 434
594a3fb7 435/**
6b783f49
JG
436@brief Sets the event context field type of the CTF IR stream class
437 \p stream_class to \p event_context_type, or unsets the current event
438 context field type from \p stream_class.
594a3fb7 439
6b783f49
JG
440If \p event_context_type is \c NULL, then this function unsets the current
441event context field type from \p stream_class, effectively making \p
442stream_class a stream class without a event context field type.
594a3fb7 443
6b783f49
JG
444As of Babeltrace \btversion, if \p event_context_type is not \c NULL,
445\p event_context_type \em must be a CTF IR structure field type object.
446
447@param[in] stream_class Stream class of which to set the packet
448 context field type.
449@param[in] event_context_type Event context field type, or \c NULL to unset
450 the current event context field type.
594a3fb7
PP
451@returns 0 on success, or a negative value on error.
452
453@prenotnull{stream_class}
594a3fb7 454@prehot{stream_class}
6b783f49
JG
455@pre <strong>\p event_context_type, if not \c NULL</strong>, is a CTF IR
456 structure field type.
594a3fb7 457@postrefcountsame{stream_class}
6b783f49
JG
458@post <strong>On success, if \p event_context_type is not \c NULL</strong>,
459 the reference count of \p event_context_type is incremented.
594a3fb7 460
3dca2276 461@sa bt_stream_class_get_event_context_field_type(): Returns the event context
6b783f49 462 field type of a given stream class.
594a3fb7 463*/
3dca2276 464extern int bt_stream_class_set_event_context_field_type(
50842bdc
PP
465 struct bt_stream_class *stream_class,
466 struct bt_field_type *event_context_type);
af181248 467
594a3fb7
PP
468/** @} */
469
470/**
471@name Event class children functions
472@{
473*/
474
475/**
476@brief Returns the number of event classes contained in the
477 CTF IR stream class \p stream_class.
478
479@param[in] stream_class Stream class of which to get the number
480 of children event classes.
481@returns Number of children event classes
482 contained in \p stream_class, or
483 a negative value on error.
484
485@prenotnull{stream_class}
486@postrefcountsame{stream_class}
487*/
50842bdc
PP
488extern int64_t bt_stream_class_get_event_class_count(
489 struct bt_stream_class *stream_class);
594a3fb7
PP
490
491/**
492@brief Returns the event class at index \p index in the CTF IR stream
493 class \p stream_class.
494
495@param[in] stream_class Stream class of which to get the event class.
496@param[in] index Index of the event class to find.
497@returns Event class at index \p index, or \c NULL
498 on error.
499
500@prenotnull{stream_class}
501@pre \p index is lesser than the number of event classes contained in the
502 stream class \p stream_class (see
50842bdc 503 bt_stream_class_get_event_class_count()).
594a3fb7
PP
504@postrefcountsame{stream_class}
505@postsuccessrefcountretinc
506
50842bdc 507@sa bt_stream_class_get_event_class_by_id(): Finds an event class
594a3fb7 508 by ID.
594a3fb7 509*/
50842bdc
PP
510extern struct bt_event_class *bt_stream_class_get_event_class_by_index(
511 struct bt_stream_class *stream_class, uint64_t index);
594a3fb7 512
594a3fb7
PP
513/**
514@brief Returns the event class with ID \c id found in the CTF IR stream
515 class \p stream_class.
516
517@param[in] stream_class Stream class of which to get the event class.
518@param[in] id ID of the event class to find.
519@returns Event class with ID \p id, or \c NULL
520 on error.
521
522@prenotnull{stream_class}
523@postrefcountsame{stream_class}
524@postsuccessrefcountretinc
594a3fb7 525*/
50842bdc
PP
526extern struct bt_event_class *bt_stream_class_get_event_class_by_id(
527 struct bt_stream_class *stream_class, uint64_t id);
594a3fb7
PP
528
529/**
530@brief Adds the CTF IR event class \p event_class to the
531 CTF IR stream class \p stream_class.
532
533On success, \p event_class becomes the child of \p stream_class.
534
535You can only add a given event class to one stream class.
536
537You can call this function even if \p stream_class is frozen. Adding
538event classes is the only operation that is permitted
539on a frozen stream class.
540
4cdafd51
PP
541This function tries to resolve the needed
542\link ctfirfieldtypes CTF IR field type\endlink of the dynamic field
543types that are found anywhere in the context or payload field
544types of \p event_class. If any automatic resolving fails:
545
546- If the needed field type should be found in one of the root field
547 types of \p event_class or \p stream_class, this function fails.
548- If \p stream_class is the child of a
549 \link ctfirtraceclass CTF IR trace class\endlink (it was added
50842bdc 550 with bt_trace_add_stream_class()), this function fails.
4cdafd51
PP
551- If \p stream_class is not the child of a trace class yet, the
552 automatic resolving is reported to the next call to
50842bdc 553 bt_trace_add_stream_class() with \p stream_class.
4cdafd51 554
594a3fb7
PP
555@param[in] stream_class Stream class to which to add \p event_class.
556@param[in] event_class Event class to add to \p stream_class.
557@returns 0 on success, or a negative value on error.
558
559@prenotnull{stream_class}
560@prenotnull{event_class}
561@prehot{event_class}
562@postrefcountsame{stream_class}
563@postsuccessrefcountinc{event_class}
2fc61597 564@postsuccessfrozen{event_class}
594a3fb7 565*/
50842bdc
PP
566extern int bt_stream_class_add_event_class(
567 struct bt_stream_class *stream_class,
568 struct bt_event_class *event_class);
594a3fb7
PP
569
570/** @} */
571
572/**
573@name Misc. function
574@{
575*/
576
577/**
578@brief Accepts the visitor \p visitor to visit the hierarchy of the
579 CTF IR stream class \p stream_class.
580
581This function traverses the hierarchy of \p stream_class in pre-order
582and calls \p visitor on each element.
583
584The stream class itself is visited first, and then all its children
585event classes.
586
587@param[in] stream_class Stream class to visit.
588@param[in] visitor Visiting function.
589@param[in] data User data.
590@returns 0 on success, or a negative value on error.
591
592@prenotnull{stream_class}
593@prenotnull{visitor}
594*/
50842bdc
PP
595extern int bt_stream_class_visit(struct bt_stream_class *stream_class,
596 bt_visitor visitor, void *data);
8bf65fbd 597
594a3fb7
PP
598/** @} */
599
600/** @} */
601
adc315b8
JG
602#ifdef __cplusplus
603}
604#endif
605
606#endif /* BABELTRACE_CTF_IR_STREAM_CLASS_H */
This page took 0.071912 seconds and 4 git commands to generate.