Rename bt_ctf_X -> bt_X, maintain backward compat. for pre-2.0 CTF writer
[babeltrace.git] / include / babeltrace / ctf-ir / fields.h
CommitLineData
2e33ac5a
PP
1#ifndef BABELTRACE_CTF_IR_FIELDS_H
2#define BABELTRACE_CTF_IR_FIELDS_H
adc315b8
JG
3
4/*
2e33ac5a 5 * Babeltrace - CTF IR: Event Fields
adc315b8 6 *
de9dd397 7 * Copyright 2013, 2014 Jérémie Galarneau <jeremie.galarneau@efficios.com>
adc315b8
JG
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
33#include <stdint.h>
cd95e351 34#include <stddef.h>
9d408fca
PP
35
36/* For bt_bool */
c14d64fa 37#include <babeltrace/types.h>
adc315b8
JG
38
39#ifdef __cplusplus
40extern "C" {
41#endif
42
50842bdc 43struct bt_field_type;
9d408fca 44
91f379cb
PP
45/**
46@defgroup ctfirfields CTF IR fields
47@ingroup ctfir
48@brief CTF IR fields.
49
50@code
51#include <babeltrace/ctf-ir/fields.h>
52@endcode
53
54A CTF IR <strong><em>field</em></strong> is an object which holds a
55concrete value, and which is described by a @ft.
56
57In the CTF IR hierarchy, you can set the root fields of two objects:
58
59- \ref ctfirpacket
50842bdc
PP
60 - Trace packet header field: bt_packet_set_header().
61 - Stream packet context field: bt_packet_set_context().
91f379cb 62- \ref ctfirevent
50842bdc
PP
63 - Stream event header field: bt_event_set_header().
64 - Stream event context field: bt_event_set_stream_event_context().
65 - Event context field: bt_event_set_event_context().
66 - Event payload field: bt_event_set_payload_field().
91f379cb
PP
67
68There are two categories of fields:
69
70- <strong>Basic fields</strong>:
71 - @intfield: contains an integral value.
72 - @floatfield: contains a floating point number value.
73 - @enumfield: contains an integer field which contains an integral
74 value.
75 - @stringfield: contains a string value.
76- <strong>Compound fields</strong>:
77 - @structfield: contains an ordered list of named fields
78 (possibly with different @fts).
79 - @arrayfield: contains an ordered list of fields which share
80 the same field type.
81 - @seqfield: contains an ordered list of fields which share
82 the same field type.
83 - @varfield: contains a single, current field.
84
85You can create a field object from a @ft object with
50842bdc 86bt_field_create(). The enumeration and compound fields create their
91f379cb
PP
87contained fields with the following getters if such fields do not exist
88yet:
89
50842bdc
PP
90- bt_field_enumeration_get_container()
91- bt_field_structure_get_field_by_name()
92- bt_field_array_get_field()
93- bt_field_sequence_get_field()
94- bt_field_variant_get_field()
91f379cb 95
7fcd5734 96If you already have a field object, you can also assign it to a specific
2225de6b 97name within a @structfield with
50842bdc 98bt_field_structure_set_field_by_name().
7fcd5734 99
91f379cb 100You can get a reference to the @ft which was used to create a field with
50842bdc
PP
101bt_field_get_type(). You can get the
102\link #bt_field_type_id type ID\endlink of this field type directly with
103bt_field_get_type_id().
91f379cb 104
50842bdc 105You can get a deep copy of a field with bt_field_copy(). The field
91f379cb
PP
106copy, and its contained field copies if it's the case, have the same
107field type as the originals.
108
109As with any Babeltrace object, CTF IR field objects have
110<a href="https://en.wikipedia.org/wiki/Reference_counting">reference
111counts</a>. See \ref refs to learn more about the reference counting
112management of Babeltrace objects.
113
114The functions which freeze CTF IR \link ctfirpacket packet\endlink and
115\link ctfirevent event\endlink objects also freeze their root field
116objects. You cannot modify a frozen field object: it is considered
117immutable, except for \link refs reference counting\endlink.
118
119@sa ctfirfieldtypes
120
121@file
122@brief CTF IR fields type and functions.
123@sa ctfirfields
124
125@addtogroup ctfirfields
126@{
127*/
128
129/**
50842bdc 130@struct bt_field
91f379cb
PP
131@brief A CTF IR field.
132@sa ctfirfields
133*/
50842bdc
PP
134struct bt_field;
135struct bt_event_class;
136struct bt_event;
137struct bt_field_type;
138struct bt_field_type_enumeration_mapping_iterator;
adc315b8 139
91f379cb
PP
140/**
141@name Creation and parent field type access functions
142@{
143*/
144
145/**
146@brief Creates an uninitialized @field described by the @ft
147 \p field_type.
148
149On success, \p field_type becomes the parent of the created field
150object.
151
152On success, this function creates an \em uninitialized field: it has
153no value. You need to set the value of the created field with one of the
154its specific setters.
155
156@param[in] field_type Field type which describes the field to create.
157@returns Created field object, or \c NULL on error.
158
159@prenotnull{field_type}
160@postsuccessrefcountret1
161@postsuccessfrozen{field_type}
162*/
50842bdc
PP
163extern struct bt_field *bt_field_create(
164 struct bt_field_type *field_type);
adc315b8 165
91f379cb
PP
166/**
167@brief Returns the parent @ft of the @field \p field.
adc315b8 168
91f379cb 169This function returns a reference to the field type which was used to
50842bdc 170create the field object in the first place with bt_field_create().
cd95e351 171
91f379cb
PP
172@param[in] field Field of which to get the parent field type.
173@returns Parent field type of \p event,
174 or \c NULL on error.
adc315b8 175
91f379cb
PP
176@prenotnull{field}
177@postrefcountsame{field}
178@postsuccessrefcountretinc
179*/
50842bdc
PP
180extern struct bt_field_type *bt_field_get_type(
181 struct bt_field *field);
cd95e351 182
91f379cb 183/** @} */
adc315b8 184
91f379cb
PP
185/**
186@name Type information
187@{
188*/
adc315b8 189
91f379cb
PP
190/**
191@brief Returns the type ID of the @ft of the @field \p field.
adc315b8 192
91f379cb
PP
193@param[in] field Field of which to get the type ID of its
194 parent field type..
195@returns Type ID of the parent field type of \p field,
50842bdc 196 or #BT_FIELD_TYPE_ID_UNKNOWN on error.
3f4a108d 197
91f379cb
PP
198@prenotnull{field}
199@postrefcountsame{field}
f78d67fb 200
50842bdc
PP
201@sa #bt_field_type_id: CTF IR field type ID.
202@sa bt_field_is_integer(): Returns whether or not a given field is a
91f379cb 203 @intfield.
50842bdc 204@sa bt_field_is_floating_point(): Returns whether or not a given
91f379cb 205 field is a @floatfield.
50842bdc 206@sa bt_field_is_enumeration(): Returns whether or not a given field
91f379cb 207 is a @enumfield.
50842bdc 208@sa bt_field_is_string(): Returns whether or not a given field is a
91f379cb 209 @stringfield.
50842bdc 210@sa bt_field_is_structure(): Returns whether or not a given field is
91f379cb 211 a @structfield.
50842bdc 212@sa bt_field_is_array(): Returns whether or not a given field is a
91f379cb 213 @arrayfield.
50842bdc 214@sa bt_field_is_sequence(): Returns whether or not a given field is
91f379cb 215 a @seqfield.
50842bdc 216@sa bt_field_is_variant(): Returns whether or not a given field is a
91f379cb
PP
217 @varfield.
218*/
50842bdc
PP
219extern enum bt_field_type_id bt_field_get_type_id(
220 struct bt_field *field);
6ead1648
JG
221
222
50842bdc 223extern bt_bool bt_field_is_set(struct bt_field *field);
6ead1648 224
50842bdc 225extern int bt_field_reset(struct bt_field *field);
adc315b8 226
96e8f959 227/*
50842bdc 228 * bt_field_signed_integer_get_value: get a signed integer field's value
96e8f959
MD
229 *
230 * Get a signed integer field's value.
231 *
232 * @param integer Signed integer field instance.
233 * @param value Pointer to a signed integer where the value will be stored.
234 *
235 * Returns 0 on success, a negative value on error.
236 */
50842bdc 237extern int bt_field_signed_integer_get_value(struct bt_field *integer,
96e8f959
MD
238 int64_t *value);
239
91f379cb
PP
240/**
241@brief Returns whether or not the @field \p field is a @intfield.
cd95e351 242
91f379cb 243@param[in] field Field to check (can be \c NULL).
c14d64fa
PP
244@returns #BT_TRUE if \p field is an integer field, or
245 #BT_FALSE otherwise (including if \p field is
91f379cb 246 \c NULL).
cd95e351 247
91f379cb
PP
248@prenotnull{field}
249@postrefcountsame{field}
adc315b8 250
50842bdc 251@sa bt_field_get_type_id(): Returns the type ID of a given
91f379cb
PP
252 field's type.
253*/
50842bdc 254extern bt_bool bt_field_is_integer(struct bt_field *field);
cd95e351 255
91f379cb
PP
256/**
257@brief Returns whether or not the @field \p field is a @floatfield.
adc315b8 258
91f379cb 259@param[in] field Field to check (can be \c NULL).
c14d64fa
PP
260@returns #BT_TRUE if \p field is a floating point number fiel
261 #BT_FALSE or 0 otherwise (including if \p field is
91f379cb
PP
262 \c NULL).
263
264@prenotnull{field}
265@postrefcountsame{field}
266
50842bdc 267@sa bt_field_get_type_id(): Returns the type ID of a given
91f379cb
PP
268 field's type.
269*/
50842bdc 270extern bt_bool bt_field_is_floating_point(struct bt_field *field);
91f379cb
PP
271
272/**
273@brief Returns whether or not the @field \p field is a @enumfield.
274
275@param[in] field Field to check (can be \c NULL).
c14d64fa
PP
276@returns #BT_TRUE if \p field is an enumeration field, or
277 #BT_FALSE otherwise (including if \p field is
91f379cb
PP
278 \c NULL).
279
280@prenotnull{field}
281@postrefcountsame{field}
282
50842bdc 283@sa bt_field_get_type_id(): Returns the type ID of a given
91f379cb
PP
284 field's type.
285*/
50842bdc 286extern bt_bool bt_field_is_enumeration(struct bt_field *field);
91f379cb
PP
287
288/**
289@brief Returns whether or not the @field \p field is a @stringfield.
290
291@param[in] field Field to check (can be \c NULL).
c14d64fa
PP
292@returns #BT_TRUE if \p field is a string field, or
293 #BT_FALSE otherwise (including if \p field is
91f379cb
PP
294 \c NULL).
295
296@prenotnull{field}
297@postrefcountsame{field}
298
50842bdc 299@sa bt_field_get_type_id(): Returns the type ID of a given
91f379cb
PP
300 field's type.
301*/
50842bdc 302extern bt_bool bt_field_is_string(struct bt_field *field);
91f379cb
PP
303
304/**
305@brief Returns whether or not the @field \p field is a @structfield.
306
307@param[in] field Field to check (can be \c NULL).
c14d64fa
PP
308@returns #BT_TRUE if \p field is a structure field, or
309 #BT_FALSE otherwise (including if \p field is
91f379cb
PP
310 \c NULL).
311
312@prenotnull{field}
313@postrefcountsame{field}
314
50842bdc 315@sa bt_field_get_type_id(): Returns the type ID of a given
91f379cb
PP
316 field's type.
317*/
50842bdc 318extern bt_bool bt_field_is_structure(struct bt_field *field);
91f379cb
PP
319
320/**
321@brief Returns whether or not the @field \p field is a @arrayfield.
322
323@param[in] field Field to check (can be \c NULL).
c14d64fa
PP
324@returns #BT_TRUE if \p field is an array field, or
325 #BT_FALSE otherwise (including if \p field is
91f379cb
PP
326 \c NULL).
327
328@prenotnull{field}
329@postrefcountsame{field}
330
50842bdc 331@sa bt_field_get_type_id(): Returns the type ID of a given
91f379cb
PP
332 field's type.
333*/
50842bdc 334extern bt_bool bt_field_is_array(struct bt_field *field);
91f379cb
PP
335
336/**
337@brief Returns whether or not the @field \p field is a @seqfield.
338
339@param[in] field Field to check (can be \c NULL).
c14d64fa
PP
340@returns #BT_TRUE if \p field is a sequence field, or
341 #BT_FALSE otherwise (including if \p field is
91f379cb
PP
342 \c NULL).
343
344@prenotnull{field}
345@postrefcountsame{field}
346
50842bdc 347@sa bt_field_get_type_id(): Returns the type ID of a given
91f379cb
PP
348 field's type.
349*/
50842bdc 350extern bt_bool bt_field_is_sequence(struct bt_field *field);
91f379cb
PP
351
352/**
353@brief Returns whether or not the @field \p field is a @varfield.
354
355@param[in] field Field to check (can be \c NULL).
c14d64fa
PP
356@returns #BT_TRUE if \p field is a variant field, or
357 #BT_FALSE otherwise (including if \p field is
91f379cb
PP
358 \c NULL).
359
360@prenotnull{field}
361@postrefcountsame{field}
362
50842bdc 363@sa bt_field_get_type_id(): Returns the type ID of a given
91f379cb
PP
364 field's type.
365*/
50842bdc 366extern bt_bool bt_field_is_variant(struct bt_field *field);
91f379cb
PP
367
368/** @} */
369
370/**
371@name Misc. functions
372@{
373*/
374
375/**
376@brief Creates a \em deep copy of the @field \p field.
377
378You can copy a frozen field: the resulting copy is <em>not frozen</em>.
379
380@param[in] field Field to copy.
381@returns Deep copy of \p field on success,
382 or \c NULL on error.
383
384@prenotnull{field}
385@postrefcountsame{field}
386@postsuccessrefcountret1
387@post <strong>On success</strong>, the returned field is not frozen.
388*/
50842bdc 389extern struct bt_field *bt_field_copy(struct bt_field *field);
91f379cb
PP
390
391/** @} */
392
393/** @} */
394
395/**
396@defgroup ctfirintfield CTF IR integer field
397@ingroup ctfirfields
398@brief CTF IR integer field.
399
400@code
401#include <babeltrace/ctf-ir/fields.h>
402@endcode
403
404A CTF IR <strong><em>integer field</em></strong> is a @field which
405holds a signed or unsigned integral value, and which is described by
406a @intft.
407
408An integer field object is considered \em unsigned if
50842bdc 409bt_field_type_integer_get_signed() on its parent field type returns
91f379cb 4100. Otherwise it is considered \em signed. You \em must use
50842bdc
PP
411bt_field_unsigned_integer_get_value() and
412bt_field_unsigned_integer_set_value() with an unsigned integer
413field, and bt_field_signed_integer_get_value() and
414bt_field_signed_integer_set_value() with a signed integer field.
91f379cb 415
50842bdc 416After you create an integer field with bt_field_create(), you
91f379cb 417\em must set an integral value with
50842bdc
PP
418bt_field_unsigned_integer_set_value() or
419bt_field_signed_integer_set_value() before you can get the
420field's value with bt_field_unsigned_integer_get_value() or
421bt_field_signed_integer_get_value().
91f379cb
PP
422
423@sa ctfirintfieldtype
424@sa ctfirfields
425
426@addtogroup ctfirintfield
427@{
428*/
429
430/**
431@brief Returns the signed integral value of the @intfield
432 \p integer_field.
433
434@param[in] integer_field Integer field of which to get the
435 signed integral value.
436@param[out] value Returned signed integral value of
437 \p integer_field.
438@returns 0 on success, or a negative value on
439 error, including if \p integer_field
440 has no integral value yet.
441
442@prenotnull{integer_field}
443@prenotnull{value}
444@preisintfield{integer_field}
50842bdc 445@pre bt_field_type_integer_get_signed() returns 1 for the parent
91f379cb
PP
446 @ft of \p integer_field.
447@pre \p integer_field contains a signed integral value previously
50842bdc 448 set with bt_field_signed_integer_set_value().
91f379cb
PP
449@postrefcountsame{integer_field}
450
50842bdc 451@sa bt_field_signed_integer_set_value(): Sets the signed integral
91f379cb
PP
452 value of a given integer field.
453*/
50842bdc
PP
454extern int bt_field_signed_integer_get_value(
455 struct bt_field *integer_field, int64_t *value);
91f379cb
PP
456
457/**
458@brief Sets the signed integral value of the @intfield
459 \p integer_field to \p value.
460
461@param[in] integer_field Integer field of which to set
462 the signed integral value.
463@param[in] value New signed integral value of
464 \p integer_field.
465@returns 0 on success, or a negative value on error.
466
467@prenotnull{integer_field}
468@preisintfield{integer_field}
469@prehot{integer_field}
50842bdc 470@pre bt_field_type_integer_get_signed() returns 1 for the parent
91f379cb
PP
471 @ft of \p integer_field.
472@postrefcountsame{integer_field}
473
50842bdc 474@sa bt_field_signed_integer_get_value(): Returns the signed integral
91f379cb
PP
475 value of a given integer field.
476*/
50842bdc
PP
477extern int bt_field_signed_integer_set_value(
478 struct bt_field *integer_field, int64_t value);
91f379cb
PP
479
480/**
481@brief Returns the unsigned integral value of the @intfield
482 \p integer_field.
483
484@param[in] integer_field Integer field of which to get the
485 unsigned integral value.
486@param[out] value Returned unsigned integral value of
487 \p integer_field.
488@returns 0 on success, or a negative value on
489 error, including if \p integer_field
490 has no integral value yet.
491
492@prenotnull{integer_field}
493@prenotnull{value}
494@preisintfield{integer_field}
50842bdc 495@pre bt_field_type_integer_get_signed() returns 0 for the parent
91f379cb
PP
496 @ft of \p integer_field.
497@pre \p integer_field contains an unsigned integral value previously
50842bdc 498 set with bt_field_unsigned_integer_set_value().
91f379cb
PP
499@postrefcountsame{integer_field}
500
50842bdc 501@sa bt_field_unsigned_integer_set_value(): Sets the unsigned
91f379cb
PP
502 integral value of a given integer field.
503*/
50842bdc
PP
504extern int bt_field_unsigned_integer_get_value(
505 struct bt_field *integer_field, uint64_t *value);
91f379cb
PP
506
507/**
508@brief Sets the unsigned integral value of the @intfield
509 \p integer_field to \p value.
510
511@param[in] integer_field Integer field of which to set
512 the unsigned integral value.
513@param[in] value New unsigned integral value of
514 \p integer_field.
515@returns 0 on success, or a negative value on error.
516
517@prenotnull{integer_field}
518@preisintfield{integer_field}
519@prehot{integer_field}
50842bdc 520@pre bt_field_type_integer_get_signed() returns 0 for the parent
91f379cb
PP
521 @ft of \p integer_field.
522@postrefcountsame{integer_field}
523
50842bdc 524@sa bt_field_unsigned_integer_get_value(): Returns the unsigned
91f379cb
PP
525 integral value of a given integer field.
526*/
50842bdc
PP
527extern int bt_field_unsigned_integer_set_value(
528 struct bt_field *integer_field, uint64_t value);
91f379cb
PP
529
530/** @} */
531
532/**
533@defgroup ctfirfloatfield CTF IR floating point number field
534@ingroup ctfirfields
535@brief CTF IR floating point number field.
536
537@code
538#include <babeltrace/ctf-ir/fields.h>
539@endcode
540
541A CTF IR <strong><em>floating point number field</em></strong> is a
542@field which holds a floating point number value, and which is
543described by a @floatft.
544
50842bdc 545After you create a floating point number field with bt_field_create(), you
91f379cb 546\em must set a floating point number value with
50842bdc
PP
547bt_field_floating_point_set_value() before you can get the
548field's value with bt_field_floating_point_get_value().
91f379cb
PP
549
550@sa ctfirfloatfieldtype
551@sa ctfirfields
552
553@addtogroup ctfirfloatfield
554@{
555*/
556
557/**
558@brief Returns the floating point number value of the @floatfield
559 \p float_field.
560
561@param[in] float_field Floating point number field of which to get the
562 floating point number value.
563@param[out] value Returned floating point number value of
564 \p float_field.
565@returns 0 on success, or a negative value on error,
566 including if \p float_field has no floating
567 point number value yet.
568
569@prenotnull{float_field}
570@prenotnull{value}
571@preisfloatfield{float_field}
572@pre \p float_field contains a floating point number value previously
50842bdc 573 set with bt_field_floating_point_set_value().
91f379cb
PP
574@postrefcountsame{float_field}
575
50842bdc 576@sa bt_field_floating_point_set_value(): Sets the floating point
91f379cb
PP
577 number value of a given floating point number field.
578*/
50842bdc
PP
579extern int bt_field_floating_point_get_value(
580 struct bt_field *float_field, double *value);
cd95e351 581
91f379cb
PP
582/**
583@brief Sets the floating point number value of the @floatfield
584 \p float_field to \p value.
585
586@param[in] float_field Floating point number field of which to set
587 the floating point number value.
588@param[in] value New floating point number value of
589 \p float_field.
590@returns 0 on success, or a negative value on error.
591
592@prenotnull{float_field}
593@preisfloatfield{float_field}
594@prehot{float_field}
595@postrefcountsame{float_field}
596
50842bdc 597@sa bt_field_floating_point_get_value(): Returns the floating point
91f379cb
PP
598 number value of a given floating point number field.
599*/
50842bdc
PP
600extern int bt_field_floating_point_set_value(
601 struct bt_field *float_field,
adc315b8
JG
602 double value);
603
91f379cb
PP
604/** @} */
605
606/**
607@defgroup ctfirenumfield CTF IR enumeration field
608@ingroup ctfirfields
609@brief CTF IR enumeration field.
610
611@code
612#include <babeltrace/ctf-ir/fields.h>
613@endcode
614
615A CTF IR <strong><em>enumeration field</em></strong> is a @field which
616holds a @intfield, and which is described by a @enumft.
617
618To set the current integral value of an enumeration field, you need to
50842bdc 619get its wrapped @intfield with bt_field_enumeration_get_container(),
91f379cb 620and then set the integral value with either
50842bdc
PP
621bt_field_signed_integer_set_value() or
622bt_field_unsigned_integer_set_value().
91f379cb
PP
623
624Once you set the integral value of an enumeration field by following the
5c3f3b7e 625previous paragraph, you can get the mappings containing this value in
50842bdc 626their range with bt_field_enumeration_get_mappings(). This function
5c3f3b7e 627returns a @enumftiter.
91f379cb
PP
628
629@sa ctfirenumfieldtype
630@sa ctfirfields
631
632@addtogroup ctfirenumfield
633@{
634*/
635
636/**
637@brief Returns the @intfield, potentially creating it, wrapped by the
638 @enumfield \p enum_field.
639
640This function creates the @intfield to return if it does not currently
641exist.
642
643@param[in] enum_field Enumeration field of which to get the wrapped
644 integer field.
645@returns Integer field wrapped by \p enum_field, or
646 \c NULL on error.
647
648@prenotnull{enum_field}
649@preisenumfield{enum_field}
650@postrefcountsame{enum_field}
651@postsuccessrefcountretinc
652*/
50842bdc
PP
653extern struct bt_field *bt_field_enumeration_get_container(
654 struct bt_field *enum_field);
91f379cb
PP
655
656/**
5c3f3b7e
PP
657@brief Returns a @enumftiter on all the mappings of the field type of
658 \p enum_field which contain the current integral value of the
659 @enumfield \p enum_field in their range.
660
661This function is the equivalent of using
50842bdc
PP
662bt_field_type_enumeration_find_mappings_by_unsigned_value() or
663bt_field_type_enumeration_find_mappings_by_signed_value() with the
5c3f3b7e
PP
664current integral value of \p enum_field.
665
666@param[in] enum_field Enumeration field of which to get the mappings
667 containing the current integral value of \p
668 enum_field in their range.
669@returns @enumftiter on the set of mappings of the field
670 type of \p enum_field which contain the current
671 integral value of \p enum_field in their range,
672 or \c NULL if no mappings were found or on
673 error.
91f379cb
PP
674
675@prenotnull{enum_field}
676@preisenumfield{enum_field}
677@pre The wrapped integer field of \p enum_field contains an integral
678 value.
679@postrefcountsame{enum_field}
8dc7eb94 680@postsuccessrefcountret1
5c3f3b7e
PP
681@post <strong>On success</strong>, the returned @enumftiter can iterate
682 on at least one mapping.
91f379cb 683*/
50842bdc
PP
684extern struct bt_field_type_enumeration_mapping_iterator *
685bt_field_enumeration_get_mappings(struct bt_field *enum_field);
91f379cb
PP
686
687/** @} */
688
689/**
690@defgroup ctfirstringfield CTF IR string field
691@ingroup ctfirfields
692@brief CTF IR string field.
693
694@code
695#include <babeltrace/ctf-ir/fields.h>
696@endcode
697
698A CTF IR <strong><em>string field</em></strong> is a @field which holds
699a string value, and which is described by a @stringft.
700
50842bdc
PP
701Use bt_field_string_set_value() to set the current string value
702of a string field object. You can also use bt_field_string_append()
703and bt_field_string_append_len() to append a string to the current
91f379cb
PP
704value of a string field.
705
50842bdc 706After you create a string field with bt_field_create(), you
91f379cb 707\em must set a string value with
50842bdc
PP
708bt_field_string_set_value(), bt_field_string_append(), or
709bt_field_string_append_len() before you can get the
710field's value with bt_field_string_get_value().
91f379cb
PP
711
712@sa ctfirstringfieldtype
713@sa ctfirfields
714
715@addtogroup ctfirstringfield
716@{
717*/
718
719/**
720@brief Returns the string value of the @stringfield \p string_field.
721
722On success, \p string_field remains the sole owner of the returned
723value.
724
725@param[in] string_field String field field of which to get the
726 string value.
727@returns String value, or \c NULL on error.
728
729@prenotnull{string_field}
730@prenotnull{value}
731@preisstringfield{string_field}
732@pre \p string_field contains a string value previously
50842bdc
PP
733 set with bt_field_string_set_value(),
734 bt_field_string_append(), or
735 bt_field_string_append_len().
91f379cb
PP
736@postrefcountsame{string_field}
737
50842bdc 738@sa bt_field_string_set_value(): Sets the string value of a given
91f379cb
PP
739 string field.
740*/
50842bdc
PP
741extern const char *bt_field_string_get_value(
742 struct bt_field *string_field);
cd95e351 743
91f379cb
PP
744/**
745@brief Sets the string value of the @stringfield \p string_field to
746 \p value.
747
748@param[in] string_field String field of which to set
749 the string value.
750@param[in] value New string value of \p string_field (copied
751 on success).
752@returns 0 on success, or a negative value on error.
753
754@prenotnull{string_field}
755@prenotnull{value}
756@preisstringfield{string_field}
757@prehot{string_field}
758@postrefcountsame{string_field}
759
50842bdc 760@sa bt_field_string_get_value(): Returns the string value of a
91f379cb
PP
761 given string field.
762*/
50842bdc 763extern int bt_field_string_set_value(struct bt_field *string_field,
adc315b8
JG
764 const char *value);
765
91f379cb
PP
766/**
767@brief Appends the string \p value to the current string value of
768 the @stringfield \p string_field.
769
770This function is the equivalent of:
771
772@code
50842bdc 773bt_field_string_append_len(string_field, value, strlen(value));
91f379cb
PP
774@endcode
775
776@param[in] string_field String field of which to append \p value to
777 its current value.
778@param[in] value String to append to the current string value
779 of \p string_field (copied on success).
780@returns 0 on success, or a negative value on error.
781
782@prenotnull{string_field}
783@prenotnull{value}
784@preisstringfield{string_field}
785@prehot{string_field}
786@postrefcountsame{string_field}
787
50842bdc 788@sa bt_field_string_set_value(): Sets the string value of a given
91f379cb
PP
789 string field.
790*/
50842bdc 791extern int bt_field_string_append(struct bt_field *string_field,
c6f9c5a3
PP
792 const char *value);
793
91f379cb
PP
794/**
795@brief Appends the first \p length characters of \p value to the
796 current string value of the @stringfield \p string_field.
797
798If \p string_field has no current string value, this function first
799sets an empty string as the string value of \p string_field and then
800appends the first \p length characters of \p value.
801
802@param[in] string_field String field of which to append the first
803 \p length characters of \p value to
804 its current value.
805@param[in] value String containing the characters to append to
806 the current string value of \p string_field
807 (copied on success).
808@param[in] length Number of characters of \p value to append to
809 the current string value of \p string_field.
810@returns 0 on success, or a negative value on error.
811
812@prenotnull{string_field}
813@prenotnull{value}
814@preisstringfield{string_field}
815@prehot{string_field}
816@postrefcountsame{string_field}
817
50842bdc 818@sa bt_field_string_set_value(): Sets the string value of a given
91f379cb
PP
819 string field.
820*/
50842bdc
PP
821extern int bt_field_string_append_len(
822 struct bt_field *string_field, const char *value,
f98c6554
PP
823 unsigned int length);
824
91f379cb 825/** @} */
cd95e351 826
91f379cb
PP
827/**
828@defgroup ctfirstructfield CTF IR structure field
829@ingroup ctfirfields
830@brief CTF IR structure field.
4ebcc695 831
91f379cb
PP
832@code
833#include <babeltrace/ctf-ir/fields.h>
834@endcode
8f3553be 835
91f379cb
PP
836A CTF IR <strong><em>structure field</em></strong> is a @field which
837contains an ordered list of zero or more named @fields which can be
838different @fts, and which is described by a @structft.
8f3553be 839
91f379cb 840To set the value of a specific field of a structure field, you need to
50842bdc
PP
841first get the field with bt_field_structure_get_field_by_name() or
842bt_field_structure_get_field_by_index(). If you already have a
7fcd5734 843field object, you can assign it to a specific name within a structure
50842bdc 844field with bt_field_structure_set_field_by_name().
8f3553be 845
91f379cb
PP
846@sa ctfirstructfieldtype
847@sa ctfirfields
8f3553be 848
91f379cb
PP
849@addtogroup ctfirstructfield
850@{
851*/
8f3553be 852
91f379cb
PP
853/**
854@brief Returns the @field named \p name, potentially creating it,
855 in the @structfield \p struct_field.
8f3553be 856
91f379cb
PP
857This function creates the @field to return if it does not currently
858exist.
8f3553be 859
91f379cb
PP
860@param[in] struct_field Structure field of which to get the field
861 named \p name.
862@param[in] name Name of the field to get from \p struct_field.
863@returns Field named \p name in \p struct_field, or
864 \c NULL on error.
8f3553be 865
91f379cb
PP
866@prenotnull{struct_field}
867@prenotnull{name}
868@preisstructfield{struct_field}
869@postrefcountsame{struct_field}
870@postsuccessrefcountretinc
871
50842bdc 872@sa bt_field_structure_get_field_by_index(): Returns the field of a
91f379cb 873 given structure field by index.
50842bdc 874@sa bt_field_structure_set_field_by_name(): Sets the field of a
2225de6b 875 given structure field by name.
91f379cb 876*/
50842bdc
PP
877extern struct bt_field *bt_field_structure_get_field_by_name(
878 struct bt_field *struct_field, const char *name);
9ac68eb1 879
91f379cb
PP
880/**
881@brief Returns the @field at index \p index in the @structfield
882 \p struct_field.
883
884@param[in] struct_field Structure field of which to get the field
885 at index \p index.
886@param[in] index Index of the field to get in \p struct_field.
887@returns Field at index \p index in \p struct_field, or
888 \c NULL on error.
889
890@prenotnull{struct_field}
891@preisstructfield{struct_field}
892@pre \p index is lesser than the number of fields contained in the
893 parent field type of \p struct_field (see
50842bdc 894 bt_field_type_structure_get_field_count()).
91f379cb
PP
895@postrefcountsame{struct_field}
896@postsuccessrefcountretinc
897
50842bdc 898@sa bt_field_structure_get_field_by_name(): Returns the field of a
2225de6b 899 given structure field by name.
50842bdc 900@sa bt_field_structure_set_field_by_name(): Sets the field of a
91f379cb
PP
901 given structure field by name.
902*/
50842bdc
PP
903extern struct bt_field *bt_field_structure_get_field_by_index(
904 struct bt_field *struct_field, uint64_t index);
91f379cb 905
7fcd5734
JD
906/**
907@brief Sets the field of the @structfield \p struct_field named \p name
908 to the @field \p field.
909
0efd97ce
JG
910If \p struct_field already contains a field named \p name, then it may
911either be replaced by \p field and its reference count is decremented,
912or \p field's value is assigned to it.
7fcd5734 913
50842bdc 914The field type of \p field, as returned by bt_field_get_type(),
7fcd5734 915\em must be equivalent to the field type returned by
50842bdc 916bt_field_type_structure_get_field_type_by_name() with the field
7fcd5734
JD
917type of \p struct_field and the same name, \p name.
918
50842bdc 919bt_trace_get_packet_header_type() for the parent trace class of
7fcd5734
JD
920\p packet.
921
922@param[in] struct_field Structure field of which to set the field
923 named \p name.
924@param[in] name Name of the field to set in \p struct_field.
925@param[in] field Field named \p name to set in \p struct_field.
926@returns 0 on success, or -1 on error.
927
928@prenotnull{struct_field}
929@prenotnull{name}
930@prenotnull{field}
931@prehot{struct_field}
932@preisstructfield{struct_field}
933@pre \p field has a field type equivalent to the field type returned by
50842bdc 934 bt_field_type_structure_get_field_type_by_name() for the
7fcd5734
JD
935 field type of \p struct_field with the name \p name.
936@postrefcountsame{struct_field}
0efd97ce
JG
937@post <strong>On success, the field in \p struct_field named \p name</strong>
938 may either be replaced by \p field or have the same value as \p field.
7fcd5734
JD
939@postsuccessrefcountinc{field}
940
50842bdc 941@sa bt_field_structure_get_field_by_index(): Returns the field of a
7fcd5734 942 given structure field by index.
50842bdc 943@sa bt_field_structure_get_field_by_name(): Returns the field of a
7fcd5734
JD
944 given structure field by name.
945*/
50842bdc
PP
946extern int bt_field_structure_set_field_by_name(
947 struct bt_field *struct_field,
948 const char *name, struct bt_field *field);
7fcd5734 949
91f379cb
PP
950/** @} */
951
952/**
953@defgroup ctfirarrayfield CTF IR array field
954@ingroup ctfirfields
955@brief CTF IR array field.
956
957@code
958#include <babeltrace/ctf-ir/fields.h>
959@endcode
960
961A CTF IR <strong><em>array field</em></strong> is a @field which
962contains an ordered list of zero or more @fields sharing the same @ft,
963and which is described by a @arrayft.
964
965To set the value of a specific field of an array field, you need to
50842bdc 966first get the field with bt_field_array_get_field().
91f379cb
PP
967
968@sa ctfirarrayfieldtype
969@sa ctfirfields
970
971@addtogroup ctfirarrayfield
972@{
973*/
974
975/**
976@brief Returns the @field at index \p index, potentially creating it,
977 in the @arrayfield \p array_field.
978
979This function creates the @field to return if it does not currently
980exist.
981
982@param[in] array_field Array field of which to get the field
983 at index \p index.
984@param[in] index Index of the field to get in \p array_field.
985@returns Field at index \p index in \p array_field, or
986 \c NULL on error.
987
988@prenotnull{array_field}
989@preisarrayfield{array_field}
50842bdc 990@pre \p index is lesser than bt_field_type_array_get_length() called
91f379cb
PP
991 on the field type of \p array_field.
992@postrefcountsame{array_field}
993@postsuccessrefcountretinc
994*/
50842bdc
PP
995extern struct bt_field *bt_field_array_get_field(
996 struct bt_field *array_field, uint64_t index);
91f379cb
PP
997
998/** @} */
999
1000/**
1001@defgroup ctfirseqfield CTF IR sequence field
1002@ingroup ctfirfields
1003@brief CTF IR sequence field.
1004
1005@code
1006#include <babeltrace/ctf-ir/fields.h>
1007@endcode
1008
1009A CTF IR <strong><em>sequence field</em></strong> is a @field which
1010contains an ordered list of zero or more @fields sharing the same @ft,
1011and which is described by a @seqft.
1012
1013Before you can get a specific field of a sequence field with
50842bdc
PP
1014bt_field_sequence_get_field(), you need to set its current length
1015@intfield with bt_field_sequence_set_length(). The integral value of
91f379cb
PP
1016the length field of a sequence field indicates the number of fields
1017it contains.
1018
1019@sa ctfirseqfieldtype
1020@sa ctfirfields
1021
1022@addtogroup ctfirseqfield
1023@{
1024*/
1025
1026/**
1027@brief Returns the @field at index \p index, potentially creating it,
1028 in the @seqfield \p sequence_field.
1029
1030This function creates the @field to return if it does not currently
1031exist.
1032
1033@param[in] sequence_field Sequence field of which to get the field
1034 at index \p index.
1035@param[in] index Index of the field to get in
1036 \p sequence_field.
1037@returns Field at index \p index in
1038 \p sequence_field, or \c NULL on error.
1039
1040@prenotnull{sequence_field}
1041@preisseqfield{sequence_field}
1042@pre \p sequence_field has a length field previously set with
50842bdc 1043 bt_field_sequence_set_length().
91f379cb
PP
1044@pre \p index is lesser than the current integral value of the current
1045 length field of \p sequence_field (see
50842bdc 1046 bt_field_sequence_get_length()).
91f379cb
PP
1047@postrefcountsame{sequence_field}
1048@postsuccessrefcountretinc
1049*/
50842bdc
PP
1050extern struct bt_field *bt_field_sequence_get_field(
1051 struct bt_field *sequence_field, uint64_t index);
91f379cb
PP
1052
1053/**
1054@brief Returns the length @intfield of the @seqfield \p sequence_field.
1055
1056The current integral value of the returned length field indicates the
1057number of fields contained in \p sequence_field.
1058
1059@param[in] sequence_field Sequence field of which to get the
1060 length field.
1061@returns Length field of \p sequence_field, or
1062 \c NULL on error.
1063
1064@prenotnull{sequence_field}
1065@preisseqfield{sequence_field}
1066@pre \p sequence_field has a length field previously set with
50842bdc 1067 bt_field_sequence_set_length().
91f379cb
PP
1068@postrefcountsame{sequence_field}
1069@postsuccessrefcountretinc
1070@post <strong>On success</strong>, the returned field is a @intfield.
1071
50842bdc 1072@sa bt_field_sequence_set_length(): Sets the length field of a given
91f379cb
PP
1073 sequence field.
1074*/
50842bdc
PP
1075extern struct bt_field *bt_field_sequence_get_length(
1076 struct bt_field *sequence_field);
91f379cb
PP
1077
1078/**
1079@brief Sets the length @intfield of the @seqfield \p sequence_field
1080 to \p length_field.
1081
1082The current integral value of \p length_field indicates the number of
1083fields contained in \p sequence_field.
1084
1085@param[in] sequence_field Sequence field of which to set the
1086 length field.
1087@param[in] length_field Length field of \p sequence_field.
1088@returns 0 on success, or a negative value on error.
1089
1090@prenotnull{sequence_field}
1091@prenotnull{length_field}
1092@preisseqfield{sequence_field}
1093@preisintfield{length_field}
1094@prehot{sequence_field}
1095@postrefcountsame{sequence_field}
1096@postsuccessrefcountinc{length_field}
1097
50842bdc 1098@sa bt_field_sequence_get_length(): Returns the length field of a
91f379cb
PP
1099 given sequence field.
1100*/
50842bdc
PP
1101extern int bt_field_sequence_set_length(struct bt_field *sequence_field,
1102 struct bt_field *length_field);
91f379cb
PP
1103
1104/** @} */
1105
1106/**
1107@defgroup ctfirvarfield CTF IR variant field
1108@ingroup ctfirfields
1109@brief CTF IR variant field.
1110
1111@code
1112#include <babeltrace/ctf-ir/fields.h>
1113@endcode
1114
1115A CTF IR <strong><em>variant field</em></strong> is a @field which
1116contains a current @field amongst one or more choices, and which is
1117described by a @varft.
1118
50842bdc 1119Use bt_field_variant_get_field() to get the @field selected by
91f379cb 1120a specific tag @enumfield. Once you call this function, you can call
50842bdc 1121bt_field_variant_get_current_field() afterwards to get this last
91f379cb
PP
1122field again.
1123
1124@sa ctfirvarfieldtype
1125@sa ctfirfields
1126
1127@addtogroup ctfirvarfield
1128@{
1129*/
1130
1131/**
1132@brief Returns the @field, potentially creating it, selected by the
1133 tag @intfield \p tag_field in the @varfield \p variant_field.
1134
1135This function creates the @field to return if it does not currently
1136exist.
1137
1138Once you call this function, you can call
50842bdc
PP
1139bt_field_variant_get_current_field() to get the same field again,
1140and you can call bt_field_variant_get_tag() to get \p tag_field.
91f379cb
PP
1141
1142@param[in] variant_field Variant field of which to get the field
1143 selected by \p tag_field.
1144@param[in] tag_field Tag field.
1145@returns Field selected by \p tag_field in
1146 \p variant_field, or \c NULL on error.
1147
1148@prenotnull{variant_field}
1149@prenotnull{tag_field}
1150@preisvarfield{variant_field}
1151@preisenumfield{tag_field}
1152@postrefcountsame{variant_field}
1153@postsuccessrefcountinc{tag_field}
1154@postsuccessrefcountretinc
1155*/
50842bdc
PP
1156extern struct bt_field *bt_field_variant_get_field(
1157 struct bt_field *variant_field,
1158 struct bt_field *tag_field);
91f379cb
PP
1159
1160/**
1161@brief Returns the currently selected @field of the @varfield
1162 \p variant_field.
1163
1164@param[in] variant_field Variant field of which to get the
1165 currently selected field.
1166@returns Currently selected field of
1167 \p variant_field, or \c NULL if there's
1168 no selected field or on error.
1169
1170@prenotnull{variant_field}
1171@preisvarfield{variant_field}
1172@pre \p variant_field contains has a current selected field previously
50842bdc 1173 set with bt_field_variant_get_field().
91f379cb
PP
1174@postrefcountsame{variant_field}
1175@postsuccessrefcountretinc
1176*/
50842bdc
PP
1177extern struct bt_field *bt_field_variant_get_current_field(
1178 struct bt_field *variant_field);
91f379cb
PP
1179
1180/**
1181@brief Returns the tag @enumfield of the @varfield \p variant_field.
1182
1183@param[in] variant_field Variant field of which to get the
1184 tag field.
1185@returns Tag field of \p variant_field, or
1186 \c NULL on error.
1187
1188@prenotnull{variant_field}
1189@preisvarfield{variant_field}
1190@pre \p variant_field contains has a current selected field previously
50842bdc 1191 set with bt_field_variant_get_field().
91f379cb
PP
1192@postrefcountsame{variant_field}
1193@postsuccessrefcountretinc
1194@post <strong>On success</strong>, the returned field is a @enumfield.
1195*/
50842bdc
PP
1196extern struct bt_field *bt_field_variant_get_tag(
1197 struct bt_field *variant_field);
91f379cb
PP
1198
1199/** @} */
a39fe52e 1200
50842bdc
PP
1201/* Pre-2.0 CTF writer compatibility */
1202#define bt_ctf_field bt_field
1203#define bt_ctf_field_create bt_field_create
1204#define bt_ctf_field_structure_get_field bt_field_structure_get_field_by_name
1205#define bt_ctf_field_variant_get_field bt_field_variant_get_field
1206#define bt_ctf_field_array_get_field bt_field_array_get_field
1207#define bt_ctf_field_sequence_set_length bt_field_sequence_set_length
1208#define bt_ctf_field_sequence_get_field bt_field_sequence_get_field
1209#define bt_ctf_field_enumeration_get_container bt_field_enumeration_get_container
1210#define bt_ctf_field_signed_integer_set_value bt_field_signed_integer_set_value
1211#define bt_ctf_field_unsigned_integer_set_value bt_field_unsigned_integer_set_value
1212#define bt_ctf_field_floating_point_set_value bt_field_floating_point_set_value
1213#define bt_ctf_field_string_set_value bt_field_string_set_value
1214
adc315b8
JG
1215#ifdef __cplusplus
1216}
1217#endif
1218
2e33ac5a 1219#endif /* BABELTRACE_CTF_IR_FIELDS_H */
This page took 0.099395 seconds and 4 git commands to generate.