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