Commit | Line | Data |
---|---|---|
5cd6d0e5 | 1 | /* |
0235b0db MJ |
2 | * SPDX-License-Identifier: MIT |
3 | * | |
e2f7325d | 4 | * Copyright 2017-2018 Philippe Proulx <pproulx@efficios.com> |
5cd6d0e5 | 5 | * Copyright 2013, 2014 Jérémie Galarneau <jeremie.galarneau@efficios.com> |
5cd6d0e5 PP |
6 | */ |
7 | ||
0235b0db MJ |
8 | #ifndef BABELTRACE_TRACE_IR_FIELD_CLASSES_INTERNAL_H |
9 | #define BABELTRACE_TRACE_IR_FIELD_CLASSES_INTERNAL_H | |
10 | ||
d98421f2 | 11 | #include "lib/assert-cond.h" |
3fadfbc0 MJ |
12 | #include <babeltrace2/trace-ir/clock-class.h> |
13 | #include <babeltrace2/trace-ir/field-class.h> | |
91d81473 | 14 | #include "common/macros.h" |
45c51519 | 15 | #include "common/common.h" |
578e048b | 16 | #include "lib/object.h" |
3fadfbc0 | 17 | #include <babeltrace2/types.h> |
c4f23e30 | 18 | #include <stdbool.h> |
5cd6d0e5 PP |
19 | #include <stdint.h> |
20 | #include <glib.h> | |
21 | ||
5cd6d0e5 PP |
22 | #define BT_FIELD_CLASS_ENUM_MAPPING_AT_INDEX(_fc, _index) \ |
23 | (&g_array_index(((struct bt_field_class_enumeration *) (_fc))->mappings, \ | |
24 | struct bt_field_class_enumeration_mapping, (_index))) | |
25 | ||
26 | #define BT_FIELD_CLASS_ENUM_MAPPING_RANGE_AT_INDEX(_mapping, _index) \ | |
27 | (&g_array_index((_mapping)->ranges, \ | |
28 | struct bt_field_class_enumeration_mapping_range, (_index))) | |
29 | ||
30 | struct bt_field; | |
31 | struct bt_field_class; | |
32 | ||
33 | struct bt_field_class { | |
34 | struct bt_object base; | |
864cad70 | 35 | enum bt_field_class_type type; |
5cd6d0e5 PP |
36 | bool frozen; |
37 | ||
c6962c96 PP |
38 | /* Owned by this */ |
39 | struct bt_value *user_attributes; | |
40 | ||
5cd6d0e5 | 41 | /* |
bdb288b3 PP |
42 | * This flag indicates whether or not this field class is part |
43 | * of a trace class. | |
5cd6d0e5 | 44 | */ |
862ca4ed | 45 | bool part_of_trace_class; |
5cd6d0e5 PP |
46 | }; |
47 | ||
5cebbe7f PP |
48 | struct bt_field_class_bool { |
49 | struct bt_field_class common; | |
50 | }; | |
51 | ||
1094efa4 PP |
52 | struct bt_field_class_bit_array { |
53 | struct bt_field_class common; | |
54 | uint64_t length; | |
55 | }; | |
56 | ||
5cd6d0e5 PP |
57 | struct bt_field_class_integer { |
58 | struct bt_field_class common; | |
59 | ||
60 | /* | |
61 | * Value range of fields built from this integer field class: | |
62 | * this is an equivalent integer size in bits. More formally, | |
63 | * `range` is `n` in: | |
64 | * | |
65 | * Unsigned range: [0, 2^n - 1] | |
66 | * Signed range: [-2^(n - 1), 2^(n - 1) - 1] | |
67 | */ | |
68 | uint64_t range; | |
69 | ||
70 | enum bt_field_class_integer_preferred_display_base base; | |
71 | }; | |
72 | ||
5cd6d0e5 PP |
73 | struct bt_field_class_enumeration_mapping { |
74 | GString *label; | |
75 | ||
45c51519 PP |
76 | /* Owner by this */ |
77 | const struct bt_integer_range_set *range_set; | |
5cd6d0e5 PP |
78 | }; |
79 | ||
9c08c816 PP |
80 | struct bt_field_class_enumeration_unsigned_mapping; |
81 | struct bt_field_class_enumeration_signed_mapping; | |
8f3ccfbc | 82 | |
5cd6d0e5 PP |
83 | struct bt_field_class_enumeration { |
84 | struct bt_field_class_integer common; | |
85 | ||
86 | /* Array of `struct bt_field_class_enumeration_mapping *` */ | |
87 | GArray *mappings; | |
88 | ||
89 | /* | |
90 | * This is an array of `const char *` which acts as a temporary | |
91 | * (potentially growing) buffer for | |
9c08c816 | 92 | * bt_field_class_enumeration_unsigned_get_mapping_labels_for_value() |
5cd6d0e5 | 93 | * and |
9c08c816 | 94 | * bt_field_class_enumeration_signed_get_mapping_labels_for_value(). |
5cd6d0e5 PP |
95 | * |
96 | * The actual strings are owned by the mappings above. | |
97 | */ | |
98 | GPtrArray *label_buf; | |
99 | }; | |
100 | ||
101 | struct bt_field_class_real { | |
102 | struct bt_field_class common; | |
5cd6d0e5 PP |
103 | }; |
104 | ||
105 | struct bt_field_class_string { | |
106 | struct bt_field_class common; | |
107 | }; | |
108 | ||
109 | /* A named field class is a (name, field class) pair */ | |
110 | struct bt_named_field_class { | |
111 | GString *name; | |
112 | ||
c6962c96 PP |
113 | /* Owned by this */ |
114 | struct bt_value *user_attributes; | |
115 | ||
5cd6d0e5 PP |
116 | /* Owned by this */ |
117 | struct bt_field_class *fc; | |
1e6fd1d7 PP |
118 | |
119 | bool frozen; | |
5cd6d0e5 PP |
120 | }; |
121 | ||
1e6fd1d7 PP |
122 | struct bt_field_class_structure_member; |
123 | struct bt_field_class_variant_option; | |
de821fe5 PP |
124 | struct bt_field_class_variant_with_selector_field_integer_unsigned_option; |
125 | struct bt_field_class_variant_with_selector_field_integer_signed_option; | |
1e6fd1d7 | 126 | |
5cd6d0e5 PP |
127 | struct bt_field_class_named_field_class_container { |
128 | struct bt_field_class common; | |
129 | ||
130 | /* | |
131 | * Key: `const char *`, not owned by this (owned by named field | |
45c51519 | 132 | * class objects contained in `named_fcs` below). |
5cd6d0e5 PP |
133 | */ |
134 | GHashTable *name_to_index; | |
135 | ||
45c51519 PP |
136 | /* Array of `struct bt_named_field_class *` */ |
137 | GPtrArray *named_fcs; | |
5cd6d0e5 PP |
138 | }; |
139 | ||
140 | struct bt_field_class_structure { | |
141 | struct bt_field_class_named_field_class_container common; | |
142 | }; | |
143 | ||
144 | struct bt_field_class_array { | |
145 | struct bt_field_class common; | |
146 | ||
147 | /* Owned by this */ | |
148 | struct bt_field_class *element_fc; | |
149 | }; | |
150 | ||
9c08c816 | 151 | struct bt_field_class_array_static { |
5cd6d0e5 PP |
152 | struct bt_field_class_array common; |
153 | uint64_t length; | |
154 | }; | |
155 | ||
9c08c816 | 156 | struct bt_field_class_array_dynamic { |
5cd6d0e5 PP |
157 | struct bt_field_class_array common; |
158 | ||
b38aea74 | 159 | /* Owned by this */ |
5cd6d0e5 PP |
160 | struct bt_field_class *length_fc; |
161 | ||
162 | /* Owned by this */ | |
163 | struct bt_field_path *length_field_path; | |
164 | }; | |
165 | ||
b38aea74 PP |
166 | struct bt_field_class_option { |
167 | struct bt_field_class common; | |
168 | ||
169 | /* Owned by this */ | |
170 | struct bt_field_class *content_fc; | |
0aa006b7 PP |
171 | }; |
172 | ||
de821fe5 | 173 | struct bt_field_class_option_with_selector_field { |
0aa006b7 | 174 | struct bt_field_class_option common; |
b38aea74 PP |
175 | |
176 | /* Owned by this */ | |
177 | struct bt_field_class *selector_fc; | |
178 | ||
179 | /* Owned by this */ | |
180 | struct bt_field_path *selector_field_path; | |
181 | }; | |
182 | ||
de821fe5 PP |
183 | struct bt_field_class_option_with_selector_field_bool { |
184 | struct bt_field_class_option_with_selector_field common; | |
0aa006b7 PP |
185 | |
186 | /* Owned by this */ | |
187 | bool sel_is_reversed; | |
188 | }; | |
189 | ||
de821fe5 PP |
190 | struct bt_field_class_option_with_selector_field_integer { |
191 | struct bt_field_class_option_with_selector_field common; | |
0aa006b7 PP |
192 | |
193 | /* Owned by this */ | |
194 | const struct bt_integer_range_set *range_set; | |
195 | }; | |
196 | ||
45c51519 | 197 | /* Variant FC (with selector) option: named field class + range set */ |
de821fe5 | 198 | struct bt_field_class_variant_with_selector_field_option { |
45c51519 PP |
199 | struct bt_named_field_class common; |
200 | ||
201 | /* Owned by this */ | |
202 | const struct bt_integer_range_set *range_set; | |
203 | }; | |
204 | ||
5cd6d0e5 | 205 | struct bt_field_class_variant { |
45c51519 PP |
206 | /* |
207 | * Depending on the variant field class type, the contained | |
208 | * named field classes are of type | |
209 | * `struct bt_named_field_class *` if the variant field class | |
210 | * doesn't have a selector, or | |
de821fe5 | 211 | * `struct bt_field_class_variant_with_selector_field_option *` |
45c51519 PP |
212 | * if it has. |
213 | */ | |
5cd6d0e5 | 214 | struct bt_field_class_named_field_class_container common; |
45c51519 | 215 | }; |
5cd6d0e5 | 216 | |
de821fe5 | 217 | struct bt_field_class_variant_with_selector_field { |
45c51519 PP |
218 | struct bt_field_class_variant common; |
219 | ||
220 | /* | |
221 | * Owned by this, but never dereferenced: only use to find it | |
222 | * elsewhere. | |
223 | */ | |
224 | const struct bt_field_class *selector_fc; | |
5cd6d0e5 PP |
225 | |
226 | /* Owned by this */ | |
227 | struct bt_field_path *selector_field_path; | |
228 | }; | |
229 | ||
5cd6d0e5 | 230 | BT_HIDDEN |
40f4ba76 | 231 | void _bt_field_class_freeze(const struct bt_field_class *field_class); |
5cd6d0e5 PP |
232 | |
233 | #ifdef BT_DEV_MODE | |
234 | # define bt_field_class_freeze _bt_field_class_freeze | |
235 | #else | |
1d7f91d1 | 236 | # define bt_field_class_freeze(_fc) ((void) _fc) |
5cd6d0e5 PP |
237 | #endif |
238 | ||
1e6fd1d7 PP |
239 | BT_HIDDEN |
240 | void _bt_named_field_class_freeze(const struct bt_named_field_class *named_fc); | |
241 | ||
242 | #ifdef BT_DEV_MODE | |
243 | # define bt_named_field_class_freeze _bt_named_field_class_freeze | |
244 | #else | |
1d7f91d1 | 245 | # define bt_named_field_class_freeze(_named_fc) ((void) _named_fc) |
1e6fd1d7 PP |
246 | #endif |
247 | ||
5cd6d0e5 PP |
248 | /* |
249 | * This function recursively marks `field_class` and its children as | |
250 | * being part of a trace. This is used to validate that all field classes | |
251 | * are used at a single location within trace objects even if they are | |
252 | * shared objects for other purposes. | |
253 | */ | |
254 | BT_HIDDEN | |
bdb288b3 | 255 | void bt_field_class_make_part_of_trace_class( |
862ca4ed | 256 | const struct bt_field_class *field_class); |
5cd6d0e5 | 257 | |
5cd6d0e5 | 258 | #endif /* BABELTRACE_TRACE_IR_FIELD_CLASSES_INTERNAL_H */ |