Commit | Line | Data |
---|---|---|
adc315b8 JG |
1 | #ifndef BABELTRACE_CTF_IR_EVENT_TYPES_INTERNAL_H |
2 | #define BABELTRACE_CTF_IR_EVENT_TYPES_INTERNAL_H | |
273b65be JG |
3 | |
4 | /* | |
adc315b8 | 5 | * BabelTrace - CTF IR: Event 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> |
273b65be | 34 | #include <babeltrace/babeltrace-internal.h> |
83509119 | 35 | #include <babeltrace/object-internal.h> |
273b65be JG |
36 | #include <babeltrace/types.h> |
37 | #include <babeltrace/ctf/events.h> | |
38 | #include <glib.h> | |
39 | ||
b75277fb JG |
40 | typedef void (*type_freeze_func)(struct bt_ctf_field_type *); |
41 | typedef int (*type_serialize_func)(struct bt_ctf_field_type *, | |
273b65be JG |
42 | struct metadata_context *); |
43 | ||
6b64f185 JG |
44 | enum bt_ctf_node { |
45 | CTF_NODE_UNKNOWN = -1, | |
46 | CTF_NODE_ENV = 0, | |
47 | CTF_NODE_TRACE_PACKET_HEADER = 1, | |
48 | CTF_NODE_STREAM_PACKET_CONTEXT = 2, | |
49 | CTF_NODE_STREAM_EVENT_HEADER = 3, | |
50 | CTF_NODE_STREAM_EVENT_CONTEXT = 4, | |
51 | CTF_NODE_EVENT_CONTEXT = 5, | |
52 | CTF_NODE_EVENT_FIELDS = 6, | |
53 | }; | |
54 | ||
55 | struct bt_ctf_field_path { | |
56 | enum bt_ctf_node root; | |
57 | /* | |
58 | * Array of integers (int) indicating the index in either | |
59 | * structures or variants that make-up the path to a field. | |
60 | */ | |
61 | GArray *path_indexes; | |
62 | }; | |
63 | ||
273b65be | 64 | struct bt_ctf_field_type { |
83509119 | 65 | struct bt_object base; |
273b65be JG |
66 | struct bt_declaration *declaration; |
67 | type_freeze_func freeze; | |
68 | type_serialize_func serialize; | |
69 | /* | |
70 | * A type can't be modified once it is added to an event or after a | |
71 | * a field has been instanciated from it. | |
72 | */ | |
73 | int frozen; | |
74 | }; | |
75 | ||
76 | struct bt_ctf_field_type_integer { | |
77 | struct bt_ctf_field_type parent; | |
78 | struct declaration_integer declaration; | |
6cfb906f | 79 | struct bt_ctf_clock *mapped_clock; |
273b65be JG |
80 | }; |
81 | ||
82 | struct enumeration_mapping { | |
b92ddaaa JG |
83 | union { |
84 | uint64_t _unsigned; | |
85 | int64_t _signed; | |
86 | } range_start; | |
87 | ||
88 | union { | |
89 | uint64_t _unsigned; | |
90 | int64_t _signed; | |
91 | } range_end; | |
273b65be JG |
92 | GQuark string; |
93 | }; | |
94 | ||
95 | struct bt_ctf_field_type_enumeration { | |
96 | struct bt_ctf_field_type parent; | |
97 | struct bt_ctf_field_type *container; | |
98 | GPtrArray *entries; /* Array of pointers to struct enum_mapping */ | |
99 | struct declaration_enum declaration; | |
100 | }; | |
101 | ||
102 | struct bt_ctf_field_type_floating_point { | |
103 | struct bt_ctf_field_type parent; | |
104 | struct declaration_float declaration; | |
105 | struct declaration_integer sign; | |
106 | struct declaration_integer mantissa; | |
107 | struct declaration_integer exp; | |
108 | }; | |
109 | ||
110 | struct structure_field { | |
111 | GQuark name; | |
112 | struct bt_ctf_field_type *type; | |
113 | }; | |
114 | ||
115 | struct bt_ctf_field_type_structure { | |
116 | struct bt_ctf_field_type parent; | |
117 | GHashTable *field_name_to_index; | |
118 | GPtrArray *fields; /* Array of pointers to struct structure_field */ | |
24724933 | 119 | struct declaration_struct declaration; |
273b65be JG |
120 | }; |
121 | ||
122 | struct bt_ctf_field_type_variant { | |
123 | struct bt_ctf_field_type parent; | |
124 | GString *tag_name; | |
125 | struct bt_ctf_field_type_enumeration *tag; | |
4a1e8671 | 126 | struct bt_ctf_field_path *tag_path; |
273b65be JG |
127 | GHashTable *field_name_to_index; |
128 | GPtrArray *fields; /* Array of pointers to struct structure_field */ | |
129 | struct declaration_variant declaration; | |
130 | }; | |
131 | ||
132 | struct bt_ctf_field_type_array { | |
133 | struct bt_ctf_field_type parent; | |
134 | struct bt_ctf_field_type *element_type; | |
135 | unsigned int length; /* Number of elements */ | |
136 | struct declaration_array declaration; | |
137 | }; | |
138 | ||
139 | struct bt_ctf_field_type_sequence { | |
140 | struct bt_ctf_field_type parent; | |
141 | struct bt_ctf_field_type *element_type; | |
142 | GString *length_field_name; | |
aa4e271c | 143 | struct bt_ctf_field_path *length_field_path; |
273b65be JG |
144 | struct declaration_sequence declaration; |
145 | }; | |
146 | ||
147 | struct bt_ctf_field_type_string { | |
148 | struct bt_ctf_field_type parent; | |
149 | struct declaration_string declaration; | |
150 | }; | |
151 | ||
152 | BT_HIDDEN | |
153 | void bt_ctf_field_type_freeze(struct bt_ctf_field_type *type); | |
154 | ||
155 | BT_HIDDEN | |
b92ddaaa JG |
156 | struct bt_ctf_field_type *bt_ctf_field_type_variant_get_field_type_signed( |
157 | struct bt_ctf_field_type_variant *variant, int64_t tag_value); | |
273b65be JG |
158 | |
159 | BT_HIDDEN | |
b92ddaaa JG |
160 | struct bt_ctf_field_type *bt_ctf_field_type_variant_get_field_type_unsigned( |
161 | struct bt_ctf_field_type_variant *variant, uint64_t tag_value); | |
273b65be JG |
162 | |
163 | BT_HIDDEN | |
164 | int bt_ctf_field_type_serialize(struct bt_ctf_field_type *type, | |
165 | struct metadata_context *context); | |
166 | ||
9ce21c30 JG |
167 | BT_HIDDEN |
168 | int bt_ctf_field_type_validate(struct bt_ctf_field_type *type); | |
169 | ||
e5958c30 JG |
170 | BT_HIDDEN |
171 | const char *bt_ctf_field_type_enumeration_get_mapping_name_unsigned( | |
172 | struct bt_ctf_field_type_enumeration *enumeration_type, | |
173 | uint64_t value); | |
174 | ||
175 | BT_HIDDEN | |
176 | const char *bt_ctf_field_type_enumeration_get_mapping_name_signed( | |
177 | struct bt_ctf_field_type_enumeration *enumeration_type, | |
178 | int64_t value); | |
179 | ||
c35a1669 JG |
180 | /* Override field type's byte order only if it is set to "native" */ |
181 | BT_HIDDEN | |
182 | void bt_ctf_field_type_set_native_byte_order( | |
183 | struct bt_ctf_field_type *type, int byte_order); | |
24724933 JG |
184 | |
185 | /* Deep copy a field type */ | |
186 | BT_HIDDEN | |
187 | struct bt_ctf_field_type *bt_ctf_field_type_copy( | |
188 | struct bt_ctf_field_type *type); | |
189 | ||
6b64f185 JG |
190 | BT_HIDDEN |
191 | struct bt_ctf_field_path *bt_ctf_field_path_create(void); | |
192 | ||
193 | BT_HIDDEN | |
194 | struct bt_ctf_field_path *bt_ctf_field_path_copy( | |
195 | struct bt_ctf_field_path *path); | |
196 | ||
197 | BT_HIDDEN | |
198 | void bt_ctf_field_path_destroy(struct bt_ctf_field_path *path); | |
39a5e0db JG |
199 | |
200 | BT_HIDDEN | |
201 | int bt_ctf_field_type_structure_get_field_name_index( | |
202 | struct bt_ctf_field_type *structure, const char *name); | |
736133f1 | 203 | |
5cec03e4 JG |
204 | /* Replace an existing field's type in a structure */ |
205 | BT_HIDDEN | |
206 | int bt_ctf_field_type_structure_set_field_index( | |
207 | struct bt_ctf_field_type *structure, | |
208 | struct bt_ctf_field_type *field, int index); | |
209 | ||
736133f1 JG |
210 | BT_HIDDEN |
211 | int bt_ctf_field_type_variant_get_field_name_index( | |
212 | struct bt_ctf_field_type *variant, const char *name); | |
aa4e271c JG |
213 | |
214 | BT_HIDDEN | |
215 | int bt_ctf_field_type_sequence_set_length_field_path( | |
216 | struct bt_ctf_field_type *type, | |
217 | struct bt_ctf_field_path *path); | |
4a1e8671 | 218 | |
32fe3f28 PP |
219 | BT_HIDDEN |
220 | struct bt_ctf_field_path *bt_ctf_field_type_sequence_get_length_field_path( | |
221 | struct bt_ctf_field_type *type); | |
222 | ||
4a1e8671 JG |
223 | BT_HIDDEN |
224 | int bt_ctf_field_type_variant_set_tag_field_path(struct bt_ctf_field_type *type, | |
225 | struct bt_ctf_field_path *path); | |
3f39933a | 226 | |
32fe3f28 PP |
227 | BT_HIDDEN |
228 | struct bt_ctf_field_path *bt_ctf_field_type_variant_get_tag_field_path( | |
229 | struct bt_ctf_field_type *type); | |
230 | ||
3f39933a JG |
231 | BT_HIDDEN |
232 | int bt_ctf_field_type_variant_set_tag(struct bt_ctf_field_type *type, | |
233 | struct bt_ctf_field_type *tag); | |
234 | ||
5cec03e4 JG |
235 | /* Replace an existing field's type in a variant */ |
236 | BT_HIDDEN | |
237 | int bt_ctf_field_type_variant_set_field_index( | |
238 | struct bt_ctf_field_type *variant, | |
239 | struct bt_ctf_field_type *field, int index); | |
240 | ||
626e93aa PP |
241 | BT_HIDDEN |
242 | int bt_ctf_field_type_array_set_element_type(struct bt_ctf_field_type *array, | |
243 | struct bt_ctf_field_type *element_type); | |
244 | ||
245 | BT_HIDDEN | |
246 | int bt_ctf_field_type_sequence_set_element_type(struct bt_ctf_field_type *array, | |
247 | struct bt_ctf_field_type *element_type); | |
248 | ||
adc315b8 | 249 | #endif /* BABELTRACE_CTF_IR_EVENT_TYPES_INTERNAL_H */ |