1 #ifndef BABELTRACE_CTF_IR_FIELDS_H
2 #define BABELTRACE_CTF_IR_FIELDS_H
5 * Babeltrace - CTF IR: Event Fields
7 * Copyright 2013, 2014 Jérémie Galarneau <jeremie.galarneau@efficios.com>
9 * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com>
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:
18 * The above copyright notice and this permission notice shall be included in
19 * all copies or substantial portions of the Software.
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
29 * The Common Trace Format (CTF) Specification is available at
30 * http://www.efficios.com/ctf
37 #include <babeltrace/ref.h>
40 #include <babeltrace/types.h>
49 @defgroup ctfirfields CTF IR fields
54 #include <babeltrace/ctf-ir/fields.h>
57 A CTF IR <strong><em>field</em></strong> is an object which holds a
58 concrete value, and which is described by a @ft.
60 In the CTF IR hierarchy, you can set the root fields of two objects:
63 - Trace packet header field: bt_packet_set_header().
64 - Stream packet context field: bt_packet_set_context().
66 - Stream event header field: bt_event_set_header().
67 - Stream event context field: bt_event_set_stream_event_context().
68 - Event context field: bt_event_set_event_context().
69 - Event payload field: bt_event_set_payload_field().
71 There are two categories of fields:
73 - <strong>Basic fields</strong>:
74 - @intfield: contains an integral value.
75 - @floatfield: contains a floating point number value.
76 - @enumfield: contains an integer field which contains an integral
78 - @stringfield: contains a string value.
79 - <strong>Compound fields</strong>:
80 - @structfield: contains an ordered list of named fields
81 (possibly with different @fts).
82 - @arrayfield: contains an ordered list of fields which share
84 - @seqfield: contains an ordered list of fields which share
86 - @varfield: contains a single, current field.
88 You can create a field object from a @ft object with
89 bt_field_create(). The enumeration and compound fields create their
90 contained fields with the following getters if such fields do not exist
93 - bt_field_enumeration_get_container()
94 - bt_field_structure_get_field_by_name()
95 - bt_field_array_get_field()
96 - bt_field_sequence_get_field()
97 - bt_field_variant_get_field()
99 If you already have a field object, you can also assign it to a specific
100 name within a @structfield with
101 bt_field_structure_set_field_by_name().
103 You can get a reference to the @ft which was used to create a field with
104 bt_field_get_type(). You can get the
105 \link #bt_field_type_id type ID\endlink of this field type directly with
106 bt_field_get_type_id().
108 You can get a deep copy of a field with bt_field_copy(). The field
109 copy, and its contained field copies if it's the case, have the same
110 field type as the originals.
112 As with any Babeltrace object, CTF IR field objects have
113 <a href="https://en.wikipedia.org/wiki/Reference_counting">reference
114 counts</a>. See \ref refs to learn more about the reference counting
115 management of Babeltrace objects.
117 The functions which freeze CTF IR \link ctfirpacket packet\endlink and
118 \link ctfirevent event\endlink objects also freeze their root field
119 objects. You cannot modify a frozen field object: it is considered
120 immutable, except for \link refs reference counting\endlink.
125 @brief CTF IR fields type and functions.
128 @addtogroup ctfirfields
134 @brief A CTF IR field.
138 struct bt_event_class
;
140 struct bt_field_type
;
141 struct bt_field_type_enumeration_mapping_iterator
;
144 @name Creation and parent field type access functions
149 @brief Creates an uninitialized @field described by the @ft
152 On success, \p field_type becomes the parent of the created field
155 On success, this function creates an \em uninitialized field: it has
156 no value. You need to set the value of the created field with one of the
157 its specific setters.
159 @param[in] field_type Field type which describes the field to create.
160 @returns Created field object, or \c NULL on error.
162 @prenotnull{field_type}
163 @postsuccessrefcountret1
164 @postsuccessfrozen{field_type}
166 extern struct bt_field
*bt_field_create(struct bt_field_type
*field_type
);
168 extern struct bt_field_type
*bt_field_borrow_type(struct bt_field
*field
);
171 @brief Returns the parent @ft of the @field \p field.
173 This function returns a reference to the field type which was used to
174 create the field object in the first place with bt_field_create().
176 @param[in] field Field of which to get the parent field type.
177 @returns Parent field type of \p event,
181 @postrefcountsame{field}
182 @postsuccessrefcountretinc
185 struct bt_field_type
*bt_field_get_type(struct bt_field
*field
)
187 return bt_get(bt_field_borrow_type(field
));
193 @name Type information
198 @brief Returns the type ID of the @ft of the @field \p field.
200 @param[in] field Field of which to get the type ID of its
202 @returns Type ID of the parent field type of \p field,
203 or #BT_FIELD_TYPE_ID_UNKNOWN on error.
206 @postrefcountsame{field}
208 @sa #bt_field_type_id: CTF IR field type ID.
209 @sa bt_field_is_integer(): Returns whether or not a given field is a
211 @sa bt_field_is_floating_point(): Returns whether or not a given
212 field is a @floatfield.
213 @sa bt_field_is_enumeration(): Returns whether or not a given field
215 @sa bt_field_is_string(): Returns whether or not a given field is a
217 @sa bt_field_is_structure(): Returns whether or not a given field is
219 @sa bt_field_is_array(): Returns whether or not a given field is a
221 @sa bt_field_is_sequence(): Returns whether or not a given field is
223 @sa bt_field_is_variant(): Returns whether or not a given field is a
226 extern enum bt_field_type_id
bt_field_get_type_id(struct bt_field
*field
);
229 @brief Returns whether or not the @field \p field is a @intfield.
231 @param[in] field Field to check (can be \c NULL).
232 @returns #BT_TRUE if \p field is an integer field, or
233 #BT_FALSE otherwise (including if \p field is
237 @postrefcountsame{field}
239 @sa bt_field_get_type_id(): Returns the type ID of a given
242 extern bt_bool
bt_field_is_integer(struct bt_field
*field
);
245 @brief Returns whether or not the @field \p field is a @floatfield.
247 @param[in] field Field to check (can be \c NULL).
248 @returns #BT_TRUE if \p field is a floating point number fiel
249 #BT_FALSE or 0 otherwise (including if \p field is
253 @postrefcountsame{field}
255 @sa bt_field_get_type_id(): Returns the type ID of a given
258 extern bt_bool
bt_field_is_floating_point(struct bt_field
*field
);
261 @brief Returns whether or not the @field \p field is a @enumfield.
263 @param[in] field Field to check (can be \c NULL).
264 @returns #BT_TRUE if \p field is an enumeration field, or
265 #BT_FALSE otherwise (including if \p field is
269 @postrefcountsame{field}
271 @sa bt_field_get_type_id(): Returns the type ID of a given
274 extern bt_bool
bt_field_is_enumeration(struct bt_field
*field
);
277 @brief Returns whether or not the @field \p field is a @stringfield.
279 @param[in] field Field to check (can be \c NULL).
280 @returns #BT_TRUE if \p field is a string field, or
281 #BT_FALSE otherwise (including if \p field is
285 @postrefcountsame{field}
287 @sa bt_field_get_type_id(): Returns the type ID of a given
290 extern bt_bool
bt_field_is_string(struct bt_field
*field
);
293 @brief Returns whether or not the @field \p field is a @structfield.
295 @param[in] field Field to check (can be \c NULL).
296 @returns #BT_TRUE if \p field is a structure field, or
297 #BT_FALSE otherwise (including if \p field is
301 @postrefcountsame{field}
303 @sa bt_field_get_type_id(): Returns the type ID of a given
306 extern bt_bool
bt_field_is_structure(struct bt_field
*field
);
309 @brief Returns whether or not the @field \p field is a @arrayfield.
311 @param[in] field Field to check (can be \c NULL).
312 @returns #BT_TRUE if \p field is an array field, or
313 #BT_FALSE otherwise (including if \p field is
317 @postrefcountsame{field}
319 @sa bt_field_get_type_id(): Returns the type ID of a given
322 extern bt_bool
bt_field_is_array(struct bt_field
*field
);
325 @brief Returns whether or not the @field \p field is a @seqfield.
327 @param[in] field Field to check (can be \c NULL).
328 @returns #BT_TRUE if \p field is a sequence field, or
329 #BT_FALSE otherwise (including if \p field is
333 @postrefcountsame{field}
335 @sa bt_field_get_type_id(): Returns the type ID of a given
338 extern bt_bool
bt_field_is_sequence(struct bt_field
*field
);
341 @brief Returns whether or not the @field \p field is a @varfield.
343 @param[in] field Field to check (can be \c NULL).
344 @returns #BT_TRUE if \p field is a variant field, or
345 #BT_FALSE otherwise (including if \p field is
349 @postrefcountsame{field}
351 @sa bt_field_get_type_id(): Returns the type ID of a given
354 extern bt_bool
bt_field_is_variant(struct bt_field
*field
);
359 @name Misc. functions
364 @brief Creates a \em deep copy of the @field \p field.
366 You can copy a frozen field: the resulting copy is <em>not frozen</em>.
368 @param[in] field Field to copy.
369 @returns Deep copy of \p field on success,
373 @postrefcountsame{field}
374 @postsuccessrefcountret1
375 @post <strong>On success</strong>, the returned field is not frozen.
377 extern struct bt_field
*bt_field_copy(struct bt_field
*field
);
384 @defgroup ctfirintfield CTF IR integer field
386 @brief CTF IR integer field.
389 #include <babeltrace/ctf-ir/fields.h>
392 A CTF IR <strong><em>integer field</em></strong> is a @field which
393 holds a signed or unsigned integral value, and which is described by
396 An integer field object is considered \em unsigned if
397 bt_field_type_integer_get_signed() on its parent field type returns
398 0. Otherwise it is considered \em signed. You \em must use
399 bt_field_integer_unsigned_get_value() and
400 bt_field_integer_unsigned_set_value() with an unsigned integer
401 field, and bt_field_integer_signed_get_value() and
402 bt_field_integer_signed_set_value() with a signed integer field.
404 After you create an integer field with bt_field_create(), you
405 \em must set an integral value with
406 bt_field_integer_unsigned_set_value() or
407 bt_field_integer_signed_set_value() before you can get the
408 field's value with bt_field_integer_unsigned_get_value() or
409 bt_field_integer_signed_get_value().
411 @sa ctfirintfieldtype
414 @addtogroup ctfirintfield
419 @brief Returns the signed integral value of the @intfield
422 @param[in] integer_field Integer field of which to get the
423 signed integral value.
424 @param[out] value Returned signed integral value of
426 @returns 0 on success, or a negative value on
427 error, including if \p integer_field
428 has no integral value yet.
430 @prenotnull{integer_field}
432 @preisintfield{integer_field}
433 @pre bt_field_type_integer_get_signed() returns 1 for the parent
434 @ft of \p integer_field.
435 @pre \p integer_field contains a signed integral value previously
436 set with bt_field_integer_signed_set_value().
437 @postrefcountsame{integer_field}
439 @sa bt_field_integer_signed_set_value(): Sets the signed integral
440 value of a given integer field.
442 extern int bt_field_integer_signed_get_value(
443 struct bt_field
*integer_field
, int64_t *value
);
446 @brief Sets the signed integral value of the @intfield
447 \p integer_field to \p value.
449 @param[in] integer_field Integer field of which to set
450 the signed integral value.
451 @param[in] value New signed integral value of
453 @returns 0 on success, or a negative value on error.
455 @prenotnull{integer_field}
456 @preisintfield{integer_field}
457 @prehot{integer_field}
458 @pre bt_field_type_integer_get_signed() returns 1 for the parent
459 @ft of \p integer_field.
460 @postrefcountsame{integer_field}
462 @sa bt_field_integer_signed_get_value(): Returns the signed integral
463 value of a given integer field.
465 extern int bt_field_integer_signed_set_value(
466 struct bt_field
*integer_field
, int64_t value
);
469 @brief Returns the unsigned integral value of the @intfield
472 @param[in] integer_field Integer field of which to get the
473 unsigned integral value.
474 @param[out] value Returned unsigned integral value of
476 @returns 0 on success, or a negative value on
477 error, including if \p integer_field
478 has no integral value yet.
480 @prenotnull{integer_field}
482 @preisintfield{integer_field}
483 @pre bt_field_type_integer_get_signed() returns 0 for the parent
484 @ft of \p integer_field.
485 @pre \p integer_field contains an unsigned integral value previously
486 set with bt_field_integer_unsigned_set_value().
487 @postrefcountsame{integer_field}
489 @sa bt_field_integer_unsigned_set_value(): Sets the unsigned
490 integral value of a given integer field.
492 extern int bt_field_integer_unsigned_get_value(
493 struct bt_field
*integer_field
, uint64_t *value
);
496 @brief Sets the unsigned integral value of the @intfield
497 \p integer_field to \p value.
499 @param[in] integer_field Integer field of which to set
500 the unsigned integral value.
501 @param[in] value New unsigned integral value of
503 @returns 0 on success, or a negative value on error.
505 @prenotnull{integer_field}
506 @preisintfield{integer_field}
507 @prehot{integer_field}
508 @pre bt_field_type_integer_get_signed() returns 0 for the parent
509 @ft of \p integer_field.
510 @postrefcountsame{integer_field}
512 @sa bt_field_integer_unsigned_get_value(): Returns the unsigned
513 integral value of a given integer field.
515 extern int bt_field_integer_unsigned_set_value(
516 struct bt_field
*integer_field
, uint64_t value
);
521 @defgroup ctfirfloatfield CTF IR floating point number field
523 @brief CTF IR floating point number field.
526 #include <babeltrace/ctf-ir/fields.h>
529 A CTF IR <strong><em>floating point number field</em></strong> is a
530 @field which holds a floating point number value, and which is
531 described by a @floatft.
533 After you create a floating point number field with bt_field_create(), you
534 \em must set a floating point number value with
535 bt_field_floating_point_set_value() before you can get the
536 field's value with bt_field_floating_point_get_value().
538 @sa ctfirfloatfieldtype
541 @addtogroup ctfirfloatfield
546 @brief Returns the floating point number value of the @floatfield
549 @param[in] float_field Floating point number field of which to get the
550 floating point number value.
551 @param[out] value Returned floating point number value of
553 @returns 0 on success, or a negative value on error,
554 including if \p float_field has no floating
555 point number value yet.
557 @prenotnull{float_field}
559 @preisfloatfield{float_field}
560 @pre \p float_field contains a floating point number value previously
561 set with bt_field_floating_point_set_value().
562 @postrefcountsame{float_field}
564 @sa bt_field_floating_point_set_value(): Sets the floating point
565 number value of a given floating point number field.
567 extern int bt_field_floating_point_get_value(
568 struct bt_field
*float_field
, double *value
);
571 @brief Sets the floating point number value of the @floatfield
572 \p float_field to \p value.
574 @param[in] float_field Floating point number field of which to set
575 the floating point number value.
576 @param[in] value New floating point number value of
578 @returns 0 on success, or a negative value on error.
580 @prenotnull{float_field}
581 @preisfloatfield{float_field}
583 @postrefcountsame{float_field}
585 @sa bt_field_floating_point_get_value(): Returns the floating point
586 number value of a given floating point number field.
588 extern int bt_field_floating_point_set_value(
589 struct bt_field
*float_field
, double value
);
594 @defgroup ctfirenumfield CTF IR enumeration field
596 @brief CTF IR enumeration field.
599 #include <babeltrace/ctf-ir/fields.h>
602 A CTF IR <strong><em>enumeration field</em></strong> is a @field which
603 holds a @intfield, and which is described by a @enumft.
605 To set the current integral value of an enumeration field, you need to
606 get its wrapped @intfield with bt_field_enumeration_get_container(),
607 and then set the integral value with either
608 bt_field_integer_signed_set_value() or
609 bt_field_integer_unsigned_set_value().
611 Once you set the integral value of an enumeration field by following the
612 previous paragraph, you can get the mappings containing this value in
613 their range with bt_field_enumeration_get_mappings(). This function
614 returns a @enumftiter.
616 @sa ctfirenumfieldtype
619 @addtogroup ctfirenumfield
623 extern struct bt_field
*bt_field_enumeration_borrow_container(
624 struct bt_field
*enum_field
);
627 @brief Returns the @intfield, potentially creating it, wrapped by the
628 @enumfield \p enum_field.
630 This function creates the @intfield to return if it does not currently
633 @param[in] enum_field Enumeration field of which to get the wrapped
635 @returns Integer field wrapped by \p enum_field, or
638 @prenotnull{enum_field}
639 @preisenumfield{enum_field}
640 @postrefcountsame{enum_field}
641 @postsuccessrefcountretinc
644 struct bt_field
*bt_field_enumeration_get_container(
645 struct bt_field
*enum_field
)
647 return bt_get(bt_field_enumeration_borrow_container(enum_field
));
651 @brief Returns a @enumftiter on all the mappings of the field type of
652 \p enum_field which contain the current integral value of the
653 @enumfield \p enum_field in their range.
655 This function is the equivalent of using
656 bt_field_type_enumeration_find_mappings_by_unsigned_value() or
657 bt_field_type_enumeration_find_mappings_by_signed_value() with the
658 current integral value of \p enum_field.
660 @param[in] enum_field Enumeration field of which to get the mappings
661 containing the current integral value of \p
662 enum_field in their range.
663 @returns @enumftiter on the set of mappings of the field
664 type of \p enum_field which contain the current
665 integral value of \p enum_field in their range,
666 or \c NULL if no mappings were found or on
669 @prenotnull{enum_field}
670 @preisenumfield{enum_field}
671 @pre The wrapped integer field of \p enum_field contains an integral
673 @postrefcountsame{enum_field}
674 @postsuccessrefcountret1
675 @post <strong>On success</strong>, the returned @enumftiter can iterate
676 on at least one mapping.
678 extern struct bt_field_type_enumeration_mapping_iterator
*
679 bt_field_enumeration_get_mappings(struct bt_field
*enum_field
);
684 @defgroup ctfirstringfield CTF IR string field
686 @brief CTF IR string field.
689 #include <babeltrace/ctf-ir/fields.h>
692 A CTF IR <strong><em>string field</em></strong> is a @field which holds
693 a string value, and which is described by a @stringft.
695 Use bt_field_string_set_value() to set the current string value
696 of a string field object. You can also use bt_field_string_append()
697 and bt_field_string_append_len() to append a string to the current
698 value of a string field.
700 After you create a string field with bt_field_create(), you
701 \em must set a string value with
702 bt_field_string_set_value(), bt_field_string_append(), or
703 bt_field_string_append_len() before you can get the
704 field's value with bt_field_string_get_value().
706 @sa ctfirstringfieldtype
709 @addtogroup ctfirstringfield
714 @brief Returns the string value of the @stringfield \p string_field.
716 On success, \p string_field remains the sole owner of the returned
719 @param[in] string_field String field field of which to get the
721 @returns String value, or \c NULL on error.
723 @prenotnull{string_field}
725 @preisstringfield{string_field}
726 @pre \p string_field contains a string value previously
727 set with bt_field_string_set_value(),
728 bt_field_string_append(), or
729 bt_field_string_append_len().
730 @postrefcountsame{string_field}
732 @sa bt_field_string_set_value(): Sets the string value of a given
735 extern const char *bt_field_string_get_value(struct bt_field
*string_field
);
738 @brief Sets the string value of the @stringfield \p string_field to
741 @param[in] string_field String field of which to set
743 @param[in] value New string value of \p string_field (copied
745 @returns 0 on success, or a negative value on error.
747 @prenotnull{string_field}
749 @preisstringfield{string_field}
750 @prehot{string_field}
751 @postrefcountsame{string_field}
753 @sa bt_field_string_get_value(): Returns the string value of a
756 extern int bt_field_string_set_value(struct bt_field
*string_field
,
760 @brief Appends the string \p value to the current string value of
761 the @stringfield \p string_field.
763 This function is the equivalent of:
766 bt_field_string_append_len(string_field, value, strlen(value));
769 @param[in] string_field String field of which to append \p value to
771 @param[in] value String to append to the current string value
772 of \p string_field (copied on success).
773 @returns 0 on success, or a negative value on error.
775 @prenotnull{string_field}
777 @preisstringfield{string_field}
778 @prehot{string_field}
779 @postrefcountsame{string_field}
781 @sa bt_field_string_set_value(): Sets the string value of a given
784 extern int bt_field_string_append(struct bt_field
*string_field
,
788 @brief Appends the first \p length characters of \p value to the
789 current string value of the @stringfield \p string_field.
791 If \p string_field has no current string value, this function first
792 sets an empty string as the string value of \p string_field and then
793 appends the first \p length characters of \p value.
795 @param[in] string_field String field of which to append the first
796 \p length characters of \p value to
798 @param[in] value String containing the characters to append to
799 the current string value of \p string_field
801 @param[in] length Number of characters of \p value to append to
802 the current string value of \p string_field.
803 @returns 0 on success, or a negative value on error.
805 @prenotnull{string_field}
807 @preisstringfield{string_field}
808 @prehot{string_field}
809 @postrefcountsame{string_field}
811 @sa bt_field_string_set_value(): Sets the string value of a given
814 extern int bt_field_string_append_len(
815 struct bt_field
*string_field
, const char *value
,
816 unsigned int length
);
821 @defgroup ctfirstructfield CTF IR structure field
823 @brief CTF IR structure field.
826 #include <babeltrace/ctf-ir/fields.h>
829 A CTF IR <strong><em>structure field</em></strong> is a @field which
830 contains an ordered list of zero or more named @fields which can be
831 different @fts, and which is described by a @structft.
833 To set the value of a specific field of a structure field, you need to
834 first get the field with bt_field_structure_get_field_by_name() or
835 bt_field_structure_get_field_by_index(). If you already have a
836 field object, you can assign it to a specific name within a structure
837 field with bt_field_structure_set_field_by_name().
839 @sa ctfirstructfieldtype
842 @addtogroup ctfirstructfield
846 extern struct bt_field
*bt_field_structure_borrow_field_by_name(
847 struct bt_field
*struct_field
, const char *name
);
850 @brief Returns the @field named \p name, potentially creating it,
851 in the @structfield \p struct_field.
853 This function creates the @field to return if it does not currently
856 @param[in] struct_field Structure field of which to get the field
858 @param[in] name Name of the field to get from \p struct_field.
859 @returns Field named \p name in \p struct_field, or
862 @prenotnull{struct_field}
864 @preisstructfield{struct_field}
865 @postrefcountsame{struct_field}
866 @postsuccessrefcountretinc
868 @sa bt_field_structure_get_field_by_index(): Returns the field of a
869 given structure field by index.
870 @sa bt_field_structure_set_field_by_name(): Sets the field of a
871 given structure field by name.
874 struct bt_field
*bt_field_structure_get_field_by_name(
875 struct bt_field
*struct_field
, const char *name
)
877 return bt_get(bt_field_structure_borrow_field_by_name(struct_field
,
881 extern struct bt_field
*bt_field_structure_borrow_field_by_index(
882 struct bt_field
*struct_field
, uint64_t index
);
885 @brief Returns the @field at index \p index in the @structfield
888 @param[in] struct_field Structure field of which to get the field
890 @param[in] index Index of the field to get in \p struct_field.
891 @returns Field at index \p index in \p struct_field, or
894 @prenotnull{struct_field}
895 @preisstructfield{struct_field}
896 @pre \p index is lesser than the number of fields contained in the
897 parent field type of \p struct_field (see
898 bt_field_type_structure_get_field_count()).
899 @postrefcountsame{struct_field}
900 @postsuccessrefcountretinc
902 @sa bt_field_structure_get_field_by_name(): Returns the field of a
903 given structure field by name.
904 @sa bt_field_structure_set_field_by_name(): Sets the field of a
905 given structure field by name.
908 struct bt_field
*bt_field_structure_get_field_by_index(
909 struct bt_field
*struct_field
, uint64_t index
)
911 return bt_get(bt_field_structure_borrow_field_by_index(struct_field
,
916 @brief Sets the field of the @structfield \p struct_field named \p name
917 to the @field \p field.
919 If \p struct_field already contains a field named \p name, then it may
920 either be replaced by \p field and its reference count is decremented,
921 or \p field's value is assigned to it.
923 The field type of \p field, as returned by bt_field_get_type(),
924 \em must be equivalent to the field type returned by
925 bt_field_type_structure_get_field_type_by_name() with the field
926 type of \p struct_field and the same name, \p name.
928 bt_trace_get_packet_header_type() for the parent trace class of
931 @param[in] struct_field Structure field of which to set the field
933 @param[in] name Name of the field to set in \p struct_field.
934 @param[in] field Field named \p name to set in \p struct_field.
935 @returns 0 on success, or -1 on error.
937 @prenotnull{struct_field}
940 @prehot{struct_field}
941 @preisstructfield{struct_field}
942 @pre \p field has a field type equivalent to the field type returned by
943 bt_field_type_structure_get_field_type_by_name() for the
944 field type of \p struct_field with the name \p name.
945 @postrefcountsame{struct_field}
946 @post <strong>On success, the field in \p struct_field named \p name</strong>
947 may either be replaced by \p field or have the same value as \p field.
948 @postsuccessrefcountinc{field}
950 @sa bt_field_structure_get_field_by_index(): Returns the field of a
951 given structure field by index.
952 @sa bt_field_structure_get_field_by_name(): Returns the field of a
953 given structure field by name.
955 extern int bt_field_structure_set_field_by_name(
956 struct bt_field
*struct_field
,
957 const char *name
, struct bt_field
*field
);
962 @defgroup ctfirarrayfield CTF IR array field
964 @brief CTF IR array field.
967 #include <babeltrace/ctf-ir/fields.h>
970 A CTF IR <strong><em>array field</em></strong> is a @field which
971 contains an ordered list of zero or more @fields sharing the same @ft,
972 and which is described by a @arrayft.
974 To set the value of a specific field of an array field, you need to
975 first get the field with bt_field_array_get_field().
977 @sa ctfirarrayfieldtype
980 @addtogroup ctfirarrayfield
984 extern struct bt_field
*bt_field_array_borrow_field(
985 struct bt_field
*array_field
, uint64_t index
);
988 @brief Returns the @field at index \p index, potentially creating it,
989 in the @arrayfield \p array_field.
991 This function creates the @field to return if it does not currently
994 @param[in] array_field Array field of which to get the field
996 @param[in] index Index of the field to get in \p array_field.
997 @returns Field at index \p index in \p array_field, or
1000 @prenotnull{array_field}
1001 @preisarrayfield{array_field}
1002 @pre \p index is lesser than bt_field_type_array_get_length() called
1003 on the field type of \p array_field.
1004 @postrefcountsame{array_field}
1005 @postsuccessrefcountretinc
1008 struct bt_field
*bt_field_array_get_field(
1009 struct bt_field
*array_field
, uint64_t index
)
1011 return bt_get(bt_field_array_borrow_field(array_field
, index
));
1017 @defgroup ctfirseqfield CTF IR sequence field
1018 @ingroup ctfirfields
1019 @brief CTF IR sequence field.
1022 #include <babeltrace/ctf-ir/fields.h>
1025 A CTF IR <strong><em>sequence field</em></strong> is a @field which
1026 contains an ordered list of zero or more @fields sharing the same @ft,
1027 and which is described by a @seqft.
1029 Before you can get a specific field of a sequence field with
1030 bt_field_sequence_get_field(), you need to set its current length
1031 @intfield with bt_field_sequence_set_length(). The integral value of
1032 the length field of a sequence field indicates the number of fields
1035 @sa ctfirseqfieldtype
1038 @addtogroup ctfirseqfield
1042 extern struct bt_field
*bt_field_sequence_borrow_field(
1043 struct bt_field
*sequence_field
, uint64_t index
);
1046 @brief Returns the @field at index \p index, potentially creating it,
1047 in the @seqfield \p sequence_field.
1049 This function creates the @field to return if it does not currently
1052 @param[in] sequence_field Sequence field of which to get the field
1054 @param[in] index Index of the field to get in
1056 @returns Field at index \p index in
1057 \p sequence_field, or \c NULL on error.
1059 @prenotnull{sequence_field}
1060 @preisseqfield{sequence_field}
1061 @pre \p sequence_field has a length field previously set with
1062 bt_field_sequence_set_length().
1063 @pre \p index is lesser than the current integral value of the current
1064 length field of \p sequence_field (see
1065 bt_field_sequence_get_length()).
1066 @postrefcountsame{sequence_field}
1067 @postsuccessrefcountretinc
1070 struct bt_field
*bt_field_sequence_get_field(
1071 struct bt_field
*sequence_field
, uint64_t index
)
1073 return bt_get(bt_field_sequence_borrow_field(sequence_field
, index
));
1076 extern struct bt_field
*bt_field_sequence_borrow_length(
1077 struct bt_field
*sequence_field
);
1080 @brief Returns the length @intfield of the @seqfield \p sequence_field.
1082 The current integral value of the returned length field indicates the
1083 number of fields contained in \p sequence_field.
1085 @param[in] sequence_field Sequence field of which to get the
1087 @returns Length field of \p sequence_field, or
1090 @prenotnull{sequence_field}
1091 @preisseqfield{sequence_field}
1092 @pre \p sequence_field has a length field previously set with
1093 bt_field_sequence_set_length().
1094 @postrefcountsame{sequence_field}
1095 @postsuccessrefcountretinc
1096 @post <strong>On success</strong>, the returned field is a @intfield.
1098 @sa bt_field_sequence_set_length(): Sets the length field of a given
1102 struct bt_field
*bt_field_sequence_get_length(
1103 struct bt_field
*sequence_field
)
1105 return bt_get(bt_field_sequence_borrow_length(sequence_field
));
1109 @brief Sets the length @intfield of the @seqfield \p sequence_field
1112 The current integral value of \p length_field indicates the number of
1113 fields contained in \p sequence_field.
1115 @param[in] sequence_field Sequence field of which to set the
1117 @param[in] length_field Length field of \p sequence_field.
1118 @returns 0 on success, or a negative value on error.
1120 @prenotnull{sequence_field}
1121 @prenotnull{length_field}
1122 @preisseqfield{sequence_field}
1123 @preisintfield{length_field}
1124 @prehot{sequence_field}
1125 @postrefcountsame{sequence_field}
1126 @postsuccessrefcountinc{length_field}
1128 @sa bt_field_sequence_get_length(): Returns the length field of a
1129 given sequence field.
1131 extern int bt_field_sequence_set_length(struct bt_field
*sequence_field
,
1132 struct bt_field
*length_field
);
1137 @defgroup ctfirvarfield CTF IR variant field
1138 @ingroup ctfirfields
1139 @brief CTF IR variant field.
1142 #include <babeltrace/ctf-ir/fields.h>
1145 A CTF IR <strong><em>variant field</em></strong> is a @field which
1146 contains a current @field amongst one or more choices, and which is
1147 described by a @varft.
1149 Use bt_field_variant_get_field() to get the @field selected by
1150 a specific tag @enumfield. Once you call this function, you can call
1151 bt_field_variant_get_current_field() afterwards to get this last
1154 @sa ctfirvarfieldtype
1157 @addtogroup ctfirvarfield
1161 extern struct bt_field
*bt_field_variant_borrow_field(
1162 struct bt_field
*variant_field
,
1163 struct bt_field
*tag_field
);
1166 @brief Returns the @field, potentially creating it, selected by the
1167 tag @intfield \p tag_field in the @varfield \p variant_field.
1169 This function creates the @field to return if it does not currently
1172 Once you call this function, you can call
1173 bt_field_variant_get_current_field() to get the same field again,
1174 and you can call bt_field_variant_get_tag() to get \p tag_field.
1176 @param[in] variant_field Variant field of which to get the field
1177 selected by \p tag_field.
1178 @param[in] tag_field Tag field.
1179 @returns Field selected by \p tag_field in
1180 \p variant_field, or \c NULL on error.
1182 @prenotnull{variant_field}
1183 @prenotnull{tag_field}
1184 @preisvarfield{variant_field}
1185 @preisenumfield{tag_field}
1186 @postrefcountsame{variant_field}
1187 @postsuccessrefcountinc{tag_field}
1188 @postsuccessrefcountretinc
1191 struct bt_field
*bt_field_variant_get_field(
1192 struct bt_field
*variant_field
,
1193 struct bt_field
*tag_field
)
1195 return bt_get(bt_field_variant_borrow_field(variant_field
, tag_field
));
1198 extern struct bt_field
*bt_field_variant_borrow_current_field(
1199 struct bt_field
*variant_field
);
1202 @brief Returns the currently selected @field of the @varfield
1205 @param[in] variant_field Variant field of which to get the
1206 currently selected field.
1207 @returns Currently selected field of
1208 \p variant_field, or \c NULL if there's
1209 no selected field or on error.
1211 @prenotnull{variant_field}
1212 @preisvarfield{variant_field}
1213 @pre \p variant_field contains has a current selected field previously
1214 set with bt_field_variant_get_field().
1215 @postrefcountsame{variant_field}
1216 @postsuccessrefcountretinc
1219 struct bt_field
*bt_field_variant_get_current_field(
1220 struct bt_field
*variant_field
)
1222 return bt_get(bt_field_variant_borrow_current_field(variant_field
));
1225 extern struct bt_field
*bt_field_variant_borrow_tag(
1226 struct bt_field
*variant_field
);
1229 @brief Returns the tag @enumfield of the @varfield \p variant_field.
1231 @param[in] variant_field Variant field of which to get the
1233 @returns Tag field of \p variant_field, or
1236 @prenotnull{variant_field}
1237 @preisvarfield{variant_field}
1238 @pre \p variant_field contains has a current selected field previously
1239 set with bt_field_variant_get_field().
1240 @postrefcountsame{variant_field}
1241 @postsuccessrefcountretinc
1242 @post <strong>On success</strong>, the returned field is a @enumfield.
1245 struct bt_field
*bt_field_variant_get_tag(
1246 struct bt_field
*variant_field
)
1248 return bt_get(bt_field_variant_borrow_tag(variant_field
));
1257 #endif /* BABELTRACE_CTF_IR_FIELDS_H */