Commit | Line | Data |
---|---|---|
3fd40f46 PP |
1 | #ifndef BABELTRACE2_CTF_WRITER_FIELD_TYPES_H |
2 | #define BABELTRACE2_CTF_WRITER_FIELD_TYPES_H | |
8deee039 PP |
3 | |
4 | /* | |
0dcb770f | 5 | * Copyright (c) 2010-2019 EfficiOS Inc. and Linux Foundation |
8deee039 PP |
6 | * |
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy | |
8 | * of this software and associated documentation files (the "Software"), to deal | |
9 | * in the Software without restriction, including without limitation the rights | |
10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
11 | * copies of the Software, and to permit persons to whom the Software is | |
12 | * furnished to do so, subject to the following conditions: | |
13 | * | |
14 | * The above copyright notice and this permission notice shall be included in | |
15 | * all copies or substantial portions of the Software. | |
16 | * | |
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
23 | * SOFTWARE. | |
8deee039 PP |
24 | */ |
25 | ||
26 | #include <stdint.h> | |
27 | #include <stddef.h> | |
3996bc53 | 28 | #include <babeltrace2-ctf-writer/types.h> |
8deee039 PP |
29 | |
30 | #ifdef __cplusplus | |
31 | extern "C" { | |
32 | #endif | |
33 | ||
34 | struct bt_ctf_field; | |
35 | struct bt_ctf_field_type; | |
36 | ||
086dc475 PP |
37 | enum bt_ctf_scope { |
38 | /// Unknown, used for errors. | |
39 | BT_CTF_SCOPE_UNKNOWN = -1, | |
40 | ||
41 | /// Trace packet header. | |
42 | BT_CTF_SCOPE_TRACE_PACKET_HEADER = 1, | |
43 | ||
44 | /// Stream packet context. | |
45 | BT_CTF_SCOPE_STREAM_PACKET_CONTEXT = 2, | |
46 | ||
47 | /// Stream event header. | |
48 | BT_CTF_SCOPE_STREAM_EVENT_HEADER = 3, | |
49 | ||
50 | /// Stream event context. | |
51 | BT_CTF_SCOPE_STREAM_EVENT_CONTEXT = 4, | |
52 | ||
53 | /// Event context. | |
54 | BT_CTF_SCOPE_EVENT_CONTEXT = 5, | |
55 | ||
56 | /// Event payload. | |
57 | BT_CTF_SCOPE_EVENT_PAYLOAD = 6, | |
58 | ||
59 | /// @cond DOCUMENT | |
60 | BT_CTF_SCOPE_ENV = 0, | |
61 | BT_CTF_SCOPE_EVENT_FIELDS = 6, | |
62 | /// @endcond | |
63 | }; | |
64 | ||
8deee039 | 65 | enum bt_ctf_field_type_id { |
086dc475 PP |
66 | BT_CTF_FIELD_TYPE_ID_UNKNOWN = -1, |
67 | BT_CTF_FIELD_TYPE_ID_INTEGER = 0, | |
68 | BT_CTF_FIELD_TYPE_ID_FLOAT = 1, | |
69 | BT_CTF_FIELD_TYPE_ID_ENUM = 2, | |
70 | BT_CTF_FIELD_TYPE_ID_STRING = 3, | |
71 | BT_CTF_FIELD_TYPE_ID_STRUCT = 4, | |
72 | BT_CTF_FIELD_TYPE_ID_ARRAY = 5, | |
73 | BT_CTF_FIELD_TYPE_ID_SEQUENCE = 6, | |
74 | BT_CTF_FIELD_TYPE_ID_VARIANT = 7, | |
75 | BT_CTF_FIELD_TYPE_ID_NR, | |
8deee039 PP |
76 | }; |
77 | ||
78 | extern enum bt_ctf_field_type_id bt_ctf_field_type_get_type_id( | |
79 | struct bt_ctf_field_type *field_type); | |
80 | ||
81 | enum bt_ctf_byte_order { | |
086dc475 PP |
82 | BT_CTF_BYTE_ORDER_UNKNOWN = -1, |
83 | BT_CTF_BYTE_ORDER_NATIVE = 0, | |
84 | BT_CTF_BYTE_ORDER_UNSPECIFIED, | |
85 | BT_CTF_BYTE_ORDER_LITTLE_ENDIAN, | |
86 | BT_CTF_BYTE_ORDER_BIG_ENDIAN, | |
87 | BT_CTF_BYTE_ORDER_NETWORK, | |
8deee039 PP |
88 | }; |
89 | ||
90 | enum bt_ctf_string_encoding { | |
086dc475 PP |
91 | BT_CTF_STRING_ENCODING_UNKNOWN = -1, |
92 | BT_CTF_STRING_ENCODING_NONE, | |
93 | BT_CTF_STRING_ENCODING_UTF8, | |
94 | BT_CTF_STRING_ENCODING_ASCII, | |
8deee039 PP |
95 | }; |
96 | ||
97 | /* Pre-2.0 CTF writer compatibility */ | |
98 | #define ctf_string_encoding bt_ctf_string_encoding | |
99 | ||
100 | extern int bt_ctf_field_type_get_alignment( | |
101 | struct bt_ctf_field_type *field_type); | |
102 | ||
103 | extern int bt_ctf_field_type_set_alignment(struct bt_ctf_field_type *field_type, | |
104 | unsigned int alignment); | |
105 | ||
106 | extern enum bt_ctf_byte_order bt_ctf_field_type_get_byte_order( | |
107 | struct bt_ctf_field_type *field_type); | |
108 | ||
109 | extern int bt_ctf_field_type_set_byte_order( | |
110 | struct bt_ctf_field_type *field_type, | |
111 | enum bt_ctf_byte_order byte_order); | |
112 | ||
113 | enum bt_ctf_integer_base { | |
114 | /// Unknown, used for errors. | |
115 | BT_CTF_INTEGER_BASE_UNKNOWN = -1, | |
116 | ||
117 | /// Unspecified by the tracer. | |
118 | BT_CTF_INTEGER_BASE_UNSPECIFIED = 0, | |
119 | ||
120 | /// Binary. | |
121 | BT_CTF_INTEGER_BASE_BINARY = 2, | |
122 | ||
123 | /// Octal. | |
124 | BT_CTF_INTEGER_BASE_OCTAL = 8, | |
125 | ||
126 | /// Decimal. | |
127 | BT_CTF_INTEGER_BASE_DECIMAL = 10, | |
128 | ||
129 | /// Hexadecimal. | |
130 | BT_CTF_INTEGER_BASE_HEXADECIMAL = 16, | |
131 | }; | |
132 | ||
133 | extern struct bt_ctf_field_type *bt_ctf_field_type_integer_create( | |
134 | unsigned int size); | |
135 | ||
136 | extern int bt_ctf_field_type_integer_get_size( | |
137 | struct bt_ctf_field_type *int_field_type); | |
138 | ||
139 | extern int bt_ctf_field_type_integer_set_size( | |
140 | struct bt_ctf_field_type *int_field_type, unsigned int size); | |
141 | ||
d7279670 | 142 | extern bt_ctf_bool bt_ctf_field_type_integer_is_signed( |
8deee039 PP |
143 | struct bt_ctf_field_type *int_field_type); |
144 | ||
145 | /* Pre-2.0 CTF writer compatibility */ | |
146 | static inline | |
147 | int bt_ctf_field_type_integer_get_signed( | |
148 | struct bt_ctf_field_type *int_field_type) | |
149 | { | |
150 | return bt_ctf_field_type_integer_is_signed(int_field_type) ? 1 : 0; | |
151 | } | |
152 | ||
153 | extern int bt_ctf_field_type_integer_set_is_signed( | |
d7279670 | 154 | struct bt_ctf_field_type *int_field_type, bt_ctf_bool is_signed); |
8deee039 PP |
155 | |
156 | /* Pre-2.0 CTF writer compatibility */ | |
157 | static inline | |
158 | int bt_ctf_field_type_integer_set_signed( | |
159 | struct bt_ctf_field_type *int_field_type, int is_signed) | |
160 | { | |
161 | return bt_ctf_field_type_integer_set_is_signed(int_field_type, | |
d7279670 | 162 | is_signed ? BT_CTF_TRUE : BT_CTF_FALSE); |
8deee039 PP |
163 | } |
164 | ||
165 | extern enum bt_ctf_integer_base bt_ctf_field_type_integer_get_base( | |
166 | struct bt_ctf_field_type *int_field_type); | |
167 | ||
168 | extern int bt_ctf_field_type_integer_set_base( | |
169 | struct bt_ctf_field_type *int_field_type, | |
170 | enum bt_ctf_integer_base base); | |
171 | ||
172 | extern enum bt_ctf_string_encoding bt_ctf_field_type_integer_get_encoding( | |
173 | struct bt_ctf_field_type *int_field_type); | |
174 | ||
175 | extern int bt_ctf_field_type_integer_set_encoding( | |
176 | struct bt_ctf_field_type *int_field_type, | |
177 | enum bt_ctf_string_encoding encoding); | |
178 | ||
179 | extern struct bt_ctf_clock_class *bt_ctf_field_type_integer_get_mapped_clock_class( | |
180 | struct bt_ctf_field_type *int_field_type); | |
181 | ||
182 | extern int bt_ctf_field_type_integer_set_mapped_clock_class( | |
183 | struct bt_ctf_field_type *int_field_type, | |
184 | struct bt_ctf_clock_class *clock_class); | |
185 | ||
186 | extern struct bt_ctf_field_type *bt_ctf_field_type_floating_point_create(void); | |
187 | ||
188 | extern int bt_ctf_field_type_floating_point_get_exponent_digits( | |
189 | struct bt_ctf_field_type *float_field_type); | |
190 | ||
191 | extern int bt_ctf_field_type_floating_point_set_exponent_digits( | |
192 | struct bt_ctf_field_type *float_field_type, | |
193 | unsigned int exponent_size); | |
194 | ||
195 | extern int bt_ctf_field_type_floating_point_get_mantissa_digits( | |
196 | struct bt_ctf_field_type *float_field_type); | |
197 | ||
198 | extern int bt_ctf_field_type_floating_point_set_mantissa_digits( | |
199 | struct bt_ctf_field_type *float_field_type, | |
200 | unsigned int mantissa_sign_size); | |
201 | ||
202 | extern struct bt_ctf_field_type *bt_ctf_field_type_enumeration_create( | |
203 | struct bt_ctf_field_type *int_field_type); | |
204 | ||
205 | extern | |
206 | struct bt_ctf_field_type *bt_ctf_field_type_enumeration_get_container_field_type( | |
207 | struct bt_ctf_field_type *enum_field_type); | |
208 | ||
209 | extern int64_t bt_ctf_field_type_enumeration_get_mapping_count( | |
210 | struct bt_ctf_field_type *enum_field_type); | |
211 | ||
212 | extern int bt_ctf_field_type_enumeration_signed_get_mapping_by_index( | |
213 | struct bt_ctf_field_type *enum_field_type, uint64_t index, | |
214 | const char **name, int64_t *range_begin, int64_t *range_end); | |
215 | ||
216 | extern int bt_ctf_field_type_enumeration_unsigned_get_mapping_by_index( | |
217 | struct bt_ctf_field_type *enum_field_type, uint64_t index, | |
218 | const char **name, uint64_t *range_begin, | |
219 | uint64_t *range_end); | |
220 | ||
221 | extern int bt_ctf_field_type_enumeration_signed_add_mapping( | |
222 | struct bt_ctf_field_type *enum_field_type, | |
223 | const char *name, int64_t range_begin, int64_t range_end); | |
224 | ||
225 | extern int bt_ctf_field_type_enumeration_unsigned_add_mapping( | |
226 | struct bt_ctf_field_type *enum_field_type, | |
227 | const char *name, uint64_t range_begin, uint64_t range_end); | |
228 | ||
229 | /* Pre-2.0 CTF writer compatibility */ | |
230 | static inline | |
231 | int bt_ctf_field_type_enumeration_add_mapping( | |
232 | struct bt_ctf_field_type *enumeration, const char *name, | |
233 | int64_t range_start, int64_t range_end) | |
234 | { | |
235 | return bt_ctf_field_type_enumeration_signed_add_mapping(enumeration, | |
236 | name, range_start, range_end); | |
237 | } | |
238 | ||
239 | extern struct bt_ctf_field_type *bt_ctf_field_type_string_create(void); | |
240 | ||
241 | extern enum bt_ctf_string_encoding bt_ctf_field_type_string_get_encoding( | |
242 | struct bt_ctf_field_type *string_field_type); | |
243 | ||
244 | extern int bt_ctf_field_type_string_set_encoding( | |
245 | struct bt_ctf_field_type *string_field_type, | |
246 | enum bt_ctf_string_encoding encoding); | |
247 | ||
248 | extern struct bt_ctf_field_type *bt_ctf_field_type_structure_create(void); | |
249 | ||
250 | extern int64_t bt_ctf_field_type_structure_get_field_count( | |
251 | struct bt_ctf_field_type *struct_field_type); | |
252 | ||
253 | extern int bt_ctf_field_type_structure_get_field_by_index( | |
254 | struct bt_ctf_field_type *struct_field_type, | |
255 | const char **field_name, struct bt_ctf_field_type **field_type, | |
256 | uint64_t index); | |
257 | ||
258 | /* Pre-2.0 CTF writer compatibility */ | |
259 | static inline | |
260 | int bt_ctf_field_type_structure_get_field(struct bt_ctf_field_type *structure, | |
261 | const char **field_name, struct bt_ctf_field_type **field_type, | |
262 | int index) | |
263 | { | |
264 | return bt_ctf_field_type_structure_get_field_by_index(structure, | |
265 | field_name, field_type, (uint64_t) index); | |
266 | } | |
267 | ||
268 | extern | |
269 | struct bt_ctf_field_type *bt_ctf_field_type_structure_get_field_type_by_name( | |
270 | struct bt_ctf_field_type *struct_field_type, | |
271 | const char *field_name); | |
272 | ||
273 | extern int bt_ctf_field_type_structure_add_field( | |
274 | struct bt_ctf_field_type *struct_field_type, | |
275 | struct bt_ctf_field_type *field_type, | |
276 | const char *field_name); | |
277 | ||
278 | extern struct bt_ctf_field_type *bt_ctf_field_type_array_create( | |
279 | struct bt_ctf_field_type *element_field_type, | |
280 | unsigned int length); | |
281 | ||
282 | extern struct bt_ctf_field_type *bt_ctf_field_type_array_get_element_field_type( | |
283 | struct bt_ctf_field_type *array_field_type); | |
284 | ||
285 | extern int64_t bt_ctf_field_type_array_get_length( | |
286 | struct bt_ctf_field_type *array_field_type); | |
287 | ||
288 | extern struct bt_ctf_field_type *bt_ctf_field_type_sequence_create( | |
289 | struct bt_ctf_field_type *element_field_type, | |
290 | const char *length_name); | |
291 | ||
292 | extern struct bt_ctf_field_type *bt_ctf_field_type_sequence_get_element_field_type( | |
293 | struct bt_ctf_field_type *sequence_field_type); | |
294 | ||
295 | extern const char *bt_ctf_field_type_sequence_get_length_field_name( | |
296 | struct bt_ctf_field_type *sequence_field_type); | |
297 | ||
298 | extern struct bt_ctf_field_type *bt_ctf_field_type_variant_create( | |
299 | struct bt_ctf_field_type *tag_field_type, | |
300 | const char *tag_name); | |
301 | ||
302 | extern struct bt_ctf_field_type *bt_ctf_field_type_variant_get_tag_field_type( | |
303 | struct bt_ctf_field_type *variant_field_type); | |
304 | ||
305 | extern const char *bt_ctf_field_type_variant_get_tag_name( | |
306 | struct bt_ctf_field_type *variant_field_type); | |
307 | ||
308 | extern int bt_ctf_field_type_variant_set_tag_name( | |
309 | struct bt_ctf_field_type *variant_field_type, | |
310 | const char *tag_name); | |
311 | ||
312 | extern int64_t bt_ctf_field_type_variant_get_field_count( | |
313 | struct bt_ctf_field_type *variant_field_type); | |
314 | ||
315 | extern int bt_ctf_field_type_variant_get_field_by_index( | |
316 | struct bt_ctf_field_type *variant_field_type, | |
317 | const char **field_name, | |
318 | struct bt_ctf_field_type **field_type, uint64_t index); | |
319 | ||
320 | extern | |
321 | struct bt_ctf_field_type *bt_ctf_field_type_variant_get_field_type_by_name( | |
322 | struct bt_ctf_field_type *variant_field_type, | |
323 | const char *field_name); | |
324 | ||
325 | extern | |
326 | struct bt_ctf_field_type *bt_ctf_field_type_variant_get_field_type_from_tag( | |
327 | struct bt_ctf_field_type *variant_field_type, | |
328 | struct bt_ctf_field *tag_field); | |
329 | ||
330 | extern int bt_ctf_field_type_variant_add_field( | |
331 | struct bt_ctf_field_type *variant_field_type, | |
332 | struct bt_ctf_field_type *field_type, | |
333 | const char *field_name); | |
334 | ||
335 | #ifdef __cplusplus | |
336 | } | |
337 | #endif | |
338 | ||
3fd40f46 | 339 | #endif /* BABELTRACE2_CTF_WRITER_FIELD_TYPES_H */ |