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