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