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