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