Rename: field type -> field class
[babeltrace.git] / lib / trace-ir / fields.c
CommitLineData
273b65be 1/*
2e33ac5a 2 * fields.c
273b65be 3 *
108b91d0 4 * Babeltrace trace IR - Event Fields
273b65be 5 *
de9dd397 6 * Copyright 2013, 2014 Jérémie Galarneau <jeremie.galarneau@efficios.com>
273b65be
JG
7 *
8 * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com>
9 *
10 * Permission is hereby granted, free of charge, to any person obtaining a copy
11 * of this software and associated documentation files (the "Software"), to deal
12 * in the Software without restriction, including without limitation the rights
13 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14 * copies of the Software, and to permit persons to whom the Software is
15 * furnished to do so, subject to the following conditions:
16 *
17 * The above copyright notice and this permission notice shall be included in
18 * all copies or substantial portions of the Software.
19 *
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26 * SOFTWARE.
27 */
28
fc25abce
PP
29#define BT_LOG_TAG "FIELDS"
30#include <babeltrace/lib-logging-internal.h>
31
8deee039 32#include <babeltrace/assert-pre-internal.h>
108b91d0
PP
33#include <babeltrace/trace-ir/fields.h>
34#include <babeltrace/trace-ir/fields-internal.h>
939190b3 35#include <babeltrace/trace-ir/field-classes-internal.h>
83509119
JG
36#include <babeltrace/object-internal.h>
37#include <babeltrace/ref.h>
3d9990ac
PP
38#include <babeltrace/compiler-internal.h>
39#include <babeltrace/compat/fcntl-internal.h>
40#include <babeltrace/align-internal.h>
8b45963b 41#include <babeltrace/assert-internal.h>
fc25abce 42#include <inttypes.h>
273b65be 43
18acc6f8 44static
7b33a0e0 45void reset_single_field(struct bt_field *field);
18acc6f8
PP
46
47static
7b33a0e0 48void reset_array_field(struct bt_field *field);
18acc6f8
PP
49
50static
7b33a0e0 51void reset_structure_field(struct bt_field *field);
18acc6f8
PP
52
53static
7b33a0e0 54void reset_variant_field(struct bt_field *field);
18acc6f8
PP
55
56static
7b33a0e0 57void set_single_field_is_frozen(struct bt_field *field, bool is_frozen);
18acc6f8
PP
58
59static
7b33a0e0 60void set_array_field_is_frozen(struct bt_field *field, bool is_frozen);
18acc6f8
PP
61
62static
7b33a0e0 63void set_structure_field_is_frozen(struct bt_field *field, bool is_frozen);
18acc6f8
PP
64
65static
7b33a0e0 66void set_variant_field_is_frozen(struct bt_field *field, bool is_frozen);
18acc6f8
PP
67
68static
7b33a0e0 69bool single_field_is_set(struct bt_field *field);
18acc6f8
PP
70
71static
7b33a0e0 72bool array_field_is_set(struct bt_field *field);
18acc6f8
PP
73
74static
7b33a0e0 75bool structure_field_is_set(struct bt_field *field);
18acc6f8
PP
76
77static
7b33a0e0 78bool variant_field_is_set(struct bt_field *field);
18acc6f8
PP
79
80static
7b33a0e0
PP
81struct bt_field_methods integer_field_methods = {
82 .set_is_frozen = set_single_field_is_frozen,
83 .is_set = single_field_is_set,
84 .reset = reset_single_field,
8deee039 85};
273b65be 86
7b33a0e0
PP
87static
88struct bt_field_methods real_field_methods = {
89 .set_is_frozen = set_single_field_is_frozen,
90 .is_set = single_field_is_set,
91 .reset = reset_single_field,
12c8a1a3
JG
92};
93
7b33a0e0
PP
94static
95struct bt_field_methods string_field_methods = {
96 .set_is_frozen = set_single_field_is_frozen,
97 .is_set = single_field_is_set,
98 .reset = reset_single_field,
273b65be
JG
99};
100
7b33a0e0
PP
101static
102struct bt_field_methods structure_field_methods = {
103 .set_is_frozen = set_structure_field_is_frozen,
104 .is_set = structure_field_is_set,
105 .reset = reset_structure_field,
87d43dc1
JG
106};
107
7b33a0e0
PP
108static
109struct bt_field_methods array_field_methods = {
110 .set_is_frozen = set_array_field_is_frozen,
111 .is_set = array_field_is_set,
112 .reset = reset_array_field,
918be005
PP
113};
114
76f869ab 115static
7b33a0e0
PP
116struct bt_field_methods variant_field_methods = {
117 .set_is_frozen = set_variant_field_is_frozen,
118 .is_set = variant_field_is_set,
119 .reset = reset_variant_field,
120};
76f869ab 121
8deee039 122static
939190b3 123struct bt_field *create_integer_field(struct bt_field_class *);
8deee039
PP
124
125static
939190b3 126struct bt_field *create_real_field(struct bt_field_class *);
8deee039
PP
127
128static
939190b3 129struct bt_field *create_string_field(struct bt_field_class *);
8deee039
PP
130
131static
939190b3 132struct bt_field *create_structure_field(struct bt_field_class *);
8deee039
PP
133
134static
939190b3 135struct bt_field *create_static_array_field(struct bt_field_class *);
8b45963b 136
8deee039 137static
939190b3 138struct bt_field *create_dynamic_array_field(struct bt_field_class *);
8b45963b 139
8deee039 140static
939190b3 141struct bt_field *create_variant_field(struct bt_field_class *);
8b45963b 142
8deee039 143static
939190b3
PP
144struct bt_field *(* const field_create_funcs[])(struct bt_field_class *) = {
145 [BT_FIELD_CLASS_ID_UNSIGNED_INTEGER] = create_integer_field,
146 [BT_FIELD_CLASS_ID_SIGNED_INTEGER] = create_integer_field,
147 [BT_FIELD_CLASS_ID_UNSIGNED_ENUMERATION] = create_integer_field,
148 [BT_FIELD_CLASS_ID_SIGNED_ENUMERATION] = create_integer_field,
149 [BT_FIELD_CLASS_ID_REAL] = create_real_field,
150 [BT_FIELD_CLASS_ID_STRING] = create_string_field,
151 [BT_FIELD_CLASS_ID_STRUCTURE] = create_structure_field,
152 [BT_FIELD_CLASS_ID_STATIC_ARRAY] = create_static_array_field,
153 [BT_FIELD_CLASS_ID_DYNAMIC_ARRAY] = create_dynamic_array_field,
154 [BT_FIELD_CLASS_ID_VARIANT] = create_variant_field,
8deee039 155};
8b45963b 156
a6918753 157static
7b33a0e0 158void destroy_integer_field(struct bt_field *field);
a6918753
PP
159
160static
7b33a0e0 161void destroy_real_field(struct bt_field *field);
a6918753
PP
162
163static
7b33a0e0 164void destroy_string_field(struct bt_field *field);
a6918753
PP
165
166static
7b33a0e0 167void destroy_structure_field(struct bt_field *field);
a6918753
PP
168
169static
7b33a0e0 170void destroy_array_field(struct bt_field *field);
a6918753
PP
171
172static
7b33a0e0 173void destroy_variant_field(struct bt_field *field);
a6918753
PP
174
175static
176void (* const field_destroy_funcs[])(struct bt_field *) = {
939190b3
PP
177 [BT_FIELD_CLASS_ID_UNSIGNED_INTEGER] = destroy_integer_field,
178 [BT_FIELD_CLASS_ID_SIGNED_INTEGER] = destroy_integer_field,
179 [BT_FIELD_CLASS_ID_UNSIGNED_ENUMERATION] = destroy_integer_field,
180 [BT_FIELD_CLASS_ID_SIGNED_ENUMERATION] = destroy_integer_field,
181 [BT_FIELD_CLASS_ID_REAL] = destroy_real_field,
182 [BT_FIELD_CLASS_ID_STRING] = destroy_string_field,
183 [BT_FIELD_CLASS_ID_STRUCTURE] = destroy_structure_field,
184 [BT_FIELD_CLASS_ID_STATIC_ARRAY] = destroy_array_field,
185 [BT_FIELD_CLASS_ID_DYNAMIC_ARRAY] = destroy_array_field,
186 [BT_FIELD_CLASS_ID_VARIANT] = destroy_variant_field,
a6918753
PP
187};
188
939190b3 189struct bt_field_class *bt_field_borrow_class(struct bt_field *field)
18acc6f8 190{
7b33a0e0 191 BT_ASSERT_PRE_NON_NULL(field, "Field");
939190b3 192 return field->class;
18acc6f8
PP
193}
194
939190b3 195enum bt_field_class_id bt_field_get_class_id(struct bt_field *field)
18acc6f8 196{
7b33a0e0 197 BT_ASSERT_PRE_NON_NULL(field, "Field");
939190b3 198 return field->class->id;
18acc6f8
PP
199}
200
a6918753 201BT_HIDDEN
939190b3 202struct bt_field *bt_field_create(struct bt_field_class *fc)
273b65be 203{
839d52a5 204 struct bt_field *field = NULL;
7b33a0e0 205
939190b3
PP
206 BT_ASSERT_PRE_NON_NULL(fc, "Field class");
207 BT_ASSERT(bt_field_class_has_known_id(fc));
208 field = field_create_funcs[fc->id](fc);
273b65be 209 if (!field) {
939190b3
PP
210 BT_LIB_LOGE("Cannot create field object from field classe: "
211 "%![fc-]+F", fc);
8deee039 212 goto end;
273b65be
JG
213 }
214
8deee039
PP
215end:
216 return field;
273b65be
JG
217}
218
7b33a0e0 219static inline
939190b3 220void init_field(struct bt_field *field, struct bt_field_class *fc,
7b33a0e0 221 struct bt_field_methods *methods)
cd95e351 222{
7b33a0e0 223 BT_ASSERT(field);
939190b3 224 BT_ASSERT(fc);
7b33a0e0
PP
225 bt_object_init_unique(&field->base);
226 field->methods = methods;
939190b3 227 field->class = bt_get(fc);
cd95e351
JG
228}
229
7b33a0e0 230static
939190b3 231struct bt_field *create_integer_field(struct bt_field_class *fc)
4ebcc695 232{
7b33a0e0
PP
233 struct bt_field_integer *int_field;
234
939190b3 235 BT_LIB_LOGD("Creating integer field object: %![fc-]+F", fc);
7b33a0e0
PP
236 int_field = g_new0(struct bt_field_integer, 1);
237 if (!int_field) {
238 BT_LOGE_STR("Failed to allocate one integer field.");
239 goto end;
240 }
241
939190b3 242 init_field((void *) int_field, fc, &integer_field_methods);
7b33a0e0
PP
243 BT_LIB_LOGD("Created integer field object: %!+f", int_field);
244
245end:
246 return (void *) int_field;
4ebcc695
PP
247}
248
7b33a0e0 249static
939190b3 250struct bt_field *create_real_field(struct bt_field_class *fc)
fea75608 251{
7b33a0e0 252 struct bt_field_real *real_field;
18acc6f8 253
939190b3 254 BT_LIB_LOGD("Creating real field object: %![fc-]+F", fc);
7b33a0e0
PP
255 real_field = g_new0(struct bt_field_real, 1);
256 if (!real_field) {
257 BT_LOGE_STR("Failed to allocate one real field.");
258 goto end;
259 }
260
939190b3 261 init_field((void *) real_field, fc, &real_field_methods);
7b33a0e0
PP
262 BT_LIB_LOGD("Created real field object: %!+f", real_field);
263
264end:
265 return (void *) real_field;
fea75608
PP
266}
267
7b33a0e0 268static
939190b3 269struct bt_field *create_string_field(struct bt_field_class *fc)
273b65be 270{
7b33a0e0 271 struct bt_field_string *string_field;
18acc6f8 272
939190b3 273 BT_LIB_LOGD("Creating string field object: %![fc-]+F", fc);
7b33a0e0
PP
274 string_field = g_new0(struct bt_field_string, 1);
275 if (!string_field) {
276 BT_LOGE_STR("Failed to allocate one string field.");
277 goto end;
278 }
18acc6f8 279
939190b3 280 init_field((void *) string_field, fc, &string_field_methods);
7b33a0e0
PP
281 string_field->buf = g_array_sized_new(FALSE, FALSE,
282 sizeof(char), 1);
283 if (!string_field->buf) {
284 BT_LOGE_STR("Failed to allocate a GArray.");
285 BT_PUT(string_field);
286 goto end;
287 }
18acc6f8 288
7b33a0e0
PP
289 g_array_index(string_field->buf, char, 0) = '\0';
290 BT_LIB_LOGD("Created string field object: %!+f", string_field);
18acc6f8 291
7b33a0e0
PP
292end:
293 return (void *) string_field;
294}
18acc6f8 295
7b33a0e0 296static inline
939190b3
PP
297int create_fields_from_named_field_classes(
298 struct bt_field_class_named_field_class_container *fc,
7b33a0e0
PP
299 GPtrArray **fields)
300{
301 int ret = 0;
302 uint64_t i;
18acc6f8 303
7b33a0e0
PP
304 *fields = g_ptr_array_new_with_free_func(
305 (GDestroyNotify) bt_field_destroy);
306 if (!*fields) {
307 BT_LOGE_STR("Failed to allocate a GPtrArray.");
308 ret = -1;
309 goto end;
18acc6f8
PP
310 }
311
939190b3 312 g_ptr_array_set_size(*fields, fc->named_fcs->len);
7b33a0e0 313
939190b3 314 for (i = 0; i < fc->named_fcs->len; i++) {
7b33a0e0 315 struct bt_field *field;
939190b3
PP
316 struct bt_named_field_class *named_fc =
317 BT_FIELD_CLASS_NAMED_FC_AT_INDEX(fc, i);
7b33a0e0 318
939190b3 319 field = bt_field_create(named_fc->fc);
7b33a0e0
PP
320 if (!field) {
321 BT_LIB_LOGE("Failed to create structure member or variant option field: "
939190b3
PP
322 "name=\"%s\", %![fc-]+F",
323 named_fc->name->str, named_fc->fc);
7b33a0e0
PP
324 ret = -1;
325 goto end;
326 }
327
328 g_ptr_array_index(*fields, i) = field;
329 }
18acc6f8
PP
330
331end:
332 return ret;
273b65be
JG
333}
334
7b33a0e0 335static
939190b3 336struct bt_field *create_structure_field(struct bt_field_class *fc)
cd95e351 337{
7b33a0e0 338 struct bt_field_structure *struct_field;
18acc6f8 339
939190b3 340 BT_LIB_LOGD("Creating structure field object: %![fc-]+F", fc);
7b33a0e0
PP
341 struct_field = g_new0(struct bt_field_structure, 1);
342 if (!struct_field) {
343 BT_LOGE_STR("Failed to allocate one structure field.");
344 goto end;
345 }
fc25abce 346
939190b3 347 init_field((void *) struct_field, fc, &structure_field_methods);
7b33a0e0 348
939190b3 349 if (create_fields_from_named_field_classes((void *) fc,
7b33a0e0
PP
350 &struct_field->fields)) {
351 BT_LIB_LOGE("Cannot create structure member fields: "
939190b3 352 "%![fc-]+F", fc);
7b33a0e0
PP
353 BT_PUT(struct_field);
354 goto end;
18acc6f8
PP
355 }
356
7b33a0e0 357 BT_LIB_LOGD("Created structure field object: %!+f", struct_field);
18acc6f8 358
7b33a0e0
PP
359end:
360 return (void *) struct_field;
cd95e351
JG
361}
362
7b33a0e0 363static
939190b3 364struct bt_field *create_variant_field(struct bt_field_class *fc)
273b65be 365{
7b33a0e0 366 struct bt_field_variant *var_field;
18acc6f8 367
939190b3 368 BT_LIB_LOGD("Creating variant field object: %![fc-]+F", fc);
7b33a0e0
PP
369 var_field = g_new0(struct bt_field_variant, 1);
370 if (!var_field) {
371 BT_LOGE_STR("Failed to allocate one variant field.");
372 goto end;
373 }
8b45963b 374
939190b3 375 init_field((void *) var_field, fc, &variant_field_methods);
18acc6f8 376
939190b3 377 if (create_fields_from_named_field_classes((void *) fc,
7b33a0e0
PP
378 &var_field->fields)) {
379 BT_LIB_LOGE("Cannot create variant member fields: "
939190b3 380 "%![fc-]+F", fc);
7b33a0e0
PP
381 BT_PUT(var_field);
382 goto end;
383 }
273b65be 384
7b33a0e0 385 BT_LIB_LOGD("Created variant field object: %!+f", var_field);
18acc6f8 386
7b33a0e0
PP
387end:
388 return (void *) var_field;
18acc6f8
PP
389}
390
391static inline
7b33a0e0 392int init_array_field_fields(struct bt_field_array *array_field)
18acc6f8
PP
393{
394 int ret = 0;
7b33a0e0 395 uint64_t i;
939190b3 396 struct bt_field_class_array *array_fc;
18acc6f8 397
7b33a0e0 398 BT_ASSERT(array_field);
939190b3 399 array_fc = (void *) array_field->common.class;
7b33a0e0
PP
400 array_field->fields = g_ptr_array_sized_new(array_field->length);
401 if (!array_field->fields) {
402 BT_LOGE_STR("Failed to allocate a GPtrArray.");
18acc6f8
PP
403 ret = -1;
404 goto end;
405 }
406
7b33a0e0
PP
407 g_ptr_array_set_free_func(array_field->fields,
408 (GDestroyNotify) bt_field_destroy);
409 g_ptr_array_set_size(array_field->fields, array_field->length);
410
411 for (i = 0; i < array_field->length; i++) {
412 array_field->fields->pdata[i] = bt_field_create(
939190b3 413 array_fc->element_fc);
7b33a0e0
PP
414 if (!array_field->fields->pdata[i]) {
415 BT_LIB_LOGE("Cannot create array field's element field: "
939190b3 416 "index=%" PRIu64 ", %![fc-]+F", i, array_fc);
7b33a0e0
PP
417 ret = -1;
418 goto end;
419 }
420 }
18acc6f8
PP
421
422end:
423 return ret;
3f4a108d
PP
424}
425
7b33a0e0 426static
939190b3 427struct bt_field *create_static_array_field(struct bt_field_class *fc)
f78d67fb 428{
939190b3 429 struct bt_field_class_static_array *array_fc = (void *) fc;
7b33a0e0 430 struct bt_field_array *array_field;
a6918753 431
939190b3 432 BT_LIB_LOGD("Creating static array field object: %![fc-]+F", fc);
7b33a0e0
PP
433 array_field = g_new0(struct bt_field_array, 1);
434 if (!array_field) {
435 BT_LOGE_STR("Failed to allocate one static array field.");
436 goto end;
437 }
f78d67fb 438
939190b3
PP
439 init_field((void *) array_field, fc, &array_field_methods);
440 array_field->length = array_fc->length;
18acc6f8 441
7b33a0e0
PP
442 if (init_array_field_fields(array_field)) {
443 BT_LIB_LOGE("Cannot create static array fields: "
939190b3 444 "%![fc-]+F", fc);
7b33a0e0
PP
445 BT_PUT(array_field);
446 goto end;
447 }
a6918753 448
7b33a0e0 449 BT_LIB_LOGD("Created static array field object: %!+f", array_field);
18acc6f8 450
7b33a0e0
PP
451end:
452 return (void *) array_field;
273b65be
JG
453}
454
7b33a0e0 455static
939190b3 456struct bt_field *create_dynamic_array_field(struct bt_field_class *fc)
cd95e351 457{
7b33a0e0 458 struct bt_field_array *array_field;
a6918753 459
939190b3 460 BT_LIB_LOGD("Creating dynamic array field object: %![fc-]+F", fc);
7b33a0e0
PP
461 array_field = g_new0(struct bt_field_array, 1);
462 if (!array_field) {
463 BT_LOGE_STR("Failed to allocate one dynamic array field.");
464 goto end;
465 }
466
939190b3 467 init_field((void *) array_field, fc, &array_field_methods);
7b33a0e0
PP
468
469 if (init_array_field_fields(array_field)) {
470 BT_LIB_LOGE("Cannot create dynamic array fields: "
939190b3 471 "%![fc-]+F", fc);
7b33a0e0
PP
472 BT_PUT(array_field);
473 goto end;
18acc6f8
PP
474 }
475
7b33a0e0
PP
476 BT_LIB_LOGD("Created dynamic array field object: %!+f", array_field);
477
478end:
479 return (void *) array_field;
a6918753
PP
480}
481
7b33a0e0 482int64_t bt_field_signed_integer_get_value(struct bt_field *field)
a6918753 483{
18acc6f8 484 struct bt_field_integer *int_field = (void *) field;
a6918753 485
7b33a0e0
PP
486 BT_ASSERT_PRE_NON_NULL(field, "Field");
487 BT_ASSERT_PRE_FIELD_IS_SET(field, "Field");
488 BT_ASSERT_PRE_FIELD_IS_SIGNED_INT(field, "Field");
489 return int_field->value.i;
cd95e351
JG
490}
491
7b33a0e0 492void bt_field_signed_integer_set_value(struct bt_field *field, int64_t value)
cd95e351 493{
7b33a0e0 494 struct bt_field_integer *int_field = (void *) field;
a6918753 495
7b33a0e0
PP
496 BT_ASSERT_PRE_NON_NULL(field, "Field");
497 BT_ASSERT_PRE_FIELD_IS_SIGNED_INT(field, "Field");
498 BT_ASSERT_PRE_FIELD_HOT(field, "Field");
499 BT_ASSERT_PRE(bt_util_value_is_in_range_signed(
939190b3 500 ((struct bt_field_class_integer *) field->class)->range, value),
7b33a0e0 501 "Value is out of bounds: value=%" PRId64 ", %![field-]+f, "
939190b3 502 "%![fc-]+F", value, field, field->class);
7b33a0e0
PP
503 int_field->value.i = value;
504 bt_field_set_single(field, true);
cd95e351
JG
505}
506
7b33a0e0 507uint64_t bt_field_unsigned_integer_get_value(struct bt_field *field)
273b65be 508{
7b33a0e0
PP
509 struct bt_field_integer *int_field = (void *) field;
510
511 BT_ASSERT_PRE_NON_NULL(field, "Field");
512 BT_ASSERT_PRE_FIELD_IS_SET(field, "Field");
513 BT_ASSERT_PRE_FIELD_IS_UNSIGNED_INT(field, "Field");
514 return int_field->value.u;
273b65be
JG
515}
516
7b33a0e0
PP
517void bt_field_unsigned_integer_set_value(struct bt_field *field,
518 uint64_t value)
cd95e351 519{
7b33a0e0 520 struct bt_field_integer *int_field = (void *) field;
a6918753 521
7b33a0e0
PP
522 BT_ASSERT_PRE_NON_NULL(field, "Field");
523 BT_ASSERT_PRE_FIELD_IS_UNSIGNED_INT(field, "Field");
524 BT_ASSERT_PRE_FIELD_HOT(field, "Field");
525 BT_ASSERT_PRE(bt_util_value_is_in_range_unsigned(
939190b3 526 ((struct bt_field_class_integer *) field->class)->range, value),
7b33a0e0 527 "Value is out of bounds: value=%" PRIu64 ", %![field-]+f, "
939190b3 528 "%![fc-]+F", value, field, field->class);
7b33a0e0
PP
529 int_field->value.u = value;
530 bt_field_set_single(field, true);
cd95e351
JG
531}
532
7b33a0e0 533double bt_field_real_get_value(struct bt_field *field)
273b65be 534{
7b33a0e0
PP
535 struct bt_field_real *real_field = (void *) field;
536
537 BT_ASSERT_PRE_NON_NULL(field, "Field");
538 BT_ASSERT_PRE_FIELD_IS_SET(field, "Field");
939190b3 539 BT_ASSERT_PRE_FIELD_HAS_CLASS_ID(field, BT_FIELD_CLASS_ID_REAL, "Field");
7b33a0e0 540 return real_field->value;
8b45963b
PP
541}
542
7b33a0e0 543void bt_field_real_set_value(struct bt_field *field, double value)
8b45963b 544{
7b33a0e0 545 struct bt_field_real *real_field = (void *) field;
18acc6f8 546
7b33a0e0 547 BT_ASSERT_PRE_NON_NULL(field, "Field");
939190b3 548 BT_ASSERT_PRE_FIELD_HAS_CLASS_ID(field, BT_FIELD_CLASS_ID_REAL, "Field");
7b33a0e0
PP
549 BT_ASSERT_PRE_FIELD_HOT(field, "Field");
550 BT_ASSERT_PRE(
939190b3 551 !((struct bt_field_class_real *) field->class)->is_single_precision ||
7b33a0e0
PP
552 (double) (float) value == value,
553 "Invalid value for a single-precision real number: value=%f, "
939190b3 554 "%![fc-]+F", value, field->class);
7b33a0e0
PP
555 real_field->value = value;
556 bt_field_set_single(field, true);
557}
558
559int bt_field_unsigned_enumeration_get_mapping_labels(struct bt_field *field,
939190b3 560 bt_field_class_enumeration_mapping_label_array *label_array,
7b33a0e0
PP
561 uint64_t *count)
562{
563 struct bt_field_integer *int_field = (void *) field;
564
565 BT_ASSERT_PRE_NON_NULL(field, "Field");
566 BT_ASSERT_PRE_NON_NULL(label_array, "Label array (output)");
567 BT_ASSERT_PRE_NON_NULL(label_array, "Count (output)");
568 BT_ASSERT_PRE_FIELD_IS_SET(field, "Field");
939190b3
PP
569 BT_ASSERT_PRE_FIELD_HAS_CLASS_ID(field,
570 BT_FIELD_CLASS_ID_UNSIGNED_ENUMERATION, "Field");
571 return bt_field_class_unsigned_enumeration_get_mapping_labels_by_value(
572 field->class, int_field->value.u, label_array, count);
273b65be
JG
573}
574
7b33a0e0 575int bt_field_signed_enumeration_get_mapping_labels(struct bt_field *field,
939190b3 576 bt_field_class_enumeration_mapping_label_array *label_array,
7b33a0e0 577 uint64_t *count)
cd95e351 578{
7b33a0e0 579 struct bt_field_integer *int_field = (void *) field;
18acc6f8 580
7b33a0e0
PP
581 BT_ASSERT_PRE_NON_NULL(field, "Field");
582 BT_ASSERT_PRE_NON_NULL(label_array, "Label array (output)");
583 BT_ASSERT_PRE_NON_NULL(label_array, "Count (output)");
584 BT_ASSERT_PRE_FIELD_IS_SET(field, "Field");
939190b3
PP
585 BT_ASSERT_PRE_FIELD_HAS_CLASS_ID(field,
586 BT_FIELD_CLASS_ID_SIGNED_ENUMERATION, "Field");
587 return bt_field_class_signed_enumeration_get_mapping_labels_by_value(
588 field->class, int_field->value.i, label_array, count);
8b45963b 589}
fc25abce 590
8deee039 591const char *bt_field_string_get_value(struct bt_field *field)
8b45963b 592{
7b33a0e0
PP
593 struct bt_field_string *string_field = (void *) field;
594
595 BT_ASSERT_PRE_NON_NULL(field, "Field");
596 BT_ASSERT_PRE_FIELD_IS_SET(field, "Field");
939190b3 597 BT_ASSERT_PRE_FIELD_HAS_CLASS_ID(field, BT_FIELD_CLASS_ID_STRING,
7b33a0e0
PP
598 "Field");
599 return (const char *) string_field->buf->data;
600}
601
602uint64_t bt_field_string_get_length(struct bt_field *field)
603{
604 struct bt_field_string *string_field = (void *) field;
18acc6f8 605
7b33a0e0
PP
606 BT_ASSERT_PRE_NON_NULL(field, "Field");
607 BT_ASSERT_PRE_FIELD_IS_SET(field, "Field");
939190b3 608 BT_ASSERT_PRE_FIELD_HAS_CLASS_ID(field, BT_FIELD_CLASS_ID_STRING,
7b33a0e0
PP
609 "Field");
610 return string_field->length;
cd95e351
JG
611}
612
8deee039 613int bt_field_string_set_value(struct bt_field *field, const char *value)
273b65be 614{
7b33a0e0 615 BT_ASSERT_PRE_NON_NULL(field, "Field");
18acc6f8 616 BT_ASSERT_PRE_NON_NULL(value, "Value");
7b33a0e0 617 BT_ASSERT_PRE_FIELD_HOT(field, "Field");
939190b3 618 BT_ASSERT_PRE_FIELD_HAS_CLASS_ID(field, BT_FIELD_CLASS_ID_STRING,
7b33a0e0 619 "Field");
18acc6f8 620 bt_field_string_clear(field);
7b33a0e0
PP
621 return bt_field_string_append_with_length(field, value,
622 (uint64_t) strlen(value));
273b65be
JG
623}
624
8deee039 625int bt_field_string_append(struct bt_field *field, const char *value)
cd95e351 626{
7b33a0e0
PP
627 return bt_field_string_append_with_length(field, value,
628 (uint64_t) strlen(value));
cd95e351
JG
629}
630
7b33a0e0
PP
631int bt_field_string_append_with_length(struct bt_field *field,
632 const char *value, uint64_t length)
273b65be 633{
18acc6f8
PP
634 struct bt_field_string *string_field = (void *) field;
635 char *data;
7b33a0e0 636 uint64_t new_length;
273b65be 637
7b33a0e0 638 BT_ASSERT_PRE_NON_NULL(field, "Field");
18acc6f8 639 BT_ASSERT_PRE_NON_NULL(value, "Value");
7b33a0e0 640 BT_ASSERT_PRE_FIELD_HOT(field, "Field");
939190b3
PP
641 BT_ASSERT_PRE_FIELD_HAS_CLASS_ID(field,
642 BT_FIELD_CLASS_ID_STRING, "Field");
a6918753 643
18acc6f8
PP
644 /* Make sure no null bytes are appended */
645 BT_ASSERT_PRE(memchr(value, '\0', length) == NULL,
646 "String value to append contains a null character: "
7b33a0e0 647 "partial-value=\"%.32s\", length=%" PRIu64, value, length);
c6f9c5a3 648
7b33a0e0 649 new_length = length + string_field->length;
18acc6f8 650
7b33a0e0
PP
651 if (unlikely(new_length + 1 > string_field->buf->len)) {
652 g_array_set_size(string_field->buf, new_length + 1);
c6f9c5a3
PP
653 }
654
18acc6f8 655 data = string_field->buf->data;
7b33a0e0
PP
656 memcpy(data + string_field->length, value, length);
657 ((char *) string_field->buf->data)[new_length] = '\0';
658 string_field->length = new_length;
659 bt_field_set_single(field, true);
18acc6f8
PP
660 return 0;
661}
8deee039 662
18acc6f8
PP
663int bt_field_string_clear(struct bt_field *field)
664{
665 struct bt_field_string *string_field = (void *) field;
666
7b33a0e0
PP
667 BT_ASSERT_PRE_NON_NULL(field, "Field");
668 BT_ASSERT_PRE_FIELD_HOT(field, "Field");
939190b3
PP
669 BT_ASSERT_PRE_FIELD_HAS_CLASS_ID(field,
670 BT_FIELD_CLASS_ID_STRING, "Field");
7b33a0e0
PP
671 string_field->length = 0;
672 bt_field_set_single(field, true);
18acc6f8
PP
673 return 0;
674}
675
7b33a0e0 676uint64_t bt_field_array_get_length(struct bt_field *field)
18acc6f8 677{
7b33a0e0 678 struct bt_field_array *array_field = (void *) field;
c6f9c5a3 679
7b33a0e0
PP
680 BT_ASSERT_PRE_NON_NULL(field, "Field");
681 BT_ASSERT_PRE_FIELD_IS_ARRAY(field, "Field");
682 return array_field->length;
8deee039 683}
f98c6554 684
7b33a0e0
PP
685int bt_field_dynamic_array_set_length(struct bt_field *field,
686 uint64_t length)
8deee039 687{
7b33a0e0
PP
688 int ret = 0;
689 struct bt_field_array *array_field = (void *) field;
f98c6554 690
7b33a0e0 691 BT_ASSERT_PRE_NON_NULL(field, "Field");
939190b3
PP
692 BT_ASSERT_PRE_FIELD_HAS_CLASS_ID(field,
693 BT_FIELD_CLASS_ID_DYNAMIC_ARRAY, "Field");
7b33a0e0 694 BT_ASSERT_PRE_FIELD_HOT(field, "Field");
273b65be 695
7b33a0e0
PP
696 if (unlikely(length > array_field->fields->len)) {
697 /* Make more room */
939190b3 698 struct bt_field_class_array *array_fc;
7b33a0e0
PP
699 uint64_t cur_len = array_field->fields->len;
700 uint64_t i;
18acc6f8 701
7b33a0e0 702 g_ptr_array_set_size(array_field->fields, length);
939190b3 703 array_fc = (void *) field->class;
18acc6f8 704
7b33a0e0
PP
705 for (i = cur_len; i < array_field->fields->len; i++) {
706 struct bt_field *elem_field = bt_field_create(
939190b3 707 array_fc->element_fc);
273b65be 708
7b33a0e0
PP
709 if (!elem_field) {
710 BT_LIB_LOGE("Cannot create element field for "
711 "dynamic array field: "
712 "index=%" PRIu64 ", "
713 "%![array-field-]+f", i, field);
714 ret = -1;
715 goto end;
716 }
9be89173 717
7b33a0e0
PP
718 BT_ASSERT(!array_field->fields->pdata[i]);
719 array_field->fields->pdata[i] = elem_field;
9be89173 720 }
9be89173
JG
721 }
722
7b33a0e0 723 array_field->length = length;
8deee039 724
273b65be 725end:
9be89173 726 return ret;
273b65be
JG
727}
728
7b33a0e0
PP
729struct bt_field *bt_field_array_borrow_element_field_by_index(
730 struct bt_field *field, uint64_t index)
a6918753 731{
7b33a0e0 732 struct bt_field_array *array_field = (void *) field;
a6918753 733
7b33a0e0
PP
734 BT_ASSERT_PRE_NON_NULL(field, "Field");
735 BT_ASSERT_PRE_FIELD_IS_ARRAY(field, "Field");
736 BT_ASSERT_PRE_VALID_INDEX(index, array_field->length);
737 return array_field->fields->pdata[index];
a6918753
PP
738}
739
7b33a0e0
PP
740struct bt_field *bt_field_structure_borrow_member_field_by_index(
741 struct bt_field *field, uint64_t index)
e42dd763 742{
7b33a0e0 743 struct bt_field_structure *struct_field = (void *) field;
e42dd763 744
7b33a0e0 745 BT_ASSERT_PRE_NON_NULL(field, "Field");
939190b3
PP
746 BT_ASSERT_PRE_FIELD_HAS_CLASS_ID(field,
747 BT_FIELD_CLASS_ID_STRUCTURE, "Field");
7b33a0e0
PP
748 BT_ASSERT_PRE_VALID_INDEX(index, struct_field->fields->len);
749 return struct_field->fields->pdata[index];
e42dd763
PP
750}
751
7b33a0e0
PP
752struct bt_field *bt_field_structure_borrow_member_field_by_name(
753 struct bt_field *field, const char *name)
273b65be 754{
7b33a0e0 755 struct bt_field *ret_field = NULL;
939190b3 756 struct bt_field_class_structure *struct_fc;
7b33a0e0
PP
757 struct bt_field_structure *struct_field = (void *) field;
758 gpointer orig_key;
759 gpointer index;
fc25abce 760
7b33a0e0
PP
761 BT_ASSERT_PRE_NON_NULL(field, "Field");
762 BT_ASSERT_PRE_NON_NULL(name, "Field name");
939190b3
PP
763 BT_ASSERT_PRE_FIELD_HAS_CLASS_ID(field,
764 BT_FIELD_CLASS_ID_STRUCTURE, "Field");
765 struct_fc = (void *) field->class;
a6918753 766
939190b3 767 if (!g_hash_table_lookup_extended(struct_fc->common.name_to_index, name,
7b33a0e0 768 &orig_key, &index)) {
a6918753 769 goto end;
fc25abce
PP
770 }
771
7b33a0e0
PP
772 ret_field = struct_field->fields->pdata[GPOINTER_TO_UINT(index)];
773 BT_ASSERT(ret_field);
a6918753
PP
774
775end:
7b33a0e0 776 return ret_field;
273b65be
JG
777}
778
7b33a0e0
PP
779struct bt_field *bt_field_variant_borrow_selected_option_field(
780 struct bt_field *field)
273b65be 781{
7b33a0e0 782 struct bt_field_variant *var_field = (void *) field;
273b65be 783
7b33a0e0 784 BT_ASSERT_PRE_NON_NULL(field, "Field");
939190b3
PP
785 BT_ASSERT_PRE_FIELD_HAS_CLASS_ID(field,
786 BT_FIELD_CLASS_ID_VARIANT, "Field");
7b33a0e0
PP
787 BT_ASSERT_PRE(var_field->selected_field,
788 "Variant field has no selected field: %!+f", field);
789 return var_field->selected_field;
273b65be
JG
790}
791
7b33a0e0
PP
792int bt_field_variant_select_option_field(struct bt_field *field,
793 uint64_t index)
273b65be 794{
7b33a0e0 795 struct bt_field_variant *var_field = (void *) field;
fc25abce 796
7b33a0e0 797 BT_ASSERT_PRE_NON_NULL(field, "Field");
939190b3
PP
798 BT_ASSERT_PRE_FIELD_HAS_CLASS_ID(field,
799 BT_FIELD_CLASS_ID_VARIANT, "Field");
7b33a0e0
PP
800 BT_ASSERT_PRE_FIELD_HOT(field, "Field");
801 BT_ASSERT_PRE_VALID_INDEX(index, var_field->fields->len);
802 var_field->selected_field = var_field->fields->pdata[index];
803 var_field->selected_index = index;
804 return 0;
273b65be
JG
805}
806
7b33a0e0
PP
807uint64_t bt_field_variant_get_selected_option_field_index(
808 struct bt_field *field)
a6918753 809{
7b33a0e0 810 struct bt_field_variant *var_field = (void *) field;
a6918753 811
7b33a0e0 812 BT_ASSERT_PRE_NON_NULL(field, "Field");
939190b3
PP
813 BT_ASSERT_PRE_FIELD_HAS_CLASS_ID(field,
814 BT_FIELD_CLASS_ID_VARIANT, "Field");
7b33a0e0
PP
815 BT_ASSERT_PRE(var_field->selected_field,
816 "Variant field has no selected field: %!+f", field);
817 return var_field->selected_index;
a6918753
PP
818}
819
7b33a0e0
PP
820static inline
821void bt_field_finalize(struct bt_field *field)
273b65be 822{
7b33a0e0 823 BT_ASSERT(field);
939190b3
PP
824 BT_LOGD_STR("Putting field's class.");
825 bt_put(field->class);
273b65be
JG
826}
827
828static
7b33a0e0 829void destroy_integer_field(struct bt_field *field)
273b65be 830{
7b33a0e0
PP
831 BT_ASSERT(field);
832 BT_LIB_LOGD("Destroying integer field object: %!+f", field);
833 bt_field_finalize(field);
834 g_free(field);
273b65be
JG
835}
836
18acc6f8 837static
7b33a0e0 838void destroy_real_field(struct bt_field *field)
273b65be 839{
7b33a0e0
PP
840 BT_ASSERT(field);
841 BT_LIB_LOGD("Destroying real field object: %!+f", field);
842 bt_field_finalize(field);
843 g_free(field);
273b65be
JG
844}
845
18acc6f8 846static
7b33a0e0 847void destroy_structure_field(struct bt_field *field)
273b65be 848{
7b33a0e0 849 struct bt_field_structure *struct_field = (void *) field;
273b65be 850
8b45963b 851 BT_ASSERT(field);
7b33a0e0
PP
852 BT_LIB_LOGD("Destroying structure field object: %!+f", field);
853 bt_field_finalize(field);
8b45963b 854
7b33a0e0
PP
855 if (struct_field->fields) {
856 g_ptr_array_free(struct_field->fields, TRUE);
273b65be 857 }
8b45963b 858
7b33a0e0 859 g_free(field);
273b65be
JG
860}
861
18acc6f8 862static
7b33a0e0 863void destroy_variant_field(struct bt_field *field)
273b65be 864{
7b33a0e0 865 struct bt_field_variant *var_field = (void *) field;
273b65be 866
8b45963b 867 BT_ASSERT(field);
7b33a0e0
PP
868 BT_LIB_LOGD("Destroying variant field object: %!+f", field);
869 bt_field_finalize(field);
a6918753 870
7b33a0e0
PP
871 if (var_field->fields) {
872 g_ptr_array_free(var_field->fields, TRUE);
fc25abce 873 }
8b45963b 874
7b33a0e0 875 g_free(field);
273b65be
JG
876}
877
18acc6f8 878static
7b33a0e0 879void destroy_array_field(struct bt_field *field)
273b65be 880{
7b33a0e0 881 struct bt_field_array *array_field = (void *) field;
273b65be 882
8b45963b 883 BT_ASSERT(field);
7b33a0e0
PP
884 BT_LIB_LOGD("Destroying array field object: %!+f", field);
885 bt_field_finalize(field);
8deee039 886
7b33a0e0
PP
887 if (array_field->fields) {
888 g_ptr_array_free(array_field->fields, TRUE);
273b65be 889 }
8b45963b 890
7b33a0e0 891 g_free(field);
273b65be
JG
892}
893
18acc6f8 894static
7b33a0e0 895void destroy_string_field(struct bt_field *field)
273b65be 896{
7b33a0e0 897 struct bt_field_string *string_field = (void *) field;
273b65be 898
8b45963b 899 BT_ASSERT(field);
7b33a0e0
PP
900 BT_LIB_LOGD("Destroying string field object: %!+f", field);
901 bt_field_finalize(field);
8deee039 902
7b33a0e0
PP
903 if (string_field->buf) {
904 g_array_free(string_field->buf, TRUE);
273b65be 905 }
7b33a0e0
PP
906
907 g_free(field);
273b65be
JG
908}
909
7b33a0e0
PP
910BT_HIDDEN
911void bt_field_destroy(struct bt_field *field)
12c8a1a3 912{
8b45963b 913 BT_ASSERT(field);
939190b3
PP
914 BT_ASSERT(bt_field_class_has_known_id(field->class));
915 field_destroy_funcs[field->class->id](field);
12c8a1a3
JG
916}
917
18acc6f8 918static
7b33a0e0 919void reset_single_field(struct bt_field *field)
12c8a1a3 920{
8b45963b 921 BT_ASSERT(field);
7b33a0e0 922 field->is_set = false;
12c8a1a3
JG
923}
924
18acc6f8 925static
7b33a0e0 926void reset_structure_field(struct bt_field *field)
12c8a1a3 927{
7b33a0e0
PP
928 uint64_t i;
929 struct bt_field_structure *struct_field = (void *) field;
12c8a1a3 930
8b45963b 931 BT_ASSERT(field);
7b33a0e0
PP
932
933 for (i = 0; i < struct_field->fields->len; i++) {
934 bt_field_reset(struct_field->fields->pdata[i]);
935 }
12c8a1a3
JG
936}
937
18acc6f8 938static
7b33a0e0 939void reset_variant_field(struct bt_field *field)
12c8a1a3 940{
7b33a0e0
PP
941 uint64_t i;
942 struct bt_field_variant *var_field = (void *) field;
12c8a1a3 943
8b45963b 944 BT_ASSERT(field);
8b45963b 945
7b33a0e0
PP
946 for (i = 0; i < var_field->fields->len; i++) {
947 bt_field_reset(var_field->fields->pdata[i]);
12c8a1a3 948 }
12c8a1a3
JG
949}
950
18acc6f8 951static
7b33a0e0 952void reset_array_field(struct bt_field *field)
12c8a1a3 953{
a6918753 954 uint64_t i;
7b33a0e0 955 struct bt_field_array *array_field = (void *) field;
12c8a1a3 956
8b45963b 957 BT_ASSERT(field);
8b45963b 958
7b33a0e0
PP
959 for (i = 0; i < array_field->fields->len; i++) {
960 bt_field_reset(array_field->fields->pdata[i]);
12c8a1a3 961 }
12c8a1a3
JG
962}
963
18acc6f8 964static
7b33a0e0 965void set_single_field_is_frozen(struct bt_field *field, bool is_frozen)
918be005 966{
a6918753 967 field->frozen = is_frozen;
918be005
PP
968}
969
18acc6f8 970static
7b33a0e0 971void set_structure_field_is_frozen(struct bt_field *field, bool is_frozen)
918be005 972{
a6918753 973 uint64_t i;
7b33a0e0 974 struct bt_field_structure *struct_field = (void *) field;
918be005 975
7b33a0e0
PP
976 BT_LIB_LOGD("Setting structure field's frozen state: "
977 "%![field-]+f, is-frozen=%d", field, is_frozen);
fc25abce 978
7b33a0e0
PP
979 for (i = 0; i < struct_field->fields->len; i++) {
980 struct bt_field *member_field = struct_field->fields->pdata[i];
918be005 981
7b33a0e0
PP
982 BT_LIB_LOGD("Setting structure field's member field's "
983 "frozen state: %![field-]+f, index=%" PRIu64,
984 member_field, i);
985 bt_field_set_is_frozen(member_field, is_frozen);
918be005
PP
986 }
987
7b33a0e0 988 set_single_field_is_frozen(field, is_frozen);
918be005
PP
989}
990
18acc6f8 991static
7b33a0e0 992void set_variant_field_is_frozen(struct bt_field *field, bool is_frozen)
918be005 993{
a6918753 994 uint64_t i;
7b33a0e0 995 struct bt_field_variant *var_field = (void *) field;
918be005 996
7b33a0e0
PP
997 BT_LIB_LOGD("Setting variant field's frozen state: "
998 "%![field-]+f, is-frozen=%d", field, is_frozen);
a6918753 999
7b33a0e0
PP
1000 for (i = 0; i < var_field->fields->len; i++) {
1001 struct bt_field *option_field = var_field->fields->pdata[i];
a6918753 1002
7b33a0e0
PP
1003 BT_LIB_LOGD("Setting variant field's option field's "
1004 "frozen state: %![field-]+f, index=%" PRIu64,
1005 option_field, i);
1006 bt_field_set_is_frozen(option_field, is_frozen);
a6918753
PP
1007 }
1008
7b33a0e0 1009 set_single_field_is_frozen(field, is_frozen);
918be005
PP
1010}
1011
18acc6f8 1012static
7b33a0e0 1013void set_array_field_is_frozen(struct bt_field *field, bool is_frozen)
918be005 1014{
7b33a0e0 1015 uint64_t i;
18acc6f8 1016 struct bt_field_array *array_field = (void *) field;
918be005 1017
7b33a0e0
PP
1018 BT_LIB_LOGD("Setting array field's frozen state: "
1019 "%![field-]+f, is-frozen=%d", field, is_frozen);
fc25abce 1020
7b33a0e0
PP
1021 for (i = 0; i < array_field->fields->len; i++) {
1022 struct bt_field *elem_field = array_field->fields->pdata[i];
918be005 1023
7b33a0e0
PP
1024 BT_LIB_LOGD("Setting array field's element field's "
1025 "frozen state: %![field-]+f, index=%" PRIu64,
fc25abce 1026 elem_field, i);
7b33a0e0 1027 bt_field_set_is_frozen(elem_field, is_frozen);
918be005
PP
1028 }
1029
7b33a0e0 1030 set_single_field_is_frozen(field, is_frozen);
918be005
PP
1031}
1032
1033BT_HIDDEN
7b33a0e0 1034void _bt_field_set_is_frozen(struct bt_field *field,
a6918753 1035 bool is_frozen)
918be005 1036{
7b33a0e0
PP
1037 BT_ASSERT(field);
1038 BT_LIB_LOGD("Setting field object's frozen state: %!+f, is-frozen=%d",
a6918753 1039 field, is_frozen);
a6918753
PP
1040 BT_ASSERT(field->methods->set_is_frozen);
1041 field->methods->set_is_frozen(field, is_frozen);
918be005 1042}
76f869ab 1043
18acc6f8 1044static
7b33a0e0 1045bool single_field_is_set(struct bt_field *field)
76f869ab 1046{
7b33a0e0
PP
1047 BT_ASSERT(field);
1048 return field->is_set;
76f869ab
JG
1049}
1050
18acc6f8 1051static
7b33a0e0 1052bool structure_field_is_set(struct bt_field *field)
76f869ab 1053{
7b33a0e0
PP
1054 bool is_set = true;
1055 uint64_t i;
1056 struct bt_field_structure *struct_field = (void *) field;
76f869ab 1057
8b45963b 1058 BT_ASSERT(field);
8deee039 1059
7b33a0e0
PP
1060 for (i = 0; i < struct_field->fields->len; i++) {
1061 is_set = bt_field_is_set(struct_field->fields->pdata[i]);
53d65c1d 1062 if (!is_set) {
76f869ab
JG
1063 goto end;
1064 }
1065 }
8deee039 1066
76f869ab 1067end:
53d65c1d 1068 return is_set;
76f869ab
JG
1069}
1070
18acc6f8 1071static
7b33a0e0 1072bool variant_field_is_set(struct bt_field *field)
76f869ab 1073{
7b33a0e0
PP
1074 struct bt_field_variant *var_field = (void *) field;
1075 bool is_set = false;
76f869ab 1076
8b45963b 1077 BT_ASSERT(field);
8deee039 1078
7b33a0e0
PP
1079 if (var_field->selected_field) {
1080 is_set = bt_field_is_set(var_field->selected_field);
76f869ab 1081 }
8deee039 1082
53d65c1d 1083 return is_set;
76f869ab
JG
1084}
1085
18acc6f8 1086static
7b33a0e0 1087bool array_field_is_set(struct bt_field *field)
76f869ab 1088{
7b33a0e0
PP
1089 bool is_set = true;
1090 uint64_t i;
1091 struct bt_field_array *array_field = (void *) field;
76f869ab 1092
8b45963b 1093 BT_ASSERT(field);
8deee039 1094
7b33a0e0
PP
1095 for (i = 0; i < array_field->length; i++) {
1096 is_set = bt_field_is_set(array_field->fields->pdata[i]);
53d65c1d 1097 if (!is_set) {
76f869ab
JG
1098 goto end;
1099 }
1100 }
8deee039 1101
76f869ab 1102end:
53d65c1d 1103 return is_set;
76f869ab 1104}
This page took 0.12175 seconds and 4 git commands to generate.