1 #ifndef BABELTRACE2_CTF_WRITER_FIELD_TYPES_H
2 #define BABELTRACE2_CTF_WRITER_FIELD_TYPES_H
5 * Copyright (c) 2010-2019 EfficiOS Inc. and Linux Foundation
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:
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
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
28 #include <babeltrace2-ctf-writer/types.h>
35 struct bt_ctf_field_type
;
38 /// Unknown, used for errors.
39 BT_CTF_SCOPE_UNKNOWN
= -1,
41 /// Trace packet header.
42 BT_CTF_SCOPE_TRACE_PACKET_HEADER
= 1,
44 /// Stream packet context.
45 BT_CTF_SCOPE_STREAM_PACKET_CONTEXT
= 2,
47 /// Stream event header.
48 BT_CTF_SCOPE_STREAM_EVENT_HEADER
= 3,
50 /// Stream event context.
51 BT_CTF_SCOPE_STREAM_EVENT_CONTEXT
= 4,
54 BT_CTF_SCOPE_EVENT_CONTEXT
= 5,
57 BT_CTF_SCOPE_EVENT_PAYLOAD
= 6,
61 BT_CTF_SCOPE_EVENT_FIELDS
= 6,
65 enum bt_ctf_field_type_id
{
66 BT_CTF_FIELD_TYPE_ID_UNKNOWN
= -1,
67 BT_CTF_FIELD_TYPE_ID_INTEGER
= 0,
68 BT_CTF_FIELD_TYPE_ID_FLOAT
= 1,
69 BT_CTF_FIELD_TYPE_ID_ENUM
= 2,
70 BT_CTF_FIELD_TYPE_ID_STRING
= 3,
71 BT_CTF_FIELD_TYPE_ID_STRUCT
= 4,
72 BT_CTF_FIELD_TYPE_ID_ARRAY
= 5,
73 BT_CTF_FIELD_TYPE_ID_SEQUENCE
= 6,
74 BT_CTF_FIELD_TYPE_ID_VARIANT
= 7,
75 BT_CTF_FIELD_TYPE_ID_NR
,
78 extern enum bt_ctf_field_type_id
bt_ctf_field_type_get_type_id(
79 struct bt_ctf_field_type
*field_type
);
81 enum bt_ctf_byte_order
{
82 BT_CTF_BYTE_ORDER_UNKNOWN
= -1,
83 BT_CTF_BYTE_ORDER_NATIVE
= 0,
84 BT_CTF_BYTE_ORDER_UNSPECIFIED
,
85 BT_CTF_BYTE_ORDER_LITTLE_ENDIAN
,
86 BT_CTF_BYTE_ORDER_BIG_ENDIAN
,
87 BT_CTF_BYTE_ORDER_NETWORK
,
90 enum bt_ctf_string_encoding
{
91 BT_CTF_STRING_ENCODING_UNKNOWN
= -1,
92 BT_CTF_STRING_ENCODING_NONE
,
93 BT_CTF_STRING_ENCODING_UTF8
,
94 BT_CTF_STRING_ENCODING_ASCII
,
97 /* Pre-2.0 CTF writer compatibility */
98 #define ctf_string_encoding bt_ctf_string_encoding
100 extern int bt_ctf_field_type_get_alignment(
101 struct bt_ctf_field_type
*field_type
);
103 extern int bt_ctf_field_type_set_alignment(struct bt_ctf_field_type
*field_type
,
104 unsigned int alignment
);
106 extern enum bt_ctf_byte_order
bt_ctf_field_type_get_byte_order(
107 struct bt_ctf_field_type
*field_type
);
109 extern int bt_ctf_field_type_set_byte_order(
110 struct bt_ctf_field_type
*field_type
,
111 enum bt_ctf_byte_order byte_order
);
113 enum bt_ctf_integer_base
{
114 /// Unknown, used for errors.
115 BT_CTF_INTEGER_BASE_UNKNOWN
= -1,
117 /// Unspecified by the tracer.
118 BT_CTF_INTEGER_BASE_UNSPECIFIED
= 0,
121 BT_CTF_INTEGER_BASE_BINARY
= 2,
124 BT_CTF_INTEGER_BASE_OCTAL
= 8,
127 BT_CTF_INTEGER_BASE_DECIMAL
= 10,
130 BT_CTF_INTEGER_BASE_HEXADECIMAL
= 16,
133 extern struct bt_ctf_field_type
*bt_ctf_field_type_integer_create(
136 extern int bt_ctf_field_type_integer_get_size(
137 struct bt_ctf_field_type
*int_field_type
);
139 extern int bt_ctf_field_type_integer_set_size(
140 struct bt_ctf_field_type
*int_field_type
, unsigned int size
);
142 extern bt_ctf_bool
bt_ctf_field_type_integer_is_signed(
143 struct bt_ctf_field_type
*int_field_type
);
145 /* Pre-2.0 CTF writer compatibility */
147 int bt_ctf_field_type_integer_get_signed(
148 struct bt_ctf_field_type
*int_field_type
)
150 return bt_ctf_field_type_integer_is_signed(int_field_type
) ? 1 : 0;
153 extern int bt_ctf_field_type_integer_set_is_signed(
154 struct bt_ctf_field_type
*int_field_type
, bt_ctf_bool is_signed
);
156 /* Pre-2.0 CTF writer compatibility */
158 int bt_ctf_field_type_integer_set_signed(
159 struct bt_ctf_field_type
*int_field_type
, int is_signed
)
161 return bt_ctf_field_type_integer_set_is_signed(int_field_type
,
162 is_signed
? BT_CTF_TRUE
: BT_CTF_FALSE
);
165 extern enum bt_ctf_integer_base
bt_ctf_field_type_integer_get_base(
166 struct bt_ctf_field_type
*int_field_type
);
168 extern int bt_ctf_field_type_integer_set_base(
169 struct bt_ctf_field_type
*int_field_type
,
170 enum bt_ctf_integer_base base
);
172 extern enum bt_ctf_string_encoding
bt_ctf_field_type_integer_get_encoding(
173 struct bt_ctf_field_type
*int_field_type
);
175 extern int bt_ctf_field_type_integer_set_encoding(
176 struct bt_ctf_field_type
*int_field_type
,
177 enum bt_ctf_string_encoding encoding
);
179 extern struct bt_ctf_clock_class
*bt_ctf_field_type_integer_get_mapped_clock_class(
180 struct bt_ctf_field_type
*int_field_type
);
182 extern int bt_ctf_field_type_integer_set_mapped_clock_class(
183 struct bt_ctf_field_type
*int_field_type
,
184 struct bt_ctf_clock_class
*clock_class
);
186 extern struct bt_ctf_field_type
*bt_ctf_field_type_floating_point_create(void);
188 extern int bt_ctf_field_type_floating_point_get_exponent_digits(
189 struct bt_ctf_field_type
*float_field_type
);
191 extern int bt_ctf_field_type_floating_point_set_exponent_digits(
192 struct bt_ctf_field_type
*float_field_type
,
193 unsigned int exponent_size
);
195 extern int bt_ctf_field_type_floating_point_get_mantissa_digits(
196 struct bt_ctf_field_type
*float_field_type
);
198 extern int bt_ctf_field_type_floating_point_set_mantissa_digits(
199 struct bt_ctf_field_type
*float_field_type
,
200 unsigned int mantissa_sign_size
);
202 extern struct bt_ctf_field_type
*bt_ctf_field_type_enumeration_create(
203 struct bt_ctf_field_type
*int_field_type
);
206 struct bt_ctf_field_type
*bt_ctf_field_type_enumeration_get_container_field_type(
207 struct bt_ctf_field_type
*enum_field_type
);
209 extern int64_t bt_ctf_field_type_enumeration_get_mapping_count(
210 struct bt_ctf_field_type
*enum_field_type
);
212 extern int bt_ctf_field_type_enumeration_signed_get_mapping_by_index(
213 struct bt_ctf_field_type
*enum_field_type
, uint64_t index
,
214 const char **name
, int64_t *range_begin
, int64_t *range_end
);
216 extern int bt_ctf_field_type_enumeration_unsigned_get_mapping_by_index(
217 struct bt_ctf_field_type
*enum_field_type
, uint64_t index
,
218 const char **name
, uint64_t *range_begin
,
219 uint64_t *range_end
);
221 extern int bt_ctf_field_type_enumeration_signed_add_mapping(
222 struct bt_ctf_field_type
*enum_field_type
,
223 const char *name
, int64_t range_begin
, int64_t range_end
);
225 extern int bt_ctf_field_type_enumeration_unsigned_add_mapping(
226 struct bt_ctf_field_type
*enum_field_type
,
227 const char *name
, uint64_t range_begin
, uint64_t range_end
);
229 /* Pre-2.0 CTF writer compatibility */
231 int bt_ctf_field_type_enumeration_add_mapping(
232 struct bt_ctf_field_type
*enumeration
, const char *name
,
233 int64_t range_start
, int64_t range_end
)
235 return bt_ctf_field_type_enumeration_signed_add_mapping(enumeration
,
236 name
, range_start
, range_end
);
239 extern struct bt_ctf_field_type
*bt_ctf_field_type_string_create(void);
241 extern enum bt_ctf_string_encoding
bt_ctf_field_type_string_get_encoding(
242 struct bt_ctf_field_type
*string_field_type
);
244 extern int bt_ctf_field_type_string_set_encoding(
245 struct bt_ctf_field_type
*string_field_type
,
246 enum bt_ctf_string_encoding encoding
);
248 extern struct bt_ctf_field_type
*bt_ctf_field_type_structure_create(void);
250 extern int64_t bt_ctf_field_type_structure_get_field_count(
251 struct bt_ctf_field_type
*struct_field_type
);
253 extern int bt_ctf_field_type_structure_get_field_by_index(
254 struct bt_ctf_field_type
*struct_field_type
,
255 const char **field_name
, struct bt_ctf_field_type
**field_type
,
258 /* Pre-2.0 CTF writer compatibility */
260 int bt_ctf_field_type_structure_get_field(struct bt_ctf_field_type
*structure
,
261 const char **field_name
, struct bt_ctf_field_type
**field_type
,
264 return bt_ctf_field_type_structure_get_field_by_index(structure
,
265 field_name
, field_type
, (uint64_t) index
);
269 struct bt_ctf_field_type
*bt_ctf_field_type_structure_get_field_type_by_name(
270 struct bt_ctf_field_type
*struct_field_type
,
271 const char *field_name
);
273 extern int bt_ctf_field_type_structure_add_field(
274 struct bt_ctf_field_type
*struct_field_type
,
275 struct bt_ctf_field_type
*field_type
,
276 const char *field_name
);
278 extern struct bt_ctf_field_type
*bt_ctf_field_type_array_create(
279 struct bt_ctf_field_type
*element_field_type
,
280 unsigned int length
);
282 extern struct bt_ctf_field_type
*bt_ctf_field_type_array_get_element_field_type(
283 struct bt_ctf_field_type
*array_field_type
);
285 extern int64_t bt_ctf_field_type_array_get_length(
286 struct bt_ctf_field_type
*array_field_type
);
288 extern struct bt_ctf_field_type
*bt_ctf_field_type_sequence_create(
289 struct bt_ctf_field_type
*element_field_type
,
290 const char *length_name
);
292 extern struct bt_ctf_field_type
*bt_ctf_field_type_sequence_get_element_field_type(
293 struct bt_ctf_field_type
*sequence_field_type
);
295 extern const char *bt_ctf_field_type_sequence_get_length_field_name(
296 struct bt_ctf_field_type
*sequence_field_type
);
298 extern struct bt_ctf_field_type
*bt_ctf_field_type_variant_create(
299 struct bt_ctf_field_type
*tag_field_type
,
300 const char *tag_name
);
302 extern struct bt_ctf_field_type
*bt_ctf_field_type_variant_get_tag_field_type(
303 struct bt_ctf_field_type
*variant_field_type
);
305 extern const char *bt_ctf_field_type_variant_get_tag_name(
306 struct bt_ctf_field_type
*variant_field_type
);
308 extern int bt_ctf_field_type_variant_set_tag_name(
309 struct bt_ctf_field_type
*variant_field_type
,
310 const char *tag_name
);
312 extern int64_t bt_ctf_field_type_variant_get_field_count(
313 struct bt_ctf_field_type
*variant_field_type
);
315 extern int bt_ctf_field_type_variant_get_field_by_index(
316 struct bt_ctf_field_type
*variant_field_type
,
317 const char **field_name
,
318 struct bt_ctf_field_type
**field_type
, uint64_t index
);
321 struct bt_ctf_field_type
*bt_ctf_field_type_variant_get_field_type_by_name(
322 struct bt_ctf_field_type
*variant_field_type
,
323 const char *field_name
);
326 struct bt_ctf_field_type
*bt_ctf_field_type_variant_get_field_type_from_tag(
327 struct bt_ctf_field_type
*variant_field_type
,
328 struct bt_ctf_field
*tag_field
);
330 extern int bt_ctf_field_type_variant_add_field(
331 struct bt_ctf_field_type
*variant_field_type
,
332 struct bt_ctf_field_type
*field_type
,
333 const char *field_name
);
339 #endif /* BABELTRACE2_CTF_WRITER_FIELD_TYPES_H */