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