2 * SPDX-License-Identifier: MIT
4 * Copyright (C) 2010-2019 EfficiOS Inc. and Linux Foundation
7 #ifndef BABELTRACE2_CTF_WRITER_FIELD_TYPES_H
8 #define BABELTRACE2_CTF_WRITER_FIELD_TYPES_H
12 #include <babeltrace2-ctf-writer/types.h>
19 struct bt_ctf_field_type
;
22 /// Unknown, used for errors.
23 BT_CTF_SCOPE_UNKNOWN
= -1,
25 /// Trace packet header.
26 BT_CTF_SCOPE_TRACE_PACKET_HEADER
= 1,
28 /// Stream packet context.
29 BT_CTF_SCOPE_STREAM_PACKET_CONTEXT
= 2,
31 /// Stream event header.
32 BT_CTF_SCOPE_STREAM_EVENT_HEADER
= 3,
34 /// Stream event context.
35 BT_CTF_SCOPE_STREAM_EVENT_CONTEXT
= 4,
38 BT_CTF_SCOPE_EVENT_CONTEXT
= 5,
41 BT_CTF_SCOPE_EVENT_PAYLOAD
= 6,
45 BT_CTF_SCOPE_EVENT_FIELDS
= 6,
49 enum bt_ctf_field_type_id
{
50 BT_CTF_FIELD_TYPE_ID_UNKNOWN
= -1,
51 BT_CTF_FIELD_TYPE_ID_INTEGER
= 0,
52 BT_CTF_FIELD_TYPE_ID_FLOAT
= 1,
53 BT_CTF_FIELD_TYPE_ID_ENUM
= 2,
54 BT_CTF_FIELD_TYPE_ID_STRING
= 3,
55 BT_CTF_FIELD_TYPE_ID_STRUCT
= 4,
56 BT_CTF_FIELD_TYPE_ID_ARRAY
= 5,
57 BT_CTF_FIELD_TYPE_ID_SEQUENCE
= 6,
58 BT_CTF_FIELD_TYPE_ID_VARIANT
= 7,
59 BT_CTF_FIELD_TYPE_ID_NR
,
62 extern enum bt_ctf_field_type_id
bt_ctf_field_type_get_type_id(
63 struct bt_ctf_field_type
*field_type
);
65 enum bt_ctf_byte_order
{
66 BT_CTF_BYTE_ORDER_UNKNOWN
= -1,
67 BT_CTF_BYTE_ORDER_NATIVE
= 0,
68 BT_CTF_BYTE_ORDER_UNSPECIFIED
,
69 BT_CTF_BYTE_ORDER_LITTLE_ENDIAN
,
70 BT_CTF_BYTE_ORDER_BIG_ENDIAN
,
71 BT_CTF_BYTE_ORDER_NETWORK
,
74 enum bt_ctf_string_encoding
{
75 BT_CTF_STRING_ENCODING_UNKNOWN
= -1,
76 BT_CTF_STRING_ENCODING_NONE
,
77 BT_CTF_STRING_ENCODING_UTF8
,
78 BT_CTF_STRING_ENCODING_ASCII
,
81 /* Pre-2.0 CTF writer compatibility */
82 #define ctf_string_encoding bt_ctf_string_encoding
84 extern int bt_ctf_field_type_get_alignment(
85 struct bt_ctf_field_type
*field_type
);
87 extern int bt_ctf_field_type_set_alignment(struct bt_ctf_field_type
*field_type
,
88 unsigned int alignment
);
90 extern enum bt_ctf_byte_order
bt_ctf_field_type_get_byte_order(
91 struct bt_ctf_field_type
*field_type
);
93 extern int bt_ctf_field_type_set_byte_order(
94 struct bt_ctf_field_type
*field_type
,
95 enum bt_ctf_byte_order byte_order
);
97 enum bt_ctf_integer_base
{
98 /// Unknown, used for errors.
99 BT_CTF_INTEGER_BASE_UNKNOWN
= -1,
101 /// Unspecified by the tracer.
102 BT_CTF_INTEGER_BASE_UNSPECIFIED
= 0,
105 BT_CTF_INTEGER_BASE_BINARY
= 2,
108 BT_CTF_INTEGER_BASE_OCTAL
= 8,
111 BT_CTF_INTEGER_BASE_DECIMAL
= 10,
114 BT_CTF_INTEGER_BASE_HEXADECIMAL
= 16,
117 extern struct bt_ctf_field_type
*bt_ctf_field_type_integer_create(
120 extern int bt_ctf_field_type_integer_get_size(
121 struct bt_ctf_field_type
*int_field_type
);
123 extern int bt_ctf_field_type_integer_set_size(
124 struct bt_ctf_field_type
*int_field_type
, unsigned int size
);
126 extern bt_ctf_bool
bt_ctf_field_type_integer_is_signed(
127 struct bt_ctf_field_type
*int_field_type
);
129 /* Pre-2.0 CTF writer compatibility */
131 int bt_ctf_field_type_integer_get_signed(
132 struct bt_ctf_field_type
*int_field_type
)
134 return bt_ctf_field_type_integer_is_signed(int_field_type
) ? 1 : 0;
137 extern int bt_ctf_field_type_integer_set_is_signed(
138 struct bt_ctf_field_type
*int_field_type
, bt_ctf_bool is_signed
);
140 /* Pre-2.0 CTF writer compatibility */
142 int bt_ctf_field_type_integer_set_signed(
143 struct bt_ctf_field_type
*int_field_type
, int is_signed
)
145 return bt_ctf_field_type_integer_set_is_signed(int_field_type
,
146 is_signed
? BT_CTF_TRUE
: BT_CTF_FALSE
);
149 extern enum bt_ctf_integer_base
bt_ctf_field_type_integer_get_base(
150 struct bt_ctf_field_type
*int_field_type
);
152 extern int bt_ctf_field_type_integer_set_base(
153 struct bt_ctf_field_type
*int_field_type
,
154 enum bt_ctf_integer_base base
);
156 extern enum bt_ctf_string_encoding
bt_ctf_field_type_integer_get_encoding(
157 struct bt_ctf_field_type
*int_field_type
);
159 extern int bt_ctf_field_type_integer_set_encoding(
160 struct bt_ctf_field_type
*int_field_type
,
161 enum bt_ctf_string_encoding encoding
);
163 extern struct bt_ctf_clock_class
*bt_ctf_field_type_integer_get_mapped_clock_class(
164 struct bt_ctf_field_type
*int_field_type
);
166 extern int bt_ctf_field_type_integer_set_mapped_clock_class(
167 struct bt_ctf_field_type
*int_field_type
,
168 struct bt_ctf_clock_class
*clock_class
);
170 extern struct bt_ctf_field_type
*bt_ctf_field_type_floating_point_create(void);
172 extern int bt_ctf_field_type_floating_point_get_exponent_digits(
173 struct bt_ctf_field_type
*float_field_type
);
175 extern int bt_ctf_field_type_floating_point_set_exponent_digits(
176 struct bt_ctf_field_type
*float_field_type
,
177 unsigned int exponent_size
);
179 extern int bt_ctf_field_type_floating_point_get_mantissa_digits(
180 struct bt_ctf_field_type
*float_field_type
);
182 extern int bt_ctf_field_type_floating_point_set_mantissa_digits(
183 struct bt_ctf_field_type
*float_field_type
,
184 unsigned int mantissa_sign_size
);
186 extern struct bt_ctf_field_type
*bt_ctf_field_type_enumeration_create(
187 struct bt_ctf_field_type
*int_field_type
);
190 struct bt_ctf_field_type
*bt_ctf_field_type_enumeration_get_container_field_type(
191 struct bt_ctf_field_type
*enum_field_type
);
193 extern int64_t bt_ctf_field_type_enumeration_get_mapping_count(
194 struct bt_ctf_field_type
*enum_field_type
);
196 extern int bt_ctf_field_type_enumeration_signed_get_mapping_by_index(
197 struct bt_ctf_field_type
*enum_field_type
, uint64_t index
,
198 const char **name
, int64_t *range_begin
, int64_t *range_end
);
200 extern int bt_ctf_field_type_enumeration_unsigned_get_mapping_by_index(
201 struct bt_ctf_field_type
*enum_field_type
, uint64_t index
,
202 const char **name
, uint64_t *range_begin
,
203 uint64_t *range_end
);
205 extern int bt_ctf_field_type_enumeration_signed_add_mapping(
206 struct bt_ctf_field_type
*enum_field_type
,
207 const char *name
, int64_t range_begin
, int64_t range_end
);
209 extern int bt_ctf_field_type_enumeration_unsigned_add_mapping(
210 struct bt_ctf_field_type
*enum_field_type
,
211 const char *name
, uint64_t range_begin
, uint64_t range_end
);
213 /* Pre-2.0 CTF writer compatibility */
215 int bt_ctf_field_type_enumeration_add_mapping(
216 struct bt_ctf_field_type
*enumeration
, const char *name
,
217 int64_t range_start
, int64_t range_end
)
219 return bt_ctf_field_type_enumeration_signed_add_mapping(enumeration
,
220 name
, range_start
, range_end
);
223 extern struct bt_ctf_field_type
*bt_ctf_field_type_string_create(void);
225 extern enum bt_ctf_string_encoding
bt_ctf_field_type_string_get_encoding(
226 struct bt_ctf_field_type
*string_field_type
);
228 extern int bt_ctf_field_type_string_set_encoding(
229 struct bt_ctf_field_type
*string_field_type
,
230 enum bt_ctf_string_encoding encoding
);
232 extern struct bt_ctf_field_type
*bt_ctf_field_type_structure_create(void);
234 extern int64_t bt_ctf_field_type_structure_get_field_count(
235 struct bt_ctf_field_type
*struct_field_type
);
237 extern int bt_ctf_field_type_structure_get_field_by_index(
238 struct bt_ctf_field_type
*struct_field_type
,
239 const char **field_name
, struct bt_ctf_field_type
**field_type
,
242 /* Pre-2.0 CTF writer compatibility */
244 int bt_ctf_field_type_structure_get_field(struct bt_ctf_field_type
*structure
,
245 const char **field_name
, struct bt_ctf_field_type
**field_type
,
248 return bt_ctf_field_type_structure_get_field_by_index(structure
,
249 field_name
, field_type
, (uint64_t) index
);
253 struct bt_ctf_field_type
*bt_ctf_field_type_structure_get_field_type_by_name(
254 struct bt_ctf_field_type
*struct_field_type
,
255 const char *field_name
);
257 extern int bt_ctf_field_type_structure_add_field(
258 struct bt_ctf_field_type
*struct_field_type
,
259 struct bt_ctf_field_type
*field_type
,
260 const char *field_name
);
262 extern struct bt_ctf_field_type
*bt_ctf_field_type_array_create(
263 struct bt_ctf_field_type
*element_field_type
,
264 unsigned int length
);
266 extern struct bt_ctf_field_type
*bt_ctf_field_type_array_get_element_field_type(
267 struct bt_ctf_field_type
*array_field_type
);
269 extern int64_t bt_ctf_field_type_array_get_length(
270 struct bt_ctf_field_type
*array_field_type
);
272 extern struct bt_ctf_field_type
*bt_ctf_field_type_sequence_create(
273 struct bt_ctf_field_type
*element_field_type
,
274 const char *length_name
);
276 extern struct bt_ctf_field_type
*bt_ctf_field_type_sequence_get_element_field_type(
277 struct bt_ctf_field_type
*sequence_field_type
);
279 extern const char *bt_ctf_field_type_sequence_get_length_field_name(
280 struct bt_ctf_field_type
*sequence_field_type
);
282 extern struct bt_ctf_field_type
*bt_ctf_field_type_variant_create(
283 struct bt_ctf_field_type
*tag_field_type
,
284 const char *tag_name
);
286 extern struct bt_ctf_field_type
*bt_ctf_field_type_variant_get_tag_field_type(
287 struct bt_ctf_field_type
*variant_field_type
);
289 extern const char *bt_ctf_field_type_variant_get_tag_name(
290 struct bt_ctf_field_type
*variant_field_type
);
292 extern int bt_ctf_field_type_variant_set_tag_name(
293 struct bt_ctf_field_type
*variant_field_type
,
294 const char *tag_name
);
296 extern int64_t bt_ctf_field_type_variant_get_field_count(
297 struct bt_ctf_field_type
*variant_field_type
);
299 extern int bt_ctf_field_type_variant_get_field_by_index(
300 struct bt_ctf_field_type
*variant_field_type
,
301 const char **field_name
,
302 struct bt_ctf_field_type
**field_type
, uint64_t index
);
305 struct bt_ctf_field_type
*bt_ctf_field_type_variant_get_field_type_by_name(
306 struct bt_ctf_field_type
*variant_field_type
,
307 const char *field_name
);
310 struct bt_ctf_field_type
*bt_ctf_field_type_variant_get_field_type_from_tag(
311 struct bt_ctf_field_type
*variant_field_type
,
312 struct bt_ctf_field
*tag_field
);
314 extern int bt_ctf_field_type_variant_add_field(
315 struct bt_ctf_field_type
*variant_field_type
,
316 struct bt_ctf_field_type
*field_type
,
317 const char *field_name
);
323 #endif /* BABELTRACE2_CTF_WRITER_FIELD_TYPES_H */