Rename bt_ctf_X -> bt_X, maintain backward compat. for pre-2.0 CTF writer
[babeltrace.git] / include / babeltrace / ctf-ir / trace.h
CommitLineData
bc37ae52
JG
1#ifndef BABELTRACE_CTF_IR_TRACE_H
2#define BABELTRACE_CTF_IR_TRACE_H
3
4/*
5 * BabelTrace - CTF IR: Trace
6 *
7 * Copyright 2014 Jérémie Galarneau <jeremie.galarneau@efficios.com>
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/* For bt_visitor */
8bf65fbd 34#include <babeltrace/ctf-ir/visitor.h>
9d408fca
PP
35
36/* For bt_bool */
c55a9f58 37#include <babeltrace/types.h>
410d0373 38#include <stdint.h>
bc37ae52
JG
39
40#ifdef __cplusplus
41extern "C" {
42#endif
43
50842bdc 44struct bt_field_type;
9d408fca
PP
45struct bt_value;
46
06300316
PP
47/**
48@defgroup ctfirtraceclass CTF IR trace class
49@ingroup ctfir
50@brief CTF IR trace class.
51
6dd2bd0c
PP
52@code
53#include <babeltrace/ctf-ir/trace.h>
54@endcode
55
06300316
PP
56A CTF IR <strong><em>trace class</em></strong> is a descriptor of
57traces.
58
59You can obtain a trace class in two different modes:
60
50842bdc 61- <strong>Normal mode</strong>: use bt_trace_create() to create a
06300316 62 default, empty trace class.
50842bdc 63- <strong>CTF writer mode</strong>: use bt_writer_get_trace() to
dfeca116 64 get the trace class created by a given CTF writer object.
06300316
PP
65
66A trace class has the following properties:
67
68- A \b name.
8a716c8d 69- A <strong>native byte order</strong>: all the
654515f1 70 \link ctfirfieldtypes field types\endlink eventually part of the trace
50842bdc 71 class with a byte order set to #BT_BYTE_ORDER_NATIVE have this
06300316 72 "real" byte order.
4a32fda0 73- A \b UUID.
06300316
PP
74- An \b environment, which is a custom key-value mapping. Keys are
75 strings and values can be strings or integers.
76
77In the Babeltrace CTF IR system, a trace class contains zero or more
78\link ctfirstreamclass stream classes\endlink, and a stream class
79contains zero or more \link ctfireventclass event classes\endlink. You
80can add an event class to a stream class with
50842bdc
PP
81bt_stream_class_add_event_class(). You can add a stream class to a
82trace class with bt_trace_add_stream_class().
06300316 83
c1e730fe 84You can access the streams of a trace, that is, the streams which were
50842bdc
PP
85created from the trace's stream classes with bt_stream_create(),
86with bt_trace_get_stream_by_index().
c1e730fe 87
06300316
PP
88A trace class owns the <strong>trace packet header</strong>
89\link ctfirfieldtypes field type\endlink, which represents the
90\c trace.packet.header CTF scope. This field type describes the
91trace packet header fields of the traces that this trace class
92describes.
93
94The trace packet header field type \em must be a structure field type as
95of Babeltrace \btversion.
96
97As per the CTF specification, the trace packet header field type \em
98must contain a field named \c stream_id if the trace class contains more
99than one stream class.
100
101As a reminder, here's the structure of a CTF packet:
102
103@imgpacketstructure
104
105A trace class also contains zero or more
fe7041b3 106\link ctfirclockclass CTF IR clock classes\endlink.
06300316
PP
107
108@todo
109Elaborate about clock classes irt clock values.
110
2c1c33a4 111As with any Babeltrace object, CTF IR trace class objects have
06300316
PP
112<a href="https://en.wikipedia.org/wiki/Reference_counting">reference
113counts</a>. See \ref refs to learn more about the reference counting
114management of Babeltrace objects.
115
116The following functions \em freeze their trace class parameter on
117success:
118
50842bdc
PP
119- bt_trace_add_stream_class()
120- bt_writer_create_stream()
dfeca116 121 (\link ctfwriter CTF writer\endlink mode only)
06300316
PP
122
123You cannot modify a frozen trace class: it is considered immutable,
124except for:
125
126- Adding a stream class to it with
50842bdc
PP
127 bt_trace_add_stream_class().
128- Adding a CTF IR clock class to it with bt_trace_add_clock_class().
06300316
PP
129- \link refs Reference counting\endlink.
130
06300316
PP
131@sa ctfirstreamclass
132@sa ctfireventclass
133@sa ctfirclockclass
134
135@file
136@brief CTF IR trace class type and functions.
137@sa ctfirtraceclass
138
139@addtogroup ctfirtraceclass
140@{
141*/
142
143/**
50842bdc 144@struct bt_trace
06300316
PP
145@brief A CTF IR trace class.
146@sa ctfirtraceclass
147*/
50842bdc
PP
148struct bt_trace;
149struct bt_stream;
150struct bt_stream_class;
151struct bt_clock_class;
bc37ae52 152
3602afb0
PP
153/**
154@brief User function type to use with
50842bdc 155 bt_trace_add_is_static_listener().
3602afb0
PP
156
157@param[in] trace_class Trace class which is now static.
158@param[in] data User data as passed to
50842bdc 159 bt_trace_add_is_static_listener() when
3602afb0
PP
160 you added the listener.
161
162@prenotnull{trace_class}
163*/
50842bdc
PP
164typedef void (* bt_trace_is_static_listener)(
165 struct bt_trace *trace_class, void *data);
3602afb0 166
8480c8cc
PP
167/**
168@brief User function type to use with
50842bdc 169 bt_trace_add_is_static_listener().
8480c8cc
PP
170
171@param[in] trace_class Trace class to which the listener was added.
172@param[in] data User data as passed to
50842bdc 173 bt_trace_add_is_static_listener() when
8480c8cc
PP
174 you added the listener.
175
176@prenotnull{trace_class}
177*/
50842bdc
PP
178typedef void (* bt_trace_listener_removed)(
179 struct bt_trace *trace_class, void *data);
8480c8cc 180
2204c381 181/**
06300316
PP
182@name Creation function
183@{
184*/
2204c381 185
06300316
PP
186/**
187@brief Creates a default CTF IR trace class.
188
189On success, the trace packet header field type of the created trace
488e09a7
PP
190class is an empty structure field type. You can modify this default
191trace packet header field type after the trace class is created with
50842bdc
PP
192bt_trace_get_packet_header_type() and
193bt_trace_set_packet_header_type().
06300316
PP
194
195The created trace class has the following initial properties:
196
197- <strong>Name</strong>: none. You can set a name
50842bdc 198 with bt_trace_set_name().
488e09a7 199- <strong>UUID</strong>: none. You can set a UUID with
50842bdc
PP
200 bt_trace_set_uuid().
201- <strong>Native byte order</strong>: #BT_BYTE_ORDER_UNSPECIFIED.
2f4b93cd 202 You can set a native byte order with
50842bdc 203 bt_trace_set_native_byte_order().
06300316 204- <strong>Environment</strong>: empty. You can add environment entries
50842bdc
PP
205 with bt_trace_set_environment_field(),
206 bt_trace_set_environment_field_integer(), and
207 bt_trace_set_environment_field_string().
06300316
PP
208
209@returns Created trace class, or \c NULL on error.
210
211@postsuccessrefcountret1
212*/
50842bdc 213extern struct bt_trace *bt_trace_create(void);
bc37ae52 214
06300316 215/** @} */
e96045d4 216
06300316
PP
217/**
218@name Properties functions
219@{
220*/
e96045d4 221
06300316
PP
222/**
223@brief Returns the name of the CTF IR trace class \p trace_class.
7f800dc7 224
06300316
PP
225On success, \p trace_class remains the sole owner of the returned
226string. The returned string is valid as long as \p trace_class exists
227and is not modified.
bc37ae52 228
06300316
PP
229@param[in] trace_class Trace class of which to get the name.
230@returns Name of trace class \p trace_class, or
231 \c NULL if \p trace_class is unnamed or
232 on error.
3487c9f3 233
06300316
PP
234@prenotnull{trace_class}
235@postrefcountsame{trace_class}
236
50842bdc 237@sa bt_trace_set_name(): Sets the name of a given trace class.
06300316 238*/
50842bdc 239extern const char *bt_trace_get_name(struct bt_trace *trace_class);
06300316
PP
240
241/**
242@brief Sets the name of the CTF IR trace class \p trace_class
243 to \p name.
244
245@param[in] trace_class Trace class of which to set the name.
246@param[in] name Name of the trace class (copied on success).
247@returns 0 on success, or a negative value on error.
248
249@prenotnull{trace_class}
250@prenotnull{name}
251@prehot{trace_class}
252@postrefcountsame{trace_class}
253
50842bdc 254@sa bt_trace_get_name(): Returns the name of a given trace class.
06300316 255*/
50842bdc 256extern int bt_trace_set_name(struct bt_trace *trace_class,
06300316
PP
257 const char *name);
258
259/**
8a716c8d 260@brief Returns the native byte order of the CTF IR trace class
06300316
PP
261 \p trace_class.
262
263@param[in] trace_class Trace class of which to get the default byte
264 order.
488e09a7 265@returns Native byte order of \p trace_class,
50842bdc 266 or #BT_BYTE_ORDER_UNKNOWN on error.
06300316
PP
267
268@prenotnull{trace_class}
269@postrefcountsame{trace_class}
270
50842bdc 271@sa bt_trace_set_native_byte_order(): Sets the native byte order of
8a716c8d 272 a given trace class.
06300316 273*/
50842bdc
PP
274extern enum bt_byte_order bt_trace_get_native_byte_order(
275 struct bt_trace *trace_class);
06300316
PP
276
277/**
8a716c8d 278@brief Sets the native byte order of the CTF IR trace class
391c8f0d 279 \p trace_class to \p native_byte_order.
06300316 280
391c8f0d 281\p native_byte_order \em must be one of:
06300316 282
50842bdc
PP
283- #BT_BYTE_ORDER_LITTLE_ENDIAN
284- #BT_BYTE_ORDER_BIG_ENDIAN
285- #BT_BYTE_ORDER_NETWORK
d41cff38 286- <strong>If the trace is not in CTF writer mode<strong>,
50842bdc 287 #BT_BYTE_ORDER_UNSPECIFIED.
06300316 288
8a716c8d 289@param[in] trace_class Trace class of which to set the native byte
391c8f0d 290 order.
488e09a7 291@param[in] native_byte_order Native byte order of the trace class.
391c8f0d 292@returns 0 on success, or a negative value on error.
06300316
PP
293
294@prenotnull{trace_class}
06300316 295@prehot{trace_class}
50842bdc 296@pre \p native_byte_order is either #BT_BYTE_ORDER_UNSPECIFIED (if the
d41cff38 297 trace is not in CTF writer mode),
50842bdc
PP
298 #BT_BYTE_ORDER_LITTLE_ENDIAN, #BT_BYTE_ORDER_BIG_ENDIAN, or
299 #BT_BYTE_ORDER_NETWORK.
06300316
PP
300@postrefcountsame{trace_class}
301
50842bdc 302@sa bt_trace_get_native_byte_order(): Returns the native byte order of a
8a716c8d 303 given trace class.
06300316 304*/
50842bdc
PP
305extern int bt_trace_set_native_byte_order(struct bt_trace *trace_class,
306 enum bt_byte_order native_byte_order);
06300316 307
4a32fda0
PP
308/**
309@brief Returns the UUID of the CTF IR trace class \p trace_class.
310
311On success, the return value is an array of 16 bytes.
312
313@param[in] trace_class Trace class of which to get the UUID.
314@returns UUID of trace class \p trace_class, or
315 \c NULL if \p trace_class has no UUID or on error.
316
317@prenotnull{trace_class}
318@postrefcountsame{trace_class}
319
50842bdc 320@sa bt_trace_set_uuid(): Sets the UUID of a given trace class.
4a32fda0 321*/
50842bdc
PP
322extern const unsigned char *bt_trace_get_uuid(
323 struct bt_trace *trace_class);
4a32fda0
PP
324
325/**
326@brief Sets the UUID of the CTF IR trace class \p trace_class to
327 \p uuid.
328
329\p uuid \em must be an array of 16 bytes.
330
331@param[in] trace_class Trace class of which to set the UUID.
332@param[in] uuid UUID of the \p trace_class (copied on
333 success).
334@returns 0 on success, or a negative value on error.
335
336@prenotnull{trace_class}
337@prenotnull{uuid}
338@prehot{trace_class}
339@pre \p uuid is an array of 16 bytes.
340@postrefcountsame{trace_class}
341
50842bdc 342@sa bt_trace_get_uuid(): Returns the UUID of a given trace class.
4a32fda0 343*/
50842bdc 344extern int bt_trace_set_uuid(struct bt_trace *trace_class,
4a32fda0
PP
345 const unsigned char *uuid);
346
06300316
PP
347/**
348@brief Returns the number of entries contained in the environment of
349 the CTF IR trace class \p trace_class.
350
351@param[in] trace_class Trace class of which to get the number
352 of environment entries.
353@returns Number of environment entries
354 contained in \p trace_class, or
355 a negative value on error.
356
357@prenotnull{trace_class}
358@postrefcountsame{trace_class}
359*/
50842bdc
PP
360extern int64_t bt_trace_get_environment_field_count(
361 struct bt_trace *trace_class);
e6fa2160 362
06300316
PP
363/**
364@brief Returns the field name of the environment entry at index
365 \p index in the CTF IR trace class \p trace_class.
366
367On success, the returned string is valid as long as this trace class
368exists and is \em not modified. \p trace_class remains the sole owner of
369the returned string.
370
371@param[in] trace_class Trace class of which to get the name of the
372 environment entry at index \p index.
373@param[in] index Index of environment entry to find.
374@returns Name of the environment entry at index \p index
375 in \p trace_class, or \c NULL on error.
376
377@prenotnull{trace_class}
378@pre \p index is lesser than the number of environment entries in
50842bdc 379 \p trace_class (see bt_trace_get_environment_field_count()).
06300316
PP
380@postrefcountsame{trace_class}
381
50842bdc 382@sa bt_trace_get_environment_field_value_by_index(): Finds a trace class's
06300316 383 environment entry by index.
50842bdc 384@sa bt_trace_get_environment_field_value_by_name(): Finds a trace
06300316 385 class's environment entry by name.
50842bdc 386@sa bt_trace_set_environment_field(): Sets the value of a trace
06300316
PP
387 class's environment entry.
388*/
e6fa2160 389extern const char *
50842bdc
PP
390bt_trace_get_environment_field_name_by_index(
391 struct bt_trace *trace_class, uint64_t index);
e6fa2160 392
06300316
PP
393/**
394@brief Returns the value of the environment entry at index
395 \p index in the CTF IR trace class \p trace_class.
396
397@param[in] trace_class Trace class of which to get the value of the
398 environment entry at index \p index.
399@param[in] index Index of the environment entry to find.
400@returns Value of the environment entry at index \p index
401 in \p trace_class, or \c NULL on error.
402
403@prenotnull{trace_class}
404@pre \p index is lesser than the number of environment entries in
50842bdc 405 \p trace_class (see bt_trace_get_environment_field_count()).
06300316
PP
406@postrefcountsame{trace_class}
407@postsuccessrefcountretinc
408
50842bdc 409@sa bt_trace_get_environment_field_value_by_name(): Finds a trace
06300316 410 class's environment entry by name.
50842bdc 411@sa bt_trace_set_environment_field(): Sets the value of a trace
06300316
PP
412 class's environment entry.
413*/
dac5c838 414extern struct bt_value *
50842bdc 415bt_trace_get_environment_field_value_by_index(struct bt_trace *trace_class,
9ac68eb1 416 uint64_t index);
e6fa2160 417
06300316
PP
418/**
419@brief Returns the value of the environment entry named \p name
420 in the CTF IR trace class \p trace_class.
421
422@param[in] trace_class Trace class of which to get the value of the
423 environment entry named \p name.
424@param[in] name Name of the environment entry to find.
425@returns Value of the environment entry named \p name
426 in \p trace_class, or \c NULL if there's no such
427 entry or on error.
428
429@prenotnull{trace_class}
430@prenotnull{name}
431@postrefcountsame{trace_class}
432@postsuccessrefcountretinc
433
50842bdc 434@sa bt_trace_get_environment_field_value_by_index(): Finds a trace class's
06300316 435 environment entry by index.
50842bdc 436@sa bt_trace_set_environment_field(): Sets the value of a trace
06300316
PP
437 class's environment entry.
438*/
dac5c838 439extern struct bt_value *
50842bdc
PP
440bt_trace_get_environment_field_value_by_name(
441 struct bt_trace *trace_class, const char *name);
e6fa2160 442
06300316
PP
443/**
444@brief Sets the environment entry named \p name in the
445 CTF IR trace class \p trace_class to \p value.
446
447If an environment entry named \p name exists in \p trace_class, its
448value is first put, and then replaced by \p value.
449
450@param[in] trace_class Trace class of which to set the environment
451 entry.
452@param[in] name Name of the environment entry to set (copied
453 on success).
454@param[in] value Value of the environment entry named \p name.
455@returns 0 on success, or a negative value on error.
456
457@prenotnull{trace_class}
458@prenotnull{name}
459@prenotnull{value}
460@prehot{trace_class}
461@pre \p value is an
462 \link bt_value_integer_create() integer value object\endlink
463 or a
464 \link bt_value_string_create() string value object\endlink.
465@postrefcountsame{trace_class}
466@postsuccessrefcountinc{value}
467
50842bdc 468@sa bt_trace_get_environment_field_value_by_index(): Finds a trace class's
06300316 469 environment entry by index.
50842bdc 470@sa bt_trace_get_environment_field_value_by_name(): Finds a trace
06300316
PP
471 class's environment entry by name.
472*/
50842bdc
PP
473extern int bt_trace_set_environment_field(
474 struct bt_trace *trace_class, const char *name,
06300316 475 struct bt_value *value);
bc37ae52 476
06300316
PP
477/**
478@brief Sets the environment entry named \p name in the
479 CTF IR trace class \p trace_class to \p value.
480
481If an environment entry named \p name exists in \p trace_class, its
482value is first put, and then replaced by a new
483\link bt_value_integer_create() integer value object\endlink
484containing \p value.
485
486@param[in] trace_class Trace class of which to set the environment
487 entry.
488@param[in] name Name of the environment entry to set (copied
489 on success).
490@param[in] value Value of the environment entry named \p name.
491@returns 0 on success, or a negative value on error.
492
493@prenotnull{trace_class}
494@prenotnull{name}
495@prehot{trace_class}
496@postrefcountsame{trace_class}
497
50842bdc 498@sa bt_trace_set_environment_field(): Sets the value of a trace
06300316
PP
499 class's environment entry.
500*/
50842bdc
PP
501extern int bt_trace_set_environment_field_integer(
502 struct bt_trace *trace_class, const char *name,
06300316 503 int64_t value);
884cd6c3 504
06300316
PP
505/**
506@brief Sets the environment entry named \p name in the
507 CTF IR trace class \p trace_class to \p value.
508
509If an environment entry named \p name exists in \p trace_class, its
510value is first put, and then replaced by a new
511\link bt_value_string_create() string value object\endlink
512containing \p value.
513
514@param[in] trace_class Trace class of which to set the environment
515 entry.
516@param[in] name Name of the environment entry to set (copied
517 on success).
518@param[in] value Value of the environment entry named \p name
519 (copied on success).
520@returns 0 on success, or a negative value on error.
521
522@prenotnull{trace_class}
523@prenotnull{name}
524@prenotnull{value}
525@prehot{trace_class}
526@postrefcountsame{trace_class}
527
50842bdc 528@sa bt_trace_set_environment_field(): Sets the value of a trace
06300316
PP
529 class's environment entry.
530*/
50842bdc
PP
531extern int bt_trace_set_environment_field_string(
532 struct bt_trace *trace_class, const char *name,
06300316
PP
533 const char *value);
534
535/** @} */
536
537/**
538@name Contained field types functions
539@{
540*/
541
542/**
543@brief Returns the packet header field type of the CTF IR trace class
544 \p trace_class.
545
546@param[in] trace_class Trace class of which to get the packet
547 header field type.
548@returns Packet header field type of \p trace_class,
6b783f49
JG
549 or \c NULL if \p trace_class has no packet header field
550 type or on error.
06300316
PP
551
552@prenotnull{trace_class}
c2f29fb9 553@postrefcountsame{trace_class}
6b783f49
JG
554@post <strong>On success, if the return value is a field type</strong>, its
555 reference count is incremented.
06300316 556
50842bdc 557@sa bt_trace_set_packet_header_type(): Sets the packet
06300316
PP
558 header field type of a given trace class.
559*/
50842bdc
PP
560extern struct bt_field_type *bt_trace_get_packet_header_type(
561 struct bt_trace *trace_class);
06300316
PP
562
563/**
564@brief Sets the packet header field type of the CTF IR trace class
6b783f49
JG
565 \p trace_class to \p packet_header_type, or unsets the current packet
566 header field type from \p trace_class.
567
568If \p packet_header_type is \c NULL, then this function unsets the current
569packet header field type from \p trace_class, effectively making \p trace_class
570a trace without a packet header field type.
06300316 571
6b783f49
JG
572As of Babeltrace \btversion, if \p packet_header_type is not \c NULL,
573\p packet_header_type \em must be a CTF IR structure field type object.
06300316
PP
574
575@param[in] trace_class Trace class of which to set the packet
576 header field type.
6b783f49
JG
577@param[in] packet_header_type Packet header field type, or \c NULL to unset
578 the current packet header field type.
06300316
PP
579@returns 0 on success, or a negative value on error.
580
581@prenotnull{trace_class}
06300316 582@prehot{trace_class}
6b783f49
JG
583@pre <strong>\p packet_header_type, if not \c NULL</strong>, is a CTF IR
584 structure field type.
06300316 585@postrefcountsame{trace_class}
6b783f49
JG
586@post <strong>On success, if \p packet_header_type is not \c NULL</strong>,
587 the reference count of \p packet_header_type is incremented.
06300316 588
50842bdc 589@sa bt_trace_get_packet_header_type(): Returns the packet
06300316
PP
590 header field type of a given trace class.
591*/
50842bdc
PP
592extern int bt_trace_set_packet_header_type(struct bt_trace *trace_class,
593 struct bt_field_type *packet_header_type);
06300316
PP
594
595/** @} */
596
597/**
fe7041b3 598@name Contained clock classes functions
06300316
PP
599@{
600*/
601
602/**
fe7041b3 603@brief Returns the number of CTF IR clock classes contained in the
06300316
PP
604 CTF IR trace class \p trace_class.
605
606@param[in] trace_class Trace class of which to get the number
fe7041b3
PP
607 of contained clock classes.
608@returns Number of contained clock classes
06300316
PP
609 contained in \p trace_class, or a negative
610 value on error.
611
612@prenotnull{trace_class}
613@postrefcountsame{trace_class}
614*/
50842bdc
PP
615extern int64_t bt_trace_get_clock_class_count(
616 struct bt_trace *trace_class);
06300316
PP
617
618/**
fe7041b3
PP
619@brief Returns the CTF IR clock class at index \p index in the CTF
620 IR trace class \p trace_class.
06300316 621
fe7041b3
PP
622@param[in] trace_class Trace class of which to get the clock class
623 contained at index \p index.
624@param[in] index Index of the clock class to find in
625 \p trace_class.
626@returns Clock class at index \p index in \p trace_class,
627 or \c NULL on error.
06300316
PP
628
629@prenotnull{trace_class}
630@pre \p index is lesser than the number of clock classes contained in
631 the trace class \p trace_class (see
50842bdc 632 bt_trace_get_clock_class_count()).
06300316
PP
633@postrefcountsame{trace_class}
634@postsuccessrefcountretinc
635
50842bdc 636@sa bt_trace_get_clock_class_by_name(): Finds a clock class by name
fe7041b3 637 in a given trace class.
50842bdc 638@sa bt_trace_add_clock_class(): Adds a clock class to a trace class.
06300316 639*/
50842bdc
PP
640extern struct bt_clock_class *bt_trace_get_clock_class_by_index(
641 struct bt_trace *trace_class, uint64_t index);
884cd6c3 642
06300316 643/**
fe7041b3
PP
644@brief Returns the CTF IR clock class named \c name found in the CTF
645 IR trace class \p trace_class.
06300316 646
fe7041b3
PP
647@param[in] trace_class Trace class of which to get the clock class
648 named \p name.
649@param[in] name Name of the clock class to find in \p trace_class.
650@returns Clock class named \p name in \p trace_class,
651 or \c NULL on error.
06300316
PP
652
653@prenotnull{trace_class}
654@prenotnull{name}
655@postrefcountsame{trace_class}
656@postsuccessrefcountretinc
657
50842bdc 658@sa bt_trace_get_clock_class_by_index(): Returns the clock class contained
ac0c6bdd 659 in a given trace class at a given index.
50842bdc 660@sa bt_trace_add_clock_class(): Adds a clock class to a trace class.
06300316 661*/
50842bdc
PP
662extern struct bt_clock_class *bt_trace_get_clock_class_by_name(
663 struct bt_trace *trace_class, const char *name);
ef0c4a15 664
06300316
PP
665/**
666@brief Adds the CTF IR clock class \p clock_class to the CTF IR
667 trace class \p trace_class.
ef0c4a15 668
fe7041b3 669On success, \p trace_class contains \p clock_class.
06300316 670
fe7041b3
PP
671You can call this function even if \p trace_class or \p clock_class
672are frozen.
06300316
PP
673
674@param[in] trace_class Trace class to which to add \p clock_class.
675@param[in] clock_class Clock class to add to \p trace_class.
676@returns 0 on success, or a negative value on error.
677
678@prenotnull{trace_class}
679@prenotnull{clock_class}
680@postrefcountsame{trace_class}
681@postsuccessrefcountinc{clock_class}
30484384 682@post <strong>On success, if \p trace_class is frozen</strong>,
2c1c33a4 683 \p clock_class is frozen.
06300316 684
50842bdc 685@sa bt_trace_get_clock_class_by_index(): Returns the clock class contained
ac0c6bdd 686 in a given trace class at a given index.
50842bdc 687@sa bt_trace_get_clock_class_by_name(): Finds a clock class by name
fe7041b3 688 in a given trace class.
06300316 689*/
50842bdc
PP
690extern int bt_trace_add_clock_class(struct bt_trace *trace_class,
691 struct bt_clock_class *clock_class);
06300316
PP
692
693/** @} */
694
695/**
696@name Stream class children functions
697@{
698*/
699
700/**
701@brief Returns the number of stream classes contained in the
702 CTF IR trace class \p trace_class.
703
704@param[in] trace_class Trace class of which to get the number
705 of children stream classes.
706@returns Number of children stream classes
707 contained in \p trace_class, or a negative
708 value on error.
709
710@prenotnull{trace_class}
711@postrefcountsame{trace_class}
712*/
50842bdc
PP
713extern int64_t bt_trace_get_stream_class_count(
714 struct bt_trace *trace_class);
06300316
PP
715
716/**
717@brief Returns the stream class at index \p index in the CTF IR trace
718 class \p trace_class.
719
720@param[in] trace_class Trace class of which to get the stream class.
721@param[in] index Index of the stream class to find.
722@returns Stream class at index \p index, or \c NULL
723 on error.
724
725@prenotnull{trace_class}
726@pre \p index is lesser than the number of stream classes contained in
727 the trace class \p trace_class (see
50842bdc 728 bt_trace_get_stream_class_count()).
06300316 729@postrefcountsame{trace_class}
06300316 730
50842bdc
PP
731@sa bt_trace_get_stream_class_by_id(): Finds a stream class by ID.
732@sa bt_trace_add_stream_class(): Adds a stream class to a trace class.
06300316 733*/
50842bdc
PP
734extern struct bt_stream_class *bt_trace_get_stream_class_by_index(
735 struct bt_trace *trace_class, uint64_t index);
ef0c4a15 736
06300316
PP
737/**
738@brief Returns the stream class with ID \c id found in the CTF IR
739 trace class \p trace_class.
740
741@param[in] trace_class Trace class of which to get the stream class.
742@param[in] id ID of the stream class to find.
743@returns Stream class with ID \p id, or \c NULL
744 on error.
745
746@prenotnull{trace_class}
747@postrefcountsame{trace_class}
748@postsuccessrefcountretinc
749
50842bdc 750@sa bt_trace_get_stream_class_by_index(): Returns the stream class contained
ac0c6bdd 751 in a given trace class at a given index.
50842bdc 752@sa bt_trace_add_stream_class(): Adds a stream class to a trace class.
06300316 753*/
50842bdc
PP
754extern struct bt_stream_class *bt_trace_get_stream_class_by_id(
755 struct bt_trace *trace_class, uint64_t id);
4841ccc1 756
06300316
PP
757/**
758@brief Adds the CTF IR stream class \p stream_class to the
759 CTF IR trace class \p trace_class.
7e4347a3 760
06300316 761On success, \p stream_class becomes the child of \p trace_class.
bc37ae52 762
06300316 763You can only add a given stream class to one trace class.
4ed90fb3 764
06300316 765You can call this function even if \p trace_class is frozen.
bc37ae52 766
4cdafd51
PP
767This function tries to resolve the needed
768\link ctfirfieldtypes CTF IR field type\endlink of the dynamic field
769types that are found anywhere in the root field types of
770\p stream_class and of all its currently contained
771\link ctfireventclass CTF IR event classes\endlink. If any automatic
772resolving fails, then this function fails.
773
06300316
PP
774@param[in] trace_class Trace class to which to add \p stream_class.
775@param[in] stream_class Stream class to add to \p trace_class.
776@returns 0 on success, or a negative value on error.
d246b111 777
06300316
PP
778@prenotnull{trace_class}
779@prenotnull{stream_class}
780@postrefcountsame{trace_class}
781@postsuccessrefcountinc{stream_class}
2c1c33a4 782@postsuccessfrozen{stream_class}
d246b111 783
50842bdc 784@sa bt_trace_get_stream_class_by_index(): Returns the stream class contained
ac0c6bdd 785 in a given trace class at a given index.
50842bdc 786@sa bt_trace_get_stream_class_by_id(): Finds a stream class by ID.
06300316 787*/
50842bdc
PP
788extern int bt_trace_add_stream_class(struct bt_trace *trace_class,
789 struct bt_stream_class *stream_class);
06300316
PP
790
791/** @} */
792
c1e730fe
PP
793/**
794@name Stream children functions
795@{
796*/
797
798/**
799@brief Returns the number of streams contained in the CTF IR trace
800 class \p trace_class.
801
802@param[in] trace_class Trace class of which to get the number
803 of children streams.
804@returns Number of children streams
805 contained in \p trace_class, or a negative
806 value on error.
807
808@prenotnull{trace_class}
809@postrefcountsame{trace_class}
810*/
50842bdc 811extern int64_t bt_trace_get_stream_count(struct bt_trace *trace_class);
c1e730fe
PP
812
813/**
814@brief Returns the stream at index \p index in the CTF IR trace
815 class \p trace_class.
816
817@param[in] trace_class Trace class of which to get the stream.
818@param[in] index Index of the stream to find.
819@returns Stream at index \p index, or \c NULL
820 on error.
821
822@prenotnull{trace_class}
823@pre \p index is lesser than the number of streams contained in
824 the trace class \p trace_class (see
50842bdc 825 bt_trace_get_stream_count()).
c1e730fe
PP
826@postrefcountsame{trace_class}
827*/
50842bdc
PP
828extern struct bt_stream *bt_trace_get_stream_by_index(
829 struct bt_trace *trace_class, uint64_t index);
c1e730fe
PP
830
831/** @} */
832
06300316
PP
833/**
834@name Misc. functions
835@{
836*/
837
5acf2ae6
PP
838/**
839@brief Returns whether or not the CTF IR trace class \p trace_class
840 is static.
841
842It is guaranteed that a static trace class will never contain new
843streams, stream classes, or clock classes. A static class is always
844frozen.
845
50842bdc 846This function returns #BT_TRUE if bt_trace_set_is_static() was
5acf2ae6
PP
847previously called on it.
848
849@param[in] trace_class Trace class to check.
c55a9f58 850@returns #BT_TRUE if \p trace_class is static,
5acf2ae6 851
50842bdc 852@sa bt_trace_set_is_static(): Makes a trace class static.
5acf2ae6 853*/
50842bdc 854extern bt_bool bt_trace_is_static(struct bt_trace *trace_class);
5acf2ae6
PP
855
856/**
857@brief Makes the CTF IR trace class \p trace_class static.
858
859A static trace class is frozen and you cannot call any modifying
860function on it:
861
50842bdc
PP
862- bt_trace_add_stream_class()
863- bt_trace_add_clock_class()
864- bt_trace_set_environment_field()
865- bt_trace_set_environment_field_integer()
866- bt_trace_set_environment_field_string()
867- bt_trace_add_is_static_listener()
5acf2ae6 868
50842bdc 869You cannot create a stream with bt_stream_create() with any of the
5acf2ae6
PP
870stream classes of a static trace class.
871
872@param[in] trace_class Trace class to make static.
873@returns 0 on success, or a negative value on error.
874
875@prenotnull{trace_class}
876@postrefcountsame{trace_class}
877@postsuccessfrozen{trace_class}
878
50842bdc 879@sa bt_trace_is_static(): Checks whether or not a given trace class
5acf2ae6 880 is static.
50842bdc 881@sa bt_trace_add_is_static_listener(): Adds a listener to a trace
3602afb0 882 class which is called when the trace class is made static.
5acf2ae6 883*/
50842bdc 884extern int bt_trace_set_is_static(struct bt_trace *trace_class);
5acf2ae6 885
3602afb0
PP
886/**
887@brief Adds the listener \p listener to the CTF IR trace class
888 \p trace_class which is called when the trace is made static.
889
890\p listener is called with \p data, the user data, the first time
50842bdc 891bt_trace_set_is_static() is called on \p trace_class.
3602afb0 892
8480c8cc 893When the trace is destroyed, or when you remove the added listener with
50842bdc 894bt_trace_remove_is_static_listener(), \p listener_removed is called
8480c8cc
PP
895if it's not \c NULL. You can use \p listener_removed to free any dynamic
896data which exists only for the added listener. You cannot call
897any function which modifies \p trace_class during the execution of
50842bdc 898\p listener_removed, including bt_trace_remove_is_static_listener().
8480c8cc 899
3602afb0 900This function fails if \p trace_class is already static: you need to
50842bdc 901check the condition first with bt_trace_is_static().
3602afb0
PP
902
903On success, this function returns a unique numeric identifier for this
904listener within \p trace. You can use this identifier to remove the
905specific listener you added with
50842bdc 906bt_trace_remove_is_static_listener().
3602afb0 907
8480c8cc
PP
908@param[in] trace_class Trace class to which to add the
909 listener.
910@param[in] listener Listener to add to \p trace_class.
911@param[in] listener_removed Remove listener called when \p listener
912 is removed from \p trace_class, or
913 \c NULL if you don't need a remove
914 listener.
915@param[in] data User data passed when \p listener or
916 \p listener_removed is called.
917@returns A unique numeric identifier for this
918 listener on success (0 or greater), or a
919 negative value on error.
3602afb0
PP
920
921@prenotnull{trace_class}
922@prenotnull{listener}
923@pre \p trace_class is not static.
924@postrefcountsame{trace_class}
925
50842bdc 926@sa bt_trace_remove_is_static_listener(): Removes a "trace is
3602afb0
PP
927 static" listener from a trace class previously added with this
928 function.
50842bdc 929@sa bt_trace_is_static(): Checks whether or not a given trace class
3602afb0 930 is static.
50842bdc 931@sa bt_trace_set_is_static(): Makes a trace class static.
3602afb0 932*/
50842bdc
PP
933extern int bt_trace_add_is_static_listener(
934 struct bt_trace *trace_class,
935 bt_trace_is_static_listener listener,
936 bt_trace_listener_removed listener_removed, void *data);
3602afb0
PP
937
938/**
939@brief Removes the "trace is static" listener identified by
940 \p listener_id from the trace class \p trace_class.
941
942@param[in] trace_class Trace class from which to remove the listener
943 identified by \p listener_id.
944@param[in] listener_id Identifier of the listener to remove from
945 \p trace_class.
946@returns 0 if this function removed the listener, or
947 a negative value on error.
948
949@prenotnull{trace_class}
950@pre \p listener_id is the identifier of a listener that you previously
50842bdc 951 added with bt_trace_add_is_static_listener() and did not
3602afb0
PP
952 already remove with this function.
953@postrefcountsame{trace_class}
954
50842bdc 955@sa bt_trace_add_is_static_listener(): Adds a listener to a trace
3602afb0
PP
956 class which is called when the trace class is made static.
957*/
50842bdc
PP
958extern int bt_trace_remove_is_static_listener(
959 struct bt_trace *trace_class, int listener_id);
3602afb0 960
06300316
PP
961/**
962@brief Accepts the visitor \p visitor to visit the hierarchy of the
963 CTF IR trace class \p trace_class.
964
965This function traverses the hierarchy of \p trace_class in pre-order
966and calls \p visitor on each element.
967
968The trace class itself is visited first, then, for each children stream
969class, the stream class itself, and all its children event classes.
970
971@param[in] trace_class Trace class to visit.
972@param[in] visitor Visiting function.
973@param[in] data User data.
974@returns 0 on success, or a negative value on error.
975
976@prenotnull{trace_class}
977@prenotnull{visitor}
978*/
50842bdc
PP
979extern int bt_trace_visit(struct bt_trace *trace_class,
980 bt_visitor visitor, void *data);
8bf65fbd 981
06300316
PP
982/** @} */
983
35827558
PP
984/** @} */
985
50842bdc
PP
986/* Pre-2.0 CTF writer compatibility */
987#define bt_ctf_trace bt_trace
988
bc37ae52
JG
989#ifdef __cplusplus
990}
991#endif
992
993#endif /* BABELTRACE_CTF_IR_TRACE_H */
This page took 0.087826 seconds and 4 git commands to generate.