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