Commit | Line | Data |
---|---|---|
3dca2276 | 1 | /* |
0235b0db | 2 | * SPDX-License-Identifier: MIT |
3dca2276 | 3 | * |
0235b0db | 4 | * Copyright (C) 2010-2019 EfficiOS Inc. and Linux Foundation |
3dca2276 PP |
5 | */ |
6 | ||
0235b0db MJ |
7 | #ifndef BABELTRACE2_CTF_WRITER_FIELD_TYPES_H |
8 | #define BABELTRACE2_CTF_WRITER_FIELD_TYPES_H | |
9 | ||
3dca2276 PP |
10 | #include <stdint.h> |
11 | #include <stddef.h> | |
217cf9d3 | 12 | #include <babeltrace2-ctf-writer/types.h> |
3dca2276 PP |
13 | |
14 | #ifdef __cplusplus | |
15 | extern "C" { | |
16 | #endif | |
17 | ||
18 | struct bt_ctf_field; | |
19 | struct bt_ctf_field_type; | |
20 | ||
16ca5ff0 PP |
21 | enum bt_ctf_scope { |
22 | /// Unknown, used for errors. | |
23 | BT_CTF_SCOPE_UNKNOWN = -1, | |
24 | ||
25 | /// Trace packet header. | |
26 | BT_CTF_SCOPE_TRACE_PACKET_HEADER = 1, | |
27 | ||
28 | /// Stream packet context. | |
29 | BT_CTF_SCOPE_STREAM_PACKET_CONTEXT = 2, | |
30 | ||
31 | /// Stream event header. | |
32 | BT_CTF_SCOPE_STREAM_EVENT_HEADER = 3, | |
33 | ||
34 | /// Stream event context. | |
35 | BT_CTF_SCOPE_STREAM_EVENT_CONTEXT = 4, | |
36 | ||
37 | /// Event context. | |
38 | BT_CTF_SCOPE_EVENT_CONTEXT = 5, | |
39 | ||
40 | /// Event payload. | |
41 | BT_CTF_SCOPE_EVENT_PAYLOAD = 6, | |
42 | ||
43 | /// @cond DOCUMENT | |
44 | BT_CTF_SCOPE_ENV = 0, | |
45 | BT_CTF_SCOPE_EVENT_FIELDS = 6, | |
46 | /// @endcond | |
47 | }; | |
48 | ||
3dca2276 | 49 | enum bt_ctf_field_type_id { |
16ca5ff0 PP |
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, | |
3dca2276 PP |
60 | }; |
61 | ||
62 | extern enum bt_ctf_field_type_id bt_ctf_field_type_get_type_id( | |
63 | struct bt_ctf_field_type *field_type); | |
64 | ||
65 | enum bt_ctf_byte_order { | |
16ca5ff0 PP |
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, | |
3dca2276 PP |
72 | }; |
73 | ||
74 | enum bt_ctf_string_encoding { | |
16ca5ff0 PP |
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, | |
3dca2276 PP |
79 | }; |
80 | ||
81 | /* Pre-2.0 CTF writer compatibility */ | |
82 | #define ctf_string_encoding bt_ctf_string_encoding | |
83 | ||
84 | extern int bt_ctf_field_type_get_alignment( | |
85 | struct bt_ctf_field_type *field_type); | |
86 | ||
87 | extern int bt_ctf_field_type_set_alignment(struct bt_ctf_field_type *field_type, | |
88 | unsigned int alignment); | |
89 | ||
90 | extern enum bt_ctf_byte_order bt_ctf_field_type_get_byte_order( | |
91 | struct bt_ctf_field_type *field_type); | |
92 | ||
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); | |
96 | ||
97 | enum bt_ctf_integer_base { | |
98 | /// Unknown, used for errors. | |
99 | BT_CTF_INTEGER_BASE_UNKNOWN = -1, | |
100 | ||
101 | /// Unspecified by the tracer. | |
102 | BT_CTF_INTEGER_BASE_UNSPECIFIED = 0, | |
103 | ||
104 | /// Binary. | |
105 | BT_CTF_INTEGER_BASE_BINARY = 2, | |
106 | ||
107 | /// Octal. | |
108 | BT_CTF_INTEGER_BASE_OCTAL = 8, | |
109 | ||
110 | /// Decimal. | |
111 | BT_CTF_INTEGER_BASE_DECIMAL = 10, | |
112 | ||
113 | /// Hexadecimal. | |
114 | BT_CTF_INTEGER_BASE_HEXADECIMAL = 16, | |
115 | }; | |
116 | ||
117 | extern struct bt_ctf_field_type *bt_ctf_field_type_integer_create( | |
118 | unsigned int size); | |
119 | ||
120 | extern int bt_ctf_field_type_integer_get_size( | |
121 | struct bt_ctf_field_type *int_field_type); | |
122 | ||
123 | extern int bt_ctf_field_type_integer_set_size( | |
124 | struct bt_ctf_field_type *int_field_type, unsigned int size); | |
125 | ||
00409097 | 126 | extern bt_ctf_bool bt_ctf_field_type_integer_is_signed( |
3dca2276 PP |
127 | struct bt_ctf_field_type *int_field_type); |
128 | ||
129 | /* Pre-2.0 CTF writer compatibility */ | |
130 | static inline | |
131 | int bt_ctf_field_type_integer_get_signed( | |
132 | struct bt_ctf_field_type *int_field_type) | |
133 | { | |
134 | return bt_ctf_field_type_integer_is_signed(int_field_type) ? 1 : 0; | |
135 | } | |
136 | ||
137 | extern int bt_ctf_field_type_integer_set_is_signed( | |
00409097 | 138 | struct bt_ctf_field_type *int_field_type, bt_ctf_bool is_signed); |
3dca2276 PP |
139 | |
140 | /* Pre-2.0 CTF writer compatibility */ | |
141 | static inline | |
142 | int bt_ctf_field_type_integer_set_signed( | |
143 | struct bt_ctf_field_type *int_field_type, int is_signed) | |
144 | { | |
145 | return bt_ctf_field_type_integer_set_is_signed(int_field_type, | |
00409097 | 146 | is_signed ? BT_CTF_TRUE : BT_CTF_FALSE); |
3dca2276 PP |
147 | } |
148 | ||
149 | extern enum bt_ctf_integer_base bt_ctf_field_type_integer_get_base( | |
150 | struct bt_ctf_field_type *int_field_type); | |
151 | ||
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); | |
155 | ||
156 | extern enum bt_ctf_string_encoding bt_ctf_field_type_integer_get_encoding( | |
157 | struct bt_ctf_field_type *int_field_type); | |
158 | ||
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); | |
162 | ||
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); | |
165 | ||
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); | |
169 | ||
170 | extern struct bt_ctf_field_type *bt_ctf_field_type_floating_point_create(void); | |
171 | ||
172 | extern int bt_ctf_field_type_floating_point_get_exponent_digits( | |
173 | struct bt_ctf_field_type *float_field_type); | |
174 | ||
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); | |
178 | ||
179 | extern int bt_ctf_field_type_floating_point_get_mantissa_digits( | |
180 | struct bt_ctf_field_type *float_field_type); | |
181 | ||
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); | |
185 | ||
186 | extern struct bt_ctf_field_type *bt_ctf_field_type_enumeration_create( | |
187 | struct bt_ctf_field_type *int_field_type); | |
188 | ||
189 | extern | |
190 | struct bt_ctf_field_type *bt_ctf_field_type_enumeration_get_container_field_type( | |
191 | struct bt_ctf_field_type *enum_field_type); | |
192 | ||
193 | extern int64_t bt_ctf_field_type_enumeration_get_mapping_count( | |
194 | struct bt_ctf_field_type *enum_field_type); | |
195 | ||
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); | |
199 | ||
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); | |
204 | ||
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); | |
208 | ||
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); | |
212 | ||
213 | /* Pre-2.0 CTF writer compatibility */ | |
214 | static inline | |
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) | |
218 | { | |
219 | return bt_ctf_field_type_enumeration_signed_add_mapping(enumeration, | |
220 | name, range_start, range_end); | |
221 | } | |
222 | ||
223 | extern struct bt_ctf_field_type *bt_ctf_field_type_string_create(void); | |
224 | ||
225 | extern enum bt_ctf_string_encoding bt_ctf_field_type_string_get_encoding( | |
226 | struct bt_ctf_field_type *string_field_type); | |
227 | ||
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); | |
231 | ||
232 | extern struct bt_ctf_field_type *bt_ctf_field_type_structure_create(void); | |
233 | ||
234 | extern int64_t bt_ctf_field_type_structure_get_field_count( | |
235 | struct bt_ctf_field_type *struct_field_type); | |
236 | ||
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, | |
240 | uint64_t index); | |
241 | ||
242 | /* Pre-2.0 CTF writer compatibility */ | |
243 | static inline | |
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, | |
246 | int index) | |
247 | { | |
248 | return bt_ctf_field_type_structure_get_field_by_index(structure, | |
249 | field_name, field_type, (uint64_t) index); | |
250 | } | |
251 | ||
252 | extern | |
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); | |
256 | ||
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); | |
261 | ||
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); | |
265 | ||
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); | |
268 | ||
269 | extern int64_t bt_ctf_field_type_array_get_length( | |
270 | struct bt_ctf_field_type *array_field_type); | |
271 | ||
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); | |
275 | ||
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); | |
278 | ||
279 | extern const char *bt_ctf_field_type_sequence_get_length_field_name( | |
280 | struct bt_ctf_field_type *sequence_field_type); | |
281 | ||
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); | |
285 | ||
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); | |
288 | ||
289 | extern const char *bt_ctf_field_type_variant_get_tag_name( | |
290 | struct bt_ctf_field_type *variant_field_type); | |
291 | ||
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); | |
295 | ||
296 | extern int64_t bt_ctf_field_type_variant_get_field_count( | |
297 | struct bt_ctf_field_type *variant_field_type); | |
298 | ||
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); | |
303 | ||
304 | extern | |
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); | |
308 | ||
309 | extern | |
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); | |
313 | ||
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); | |
318 | ||
319 | #ifdef __cplusplus | |
320 | } | |
321 | #endif | |
322 | ||
924dc299 | 323 | #endif /* BABELTRACE2_CTF_WRITER_FIELD_TYPES_H */ |