Commit | Line | Data |
---|---|---|
1c822dfb JG |
1 | #ifndef BABELTRACE_CTF_IR_FIELD_TYPES_INTERNAL_H |
2 | #define BABELTRACE_CTF_IR_FIELD_TYPES_INTERNAL_H | |
3 | ||
4 | /* | |
5 | * BabelTrace - CTF IR: Event field types internal | |
6 | * | |
7 | * Copyright 2013, 2014 Jérémie Galarneau <jeremie.galarneau@efficios.com> | |
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 | ||
30 | #include <babeltrace/ctf-writer/event-types.h> | |
31 | #include <babeltrace/ctf-writer/event-fields.h> | |
32 | #include <babeltrace/ctf-writer/writer.h> | |
33 | #include <babeltrace/ctf-ir/trace-internal.h> | |
34 | #include <babeltrace/babeltrace-internal.h> | |
35 | #include <babeltrace/object-internal.h> | |
36 | #include <babeltrace/types.h> | |
37 | #include <babeltrace/ctf/events.h> | |
38 | #include <glib.h> | |
39 | ||
40 | typedef void (*type_freeze_func)(struct bt_ctf_field_type *); | |
41 | typedef int (*type_serialize_func)(struct bt_ctf_field_type *, | |
42 | struct metadata_context *); | |
43 | ||
1c822dfb JG |
44 | enum bt_ctf_ir_scope { |
45 | BT_CTF_SCOPE_UNKNOWN = -1, | |
46 | BT_CTF_SCOPE_ENV = 0, | |
47 | BT_CTF_SCOPE_TRACE_PACKET_HEADER = 1, | |
48 | BT_CTF_SCOPE_STREAM_PACKET_CONTEXT = 2, | |
49 | BT_CTF_SCOPE_STREAM_EVENT_HEADER = 3, | |
50 | BT_CTF_SCOPE_STREAM_EVENT_CONTEXT = 4, | |
51 | BT_CTF_SCOPE_EVENT_CONTEXT = 5, | |
52 | BT_CTF_SCOPE_EVENT_FIELDS = 6, | |
53 | }; | |
54 | ||
55 | struct bt_ctf_field_type { | |
56 | struct bt_object base; | |
57 | struct bt_declaration *declaration; | |
58 | type_freeze_func freeze; | |
59 | type_serialize_func serialize; | |
60 | /* | |
61 | * A type can't be modified once it is added to an event or after a | |
62 | * a field has been instanciated from it. | |
63 | */ | |
64 | int frozen; | |
65 | ||
66 | /* | |
67 | * This flag indicates if the field type is valid. A valid | |
68 | * field type is _always_ frozen. All the nested field types of | |
69 | * a valid field type are also valid (and thus frozen). | |
70 | */ | |
71 | int valid; | |
72 | }; | |
73 | ||
74 | struct bt_ctf_field_type_integer { | |
75 | struct bt_ctf_field_type parent; | |
76 | struct declaration_integer declaration; | |
77 | struct bt_ctf_clock *mapped_clock; | |
78 | ||
79 | /* | |
80 | * This is what the user sets and is never modified by internal | |
81 | * code. | |
82 | * | |
83 | * This field must contain a `BT_CTF_BYTE_ORDER_*` value. | |
84 | */ | |
85 | enum bt_ctf_byte_order user_byte_order; | |
86 | }; | |
87 | ||
88 | struct enumeration_mapping { | |
89 | union { | |
90 | uint64_t _unsigned; | |
91 | int64_t _signed; | |
92 | } range_start; | |
93 | ||
94 | union { | |
95 | uint64_t _unsigned; | |
96 | int64_t _signed; | |
97 | } range_end; | |
98 | GQuark string; | |
99 | }; | |
100 | ||
101 | struct bt_ctf_field_type_enumeration { | |
102 | struct bt_ctf_field_type parent; | |
103 | struct bt_ctf_field_type *container; | |
104 | GPtrArray *entries; /* Array of ptrs to struct enumeration_mapping */ | |
105 | struct declaration_enum declaration; | |
106 | }; | |
107 | ||
108 | struct bt_ctf_field_type_floating_point { | |
109 | struct bt_ctf_field_type parent; | |
110 | struct declaration_float declaration; | |
111 | ||
112 | /* | |
113 | * The `declaration` field above contains 3 pointers pointing | |
114 | * to the fields below. This avoids unnecessary dynamic | |
115 | * allocations. | |
116 | */ | |
117 | struct declaration_integer sign; | |
118 | struct declaration_integer mantissa; | |
119 | struct declaration_integer exp; | |
120 | ||
121 | /* | |
122 | * This is what the user sets and is never modified by internal | |
123 | * code. | |
124 | * | |
125 | * This field must contain a `BT_CTF_BYTE_ORDER_*` value. | |
126 | */ | |
127 | enum bt_ctf_byte_order user_byte_order; | |
128 | }; | |
129 | ||
130 | struct structure_field { | |
131 | GQuark name; | |
132 | struct bt_ctf_field_type *type; | |
133 | }; | |
134 | ||
135 | struct bt_ctf_field_type_structure { | |
136 | struct bt_ctf_field_type parent; | |
137 | GHashTable *field_name_to_index; | |
138 | GPtrArray *fields; /* Array of pointers to struct structure_field */ | |
139 | struct declaration_struct declaration; | |
140 | }; | |
141 | ||
142 | struct bt_ctf_field_type_variant { | |
143 | struct bt_ctf_field_type parent; | |
144 | GString *tag_name; | |
145 | struct bt_ctf_field_type_enumeration *tag; | |
146 | struct bt_ctf_field_path *tag_field_path; | |
147 | GHashTable *field_name_to_index; | |
148 | GPtrArray *fields; /* Array of pointers to struct structure_field */ | |
149 | struct declaration_variant declaration; | |
150 | }; | |
151 | ||
152 | struct bt_ctf_field_type_array { | |
153 | struct bt_ctf_field_type parent; | |
154 | struct bt_ctf_field_type *element_type; | |
155 | unsigned int length; /* Number of elements */ | |
156 | struct declaration_array declaration; | |
157 | }; | |
158 | ||
159 | struct bt_ctf_field_type_sequence { | |
160 | struct bt_ctf_field_type parent; | |
161 | struct bt_ctf_field_type *element_type; | |
162 | GString *length_field_name; | |
163 | struct bt_ctf_field_path *length_field_path; | |
164 | struct declaration_sequence declaration; | |
165 | }; | |
166 | ||
167 | struct bt_ctf_field_type_string { | |
168 | struct bt_ctf_field_type parent; | |
169 | struct declaration_string declaration; | |
170 | }; | |
171 | ||
172 | BT_HIDDEN | |
173 | void bt_ctf_field_type_freeze(struct bt_ctf_field_type *type); | |
174 | ||
175 | BT_HIDDEN | |
176 | struct bt_ctf_field_type *bt_ctf_field_type_variant_get_field_type_signed( | |
177 | struct bt_ctf_field_type_variant *variant, int64_t tag_value); | |
178 | ||
179 | BT_HIDDEN | |
180 | struct bt_ctf_field_type *bt_ctf_field_type_variant_get_field_type_unsigned( | |
181 | struct bt_ctf_field_type_variant *variant, uint64_t tag_value); | |
182 | ||
183 | BT_HIDDEN | |
184 | int bt_ctf_field_type_serialize(struct bt_ctf_field_type *type, | |
185 | struct metadata_context *context); | |
186 | ||
187 | BT_HIDDEN | |
188 | int bt_ctf_field_type_validate(struct bt_ctf_field_type *type); | |
189 | ||
190 | BT_HIDDEN | |
191 | const char *bt_ctf_field_type_enumeration_get_mapping_name_unsigned( | |
192 | struct bt_ctf_field_type_enumeration *enumeration_type, | |
193 | uint64_t value); | |
194 | ||
195 | BT_HIDDEN | |
196 | const char *bt_ctf_field_type_enumeration_get_mapping_name_signed( | |
197 | struct bt_ctf_field_type_enumeration *enumeration_type, | |
198 | int64_t value); | |
199 | ||
200 | /* Override field type's byte order only if it is set to "native" */ | |
201 | BT_HIDDEN | |
202 | void bt_ctf_field_type_set_native_byte_order( | |
203 | struct bt_ctf_field_type *type, int byte_order); | |
204 | ||
205 | /* Deep copy a field type */ | |
206 | BT_HIDDEN | |
207 | struct bt_ctf_field_type *bt_ctf_field_type_copy( | |
208 | struct bt_ctf_field_type *type); | |
209 | ||
210 | BT_HIDDEN | |
211 | int bt_ctf_field_type_structure_get_field_name_index( | |
212 | struct bt_ctf_field_type *structure, const char *name); | |
213 | ||
214 | /* Replace an existing field's type in a structure */ | |
215 | BT_HIDDEN | |
216 | int bt_ctf_field_type_structure_set_field_index( | |
217 | struct bt_ctf_field_type *structure, | |
218 | struct bt_ctf_field_type *field, int index); | |
219 | ||
220 | BT_HIDDEN | |
221 | int bt_ctf_field_type_variant_get_field_name_index( | |
222 | struct bt_ctf_field_type *variant, const char *name); | |
223 | ||
224 | BT_HIDDEN | |
225 | int bt_ctf_field_type_sequence_set_length_field_path( | |
226 | struct bt_ctf_field_type *type, | |
227 | struct bt_ctf_field_path *path); | |
228 | ||
229 | BT_HIDDEN | |
230 | int bt_ctf_field_type_variant_set_tag_field_path(struct bt_ctf_field_type *type, | |
231 | struct bt_ctf_field_path *path); | |
232 | ||
233 | BT_HIDDEN | |
234 | int bt_ctf_field_type_variant_set_tag_field_type(struct bt_ctf_field_type *type, | |
235 | struct bt_ctf_field_type *tag_type); | |
236 | ||
237 | /* Replace an existing field's type in a variant */ | |
238 | BT_HIDDEN | |
239 | int bt_ctf_field_type_variant_set_field_index( | |
240 | struct bt_ctf_field_type *variant, | |
241 | struct bt_ctf_field_type *field, int index); | |
242 | ||
243 | BT_HIDDEN | |
244 | int bt_ctf_field_type_array_set_element_type(struct bt_ctf_field_type *array, | |
245 | struct bt_ctf_field_type *element_type); | |
246 | ||
247 | BT_HIDDEN | |
248 | int bt_ctf_field_type_sequence_set_element_type(struct bt_ctf_field_type *array, | |
249 | struct bt_ctf_field_type *element_type); | |
250 | ||
251 | BT_HIDDEN | |
252 | int bt_ctf_field_type_get_field_count(struct bt_ctf_field_type *type); | |
253 | ||
254 | BT_HIDDEN | |
255 | struct bt_ctf_field_type *bt_ctf_field_type_get_field_at_index( | |
256 | struct bt_ctf_field_type *type, int index); | |
257 | ||
258 | BT_HIDDEN | |
259 | int bt_ctf_field_type_get_field_index(struct bt_ctf_field_type *type, | |
260 | const char *name); | |
261 | ||
5ad19bf0 JG |
262 | /* |
263 | * bt_ctf_field_type_integer_get_size: get an integer type's size. | |
264 | * | |
265 | * Get an integer type's size. | |
266 | * | |
267 | * @param integer Integer type. | |
268 | * | |
269 | * Returns the integer type's size, a negative value on error. | |
270 | */ | |
271 | BT_HIDDEN | |
272 | int bt_ctf_field_type_integer_get_size(struct bt_ctf_field_type *integer); | |
273 | ||
274 | /* | |
275 | * bt_ctf_field_type_integer_get_base: get an integer type's base. | |
276 | * | |
277 | * Get an integer type's base used to pretty-print the resulting trace. | |
278 | * | |
279 | * @param integer Integer type. | |
280 | * | |
281 | * Returns the integer type's base on success, BT_CTF_INTEGER_BASE_UNKNOWN on | |
282 | * error. | |
283 | */ | |
284 | BT_HIDDEN | |
285 | enum bt_ctf_integer_base bt_ctf_field_type_integer_get_base( | |
286 | struct bt_ctf_field_type *integer); | |
287 | ||
288 | /* | |
289 | * bt_ctf_field_type_integer_get_encoding: get an integer type's encoding. | |
290 | * | |
291 | * @param integer Integer type. | |
292 | * | |
293 | * Returns the string field's encoding on success, | |
294 | * BT_CTF_STRING_ENCODING_UNKNOWN on error. | |
295 | */ | |
296 | BT_HIDDEN | |
297 | enum bt_ctf_string_encoding bt_ctf_field_type_integer_get_encoding( | |
298 | struct bt_ctf_field_type *integer); | |
299 | ||
300 | /** | |
301 | * bt_ctf_field_type_integer_get_mapped_clock: get an integer type's mapped clock. | |
302 | * | |
303 | * @param integer Integer type. | |
304 | * | |
305 | * Returns the integer's mapped clock (if any), NULL on error. | |
306 | */ | |
307 | BT_HIDDEN | |
308 | struct bt_ctf_clock *bt_ctf_field_type_integer_get_mapped_clock( | |
309 | struct bt_ctf_field_type *integer); | |
310 | ||
311 | /** | |
312 | * bt_ctf_field_type_integer_set_mapped_clock: set an integer type's mapped clock. | |
313 | * | |
314 | * @param integer Integer type. | |
315 | * @param clock Clock to map. | |
316 | * | |
317 | * Returns 0 on success, a negative value on error. | |
318 | */ | |
319 | BT_HIDDEN | |
320 | int bt_ctf_field_type_integer_set_mapped_clock( | |
321 | struct bt_ctf_field_type *integer, | |
322 | struct bt_ctf_clock *clock); | |
323 | ||
324 | /* | |
325 | * bt_ctf_field_type_enumeration_get_container_type: get underlying container. | |
326 | * | |
327 | * Get the enumeration type's underlying integer container type. | |
328 | * | |
329 | * @param enumeration Enumeration type. | |
330 | * | |
331 | * Returns an allocated field type on success, NULL on error. | |
332 | */ | |
333 | BT_HIDDEN | |
334 | struct bt_ctf_field_type *bt_ctf_field_type_enumeration_get_container_type( | |
335 | struct bt_ctf_field_type *enumeration); | |
336 | ||
337 | /* | |
338 | * bt_ctf_field_type_enumeration_add_mapping_unsigned: add an enumeration | |
339 | * mapping. | |
340 | * | |
341 | * Add a mapping to the enumeration. The range's values are inclusive. | |
342 | * | |
343 | * @param enumeration Enumeration type. | |
344 | * @param name Enumeration mapping name (will be copied). | |
345 | * @param range_start Enumeration mapping range start. | |
346 | * @param range_end Enumeration mapping range end. | |
347 | * | |
348 | * Returns 0 on success, a negative value on error. | |
349 | */ | |
350 | BT_HIDDEN | |
351 | int bt_ctf_field_type_enumeration_add_mapping_unsigned( | |
352 | struct bt_ctf_field_type *enumeration, const char *name, | |
353 | uint64_t range_start, uint64_t range_end); | |
354 | ||
355 | /* | |
356 | * bt_ctf_field_type_enumeration_get_mapping_count: Get the number of mappings | |
357 | * defined in the enumeration. | |
358 | * | |
359 | * @param enumeration Enumeration type. | |
360 | * | |
361 | * Returns the mapping count on success, a negative value on error. | |
362 | */ | |
363 | BT_HIDDEN | |
364 | int bt_ctf_field_type_enumeration_get_mapping_count( | |
365 | struct bt_ctf_field_type *enumeration); | |
366 | ||
367 | /* | |
368 | * bt_ctf_field_type_enumeration_get_mapping: get an enumeration mapping. | |
369 | * | |
370 | * @param enumeration Enumeration type. | |
371 | * @param index Index of mapping. | |
372 | * @param name Pointer where the mapping's name will be returned (valid for | |
373 | * the lifetime of the enumeration). | |
374 | * @param range_start Pointer where the enumeration mapping's range start will | |
375 | * be returned. | |
376 | * @param range_end Pointer where the enumeration mapping's range end will | |
377 | * be returned. | |
378 | * | |
379 | * Returns 0 on success, a negative value on error. | |
380 | */ | |
381 | BT_HIDDEN | |
382 | int bt_ctf_field_type_enumeration_get_mapping( | |
383 | struct bt_ctf_field_type *enumeration, int index, | |
384 | const char **name, int64_t *range_start, int64_t *range_end); | |
385 | ||
386 | /* | |
387 | * bt_ctf_field_type_enumeration_get_mapping_unsigned: get a mapping. | |
388 | * | |
389 | * @param enumeration Enumeration type. | |
390 | * @param index Index of mapping. | |
391 | * @param name Pointer where the mapping's name will be returned (valid for | |
392 | * the lifetime of the enumeration). | |
393 | * @param range_start Pointer where the enumeration mapping's range start will | |
394 | * be returned. | |
395 | * @param range_end Pointer where the enumeration mapping's range end will | |
396 | * be returned. | |
397 | * | |
398 | * Returns 0 on success, a negative value on error. | |
399 | */ | |
400 | BT_HIDDEN | |
401 | int bt_ctf_field_type_enumeration_get_mapping_unsigned( | |
402 | struct bt_ctf_field_type *enumeration, int index, | |
403 | const char **name, uint64_t *range_start, | |
404 | uint64_t *range_end); | |
405 | ||
406 | /* | |
407 | * bt_ctf_field_type_enumeration_get_mapping_index_by_name: get an enumerations' | |
408 | * mapping index by name. | |
409 | * | |
410 | * @param enumeration Enumeration type. | |
411 | * @param name Mapping name. | |
412 | * | |
413 | * Returns mapping index on success, a negative value on error. | |
414 | */ | |
415 | BT_HIDDEN | |
416 | int bt_ctf_field_type_enumeration_get_mapping_index_by_name( | |
417 | struct bt_ctf_field_type *enumeration, const char *name); | |
418 | ||
419 | /* | |
420 | * bt_ctf_field_type_enumeration_get_mapping_index_by_value: get an | |
421 | * enumerations' mapping index by value. | |
422 | * | |
423 | * @param enumeration Enumeration type. | |
424 | * @param value Value. | |
425 | * | |
426 | * Returns mapping index on success, a negative value on error. | |
427 | */ | |
428 | BT_HIDDEN | |
429 | int bt_ctf_field_type_enumeration_get_mapping_index_by_value( | |
430 | struct bt_ctf_field_type *enumeration, int64_t value); | |
431 | ||
432 | /* | |
433 | * bt_ctf_field_type_enumeration_get_mapping_index_by_unsigned_value: get an | |
434 | * enumerations' mapping index by value. | |
435 | * | |
436 | * @param enumeration Enumeration type. | |
437 | * @param value Value. | |
438 | * | |
439 | * Returns 0 on success, a negative value on error. | |
440 | */ | |
441 | BT_HIDDEN | |
442 | int bt_ctf_field_type_enumeration_get_mapping_index_by_unsigned_value( | |
443 | struct bt_ctf_field_type *enumeration, uint64_t value); | |
444 | ||
445 | /* | |
446 | * bt_ctf_field_type_floating_point_get_exponent_digits: get exponent digit | |
447 | * count. | |
448 | * | |
449 | * @param floating_point Floating point type. | |
450 | * | |
451 | * Returns the exponent digit count on success, a negative value on error. | |
452 | */ | |
453 | BT_HIDDEN | |
454 | int bt_ctf_field_type_floating_point_get_exponent_digits( | |
455 | struct bt_ctf_field_type *floating_point); | |
456 | ||
457 | /* | |
458 | * bt_ctf_field_type_floating_point_get_mantissa_digits: get mantissa digit | |
459 | * count. | |
460 | * | |
461 | * @param floating_point Floating point type. | |
462 | * | |
463 | * Returns the mantissa digit count on success, a negative value on error. | |
464 | */ | |
465 | BT_HIDDEN | |
466 | int bt_ctf_field_type_floating_point_get_mantissa_digits( | |
467 | struct bt_ctf_field_type *floating_point); | |
468 | ||
469 | /* | |
470 | * bt_ctf_field_type_structure_get_field_count: Get the number of fields defined | |
471 | * in the structure. | |
472 | * | |
473 | * @param structure Structure type. | |
474 | * | |
475 | * Returns the field count on success, a negative value on error. | |
476 | */ | |
477 | BT_HIDDEN | |
478 | int bt_ctf_field_type_structure_get_field_count( | |
479 | struct bt_ctf_field_type *structure); | |
480 | ||
481 | /* | |
482 | * bt_ctf_field_type_structure_get_field_type_by_name: get a structure field's | |
483 | * type by name. | |
484 | * | |
485 | * @param structure Structure type. | |
486 | * @param field_name Name of the structure's field. | |
487 | * | |
488 | * Returns a field type instance on success, NULL on error. | |
489 | */ | |
490 | BT_HIDDEN | |
491 | struct bt_ctf_field_type *bt_ctf_field_type_structure_get_field_type_by_name( | |
492 | struct bt_ctf_field_type *structure, const char *field_name); | |
493 | ||
494 | /* | |
495 | * bt_ctf_field_type_variant_get_tag_type: get a variant's tag type. | |
496 | * | |
497 | * @param variant Variant type. | |
498 | * | |
499 | * Returns a field type instance on success, NULL if unset. | |
500 | */ | |
501 | BT_HIDDEN | |
502 | struct bt_ctf_field_type *bt_ctf_field_type_variant_get_tag_type( | |
503 | struct bt_ctf_field_type *variant); | |
504 | ||
505 | /* | |
506 | * bt_ctf_field_type_variant_get_tag_name: get a variant's tag name. | |
507 | * | |
508 | * @param variant Variant type. | |
509 | * | |
510 | * Returns the tag field's name, NULL if unset. | |
511 | */ | |
512 | BT_HIDDEN | |
513 | const char *bt_ctf_field_type_variant_get_tag_name( | |
514 | struct bt_ctf_field_type *variant); | |
515 | ||
516 | /* | |
517 | * bt_ctf_field_type_variant_set_tag_name: set a variant's tag name. | |
518 | * | |
519 | * @param variant Variant type. | |
520 | * @param name Tag field name. | |
521 | * | |
522 | * Returns 0 on success, a negative value on error. | |
523 | */ | |
524 | BT_HIDDEN | |
525 | int bt_ctf_field_type_variant_set_tag_name( | |
526 | struct bt_ctf_field_type *variant, const char *name); | |
527 | ||
528 | /* | |
529 | * bt_ctf_field_type_variant_get_field_type_by_name: get variant field's type. | |
530 | * | |
531 | * @param structure Variant type. | |
532 | * @param field_name Name of the variant's field. | |
533 | * | |
534 | * Returns a field type instance on success, NULL on error. | |
535 | */ | |
536 | BT_HIDDEN | |
537 | struct bt_ctf_field_type *bt_ctf_field_type_variant_get_field_type_by_name( | |
538 | struct bt_ctf_field_type *variant, const char *field_name); | |
539 | ||
540 | /* | |
541 | * bt_ctf_field_type_variant_get_field_type_from_tag: get variant field's type. | |
542 | * | |
543 | * @param variant Variant type. | |
544 | * @param tag Type tag (enum). | |
545 | * | |
546 | * Returns a field type instance on success, NULL on error. | |
547 | */ | |
548 | BT_HIDDEN | |
549 | struct bt_ctf_field_type *bt_ctf_field_type_variant_get_field_type_from_tag( | |
550 | struct bt_ctf_field_type *variant, struct bt_ctf_field *tag); | |
551 | ||
552 | /* | |
553 | * bt_ctf_field_type_variant_get_field_count: Get the number of fields defined | |
554 | * in the variant. | |
555 | * | |
556 | * @param variant Variant type. | |
557 | * | |
558 | * Returns the field count on success, a negative value on error. | |
559 | */ | |
560 | BT_HIDDEN | |
561 | int bt_ctf_field_type_variant_get_field_count( | |
562 | struct bt_ctf_field_type *variant); | |
563 | ||
564 | /* | |
565 | * bt_ctf_field_type_variant_get_field: get a variant's field name and type. | |
566 | * | |
567 | * @param variant Variant type. | |
568 | * @param field_type Pointer to a const char* where the field's name will | |
569 | * be returned. | |
570 | * @param field_type Pointer to a bt_ctf_field_type* where the field's type will | |
571 | * be returned. | |
572 | * @param index Index of field. | |
573 | * | |
574 | * Returns 0 on success, a negative value on error. | |
575 | */ | |
576 | BT_HIDDEN | |
577 | int bt_ctf_field_type_variant_get_field( | |
578 | struct bt_ctf_field_type *variant, const char **field_name, | |
579 | struct bt_ctf_field_type **field_type, int index); | |
580 | ||
581 | /* | |
582 | * bt_ctf_field_type_array_get_element_type: get an array's element type. | |
583 | * | |
584 | * @param array Array type. | |
585 | * | |
586 | * Returns a field type instance on success, NULL on error. | |
587 | */ | |
588 | BT_HIDDEN | |
589 | struct bt_ctf_field_type *bt_ctf_field_type_array_get_element_type( | |
590 | struct bt_ctf_field_type *array); | |
591 | ||
592 | /* | |
593 | * bt_ctf_field_type_array_get_length: get an array's length. | |
594 | * | |
595 | * @param array Array type. | |
596 | * | |
597 | * Returns the array's length on success, a negative value on error. | |
598 | */ | |
599 | BT_HIDDEN | |
600 | int64_t bt_ctf_field_type_array_get_length(struct bt_ctf_field_type *array); | |
601 | ||
602 | /* | |
603 | * bt_ctf_field_type_sequence_get_element_type: get a sequence's element type. | |
604 | * | |
605 | * @param sequence Sequence type. | |
606 | * | |
607 | * Returns a field type instance on success, NULL on error. | |
608 | */ | |
609 | BT_HIDDEN | |
610 | struct bt_ctf_field_type *bt_ctf_field_type_sequence_get_element_type( | |
611 | struct bt_ctf_field_type *sequence); | |
612 | ||
613 | /* | |
614 | * bt_ctf_field_type_sequence_get_length_field_name: get length field name. | |
615 | * | |
616 | * @param sequence Sequence type. | |
617 | * | |
618 | * Returns the sequence's length field on success, NULL on error. | |
619 | */ | |
620 | BT_HIDDEN | |
621 | const char *bt_ctf_field_type_sequence_get_length_field_name( | |
622 | struct bt_ctf_field_type *sequence); | |
623 | ||
624 | /* | |
625 | * bt_ctf_field_type_string_get_encoding: get a string type's encoding. | |
626 | * | |
627 | * Get the string type's encoding. | |
628 | * | |
629 | * @param string_type String type. | |
630 | * | |
631 | * Returns the string's encoding on success, a BT_CTF_STRING_ENCODING_UNKNOWN | |
632 | * on error. | |
633 | */ | |
634 | BT_HIDDEN | |
635 | enum bt_ctf_string_encoding bt_ctf_field_type_string_get_encoding( | |
636 | struct bt_ctf_field_type *string_type); | |
637 | ||
638 | /* | |
639 | * bt_ctf_field_type_get_alignment: get a field type's alignment. | |
640 | * | |
641 | * Get the field type's alignment. | |
642 | * | |
643 | * @param type Field type. | |
644 | * | |
645 | * Returns the field type's alignment on success, a negative value on error and | |
646 | * 0 if the alignment is undefined (as in the case of a variant). | |
647 | */ | |
648 | BT_HIDDEN | |
649 | int bt_ctf_field_type_get_alignment(struct bt_ctf_field_type *type); | |
650 | ||
651 | /* | |
652 | * bt_ctf_field_type_get_byte_order: get a field type's byte order. | |
653 | * | |
654 | * @param type Field type. | |
655 | * | |
656 | * Returns the field type's byte order on success, a negative value on error. | |
657 | */ | |
658 | BT_HIDDEN | |
659 | enum bt_ctf_byte_order bt_ctf_field_type_get_byte_order( | |
660 | struct bt_ctf_field_type *type); | |
661 | ||
662 | ||
663 | /* | |
664 | * bt_ctf_field_type_variant_get_tag_field_path: get a variant's tag's field | |
665 | * path. | |
666 | * | |
667 | * Get the variant's tag's field path. | |
668 | * | |
669 | * @param type Field type. | |
670 | * | |
671 | * Returns the field path on success, NULL on error or if no field path is set. | |
672 | */ | |
673 | BT_HIDDEN | |
674 | struct bt_ctf_field_path *bt_ctf_field_type_variant_get_tag_field_path( | |
675 | struct bt_ctf_field_type *type); | |
676 | ||
677 | /* | |
678 | * bt_ctf_field_type_sequence_get_length_field_path: get a sequence's length's | |
679 | * field path. | |
680 | * | |
681 | * Get the sequence's length's field path. | |
682 | * | |
683 | * @param type Field type. | |
684 | * | |
685 | * Returns the field path on success, NULL on error or if no field path is set. | |
686 | */ | |
687 | BT_HIDDEN | |
688 | struct bt_ctf_field_path *bt_ctf_field_type_sequence_get_length_field_path( | |
689 | struct bt_ctf_field_type *type); | |
690 | ||
691 | /* | |
692 | * bt_ctf_field_type_compare: compare two field types recursively | |
693 | * | |
694 | * Compare two field types recursively. | |
695 | * | |
696 | * The registered tag field type of a variant field type is ignored: | |
697 | * only the tag strings are compared. | |
698 | * | |
699 | * @param type_a Field type A. | |
700 | * @param type_b Field type B. | |
701 | * | |
702 | * Returns 0 if both field types are semantically equivalent, a positive | |
703 | * value if they are not equivalent, or a negative value on error. | |
704 | */ | |
705 | BT_HIDDEN | |
706 | int bt_ctf_field_type_compare(struct bt_ctf_field_type *type_a, | |
707 | struct bt_ctf_field_type *type_b); | |
708 | ||
709 | /* | |
710 | * bt_ctf_field_type_get_type_id: get a field type's bt_ctf_type_id. | |
711 | * | |
712 | * @param type Field type. | |
713 | * | |
714 | * Returns the field type's bt_ctf_type_id, CTF_TYPE_UNKNOWN on error. | |
715 | */ | |
716 | BT_HIDDEN | |
830017b0 | 717 | enum ctf_type_id bt_ctf_field_type_get_type_id( |
5ad19bf0 JG |
718 | struct bt_ctf_field_type *type); |
719 | ||
720 | /* | |
721 | * bt_ctf_field_type_is_integer: returns whether or not a given field | |
722 | * type is an integer type. | |
723 | * | |
724 | * @param type Field type. | |
725 | * | |
726 | * Returns 1 if the field type is an integer type, 0 otherwise. | |
727 | */ | |
728 | BT_HIDDEN | |
729 | int bt_ctf_field_type_is_integer(struct bt_ctf_field_type *type); | |
730 | ||
731 | /* | |
732 | * bt_ctf_field_type_is_floating_point: returns whether or not a given field | |
733 | * type is a floating point number type. | |
734 | * | |
735 | * @param type Field type. | |
736 | * | |
737 | * Returns 1 if the field type is a floating point number type, 0 otherwise. | |
738 | */ | |
739 | BT_HIDDEN | |
740 | int bt_ctf_field_type_is_floating_point(struct bt_ctf_field_type *type); | |
741 | ||
742 | /* | |
743 | * bt_ctf_field_type_is_enumeration: returns whether or not a given field | |
744 | * type is an enumeration type. | |
745 | * | |
746 | * @param type Field type. | |
747 | * | |
748 | * Returns 1 if the field type is an enumeration type, 0 otherwise. | |
749 | */ | |
750 | BT_HIDDEN | |
751 | int bt_ctf_field_type_is_enumeration(struct bt_ctf_field_type *type); | |
752 | ||
753 | /* | |
754 | * bt_ctf_field_type_is_string: returns whether or not a given field | |
755 | * type is a string type. | |
756 | * | |
757 | * @param type Field type. | |
758 | * | |
759 | * Returns 1 if the field type is a string type, 0 otherwise. | |
760 | */ | |
761 | BT_HIDDEN | |
762 | int bt_ctf_field_type_is_string(struct bt_ctf_field_type *type); | |
763 | ||
764 | /* | |
765 | * bt_ctf_field_type_is_structure: returns whether or not a given field | |
766 | * type is a structure type. | |
767 | * | |
768 | * @param type Field type. | |
769 | * | |
770 | * Returns 1 if the field type is a structure type, 0 otherwise. | |
771 | */ | |
772 | BT_HIDDEN | |
773 | int bt_ctf_field_type_is_structure(struct bt_ctf_field_type *type); | |
774 | ||
775 | /* | |
776 | * bt_ctf_field_type_is_array: returns whether or not a given field | |
777 | * type is an array type. | |
778 | * | |
779 | * @param type Field type. | |
780 | * | |
781 | * Returns 1 if the field type is an array type, 0 otherwise. | |
782 | */ | |
783 | BT_HIDDEN | |
784 | int bt_ctf_field_type_is_array(struct bt_ctf_field_type *type); | |
785 | ||
786 | /* | |
787 | * bt_ctf_field_type_is_sequence: returns whether or not a given field | |
788 | * type is a sequence type. | |
789 | * | |
790 | * @param type Field type. | |
791 | * | |
792 | * Returns 1 if the field type is a sequence type, 0 otherwise. | |
793 | */ | |
794 | BT_HIDDEN | |
795 | int bt_ctf_field_type_is_sequence(struct bt_ctf_field_type *type); | |
796 | ||
797 | /* | |
798 | * bt_ctf_field_type_is_variant: returns whether or not a given field | |
799 | * type is a variant type. | |
800 | * | |
801 | * @param type Field type. | |
802 | * | |
803 | * Returns 1 if the field type is a variant type, 0 otherwise. | |
804 | */ | |
805 | BT_HIDDEN | |
806 | int bt_ctf_field_type_is_variant(struct bt_ctf_field_type *type); | |
807 | ||
1c822dfb | 808 | #endif /* BABELTRACE_CTF_IR_FIELD_TYPES_INTERNAL_H */ |