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