Remove Babeltrace 1 files and reorganize the tree
[babeltrace.git] / include / babeltrace / ctf-ir / field-types-internal.h
CommitLineData
2e33ac5a
PP
1#ifndef BABELTRACE_CTF_IR_FIELD_TYPES_INTERNAL_H
2#define BABELTRACE_CTF_IR_FIELD_TYPES_INTERNAL_H
273b65be
JG
3
4/*
2e33ac5a 5 * BabelTrace - CTF IR: Event field types internal
273b65be 6 *
de9dd397 7 * Copyright 2013, 2014 Jérémie Galarneau <jeremie.galarneau@efficios.com>
273b65be
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
30#include <babeltrace/ctf-writer/event-types.h>
273b65be
JG
31#include <babeltrace/ctf-writer/event-fields.h>
32#include <babeltrace/ctf-writer/writer.h>
bc37ae52 33#include <babeltrace/ctf-ir/trace-internal.h>
ac0c6bdd 34#include <babeltrace/ctf-ir/clock-class.h>
273b65be 35#include <babeltrace/babeltrace-internal.h>
83509119 36#include <babeltrace/object-internal.h>
273b65be
JG
37#include <glib.h>
38
b75277fb
JG
39typedef void (*type_freeze_func)(struct bt_ctf_field_type *);
40typedef int (*type_serialize_func)(struct bt_ctf_field_type *,
273b65be
JG
41 struct metadata_context *);
42
43struct bt_ctf_field_type {
83509119 44 struct bt_object base;
dc3fffef
PP
45 enum bt_ctf_type_id id;
46 unsigned int alignment;
273b65be
JG
47 type_freeze_func freeze;
48 type_serialize_func serialize;
49 /*
50 * A type can't be modified once it is added to an event or after a
51 * a field has been instanciated from it.
52 */
53 int frozen;
81e36fac
PP
54
55 /*
56 * This flag indicates if the field type is valid. A valid
57 * field type is _always_ frozen. All the nested field types of
58 * a valid field type are also valid (and thus frozen).
59 */
60 int valid;
273b65be
JG
61};
62
63struct bt_ctf_field_type_integer {
64 struct bt_ctf_field_type parent;
ac0c6bdd 65 struct bt_ctf_clock_class *mapped_clock;
445c3471 66 enum bt_ctf_byte_order user_byte_order;
dc3fffef
PP
67 bool is_signed;
68 unsigned int size;
69 enum bt_ctf_integer_base base;
70 enum bt_ctf_string_encoding encoding;
273b65be
JG
71};
72
73struct enumeration_mapping {
b92ddaaa
JG
74 union {
75 uint64_t _unsigned;
76 int64_t _signed;
77 } range_start;
78
79 union {
80 uint64_t _unsigned;
81 int64_t _signed;
82 } range_end;
273b65be
JG
83 GQuark string;
84};
85
86struct bt_ctf_field_type_enumeration {
87 struct bt_ctf_field_type parent;
88 struct bt_ctf_field_type *container;
db8ef253 89 GPtrArray *entries; /* Array of ptrs to struct enumeration_mapping */
d49e1284 90 /* Only set during validation. */
96e8f959
MD
91 bool has_overlapping_ranges;
92};
93
d49e1284 94enum bt_ctf_field_type_enumeration_mapping_iterator_type {
96e8f959
MD
95 ITERATOR_BY_NAME,
96 ITERATOR_BY_SIGNED_VALUE,
97 ITERATOR_BY_UNSIGNED_VALUE,
98};
99
100struct bt_ctf_field_type_enumeration_mapping_iterator {
101 struct bt_object base;
102 struct bt_ctf_field_type_enumeration *enumeration_type;
d49e1284 103 enum bt_ctf_field_type_enumeration_mapping_iterator_type type;
96e8f959
MD
104 int index;
105 union {
106 GQuark name_quark;
107 int64_t signed_value;
108 uint64_t unsigned_value;
109 } u;
273b65be
JG
110};
111
112struct bt_ctf_field_type_floating_point {
113 struct bt_ctf_field_type parent;
445c3471 114 enum bt_ctf_byte_order user_byte_order;
dc3fffef
PP
115 unsigned int exp_dig;
116 unsigned int mant_dig;
273b65be
JG
117};
118
119struct structure_field {
120 GQuark name;
121 struct bt_ctf_field_type *type;
122};
123
124struct bt_ctf_field_type_structure {
125 struct bt_ctf_field_type parent;
126 GHashTable *field_name_to_index;
127 GPtrArray *fields; /* Array of pointers to struct structure_field */
273b65be
JG
128};
129
130struct bt_ctf_field_type_variant {
131 struct bt_ctf_field_type parent;
132 GString *tag_name;
133 struct bt_ctf_field_type_enumeration *tag;
b011f6b0 134 struct bt_ctf_field_path *tag_field_path;
273b65be
JG
135 GHashTable *field_name_to_index;
136 GPtrArray *fields; /* Array of pointers to struct structure_field */
273b65be
JG
137};
138
139struct bt_ctf_field_type_array {
140 struct bt_ctf_field_type parent;
141 struct bt_ctf_field_type *element_type;
142 unsigned int length; /* Number of elements */
273b65be
JG
143};
144
145struct bt_ctf_field_type_sequence {
146 struct bt_ctf_field_type parent;
147 struct bt_ctf_field_type *element_type;
148 GString *length_field_name;
aa4e271c 149 struct bt_ctf_field_path *length_field_path;
273b65be
JG
150};
151
152struct bt_ctf_field_type_string {
153 struct bt_ctf_field_type parent;
dc3fffef 154 enum bt_ctf_string_encoding encoding;
273b65be
JG
155};
156
157BT_HIDDEN
158void bt_ctf_field_type_freeze(struct bt_ctf_field_type *type);
159
160BT_HIDDEN
b92ddaaa
JG
161struct bt_ctf_field_type *bt_ctf_field_type_variant_get_field_type_signed(
162 struct bt_ctf_field_type_variant *variant, int64_t tag_value);
273b65be
JG
163
164BT_HIDDEN
b92ddaaa
JG
165struct bt_ctf_field_type *bt_ctf_field_type_variant_get_field_type_unsigned(
166 struct bt_ctf_field_type_variant *variant, uint64_t tag_value);
273b65be
JG
167
168BT_HIDDEN
169int bt_ctf_field_type_serialize(struct bt_ctf_field_type *type,
170 struct metadata_context *context);
171
9ce21c30
JG
172BT_HIDDEN
173int bt_ctf_field_type_validate(struct bt_ctf_field_type *type);
174
39a5e0db
JG
175BT_HIDDEN
176int bt_ctf_field_type_structure_get_field_name_index(
177 struct bt_ctf_field_type *structure, const char *name);
736133f1 178
5cec03e4
JG
179/* Replace an existing field's type in a structure */
180BT_HIDDEN
181int bt_ctf_field_type_structure_set_field_index(
182 struct bt_ctf_field_type *structure,
183 struct bt_ctf_field_type *field, int index);
184
736133f1
JG
185BT_HIDDEN
186int bt_ctf_field_type_variant_get_field_name_index(
187 struct bt_ctf_field_type *variant, const char *name);
aa4e271c
JG
188
189BT_HIDDEN
190int bt_ctf_field_type_sequence_set_length_field_path(
191 struct bt_ctf_field_type *type,
192 struct bt_ctf_field_path *path);
4a1e8671
JG
193
194BT_HIDDEN
195int bt_ctf_field_type_variant_set_tag_field_path(struct bt_ctf_field_type *type,
196 struct bt_ctf_field_path *path);
3f39933a
JG
197
198BT_HIDDEN
4b5fcb78
PP
199int bt_ctf_field_type_variant_set_tag_field_type(struct bt_ctf_field_type *type,
200 struct bt_ctf_field_type *tag_type);
3f39933a 201
5cec03e4
JG
202/* Replace an existing field's type in a variant */
203BT_HIDDEN
204int bt_ctf_field_type_variant_set_field_index(
205 struct bt_ctf_field_type *variant,
206 struct bt_ctf_field_type *field, int index);
207
626e93aa
PP
208BT_HIDDEN
209int bt_ctf_field_type_array_set_element_type(struct bt_ctf_field_type *array,
210 struct bt_ctf_field_type *element_type);
211
212BT_HIDDEN
213int bt_ctf_field_type_sequence_set_element_type(struct bt_ctf_field_type *array,
214 struct bt_ctf_field_type *element_type);
215
09840de5
PP
216BT_HIDDEN
217int bt_ctf_field_type_get_field_count(struct bt_ctf_field_type *type);
218
219BT_HIDDEN
220struct bt_ctf_field_type *bt_ctf_field_type_get_field_at_index(
221 struct bt_ctf_field_type *type, int index);
222
223BT_HIDDEN
224int bt_ctf_field_type_get_field_index(struct bt_ctf_field_type *type,
225 const char *name);
226
2e33ac5a 227#endif /* BABELTRACE_CTF_IR_FIELD_TYPES_INTERNAL_H */
This page took 0.044605 seconds and 4 git commands to generate.