Commit | Line | Data |
---|---|---|
2e33ac5a PP |
1 | #ifndef BABELTRACE_CTF_IR_FIELDS_H |
2 | #define BABELTRACE_CTF_IR_FIELDS_H | |
adc315b8 JG |
3 | |
4 | /* | |
2e33ac5a | 5 | * Babeltrace - CTF IR: Event Fields |
adc315b8 | 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 <stdint.h> | |
cd95e351 | 34 | #include <stddef.h> |
adc315b8 JG |
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; | |
43 | struct bt_ctf_field_type; | |
44 | ||
45 | /* | |
46 | * bt_ctf_field_create: create an instance of a field. | |
47 | * | |
48 | * Allocate a new field of the type described by the bt_ctf_field_type | |
49 | * structure.The creation of a field sets its reference count to 1. | |
50 | * | |
51 | * @param type Field type to be instanciated. | |
52 | * | |
53 | * Returns an allocated field on success, NULL on error. | |
54 | */ | |
55 | extern struct bt_ctf_field *bt_ctf_field_create( | |
56 | struct bt_ctf_field_type *type); | |
57 | ||
58 | /* | |
59 | * bt_ctf_field_structure_get_field: get a structure's field. | |
60 | * | |
61 | * Get the structure's field corresponding to the provided field name. | |
51865548 | 62 | * bt_put() must be called on the returned value. |
adc315b8 JG |
63 | * |
64 | * @param structure Structure field instance. | |
65 | * @param name Name of the field in the provided structure. | |
66 | * | |
67 | * Returns a field instance on success, NULL on error. | |
68 | */ | |
69 | extern struct bt_ctf_field *bt_ctf_field_structure_get_field( | |
70 | struct bt_ctf_field *structure, const char *name); | |
71 | ||
cd95e351 JG |
72 | /* |
73 | * bt_ctf_field_structure_get_field_by_index: get a structure's field by index. | |
74 | * | |
75 | * Get the structure's field corresponding to the provided field name. | |
51865548 | 76 | * bt_put() must be called on the returned value. |
cd95e351 JG |
77 | * The indexes are the same as those provided for bt_ctf_field_type_structure. |
78 | * | |
79 | * @param structure Structure field instance. | |
80 | * @param index Index of the field in the provided structure. | |
81 | * | |
82 | * Returns a field instance on success, NULL on error. | |
83 | */ | |
84 | extern struct bt_ctf_field *bt_ctf_field_structure_get_field_by_index( | |
074ee56d | 85 | struct bt_ctf_field *structure, int index); |
cd95e351 | 86 | |
adc315b8 JG |
87 | /* |
88 | * bt_ctf_field_array_get_field: get an array's field at position "index". | |
89 | * | |
51865548 | 90 | * Return the array's field at position "index". bt_put() must be |
adc315b8 JG |
91 | * called on the returned value. |
92 | * | |
93 | * @param array Array field instance. | |
94 | * @param index Position of the array's desired element. | |
95 | * | |
96 | * Returns a field instance on success, NULL on error. | |
97 | */ | |
98 | extern struct bt_ctf_field *bt_ctf_field_array_get_field( | |
99 | struct bt_ctf_field *array, uint64_t index); | |
100 | ||
cd95e351 JG |
101 | /* |
102 | * bt_ctf_field_sequence_get_length: get a sequence's length. | |
103 | * | |
104 | * Get the sequence's length field. | |
105 | * | |
106 | * @param sequence Sequence field instance. | |
107 | * | |
108 | * Returns a field instance on success, NULL if a length was never set. | |
109 | */ | |
110 | extern struct bt_ctf_field *bt_ctf_field_sequence_get_length( | |
111 | struct bt_ctf_field *sequence); | |
112 | ||
adc315b8 JG |
113 | /* |
114 | * bt_ctf_field_sequence_set_length: set a sequence's length. | |
115 | * | |
116 | * Set the sequence's length field. | |
117 | * | |
118 | * @param sequence Sequence field instance. | |
152e7331 JG |
119 | * @param length_field Unsigned integer field instance indicating the |
120 | * sequence's length. | |
adc315b8 | 121 | * |
cd95e351 | 122 | * Returns 0 on success, a negative value on error. |
adc315b8 JG |
123 | */ |
124 | extern int bt_ctf_field_sequence_set_length(struct bt_ctf_field *sequence, | |
125 | struct bt_ctf_field *length_field); | |
126 | ||
127 | /* | |
128 | * bt_ctf_field_sequence_get_field: get a sequence's field at position "index". | |
129 | * | |
130 | * Return the sequence's field at position "index". The sequence's length must | |
131 | * have been set prior to calling this function using | |
132 | * bt_ctf_field_sequence_set_length(). | |
51865548 | 133 | * bt_put() must be called on the returned value. |
adc315b8 JG |
134 | * |
135 | * @param array Sequence field instance. | |
136 | * @param index Position of the sequence's desired element. | |
137 | * | |
138 | * Returns a field instance on success, NULL on error. | |
139 | */ | |
140 | extern struct bt_ctf_field *bt_ctf_field_sequence_get_field( | |
141 | struct bt_ctf_field *sequence, uint64_t index); | |
142 | ||
143 | /* | |
144 | * bt_ctf_field_variant_get_field: get a variant's selected field. | |
145 | * | |
146 | * Return the variant's selected field. The "tag" field is the selector enum | |
51865548 | 147 | * field. bt_put() must be called on the returned value. |
adc315b8 JG |
148 | * |
149 | * @param variant Variant field instance. | |
150 | * @param tag Selector enumeration field. | |
151 | * | |
152 | * Returns a field instance on success, NULL on error. | |
153 | */ | |
154 | extern struct bt_ctf_field *bt_ctf_field_variant_get_field( | |
155 | struct bt_ctf_field *variant, struct bt_ctf_field *tag); | |
156 | ||
3f4a108d PP |
157 | /* |
158 | * bt_ctf_field_variant_get_current_field: get the current selected field of a | |
159 | * variant. | |
160 | * | |
161 | * Return the variant's current selected field. This function, unlike | |
162 | * bt_ctf_field_variant_get_field(), does not create any field; it | |
163 | * returns NULL if there's no current selected field yet. | |
164 | * | |
165 | * @param variant Variant field instance. | |
166 | * | |
167 | * Returns a field instance on success, NULL on error or when there's no | |
168 | * current selected field. | |
169 | */ | |
170 | extern struct bt_ctf_field *bt_ctf_field_variant_get_current_field( | |
171 | struct bt_ctf_field *variant); | |
172 | ||
f78d67fb JG |
173 | /* |
174 | * bt_ctf_field_variant_get_tag: get the tag field of a variant. | |
175 | * | |
176 | * Return the variant's associated tag field. This function, unlike | |
177 | * bt_ctf_field_variant_get_field(), does not create any field; it | |
178 | * returns NULL if there's no current selected field yet (and, thus, no | |
179 | * associated tag). | |
180 | * | |
181 | * @param variant Variant field instance. | |
182 | * | |
183 | * Returns a field instance (enumeration) on success, NULL on error or when | |
184 | * there is no currently selected field. | |
185 | */ | |
186 | extern struct bt_ctf_field *bt_ctf_field_variant_get_tag( | |
187 | struct bt_ctf_field *variant); | |
188 | ||
adc315b8 JG |
189 | /* |
190 | * bt_ctf_field_enumeration_get_container: get an enumeration field's container. | |
191 | * | |
192 | * Return the enumeration's underlying container field (an integer). | |
51865548 | 193 | * bt_put() must be called on the returned value. |
adc315b8 JG |
194 | * |
195 | * @param enumeration Enumeration field instance. | |
196 | * | |
197 | * Returns a field instance on success, NULL on error. | |
198 | */ | |
199 | extern struct bt_ctf_field *bt_ctf_field_enumeration_get_container( | |
200 | struct bt_ctf_field *enumeration); | |
201 | ||
cd95e351 JG |
202 | /* |
203 | * bt_ctf_field_enumeration_get_mapping_name: get an enumeration field's mapping | |
204 | * name. | |
205 | * | |
206 | * Return the enumeration's underlying container field (an integer). | |
51865548 | 207 | * bt_put() must be called on the returned value. |
cd95e351 JG |
208 | * |
209 | * @param enumeration Enumeration field instance. | |
210 | * | |
211 | * Returns a field instance on success, NULL on error. | |
212 | */ | |
213 | extern const char *bt_ctf_field_enumeration_get_mapping_name( | |
214 | struct bt_ctf_field *enumeration); | |
215 | ||
216 | /* | |
217 | * bt_ctf_field_signed_integer_get_value: get a signed integer field's value | |
218 | * | |
219 | * Get a signed integer field's value. | |
220 | * | |
221 | * @param integer Signed integer field instance. | |
222 | * @param value Pointer to a signed integer where the value will be stored. | |
223 | * | |
224 | * Returns 0 on success, a negative value on error. | |
225 | */ | |
226 | extern int bt_ctf_field_signed_integer_get_value(struct bt_ctf_field *integer, | |
227 | int64_t *value); | |
228 | ||
adc315b8 JG |
229 | /* |
230 | * bt_ctf_field_signed_integer_set_value: set a signed integer field's value | |
231 | * | |
232 | * Set a signed integer field's value. The value is checked to make sure it | |
233 | * can be stored in the underlying field. | |
234 | * | |
235 | * @param integer Signed integer field instance. | |
236 | * @param value Signed integer field value. | |
237 | * | |
238 | * Returns 0 on success, a negative value on error. | |
239 | */ | |
240 | extern int bt_ctf_field_signed_integer_set_value(struct bt_ctf_field *integer, | |
241 | int64_t value); | |
242 | ||
cd95e351 JG |
243 | /* |
244 | * bt_ctf_field_unsigned_integer_get_value: get unsigned integer field's value | |
245 | * | |
246 | * Get an unsigned integer field's value. | |
247 | * | |
248 | * @param integer Unsigned integer field instance. | |
249 | * @param value Pointer to an unsigned integer where the value will be stored. | |
250 | * | |
251 | * Returns 0 on success, a negative value on error. | |
252 | */ | |
253 | extern int bt_ctf_field_unsigned_integer_get_value(struct bt_ctf_field *integer, | |
254 | uint64_t *value); | |
255 | ||
adc315b8 JG |
256 | /* |
257 | * bt_ctf_field_unsigned_integer_set_value: set unsigned integer field's value | |
258 | * | |
259 | * Set an unsigned integer field's value. The value is checked to make sure it | |
260 | * can be stored in the underlying field. | |
261 | * | |
262 | * @param integer Unsigned integer field instance. | |
263 | * @param value Unsigned integer field value. | |
264 | * | |
265 | * Returns 0 on success, a negative value on error. | |
266 | */ | |
267 | extern int bt_ctf_field_unsigned_integer_set_value(struct bt_ctf_field *integer, | |
268 | uint64_t value); | |
269 | ||
cd95e351 JG |
270 | /* |
271 | * bt_ctf_field_floating_point_get_value: get a floating point field's value | |
272 | * | |
273 | * Get a floating point field's value. | |
274 | * | |
275 | * @param floating_point Floating point field instance. | |
276 | * @param value Pointer to a double where the value will be stored. | |
277 | * | |
278 | * Returns 0 on success, a negative value on error. | |
279 | */ | |
280 | extern int bt_ctf_field_floating_point_get_value( | |
281 | struct bt_ctf_field *floating_point, double *value); | |
282 | ||
adc315b8 JG |
283 | /* |
284 | * bt_ctf_field_floating_point_set_value: set a floating point field's value | |
285 | * | |
286 | * Set a floating point field's value. The underlying type may not support the | |
287 | * double's full precision. | |
288 | * | |
289 | * @param floating_point Floating point field instance. | |
290 | * @param value Floating point field value. | |
291 | * | |
292 | * Returns 0 on success, a negative value on error. | |
293 | */ | |
294 | extern int bt_ctf_field_floating_point_set_value( | |
295 | struct bt_ctf_field *floating_point, | |
296 | double value); | |
297 | ||
cd95e351 JG |
298 | /* |
299 | * bt_ctf_field_string_get_value: get a string field's value | |
300 | * | |
301 | * Get a string field's value. | |
302 | * | |
303 | * @param string_field String field instance. | |
304 | * | |
305 | * Returns the string's value, NULL if unset. | |
306 | */ | |
307 | extern const char *bt_ctf_field_string_get_value( | |
308 | struct bt_ctf_field *string_field); | |
309 | ||
adc315b8 JG |
310 | /* |
311 | * bt_ctf_field_string_set_value: set a string field's value | |
312 | * | |
313 | * Set a string field's value. | |
314 | * | |
cd95e351 | 315 | * @param string_field String field instance. |
adc315b8 JG |
316 | * @param value String field value (will be copied). |
317 | * | |
318 | * Returns 0 on success, a negative value on error. | |
319 | */ | |
cd95e351 | 320 | extern int bt_ctf_field_string_set_value(struct bt_ctf_field *string_field, |
adc315b8 JG |
321 | const char *value); |
322 | ||
c6f9c5a3 PP |
323 | /* |
324 | * bt_ctf_field_string_append: append a string to a string field's | |
325 | * current value. | |
326 | * | |
327 | * Append a string to the current value of a string field. If the string | |
328 | * field was never set using bt_ctf_field_string_set_value(), it is | |
329 | * first set to an empty string, and then the concatenation happens. | |
330 | * | |
331 | * @param string_field String field instance. | |
332 | * @param value String to append to the current string field's value. | |
333 | * | |
334 | * Returns 0 on success, a negative value on error. | |
335 | */ | |
336 | extern int bt_ctf_field_string_append(struct bt_ctf_field *string_field, | |
337 | const char *value); | |
338 | ||
f98c6554 PP |
339 | /* |
340 | * bt_ctf_field_string_append_len: append a string of a given length to | |
341 | * a string field's current value. | |
342 | * | |
343 | * Append a string of a given length to the current value of a string | |
344 | * field. If the string field was never set using | |
345 | * bt_ctf_field_string_set_value(), it is first set to an empty string, | |
346 | * and then the concatenation happens. | |
347 | * | |
348 | * If a null byte is encountered before the given length, only the | |
349 | * substring before the first null byte is appended. | |
350 | * | |
351 | * @param string_field String field instance. | |
352 | * @param value String to append to the current string field's value. | |
353 | * @param length Length of string value to append. | |
354 | * | |
355 | * Returns 0 on success, a negative value on error. | |
356 | */ | |
357 | extern int bt_ctf_field_string_append_len( | |
358 | struct bt_ctf_field *string_field, const char *value, | |
359 | unsigned int length); | |
360 | ||
cd95e351 JG |
361 | /* |
362 | * bt_ctf_field_get_type: get a field's type | |
363 | * | |
364 | * @param field Field intance. | |
365 | * | |
366 | * Returns a field type instance on success, NULL on error. | |
367 | */ | |
368 | extern struct bt_ctf_field_type *bt_ctf_field_get_type( | |
369 | struct bt_ctf_field *field); | |
370 | ||
4ebcc695 PP |
371 | /* |
372 | * bt_ctf_field_get_type_id: get a field's ctf_type_id. | |
373 | * | |
374 | * This is a helper function which avoids a call to | |
375 | * bt_ctf_field_get_type(), followed by a call to | |
376 | * bt_ctf_field_type_get_type_id(), followed by a call to | |
377 | * bt_ctf_put(). | |
378 | * | |
379 | * @param field Field instance. | |
380 | * | |
381 | * Returns the field's ctf_type_id, CTF_TYPE_UNKNOWN on error. | |
382 | */ | |
9a19a512 | 383 | extern enum bt_ctf_type_id bt_ctf_field_get_type_id(struct bt_ctf_field *field); |
4ebcc695 | 384 | |
8f3553be PP |
385 | /* |
386 | * bt_ctf_field_is_integer: returns whether or not a given field | |
387 | * is an integer type. | |
388 | * | |
389 | * @param field Field instance. | |
390 | * | |
391 | * Returns 1 if the field instance is an integer type, 0 otherwise. | |
392 | */ | |
393 | extern int bt_ctf_field_is_integer(struct bt_ctf_field *field); | |
394 | ||
395 | /* | |
396 | * bt_ctf_field_is_floating_point: returns whether or not a given field | |
397 | * is a floating point number type. | |
398 | * | |
399 | * @param field Field instance. | |
400 | * | |
401 | * Returns 1 if the field instance is a floating point number type, 0 otherwise. | |
402 | */ | |
403 | extern int bt_ctf_field_is_floating_point(struct bt_ctf_field *field); | |
404 | ||
405 | /* | |
406 | * bt_ctf_field_is_enumeration: returns whether or not a given field | |
407 | * is an enumeration type. | |
408 | * | |
409 | * @param field Field instance. | |
410 | * | |
411 | * Returns 1 if the field instance is an enumeration type, 0 otherwise. | |
412 | */ | |
413 | extern int bt_ctf_field_is_enumeration(struct bt_ctf_field *field); | |
414 | ||
415 | /* | |
416 | * bt_ctf_field_is_string: returns whether or not a given field | |
417 | * is a string type. | |
418 | * | |
419 | * @param field Field instance. | |
420 | * | |
421 | * Returns 1 if the field instance is a string type, 0 otherwise. | |
422 | */ | |
423 | extern int bt_ctf_field_is_string(struct bt_ctf_field *field); | |
424 | ||
425 | /* | |
426 | * bt_ctf_field_is_structure: returns whether or not a given field | |
427 | * is a structure type. | |
428 | * | |
429 | * @param field Field instance. | |
430 | * | |
431 | * Returns 1 if the field instance is a structure type, 0 otherwise. | |
432 | */ | |
433 | extern int bt_ctf_field_is_structure(struct bt_ctf_field *field); | |
434 | ||
435 | /* | |
436 | * bt_ctf_field_is_array: returns whether or not a given field | |
437 | * is an array type. | |
438 | * | |
439 | * @param field Field instance. | |
440 | * | |
441 | * Returns 1 if the field instance is an array type, 0 otherwise. | |
442 | */ | |
443 | extern int bt_ctf_field_is_array(struct bt_ctf_field *field); | |
444 | ||
445 | /* | |
446 | * bt_ctf_field_is_sequence: returns whether or not a given field | |
447 | * is a sequence type. | |
448 | * | |
449 | * @param field Field instance. | |
450 | * | |
451 | * Returns 1 if the field instance is a sequence type, 0 otherwise. | |
452 | */ | |
453 | extern int bt_ctf_field_is_sequence(struct bt_ctf_field *field); | |
454 | ||
455 | /* | |
456 | * bt_ctf_field_is_variant: returns whether or not a given field | |
457 | * is a variant type. | |
458 | * | |
459 | * @param field Field instance. | |
460 | * | |
461 | * Returns 1 if the field instance is a variant type, 0 otherwise. | |
462 | */ | |
463 | extern int bt_ctf_field_is_variant(struct bt_ctf_field *field); | |
464 | ||
a39fe52e PP |
465 | /* |
466 | * bt_ctf_field_copy: get a field's deep copy. | |
467 | * | |
468 | * Get a field's deep copy. The created field copy shares the source's | |
469 | * associated field types. | |
470 | * | |
471 | * On success, the returned copy has its reference count set to 1. | |
472 | * | |
473 | * @param field Field instance. | |
474 | * | |
475 | * Returns the field copy on success, NULL on error. | |
476 | */ | |
477 | extern struct bt_ctf_field *bt_ctf_field_copy(struct bt_ctf_field *field); | |
478 | ||
adc315b8 JG |
479 | #ifdef __cplusplus |
480 | } | |
481 | #endif | |
482 | ||
2e33ac5a | 483 | #endif /* BABELTRACE_CTF_IR_FIELDS_H */ |