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 | ||
9d408fca | 33 | /* For bt_ctf_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 | |
41 | extern "C" { | |
42 | #endif | |
43 | ||
9d408fca PP |
44 | struct bt_ctf_field_type; |
45 | struct 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 |
56 | A CTF IR <strong><em>trace class</em></strong> is a descriptor of |
57 | traces. | |
58 | ||
59 | You can obtain a trace class in two different modes: | |
60 | ||
61 | - <strong>Normal mode</strong>: use bt_ctf_trace_create() to create a | |
62 | default, empty trace class. | |
dfeca116 PP |
63 | - <strong>CTF writer mode</strong>: use bt_ctf_writer_get_trace() to |
64 | get the trace class created by a given CTF writer object. | |
06300316 PP |
65 | |
66 | A 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 |
06300316 PP |
71 | class with a byte order set to #BT_CTF_BYTE_ORDER_NATIVE have this |
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 | ||
77 | In the Babeltrace CTF IR system, a trace class contains zero or more | |
78 | \link ctfirstreamclass stream classes\endlink, and a stream class | |
79 | contains zero or more \link ctfireventclass event classes\endlink. You | |
80 | can add an event class to a stream class with | |
81 | bt_ctf_stream_class_add_event_class(). You can add a stream class to a | |
82 | trace class with bt_ctf_trace_add_stream_class(). | |
83 | ||
c1e730fe PP |
84 | You can access the streams of a trace, that is, the streams which were |
85 | created from the trace's stream classes with bt_ctf_stream_create(), | |
9ac68eb1 | 86 | with bt_ctf_trace_get_stream_by_index(). |
c1e730fe | 87 | |
06300316 PP |
88 | A 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 | |
91 | trace packet header fields of the traces that this trace class | |
92 | describes. | |
93 | ||
94 | The trace packet header field type \em must be a structure field type as | |
95 | of Babeltrace \btversion. | |
96 | ||
97 | As per the CTF specification, the trace packet header field type \em | |
98 | must contain a field named \c stream_id if the trace class contains more | |
99 | than one stream class. | |
100 | ||
101 | As a reminder, here's the structure of a CTF packet: | |
102 | ||
103 | @imgpacketstructure | |
104 | ||
105 | A trace class also contains zero or more | |
fe7041b3 | 106 | \link ctfirclockclass CTF IR clock classes\endlink. |
06300316 PP |
107 | |
108 | @todo | |
109 | Elaborate about clock classes irt clock values. | |
110 | ||
2c1c33a4 | 111 | As with any Babeltrace object, CTF IR trace class objects have |
06300316 PP |
112 | <a href="https://en.wikipedia.org/wiki/Reference_counting">reference |
113 | counts</a>. See \ref refs to learn more about the reference counting | |
114 | management of Babeltrace objects. | |
115 | ||
116 | The following functions \em freeze their trace class parameter on | |
117 | success: | |
118 | ||
119 | - bt_ctf_trace_add_stream_class() | |
120 | - bt_ctf_writer_create_stream() | |
dfeca116 | 121 | (\link ctfwriter CTF writer\endlink mode only) |
06300316 PP |
122 | |
123 | You cannot modify a frozen trace class: it is considered immutable, | |
124 | except for: | |
125 | ||
126 | - Adding a stream class to it with | |
127 | bt_ctf_trace_add_stream_class(). | |
fe7041b3 | 128 | - Adding a CTF IR clock class to it with bt_ctf_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 | /** | |
144 | @struct bt_ctf_trace | |
145 | @brief A CTF IR trace class. | |
146 | @sa ctfirtraceclass | |
147 | */ | |
bc37ae52 JG |
148 | struct bt_ctf_trace; |
149 | struct bt_ctf_stream; | |
150 | struct bt_ctf_stream_class; | |
ac0c6bdd | 151 | struct bt_ctf_clock_class; |
bc37ae52 | 152 | |
3602afb0 PP |
153 | /** |
154 | @brief User function type to use with | |
155 | bt_ctf_trace_add_is_static_listener(). | |
156 | ||
157 | @param[in] trace_class Trace class which is now static. | |
158 | @param[in] data User data as passed to | |
159 | bt_ctf_trace_add_is_static_listener() when | |
160 | you added the listener. | |
161 | ||
162 | @prenotnull{trace_class} | |
163 | */ | |
164 | typedef void (* bt_ctf_trace_is_static_listener)( | |
165 | struct bt_ctf_trace *trace_class, void *data); | |
166 | ||
8480c8cc PP |
167 | /** |
168 | @brief User function type to use with | |
169 | bt_ctf_trace_add_is_static_listener(). | |
170 | ||
171 | @param[in] trace_class Trace class to which the listener was added. | |
172 | @param[in] data User data as passed to | |
173 | bt_ctf_trace_add_is_static_listener() when | |
174 | you added the listener. | |
175 | ||
176 | @prenotnull{trace_class} | |
177 | */ | |
178 | typedef void (* bt_ctf_trace_listener_removed)( | |
179 | struct bt_ctf_trace *trace_class, void *data); | |
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 | ||
189 | On success, the trace packet header field type of the created trace | |
488e09a7 PP |
190 | class is an empty structure field type. You can modify this default |
191 | trace packet header field type after the trace class is created with | |
192 | bt_ctf_trace_get_packet_header_type() and | |
193 | bt_ctf_trace_set_packet_header_type(). | |
06300316 PP |
194 | |
195 | The created trace class has the following initial properties: | |
196 | ||
197 | - <strong>Name</strong>: none. You can set a name | |
198 | with bt_ctf_trace_set_name(). | |
488e09a7 PP |
199 | - <strong>UUID</strong>: none. You can set a UUID with |
200 | bt_ctf_trace_set_uuid(). | |
2f4b93cd PP |
201 | - <strong>Native byte order</strong>: #BT_CTF_BYTE_ORDER_UNSPECIFIED. |
202 | You can set a native byte order with | |
203 | bt_ctf_trace_set_native_byte_order(). | |
06300316 PP |
204 | - <strong>Environment</strong>: empty. You can add environment entries |
205 | with bt_ctf_trace_set_environment_field(), | |
206 | bt_ctf_trace_set_environment_field_integer(), and | |
207 | bt_ctf_trace_set_environment_field_string(). | |
208 | ||
209 | @returns Created trace class, or \c NULL on error. | |
210 | ||
211 | @postsuccessrefcountret1 | |
212 | */ | |
bc37ae52 JG |
213 | extern struct bt_ctf_trace *bt_ctf_trace_create(void); |
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 |
225 | On success, \p trace_class remains the sole owner of the returned |
226 | string. The returned string is valid as long as \p trace_class exists | |
227 | and 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 | ||
237 | @sa bt_ctf_trace_set_name(): Sets the name of a given trace class. | |
238 | */ | |
239 | extern const char *bt_ctf_trace_get_name(struct bt_ctf_trace *trace_class); | |
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 | ||
254 | @sa bt_ctf_trace_get_name(): Returns the name of a given trace class. | |
255 | */ | |
256 | extern int bt_ctf_trace_set_name(struct bt_ctf_trace *trace_class, | |
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, |
8a716c8d | 266 | or #BT_CTF_BYTE_ORDER_UNKNOWN on error. |
06300316 PP |
267 | |
268 | @prenotnull{trace_class} | |
269 | @postrefcountsame{trace_class} | |
270 | ||
8a716c8d PP |
271 | @sa bt_ctf_trace_set_native_byte_order(): Sets the native byte order of |
272 | a given trace class. | |
06300316 | 273 | */ |
8a716c8d | 274 | extern enum bt_ctf_byte_order bt_ctf_trace_get_native_byte_order( |
06300316 PP |
275 | struct bt_ctf_trace *trace_class); |
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 PP |
282 | |
283 | - #BT_CTF_BYTE_ORDER_LITTLE_ENDIAN | |
284 | - #BT_CTF_BYTE_ORDER_BIG_ENDIAN | |
285 | - #BT_CTF_BYTE_ORDER_NETWORK | |
d41cff38 | 286 | - <strong>If the trace is not in CTF writer mode<strong>, |
2f4b93cd | 287 | #BT_CTF_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} |
2f4b93cd | 296 | @pre \p native_byte_order is either #BT_CTF_BYTE_ORDER_UNSPECIFIED (if the |
d41cff38 PP |
297 | trace is not in CTF writer mode), |
298 | #BT_CTF_BYTE_ORDER_LITTLE_ENDIAN, #BT_CTF_BYTE_ORDER_BIG_ENDIAN, or | |
06300316 PP |
299 | #BT_CTF_BYTE_ORDER_NETWORK. |
300 | @postrefcountsame{trace_class} | |
301 | ||
8a716c8d PP |
302 | @sa bt_ctf_trace_get_native_byte_order(): Returns the native byte order of a |
303 | given trace class. | |
06300316 | 304 | */ |
391c8f0d PP |
305 | extern int bt_ctf_trace_set_native_byte_order(struct bt_ctf_trace *trace_class, |
306 | enum bt_ctf_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 | ||
311 | On 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 | ||
320 | @sa bt_ctf_trace_set_uuid(): Sets the UUID of a given trace class. | |
321 | */ | |
322 | extern const unsigned char *bt_ctf_trace_get_uuid( | |
323 | struct bt_ctf_trace *trace_class); | |
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 | ||
342 | @sa bt_ctf_trace_get_uuid(): Returns the UUID of a given trace class. | |
343 | */ | |
344 | extern int bt_ctf_trace_set_uuid(struct bt_ctf_trace *trace_class, | |
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 | */ | |
544d0515 | 360 | extern int64_t bt_ctf_trace_get_environment_field_count( |
06300316 | 361 | struct bt_ctf_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 | ||
367 | On success, the returned string is valid as long as this trace class | |
368 | exists and is \em not modified. \p trace_class remains the sole owner of | |
369 | the 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 | |
379 | \p trace_class (see bt_ctf_trace_get_environment_field_count()). | |
380 | @postrefcountsame{trace_class} | |
381 | ||
9ac68eb1 | 382 | @sa bt_ctf_trace_get_environment_field_value_by_index(): Finds a trace class's |
06300316 PP |
383 | environment entry by index. |
384 | @sa bt_ctf_trace_get_environment_field_value_by_name(): Finds a trace | |
385 | class's environment entry by name. | |
386 | @sa bt_ctf_trace_set_environment_field(): Sets the value of a trace | |
387 | class's environment entry. | |
388 | */ | |
e6fa2160 | 389 | extern const char * |
9ac68eb1 PP |
390 | bt_ctf_trace_get_environment_field_name_by_index( |
391 | struct bt_ctf_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 | |
405 | \p trace_class (see bt_ctf_trace_get_environment_field_count()). | |
406 | @postrefcountsame{trace_class} | |
407 | @postsuccessrefcountretinc | |
408 | ||
409 | @sa bt_ctf_trace_get_environment_field_value_by_name(): Finds a trace | |
410 | class's environment entry by name. | |
411 | @sa bt_ctf_trace_set_environment_field(): Sets the value of a trace | |
412 | class's environment entry. | |
413 | */ | |
dac5c838 | 414 | extern struct bt_value * |
9ac68eb1 PP |
415 | bt_ctf_trace_get_environment_field_value_by_index(struct bt_ctf_trace *trace_class, |
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 | ||
9ac68eb1 | 434 | @sa bt_ctf_trace_get_environment_field_value_by_index(): Finds a trace class's |
06300316 PP |
435 | environment entry by index. |
436 | @sa bt_ctf_trace_set_environment_field(): Sets the value of a trace | |
437 | class's environment entry. | |
438 | */ | |
dac5c838 | 439 | extern struct bt_value * |
06300316 PP |
440 | bt_ctf_trace_get_environment_field_value_by_name( |
441 | struct bt_ctf_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 | ||
447 | If an environment entry named \p name exists in \p trace_class, its | |
448 | value 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 | ||
9ac68eb1 | 468 | @sa bt_ctf_trace_get_environment_field_value_by_index(): Finds a trace class's |
06300316 PP |
469 | environment entry by index. |
470 | @sa bt_ctf_trace_get_environment_field_value_by_name(): Finds a trace | |
471 | class's environment entry by name. | |
472 | */ | |
473 | extern int bt_ctf_trace_set_environment_field( | |
474 | struct bt_ctf_trace *trace_class, const char *name, | |
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 | ||
481 | If an environment entry named \p name exists in \p trace_class, its | |
482 | value is first put, and then replaced by a new | |
483 | \link bt_value_integer_create() integer value object\endlink | |
484 | containing \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 | ||
498 | @sa bt_ctf_trace_set_environment_field(): Sets the value of a trace | |
499 | class's environment entry. | |
500 | */ | |
501 | extern int bt_ctf_trace_set_environment_field_integer( | |
502 | struct bt_ctf_trace *trace_class, const char *name, | |
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 | ||
509 | If an environment entry named \p name exists in \p trace_class, its | |
510 | value is first put, and then replaced by a new | |
511 | \link bt_value_string_create() string value object\endlink | |
512 | containing \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 | ||
528 | @sa bt_ctf_trace_set_environment_field(): Sets the value of a trace | |
529 | class's environment entry. | |
530 | */ | |
531 | extern int bt_ctf_trace_set_environment_field_string( | |
532 | struct bt_ctf_trace *trace_class, const char *name, | |
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 PP |
556 | |
557 | @sa bt_ctf_trace_set_packet_header_type(): Sets the packet | |
558 | header field type of a given trace class. | |
559 | */ | |
560 | extern struct bt_ctf_field_type *bt_ctf_trace_get_packet_header_type( | |
561 | struct bt_ctf_trace *trace_class); | |
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 | ||
568 | If \p packet_header_type is \c NULL, then this function unsets the current | |
569 | packet header field type from \p trace_class, effectively making \p trace_class | |
570 | a trace without a packet header field type. | |
06300316 | 571 | |
6b783f49 JG |
572 | As 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 PP |
588 | |
589 | @sa bt_ctf_trace_get_packet_header_type(): Returns the packet | |
590 | header field type of a given trace class. | |
591 | */ | |
592 | extern int bt_ctf_trace_set_packet_header_type(struct bt_ctf_trace *trace_class, | |
593 | struct bt_ctf_field_type *packet_header_type); | |
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 | */ | |
544d0515 PP |
615 | extern int64_t bt_ctf_trace_get_clock_class_count( |
616 | struct bt_ctf_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 | |
ac0c6bdd | 632 | bt_ctf_trace_get_clock_class_count()). |
06300316 PP |
633 | @postrefcountsame{trace_class} |
634 | @postsuccessrefcountretinc | |
635 | ||
fe7041b3 PP |
636 | @sa bt_ctf_trace_get_clock_class_by_name(): Finds a clock class by name |
637 | in a given trace class. | |
ac0c6bdd | 638 | @sa bt_ctf_trace_add_clock_class(): Adds a clock class to a trace class. |
06300316 | 639 | */ |
9ac68eb1 PP |
640 | extern struct bt_ctf_clock_class *bt_ctf_trace_get_clock_class_by_index( |
641 | struct bt_ctf_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 | ||
9ac68eb1 | 658 | @sa bt_ctf_trace_get_clock_class_by_index(): Returns the clock class contained |
ac0c6bdd PP |
659 | in a given trace class at a given index. |
660 | @sa bt_ctf_trace_add_clock_class(): Adds a clock class to a trace class. | |
06300316 | 661 | */ |
ac0c6bdd | 662 | extern struct bt_ctf_clock_class *bt_ctf_trace_get_clock_class_by_name( |
06300316 | 663 | struct bt_ctf_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 | 669 | On success, \p trace_class contains \p clock_class. |
06300316 | 670 | |
fe7041b3 PP |
671 | You can call this function even if \p trace_class or \p clock_class |
672 | are 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 | |
9ac68eb1 | 685 | @sa bt_ctf_trace_get_clock_class_by_index(): Returns the clock class contained |
ac0c6bdd | 686 | in a given trace class at a given index. |
fe7041b3 PP |
687 | @sa bt_ctf_trace_get_clock_class_by_name(): Finds a clock class by name |
688 | in a given trace class. | |
06300316 | 689 | */ |
ac0c6bdd PP |
690 | extern int bt_ctf_trace_add_clock_class(struct bt_ctf_trace *trace_class, |
691 | struct bt_ctf_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 | */ | |
544d0515 PP |
713 | extern int64_t bt_ctf_trace_get_stream_class_count( |
714 | struct bt_ctf_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 | |
728 | bt_ctf_trace_get_stream_class_count()). | |
729 | @postrefcountsame{trace_class} | |
06300316 PP |
730 | |
731 | @sa bt_ctf_trace_get_stream_class_by_id(): Finds a stream class by ID. | |
732 | @sa bt_ctf_trace_add_stream_class(): Adds a stream class to a trace class. | |
733 | */ | |
9ac68eb1 PP |
734 | extern struct bt_ctf_stream_class *bt_ctf_trace_get_stream_class_by_index( |
735 | struct bt_ctf_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 | ||
9ac68eb1 | 750 | @sa bt_ctf_trace_get_stream_class_by_index(): Returns the stream class contained |
ac0c6bdd | 751 | in a given trace class at a given index. |
06300316 PP |
752 | @sa bt_ctf_trace_add_stream_class(): Adds a stream class to a trace class. |
753 | */ | |
4841ccc1 | 754 | extern struct bt_ctf_stream_class *bt_ctf_trace_get_stream_class_by_id( |
9ac68eb1 | 755 | struct bt_ctf_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 | 761 | On success, \p stream_class becomes the child of \p trace_class. |
bc37ae52 | 762 | |
06300316 | 763 | You can only add a given stream class to one trace class. |
4ed90fb3 | 764 | |
06300316 | 765 | You can call this function even if \p trace_class is frozen. |
bc37ae52 | 766 | |
4cdafd51 PP |
767 | This function tries to resolve the needed |
768 | \link ctfirfieldtypes CTF IR field type\endlink of the dynamic field | |
769 | types 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 | |
772 | resolving 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 | |
9ac68eb1 | 784 | @sa bt_ctf_trace_get_stream_class_by_index(): Returns the stream class contained |
ac0c6bdd | 785 | in a given trace class at a given index. |
06300316 PP |
786 | @sa bt_ctf_trace_get_stream_class_by_id(): Finds a stream class by ID. |
787 | */ | |
788 | extern int bt_ctf_trace_add_stream_class(struct bt_ctf_trace *trace_class, | |
789 | struct bt_ctf_stream_class *stream_class); | |
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 | */ | |
544d0515 | 811 | extern int64_t bt_ctf_trace_get_stream_count(struct bt_ctf_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 | |
825 | bt_ctf_trace_get_stream_count()). | |
826 | @postrefcountsame{trace_class} | |
827 | */ | |
9ac68eb1 PP |
828 | extern struct bt_ctf_stream *bt_ctf_trace_get_stream_by_index( |
829 | struct bt_ctf_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 | ||
842 | It is guaranteed that a static trace class will never contain new | |
843 | streams, stream classes, or clock classes. A static class is always | |
844 | frozen. | |
845 | ||
c55a9f58 | 846 | This function returns #BT_TRUE if bt_ctf_trace_set_is_static() was |
5acf2ae6 PP |
847 | previously 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 PP |
851 | |
852 | @sa bt_ctf_trace_set_is_static(): Makes a trace class static. | |
853 | */ | |
c55a9f58 | 854 | extern bt_bool bt_ctf_trace_is_static(struct bt_ctf_trace *trace_class); |
5acf2ae6 PP |
855 | |
856 | /** | |
857 | @brief Makes the CTF IR trace class \p trace_class static. | |
858 | ||
859 | A static trace class is frozen and you cannot call any modifying | |
860 | function on it: | |
861 | ||
862 | - bt_ctf_trace_add_stream_class() | |
863 | - bt_ctf_trace_add_clock_class() | |
3602afb0 PP |
864 | - bt_ctf_trace_set_environment_field() |
865 | - bt_ctf_trace_set_environment_field_integer() | |
866 | - bt_ctf_trace_set_environment_field_string() | |
867 | - bt_ctf_trace_add_is_static_listener() | |
5acf2ae6 PP |
868 | |
869 | You cannot create a stream with bt_ctf_stream_create() with any of the | |
870 | stream 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 | ||
879 | @sa bt_ctf_trace_is_static(): Checks whether or not a given trace class | |
880 | is static. | |
3602afb0 PP |
881 | @sa bt_ctf_trace_add_is_static_listener(): Adds a listener to a trace |
882 | class which is called when the trace class is made static. | |
5acf2ae6 PP |
883 | */ |
884 | extern int bt_ctf_trace_set_is_static(struct bt_ctf_trace *trace_class); | |
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 | |
891 | bt_ctf_trace_set_is_static() is called on \p trace_class. | |
892 | ||
8480c8cc PP |
893 | When the trace is destroyed, or when you remove the added listener with |
894 | bt_ctf_trace_remove_is_static_listener(), \p listener_removed is called | |
895 | if it's not \c NULL. You can use \p listener_removed to free any dynamic | |
896 | data which exists only for the added listener. You cannot call | |
897 | any function which modifies \p trace_class during the execution of | |
898 | \p listener_removed, including bt_ctf_trace_remove_is_static_listener(). | |
899 | ||
3602afb0 PP |
900 | This function fails if \p trace_class is already static: you need to |
901 | check the condition first with bt_ctf_trace_is_static(). | |
902 | ||
903 | On success, this function returns a unique numeric identifier for this | |
904 | listener within \p trace. You can use this identifier to remove the | |
905 | specific listener you added with | |
906 | bt_ctf_trace_remove_is_static_listener(). | |
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 | ||
926 | @sa bt_ctf_trace_remove_is_static_listener(): Removes a "trace is | |
927 | static" listener from a trace class previously added with this | |
928 | function. | |
929 | @sa bt_ctf_trace_is_static(): Checks whether or not a given trace class | |
930 | is static. | |
931 | @sa bt_ctf_trace_set_is_static(): Makes a trace class static. | |
932 | */ | |
933 | extern int bt_ctf_trace_add_is_static_listener( | |
934 | struct bt_ctf_trace *trace_class, | |
8480c8cc PP |
935 | bt_ctf_trace_is_static_listener listener, |
936 | bt_ctf_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 | |
951 | added with bt_ctf_trace_add_is_static_listener() and did not | |
952 | already remove with this function. | |
953 | @postrefcountsame{trace_class} | |
954 | ||
955 | @sa bt_ctf_trace_add_is_static_listener(): Adds a listener to a trace | |
956 | class which is called when the trace class is made static. | |
957 | */ | |
958 | extern int bt_ctf_trace_remove_is_static_listener( | |
959 | struct bt_ctf_trace *trace_class, int listener_id); | |
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 | ||
965 | This function traverses the hierarchy of \p trace_class in pre-order | |
966 | and calls \p visitor on each element. | |
967 | ||
968 | The trace class itself is visited first, then, for each children stream | |
969 | class, 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 | */ | |
979 | extern int bt_ctf_trace_visit(struct bt_ctf_trace *trace_class, | |
d9a13d86 | 980 | bt_ctf_visitor visitor, void *data); |
8bf65fbd | 981 | |
06300316 PP |
982 | /** @} */ |
983 | ||
35827558 PP |
984 | /** @} */ |
985 | ||
bc37ae52 JG |
986 | #ifdef __cplusplus |
987 | } | |
988 | #endif | |
989 | ||
990 | #endif /* BABELTRACE_CTF_IR_TRACE_H */ |