Commit | Line | Data |
---|---|---|
adc315b8 JG |
1 | #ifndef BABELTRACE_CTF_IR_EVENT_TYPES_H |
2 | #define BABELTRACE_CTF_IR_EVENT_TYPES_H | |
3 | ||
4 | /* | |
5 | * BabelTrace - CTF IR: Event Types | |
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 <babeltrace/ctf/events.h> | |
34 | #include <stdint.h> | |
35 | ||
36 | #ifdef __cplusplus | |
37 | extern "C" { | |
38 | #endif | |
39 | ||
40 | struct bt_ctf_event_class; | |
41 | struct bt_ctf_event; | |
42 | struct bt_ctf_field_type; | |
b92ddaaa | 43 | struct bt_ctf_field; |
b011f6b0 | 44 | struct bt_ctf_field_path; |
adc315b8 JG |
45 | |
46 | enum bt_ctf_integer_base { | |
47 | BT_CTF_INTEGER_BASE_UNKNOWN = -1, | |
48 | BT_CTF_INTEGER_BASE_BINARY = 2, | |
49 | BT_CTF_INTEGER_BASE_OCTAL = 8, | |
50 | BT_CTF_INTEGER_BASE_DECIMAL = 10, | |
51 | BT_CTF_INTEGER_BASE_HEXADECIMAL = 16, | |
52 | }; | |
53 | ||
54 | enum bt_ctf_byte_order { | |
b92ddaaa | 55 | BT_CTF_BYTE_ORDER_UNKNOWN = -1, |
c35a1669 | 56 | /* |
46df6b28 PP |
57 | * Note that native, in the context of the CTF specification, is defined |
58 | * as "the byte order described in the trace" and does not mean that the | |
59 | * host's endianness will be used. | |
c35a1669 | 60 | */ |
adc315b8 JG |
61 | BT_CTF_BYTE_ORDER_NATIVE = 0, |
62 | BT_CTF_BYTE_ORDER_LITTLE_ENDIAN, | |
63 | BT_CTF_BYTE_ORDER_BIG_ENDIAN, | |
64 | BT_CTF_BYTE_ORDER_NETWORK, | |
65 | }; | |
66 | ||
46df6b28 PP |
67 | enum bt_ctf_scope { |
68 | BT_CTF_SCOPE_UNKNOWN = -1, | |
69 | BT_CTF_SCOPE_ENV = 0, | |
70 | BT_CTF_SCOPE_TRACE_PACKET_HEADER = 1, | |
71 | BT_CTF_SCOPE_STREAM_PACKET_CONTEXT = 2, | |
72 | BT_CTF_SCOPE_STREAM_EVENT_HEADER = 3, | |
73 | BT_CTF_SCOPE_STREAM_EVENT_CONTEXT = 4, | |
74 | BT_CTF_SCOPE_EVENT_CONTEXT = 5, | |
75 | BT_CTF_SCOPE_EVENT_FIELDS = 6, | |
b011f6b0 PP |
76 | }; |
77 | ||
adc315b8 JG |
78 | /* |
79 | * bt_ctf_field_type_integer_create: create an integer field type. | |
80 | * | |
81 | * Allocate a new integer field type of the given size. The creation of a field | |
0ce5791b | 82 | * type sets its reference count to 1. |
adc315b8 JG |
83 | * |
84 | * @param size Integer field type size/length in bits. | |
85 | * | |
86 | * Returns an allocated field type on success, NULL on error. | |
87 | */ | |
88 | extern struct bt_ctf_field_type *bt_ctf_field_type_integer_create( | |
89 | unsigned int size); | |
90 | ||
b92ddaaa JG |
91 | /* |
92 | * bt_ctf_field_type_integer_get_size: get an integer type's size. | |
93 | * | |
94 | * Get an integer type's size. | |
95 | * | |
96 | * @param integer Integer type. | |
97 | * | |
98 | * Returns the integer type's size, a negative value on error. | |
99 | */ | |
100 | extern int bt_ctf_field_type_integer_get_size( | |
101 | struct bt_ctf_field_type *integer); | |
102 | ||
103 | /* | |
104 | * bt_ctf_field_type_integer_get_signed: get an integer type's signedness. | |
105 | * | |
106 | * Get an integer type's signedness attribute. | |
107 | * | |
108 | * @param integer Integer type. | |
109 | * | |
110 | * Returns the integer's signedness, a negative value on error. | |
111 | */ | |
112 | extern int bt_ctf_field_type_integer_get_signed( | |
113 | struct bt_ctf_field_type *integer); | |
114 | ||
adc315b8 JG |
115 | /* |
116 | * bt_ctf_field_type_integer_set_signed: set an integer type's signedness. | |
117 | * | |
118 | * Set an integer type's signedness attribute. | |
119 | * | |
120 | * @param integer Integer type. | |
121 | * @param is_signed Integer's signedness, defaults to FALSE. | |
122 | * | |
123 | * Returns 0 on success, a negative value on error. | |
124 | */ | |
125 | extern int bt_ctf_field_type_integer_set_signed( | |
126 | struct bt_ctf_field_type *integer, int is_signed); | |
127 | ||
b92ddaaa JG |
128 | /* |
129 | * bt_ctf_field_type_integer_get_base: get an integer type's base. | |
130 | * | |
131 | * Get an integer type's base used to pretty-print the resulting trace. | |
132 | * | |
133 | * @param integer Integer type. | |
134 | * | |
135 | * Returns the integer type's base on success, BT_CTF_INTEGER_BASE_UNKNOWN on | |
136 | * error. | |
137 | */ | |
138 | extern enum bt_ctf_integer_base bt_ctf_field_type_integer_get_base( | |
139 | struct bt_ctf_field_type *integer); | |
140 | ||
adc315b8 JG |
141 | /* |
142 | * bt_ctf_field_type_integer_set_base: set an integer type's base. | |
143 | * | |
144 | * Set an integer type's base used to pretty-print the resulting trace. | |
145 | * | |
146 | * @param integer Integer type. | |
147 | * @param base Integer base, defaults to BT_CTF_INTEGER_BASE_DECIMAL. | |
148 | * | |
149 | * Returns 0 on success, a negative value on error. | |
150 | */ | |
2c4a0758 | 151 | extern int bt_ctf_field_type_integer_set_base(struct bt_ctf_field_type *integer, |
adc315b8 JG |
152 | enum bt_ctf_integer_base base); |
153 | ||
b92ddaaa JG |
154 | /* |
155 | * bt_ctf_field_type_integer_get_encoding: get an integer type's encoding. | |
156 | * | |
157 | * @param integer Integer type. | |
158 | * | |
159 | * Returns the string field's encoding on success, CTF_STRING_UNKNOWN on error. | |
160 | */ | |
161 | extern enum ctf_string_encoding bt_ctf_field_type_integer_get_encoding( | |
162 | struct bt_ctf_field_type *integer); | |
163 | ||
adc315b8 JG |
164 | /* |
165 | * bt_ctf_field_type_integer_set_encoding: set an integer type's encoding. | |
166 | * | |
167 | * An integer encoding may be set to signal that the integer must be printed as | |
168 | * a text character. | |
169 | * | |
170 | * @param integer Integer type. | |
171 | * @param encoding Integer output encoding, defaults to CTF_STRING_ENCODING_NONE | |
172 | * | |
173 | * Returns 0 on success, a negative value on error. | |
174 | */ | |
175 | extern int bt_ctf_field_type_integer_set_encoding( | |
176 | struct bt_ctf_field_type *integer, | |
177 | enum ctf_string_encoding encoding); | |
178 | ||
6cfb906f JG |
179 | /** |
180 | * bt_ctf_field_type_integer_get_mapped_clock: get an integer type's mapped clock. | |
181 | * | |
182 | * @param integer Integer type. | |
183 | * | |
184 | * Returns the integer's mapped clock (if any), NULL on error. | |
185 | */ | |
186 | extern struct bt_ctf_clock *bt_ctf_field_type_integer_get_mapped_clock( | |
187 | struct bt_ctf_field_type *integer); | |
188 | ||
189 | /** | |
190 | * bt_ctf_field_type_integer_set_mapped_clock: set an integer type's mapped clock. | |
191 | * | |
192 | * @param integer Integer type. | |
193 | * @param clock Clock to map. | |
194 | * | |
195 | * Returns 0 on success, a negative value on error. | |
196 | */ | |
197 | extern int bt_ctf_field_type_integer_set_mapped_clock( | |
198 | struct bt_ctf_field_type *integer, | |
199 | struct bt_ctf_clock *clock); | |
200 | ||
adc315b8 JG |
201 | /* |
202 | * bt_ctf_field_type_enumeration_create: create an enumeration field type. | |
203 | * | |
204 | * Allocate a new enumeration field type with the given underlying type. The | |
205 | * creation of a field type sets its reference count to 1. | |
206 | * The resulting enumeration will share the integer_container_type's ownership | |
207 | * by increasing its reference count. | |
208 | * | |
209 | * @param integer_container_type Underlying integer type of the enumeration | |
210 | * type. | |
211 | * | |
212 | * Returns an allocated field type on success, NULL on error. | |
213 | */ | |
214 | extern struct bt_ctf_field_type *bt_ctf_field_type_enumeration_create( | |
215 | struct bt_ctf_field_type *integer_container_type); | |
216 | ||
b92ddaaa JG |
217 | /* |
218 | * bt_ctf_field_type_enumeration_get_container_type: get underlying container. | |
219 | * | |
220 | * Get the enumeration type's underlying integer container type. | |
221 | * | |
222 | * @param enumeration Enumeration type. | |
223 | * | |
224 | * Returns an allocated field type on success, NULL on error. | |
225 | */ | |
226 | extern | |
227 | struct bt_ctf_field_type *bt_ctf_field_type_enumeration_get_container_type( | |
228 | struct bt_ctf_field_type *enumeration); | |
229 | ||
adc315b8 JG |
230 | /* |
231 | * bt_ctf_field_type_enumeration_add_mapping: add an enumeration mapping. | |
232 | * | |
233 | * Add a mapping to the enumeration. The range's values are inclusive. | |
234 | * | |
235 | * @param enumeration Enumeration type. | |
b92ddaaa | 236 | * @param name Enumeration mapping name (will be copied). |
adc315b8 JG |
237 | * @param range_start Enumeration mapping range start. |
238 | * @param range_end Enumeration mapping range end. | |
239 | * | |
240 | * Returns 0 on success, a negative value on error. | |
241 | */ | |
242 | extern int bt_ctf_field_type_enumeration_add_mapping( | |
b92ddaaa | 243 | struct bt_ctf_field_type *enumeration, const char *name, |
adc315b8 JG |
244 | int64_t range_start, int64_t range_end); |
245 | ||
b92ddaaa JG |
246 | /* |
247 | * bt_ctf_field_type_enumeration_add_mapping_unsigned: add an enumeration | |
248 | * mapping. | |
249 | * | |
250 | * Add a mapping to the enumeration. The range's values are inclusive. | |
251 | * | |
252 | * @param enumeration Enumeration type. | |
253 | * @param name Enumeration mapping name (will be copied). | |
254 | * @param range_start Enumeration mapping range start. | |
255 | * @param range_end Enumeration mapping range end. | |
256 | * | |
257 | * Returns 0 on success, a negative value on error. | |
258 | */ | |
259 | extern int bt_ctf_field_type_enumeration_add_mapping_unsigned( | |
260 | struct bt_ctf_field_type *enumeration, const char *name, | |
261 | uint64_t range_start, uint64_t range_end); | |
262 | ||
263 | /* | |
264 | * bt_ctf_field_type_enumeration_get_mapping_count: Get the number of mappings | |
265 | * defined in the enumeration. | |
266 | * | |
267 | * @param enumeration Enumeration type. | |
268 | * | |
269 | * Returns the mapping count on success, a negative value on error. | |
270 | */ | |
074ee56d | 271 | extern int bt_ctf_field_type_enumeration_get_mapping_count( |
b92ddaaa JG |
272 | struct bt_ctf_field_type *enumeration); |
273 | ||
274 | /* | |
275 | * bt_ctf_field_type_enumeration_get_mapping: get an enumeration mapping. | |
276 | * | |
277 | * @param enumeration Enumeration type. | |
278 | * @param index Index of mapping. | |
279 | * @param name Pointer where the mapping's name will be returned (valid for | |
280 | * the lifetime of the enumeration). | |
281 | * @param range_start Pointer where the enumeration mapping's range start will | |
282 | * be returned. | |
283 | * @param range_end Pointer where the enumeration mapping's range end will | |
284 | * be returned. | |
285 | * | |
286 | * Returns 0 on success, a negative value on error. | |
287 | */ | |
288 | extern int bt_ctf_field_type_enumeration_get_mapping( | |
074ee56d | 289 | struct bt_ctf_field_type *enumeration, int index, |
b92ddaaa JG |
290 | const char **name, int64_t *range_start, int64_t *range_end); |
291 | ||
292 | /* | |
293 | * bt_ctf_field_type_enumeration_get_mapping_unsigned: get a mapping. | |
294 | * | |
295 | * @param enumeration Enumeration type. | |
296 | * @param index Index of mapping. | |
297 | * @param name Pointer where the mapping's name will be returned (valid for | |
298 | * the lifetime of the enumeration). | |
299 | * @param range_start Pointer where the enumeration mapping's range start will | |
300 | * be returned. | |
301 | * @param range_end Pointer where the enumeration mapping's range end will | |
302 | * be returned. | |
303 | * | |
304 | * Returns 0 on success, a negative value on error. | |
305 | */ | |
306 | extern int bt_ctf_field_type_enumeration_get_mapping_unsigned( | |
074ee56d | 307 | struct bt_ctf_field_type *enumeration, int index, |
b92ddaaa JG |
308 | const char **name, uint64_t *range_start, |
309 | uint64_t *range_end); | |
310 | ||
311 | /* | |
312 | * bt_ctf_field_type_enumeration_get_mapping_index_by_name: get an enumerations' | |
313 | * mapping index by name. | |
314 | * | |
315 | * @param enumeration Enumeration type. | |
316 | * @param name Mapping name. | |
b92ddaaa | 317 | * |
074ee56d | 318 | * Returns mapping index on success, a negative value on error. |
b92ddaaa JG |
319 | */ |
320 | extern int bt_ctf_field_type_enumeration_get_mapping_index_by_name( | |
074ee56d | 321 | struct bt_ctf_field_type *enumeration, const char *name); |
b92ddaaa JG |
322 | |
323 | /* | |
324 | * bt_ctf_field_type_enumeration_get_mapping_index_by_value: get an | |
325 | * enumerations' mapping index by value. | |
326 | * | |
327 | * @param enumeration Enumeration type. | |
328 | * @param value Value. | |
b92ddaaa | 329 | * |
074ee56d | 330 | * Returns mapping index on success, a negative value on error. |
b92ddaaa JG |
331 | */ |
332 | extern int bt_ctf_field_type_enumeration_get_mapping_index_by_value( | |
074ee56d | 333 | struct bt_ctf_field_type *enumeration, int64_t value); |
b92ddaaa JG |
334 | |
335 | /* | |
336 | * bt_ctf_field_type_enumeration_get_mapping_index_by_unsigned_value: get an | |
337 | * enumerations' mapping index by value. | |
338 | * | |
339 | * @param enumeration Enumeration type. | |
340 | * @param value Value. | |
b92ddaaa JG |
341 | * |
342 | * Returns 0 on success, a negative value on error. | |
343 | */ | |
344 | extern int bt_ctf_field_type_enumeration_get_mapping_index_by_unsigned_value( | |
074ee56d | 345 | struct bt_ctf_field_type *enumeration, uint64_t value); |
b92ddaaa | 346 | |
adc315b8 JG |
347 | /* |
348 | * bt_ctf_field_type_floating_point_create: create a floating point field type. | |
349 | * | |
350 | * Allocate a new floating point field type. The creation of a field type sets | |
351 | * its reference count to 1. | |
352 | * | |
353 | * Returns an allocated field type on success, NULL on error. | |
354 | */ | |
355 | extern struct bt_ctf_field_type *bt_ctf_field_type_floating_point_create(void); | |
356 | ||
b92ddaaa JG |
357 | /* |
358 | * bt_ctf_field_type_floating_point_get_exponent_digits: get exponent digit | |
359 | * count. | |
360 | * | |
361 | * @param floating_point Floating point type. | |
362 | * | |
363 | * Returns the exponent digit count on success, a negative value on error. | |
364 | */ | |
365 | extern int bt_ctf_field_type_floating_point_get_exponent_digits( | |
366 | struct bt_ctf_field_type *floating_point); | |
367 | ||
adc315b8 JG |
368 | /* |
369 | * bt_ctf_field_type_floating_point_set_exponent_digits: set exponent digit | |
b92ddaaa | 370 | * count. |
adc315b8 JG |
371 | * |
372 | * Set the number of exponent digits to use to store the floating point field. | |
373 | * The only values currently supported are FLT_EXP_DIG and DBL_EXP_DIG. | |
374 | * | |
375 | * @param floating_point Floating point type. | |
376 | * @param exponent_digits Number of digits to allocate to the exponent (defaults | |
377 | * to FLT_EXP_DIG). | |
378 | * | |
379 | * Returns 0 on success, a negative value on error. | |
380 | */ | |
381 | extern int bt_ctf_field_type_floating_point_set_exponent_digits( | |
382 | struct bt_ctf_field_type *floating_point, | |
383 | unsigned int exponent_digits); | |
384 | ||
385 | /* | |
b92ddaaa | 386 | * bt_ctf_field_type_floating_point_get_mantissa_digits: get mantissa digit |
adc315b8 JG |
387 | * count. |
388 | * | |
b92ddaaa JG |
389 | * @param floating_point Floating point type. |
390 | * | |
391 | * Returns the mantissa digit count on success, a negative value on error. | |
392 | */ | |
393 | extern int bt_ctf_field_type_floating_point_get_mantissa_digits( | |
394 | struct bt_ctf_field_type *floating_point); | |
395 | ||
396 | /* | |
397 | * bt_ctf_field_type_floating_point_set_mantissa_digits: set mantissa digit | |
398 | * count. | |
399 | * | |
adc315b8 JG |
400 | * Set the number of mantissa digits to use to store the floating point field. |
401 | * The only values currently supported are FLT_MANT_DIG and DBL_MANT_DIG. | |
402 | * | |
403 | * @param floating_point Floating point type. | |
404 | * @param mantissa_digits Number of digits to allocate to the mantissa (defaults | |
405 | * to FLT_MANT_DIG). | |
406 | * | |
407 | * Returns 0 on success, a negative value on error. | |
408 | */ | |
409 | extern int bt_ctf_field_type_floating_point_set_mantissa_digits( | |
410 | struct bt_ctf_field_type *floating_point, | |
411 | unsigned int mantissa_digits); | |
412 | ||
413 | /* | |
414 | * bt_ctf_field_type_structure_create: create a structure field type. | |
415 | * | |
416 | * Allocate a new structure field type. The creation of a field type sets | |
417 | * its reference count to 1. | |
418 | * | |
419 | * Returns an allocated field type on success, NULL on error. | |
420 | */ | |
421 | extern struct bt_ctf_field_type *bt_ctf_field_type_structure_create(void); | |
422 | ||
423 | /* | |
424 | * bt_ctf_field_type_structure_add_field: add a field to a structure. | |
425 | * | |
426 | * Add a field of type "field_type" to the structure. The structure will share | |
427 | * field_type's ownership by increasing its reference count. | |
428 | * | |
429 | * @param structure Structure type. | |
430 | * @param field_type Type of the field to add to the structure type. | |
431 | * @param field_name Name of the structure's new field (will be copied). | |
432 | * | |
433 | * Returns 0 on success, a negative value on error. | |
434 | */ | |
435 | extern int bt_ctf_field_type_structure_add_field( | |
436 | struct bt_ctf_field_type *structure, | |
437 | struct bt_ctf_field_type *field_type, | |
438 | const char *field_name); | |
439 | ||
b92ddaaa JG |
440 | /* |
441 | * bt_ctf_field_type_structure_get_field_count: Get the number of fields defined | |
442 | * in the structure. | |
443 | * | |
444 | * @param structure Structure type. | |
445 | * | |
446 | * Returns the field count on success, a negative value on error. | |
447 | */ | |
074ee56d | 448 | extern int bt_ctf_field_type_structure_get_field_count( |
b92ddaaa JG |
449 | struct bt_ctf_field_type *structure); |
450 | ||
451 | /* | |
452 | * bt_ctf_field_type_structure_get_field: get a structure's field type and name. | |
453 | * | |
454 | * @param structure Structure type. | |
455 | * @param field_type Pointer to a const char* where the field's name will | |
456 | * be returned. | |
457 | * @param field_type Pointer to a bt_ctf_field_type* where the field's type will | |
458 | * be returned. | |
459 | * @param index Index of field. | |
460 | * | |
461 | * Returns 0 on success, a negative value on error. | |
462 | */ | |
463 | extern int bt_ctf_field_type_structure_get_field( | |
464 | struct bt_ctf_field_type *structure, | |
465 | const char **field_name, struct bt_ctf_field_type **field_type, | |
074ee56d | 466 | int index); |
b92ddaaa JG |
467 | |
468 | /* | |
469 | * bt_ctf_field_type_structure_get_field_type_by_name: get a structure field's | |
470 | * type by name. | |
471 | * | |
472 | * @param structure Structure type. | |
473 | * @param field_name Name of the structure's field. | |
474 | * | |
475 | * Returns a field type instance on success, NULL on error. | |
476 | */ | |
477 | extern | |
478 | struct bt_ctf_field_type *bt_ctf_field_type_structure_get_field_type_by_name( | |
479 | struct bt_ctf_field_type *structure, const char *field_name); | |
480 | ||
adc315b8 JG |
481 | /* |
482 | * bt_ctf_field_type_variant_create: create a variant field type. | |
483 | * | |
484 | * Allocate a new variant field type. The creation of a field type sets | |
485 | * its reference count to 1. tag_name must be the name of an enumeration | |
486 | * field declared in the same scope as this variant. | |
487 | * | |
488 | * @param enum_tag Type of the variant's tag/selector (must be an enumeration). | |
489 | * @param tag_name Name of the variant's tag/selector field (will be copied). | |
490 | * | |
491 | * Returns an allocated field type on success, NULL on error. | |
492 | */ | |
493 | extern struct bt_ctf_field_type *bt_ctf_field_type_variant_create( | |
b92ddaaa JG |
494 | struct bt_ctf_field_type *enum_tag, const char *tag_name); |
495 | ||
496 | /* | |
497 | * bt_ctf_field_type_variant_get_tag_type: get a variant's tag type. | |
498 | * | |
499 | * @param variant Variant type. | |
500 | * | |
6964b7fd | 501 | * Returns a field type instance on success, NULL if unset. |
b92ddaaa JG |
502 | */ |
503 | extern struct bt_ctf_field_type *bt_ctf_field_type_variant_get_tag_type( | |
504 | struct bt_ctf_field_type *variant); | |
505 | ||
506 | /* | |
507 | * bt_ctf_field_type_variant_get_tag_name: get a variant's tag name. | |
508 | * | |
509 | * @param variant Variant type. | |
510 | * | |
6964b7fd | 511 | * Returns the tag field's name, NULL if unset. |
b92ddaaa JG |
512 | */ |
513 | extern const char *bt_ctf_field_type_variant_get_tag_name( | |
514 | struct bt_ctf_field_type *variant); | |
adc315b8 | 515 | |
d9b1ab6d JG |
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 | extern int bt_ctf_field_type_variant_set_tag_name( | |
525 | struct bt_ctf_field_type *variant, const char *name); | |
526 | ||
adc315b8 JG |
527 | /* |
528 | * bt_ctf_field_type_variant_add_field: add a field to a variant. | |
529 | * | |
b92ddaaa | 530 | * Add a field of type "field_type" to the variant. The variant will share |
adc315b8 JG |
531 | * field_type's ownership by increasing its reference count. The "field_name" |
532 | * will be copied. field_name must match a mapping in the tag/selector | |
533 | * enumeration. | |
534 | * | |
535 | * @param variant Variant type. | |
536 | * @param field_type Type of the variant type's new field. | |
537 | * @param field_name Name of the variant type's new field (will be copied). | |
538 | * | |
539 | * Returns 0 on success, a negative value on error. | |
540 | */ | |
541 | extern int bt_ctf_field_type_variant_add_field( | |
542 | struct bt_ctf_field_type *variant, | |
543 | struct bt_ctf_field_type *field_type, | |
544 | const char *field_name); | |
545 | ||
b92ddaaa JG |
546 | /* |
547 | * bt_ctf_field_type_variant_get_field_type_by_name: get variant field's type. | |
548 | * | |
549 | * @param structure Variant type. | |
550 | * @param field_name Name of the variant's field. | |
551 | * | |
552 | * Returns a field type instance on success, NULL on error. | |
553 | */ | |
554 | extern | |
555 | struct bt_ctf_field_type *bt_ctf_field_type_variant_get_field_type_by_name( | |
556 | struct bt_ctf_field_type *variant, const char *field_name); | |
557 | ||
558 | /* | |
559 | * bt_ctf_field_type_variant_get_field_type_from_tag: get variant field's type. | |
560 | * | |
561 | * @param variant Variant type. | |
562 | * @param tag Type tag (enum). | |
563 | * | |
564 | * Returns a field type instance on success, NULL on error. | |
565 | */ | |
566 | extern | |
567 | struct bt_ctf_field_type *bt_ctf_field_type_variant_get_field_type_from_tag( | |
568 | struct bt_ctf_field_type *variant, struct bt_ctf_field *tag); | |
569 | ||
570 | /* | |
571 | * bt_ctf_field_type_variant_get_field_count: Get the number of fields defined | |
572 | * in the variant. | |
573 | * | |
574 | * @param variant Variant type. | |
575 | * | |
576 | * Returns the field count on success, a negative value on error. | |
577 | */ | |
074ee56d | 578 | extern int bt_ctf_field_type_variant_get_field_count( |
b92ddaaa JG |
579 | struct bt_ctf_field_type *variant); |
580 | ||
581 | /* | |
582 | * bt_ctf_field_type_variant_get_field: get a variant's field name and type. | |
583 | * | |
584 | * @param variant Variant type. | |
585 | * @param field_type Pointer to a const char* where the field's name will | |
586 | * be returned. | |
587 | * @param field_type Pointer to a bt_ctf_field_type* where the field's type will | |
588 | * be returned. | |
589 | * @param index Index of field. | |
590 | * | |
591 | * Returns 0 on success, a negative value on error. | |
592 | */ | |
593 | extern int bt_ctf_field_type_variant_get_field( | |
594 | struct bt_ctf_field_type *variant, const char **field_name, | |
074ee56d | 595 | struct bt_ctf_field_type **field_type, int index); |
b92ddaaa | 596 | |
adc315b8 JG |
597 | /* |
598 | * bt_ctf_field_type_array_create: create an array field type. | |
599 | * | |
600 | * Allocate a new array field type. The creation of a field type sets | |
601 | * its reference count to 1. | |
602 | * | |
603 | * @param element_type Array's element type. | |
604 | * @oaram length Array type's length. | |
605 | * | |
606 | * Returns an allocated field type on success, NULL on error. | |
607 | */ | |
608 | extern struct bt_ctf_field_type *bt_ctf_field_type_array_create( | |
b92ddaaa JG |
609 | struct bt_ctf_field_type *element_type, unsigned int length); |
610 | ||
611 | /* | |
612 | * bt_ctf_field_type_array_get_element_type: get an array's element type. | |
613 | * | |
614 | * @param array Array type. | |
615 | * | |
616 | * Returns a field type instance on success, NULL on error. | |
617 | */ | |
618 | extern struct bt_ctf_field_type *bt_ctf_field_type_array_get_element_type( | |
619 | struct bt_ctf_field_type *array); | |
620 | ||
621 | /* | |
622 | * bt_ctf_field_type_array_get_length: get an array's length. | |
623 | * | |
624 | * @param array Array type. | |
625 | * | |
626 | * Returns the array's length on success, a negative value on error. | |
627 | */ | |
628 | extern int64_t bt_ctf_field_type_array_get_length( | |
629 | struct bt_ctf_field_type *array); | |
adc315b8 JG |
630 | |
631 | /* | |
632 | * bt_ctf_field_type_sequence_create: create a sequence field type. | |
633 | * | |
634 | * Allocate a new sequence field type. The creation of a field type sets | |
635 | * its reference count to 1. "length_field_name" must match an integer field | |
636 | * declared in the same scope. | |
637 | * | |
638 | * @param element_type Sequence's element type. | |
639 | * @param length_field_name Name of the sequence's length field (will be | |
640 | * copied). | |
641 | * | |
642 | * Returns an allocated field type on success, NULL on error. | |
643 | */ | |
644 | extern struct bt_ctf_field_type *bt_ctf_field_type_sequence_create( | |
645 | struct bt_ctf_field_type *element_type, | |
646 | const char *length_field_name); | |
647 | ||
b92ddaaa JG |
648 | /* |
649 | * bt_ctf_field_type_sequence_get_element_type: get a sequence's element type. | |
650 | * | |
651 | * @param sequence Sequence type. | |
652 | * | |
653 | * Returns a field type instance on success, NULL on error. | |
654 | */ | |
655 | extern struct bt_ctf_field_type *bt_ctf_field_type_sequence_get_element_type( | |
656 | struct bt_ctf_field_type *sequence); | |
657 | ||
658 | /* | |
659 | * bt_ctf_field_type_sequence_get_length_field_name: get length field name. | |
660 | * | |
661 | * @param sequence Sequence type. | |
662 | * | |
663 | * Returns the sequence's length field on success, NULL on error. | |
664 | */ | |
665 | extern const char *bt_ctf_field_type_sequence_get_length_field_name( | |
666 | struct bt_ctf_field_type *sequence); | |
667 | ||
adc315b8 JG |
668 | /* |
669 | * bt_ctf_field_type_string_create: create a string field type. | |
670 | * | |
671 | * Allocate a new string field type. The creation of a field type sets | |
672 | * its reference count to 1. | |
673 | * | |
674 | * Returns an allocated field type on success, NULL on error. | |
675 | */ | |
676 | extern struct bt_ctf_field_type *bt_ctf_field_type_string_create(void); | |
677 | ||
b92ddaaa JG |
678 | /* |
679 | * bt_ctf_field_type_string_get_encoding: get a string type's encoding. | |
680 | * | |
681 | * Get the string type's encoding. | |
682 | * | |
683 | * @param string_type String type. | |
684 | * | |
685 | * Returns the string's encoding on success, a CTF_STRING_UNKNOWN on error. | |
686 | */ | |
687 | extern enum ctf_string_encoding bt_ctf_field_type_string_get_encoding( | |
688 | struct bt_ctf_field_type *string_type); | |
689 | ||
adc315b8 JG |
690 | /* |
691 | * bt_ctf_field_type_string_set_encoding: set a string type's encoding. | |
692 | * | |
693 | * Set the string type's encoding. | |
694 | * | |
b92ddaaa | 695 | * @param string_type String type. |
adc315b8 JG |
696 | * @param encoding String field encoding, default CTF_STRING_ENCODING_ASCII. |
697 | * Valid values are CTF_STRING_ENCODING_ASCII and CTF_STRING_ENCODING_UTF8. | |
698 | * | |
699 | * Returns 0 on success, a negative value on error. | |
700 | */ | |
701 | extern int bt_ctf_field_type_string_set_encoding( | |
b92ddaaa | 702 | struct bt_ctf_field_type *string_type, |
adc315b8 JG |
703 | enum ctf_string_encoding encoding); |
704 | ||
b92ddaaa JG |
705 | /* |
706 | * bt_ctf_field_type_get_alignment: get a field type's alignment. | |
707 | * | |
708 | * Get the field type's alignment. | |
709 | * | |
710 | * @param type Field type. | |
711 | * | |
46caf2cb JG |
712 | * Returns the field type's alignment on success, a negative value on error and |
713 | * 0 if the alignment is undefined (as in the case of a variant). | |
b92ddaaa JG |
714 | */ |
715 | extern int bt_ctf_field_type_get_alignment(struct bt_ctf_field_type *type); | |
716 | ||
adc315b8 JG |
717 | /* |
718 | * bt_ctf_field_type_set_alignment: set a field type's alignment. | |
719 | * | |
720 | * Set the field type's alignment. | |
721 | * | |
722 | * @param type Field type. | |
723 | * @param alignment Type's alignment. Defaults to 1 (bit-aligned). However, | |
724 | * some types, such as structures and string, may impose other alignment | |
725 | * constraints. | |
726 | * | |
727 | * Returns 0 on success, a negative value on error. | |
728 | */ | |
729 | extern int bt_ctf_field_type_set_alignment(struct bt_ctf_field_type *type, | |
730 | unsigned int alignment); | |
731 | ||
b92ddaaa JG |
732 | /* |
733 | * bt_ctf_field_type_get_byte_order: get a field type's byte order. | |
734 | * | |
735 | * @param type Field type. | |
736 | * | |
737 | * Returns the field type's byte order on success, a negative value on error. | |
738 | */ | |
739 | extern enum bt_ctf_byte_order bt_ctf_field_type_get_byte_order( | |
740 | struct bt_ctf_field_type *type); | |
741 | ||
adc315b8 JG |
742 | /* |
743 | * bt_ctf_field_type_set_byte_order: set a field type's byte order. | |
744 | * | |
745 | * Set the field type's byte order. | |
746 | * | |
747 | * @param type Field type. | |
748 | * @param byte_order Field type's byte order. Defaults to | |
c35a1669 | 749 | * BT_CTF_BYTE_ORDER_NATIVE; the trace's endianness. |
adc315b8 JG |
750 | * |
751 | * Returns 0 on success, a negative value on error. | |
752 | */ | |
753 | extern int bt_ctf_field_type_set_byte_order(struct bt_ctf_field_type *type, | |
754 | enum bt_ctf_byte_order byte_order); | |
755 | ||
b011f6b0 PP |
756 | /* |
757 | * bt_ctf_field_type_variant_get_tag_field_path: get a variant's tag's field | |
758 | * path. | |
759 | * | |
760 | * Get the variant's tag's field path. | |
761 | * | |
762 | * @param type Field type. | |
763 | * | |
764 | * Returns the field path on success, NULL on error or if no field path is set. | |
765 | */ | |
766 | extern struct bt_ctf_field_path *bt_ctf_field_type_variant_get_tag_field_path( | |
767 | struct bt_ctf_field_type *type); | |
768 | ||
769 | /* | |
770 | * bt_ctf_field_type_sequence_get_length_field_path: get a sequence's length's | |
771 | * field path. | |
772 | * | |
773 | * Get the sequence's length's field path. | |
774 | * | |
775 | * @param type Field type. | |
776 | * | |
777 | * Returns the field path on success, NULL on error or if no field path is set. | |
778 | */ | |
779 | extern struct bt_ctf_field_path *bt_ctf_field_type_sequence_get_length_field_path( | |
780 | struct bt_ctf_field_type *type); | |
781 | ||
265e809c PP |
782 | /* |
783 | * bt_ctf_field_type_compare: compare two field types recursively | |
784 | * | |
785 | * Compare two field types recursively. | |
786 | * | |
787 | * The registered tag field type of a variant field type is ignored: | |
788 | * only the tag strings are compared. | |
789 | * | |
790 | * @param type_a Field type A. | |
791 | * @param type_b Field type B. | |
792 | * | |
81e36fac PP |
793 | * Returns 0 if both field types are semantically equivalent, a positive |
794 | * value if they are not equivalent, or a negative value on error. | |
265e809c PP |
795 | */ |
796 | extern int bt_ctf_field_type_compare(struct bt_ctf_field_type *type_a, | |
797 | struct bt_ctf_field_type *type_b); | |
798 | ||
b92ddaaa JG |
799 | /* |
800 | * bt_ctf_field_type_get_type_id: get a field type's ctf_type_id. | |
801 | * | |
802 | * @param type Field type. | |
803 | * | |
804 | * Returns the field type's ctf_type_id, CTF_TYPE_UNKNOWN on error. | |
805 | */ | |
806 | extern enum ctf_type_id bt_ctf_field_type_get_type_id( | |
807 | struct bt_ctf_field_type *type); | |
808 | ||
56db8d7a PP |
809 | /* |
810 | * bt_ctf_field_type_is_integer: returns whether or not a given field | |
811 | * type is an integer type. | |
812 | * | |
813 | * @param type Field type. | |
814 | * | |
815 | * Returns 1 if the field type is an integer type, 0 otherwise. | |
816 | */ | |
817 | extern int bt_ctf_field_type_is_integer(struct bt_ctf_field_type *type); | |
818 | ||
819 | /* | |
820 | * bt_ctf_field_type_is_floating_point: returns whether or not a given field | |
821 | * type is a floating point number type. | |
822 | * | |
823 | * @param type Field type. | |
824 | * | |
825 | * Returns 1 if the field type is a floating point number type, 0 otherwise. | |
826 | */ | |
827 | extern int bt_ctf_field_type_is_floating_point(struct bt_ctf_field_type *type); | |
828 | ||
829 | /* | |
830 | * bt_ctf_field_type_is_enumeration: returns whether or not a given field | |
831 | * type is an enumeration type. | |
832 | * | |
833 | * @param type Field type. | |
834 | * | |
835 | * Returns 1 if the field type is an enumeration type, 0 otherwise. | |
836 | */ | |
837 | extern int bt_ctf_field_type_is_enumeration(struct bt_ctf_field_type *type); | |
838 | ||
839 | /* | |
840 | * bt_ctf_field_type_is_string: returns whether or not a given field | |
841 | * type is a string type. | |
842 | * | |
843 | * @param type Field type. | |
844 | * | |
845 | * Returns 1 if the field type is a string type, 0 otherwise. | |
846 | */ | |
847 | extern int bt_ctf_field_type_is_string(struct bt_ctf_field_type *type); | |
848 | ||
849 | /* | |
850 | * bt_ctf_field_type_is_structure: returns whether or not a given field | |
851 | * type is a structure type. | |
852 | * | |
853 | * @param type Field type. | |
854 | * | |
855 | * Returns 1 if the field type is a structure type, 0 otherwise. | |
856 | */ | |
857 | extern int bt_ctf_field_type_is_structure(struct bt_ctf_field_type *type); | |
858 | ||
859 | /* | |
860 | * bt_ctf_field_type_is_array: returns whether or not a given field | |
861 | * type is an array type. | |
862 | * | |
863 | * @param type Field type. | |
864 | * | |
865 | * Returns 1 if the field type is an array type, 0 otherwise. | |
866 | */ | |
867 | extern int bt_ctf_field_type_is_array(struct bt_ctf_field_type *type); | |
868 | ||
869 | /* | |
870 | * bt_ctf_field_type_is_sequence: returns whether or not a given field | |
871 | * type is a sequence type. | |
872 | * | |
873 | * @param type Field type. | |
874 | * | |
875 | * Returns 1 if the field type is a sequence type, 0 otherwise. | |
876 | */ | |
877 | extern int bt_ctf_field_type_is_sequence(struct bt_ctf_field_type *type); | |
878 | ||
879 | /* | |
880 | * bt_ctf_field_type_is_variant: returns whether or not a given field | |
881 | * type is a variant type. | |
882 | * | |
883 | * @param type Field type. | |
884 | * | |
885 | * Returns 1 if the field type is a variant type, 0 otherwise. | |
886 | */ | |
887 | extern int bt_ctf_field_type_is_variant(struct bt_ctf_field_type *type); | |
888 | ||
adc315b8 JG |
889 | /* |
890 | * bt_ctf_field_type_get and bt_ctf_field_type_put: increment and decrement | |
891 | * the field type's reference count. | |
892 | * | |
de3dd40e PP |
893 | * You may also use bt_ctf_get() and bt_ctf_put() with field type objects. |
894 | * | |
adc315b8 JG |
895 | * These functions ensure that the field type won't be destroyed while it |
896 | * is in use. The same number of get and put (plus one extra put to | |
897 | * release the initial reference done at creation) have to be done to | |
898 | * destroy a field type. | |
899 | * | |
900 | * When the field type's reference count is decremented to 0 by a | |
901 | * bt_ctf_field_type_put, the field type is freed. | |
902 | * | |
903 | * @param type Field type. | |
904 | */ | |
905 | extern void bt_ctf_field_type_get(struct bt_ctf_field_type *type); | |
906 | extern void bt_ctf_field_type_put(struct bt_ctf_field_type *type); | |
907 | ||
908 | #ifdef __cplusplus | |
909 | } | |
910 | #endif | |
911 | ||
912 | #endif /* BABELTRACE_CTF_IR_EVENT_TYPES_H */ |