Commit | Line | Data |
---|---|---|
5cd6d0e5 | 1 | /* |
e2f7325d | 2 | * Copyright 2017-2018 Philippe Proulx <pproulx@efficios.com> |
5cd6d0e5 PP |
3 | * Copyright 2013, 2014 Jérémie Galarneau <jeremie.galarneau@efficios.com> |
4 | * | |
5cd6d0e5 PP |
5 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
6 | * of this software and associated documentation files (the "Software"), to deal | |
7 | * in the Software without restriction, including without limitation the rights | |
8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
9 | * copies of the Software, and to permit persons to whom the Software is | |
10 | * furnished to do so, subject to the following conditions: | |
11 | * | |
12 | * The above copyright notice and this permission notice shall be included in | |
13 | * all copies or substantial portions of the Software. | |
14 | * | |
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
21 | * SOFTWARE. | |
22 | */ | |
23 | ||
350ad6c1 | 24 | #define BT_LOG_TAG "LIB/FIELD-CLASS" |
c2d9d9cf | 25 | #include "lib/logging.h" |
5cd6d0e5 | 26 | |
578e048b | 27 | #include "lib/assert-pre.h" |
3fadfbc0 MJ |
28 | #include <babeltrace2/trace-ir/field-class.h> |
29 | #include <babeltrace2/trace-ir/field-class-const.h> | |
3fadfbc0 MJ |
30 | #include <babeltrace2/trace-ir/field-const.h> |
31 | #include <babeltrace2/trace-ir/field.h> | |
3fadfbc0 | 32 | #include <babeltrace2/trace-ir/clock-class.h> |
578e048b MJ |
33 | #include "lib/object.h" |
34 | #include "compat/compiler.h" | |
35 | #include "compat/endian.h" | |
36 | #include "common/assert.h" | |
37 | #include "compat/glib.h" | |
5cd6d0e5 PP |
38 | #include <float.h> |
39 | #include <inttypes.h> | |
40 | #include <stdlib.h> | |
41 | ||
578e048b MJ |
42 | #include "clock-class.h" |
43 | #include "field-class.h" | |
44 | #include "field.h" | |
45 | #include "field-path.h" | |
46 | #include "utils.h" | |
d24d5663 | 47 | #include "lib/func-status.h" |
45c51519 | 48 | #include "lib/integer-range-set.h" |
c6962c96 | 49 | #include "lib/value.h" |
578e048b | 50 | |
40f4ba76 PP |
51 | enum bt_field_class_type bt_field_class_get_type( |
52 | const struct bt_field_class *fc) | |
5cd6d0e5 | 53 | { |
bdb288b3 | 54 | BT_ASSERT_PRE_DEV_NON_NULL(fc, "Field class"); |
864cad70 | 55 | return fc->type; |
5cd6d0e5 PP |
56 | } |
57 | ||
58 | static | |
c6962c96 | 59 | int init_field_class(struct bt_field_class *fc, enum bt_field_class_type type, |
5cd6d0e5 PP |
60 | bt_object_release_func release_func) |
61 | { | |
c6962c96 PP |
62 | int ret = 0; |
63 | ||
5cd6d0e5 | 64 | BT_ASSERT(fc); |
5cd6d0e5 PP |
65 | BT_ASSERT(release_func); |
66 | bt_object_init_shared(&fc->base, release_func); | |
864cad70 | 67 | fc->type = type; |
c6962c96 PP |
68 | fc->user_attributes = bt_value_map_create(); |
69 | if (!fc->user_attributes) { | |
70 | BT_LIB_LOGE_APPEND_CAUSE( | |
71 | "Failed to create a map value object."); | |
72 | ret = -1; | |
73 | goto end; | |
74 | } | |
75 | ||
76 | end: | |
77 | return ret; | |
78 | } | |
79 | ||
80 | static | |
81 | void finalize_field_class(struct bt_field_class *fc) | |
82 | { | |
83 | BT_OBJECT_PUT_REF_AND_RESET(fc->user_attributes); | |
5cd6d0e5 PP |
84 | } |
85 | ||
1094efa4 PP |
86 | static |
87 | void destroy_bit_array_field_class(struct bt_object *obj) | |
88 | { | |
89 | BT_ASSERT(obj); | |
90 | BT_LIB_LOGD("Destroying bit array field class object: %!+F", obj); | |
c6962c96 | 91 | finalize_field_class((void *) obj); |
1094efa4 PP |
92 | g_free(obj); |
93 | } | |
94 | ||
95 | struct bt_field_class *bt_field_class_bit_array_create( | |
96 | struct bt_trace_class *trace_class, uint64_t length) | |
97 | { | |
98 | struct bt_field_class_bit_array *ba_fc = NULL; | |
99 | ||
100 | BT_ASSERT_PRE_NON_NULL(trace_class, "Trace class"); | |
101 | BT_ASSERT_PRE(length > 0 && length <= 64, | |
102 | "Unsupported length for bit array field class " | |
103 | "(minimum is 1, maximum is 64): length=%" PRIu64, length); | |
104 | BT_LOGD("Creating default bit array field class object."); | |
105 | ba_fc = g_new0(struct bt_field_class_bit_array, 1); | |
106 | if (!ba_fc) { | |
107 | BT_LIB_LOGE_APPEND_CAUSE( | |
108 | "Failed to allocate one bit array field class."); | |
109 | goto error; | |
110 | } | |
111 | ||
c6962c96 PP |
112 | if (init_field_class((void *) ba_fc, BT_FIELD_CLASS_TYPE_BIT_ARRAY, |
113 | destroy_bit_array_field_class)) { | |
114 | goto error; | |
115 | } | |
116 | ||
1094efa4 PP |
117 | ba_fc->length = length; |
118 | BT_LIB_LOGD("Created bit array field class object: %!+F", ba_fc); | |
119 | goto end; | |
120 | ||
121 | error: | |
122 | BT_OBJECT_PUT_REF_AND_RESET(ba_fc); | |
123 | ||
124 | end: | |
125 | return (void *) ba_fc; | |
126 | } | |
127 | ||
128 | uint64_t bt_field_class_bit_array_get_length(const struct bt_field_class *fc) | |
129 | { | |
130 | const struct bt_field_class_bit_array *ba_fc = (const void *) fc; | |
131 | ||
132 | BT_ASSERT_PRE_DEV_NON_NULL(fc, "Field class"); | |
133 | BT_ASSERT_PRE_DEV_FC_HAS_ID(fc, BT_FIELD_CLASS_TYPE_BIT_ARRAY, | |
134 | "Field class"); | |
135 | return ba_fc->length; | |
136 | } | |
137 | ||
5cebbe7f PP |
138 | static |
139 | void destroy_bool_field_class(struct bt_object *obj) | |
140 | { | |
141 | BT_ASSERT(obj); | |
142 | BT_LIB_LOGD("Destroying boolean field class object: %!+F", obj); | |
c6962c96 | 143 | finalize_field_class((void *) obj); |
5cebbe7f PP |
144 | g_free(obj); |
145 | } | |
146 | ||
147 | struct bt_field_class *bt_field_class_bool_create( | |
148 | bt_trace_class *trace_class) | |
149 | { | |
150 | struct bt_field_class_bool *bool_fc = NULL; | |
151 | ||
152 | BT_ASSERT_PRE_NON_NULL(trace_class, "Trace class"); | |
153 | BT_LOGD("Creating default boolean field class object."); | |
154 | bool_fc = g_new0(struct bt_field_class_bool, 1); | |
155 | if (!bool_fc) { | |
156 | BT_LIB_LOGE_APPEND_CAUSE( | |
157 | "Failed to allocate one boolean field class."); | |
158 | goto error; | |
159 | } | |
160 | ||
c6962c96 PP |
161 | if (init_field_class((void *) bool_fc, BT_FIELD_CLASS_TYPE_BOOL, |
162 | destroy_bool_field_class)) { | |
163 | goto error; | |
164 | } | |
165 | ||
5cebbe7f PP |
166 | BT_LIB_LOGD("Created boolean field class object: %!+F", bool_fc); |
167 | goto end; | |
168 | ||
169 | error: | |
170 | BT_OBJECT_PUT_REF_AND_RESET(bool_fc); | |
171 | ||
172 | end: | |
173 | return (void *) bool_fc; | |
174 | } | |
175 | ||
5cd6d0e5 | 176 | static |
c6962c96 | 177 | int init_integer_field_class(struct bt_field_class_integer *fc, |
864cad70 | 178 | enum bt_field_class_type type, |
5cd6d0e5 PP |
179 | bt_object_release_func release_func) |
180 | { | |
c6962c96 PP |
181 | int ret; |
182 | ||
183 | ret = init_field_class((void *) fc, type, release_func); | |
184 | if (ret) { | |
185 | goto end; | |
186 | } | |
187 | ||
5cd6d0e5 PP |
188 | fc->range = 64; |
189 | fc->base = BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_DECIMAL; | |
c6962c96 PP |
190 | |
191 | end: | |
192 | return ret; | |
5cd6d0e5 PP |
193 | } |
194 | ||
195 | static | |
196 | void destroy_integer_field_class(struct bt_object *obj) | |
197 | { | |
198 | BT_ASSERT(obj); | |
e5be10ef | 199 | BT_LIB_LOGD("Destroying integer field class object: %!+F", obj); |
c6962c96 | 200 | finalize_field_class((void *) obj); |
5cd6d0e5 PP |
201 | g_free(obj); |
202 | } | |
203 | ||
204 | static inline | |
1122a43a PP |
205 | struct bt_field_class *create_integer_field_class(bt_trace_class *trace_class, |
206 | enum bt_field_class_type type) | |
5cd6d0e5 PP |
207 | { |
208 | struct bt_field_class_integer *int_fc = NULL; | |
209 | ||
1122a43a | 210 | BT_ASSERT_PRE_NON_NULL(trace_class, "Trace class"); |
e5be10ef | 211 | BT_LOGD("Creating default integer field class object: type=%s", |
864cad70 | 212 | bt_common_field_class_type_string(type)); |
5cd6d0e5 PP |
213 | int_fc = g_new0(struct bt_field_class_integer, 1); |
214 | if (!int_fc) { | |
870631a2 PP |
215 | BT_LIB_LOGE_APPEND_CAUSE( |
216 | "Failed to allocate one integer field class."); | |
5cd6d0e5 PP |
217 | goto error; |
218 | } | |
219 | ||
c6962c96 PP |
220 | if (init_integer_field_class(int_fc, type, |
221 | destroy_integer_field_class)) { | |
222 | goto error; | |
223 | } | |
224 | ||
e5be10ef | 225 | BT_LIB_LOGD("Created integer field class object: %!+F", int_fc); |
5cd6d0e5 PP |
226 | goto end; |
227 | ||
228 | error: | |
65300d60 | 229 | BT_OBJECT_PUT_REF_AND_RESET(int_fc); |
5cd6d0e5 PP |
230 | |
231 | end: | |
232 | return (void *) int_fc; | |
233 | } | |
234 | ||
9c08c816 | 235 | struct bt_field_class *bt_field_class_integer_unsigned_create( |
1122a43a | 236 | bt_trace_class *trace_class) |
5cd6d0e5 | 237 | { |
1122a43a | 238 | return create_integer_field_class(trace_class, |
e5be10ef | 239 | BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER); |
5cd6d0e5 PP |
240 | } |
241 | ||
9c08c816 | 242 | struct bt_field_class *bt_field_class_integer_signed_create( |
1122a43a | 243 | bt_trace_class *trace_class) |
5cd6d0e5 | 244 | { |
1122a43a | 245 | return create_integer_field_class(trace_class, |
e5be10ef | 246 | BT_FIELD_CLASS_TYPE_SIGNED_INTEGER); |
5cd6d0e5 PP |
247 | } |
248 | ||
249 | uint64_t bt_field_class_integer_get_field_value_range( | |
40f4ba76 | 250 | const struct bt_field_class *fc) |
5cd6d0e5 | 251 | { |
40f4ba76 | 252 | const struct bt_field_class_integer *int_fc = (const void *) fc; |
5cd6d0e5 | 253 | |
bdb288b3 PP |
254 | BT_ASSERT_PRE_DEV_NON_NULL(fc, "Field class"); |
255 | BT_ASSERT_PRE_DEV_FC_IS_INT(fc, "Field class"); | |
5cd6d0e5 PP |
256 | return int_fc->range; |
257 | } | |
258 | ||
5cd6d0e5 PP |
259 | static |
260 | bool size_is_valid_for_enumeration_field_class(struct bt_field_class *fc, | |
261 | uint64_t size) | |
262 | { | |
263 | // TODO | |
264 | return true; | |
265 | } | |
266 | ||
40f4ba76 PP |
267 | void bt_field_class_integer_set_field_value_range( |
268 | struct bt_field_class *fc, uint64_t size) | |
5cd6d0e5 PP |
269 | { |
270 | struct bt_field_class_integer *int_fc = (void *) fc; | |
271 | ||
272 | BT_ASSERT_PRE_NON_NULL(fc, "Field class"); | |
273 | BT_ASSERT_PRE_FC_IS_INT(fc, "Field class"); | |
bdb288b3 | 274 | BT_ASSERT_PRE_DEV_FC_HOT(fc, "Field class"); |
5cd6d0e5 | 275 | BT_ASSERT_PRE(size <= 64, |
e5be10ef | 276 | "Unsupported size for integer field class's field value range " |
5cd6d0e5 | 277 | "(maximum is 64): size=%" PRIu64, size); |
864cad70 PP |
278 | BT_ASSERT_PRE( |
279 | int_fc->common.type == BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER || | |
280 | int_fc->common.type == BT_FIELD_CLASS_TYPE_SIGNED_INTEGER || | |
5cd6d0e5 | 281 | size_is_valid_for_enumeration_field_class(fc, size), |
e5be10ef | 282 | "Invalid field value range for enumeration field class: " |
5cd6d0e5 PP |
283 | "at least one of the current mapping ranges contains values " |
284 | "which are outside this range: %!+F, size=%" PRIu64, fc, size); | |
285 | int_fc->range = size; | |
3f7d4d90 | 286 | BT_LIB_LOGD("Set integer field class's field value range: %!+F", fc); |
5cd6d0e5 PP |
287 | } |
288 | ||
289 | enum bt_field_class_integer_preferred_display_base | |
40f4ba76 | 290 | bt_field_class_integer_get_preferred_display_base(const struct bt_field_class *fc) |
5cd6d0e5 | 291 | { |
40f4ba76 | 292 | const struct bt_field_class_integer *int_fc = (const void *) fc; |
5cd6d0e5 | 293 | |
bdb288b3 PP |
294 | BT_ASSERT_PRE_DEV_NON_NULL(fc, "Field class"); |
295 | BT_ASSERT_PRE_DEV_FC_IS_INT(fc, "Field class"); | |
5cd6d0e5 PP |
296 | return int_fc->base; |
297 | } | |
298 | ||
40f4ba76 PP |
299 | void bt_field_class_integer_set_preferred_display_base( |
300 | struct bt_field_class *fc, | |
5cd6d0e5 PP |
301 | enum bt_field_class_integer_preferred_display_base base) |
302 | { | |
303 | struct bt_field_class_integer *int_fc = (void *) fc; | |
304 | ||
305 | BT_ASSERT_PRE_NON_NULL(fc, "Field class"); | |
306 | BT_ASSERT_PRE_FC_IS_INT(fc, "Field class"); | |
bdb288b3 | 307 | BT_ASSERT_PRE_DEV_FC_HOT(fc, "Field class"); |
5cd6d0e5 | 308 | int_fc->base = base; |
3f7d4d90 | 309 | BT_LIB_LOGD("Set integer field class's preferred display base: %!+F", fc); |
5cd6d0e5 PP |
310 | } |
311 | ||
312 | static | |
313 | void finalize_enumeration_field_class_mapping( | |
314 | struct bt_field_class_enumeration_mapping *mapping) | |
315 | { | |
316 | BT_ASSERT(mapping); | |
317 | ||
318 | if (mapping->label) { | |
319 | g_string_free(mapping->label, TRUE); | |
45c51519 | 320 | mapping->label = NULL; |
5cd6d0e5 PP |
321 | } |
322 | ||
45c51519 | 323 | BT_OBJECT_PUT_REF_AND_RESET(mapping->range_set); |
5cd6d0e5 PP |
324 | } |
325 | ||
326 | static | |
327 | void destroy_enumeration_field_class(struct bt_object *obj) | |
328 | { | |
329 | struct bt_field_class_enumeration *fc = (void *) obj; | |
330 | ||
331 | BT_ASSERT(fc); | |
e5be10ef | 332 | BT_LIB_LOGD("Destroying enumeration field class object: %!+F", fc); |
c6962c96 | 333 | finalize_field_class((void *) obj); |
5cd6d0e5 PP |
334 | |
335 | if (fc->mappings) { | |
336 | uint64_t i; | |
337 | ||
338 | for (i = 0; i < fc->mappings->len; i++) { | |
339 | finalize_enumeration_field_class_mapping( | |
340 | BT_FIELD_CLASS_ENUM_MAPPING_AT_INDEX(fc, i)); | |
341 | } | |
342 | ||
343 | g_array_free(fc->mappings, TRUE); | |
238b7404 | 344 | fc->mappings = NULL; |
5cd6d0e5 PP |
345 | } |
346 | ||
347 | if (fc->label_buf) { | |
348 | g_ptr_array_free(fc->label_buf, TRUE); | |
238b7404 | 349 | fc->label_buf = NULL; |
5cd6d0e5 PP |
350 | } |
351 | ||
352 | g_free(fc); | |
353 | } | |
354 | ||
355 | static | |
40f4ba76 | 356 | struct bt_field_class *create_enumeration_field_class( |
1122a43a | 357 | bt_trace_class *trace_class, enum bt_field_class_type type) |
5cd6d0e5 PP |
358 | { |
359 | struct bt_field_class_enumeration *enum_fc = NULL; | |
360 | ||
1122a43a | 361 | BT_ASSERT_PRE_NON_NULL(trace_class, "Trace class"); |
e5be10ef | 362 | BT_LOGD("Creating default enumeration field class object: type=%s", |
864cad70 | 363 | bt_common_field_class_type_string(type)); |
5cd6d0e5 PP |
364 | enum_fc = g_new0(struct bt_field_class_enumeration, 1); |
365 | if (!enum_fc) { | |
870631a2 PP |
366 | BT_LIB_LOGE_APPEND_CAUSE( |
367 | "Failed to allocate one enumeration field class."); | |
5cd6d0e5 PP |
368 | goto error; |
369 | } | |
370 | ||
c6962c96 PP |
371 | if (init_integer_field_class((void *) enum_fc, type, |
372 | destroy_enumeration_field_class)) { | |
373 | goto error; | |
374 | } | |
375 | ||
5cd6d0e5 PP |
376 | enum_fc->mappings = g_array_new(FALSE, TRUE, |
377 | sizeof(struct bt_field_class_enumeration_mapping)); | |
378 | if (!enum_fc->mappings) { | |
870631a2 | 379 | BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GArray."); |
5cd6d0e5 PP |
380 | goto error; |
381 | } | |
382 | ||
383 | enum_fc->label_buf = g_ptr_array_new(); | |
384 | if (!enum_fc->label_buf) { | |
870631a2 | 385 | BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GArray."); |
5cd6d0e5 PP |
386 | goto error; |
387 | } | |
388 | ||
e5be10ef | 389 | BT_LIB_LOGD("Created enumeration field class object: %!+F", enum_fc); |
5cd6d0e5 PP |
390 | goto end; |
391 | ||
392 | error: | |
65300d60 | 393 | BT_OBJECT_PUT_REF_AND_RESET(enum_fc); |
5cd6d0e5 PP |
394 | |
395 | end: | |
396 | return (void *) enum_fc; | |
397 | } | |
398 | ||
9c08c816 | 399 | struct bt_field_class *bt_field_class_enumeration_unsigned_create( |
1122a43a | 400 | bt_trace_class *trace_class) |
5cd6d0e5 | 401 | { |
1122a43a | 402 | return create_enumeration_field_class(trace_class, |
864cad70 | 403 | BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION); |
5cd6d0e5 PP |
404 | } |
405 | ||
9c08c816 | 406 | struct bt_field_class *bt_field_class_enumeration_signed_create( |
1122a43a | 407 | bt_trace_class *trace_class) |
5cd6d0e5 | 408 | { |
1122a43a | 409 | return create_enumeration_field_class(trace_class, |
864cad70 | 410 | BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION); |
5cd6d0e5 PP |
411 | } |
412 | ||
40f4ba76 PP |
413 | uint64_t bt_field_class_enumeration_get_mapping_count( |
414 | const struct bt_field_class *fc) | |
5cd6d0e5 | 415 | { |
40f4ba76 | 416 | const struct bt_field_class_enumeration *enum_fc = (const void *) fc; |
5cd6d0e5 | 417 | |
bdb288b3 PP |
418 | BT_ASSERT_PRE_DEV_NON_NULL(fc, "Field class"); |
419 | BT_ASSERT_PRE_DEV_FC_IS_ENUM(fc, "Field class"); | |
5cd6d0e5 PP |
420 | return (uint64_t) enum_fc->mappings->len; |
421 | } | |
422 | ||
9c08c816 PP |
423 | const struct bt_field_class_enumeration_unsigned_mapping * |
424 | bt_field_class_enumeration_unsigned_borrow_mapping_by_index_const( | |
8f3ccfbc | 425 | const struct bt_field_class *fc, uint64_t index) |
5cd6d0e5 | 426 | { |
40f4ba76 | 427 | const struct bt_field_class_enumeration *enum_fc = (const void *) fc; |
5cd6d0e5 | 428 | |
bdb288b3 PP |
429 | BT_ASSERT_PRE_DEV_NON_NULL(fc, "Field class"); |
430 | BT_ASSERT_PRE_DEV_VALID_INDEX(index, enum_fc->mappings->len); | |
431 | BT_ASSERT_PRE_DEV_FC_HAS_ID(fc, BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION, | |
5cd6d0e5 | 432 | "Field class"); |
8f3ccfbc | 433 | return (const void *) BT_FIELD_CLASS_ENUM_MAPPING_AT_INDEX(fc, index); |
5cd6d0e5 PP |
434 | } |
435 | ||
9c08c816 PP |
436 | const struct bt_field_class_enumeration_signed_mapping * |
437 | bt_field_class_enumeration_signed_borrow_mapping_by_index_const( | |
8f3ccfbc | 438 | const struct bt_field_class *fc, uint64_t index) |
5cd6d0e5 | 439 | { |
40f4ba76 | 440 | const struct bt_field_class_enumeration *enum_fc = (const void *) fc; |
5cd6d0e5 | 441 | |
bdb288b3 PP |
442 | BT_ASSERT_PRE_DEV_NON_NULL(fc, "Field class"); |
443 | BT_ASSERT_PRE_DEV_VALID_INDEX(index, enum_fc->mappings->len); | |
444 | BT_ASSERT_PRE_DEV_FC_HAS_ID(fc, BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION, | |
5cd6d0e5 | 445 | "Field class"); |
8f3ccfbc | 446 | return (const void *) BT_FIELD_CLASS_ENUM_MAPPING_AT_INDEX(fc, index); |
5cd6d0e5 PP |
447 | } |
448 | ||
45c51519 PP |
449 | static |
450 | const struct bt_field_class_enumeration_mapping * | |
451 | borrow_enumeration_field_class_mapping_by_label( | |
452 | const struct bt_field_class_enumeration *fc, const char *label) | |
5cd6d0e5 | 453 | { |
45c51519 PP |
454 | struct bt_field_class_enumeration_mapping *mapping = NULL; |
455 | uint64_t i; | |
456 | ||
457 | BT_ASSERT(fc); | |
458 | BT_ASSERT_PRE_DEV_NON_NULL(label, "Label"); | |
459 | ||
460 | for (i = 0; i < fc->mappings->len; i++) { | |
461 | struct bt_field_class_enumeration_mapping *this_mapping = | |
462 | BT_FIELD_CLASS_ENUM_MAPPING_AT_INDEX(fc, i); | |
463 | ||
464 | if (strcmp(this_mapping->label->str, label) == 0) { | |
465 | mapping = this_mapping; | |
466 | goto end; | |
467 | } | |
468 | } | |
469 | ||
470 | end: | |
471 | return mapping; | |
5cd6d0e5 PP |
472 | } |
473 | ||
9c08c816 PP |
474 | const struct bt_field_class_enumeration_signed_mapping * |
475 | bt_field_class_enumeration_signed_borrow_mapping_by_label_const( | |
45c51519 | 476 | const struct bt_field_class *fc, const char *label) |
5cd6d0e5 | 477 | { |
45c51519 PP |
478 | BT_ASSERT_PRE_DEV_NON_NULL(fc, "Field class"); |
479 | BT_ASSERT_PRE_DEV_FC_HAS_ID(fc, BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION, | |
480 | "Field class"); | |
481 | return (const void *) borrow_enumeration_field_class_mapping_by_label( | |
482 | (const void *) fc, label); | |
5cd6d0e5 PP |
483 | } |
484 | ||
9c08c816 PP |
485 | const struct bt_field_class_enumeration_unsigned_mapping * |
486 | bt_field_class_enumeration_unsigned_borrow_mapping_by_label_const( | |
45c51519 | 487 | const struct bt_field_class *fc, const char *label) |
5cd6d0e5 | 488 | { |
45c51519 PP |
489 | BT_ASSERT_PRE_DEV_NON_NULL(fc, "Field class"); |
490 | BT_ASSERT_PRE_DEV_FC_HAS_ID(fc, | |
491 | BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION, "Field class"); | |
492 | return (const void *) borrow_enumeration_field_class_mapping_by_label( | |
493 | (const void *) fc, label); | |
494 | } | |
5cd6d0e5 | 495 | |
45c51519 PP |
496 | const char *bt_field_class_enumeration_mapping_get_label( |
497 | const struct bt_field_class_enumeration_mapping *mapping) | |
498 | { | |
499 | BT_ASSERT_PRE_DEV_NON_NULL(mapping, "Enumeration field class mapping"); | |
500 | return mapping->label->str; | |
5cd6d0e5 PP |
501 | } |
502 | ||
45c51519 | 503 | const struct bt_integer_range_set_unsigned * |
9c08c816 PP |
504 | bt_field_class_enumeration_unsigned_mapping_borrow_ranges_const( |
505 | const struct bt_field_class_enumeration_unsigned_mapping *u_mapping) | |
5cd6d0e5 | 506 | { |
45c51519 PP |
507 | const struct bt_field_class_enumeration_mapping *mapping = |
508 | (const void *) u_mapping; | |
509 | ||
510 | BT_ASSERT_PRE_DEV_NON_NULL(mapping, "Enumeration field class mapping"); | |
511 | return (const void *) mapping->range_set; | |
5cd6d0e5 PP |
512 | } |
513 | ||
45c51519 | 514 | const struct bt_integer_range_set_signed * |
9c08c816 PP |
515 | bt_field_class_enumeration_signed_mapping_borrow_ranges_const( |
516 | const struct bt_field_class_enumeration_signed_mapping *s_mapping) | |
5cd6d0e5 | 517 | { |
45c51519 PP |
518 | const struct bt_field_class_enumeration_mapping *mapping = |
519 | (const void *) s_mapping; | |
520 | ||
521 | BT_ASSERT_PRE_DEV_NON_NULL(mapping, "Enumeration field class mapping"); | |
522 | return (const void *) mapping->range_set; | |
5cd6d0e5 PP |
523 | } |
524 | ||
185ecf64 | 525 | enum bt_field_class_enumeration_get_mapping_labels_for_value_status |
9c08c816 | 526 | bt_field_class_enumeration_unsigned_get_mapping_labels_for_value( |
40f4ba76 | 527 | const struct bt_field_class *fc, uint64_t value, |
5cd6d0e5 PP |
528 | bt_field_class_enumeration_mapping_label_array *label_array, |
529 | uint64_t *count) | |
530 | { | |
40f4ba76 | 531 | const struct bt_field_class_enumeration *enum_fc = (const void *) fc; |
5cd6d0e5 PP |
532 | uint64_t i; |
533 | ||
bdb288b3 PP |
534 | BT_ASSERT_PRE_DEV_NON_NULL(fc, "Field class"); |
535 | BT_ASSERT_PRE_DEV_NON_NULL(label_array, "Label array (output)"); | |
536 | BT_ASSERT_PRE_DEV_NON_NULL(count, "Count (output)"); | |
537 | BT_ASSERT_PRE_DEV_FC_HAS_ID(fc, BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION, | |
5cd6d0e5 PP |
538 | "Field class"); |
539 | g_ptr_array_set_size(enum_fc->label_buf, 0); | |
540 | ||
541 | for (i = 0; i < enum_fc->mappings->len; i++) { | |
542 | uint64_t j; | |
40f4ba76 | 543 | const struct bt_field_class_enumeration_mapping *mapping = |
5cd6d0e5 PP |
544 | BT_FIELD_CLASS_ENUM_MAPPING_AT_INDEX(enum_fc, i); |
545 | ||
45c51519 PP |
546 | for (j = 0; j < mapping->range_set->ranges->len; j++) { |
547 | const struct bt_integer_range *range = (const void *) | |
548 | BT_INTEGER_RANGE_SET_RANGE_AT_INDEX( | |
549 | mapping->range_set, j); | |
5cd6d0e5 PP |
550 | |
551 | if (value >= range->lower.u && | |
552 | value <= range->upper.u) { | |
553 | g_ptr_array_add(enum_fc->label_buf, | |
554 | mapping->label->str); | |
555 | break; | |
556 | } | |
557 | } | |
558 | } | |
559 | ||
560 | *label_array = (void *) enum_fc->label_buf->pdata; | |
561 | *count = (uint64_t) enum_fc->label_buf->len; | |
d24d5663 | 562 | return BT_FUNC_STATUS_OK; |
5cd6d0e5 PP |
563 | } |
564 | ||
185ecf64 | 565 | enum bt_field_class_enumeration_get_mapping_labels_for_value_status |
9c08c816 | 566 | bt_field_class_enumeration_signed_get_mapping_labels_for_value( |
40f4ba76 | 567 | const struct bt_field_class *fc, int64_t value, |
5cd6d0e5 PP |
568 | bt_field_class_enumeration_mapping_label_array *label_array, |
569 | uint64_t *count) | |
570 | { | |
40f4ba76 | 571 | const struct bt_field_class_enumeration *enum_fc = (const void *) fc; |
5cd6d0e5 PP |
572 | uint64_t i; |
573 | ||
bdb288b3 PP |
574 | BT_ASSERT_PRE_DEV_NON_NULL(fc, "Field class"); |
575 | BT_ASSERT_PRE_DEV_NON_NULL(label_array, "Label array (output)"); | |
576 | BT_ASSERT_PRE_DEV_NON_NULL(count, "Count (output)"); | |
577 | BT_ASSERT_PRE_DEV_FC_HAS_ID(fc, BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION, | |
5cd6d0e5 PP |
578 | "Field class"); |
579 | g_ptr_array_set_size(enum_fc->label_buf, 0); | |
580 | ||
581 | for (i = 0; i < enum_fc->mappings->len; i++) { | |
582 | uint64_t j; | |
40f4ba76 | 583 | const struct bt_field_class_enumeration_mapping *mapping = |
5cd6d0e5 PP |
584 | BT_FIELD_CLASS_ENUM_MAPPING_AT_INDEX(enum_fc, i); |
585 | ||
45c51519 PP |
586 | for (j = 0; j < mapping->range_set->ranges->len; j++) { |
587 | const struct bt_integer_range *range = (const void *) | |
588 | BT_INTEGER_RANGE_SET_RANGE_AT_INDEX( | |
589 | mapping->range_set, j); | |
5cd6d0e5 PP |
590 | |
591 | if (value >= range->lower.i && | |
592 | value <= range->upper.i) { | |
593 | g_ptr_array_add(enum_fc->label_buf, | |
594 | mapping->label->str); | |
595 | break; | |
596 | } | |
597 | } | |
598 | } | |
599 | ||
600 | *label_array = (void *) enum_fc->label_buf->pdata; | |
601 | *count = (uint64_t) enum_fc->label_buf->len; | |
d24d5663 | 602 | return BT_FUNC_STATUS_OK; |
5cd6d0e5 PP |
603 | } |
604 | ||
45c51519 PP |
605 | static |
606 | bool enumeration_field_class_has_mapping_with_label( | |
607 | const struct bt_field_class_enumeration *enum_fc, | |
608 | const char *label) | |
5cd6d0e5 | 609 | { |
5cd6d0e5 | 610 | uint64_t i; |
45c51519 | 611 | bool exists = false; |
5cd6d0e5 | 612 | |
45c51519 PP |
613 | BT_ASSERT(enum_fc); |
614 | BT_ASSERT(label); | |
5cd6d0e5 | 615 | |
5cd6d0e5 PP |
616 | for (i = 0; i < enum_fc->mappings->len; i++) { |
617 | struct bt_field_class_enumeration_mapping *mapping_candidate = | |
618 | BT_FIELD_CLASS_ENUM_MAPPING_AT_INDEX(enum_fc, i); | |
619 | ||
620 | if (strcmp(mapping_candidate->label->str, label) == 0) { | |
45c51519 PP |
621 | exists = true; |
622 | goto end; | |
5cd6d0e5 PP |
623 | } |
624 | } | |
625 | ||
45c51519 PP |
626 | end: |
627 | return exists; | |
628 | } | |
5cd6d0e5 | 629 | |
45c51519 PP |
630 | static inline |
631 | enum bt_field_class_enumeration_add_mapping_status | |
632 | add_mapping_to_enumeration_field_class(struct bt_field_class *fc, | |
633 | const char *label, const struct bt_integer_range_set *range_set) | |
634 | { | |
635 | enum bt_field_class_enumeration_add_mapping_status status = | |
636 | BT_FUNC_STATUS_OK; | |
637 | struct bt_field_class_enumeration *enum_fc = (void *) fc; | |
638 | struct bt_field_class_enumeration_mapping mapping = { 0 }; | |
639 | ||
640 | BT_ASSERT(fc); | |
641 | BT_ASSERT_PRE_NON_NULL(label, "Label"); | |
6769570a | 642 | BT_ASSERT_PRE_NON_NULL(range_set, "Integer range set"); |
45c51519 PP |
643 | BT_ASSERT_PRE(!enumeration_field_class_has_mapping_with_label( |
644 | enum_fc, label), | |
645 | "Duplicate mapping name in enumeration field class: " | |
646 | "%![enum-fc-]+F, label=\"%s\"", fc, label); | |
647 | mapping.range_set = range_set; | |
648 | bt_object_get_ref(mapping.range_set); | |
649 | mapping.label = g_string_new(label); | |
650 | if (!mapping.label) { | |
651 | finalize_enumeration_field_class_mapping(&mapping); | |
652 | status = BT_FUNC_STATUS_MEMORY_ERROR; | |
653 | goto end; | |
5cd6d0e5 PP |
654 | } |
655 | ||
45c51519 | 656 | g_array_append_val(enum_fc->mappings, mapping); |
3f7d4d90 | 657 | BT_LIB_LOGD("Added mapping to enumeration field class: " |
45c51519 | 658 | "%![fc-]+F, label=\"%s\"", fc, label); |
5cd6d0e5 PP |
659 | |
660 | end: | |
45c51519 | 661 | return status; |
5cd6d0e5 PP |
662 | } |
663 | ||
45c51519 | 664 | enum bt_field_class_enumeration_add_mapping_status |
9c08c816 | 665 | bt_field_class_enumeration_unsigned_add_mapping( |
40f4ba76 | 666 | struct bt_field_class *fc, const char *label, |
45c51519 | 667 | const struct bt_integer_range_set_unsigned *range_set) |
5cd6d0e5 | 668 | { |
5cd6d0e5 | 669 | BT_ASSERT_PRE_NON_NULL(fc, "Field class"); |
864cad70 | 670 | BT_ASSERT_PRE_FC_HAS_ID(fc, BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION, |
5cd6d0e5 | 671 | "Field class"); |
45c51519 PP |
672 | return add_mapping_to_enumeration_field_class(fc, label, |
673 | (const void *) range_set); | |
674 | } | |
675 | ||
676 | enum bt_field_class_enumeration_add_mapping_status | |
9c08c816 | 677 | bt_field_class_enumeration_signed_add_mapping( |
40f4ba76 | 678 | struct bt_field_class *fc, const char *label, |
45c51519 | 679 | const struct bt_integer_range_set_signed *range_set) |
5cd6d0e5 | 680 | { |
5cd6d0e5 | 681 | BT_ASSERT_PRE_NON_NULL(fc, "Field class"); |
864cad70 | 682 | BT_ASSERT_PRE_FC_HAS_ID(fc, BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION, |
5cd6d0e5 | 683 | "Field class"); |
45c51519 PP |
684 | return add_mapping_to_enumeration_field_class(fc, label, |
685 | (const void *) range_set); | |
5cd6d0e5 PP |
686 | } |
687 | ||
688 | static | |
689 | void destroy_real_field_class(struct bt_object *obj) | |
690 | { | |
691 | BT_ASSERT(obj); | |
e5be10ef | 692 | BT_LIB_LOGD("Destroying real field class object: %!+F", obj); |
c6962c96 | 693 | finalize_field_class((void *) obj); |
5cd6d0e5 PP |
694 | g_free(obj); |
695 | } | |
696 | ||
fe4df857 FD |
697 | static |
698 | struct bt_field_class *create_real_field_class(bt_trace_class *trace_class, | |
699 | enum bt_field_class_type type) | |
5cd6d0e5 PP |
700 | { |
701 | struct bt_field_class_real *real_fc = NULL; | |
702 | ||
1122a43a | 703 | BT_ASSERT_PRE_NON_NULL(trace_class, "Trace class"); |
fe4df857 FD |
704 | BT_LOGD("Creating default real field class object: type=%s", |
705 | bt_common_field_class_type_string(type)); | |
5cd6d0e5 PP |
706 | real_fc = g_new0(struct bt_field_class_real, 1); |
707 | if (!real_fc) { | |
870631a2 | 708 | BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate one real field class."); |
5cd6d0e5 PP |
709 | goto error; |
710 | } | |
711 | ||
fe4df857 | 712 | if (init_field_class((void *) real_fc, type, destroy_real_field_class)) { |
c6962c96 PP |
713 | goto error; |
714 | } | |
715 | ||
e5be10ef | 716 | BT_LIB_LOGD("Created real field class object: %!+F", real_fc); |
5cd6d0e5 PP |
717 | goto end; |
718 | ||
719 | error: | |
65300d60 | 720 | BT_OBJECT_PUT_REF_AND_RESET(real_fc); |
5cd6d0e5 PP |
721 | |
722 | end: | |
723 | return (void *) real_fc; | |
724 | } | |
725 | ||
fe4df857 FD |
726 | struct bt_field_class *bt_field_class_real_single_precision_create( |
727 | bt_trace_class *trace_class) | |
5cd6d0e5 | 728 | { |
fe4df857 FD |
729 | return create_real_field_class(trace_class, |
730 | BT_FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL); | |
5cd6d0e5 PP |
731 | } |
732 | ||
fe4df857 FD |
733 | struct bt_field_class *bt_field_class_real_double_precision_create( |
734 | bt_trace_class *trace_class) | |
5cd6d0e5 | 735 | { |
fe4df857 FD |
736 | return create_real_field_class(trace_class, |
737 | BT_FIELD_CLASS_TYPE_DOUBLE_PRECISION_REAL); | |
5cd6d0e5 PP |
738 | } |
739 | ||
740 | static | |
741 | int init_named_field_classes_container( | |
742 | struct bt_field_class_named_field_class_container *fc, | |
40f4ba76 | 743 | enum bt_field_class_type type, |
45c51519 PP |
744 | bt_object_release_func fc_release_func, |
745 | GDestroyNotify named_fc_destroy_func) | |
5cd6d0e5 PP |
746 | { |
747 | int ret = 0; | |
748 | ||
c6962c96 PP |
749 | ret = init_field_class((void *) fc, type, fc_release_func); |
750 | if (ret) { | |
751 | goto end; | |
752 | } | |
753 | ||
45c51519 | 754 | fc->named_fcs = g_ptr_array_new_with_free_func(named_fc_destroy_func); |
5cd6d0e5 | 755 | if (!fc->named_fcs) { |
45c51519 | 756 | BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GPtrArray."); |
5cd6d0e5 PP |
757 | ret = -1; |
758 | goto end; | |
759 | } | |
760 | ||
761 | fc->name_to_index = g_hash_table_new(g_str_hash, g_str_equal); | |
762 | if (!fc->name_to_index) { | |
870631a2 | 763 | BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GHashTable."); |
5cd6d0e5 PP |
764 | ret = -1; |
765 | goto end; | |
766 | } | |
767 | ||
768 | end: | |
769 | return ret; | |
770 | } | |
771 | ||
772 | static | |
773 | void finalize_named_field_class(struct bt_named_field_class *named_fc) | |
774 | { | |
775 | BT_ASSERT(named_fc); | |
e5be10ef | 776 | BT_LIB_LOGD("Finalizing named field class: " |
5cd6d0e5 PP |
777 | "addr=%p, name=\"%s\", %![fc-]+F", |
778 | named_fc, named_fc->name ? named_fc->name->str : NULL, | |
779 | named_fc->fc); | |
c6962c96 | 780 | BT_OBJECT_PUT_REF_AND_RESET(named_fc->user_attributes); |
5cd6d0e5 PP |
781 | |
782 | if (named_fc->name) { | |
783 | g_string_free(named_fc->name, TRUE); | |
45c51519 | 784 | named_fc->name = NULL; |
5cd6d0e5 PP |
785 | } |
786 | ||
e5be10ef | 787 | BT_LOGD_STR("Putting named field class's field class."); |
238b7404 | 788 | BT_OBJECT_PUT_REF_AND_RESET(named_fc->fc); |
5cd6d0e5 PP |
789 | } |
790 | ||
45c51519 PP |
791 | static |
792 | void destroy_named_field_class(gpointer ptr) | |
793 | { | |
c6962c96 PP |
794 | struct bt_named_field_class *named_fc = ptr; |
795 | ||
45c51519 | 796 | if (ptr) { |
c7d2f7b6 | 797 | BT_OBJECT_PUT_REF_AND_RESET(named_fc->user_attributes); |
45c51519 PP |
798 | finalize_named_field_class(ptr); |
799 | g_free(ptr); | |
800 | } | |
801 | } | |
802 | ||
803 | static | |
804 | void destroy_variant_with_selector_option(gpointer ptr) | |
805 | { | |
806 | struct bt_field_class_variant_with_selector_option *opt = ptr; | |
807 | ||
808 | if (ptr) { | |
809 | finalize_named_field_class(&opt->common); | |
810 | BT_OBJECT_PUT_REF_AND_RESET(opt->range_set); | |
811 | g_free(ptr); | |
812 | } | |
813 | } | |
814 | ||
5cd6d0e5 PP |
815 | static |
816 | void finalize_named_field_classes_container( | |
817 | struct bt_field_class_named_field_class_container *fc) | |
818 | { | |
5cd6d0e5 PP |
819 | BT_ASSERT(fc); |
820 | ||
821 | if (fc->named_fcs) { | |
45c51519 PP |
822 | g_ptr_array_free(fc->named_fcs, TRUE); |
823 | fc->named_fcs = NULL; | |
5cd6d0e5 | 824 | |
5cd6d0e5 PP |
825 | } |
826 | ||
827 | if (fc->name_to_index) { | |
828 | g_hash_table_destroy(fc->name_to_index); | |
45c51519 | 829 | fc->name_to_index = NULL; |
5cd6d0e5 PP |
830 | } |
831 | } | |
832 | ||
833 | static | |
834 | void destroy_structure_field_class(struct bt_object *obj) | |
835 | { | |
836 | BT_ASSERT(obj); | |
1998d1ab | 837 | BT_LIB_LOGD("Destroying structure field class object: %!+F", obj); |
c6962c96 | 838 | finalize_field_class((void *) obj); |
5cd6d0e5 PP |
839 | finalize_named_field_classes_container((void *) obj); |
840 | g_free(obj); | |
841 | } | |
842 | ||
1122a43a PP |
843 | struct bt_field_class *bt_field_class_structure_create( |
844 | bt_trace_class *trace_class) | |
5cd6d0e5 PP |
845 | { |
846 | int ret; | |
847 | struct bt_field_class_structure *struct_fc = NULL; | |
848 | ||
1122a43a | 849 | BT_ASSERT_PRE_NON_NULL(trace_class, "Trace class"); |
e5be10ef | 850 | BT_LOGD_STR("Creating default structure field class object."); |
5cd6d0e5 PP |
851 | struct_fc = g_new0(struct bt_field_class_structure, 1); |
852 | if (!struct_fc) { | |
870631a2 PP |
853 | BT_LIB_LOGE_APPEND_CAUSE( |
854 | "Failed to allocate one structure field class."); | |
5cd6d0e5 PP |
855 | goto error; |
856 | } | |
857 | ||
858 | ret = init_named_field_classes_container((void *) struct_fc, | |
45c51519 PP |
859 | BT_FIELD_CLASS_TYPE_STRUCTURE, destroy_structure_field_class, |
860 | destroy_named_field_class); | |
5cd6d0e5 | 861 | if (ret) { |
45c51519 | 862 | /* init_named_field_classes_container() logs errors */ |
5cd6d0e5 PP |
863 | goto error; |
864 | } | |
865 | ||
e5be10ef | 866 | BT_LIB_LOGD("Created structure field class object: %!+F", struct_fc); |
5cd6d0e5 PP |
867 | goto end; |
868 | ||
869 | error: | |
65300d60 | 870 | BT_OBJECT_PUT_REF_AND_RESET(struct_fc); |
5cd6d0e5 PP |
871 | |
872 | end: | |
873 | return (void *) struct_fc; | |
874 | } | |
875 | ||
876 | static | |
45c51519 | 877 | int init_named_field_class(struct bt_named_field_class *named_fc, |
5cd6d0e5 PP |
878 | const char *name, struct bt_field_class *fc) |
879 | { | |
45c51519 | 880 | int status = BT_FUNC_STATUS_OK; |
5cd6d0e5 | 881 | |
45c51519 PP |
882 | BT_ASSERT(named_fc); |
883 | BT_ASSERT(name); | |
884 | BT_ASSERT(fc); | |
885 | named_fc->name = g_string_new(name); | |
886 | if (!named_fc->name) { | |
870631a2 | 887 | BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GString."); |
45c51519 | 888 | status = BT_FUNC_STATUS_MEMORY_ERROR; |
5cd6d0e5 PP |
889 | goto end; |
890 | } | |
891 | ||
c6962c96 PP |
892 | named_fc->user_attributes = bt_value_map_create(); |
893 | if (!named_fc->user_attributes) { | |
894 | BT_LIB_LOGE_APPEND_CAUSE( | |
895 | "Failed to create a map value object."); | |
896 | status = BT_FUNC_STATUS_MEMORY_ERROR; | |
897 | goto end; | |
898 | } | |
899 | ||
398454ed | 900 | named_fc->fc = fc; |
6871026b | 901 | bt_object_get_ref_no_null_check(named_fc->fc); |
1e6fd1d7 | 902 | |
45c51519 PP |
903 | end: |
904 | return status; | |
905 | } | |
906 | ||
907 | static | |
908 | struct bt_named_field_class *create_named_field_class(const char *name, | |
909 | struct bt_field_class *fc) | |
910 | { | |
911 | struct bt_named_field_class *named_fc = g_new0( | |
912 | struct bt_named_field_class, 1); | |
913 | ||
914 | if (!named_fc) { | |
915 | BT_LIB_LOGE_APPEND_CAUSE( | |
916 | "Failed to allocate a named field class."); | |
917 | goto error; | |
918 | } | |
919 | ||
920 | if (init_named_field_class(named_fc, name, fc)) { | |
921 | /* init_named_field_class() logs errors */ | |
922 | goto error; | |
923 | } | |
924 | ||
925 | goto end; | |
926 | ||
927 | error: | |
928 | destroy_named_field_class(named_fc); | |
929 | named_fc = NULL; | |
5cd6d0e5 PP |
930 | |
931 | end: | |
45c51519 PP |
932 | return named_fc; |
933 | } | |
934 | ||
935 | static | |
936 | struct bt_field_class_variant_with_selector_option * | |
937 | create_variant_with_selector_option( | |
938 | const char *name, struct bt_field_class *fc, | |
939 | const struct bt_integer_range_set *range_set) | |
940 | { | |
941 | struct bt_field_class_variant_with_selector_option *opt = g_new0( | |
942 | struct bt_field_class_variant_with_selector_option, 1); | |
943 | ||
944 | BT_ASSERT(range_set); | |
945 | ||
946 | if (!opt) { | |
947 | BT_LIB_LOGE_APPEND_CAUSE( | |
948 | "Failed to allocate a named field class."); | |
949 | goto error; | |
950 | } | |
951 | ||
952 | if (init_named_field_class(&opt->common, name, fc)) { | |
953 | goto error; | |
954 | } | |
955 | ||
956 | opt->range_set = range_set; | |
6871026b | 957 | bt_object_get_ref_no_null_check(opt->range_set); |
45c51519 PP |
958 | bt_integer_range_set_freeze(range_set); |
959 | goto end; | |
960 | ||
961 | error: | |
962 | destroy_variant_with_selector_option(opt); | |
963 | opt = NULL; | |
964 | ||
965 | end: | |
966 | return opt; | |
967 | } | |
968 | ||
969 | static | |
970 | int append_named_field_class_to_container_field_class( | |
971 | struct bt_field_class_named_field_class_container *container_fc, | |
972 | struct bt_named_field_class *named_fc) | |
973 | { | |
974 | BT_ASSERT(container_fc); | |
975 | BT_ASSERT(named_fc); | |
976 | BT_ASSERT_PRE_DEV_FC_HOT(container_fc, "Field class"); | |
977 | BT_ASSERT_PRE(!bt_g_hash_table_contains(container_fc->name_to_index, | |
978 | named_fc->name->str), | |
979 | "Duplicate member/option name in structure/variant field class: " | |
980 | "%![container-fc-]+F, name=\"%s\"", container_fc, | |
981 | named_fc->name->str); | |
c6962c96 PP |
982 | |
983 | /* | |
984 | * Freeze the contained field class, but not the named field | |
985 | * class itself, as it's still possible afterwards to modify | |
986 | * properties of the member/option object. | |
987 | */ | |
988 | bt_field_class_freeze(named_fc->fc); | |
45c51519 PP |
989 | g_ptr_array_add(container_fc->named_fcs, named_fc); |
990 | g_hash_table_insert(container_fc->name_to_index, named_fc->name->str, | |
991 | GUINT_TO_POINTER(container_fc->named_fcs->len - 1)); | |
992 | return BT_FUNC_STATUS_OK; | |
5cd6d0e5 PP |
993 | } |
994 | ||
d24d5663 PP |
995 | enum bt_field_class_structure_append_member_status |
996 | bt_field_class_structure_append_member( | |
4295b9e0 PP |
997 | struct bt_field_class *fc, const char *name, |
998 | struct bt_field_class *member_fc) | |
5cd6d0e5 | 999 | { |
45c51519 PP |
1000 | enum bt_field_class_structure_append_member_status status; |
1001 | struct bt_named_field_class *named_fc = NULL; | |
e5be10ef | 1002 | |
5cd6d0e5 | 1003 | BT_ASSERT_PRE_NON_NULL(fc, "Field class"); |
740faaf4 PP |
1004 | BT_ASSERT_PRE_FC_HAS_ID(fc, BT_FIELD_CLASS_TYPE_STRUCTURE, |
1005 | "Field class"); | |
45c51519 PP |
1006 | named_fc = create_named_field_class(name, member_fc); |
1007 | if (!named_fc) { | |
1008 | /* create_named_field_class() logs errors */ | |
1009 | status = BT_FUNC_STATUS_MEMORY_ERROR; | |
1010 | goto end; | |
1011 | } | |
1012 | ||
1013 | status = append_named_field_class_to_container_field_class((void *) fc, | |
1014 | named_fc); | |
1015 | if (status == BT_FUNC_STATUS_OK) { | |
1016 | /* Moved to the container */ | |
1017 | named_fc = NULL; | |
1018 | } | |
1019 | ||
1020 | end: | |
1021 | return status; | |
5cd6d0e5 PP |
1022 | } |
1023 | ||
40f4ba76 PP |
1024 | uint64_t bt_field_class_structure_get_member_count( |
1025 | const struct bt_field_class *fc) | |
5cd6d0e5 PP |
1026 | { |
1027 | struct bt_field_class_structure *struct_fc = (void *) fc; | |
1028 | ||
bdb288b3 PP |
1029 | BT_ASSERT_PRE_DEV_NON_NULL(fc, "Field class"); |
1030 | BT_ASSERT_PRE_DEV_FC_HAS_ID(fc, BT_FIELD_CLASS_TYPE_STRUCTURE, | |
740faaf4 | 1031 | "Field class"); |
5cd6d0e5 PP |
1032 | return (uint64_t) struct_fc->common.named_fcs->len; |
1033 | } | |
1034 | ||
1035 | static | |
1e6fd1d7 PP |
1036 | struct bt_named_field_class * |
1037 | borrow_named_field_class_from_container_field_class_at_index( | |
740faaf4 | 1038 | struct bt_field_class_named_field_class_container *fc, |
1e6fd1d7 | 1039 | uint64_t index) |
5cd6d0e5 | 1040 | { |
5cd6d0e5 | 1041 | BT_ASSERT(fc); |
bdb288b3 | 1042 | BT_ASSERT_PRE_DEV_VALID_INDEX(index, fc->named_fcs->len); |
45c51519 | 1043 | return fc->named_fcs->pdata[index]; |
5cd6d0e5 PP |
1044 | } |
1045 | ||
1e6fd1d7 PP |
1046 | const struct bt_field_class_structure_member * |
1047 | bt_field_class_structure_borrow_member_by_index_const( | |
1048 | const struct bt_field_class *fc, uint64_t index) | |
5cd6d0e5 | 1049 | { |
bdb288b3 PP |
1050 | BT_ASSERT_PRE_DEV_NON_NULL(fc, "Field class"); |
1051 | BT_ASSERT_PRE_DEV_FC_HAS_ID(fc, BT_FIELD_CLASS_TYPE_STRUCTURE, | |
740faaf4 | 1052 | "Field class"); |
1e6fd1d7 PP |
1053 | return (const void *) |
1054 | borrow_named_field_class_from_container_field_class_at_index( | |
1055 | (void *) fc, index); | |
740faaf4 PP |
1056 | } |
1057 | ||
1e6fd1d7 PP |
1058 | struct bt_field_class_structure_member * |
1059 | bt_field_class_structure_borrow_member_by_index( | |
1060 | struct bt_field_class *fc, uint64_t index) | |
740faaf4 | 1061 | { |
bdb288b3 PP |
1062 | BT_ASSERT_PRE_DEV_NON_NULL(fc, "Field class"); |
1063 | BT_ASSERT_PRE_DEV_FC_HAS_ID(fc, BT_FIELD_CLASS_TYPE_STRUCTURE, | |
740faaf4 | 1064 | "Field class"); |
1e6fd1d7 PP |
1065 | return (void *) |
1066 | borrow_named_field_class_from_container_field_class_at_index( | |
1067 | (void *) fc, index); | |
e5be10ef PP |
1068 | } |
1069 | ||
5cd6d0e5 | 1070 | static |
1e6fd1d7 PP |
1071 | struct bt_named_field_class * |
1072 | borrow_named_field_class_from_container_field_class_by_name( | |
740faaf4 | 1073 | struct bt_field_class_named_field_class_container *fc, |
5cd6d0e5 PP |
1074 | const char *name) |
1075 | { | |
1e6fd1d7 | 1076 | struct bt_named_field_class *named_fc = NULL; |
5cd6d0e5 PP |
1077 | gpointer orig_key; |
1078 | gpointer value; | |
1079 | ||
1080 | BT_ASSERT(fc); | |
bdb288b3 | 1081 | BT_ASSERT_PRE_DEV_NON_NULL(name, "Name"); |
5cd6d0e5 PP |
1082 | if (!g_hash_table_lookup_extended(fc->name_to_index, name, &orig_key, |
1083 | &value)) { | |
1084 | goto end; | |
1085 | } | |
1086 | ||
45c51519 | 1087 | named_fc = fc->named_fcs->pdata[GPOINTER_TO_UINT(value)]; |
5cd6d0e5 PP |
1088 | |
1089 | end: | |
1e6fd1d7 | 1090 | return named_fc; |
5cd6d0e5 PP |
1091 | } |
1092 | ||
1e6fd1d7 | 1093 | const struct bt_field_class_structure_member * |
7c06e353 | 1094 | bt_field_class_structure_borrow_member_by_name_const( |
40f4ba76 | 1095 | const struct bt_field_class *fc, const char *name) |
5cd6d0e5 | 1096 | { |
bdb288b3 PP |
1097 | BT_ASSERT_PRE_DEV_NON_NULL(fc, "Field class"); |
1098 | BT_ASSERT_PRE_DEV_FC_HAS_ID(fc, BT_FIELD_CLASS_TYPE_STRUCTURE, | |
740faaf4 | 1099 | "Field class"); |
1e6fd1d7 PP |
1100 | return (const void *) |
1101 | borrow_named_field_class_from_container_field_class_by_name( | |
740faaf4 PP |
1102 | (void *) fc, name); |
1103 | } | |
1104 | ||
1e6fd1d7 | 1105 | struct bt_field_class_structure_member * |
fffedc87 | 1106 | bt_field_class_structure_borrow_member_by_name( |
740faaf4 PP |
1107 | struct bt_field_class *fc, const char *name) |
1108 | { | |
bdb288b3 PP |
1109 | BT_ASSERT_PRE_DEV_NON_NULL(fc, "Field class"); |
1110 | BT_ASSERT_PRE_DEV_FC_HAS_ID(fc, BT_FIELD_CLASS_TYPE_STRUCTURE, | |
740faaf4 | 1111 | "Field class"); |
1e6fd1d7 PP |
1112 | return (void *) |
1113 | borrow_named_field_class_from_container_field_class_by_name( | |
40f4ba76 | 1114 | (void *) fc, name); |
e5be10ef PP |
1115 | } |
1116 | ||
1e6fd1d7 PP |
1117 | const char *bt_field_class_structure_member_get_name( |
1118 | const struct bt_field_class_structure_member *member) | |
1119 | { | |
1120 | const struct bt_named_field_class *named_fc = (const void *) member; | |
1121 | ||
bdb288b3 | 1122 | BT_ASSERT_PRE_DEV_NON_NULL(member, "Structure field class member"); |
1e6fd1d7 PP |
1123 | return named_fc->name->str; |
1124 | } | |
1125 | ||
1126 | const struct bt_field_class * | |
1127 | bt_field_class_structure_member_borrow_field_class_const( | |
1128 | const struct bt_field_class_structure_member *member) | |
1129 | { | |
1130 | const struct bt_named_field_class *named_fc = (const void *) member; | |
1131 | ||
bdb288b3 | 1132 | BT_ASSERT_PRE_DEV_NON_NULL(member, "Structure field class member"); |
1e6fd1d7 PP |
1133 | return named_fc->fc; |
1134 | } | |
1135 | ||
bcd7ef6f FD |
1136 | struct bt_field_class * |
1137 | bt_field_class_structure_member_borrow_field_class( | |
1138 | struct bt_field_class_structure_member *member) | |
1139 | { | |
1140 | struct bt_named_field_class *named_fc = (void *) member; | |
1141 | ||
1142 | BT_ASSERT_PRE_DEV_NON_NULL(member, "Structure field class member"); | |
1143 | return named_fc->fc; | |
1144 | } | |
1145 | ||
b38aea74 PP |
1146 | static |
1147 | void destroy_option_field_class(struct bt_object *obj) | |
1148 | { | |
1149 | struct bt_field_class_option *fc = (void *) obj; | |
1150 | ||
1151 | BT_ASSERT(fc); | |
1152 | BT_LIB_LOGD("Destroying option field class object: %!+F", fc); | |
c6962c96 | 1153 | finalize_field_class((void *) obj); |
b38aea74 PP |
1154 | BT_LOGD_STR("Putting content field class."); |
1155 | BT_OBJECT_PUT_REF_AND_RESET(fc->content_fc); | |
0aa006b7 PP |
1156 | |
1157 | if (fc->common.type != BT_FIELD_CLASS_TYPE_OPTION_WITHOUT_SELECTOR) { | |
1158 | struct bt_field_class_option_with_selector *with_sel_fc = | |
1159 | (void *) obj; | |
1160 | ||
1161 | BT_LOGD_STR("Putting selector field path."); | |
1162 | BT_OBJECT_PUT_REF_AND_RESET(with_sel_fc->selector_field_path); | |
1163 | BT_LOGD_STR("Putting selector field class."); | |
1164 | BT_OBJECT_PUT_REF_AND_RESET(with_sel_fc->selector_fc); | |
1165 | ||
1166 | if (fc->common.type != BT_FIELD_CLASS_TYPE_OPTION_WITH_BOOL_SELECTOR) { | |
1167 | struct bt_field_class_option_with_selector_integer *with_int_sel_fc = | |
1168 | (void *) obj; | |
1169 | ||
1170 | BT_LOGD_STR("Putting integer range set."); | |
1171 | BT_OBJECT_PUT_REF_AND_RESET(with_int_sel_fc->range_set); | |
1172 | } | |
1173 | } | |
1174 | ||
b38aea74 PP |
1175 | g_free(fc); |
1176 | } | |
1177 | ||
0aa006b7 PP |
1178 | static |
1179 | struct bt_field_class *create_option_field_class( | |
1180 | struct bt_trace_class *trace_class, | |
1181 | enum bt_field_class_type fc_type, | |
1182 | struct bt_field_class *content_fc, | |
1183 | struct bt_field_class *selector_fc) | |
b38aea74 PP |
1184 | { |
1185 | struct bt_field_class_option *opt_fc = NULL; | |
1186 | ||
1187 | BT_ASSERT_PRE_NON_NULL(trace_class, "Trace class"); | |
1188 | BT_ASSERT_PRE_NON_NULL(content_fc, "Content field class"); | |
1189 | BT_LIB_LOGD("Creating option field class: " | |
0aa006b7 PP |
1190 | "type=%s, %![content-fc-]+F, %![sel-fc-]+F", |
1191 | bt_common_field_class_type_string(fc_type), | |
1192 | content_fc, selector_fc); | |
1193 | ||
1194 | if (fc_type != BT_FIELD_CLASS_TYPE_OPTION_WITHOUT_SELECTOR) { | |
1195 | struct bt_field_class_option_with_selector *opt_with_sel_fc = NULL; | |
1196 | ||
1197 | BT_ASSERT_PRE_NON_NULL(selector_fc, "Selector field class"); | |
1198 | ||
1199 | if (fc_type == BT_FIELD_CLASS_TYPE_OPTION_WITH_BOOL_SELECTOR) { | |
1200 | BT_ASSERT_PRE_FC_HAS_ID(selector_fc, | |
1201 | BT_FIELD_CLASS_TYPE_BOOL, | |
1202 | "Selector field class"); | |
1203 | opt_with_sel_fc = (void *) g_new0( | |
1204 | struct bt_field_class_option_with_selector_bool, 1); | |
1205 | } else { | |
1206 | BT_ASSERT_PRE_FC_IS_INT(selector_fc, | |
1207 | "Selector field class"); | |
1208 | opt_with_sel_fc = (void *) g_new0( | |
1209 | struct bt_field_class_option_with_selector_integer, 1); | |
1210 | } | |
1211 | ||
1212 | if (!opt_with_sel_fc) { | |
1213 | BT_LIB_LOGE_APPEND_CAUSE( | |
1214 | "Failed to allocate one option with selector field class."); | |
1215 | goto error; | |
1216 | } | |
1217 | ||
1218 | opt_with_sel_fc->selector_fc = selector_fc; | |
6871026b | 1219 | bt_object_get_ref_no_null_check(opt_with_sel_fc->selector_fc); |
0aa006b7 PP |
1220 | opt_fc = (void *) opt_with_sel_fc; |
1221 | } else { | |
1222 | opt_fc = g_new0(struct bt_field_class_option, 1); | |
1223 | if (!opt_fc) { | |
1224 | BT_LIB_LOGE_APPEND_CAUSE( | |
1225 | "Failed to allocate one option field class."); | |
1226 | goto error; | |
1227 | } | |
b38aea74 PP |
1228 | } |
1229 | ||
0aa006b7 PP |
1230 | BT_ASSERT(opt_fc); |
1231 | ||
1232 | if (init_field_class((void *) opt_fc, fc_type, | |
c6962c96 PP |
1233 | destroy_option_field_class)) { |
1234 | goto error; | |
1235 | } | |
1236 | ||
b38aea74 | 1237 | opt_fc->content_fc = content_fc; |
6871026b | 1238 | bt_object_get_ref_no_null_check(opt_fc->content_fc); |
b38aea74 PP |
1239 | bt_field_class_freeze(opt_fc->content_fc); |
1240 | ||
1241 | if (selector_fc) { | |
b38aea74 PP |
1242 | bt_field_class_freeze(selector_fc); |
1243 | } | |
1244 | ||
1245 | BT_LIB_LOGD("Created option field class object: " | |
1246 | "%![opt-fc-]+F, %![sel-fc-]+F", opt_fc, selector_fc); | |
1247 | goto end; | |
1248 | ||
1249 | error: | |
1250 | BT_OBJECT_PUT_REF_AND_RESET(opt_fc); | |
1251 | ||
1252 | end: | |
1253 | return (void *) opt_fc; | |
1254 | } | |
1255 | ||
0aa006b7 PP |
1256 | struct bt_field_class *bt_field_class_option_without_selector_create( |
1257 | struct bt_trace_class *trace_class, | |
1258 | struct bt_field_class *content_fc) | |
1259 | { | |
1260 | return create_option_field_class(trace_class, | |
1261 | BT_FIELD_CLASS_TYPE_OPTION_WITHOUT_SELECTOR, | |
1262 | content_fc, NULL); | |
1263 | } | |
1264 | ||
1265 | struct bt_field_class *bt_field_class_option_with_selector_bool_create( | |
1266 | struct bt_trace_class *trace_class, | |
1267 | struct bt_field_class *content_fc, | |
1268 | struct bt_field_class *selector_fc) | |
1269 | { | |
1270 | struct bt_field_class_option_with_selector_bool *fc = | |
1271 | (void *) create_option_field_class(trace_class, | |
1272 | BT_FIELD_CLASS_TYPE_OPTION_WITH_BOOL_SELECTOR, | |
1273 | content_fc, selector_fc); | |
1274 | ||
1275 | if (!fc) { | |
1276 | goto end; | |
1277 | } | |
1278 | ||
1279 | end: | |
1280 | return (void *) fc; | |
1281 | } | |
1282 | ||
1283 | struct bt_field_class * | |
1284 | bt_field_class_option_with_selector_integer_unsigned_create( | |
1285 | struct bt_trace_class *trace_class, | |
1286 | struct bt_field_class *content_fc, | |
1287 | struct bt_field_class *selector_fc, | |
1288 | const struct bt_integer_range_set_unsigned *u_range_set) | |
1289 | { | |
1290 | struct bt_field_class_option_with_selector_integer *fc; | |
1291 | const struct bt_integer_range_set *range_set = | |
1292 | (const void *) u_range_set; | |
1293 | ||
1294 | BT_ASSERT_PRE_NON_NULL(range_set, "Integer range set"); | |
1295 | BT_ASSERT_PRE(range_set->ranges->len > 0, | |
1296 | "Integer range set is empty: %!+R", range_set); | |
1297 | fc = (void *) create_option_field_class(trace_class, | |
1298 | BT_FIELD_CLASS_TYPE_OPTION_WITH_UNSIGNED_INTEGER_SELECTOR, | |
1299 | content_fc, selector_fc); | |
1300 | ||
1301 | if (!fc) { | |
1302 | goto end; | |
1303 | } | |
1304 | ||
1305 | fc->range_set = range_set; | |
6871026b | 1306 | bt_object_get_ref_no_null_check(fc->range_set); |
0aa006b7 PP |
1307 | bt_integer_range_set_freeze(range_set); |
1308 | ||
1309 | end: | |
1310 | return (void *) fc; | |
1311 | } | |
1312 | ||
1313 | struct bt_field_class * | |
1314 | bt_field_class_option_with_selector_integer_signed_create( | |
1315 | struct bt_trace_class *trace_class, | |
1316 | struct bt_field_class *content_fc, | |
1317 | struct bt_field_class *selector_fc, | |
1318 | const struct bt_integer_range_set_signed *i_range_set) | |
1319 | { | |
1320 | struct bt_field_class_option_with_selector_integer *fc; | |
1321 | const struct bt_integer_range_set *range_set = | |
1322 | (const void *) i_range_set; | |
1323 | ||
1324 | BT_ASSERT_PRE_NON_NULL(range_set, "Integer range set"); | |
1325 | BT_ASSERT_PRE(range_set->ranges->len > 0, | |
1326 | "Integer range set is empty: %!+R", range_set); | |
1327 | fc = (void *) create_option_field_class(trace_class, | |
1328 | BT_FIELD_CLASS_TYPE_OPTION_WITH_SIGNED_INTEGER_SELECTOR, | |
1329 | content_fc, selector_fc); | |
1330 | ||
1331 | if (!fc) { | |
1332 | goto end; | |
1333 | } | |
1334 | ||
1335 | fc->range_set = range_set; | |
6871026b | 1336 | bt_object_get_ref_no_null_check(fc->range_set); |
0aa006b7 PP |
1337 | bt_integer_range_set_freeze(range_set); |
1338 | ||
1339 | end: | |
1340 | return (void *) fc; | |
1341 | } | |
1342 | ||
b38aea74 PP |
1343 | const struct bt_field_class *bt_field_class_option_borrow_field_class_const( |
1344 | const struct bt_field_class *fc) | |
1345 | { | |
1346 | struct bt_field_class_option *opt_fc = (void *) fc; | |
1347 | ||
1348 | BT_ASSERT_PRE_NON_NULL(fc, "Field class"); | |
0aa006b7 | 1349 | BT_ASSERT_PRE_FC_IS_OPTION(fc, "Field class"); |
b38aea74 PP |
1350 | return opt_fc->content_fc; |
1351 | } | |
1352 | ||
bcd7ef6f FD |
1353 | struct bt_field_class *bt_field_class_option_borrow_field_class( |
1354 | struct bt_field_class *fc) | |
1355 | { | |
1356 | struct bt_field_class_option *opt_fc = (void *) fc; | |
1357 | ||
1358 | BT_ASSERT_PRE_NON_NULL(fc, "Field class"); | |
0aa006b7 | 1359 | BT_ASSERT_PRE_FC_IS_OPTION(fc, "Field class"); |
bcd7ef6f FD |
1360 | return opt_fc->content_fc; |
1361 | } | |
1362 | ||
b38aea74 | 1363 | const struct bt_field_path * |
0aa006b7 | 1364 | bt_field_class_option_with_selector_borrow_selector_field_path_const( |
b38aea74 PP |
1365 | const struct bt_field_class *fc) |
1366 | { | |
0aa006b7 PP |
1367 | const struct bt_field_class_option_with_selector *opt_fc = |
1368 | (const void *) fc; | |
b38aea74 PP |
1369 | |
1370 | BT_ASSERT_PRE_NON_NULL(fc, "Field class"); | |
0aa006b7 | 1371 | BT_ASSERT_PRE_FC_IS_OPTION_WITH_SEL(fc, "Field class"); |
b38aea74 PP |
1372 | return opt_fc->selector_field_path; |
1373 | } | |
1374 | ||
0aa006b7 PP |
1375 | void bt_field_class_option_with_selector_bool_set_selector_is_reversed( |
1376 | struct bt_field_class *fc, bt_bool sel_is_reversed) | |
1377 | { | |
1378 | struct bt_field_class_option_with_selector_bool *opt_fc = (void *) fc; | |
1379 | ||
1380 | BT_ASSERT_PRE_NON_NULL(fc, "Field class"); | |
1381 | BT_ASSERT_PRE_FC_HAS_ID(fc, | |
1382 | BT_FIELD_CLASS_TYPE_OPTION_WITH_BOOL_SELECTOR, "Field class"); | |
1383 | BT_ASSERT_PRE_DEV_FC_HOT(fc, "Field class"); | |
1384 | opt_fc->sel_is_reversed = sel_is_reversed; | |
1385 | } | |
1386 | ||
1387 | bt_bool bt_field_class_option_with_selector_bool_selector_is_reversed( | |
1388 | const struct bt_field_class *fc) | |
1389 | { | |
1390 | struct bt_field_class_option_with_selector_bool *opt_fc = (void *) fc; | |
1391 | ||
1392 | BT_ASSERT_PRE_NON_NULL(fc, "Field class"); | |
1393 | BT_ASSERT_PRE_FC_HAS_ID(fc, | |
1394 | BT_FIELD_CLASS_TYPE_OPTION_WITH_BOOL_SELECTOR, "Field class"); | |
1395 | return opt_fc->sel_is_reversed; | |
1396 | } | |
1397 | ||
1398 | const struct bt_integer_range_set_unsigned * | |
1399 | bt_field_class_option_with_selector_integer_unsigned_borrow_selector_ranges_const( | |
1400 | const struct bt_field_class *fc) | |
1401 | { | |
1402 | struct bt_field_class_option_with_selector_integer *opt_fc = | |
1403 | (void *) fc; | |
1404 | ||
1405 | BT_ASSERT_PRE_NON_NULL(fc, "Field class"); | |
1406 | BT_ASSERT_PRE_FC_IS_OPTION_WITH_INT_SEL(fc, "Field class"); | |
1407 | return (const void *) opt_fc->range_set; | |
1408 | } | |
1409 | ||
1410 | const struct bt_integer_range_set_signed * | |
1411 | bt_field_class_option_with_selector_integer_signed_borrow_selector_ranges_const( | |
1412 | const struct bt_field_class *fc) | |
1413 | { | |
1414 | struct bt_field_class_option_with_selector_integer *opt_fc = | |
1415 | (void *) fc; | |
1416 | ||
1417 | BT_ASSERT_PRE_NON_NULL(fc, "Field class"); | |
1418 | BT_ASSERT_PRE_FC_IS_OPTION_WITH_INT_SEL(fc, "Field class"); | |
1419 | return (const void *) opt_fc->range_set; | |
1420 | } | |
1421 | ||
45c51519 PP |
1422 | static |
1423 | void finalize_variant_field_class(struct bt_field_class_variant *var_fc) | |
1e6fd1d7 | 1424 | { |
45c51519 PP |
1425 | BT_ASSERT(var_fc); |
1426 | BT_LIB_LOGD("Finalizing variant field class object: %!+F", var_fc); | |
c6962c96 | 1427 | finalize_field_class((void *) var_fc); |
45c51519 | 1428 | finalize_named_field_classes_container((void *) var_fc); |
1e6fd1d7 PP |
1429 | } |
1430 | ||
5cd6d0e5 PP |
1431 | static |
1432 | void destroy_variant_field_class(struct bt_object *obj) | |
1433 | { | |
1434 | struct bt_field_class_variant *fc = (void *) obj; | |
1435 | ||
1436 | BT_ASSERT(fc); | |
45c51519 PP |
1437 | finalize_variant_field_class(fc); |
1438 | g_free(fc); | |
1439 | } | |
1440 | ||
1441 | static | |
1442 | void destroy_variant_with_selector_field_class(struct bt_object *obj) | |
1443 | { | |
1444 | struct bt_field_class_variant_with_selector *fc = (void *) obj; | |
1445 | ||
1446 | BT_ASSERT(fc); | |
1447 | finalize_variant_field_class(&fc->common); | |
5cd6d0e5 | 1448 | BT_LOGD_STR("Putting selector field path."); |
238b7404 PP |
1449 | BT_OBJECT_PUT_REF_AND_RESET(fc->selector_field_path); |
1450 | BT_LOGD_STR("Putting selector field class."); | |
1451 | BT_OBJECT_PUT_REF_AND_RESET(fc->selector_fc); | |
5cd6d0e5 PP |
1452 | g_free(fc); |
1453 | } | |
1454 | ||
1122a43a | 1455 | struct bt_field_class *bt_field_class_variant_create( |
45c51519 | 1456 | bt_trace_class *trace_class, bt_field_class *selector_fc) |
5cd6d0e5 PP |
1457 | { |
1458 | int ret; | |
1459 | struct bt_field_class_variant *var_fc = NULL; | |
45c51519 PP |
1460 | struct bt_field_class_variant_with_selector *var_with_sel_fc = NULL; |
1461 | enum bt_field_class_type fc_type; | |
5cd6d0e5 | 1462 | |
1122a43a | 1463 | BT_ASSERT_PRE_NON_NULL(trace_class, "Trace class"); |
45c51519 PP |
1464 | |
1465 | if (selector_fc) { | |
1466 | BT_ASSERT_PRE_FC_IS_INT(selector_fc, "Selector field class"); | |
5cd6d0e5 PP |
1467 | } |
1468 | ||
45c51519 PP |
1469 | BT_LIB_LOGD("Creating default variant field class: %![sel-fc-]+F", |
1470 | selector_fc); | |
1471 | ||
1472 | if (selector_fc) { | |
1473 | var_with_sel_fc = g_new0( | |
1474 | struct bt_field_class_variant_with_selector, 1); | |
1475 | if (!var_with_sel_fc) { | |
1476 | BT_LIB_LOGE_APPEND_CAUSE( | |
1477 | "Failed to allocate one variant field class with selector."); | |
1478 | goto error; | |
1479 | } | |
1480 | ||
1481 | if (selector_fc->type == BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER || | |
1482 | selector_fc->type == BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION) { | |
fabfe034 | 1483 | fc_type = BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_INTEGER_SELECTOR; |
45c51519 | 1484 | } else { |
fabfe034 | 1485 | fc_type = BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR; |
45c51519 PP |
1486 | } |
1487 | ||
1488 | ret = init_named_field_classes_container( | |
1489 | (void *) var_with_sel_fc, fc_type, | |
1490 | destroy_variant_with_selector_field_class, | |
1491 | destroy_variant_with_selector_option); | |
1492 | if (ret) { | |
1493 | /* init_named_field_classes_container() logs errors */ | |
1494 | goto error; | |
1495 | } | |
1496 | ||
1497 | var_with_sel_fc->selector_fc = selector_fc; | |
6871026b | 1498 | bt_object_get_ref_no_null_check(var_with_sel_fc->selector_fc); |
45c51519 PP |
1499 | bt_field_class_freeze(selector_fc); |
1500 | var_fc = (void *) var_with_sel_fc; | |
d166032f FD |
1501 | BT_LIB_LOGD("Created default variant field class with selector object: " |
1502 | "%![var-fc-]+F, %![sel-fc-]+F", var_fc, selector_fc); | |
45c51519 PP |
1503 | } else { |
1504 | var_fc = g_new0(struct bt_field_class_variant, 1); | |
1505 | if (!var_fc) { | |
1506 | BT_LIB_LOGE_APPEND_CAUSE( | |
1507 | "Failed to allocate one variant field class without selector."); | |
1508 | goto error; | |
1509 | } | |
1510 | ||
1511 | ret = init_named_field_classes_container((void *) var_fc, | |
1512 | BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR, | |
1513 | destroy_variant_field_class, destroy_named_field_class); | |
1514 | if (ret) { | |
1515 | /* init_named_field_classes_container() logs errors */ | |
1516 | goto error; | |
1517 | } | |
d166032f FD |
1518 | BT_LIB_LOGD("Created default variant field class without selector object: " |
1519 | "%![var-fc-]+F", var_fc); | |
5cd6d0e5 PP |
1520 | } |
1521 | ||
45c51519 | 1522 | BT_ASSERT(var_fc); |
5cd6d0e5 PP |
1523 | goto end; |
1524 | ||
1525 | error: | |
65300d60 | 1526 | BT_OBJECT_PUT_REF_AND_RESET(var_fc); |
9fdff45c | 1527 | BT_OBJECT_PUT_REF_AND_RESET(var_with_sel_fc); |
5cd6d0e5 PP |
1528 | |
1529 | end: | |
1530 | return (void *) var_fc; | |
1531 | } | |
1532 | ||
45c51519 PP |
1533 | enum bt_field_class_variant_without_selector_append_option_status |
1534 | bt_field_class_variant_without_selector_append_option(struct bt_field_class *fc, | |
1535 | const char *name, struct bt_field_class *option_fc) | |
1536 | { | |
1537 | enum bt_field_class_variant_without_selector_append_option_status status; | |
1538 | struct bt_named_field_class *named_fc = NULL; | |
1539 | ||
1540 | BT_ASSERT_PRE_NON_NULL(fc, "Field class"); | |
1541 | BT_ASSERT_PRE_NON_NULL(name, "Name"); | |
1542 | BT_ASSERT_PRE_NON_NULL(option_fc, "Option field class"); | |
1543 | BT_ASSERT_PRE_FC_HAS_ID(fc, | |
1544 | BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR, "Field class"); | |
1545 | named_fc = create_named_field_class(name, option_fc); | |
1546 | if (!named_fc) { | |
1547 | /* create_named_field_class() logs errors */ | |
1548 | status = BT_FUNC_STATUS_MEMORY_ERROR; | |
1549 | goto end; | |
1550 | } | |
1551 | ||
1552 | status = append_named_field_class_to_container_field_class((void *) fc, | |
1553 | named_fc); | |
1554 | if (status == BT_FUNC_STATUS_OK) { | |
1555 | /* Moved to the container */ | |
1556 | named_fc = NULL; | |
1557 | } | |
1558 | ||
1559 | end: | |
1560 | if (named_fc) { | |
1561 | destroy_named_field_class(named_fc); | |
1562 | } | |
1563 | ||
1564 | return status; | |
5cd6d0e5 PP |
1565 | } |
1566 | ||
45c51519 PP |
1567 | static |
1568 | int ranges_overlap(GPtrArray *var_fc_opts, const struct bt_integer_range_set *range_set, | |
1569 | bool is_signed, bool *has_overlap) | |
1570 | { | |
1571 | int status = BT_FUNC_STATUS_OK; | |
1572 | struct bt_integer_range_set *full_range_set; | |
1573 | uint64_t i; | |
1574 | ||
1575 | *has_overlap = false; | |
1576 | ||
1577 | /* | |
1578 | * Build a single range set with all the ranges and test for | |
1579 | * overlaps. | |
1580 | */ | |
1581 | if (is_signed) { | |
1582 | full_range_set = (void *) bt_integer_range_set_signed_create(); | |
1583 | } else { | |
1584 | full_range_set = (void *) bt_integer_range_set_unsigned_create(); | |
1585 | } | |
1586 | ||
1587 | if (!full_range_set) { | |
1588 | BT_LOGE_STR("Failed to create a range set."); | |
1589 | status = BT_FUNC_STATUS_MEMORY_ERROR; | |
1590 | goto end; | |
1591 | } | |
1592 | ||
1593 | /* Add existing option ranges */ | |
1594 | for (i = 0; i < var_fc_opts->len; i++) { | |
1595 | struct bt_field_class_variant_with_selector_option *opt = | |
1596 | var_fc_opts->pdata[i]; | |
1597 | uint64_t j; | |
1598 | ||
1599 | for (j = 0; j < opt->range_set->ranges->len; j++) { | |
1600 | struct bt_integer_range *range = BT_INTEGER_RANGE_SET_RANGE_AT_INDEX( | |
1601 | opt->range_set, j); | |
1602 | ||
1603 | if (is_signed) { | |
1604 | status = bt_integer_range_set_signed_add_range( | |
1605 | (void *) full_range_set, range->lower.i, | |
1606 | range->upper.i); | |
1607 | } else { | |
1608 | status = bt_integer_range_set_unsigned_add_range( | |
1609 | (void *) full_range_set, range->lower.u, | |
1610 | range->upper.u); | |
1611 | } | |
1612 | ||
1613 | if (status) { | |
1614 | goto end; | |
1615 | } | |
1616 | } | |
1617 | } | |
1618 | ||
1619 | /* Add new ranges */ | |
1620 | for (i = 0; i < range_set->ranges->len; i++) { | |
1621 | struct bt_integer_range *range = BT_INTEGER_RANGE_SET_RANGE_AT_INDEX( | |
1622 | range_set, i); | |
1623 | ||
1624 | if (is_signed) { | |
1625 | status = bt_integer_range_set_signed_add_range( | |
1626 | (void *) full_range_set, range->lower.i, | |
1627 | range->upper.i); | |
1628 | } else { | |
1629 | status = bt_integer_range_set_unsigned_add_range( | |
1630 | (void *) full_range_set, range->lower.u, | |
1631 | range->upper.u); | |
1632 | } | |
1633 | ||
1634 | if (status) { | |
1635 | goto end; | |
1636 | } | |
1637 | } | |
1638 | ||
1639 | /* Check overlaps */ | |
1640 | if (is_signed) { | |
1641 | *has_overlap = bt_integer_range_set_signed_has_overlaps(full_range_set); | |
1642 | } else { | |
1643 | *has_overlap = bt_integer_range_set_unsigned_has_overlaps( | |
1644 | full_range_set); | |
1645 | } | |
1646 | ||
1647 | end: | |
1648 | bt_object_put_ref(full_range_set); | |
1649 | return status; | |
1650 | } | |
1651 | ||
1652 | static | |
1653 | int append_option_to_variant_with_selector_field_class( | |
1654 | struct bt_field_class *fc, const char *name, | |
1655 | struct bt_field_class *option_fc, | |
1656 | const struct bt_integer_range_set *range_set, | |
1657 | enum bt_field_class_type expected_type) | |
5cd6d0e5 | 1658 | { |
45c51519 PP |
1659 | int status; |
1660 | struct bt_field_class_variant_with_selector *var_fc = (void *) fc; | |
1661 | struct bt_field_class_variant_with_selector_option *opt = NULL; | |
1662 | bool has_overlap; | |
e5be10ef | 1663 | |
5cd6d0e5 | 1664 | BT_ASSERT_PRE_NON_NULL(fc, "Field class"); |
45c51519 PP |
1665 | BT_ASSERT_PRE_NON_NULL(name, "Name"); |
1666 | BT_ASSERT_PRE_NON_NULL(option_fc, "Option field class"); | |
6769570a | 1667 | BT_ASSERT_PRE_NON_NULL(range_set, "Integer range set"); |
45c51519 PP |
1668 | BT_ASSERT_PRE_FC_HAS_ID(fc, expected_type, "Field class"); |
1669 | BT_ASSERT_PRE(range_set->ranges->len > 0, | |
6769570a | 1670 | "Integer range set is empty: %!+R", range_set); |
45c51519 | 1671 | status = ranges_overlap(var_fc->common.common.named_fcs, range_set, |
fabfe034 | 1672 | expected_type == BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR, |
45c51519 PP |
1673 | &has_overlap); |
1674 | if (status) { | |
1675 | /* ranges_overlap() logs errors */ | |
1676 | goto end; | |
1677 | } | |
1678 | ||
1679 | BT_ASSERT_PRE(!has_overlap, | |
6769570a PP |
1680 | "Integer range set's ranges and existing ranges have an overlap: " |
1681 | "%!+R", range_set); | |
45c51519 PP |
1682 | opt = create_variant_with_selector_option(name, option_fc, range_set); |
1683 | if (!opt) { | |
1684 | /* create_variant_with_selector_option() logs errors */ | |
1685 | status = BT_FUNC_STATUS_MEMORY_ERROR; | |
1686 | goto end; | |
1687 | } | |
1688 | ||
1689 | status = append_named_field_class_to_container_field_class((void *) fc, | |
1690 | &opt->common); | |
1691 | if (status == BT_FUNC_STATUS_OK) { | |
1692 | /* Moved to the container */ | |
1693 | opt = NULL; | |
1694 | } | |
1695 | ||
1696 | end: | |
1697 | if (opt) { | |
1698 | destroy_variant_with_selector_option(opt); | |
1699 | } | |
1700 | ||
1701 | return status; | |
1702 | } | |
1703 | ||
fabfe034 PP |
1704 | enum bt_field_class_variant_with_selector_integer_append_option_status |
1705 | bt_field_class_variant_with_selector_integer_unsigned_append_option( | |
45c51519 PP |
1706 | struct bt_field_class *fc, const char *name, |
1707 | struct bt_field_class *option_fc, | |
1708 | const struct bt_integer_range_set_unsigned *range_set) | |
1709 | { | |
1710 | return append_option_to_variant_with_selector_field_class(fc, | |
1711 | name, option_fc, (const void *) range_set, | |
fabfe034 | 1712 | BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_INTEGER_SELECTOR); |
45c51519 PP |
1713 | } |
1714 | ||
fabfe034 PP |
1715 | enum bt_field_class_variant_with_selector_integer_append_option_status |
1716 | bt_field_class_variant_with_selector_integer_signed_append_option( | |
45c51519 PP |
1717 | struct bt_field_class *fc, const char *name, |
1718 | struct bt_field_class *option_fc, | |
1719 | const struct bt_integer_range_set_signed *range_set) | |
1720 | { | |
1721 | return append_option_to_variant_with_selector_field_class(fc, | |
1722 | name, option_fc, (const void *) range_set, | |
fabfe034 | 1723 | BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR); |
45c51519 PP |
1724 | } |
1725 | ||
1726 | uint64_t bt_field_class_variant_get_option_count(const struct bt_field_class *fc) | |
1727 | { | |
1728 | const struct bt_field_class_variant *var_fc = (const void *) fc; | |
1729 | ||
1730 | BT_ASSERT_PRE_DEV_NON_NULL(fc, "Field class"); | |
1731 | BT_ASSERT_PRE_DEV_FC_IS_VARIANT(fc, "Field class"); | |
1732 | return (uint64_t) var_fc->common.named_fcs->len; | |
5cd6d0e5 PP |
1733 | } |
1734 | ||
1e6fd1d7 | 1735 | const struct bt_field_class_variant_option * |
7c06e353 | 1736 | bt_field_class_variant_borrow_option_by_name_const( |
40f4ba76 | 1737 | const struct bt_field_class *fc, const char *name) |
5cd6d0e5 | 1738 | { |
bdb288b3 | 1739 | BT_ASSERT_PRE_DEV_NON_NULL(fc, "Field class"); |
45c51519 | 1740 | BT_ASSERT_PRE_DEV_FC_IS_VARIANT(fc, "Field class"); |
1e6fd1d7 PP |
1741 | return (const void *) |
1742 | borrow_named_field_class_from_container_field_class_by_name( | |
1743 | (void *) fc, name); | |
740faaf4 PP |
1744 | } |
1745 | ||
45c51519 PP |
1746 | const struct bt_field_class_variant_option * |
1747 | bt_field_class_variant_borrow_option_by_index_const( | |
1748 | const struct bt_field_class *fc, uint64_t index) | |
740faaf4 | 1749 | { |
bdb288b3 | 1750 | BT_ASSERT_PRE_DEV_NON_NULL(fc, "Field class"); |
45c51519 PP |
1751 | BT_ASSERT_PRE_DEV_FC_IS_VARIANT(fc, "Field class"); |
1752 | return (const void *) | |
1753 | borrow_named_field_class_from_container_field_class_at_index( | |
c6fe8c40 PP |
1754 | (void *) fc, index); |
1755 | } | |
1756 | ||
1757 | struct bt_field_class_variant_option * | |
1758 | bt_field_class_variant_borrow_option_by_name( | |
1759 | struct bt_field_class *fc, const char *name) | |
1760 | { | |
1761 | BT_ASSERT_PRE_DEV_NON_NULL(fc, "Field class"); | |
1762 | BT_ASSERT_PRE_DEV_FC_IS_VARIANT(fc, "Field class"); | |
1763 | return (void *) | |
1764 | borrow_named_field_class_from_container_field_class_by_name( | |
1765 | (void *) fc, name); | |
1766 | } | |
1767 | ||
1768 | struct bt_field_class_variant_option * | |
1769 | bt_field_class_variant_borrow_option_by_index( | |
1770 | struct bt_field_class *fc, uint64_t index) | |
1771 | { | |
1772 | BT_ASSERT_PRE_DEV_NON_NULL(fc, "Field class"); | |
1773 | BT_ASSERT_PRE_DEV_FC_IS_VARIANT(fc, "Field class"); | |
1774 | return (void *) | |
1775 | borrow_named_field_class_from_container_field_class_at_index( | |
45c51519 | 1776 | (void *) fc, index); |
e5be10ef PP |
1777 | } |
1778 | ||
fabfe034 PP |
1779 | const struct bt_field_class_variant_with_selector_integer_unsigned_option * |
1780 | bt_field_class_variant_with_selector_integer_unsigned_borrow_option_by_name_const( | |
45c51519 | 1781 | const struct bt_field_class *fc, const char *name) |
5cd6d0e5 | 1782 | { |
bdb288b3 | 1783 | BT_ASSERT_PRE_DEV_NON_NULL(fc, "Field class"); |
45c51519 | 1784 | BT_ASSERT_PRE_DEV_FC_HAS_ID(fc, |
fabfe034 | 1785 | BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_INTEGER_SELECTOR, |
45c51519 PP |
1786 | "Field class"); |
1787 | return (const void *) | |
1788 | borrow_named_field_class_from_container_field_class_by_name( | |
1789 | (void *) fc, name); | |
5cd6d0e5 PP |
1790 | } |
1791 | ||
fabfe034 PP |
1792 | const struct bt_field_class_variant_with_selector_integer_unsigned_option * |
1793 | bt_field_class_variant_with_selector_integer_unsigned_borrow_option_by_index_const( | |
1e6fd1d7 | 1794 | const struct bt_field_class *fc, uint64_t index) |
5cd6d0e5 | 1795 | { |
bdb288b3 | 1796 | BT_ASSERT_PRE_DEV_NON_NULL(fc, "Field class"); |
45c51519 | 1797 | BT_ASSERT_PRE_DEV_FC_HAS_ID(fc, |
fabfe034 | 1798 | BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_INTEGER_SELECTOR, |
45c51519 | 1799 | "Field class"); |
1e6fd1d7 PP |
1800 | return (const void *) |
1801 | borrow_named_field_class_from_container_field_class_at_index( | |
1802 | (void *) fc, index); | |
740faaf4 PP |
1803 | } |
1804 | ||
fabfe034 PP |
1805 | const struct bt_field_class_variant_with_selector_integer_signed_option * |
1806 | bt_field_class_variant_with_selector_integer_signed_borrow_option_by_name_const( | |
45c51519 | 1807 | const struct bt_field_class *fc, const char *name) |
740faaf4 | 1808 | { |
bdb288b3 | 1809 | BT_ASSERT_PRE_DEV_NON_NULL(fc, "Field class"); |
45c51519 | 1810 | BT_ASSERT_PRE_DEV_FC_HAS_ID(fc, |
fabfe034 | 1811 | BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR, |
45c51519 PP |
1812 | "Field class"); |
1813 | return (const void *) | |
1814 | borrow_named_field_class_from_container_field_class_by_name( | |
1815 | (void *) fc, name); | |
1816 | } | |
1817 | ||
fabfe034 PP |
1818 | const struct bt_field_class_variant_with_selector_integer_signed_option * |
1819 | bt_field_class_variant_with_selector_integer_signed_borrow_option_by_index_const( | |
45c51519 PP |
1820 | const struct bt_field_class *fc, uint64_t index) |
1821 | { | |
1822 | BT_ASSERT_PRE_DEV_NON_NULL(fc, "Field class"); | |
1823 | BT_ASSERT_PRE_DEV_FC_HAS_ID(fc, | |
fabfe034 | 1824 | BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR, |
45c51519 PP |
1825 | "Field class"); |
1826 | return (const void *) | |
1e6fd1d7 PP |
1827 | borrow_named_field_class_from_container_field_class_at_index( |
1828 | (void *) fc, index); | |
1829 | } | |
1830 | ||
1831 | const char *bt_field_class_variant_option_get_name( | |
1832 | const struct bt_field_class_variant_option *option) | |
1833 | { | |
1834 | const struct bt_named_field_class *named_fc = (const void *) option; | |
1835 | ||
bdb288b3 | 1836 | BT_ASSERT_PRE_DEV_NON_NULL(option, "Variant field class option"); |
1e6fd1d7 PP |
1837 | return named_fc->name->str; |
1838 | } | |
1839 | ||
1840 | const struct bt_field_class * | |
1841 | bt_field_class_variant_option_borrow_field_class_const( | |
1842 | const struct bt_field_class_variant_option *option) | |
1843 | { | |
1844 | const struct bt_named_field_class *named_fc = (const void *) option; | |
1845 | ||
bdb288b3 | 1846 | BT_ASSERT_PRE_DEV_NON_NULL(option, "Variant field class option"); |
1e6fd1d7 PP |
1847 | return named_fc->fc; |
1848 | } | |
1849 | ||
bcd7ef6f FD |
1850 | struct bt_field_class * |
1851 | bt_field_class_variant_option_borrow_field_class( | |
1852 | struct bt_field_class_variant_option *option) | |
1853 | { | |
1854 | struct bt_named_field_class *named_fc = (void *) option; | |
1855 | ||
1856 | BT_ASSERT_PRE_DEV_NON_NULL(option, "Variant field class option"); | |
1857 | return named_fc->fc; | |
1858 | } | |
1859 | ||
45c51519 | 1860 | const struct bt_integer_range_set_unsigned * |
fabfe034 PP |
1861 | bt_field_class_variant_with_selector_integer_unsigned_option_borrow_ranges_const( |
1862 | const struct bt_field_class_variant_with_selector_integer_unsigned_option *option) | |
1e6fd1d7 | 1863 | { |
45c51519 PP |
1864 | const struct bt_field_class_variant_with_selector_option *opt = |
1865 | (const void *) option; | |
1e6fd1d7 | 1866 | |
bdb288b3 | 1867 | BT_ASSERT_PRE_DEV_NON_NULL(option, "Variant field class option"); |
45c51519 PP |
1868 | return (const void *) opt->range_set; |
1869 | } | |
1870 | ||
1871 | const struct bt_integer_range_set_signed * | |
fabfe034 PP |
1872 | bt_field_class_variant_with_selector_integer_signed_option_borrow_ranges_const( |
1873 | const struct bt_field_class_variant_with_selector_integer_signed_option *option) | |
45c51519 PP |
1874 | { |
1875 | const struct bt_field_class_variant_with_selector_option *opt = | |
1876 | (const void *) option; | |
1877 | ||
1878 | BT_ASSERT_PRE_DEV_NON_NULL(option, "Variant field class option"); | |
1879 | return (const void *) opt->range_set; | |
5cd6d0e5 PP |
1880 | } |
1881 | ||
40f4ba76 | 1882 | const struct bt_field_path * |
45c51519 | 1883 | bt_field_class_variant_with_selector_borrow_selector_field_path_const( |
40f4ba76 | 1884 | const struct bt_field_class *fc) |
e5be10ef | 1885 | { |
45c51519 PP |
1886 | const struct bt_field_class_variant_with_selector *var_fc = |
1887 | (const void *) fc; | |
5cd6d0e5 | 1888 | |
bdb288b3 | 1889 | BT_ASSERT_PRE_DEV_NON_NULL(fc, "Field class"); |
45c51519 | 1890 | BT_ASSERT_PRE_DEV_FC_IS_VARIANT_WITH_SEL(fc, "Field class"); |
5cd6d0e5 PP |
1891 | return var_fc->selector_field_path; |
1892 | } | |
1893 | ||
1894 | static | |
c6962c96 | 1895 | int init_array_field_class(struct bt_field_class_array *fc, |
864cad70 | 1896 | enum bt_field_class_type type, bt_object_release_func release_func, |
5cd6d0e5 PP |
1897 | struct bt_field_class *element_fc) |
1898 | { | |
c6962c96 PP |
1899 | int ret; |
1900 | ||
5cd6d0e5 | 1901 | BT_ASSERT(element_fc); |
c6962c96 PP |
1902 | ret = init_field_class((void *) fc, type, release_func); |
1903 | if (ret) { | |
1904 | goto end; | |
1905 | } | |
1906 | ||
398454ed | 1907 | fc->element_fc = element_fc; |
6871026b | 1908 | bt_object_get_ref_no_null_check(fc->element_fc); |
5cd6d0e5 | 1909 | bt_field_class_freeze(element_fc); |
c6962c96 PP |
1910 | |
1911 | end: | |
1912 | return ret; | |
5cd6d0e5 PP |
1913 | } |
1914 | ||
1915 | static | |
1916 | void finalize_array_field_class(struct bt_field_class_array *array_fc) | |
1917 | { | |
1918 | BT_ASSERT(array_fc); | |
e5be10ef | 1919 | BT_LOGD_STR("Putting element field class."); |
c6962c96 | 1920 | finalize_field_class((void *) array_fc); |
238b7404 | 1921 | BT_OBJECT_PUT_REF_AND_RESET(array_fc->element_fc); |
5cd6d0e5 PP |
1922 | } |
1923 | ||
1924 | static | |
1925 | void destroy_static_array_field_class(struct bt_object *obj) | |
1926 | { | |
1927 | BT_ASSERT(obj); | |
e5be10ef | 1928 | BT_LIB_LOGD("Destroying static array field class object: %!+F", obj); |
5cd6d0e5 PP |
1929 | finalize_array_field_class((void *) obj); |
1930 | g_free(obj); | |
1931 | } | |
1932 | ||
40f4ba76 | 1933 | struct bt_field_class * |
9c08c816 | 1934 | bt_field_class_array_static_create(bt_trace_class *trace_class, |
1122a43a | 1935 | struct bt_field_class *element_fc, uint64_t length) |
5cd6d0e5 | 1936 | { |
9c08c816 | 1937 | struct bt_field_class_array_static *array_fc = NULL; |
5cd6d0e5 | 1938 | |
1122a43a | 1939 | BT_ASSERT_PRE_NON_NULL(trace_class, "Trace class"); |
e5be10ef PP |
1940 | BT_ASSERT_PRE_NON_NULL(element_fc, "Element field class"); |
1941 | BT_LOGD_STR("Creating default static array field class object."); | |
9c08c816 | 1942 | array_fc = g_new0(struct bt_field_class_array_static, 1); |
5cd6d0e5 | 1943 | if (!array_fc) { |
870631a2 PP |
1944 | BT_LIB_LOGE_APPEND_CAUSE( |
1945 | "Failed to allocate one static array field class."); | |
5cd6d0e5 PP |
1946 | goto error; |
1947 | } | |
1948 | ||
c6962c96 PP |
1949 | if (init_array_field_class((void *) array_fc, |
1950 | BT_FIELD_CLASS_TYPE_STATIC_ARRAY, | |
1951 | destroy_static_array_field_class, element_fc)) { | |
1952 | goto error; | |
1953 | } | |
1954 | ||
5cd6d0e5 | 1955 | array_fc->length = length; |
e5be10ef | 1956 | BT_LIB_LOGD("Created static array field class object: %!+F", array_fc); |
5cd6d0e5 PP |
1957 | goto end; |
1958 | ||
1959 | error: | |
65300d60 | 1960 | BT_OBJECT_PUT_REF_AND_RESET(array_fc); |
5cd6d0e5 PP |
1961 | |
1962 | end: | |
1963 | return (void *) array_fc; | |
1964 | } | |
1965 | ||
40f4ba76 PP |
1966 | const struct bt_field_class * |
1967 | bt_field_class_array_borrow_element_field_class_const( | |
1968 | const struct bt_field_class *fc) | |
5cd6d0e5 | 1969 | { |
40f4ba76 | 1970 | const struct bt_field_class_array *array_fc = (const void *) fc; |
5cd6d0e5 | 1971 | |
bdb288b3 PP |
1972 | BT_ASSERT_PRE_DEV_NON_NULL(fc, "Field class"); |
1973 | BT_ASSERT_PRE_DEV_FC_IS_ARRAY(fc, "Field class"); | |
5cd6d0e5 PP |
1974 | return array_fc->element_fc; |
1975 | } | |
1976 | ||
740faaf4 PP |
1977 | struct bt_field_class * |
1978 | bt_field_class_array_borrow_element_field_class(struct bt_field_class *fc) | |
1979 | { | |
1980 | struct bt_field_class_array *array_fc = (void *) fc; | |
1981 | ||
bdb288b3 PP |
1982 | BT_ASSERT_PRE_DEV_NON_NULL(fc, "Field class"); |
1983 | BT_ASSERT_PRE_DEV_FC_IS_ARRAY(fc, "Field class"); | |
740faaf4 PP |
1984 | return array_fc->element_fc; |
1985 | } | |
1986 | ||
9c08c816 | 1987 | uint64_t bt_field_class_array_static_get_length(const struct bt_field_class *fc) |
e5be10ef | 1988 | { |
9c08c816 | 1989 | const struct bt_field_class_array_static *array_fc = (const void *) fc; |
5cd6d0e5 | 1990 | |
bdb288b3 PP |
1991 | BT_ASSERT_PRE_DEV_NON_NULL(fc, "Field class"); |
1992 | BT_ASSERT_PRE_DEV_FC_HAS_ID(fc, BT_FIELD_CLASS_TYPE_STATIC_ARRAY, | |
5cd6d0e5 PP |
1993 | "Field class"); |
1994 | return (uint64_t) array_fc->length; | |
1995 | } | |
1996 | ||
1997 | static | |
1998 | void destroy_dynamic_array_field_class(struct bt_object *obj) | |
1999 | { | |
9c08c816 | 2000 | struct bt_field_class_array_dynamic *fc = (void *) obj; |
5cd6d0e5 PP |
2001 | |
2002 | BT_ASSERT(fc); | |
e5be10ef | 2003 | BT_LIB_LOGD("Destroying dynamic array field class object: %!+F", fc); |
5cd6d0e5 PP |
2004 | finalize_array_field_class((void *) fc); |
2005 | BT_LOGD_STR("Putting length field path."); | |
238b7404 PP |
2006 | BT_OBJECT_PUT_REF_AND_RESET(fc->length_field_path); |
2007 | BT_LOGD_STR("Putting length field class."); | |
2008 | BT_OBJECT_PUT_REF_AND_RESET(fc->length_fc); | |
5cd6d0e5 PP |
2009 | g_free(fc); |
2010 | } | |
2011 | ||
9c08c816 | 2012 | struct bt_field_class *bt_field_class_array_dynamic_create( |
1367bc7c PP |
2013 | struct bt_trace_class *trace_class, |
2014 | struct bt_field_class *element_fc, | |
2015 | struct bt_field_class *length_fc) | |
5cd6d0e5 | 2016 | { |
9c08c816 | 2017 | struct bt_field_class_array_dynamic *array_fc = NULL; |
5cd6d0e5 | 2018 | |
1122a43a | 2019 | BT_ASSERT_PRE_NON_NULL(trace_class, "Trace class"); |
e5be10ef PP |
2020 | BT_ASSERT_PRE_NON_NULL(element_fc, "Element field class"); |
2021 | BT_LOGD_STR("Creating default dynamic array field class object."); | |
9c08c816 | 2022 | array_fc = g_new0(struct bt_field_class_array_dynamic, 1); |
5cd6d0e5 | 2023 | if (!array_fc) { |
870631a2 PP |
2024 | BT_LIB_LOGE_APPEND_CAUSE( |
2025 | "Failed to allocate one dynamic array field class."); | |
5cd6d0e5 PP |
2026 | goto error; |
2027 | } | |
2028 | ||
c6962c96 | 2029 | if (init_array_field_class((void *) array_fc, |
81b8fa44 PP |
2030 | length_fc ? |
2031 | BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITH_LENGTH_FIELD : | |
2032 | BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITHOUT_LENGTH_FIELD, | |
c6962c96 PP |
2033 | destroy_dynamic_array_field_class, element_fc)) { |
2034 | goto error; | |
2035 | } | |
1367bc7c PP |
2036 | |
2037 | if (length_fc) { | |
2038 | BT_ASSERT_PRE_FC_IS_UNSIGNED_INT(length_fc, | |
2039 | "Length field class"); | |
2040 | array_fc->length_fc = length_fc; | |
6871026b | 2041 | bt_object_get_ref_no_null_check(array_fc->length_fc); |
1367bc7c PP |
2042 | bt_field_class_freeze(length_fc); |
2043 | } | |
2044 | ||
e5be10ef | 2045 | BT_LIB_LOGD("Created dynamic array field class object: %!+F", array_fc); |
5cd6d0e5 PP |
2046 | goto end; |
2047 | ||
2048 | error: | |
65300d60 | 2049 | BT_OBJECT_PUT_REF_AND_RESET(array_fc); |
5cd6d0e5 PP |
2050 | |
2051 | end: | |
2052 | return (void *) array_fc; | |
2053 | } | |
2054 | ||
40f4ba76 | 2055 | const struct bt_field_path * |
81b8fa44 | 2056 | bt_field_class_array_dynamic_with_length_field_borrow_length_field_path_const( |
40f4ba76 | 2057 | const struct bt_field_class *fc) |
5cd6d0e5 | 2058 | { |
9c08c816 | 2059 | const struct bt_field_class_array_dynamic *seq_fc = (const void *) fc; |
5cd6d0e5 | 2060 | |
bdb288b3 | 2061 | BT_ASSERT_PRE_DEV_NON_NULL(fc, "Field class"); |
81b8fa44 PP |
2062 | BT_ASSERT_PRE_DEV_FC_HAS_ID(fc, |
2063 | BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITH_LENGTH_FIELD, | |
5cd6d0e5 PP |
2064 | "Field class"); |
2065 | return seq_fc->length_field_path; | |
2066 | } | |
2067 | ||
2068 | static | |
2069 | void destroy_string_field_class(struct bt_object *obj) | |
2070 | { | |
2071 | BT_ASSERT(obj); | |
e5be10ef | 2072 | BT_LIB_LOGD("Destroying string field class object: %!+F", obj); |
c6962c96 | 2073 | finalize_field_class((void *) obj); |
5cd6d0e5 PP |
2074 | g_free(obj); |
2075 | } | |
2076 | ||
1122a43a | 2077 | struct bt_field_class *bt_field_class_string_create(bt_trace_class *trace_class) |
5cd6d0e5 PP |
2078 | { |
2079 | struct bt_field_class_string *string_fc = NULL; | |
2080 | ||
1122a43a | 2081 | BT_ASSERT_PRE_NON_NULL(trace_class, "Trace class"); |
e5be10ef | 2082 | BT_LOGD_STR("Creating default string field class object."); |
5cd6d0e5 PP |
2083 | string_fc = g_new0(struct bt_field_class_string, 1); |
2084 | if (!string_fc) { | |
870631a2 PP |
2085 | BT_LIB_LOGE_APPEND_CAUSE( |
2086 | "Failed to allocate one string field class."); | |
5cd6d0e5 PP |
2087 | goto error; |
2088 | } | |
2089 | ||
c6962c96 PP |
2090 | if (init_field_class((void *) string_fc, BT_FIELD_CLASS_TYPE_STRING, |
2091 | destroy_string_field_class)) { | |
2092 | goto error; | |
2093 | } | |
2094 | ||
e5be10ef | 2095 | BT_LIB_LOGD("Created string field class object: %!+F", string_fc); |
5cd6d0e5 PP |
2096 | goto end; |
2097 | ||
2098 | error: | |
65300d60 | 2099 | BT_OBJECT_PUT_REF_AND_RESET(string_fc); |
5cd6d0e5 PP |
2100 | |
2101 | end: | |
2102 | return (void *) string_fc; | |
2103 | } | |
2104 | ||
2105 | BT_HIDDEN | |
1e6fd1d7 | 2106 | void _bt_field_class_freeze(const struct bt_field_class *c_fc) |
5cd6d0e5 | 2107 | { |
1e6fd1d7 PP |
2108 | struct bt_field_class *fc = (void *) c_fc; |
2109 | ||
5cd6d0e5 PP |
2110 | /* |
2111 | * Element/member/option field classes are frozen when added to | |
2112 | * their owner. | |
2113 | */ | |
2114 | BT_ASSERT(fc); | |
c6962c96 | 2115 | bt_value_freeze(fc->user_attributes); |
1e6fd1d7 PP |
2116 | fc->frozen = true; |
2117 | ||
2118 | switch (fc->type) { | |
2119 | case BT_FIELD_CLASS_TYPE_STRUCTURE: | |
45c51519 | 2120 | case BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR: |
fabfe034 PP |
2121 | case BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_INTEGER_SELECTOR: |
2122 | case BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR: | |
1e6fd1d7 PP |
2123 | { |
2124 | struct bt_field_class_named_field_class_container *container_fc = | |
2125 | (void *) fc; | |
2126 | uint64_t i; | |
2127 | ||
2128 | for (i = 0; i < container_fc->named_fcs->len; i++) { | |
45c51519 PP |
2129 | bt_named_field_class_freeze( |
2130 | container_fc->named_fcs->pdata[i]); | |
1e6fd1d7 PP |
2131 | } |
2132 | ||
2133 | break; | |
2134 | } | |
2135 | default: | |
2136 | break; | |
2137 | } | |
2138 | } | |
2139 | ||
2140 | BT_HIDDEN | |
2141 | void _bt_named_field_class_freeze(const struct bt_named_field_class *named_fc) | |
2142 | { | |
2143 | BT_ASSERT(named_fc); | |
c6962c96 PP |
2144 | BT_ASSERT(named_fc->fc->frozen); |
2145 | BT_LIB_LOGD("Freezing named field class's user attributes: %!+v", | |
2146 | named_fc->user_attributes); | |
2147 | bt_value_freeze(named_fc->user_attributes); | |
1e6fd1d7 | 2148 | ((struct bt_named_field_class *) named_fc)->frozen = true; |
5cd6d0e5 PP |
2149 | } |
2150 | ||
2151 | BT_HIDDEN | |
bdb288b3 | 2152 | void bt_field_class_make_part_of_trace_class(const struct bt_field_class *c_fc) |
5cd6d0e5 | 2153 | { |
40f4ba76 PP |
2154 | struct bt_field_class *fc = (void *) c_fc; |
2155 | ||
5cd6d0e5 | 2156 | BT_ASSERT(fc); |
862ca4ed | 2157 | BT_ASSERT_PRE(!fc->part_of_trace_class, |
5cd6d0e5 | 2158 | "Field class is already part of a trace: %!+F", fc); |
862ca4ed | 2159 | fc->part_of_trace_class = true; |
5cd6d0e5 | 2160 | |
864cad70 PP |
2161 | switch (fc->type) { |
2162 | case BT_FIELD_CLASS_TYPE_STRUCTURE: | |
45c51519 | 2163 | case BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR: |
fabfe034 PP |
2164 | case BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_INTEGER_SELECTOR: |
2165 | case BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR: | |
5cd6d0e5 PP |
2166 | { |
2167 | struct bt_field_class_named_field_class_container *container_fc = | |
2168 | (void *) fc; | |
2169 | uint64_t i; | |
2170 | ||
2171 | for (i = 0; i < container_fc->named_fcs->len; i++) { | |
2172 | struct bt_named_field_class *named_fc = | |
45c51519 | 2173 | container_fc->named_fcs->pdata[i]; |
5cd6d0e5 | 2174 | |
862ca4ed | 2175 | bt_field_class_make_part_of_trace_class(named_fc->fc); |
5cd6d0e5 PP |
2176 | } |
2177 | ||
2178 | break; | |
2179 | } | |
864cad70 | 2180 | case BT_FIELD_CLASS_TYPE_STATIC_ARRAY: |
81b8fa44 PP |
2181 | case BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITHOUT_LENGTH_FIELD: |
2182 | case BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITH_LENGTH_FIELD: | |
5cd6d0e5 PP |
2183 | { |
2184 | struct bt_field_class_array *array_fc = (void *) fc; | |
2185 | ||
862ca4ed | 2186 | bt_field_class_make_part_of_trace_class(array_fc->element_fc); |
5cd6d0e5 PP |
2187 | break; |
2188 | } | |
2189 | default: | |
2190 | break; | |
2191 | } | |
2192 | } | |
c5b9b441 | 2193 | |
c6962c96 PP |
2194 | const struct bt_value *bt_field_class_borrow_user_attributes_const( |
2195 | const struct bt_field_class *fc) | |
2196 | { | |
2197 | BT_ASSERT_PRE_DEV_NON_NULL(fc, "Field class"); | |
2198 | return fc->user_attributes; | |
2199 | } | |
2200 | ||
2201 | struct bt_value *bt_field_class_borrow_user_attributes( | |
2202 | struct bt_field_class *field_class) | |
2203 | { | |
2204 | return (void *) bt_field_class_borrow_user_attributes_const( | |
2205 | (void *) field_class); | |
2206 | } | |
2207 | ||
2208 | ||
2209 | void bt_field_class_set_user_attributes( | |
2210 | struct bt_field_class *fc, | |
2211 | const struct bt_value *user_attributes) | |
2212 | { | |
2213 | BT_ASSERT_PRE_NON_NULL(fc, "Field class"); | |
2214 | BT_ASSERT_PRE_NON_NULL(user_attributes, "User attributes"); | |
2215 | BT_ASSERT_PRE(user_attributes->type == BT_VALUE_TYPE_MAP, | |
2216 | "User attributes object is not a map value object."); | |
2217 | BT_ASSERT_PRE_DEV_FC_HOT(fc, "Field class"); | |
6871026b | 2218 | bt_object_put_ref_no_null_check(fc->user_attributes); |
c6962c96 | 2219 | fc->user_attributes = (void *) user_attributes; |
6871026b | 2220 | bt_object_get_ref_no_null_check(fc->user_attributes); |
c6962c96 PP |
2221 | } |
2222 | ||
2223 | static | |
2224 | const struct bt_value *bt_named_field_class_borrow_user_attributes_const( | |
2225 | const struct bt_named_field_class *named_fc) | |
2226 | { | |
2227 | return named_fc->user_attributes; | |
2228 | } | |
2229 | ||
2230 | static | |
2231 | void bt_named_field_class_set_user_attributes( | |
2232 | struct bt_named_field_class *named_fc, | |
2233 | const struct bt_value *user_attributes) | |
2234 | { | |
2235 | BT_ASSERT_PRE_NON_NULL(user_attributes, "User attributes"); | |
2236 | BT_ASSERT_PRE(user_attributes->type == BT_VALUE_TYPE_MAP, | |
2237 | "User attributes object is not a map value object."); | |
2238 | BT_ASSERT_PRE_DEV_HOT(named_fc, | |
2239 | "Structure field class member or variant field class option", | |
2240 | "."); | |
6871026b | 2241 | bt_object_put_ref_no_null_check(named_fc->user_attributes); |
c6962c96 | 2242 | named_fc->user_attributes = (void *) user_attributes; |
6871026b | 2243 | bt_object_get_ref_no_null_check(named_fc->user_attributes); |
c6962c96 PP |
2244 | } |
2245 | ||
2246 | const struct bt_value * | |
2247 | bt_field_class_structure_member_borrow_user_attributes_const( | |
2248 | const struct bt_field_class_structure_member *member) | |
2249 | { | |
2250 | BT_ASSERT_PRE_NON_NULL(member, "Structure field class member"); | |
2251 | return bt_named_field_class_borrow_user_attributes_const( | |
2252 | (const void *) member); | |
2253 | } | |
2254 | ||
2255 | struct bt_value * | |
2256 | bt_field_class_structure_member_borrow_user_attributes( | |
2257 | struct bt_field_class_structure_member *member) | |
2258 | { | |
2259 | BT_ASSERT_PRE_NON_NULL(member, "Structure field class member"); | |
2260 | return (void *) bt_named_field_class_borrow_user_attributes_const( | |
2261 | (void *) member); | |
2262 | } | |
2263 | ||
2264 | void bt_field_class_structure_member_set_user_attributes( | |
2265 | struct bt_field_class_structure_member *member, | |
2266 | const struct bt_value *user_attributes) | |
2267 | { | |
2268 | BT_ASSERT_PRE_NON_NULL(member, "Structure field class member"); | |
2269 | bt_named_field_class_set_user_attributes((void *) member, | |
2270 | user_attributes); | |
2271 | } | |
2272 | ||
2273 | const struct bt_value *bt_field_class_variant_option_borrow_user_attributes_const( | |
2274 | const struct bt_field_class_variant_option *option) | |
2275 | { | |
2276 | BT_ASSERT_PRE_NON_NULL(option, "Variant field class option"); | |
2277 | return bt_named_field_class_borrow_user_attributes_const( | |
2278 | (const void *) option); | |
2279 | } | |
2280 | ||
2281 | struct bt_value *bt_field_class_variant_option_borrow_user_attributes( | |
2282 | struct bt_field_class_variant_option *option) | |
2283 | { | |
2284 | BT_ASSERT_PRE_NON_NULL(option, "Variant field class option"); | |
2285 | return (void *) bt_named_field_class_borrow_user_attributes_const( | |
2286 | (void *) option); | |
2287 | } | |
2288 | ||
2289 | void bt_field_class_variant_option_set_user_attributes( | |
2290 | struct bt_field_class_variant_option *option, | |
2291 | const struct bt_value *user_attributes) | |
2292 | { | |
2293 | BT_ASSERT_PRE_NON_NULL(option, "Variant field class option"); | |
2294 | bt_named_field_class_set_user_attributes((void *) option, | |
2295 | user_attributes); | |
2296 | } | |
2297 | ||
c5b9b441 PP |
2298 | void bt_field_class_get_ref(const struct bt_field_class *field_class) |
2299 | { | |
2300 | bt_object_get_ref(field_class); | |
2301 | } | |
2302 | ||
2303 | void bt_field_class_put_ref(const struct bt_field_class *field_class) | |
2304 | { | |
2305 | bt_object_put_ref(field_class); | |
2306 | } |