a3f73dba82c77b8b5d5f1a87f72bbdf074dba593
[babeltrace.git] / include / babeltrace2 / trace-ir / trace.h
1 #ifndef BABELTRACE2_TRACE_IR_TRACE_H
2 #define BABELTRACE2_TRACE_IR_TRACE_H
3
4 /*
5 * Copyright (c) 2010-2019 EfficiOS Inc. and Linux Foundation
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 * of this software and associated documentation files (the "Software"), to deal
9 * in the Software without restriction, including without limitation the rights
10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 * copies of the Software, and to permit persons to whom the Software is
12 * furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 * SOFTWARE.
24 */
25
26 #ifndef __BT_IN_BABELTRACE_H
27 # error "Please include <babeltrace2/babeltrace.h> instead."
28 #endif
29
30 #include <stdint.h>
31
32 #include <babeltrace2/types.h>
33
34 #ifdef __cplusplus
35 extern "C" {
36 #endif
37
38 /*!
39 @defgroup api-tir-trace Trace
40 @ingroup api-tir
41
42 @brief
43 Trace (set of \bt_p_stream).
44
45 A <strong><em>trace</em></strong> is a set of \bt_p_stream with
46 properties:
47
48 @image html trace-structure.png
49
50 In the illustration above, notice that a trace is an instance of a
51 \bt_trace_cls and that it contains streams.
52
53 Borrow the class of a trace with bt_trace_borrow_class() and
54 bt_trace_borrow_class_const().
55
56 A trace is a \ref api-tir "trace IR" data object.
57
58 A trace is a \ref api-fund-shared-object "shared object": get a
59 new reference with bt_trace_get_ref() and put an existing
60 reference with bt_trace_put_ref().
61
62 Some library functions \ref api-fund-freezing "freeze" traces on
63 success. The documentation of those functions indicate this
64 postcondition. With a frozen trace, you can still:
65
66 - Create \bt_p_stream from it with bt_stream_create() or
67 bt_stream_create_with_id().
68 - Add a destruction listener to it with
69 bt_trace_add_destruction_listener().
70
71 The type of a trace is #bt_trace.
72
73 A trace contains \bt_p_stream. All the streams of a
74 given trace have unique \ref api-tir-stream-prop-id "numeric IDs".
75 Get the number of streams in a trace with bt_trace_get_stream_count().
76 Borrow a specific stream from a trace with
77 bt_trace_borrow_stream_by_index(),
78 bt_trace_borrow_stream_by_index_const(), bt_trace_borrow_stream_by_id(),
79 or bt_trace_borrow_stream_by_id_const().
80
81 Create a default trace from a \bt_trace_cls with bt_trace_create().
82
83 Add to and remove a destruction listener from a trace with
84 bt_trace_add_destruction_listener() and
85 bt_trace_remove_destruction_listener().
86
87 <h1>Properties</h1>
88
89 A trace has the following properties:
90
91 <dl>
92 <dt>
93 \anchor api-tir-trace-prop-name
94 \bt_dt_opt Name
95 </dt>
96 <dd>
97 Name of the trace.
98
99 Use bt_trace_set_name() and bt_trace_get_name().
100 </dd>
101
102 <dt>
103 \anchor api-tir-trace-prop-uuid
104 \bt_dt_opt UUID
105 </dt>
106 <dd>
107 <a href="https://en.wikipedia.org/wiki/Universally_unique_identifier">UUID</a>
108 of the trace.
109
110 The trace's UUID uniquely identifies the trace.
111
112 Use bt_trace_set_uuid() and bt_trace_get_uuid().
113 </dd>
114
115 <dt>
116 \anchor api-tir-trace-prop-env
117 \bt_dt_opt Environment
118 </dt>
119 <dd>
120 Generic key-value store which describes the environment of the trace
121 (for example, the system's hostname, its network address, the
122 tracer's name and version, and the rest).
123
124 Trace environment keys are strings while values are signed integers
125 or strings.
126
127 Set a trace environment entry's value with
128 bt_trace_set_environment_entry_integer() and
129 bt_trace_set_environment_entry_string().
130
131 Get the number of environment entries in a trace with
132 bt_trace_get_environment_entry_count().
133
134 Borrow an environment entry from a trace with
135 bt_trace_borrow_environment_entry_value_by_name_const().
136 </dd>
137
138 <dt>
139 \anchor api-tir-trace-prop-user-attrs
140 \bt_dt_opt User attributes
141 </dt>
142 <dd>
143 User attributes of the trace.
144
145 User attributes are custom attributes attached to a trace.
146
147 Use bt_trace_set_user_attributes(),
148 bt_trace_borrow_user_attributes(), and
149 bt_trace_borrow_user_attributes_const().
150 </dd>
151 </dl>
152 */
153
154 /*! @{ */
155
156 /*!
157 @name Type
158 @{
159
160 @typedef struct bt_trace bt_trace;
161
162 @brief
163 Trace.
164
165 @}
166 */
167
168 /*!
169 @name Creation
170 @{
171 */
172
173 /*!
174 @brief
175 Creates a default trace from the \bt_trace_cls \bt_p{trace_class}.
176
177 This function instantiates \bt_p{trace_class}.
178
179 On success, the returned trace has the following property values:
180
181 <table>
182 <tr>
183 <th>Property
184 <th>Value
185 <tr>
186 <td>\ref api-tir-trace-prop-name "Name"
187 <td>\em None
188 <tr>
189 <td>\ref api-tir-trace-prop-uuid "UUID"
190 <td>\em None
191 <tr>
192 <td>\ref api-tir-trace-prop-env "Environment"
193 <td>Empty
194 <tr>
195 <td>\ref api-tir-trace-prop-user-attrs "User attributes"
196 <td>Empty \bt_map_val
197 </table>
198
199 @param[in] trace_class
200 Trace class from which to create the default trace.
201
202 @returns
203 New trace reference, or \c NULL on memory error.
204 */
205 extern bt_trace *bt_trace_create(bt_trace_class *trace_class);
206
207 /*! @} */
208
209 /*!
210 @name Class access
211 @{
212 */
213
214 /*!
215 @brief
216 Borrows the \ref api-tir-trace-cls "class" of the trace
217 \bt_p{trace}.
218
219 @param[in] trace
220 Trace of which to borrow the class.
221
222 @returns
223 \em Borrowed reference of the class of \bt_p{trace}.
224
225 @bt_pre_not_null{trace}
226
227 @sa bt_trace_borrow_class_const() &mdash;
228 \c const version of this function.
229 */
230 extern bt_trace_class *bt_trace_borrow_class(bt_trace *trace);
231
232 /*!
233 @brief
234 Borrows the \ref api-tir-trace-cls "class" of the trace
235 \bt_p{trace} (\c const version).
236
237 See bt_trace_borrow_class().
238 */
239 extern const bt_trace_class *bt_trace_borrow_class_const(
240 const bt_trace *trace);
241
242 /*! @} */
243
244 /*!
245 @name Stream access
246 @{
247 */
248
249 /*!
250 @brief
251 Returns the number of \bt_p_stream contained in the trace
252 \bt_p{trace}.
253
254 @param[in] trace
255 Trace of which to get the number of contained streams.
256
257 @returns
258 Number of contained streams in \bt_p{trace}.
259
260 @bt_pre_not_null{trace}
261 */
262 extern uint64_t bt_trace_get_stream_count(const bt_trace *trace);
263
264 /*!
265 @brief
266 Borrows the \bt_stream at index \bt_p{index} from the
267 trace \bt_p{trace}.
268
269 @param[in] trace
270 Trace from which to borrow the stream at index
271 \bt_p{index}.
272 @param[in] index
273 Index of the stream to borrow from \bt_p{trace}.
274
275 @returns
276 @parblock
277 \em Borrowed reference of the stream of
278 \bt_p{trace} at index \bt_p{index}.
279
280 The returned pointer remains valid as long as \bt_p{trace}
281 exists.
282 @endparblock
283
284 @bt_pre_not_null{trace}
285 @pre
286 \bt_p{index} is less than the number of streams in
287 \bt_p{trace} (as returned by
288 bt_trace_get_stream_count()).
289
290 @sa bt_trace_get_stream_count() &mdash;
291 Returns the number of streams contained in a trace.
292 @sa bt_trace_borrow_stream_by_index_const() &mdash;
293 \c const version of this function.
294 */
295 extern bt_stream *bt_trace_borrow_stream_by_index(bt_trace *trace,
296 uint64_t index);
297
298 /*!
299 @brief
300 Borrows the \bt_stream at index \bt_p{index} from the
301 trace \bt_p{trace} (\c const version).
302
303 See bt_trace_borrow_stream_by_index().
304 */
305 extern const bt_stream *bt_trace_borrow_stream_by_index_const(
306 const bt_trace *trace, uint64_t index);
307
308 /*!
309 @brief
310 Borrows the \bt_stream having the numeric ID \bt_p{id} from the
311 trace \bt_p{trace}.
312
313 If there's no stream having the numeric ID \bt_p{id} in
314 \bt_p{trace}, this function returns \c NULL.
315
316 @param[in] trace
317 Trace from which to borrow the stream having the
318 numeric ID \bt_p{id}.
319 @param[in] id
320 ID of the stream to borrow from \bt_p{trace}.
321
322 @returns
323 @parblock
324 \em Borrowed reference of the stream of
325 \bt_p{trace} having the numeric ID \bt_p{id}, or \c NULL
326 if none.
327
328 The returned pointer remains valid as long as \bt_p{trace}
329 exists.
330 @endparblock
331
332 @bt_pre_not_null{trace}
333
334 @sa bt_trace_borrow_stream_by_id_const() &mdash;
335 \c const version of this function.
336 */
337 extern bt_stream *bt_trace_borrow_stream_by_id(bt_trace *trace,
338 uint64_t id);
339
340 /*!
341 @brief
342 Borrows the \bt_stream having the numeric ID \bt_p{id} from the
343 trace \bt_p{trace} (\c const version).
344
345 See bt_trace_borrow_stream_by_id().
346 */
347 extern const bt_stream *bt_trace_borrow_stream_by_id_const(
348 const bt_trace *trace, uint64_t id);
349
350 /*! @} */
351
352 /*!
353 @name Properties
354 @{
355 */
356
357 /*!
358 @brief
359 Status codes for bt_trace_set_name().
360 */
361 typedef enum bt_trace_set_name_status {
362 /*!
363 @brief
364 Success.
365 */
366 BT_TRACE_SET_NAME_STATUS_OK = __BT_FUNC_STATUS_OK,
367
368 /*!
369 @brief
370 Out of memory.
371 */
372 BT_TRACE_SET_NAME_STATUS_MEMORY_ERROR = __BT_FUNC_STATUS_MEMORY_ERROR,
373 } bt_trace_set_name_status;
374
375 /*!
376 @brief
377 Sets the name of the trace \bt_p{trace} to a copy of \bt_p{name}.
378
379 See the \ref api-tir-trace-prop-name "name" property.
380
381 @param[in] trace
382 Trace of which to set the name to \bt_p{name}.
383 @param[in] name
384 New name of \bt_p{trace} (copied).
385
386 @retval #BT_TRACE_SET_NAME_STATUS_OK
387 Success.
388 @retval #BT_TRACE_SET_NAME_STATUS_MEMORY_ERROR
389 Out of memory.
390
391 @bt_pre_not_null{trace}
392 @bt_pre_hot{trace}
393 @bt_pre_not_null{name}
394
395 @sa bt_trace_get_name() &mdash;
396 Returns the name of a trace.
397 */
398 extern bt_trace_set_name_status bt_trace_set_name(bt_trace *trace,
399 const char *name);
400
401 /*!
402 @brief
403 Returns the name of the trace \bt_p{trace}.
404
405 See the \ref api-tir-trace-prop-name "name" property.
406
407 If \bt_p{trace} has no name, this function returns \c NULL.
408
409 @param[in] trace
410 Trace of which to get the name.
411
412 @returns
413 @parblock
414 Name of \bt_p{trace}, or \c NULL if none.
415
416 The returned pointer remains valid as long as \bt_p{trace}
417 is not modified.
418 @endparblock
419
420 @bt_pre_not_null{trace}
421
422 @sa bt_trace_set_name() &mdash;
423 Sets the name of a trace.
424 */
425 extern const char *bt_trace_get_name(const bt_trace *trace);
426
427 /*!
428 @brief
429 Sets the
430 <a href="https://en.wikipedia.org/wiki/Universally_unique_identifier">UUID</a>
431 of the trace \bt_p{trace} to a copy of \bt_p{uuid}.
432
433 See the \ref api-tir-trace-prop-uuid "UUID" property.
434
435 @param[in] trace
436 Trace of which to set the UUID to \bt_p{uuid}.
437 @param[in] uuid
438 New UUID of \bt_p{trace} (copied).
439
440 @bt_pre_not_null{trace}
441 @bt_pre_hot{trace}
442 @bt_pre_not_null{uuid}
443
444 @sa bt_trace_get_uuid() &mdash;
445 Returns the UUID of a trace.
446 */
447 extern void bt_trace_set_uuid(bt_trace *trace, bt_uuid uuid);
448
449 /*!
450 @brief
451 Returns the UUID of the trace \bt_p{trace}.
452
453 See the \ref api-tir-trace-prop-uuid "UUID" property.
454
455 If \bt_p{trace} has no UUID, this function returns \c NULL.
456
457 @param[in] trace
458 Trace of which to get the UUID.
459
460 @returns
461 @parblock
462 UUID of \bt_p{trace}, or \c NULL if none.
463
464 The returned pointer remains valid as long as \bt_p{trace}
465 is not modified.
466 @endparblock
467
468 @bt_pre_not_null{trace}
469
470 @sa bt_trace_set_uuid() &mdash;
471 Sets the UUID of a trace.
472 */
473 extern bt_uuid bt_trace_get_uuid(const bt_trace *trace);
474
475 /*!
476 @brief
477 Status codes for bt_trace_set_name().
478 */
479 typedef enum bt_trace_set_environment_entry_status {
480 /*!
481 @brief
482 Success.
483 */
484 BT_TRACE_SET_ENVIRONMENT_ENTRY_STATUS_OK = __BT_FUNC_STATUS_OK,
485
486 /*!
487 @brief
488 Out of memory.
489 */
490 BT_TRACE_SET_ENVIRONMENT_ENTRY_STATUS_MEMORY_ERROR = __BT_FUNC_STATUS_MEMORY_ERROR,
491 } bt_trace_set_environment_entry_status;
492
493 /*!
494 @brief
495 Sets the value of the environment entry of the trace \bt_p{trace}
496 named \bt_p{name} to the signed integer \bt_p{value}.
497
498 See the \ref api-tir-trace-prop-env "environment" property.
499
500 On success, if \bt_p{trace} already contains an environment entry named
501 \bt_p{name}, this function replaces the existing entry's value with
502 \bt_p{value}.
503
504 @param[in] trace
505 Trace in which to insert or replace an environment entry named
506 \bt_p{name} with the value \bt_p{value}.
507 @param[in] name
508 Name of the entry to insert or replace in \bt_p{trace} (copied).
509 @param[in] value
510 Value of the environment entry to insert or replace in \bt_p{trace}.
511
512 @retval #BT_TRACE_SET_ENVIRONMENT_ENTRY_STATUS_OK
513 Success.
514 @retval #BT_TRACE_SET_ENVIRONMENT_ENTRY_STATUS_MEMORY_ERROR
515 Out of memory.
516
517 @bt_pre_not_null{trace}
518 @bt_pre_hot{trace}
519 @bt_pre_not_null{name}
520
521 @sa bt_trace_set_environment_entry_string() &mdash;
522 Sets a trace environment entry's value to a string.
523 */
524 extern bt_trace_set_environment_entry_status
525 bt_trace_set_environment_entry_integer(bt_trace *trace, const char *name,
526 int64_t value);
527
528 /*!
529 @brief
530 Sets the value of the environment entry of the trace \bt_p{trace}
531 named \bt_p{name} to the string \bt_p{value}.
532
533 See the \ref api-tir-trace-prop-env "environment" property.
534
535 On success, if \bt_p{trace} already contains an environment entry named
536 \bt_p{name}, this function replaces the existing entry's value with
537 \bt_p{value}.
538
539 @param[in] trace
540 Trace in which to insert or replace an environment entry named
541 \bt_p{name} with the value \bt_p{value}.
542 @param[in] name
543 Name of the entry to insert or replace in \bt_p{trace} (copied).
544 @param[in] value
545 Value of the environment entry to insert or replace in \bt_p{trace}.
546
547 @retval #BT_TRACE_SET_ENVIRONMENT_ENTRY_STATUS_OK
548 Success.
549 @retval #BT_TRACE_SET_ENVIRONMENT_ENTRY_STATUS_MEMORY_ERROR
550 Out of memory.
551
552 @bt_pre_not_null{trace}
553 @bt_pre_hot{trace}
554 @bt_pre_not_null{name}
555 @bt_pre_not_null{value}
556
557 @sa bt_trace_set_environment_entry_integer() &mdash;
558 Sets a trace environment entry's value to a signed integer.
559 */
560 extern bt_trace_set_environment_entry_status
561 bt_trace_set_environment_entry_string(bt_trace *trace, const char *name,
562 const char *value);
563
564 /*!
565 @brief
566 Returns the number of environment entries contained in the trace
567 \bt_p{trace}.
568
569 See the \ref api-tir-trace-prop-env "environment" property.
570
571 @param[in] trace
572 Trace of which to get the number of environment entries.
573
574 @returns
575 Number of environment entries in \bt_p{trace}.
576
577 @bt_pre_not_null{trace}
578 */
579 extern uint64_t bt_trace_get_environment_entry_count(const bt_trace *trace);
580
581 /*!
582 @brief
583 Borrows the environment entry at index \bt_p{index} from the
584 trace \bt_p{trace}, setting \bt_p{*name} to its name and
585 \bt_p{*value} to its value.
586
587 See the \ref api-tir-trace-prop-env "environment" property.
588
589 @param[in] trace
590 Trace from which to borrow the environment entry at index
591 \bt_p{index}.
592 @param[in] index
593 Index of the environment entry to borrow from \bt_p{trace}.
594 @param[in] name
595 @parblock
596 <strong>On success</strong>, \bt_p{*name} is the name of the
597 environment entry at index \bt_p{index} in \bt_p{trace}.
598
599 The returned pointer remains valid as long as \bt_p{trace}
600 is not modified.
601 @endparblock
602 @param[in] value
603 @parblock
604 <strong>On success</strong>, \bt_p{*value} is a \em borrowed
605 reference of the environment entry at index \bt_p{index} in
606 \bt_p{trace}.
607
608 \bt_p{*value} is either a \bt_sint_val
609 (#BT_VALUE_TYPE_SIGNED_INTEGER) or a \bt_string_val
610 (#BT_VALUE_TYPE_STRING).
611
612 The returned pointer remains valid as long as \bt_p{trace}
613 is not modified.
614 @endparblock
615
616 @bt_pre_not_null{trace}
617 @pre
618 \bt_p{index} is less than the number of environment entries in
619 \bt_p{trace} (as returned by
620 bt_trace_get_environment_entry_count()).
621 @bt_pre_not_null{name}
622 @bt_pre_not_null{value}
623
624 @sa bt_trace_get_environment_entry_count() &mdash;
625 Returns the number of environment entries contained in a trace.
626 */
627 extern void bt_trace_borrow_environment_entry_by_index_const(
628 const bt_trace *trace, uint64_t index,
629 const char **name, const bt_value **value);
630
631 /*!
632 @brief
633 Borrows the value of the environment entry named \bt_p{name}
634 in the trace \bt_p{trace}.
635
636 See the \ref api-tir-trace-prop-env "environment" property.
637
638 If there's no environment entry named \bt_p{name} in \bt_p{trace}, this
639 function returns \c NULL.
640
641 @param[in] trace
642 Trace from which to borrow the value of the environment entry
643 named \bt_p{name}.
644 @param[in] name
645 Name of the environment entry to borrow from \bt_p{trace}.
646
647 @returns
648 @parblock
649 \em Borrowed reference of the value of the environment entry named
650 \bt_p{name} in \bt_p{trace}.
651
652 The returned value is either a \bt_sint_val
653 (#BT_VALUE_TYPE_SIGNED_INTEGER) or a \bt_string_val
654 (#BT_VALUE_TYPE_STRING).
655
656 The returned pointer remains valid as long as \bt_p{trace}
657 is not modified.
658 @endparblock
659
660 @bt_pre_not_null{trace}
661 @bt_pre_not_null{name}
662 */
663 extern const bt_value *bt_trace_borrow_environment_entry_value_by_name_const(
664 const bt_trace *trace, const char *name);
665
666 /*!
667 @brief
668 Sets the user attributes of the trace \bt_p{trace} to
669 \bt_p{user_attributes}.
670
671 See the \ref api-tir-trace-prop-user-attrs "user attributes"
672 property.
673
674 @note
675 When you create a default trace with bt_trace_create(), the trace's
676 initial user attributes is an empty \bt_map_val. Therefore you can
677 borrow it with bt_trace_borrow_user_attributes() and fill it
678 directly instead of setting a new one with this function.
679
680 @param[in] trace
681 Trace of which to set the user attributes to \bt_p{user_attributes}.
682 @param[in] user_attributes
683 New user attributes of \bt_p{trace}.
684
685 @bt_pre_not_null{trace}
686 @bt_pre_hot{trace}
687 @bt_pre_not_null{user_attributes}
688 @bt_pre_is_map_val{user_attributes}
689
690 @sa bt_trace_borrow_user_attributes() &mdash;
691 Borrows the user attributes of a trace.
692 */
693 extern void bt_trace_set_user_attributes(
694 bt_trace *trace, const bt_value *user_attributes);
695
696 /*!
697 @brief
698 Borrows the user attributes of the trace \bt_p{trace}.
699
700 See the \ref api-tir-trace-prop-user-attrs "user attributes"
701 property.
702
703 @note
704 When you create a default trace with bt_trace_create(), the trace's
705 initial user attributes is an empty \bt_map_val.
706
707 @param[in] trace
708 Trace from which to borrow the user attributes.
709
710 @returns
711 User attributes of \bt_p{trace} (a \bt_map_val).
712
713 @bt_pre_not_null{trace}
714
715 @sa bt_trace_set_user_attributes() &mdash;
716 Sets the user attributes of a trace.
717 @sa bt_trace_borrow_user_attributes_const() &mdash;
718 \c const version of this function.
719 */
720 extern bt_value *bt_trace_borrow_user_attributes(bt_trace *trace);
721
722 /*!
723 @brief
724 Borrows the user attributes of the trace \bt_p{trace}
725 (\c const version).
726
727 See bt_trace_borrow_user_attributes().
728 */
729 extern const bt_value *bt_trace_borrow_user_attributes_const(
730 const bt_trace *trace);
731
732 /*! @} */
733
734 /*!
735 @name Listeners
736 @{
737 */
738
739 /*!
740 @brief
741 User function for bt_trace_add_destruction_listener().
742
743 This is the user function type for a trace destruction listener.
744
745 @param[in] trace
746 Trace being destroyed (\ref api-fund-freezing "frozen").
747 @param[in] user_data
748 User data, as passed as the \bt_p{user_data} parameter of
749 bt_trace_add_destruction_listener().
750
751 @bt_pre_not_null{trace}
752
753 @post
754 The reference count of \bt_p{trace} is not changed.
755 @bt_post_no_error
756
757 @sa bt_trace_add_destruction_listener() &mdash;
758 Adds a destruction listener to a trace.
759 */
760 typedef void (* bt_trace_destruction_listener_func)(
761 const bt_trace *trace, void *user_data);
762
763 /*!
764 @brief
765 Status codes for bt_trace_add_destruction_listener().
766 */
767 typedef enum bt_trace_add_listener_status {
768 /*!
769 @brief
770 Success.
771 */
772 BT_TRACE_ADD_LISTENER_STATUS_OK = __BT_FUNC_STATUS_OK,
773
774 /*!
775 @brief
776 Out of memory.
777 */
778 BT_TRACE_ADD_LISTENER_STATUS_MEMORY_ERROR = __BT_FUNC_STATUS_MEMORY_ERROR,
779 } bt_trace_add_listener_status;
780
781 /*!
782 @brief
783 Adds a destruction listener having the function \bt_p{user_func}
784 to the trace \bt_p{trace}.
785
786 All the destruction listener user functions of a trace are called
787 when it's being destroyed.
788
789 If \bt_p{listener_id} is not \c NULL, then this function, on success,
790 sets \bt_p{*listener_id} to the ID of the added destruction listener
791 within \bt_p{trace}. You can then use this ID to remove the
792 added destruction listener with bt_trace_remove_destruction_listener().
793
794 @param[in] trace
795 Trace to add the destruction listener to.
796 @param[in] user_func
797 User function of the destruction listener to add to
798 \bt_p{trace}.
799 @param[in] user_data
800 User data to pass as the \bt_p{user_data} parameter of
801 \bt_p{user_func}.
802 @param[out] listener_id
803 <strong>On success and if not \c NULL</strong>, \bt_p{*listener_id}
804 is the ID of the added destruction listener within
805 \bt_p{trace}.
806
807 @retval #BT_TRACE_ADD_LISTENER_STATUS_OK
808 Success.
809 @retval #BT_TRACE_ADD_LISTENER_STATUS_MEMORY_ERROR
810 Out of memory.
811
812 @bt_pre_not_null{trace}
813 @bt_pre_not_null{user_func}
814
815 @sa bt_trace_remove_destruction_listener() &mdash;
816 Removes a destruction listener from a trace.
817 */
818 extern bt_trace_add_listener_status bt_trace_add_destruction_listener(
819 const bt_trace *trace,
820 bt_trace_destruction_listener_func user_func,
821 void *user_data, bt_listener_id *listener_id);
822
823 /*!
824 @brief
825 Status codes for bt_trace_remove_destruction_listener().
826 */
827 typedef enum bt_trace_remove_listener_status {
828 /*!
829 @brief
830 Success.
831 */
832 BT_TRACE_REMOVE_LISTENER_STATUS_OK = __BT_FUNC_STATUS_OK,
833
834 /*!
835 @brief
836 Out of memory.
837 */
838 BT_TRACE_REMOVE_LISTENER_STATUS_MEMORY_ERROR = __BT_FUNC_STATUS_MEMORY_ERROR,
839 } bt_trace_remove_listener_status;
840
841 /*!
842 @brief
843 Removes the destruction listener having the ID \bt_p{listener_id}
844 from the trace \bt_p{trace}.
845
846 The destruction listener to remove from \bt_p{trace} was
847 previously added with bt_trace_add_destruction_listener().
848
849 You can call this function when \bt_p{trace} is
850 \ref api-fund-freezing "frozen".
851
852 @param[in] trace
853 Trace from which to remove the destruction listener having
854 the ID \bt_p{listener_id}.
855 @param[in] listener_id
856 ID of the destruction listener to remove from \bt_p{trace}­.
857
858 @retval #BT_TRACE_REMOVE_LISTENER_STATUS_OK
859 Success.
860 @retval #BT_TRACE_REMOVE_LISTENER_STATUS_MEMORY_ERROR
861 Out of memory.
862
863 @bt_pre_not_null{trace}
864 @pre
865 \bt_p{listener_id} is the ID of an existing destruction listener
866 in \bt_p{trace}.
867
868 @sa bt_trace_add_destruction_listener() &mdash;
869 Adds a destruction listener to a trace.
870 */
871 extern bt_trace_remove_listener_status bt_trace_remove_destruction_listener(
872 const bt_trace *trace, bt_listener_id listener_id);
873
874 /*! @} */
875
876 /*!
877 @name Reference count
878 @{
879 */
880
881 /*!
882 @brief
883 Increments the \ref api-fund-shared-object "reference count" of
884 the trace \bt_p{trace}.
885
886 @param[in] trace
887 @parblock
888 Trace of which to increment the reference count.
889
890 Can be \c NULL.
891 @endparblock
892
893 @sa bt_trace_put_ref() &mdash;
894 Decrements the reference count of a trace.
895 */
896 extern void bt_trace_get_ref(const bt_trace *trace);
897
898 /*!
899 @brief
900 Decrements the \ref api-fund-shared-object "reference count" of
901 the trace \bt_p{trace}.
902
903 @param[in] trace
904 @parblock
905 Trace of which to decrement the reference count.
906
907 Can be \c NULL.
908 @endparblock
909
910 @sa bt_trace_get_ref() &mdash;
911 Increments the reference count of a trace.
912 */
913 extern void bt_trace_put_ref(const bt_trace *trace);
914
915 /*!
916 @brief
917 Decrements the reference count of the trace
918 \bt_p{_trace}, and then sets \bt_p{_trace} to \c NULL.
919
920 @param _trace
921 @parblock
922 Trace of which to decrement the reference count.
923
924 Can contain \c NULL.
925 @endparblock
926
927 @bt_pre_assign_expr{_trace}
928 */
929 #define BT_TRACE_PUT_REF_AND_RESET(_trace) \
930 do { \
931 bt_trace_put_ref(_trace); \
932 (_trace) = NULL; \
933 } while (0)
934
935 /*!
936 @brief
937 Decrements the reference count of the trace \bt_p{_dst}, sets
938 \bt_p{_dst} to \bt_p{_src}, and then sets \bt_p{_src} to \c NULL.
939
940 This macro effectively moves a trace reference from the expression
941 \bt_p{_src} to the expression \bt_p{_dst}, putting the existing
942 \bt_p{_dst} reference.
943
944 @param _dst
945 @parblock
946 Destination expression.
947
948 Can contain \c NULL.
949 @endparblock
950 @param _src
951 @parblock
952 Source expression.
953
954 Can contain \c NULL.
955 @endparblock
956
957 @bt_pre_assign_expr{_dst}
958 @bt_pre_assign_expr{_src}
959 */
960 #define BT_TRACE_MOVE_REF(_dst, _src) \
961 do { \
962 bt_trace_put_ref(_dst); \
963 (_dst) = (_src); \
964 (_src) = NULL; \
965 } while (0)
966
967 /*! @} */
968
969 /*! @} */
970
971 #ifdef __cplusplus
972 }
973 #endif
974
975 #endif /* BABELTRACE2_TRACE_IR_TRACE_H */
This page took 0.048877 seconds and 4 git commands to generate.