Cleanup: add `#include <stdbool.h>` whenever `bool` type is used
[babeltrace.git] / src / lib / trace-ir / field.c
CommitLineData
273b65be 1/*
f2b0325d 2 * Copyright 2017-2018 Philippe Proulx <pproulx@efficios.com>
de9dd397 3 * Copyright 2013, 2014 Jérémie Galarneau <jeremie.galarneau@efficios.com>
273b65be
JG
4 *
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"
1633ef46 25#include "lib/logging.h"
fc25abce 26
57952005 27#include "lib/assert-pre.h"
71c5da58
MJ
28#include <babeltrace2/trace-ir/field.h>
29#include <babeltrace2/trace-ir/field-const.h>
57952005
MJ
30#include "lib/object.h"
31#include "compat/compiler.h"
32#include "compat/fcntl.h"
33#include "common/align.h"
34#include "common/assert.h"
fc25abce 35#include <inttypes.h>
969c1d8a 36#include <stdbool.h>
273b65be 37
57952005
MJ
38#include "field.h"
39#include "field-class.h"
fb25b9e3 40#include "lib/func-status.h"
57952005 41
18acc6f8 42static
7b33a0e0 43void reset_single_field(struct bt_field *field);
18acc6f8
PP
44
45static
7b33a0e0 46void reset_array_field(struct bt_field *field);
18acc6f8
PP
47
48static
7b33a0e0 49void reset_structure_field(struct bt_field *field);
18acc6f8 50
247fa9e3
PP
51static
52void reset_option_field(struct bt_field *field);
53
18acc6f8 54static
7b33a0e0 55void reset_variant_field(struct bt_field *field);
18acc6f8
PP
56
57static
7b33a0e0 58void set_single_field_is_frozen(struct bt_field *field, bool is_frozen);
18acc6f8
PP
59
60static
7b33a0e0 61void set_array_field_is_frozen(struct bt_field *field, bool is_frozen);
18acc6f8
PP
62
63static
7b33a0e0 64void set_structure_field_is_frozen(struct bt_field *field, bool is_frozen);
18acc6f8 65
247fa9e3
PP
66static
67void set_option_field_is_frozen(struct bt_field *field, bool is_frozen);
68
18acc6f8 69static
7b33a0e0 70void set_variant_field_is_frozen(struct bt_field *field, bool is_frozen);
18acc6f8
PP
71
72static
78cf9df6 73bool single_field_is_set(const struct bt_field *field);
18acc6f8
PP
74
75static
78cf9df6 76bool array_field_is_set(const struct bt_field *field);
18acc6f8
PP
77
78static
78cf9df6 79bool structure_field_is_set(const struct bt_field *field);
18acc6f8 80
247fa9e3
PP
81static
82bool option_field_is_set(const struct bt_field *field);
83
18acc6f8 84static
78cf9df6 85bool variant_field_is_set(const struct bt_field *field);
18acc6f8 86
9414b439
PP
87static
88struct bt_field_methods bool_field_methods = {
89 .set_is_frozen = set_single_field_is_frozen,
90 .is_set = single_field_is_set,
91 .reset = reset_single_field,
92};
93
6943da6a
PP
94static
95struct bt_field_methods bit_array_field_methods = {
96 .set_is_frozen = set_single_field_is_frozen,
97 .is_set = single_field_is_set,
98 .reset = reset_single_field,
99};
100
18acc6f8 101static
7b33a0e0
PP
102struct bt_field_methods integer_field_methods = {
103 .set_is_frozen = set_single_field_is_frozen,
104 .is_set = single_field_is_set,
105 .reset = reset_single_field,
8deee039 106};
273b65be 107
7b33a0e0
PP
108static
109struct bt_field_methods real_field_methods = {
110 .set_is_frozen = set_single_field_is_frozen,
111 .is_set = single_field_is_set,
112 .reset = reset_single_field,
12c8a1a3
JG
113};
114
7b33a0e0
PP
115static
116struct bt_field_methods string_field_methods = {
117 .set_is_frozen = set_single_field_is_frozen,
118 .is_set = single_field_is_set,
119 .reset = reset_single_field,
273b65be
JG
120};
121
7b33a0e0
PP
122static
123struct bt_field_methods structure_field_methods = {
124 .set_is_frozen = set_structure_field_is_frozen,
125 .is_set = structure_field_is_set,
126 .reset = reset_structure_field,
87d43dc1
JG
127};
128
7b33a0e0
PP
129static
130struct bt_field_methods array_field_methods = {
131 .set_is_frozen = set_array_field_is_frozen,
132 .is_set = array_field_is_set,
133 .reset = reset_array_field,
918be005
PP
134};
135
247fa9e3
PP
136static
137struct bt_field_methods option_field_methods = {
138 .set_is_frozen = set_option_field_is_frozen,
139 .is_set = option_field_is_set,
140 .reset = reset_option_field,
141};
142
76f869ab 143static
7b33a0e0
PP
144struct bt_field_methods variant_field_methods = {
145 .set_is_frozen = set_variant_field_is_frozen,
146 .is_set = variant_field_is_set,
147 .reset = reset_variant_field,
148};
76f869ab 149
9414b439
PP
150static
151struct bt_field *create_bool_field(struct bt_field_class *);
152
6943da6a
PP
153static
154struct bt_field *create_bit_array_field(struct bt_field_class *);
155
8deee039 156static
939190b3 157struct bt_field *create_integer_field(struct bt_field_class *);
8deee039
PP
158
159static
939190b3 160struct bt_field *create_real_field(struct bt_field_class *);
8deee039
PP
161
162static
939190b3 163struct bt_field *create_string_field(struct bt_field_class *);
8deee039
PP
164
165static
939190b3 166struct bt_field *create_structure_field(struct bt_field_class *);
5d2d8d18 167
8deee039 168static
939190b3 169struct bt_field *create_static_array_field(struct bt_field_class *);
8b45963b 170
8deee039 171static
939190b3 172struct bt_field *create_dynamic_array_field(struct bt_field_class *);
8b45963b 173
247fa9e3
PP
174static
175struct bt_field *create_option_field(struct bt_field_class *);
176
8deee039 177static
939190b3 178struct bt_field *create_variant_field(struct bt_field_class *);
8b45963b 179
9414b439
PP
180static
181void destroy_bool_field(struct bt_field *field);
182
6943da6a
PP
183static
184void destroy_bit_array_field(struct bt_field *field);
185
a6918753 186static
7b33a0e0 187void destroy_integer_field(struct bt_field *field);
a6918753
PP
188
189static
7b33a0e0 190void destroy_real_field(struct bt_field *field);
a6918753
PP
191
192static
7b33a0e0 193void destroy_string_field(struct bt_field *field);
a6918753
PP
194
195static
7b33a0e0 196void destroy_structure_field(struct bt_field *field);
a6918753
PP
197
198static
7b33a0e0 199void destroy_array_field(struct bt_field *field);
a6918753 200
247fa9e3
PP
201static
202void destroy_option_field(struct bt_field *field);
203
a6918753 204static
7b33a0e0 205void destroy_variant_field(struct bt_field *field);
a6918753 206
844d5df6 207struct bt_field_class *bt_field_borrow_class(struct bt_field *field)
18acc6f8 208{
fa6cfec3 209 BT_ASSERT_PRE_DEV_NON_NULL(field, "Field");
939190b3 210 return field->class;
18acc6f8
PP
211}
212
78cf9df6
PP
213const struct bt_field_class *bt_field_borrow_class_const(
214 const struct bt_field *field)
9e550e5f 215{
fa6cfec3 216 BT_ASSERT_PRE_DEV_NON_NULL(field, "Field");
78cf9df6 217 return field->class;
9e550e5f
PP
218}
219
78cf9df6 220enum bt_field_class_type bt_field_get_class_type(const struct bt_field *field)
18acc6f8 221{
fa6cfec3 222 BT_ASSERT_PRE_DEV_NON_NULL(field, "Field");
af0c18e3 223 return field->class->type;
18acc6f8
PP
224}
225
a6918753 226BT_HIDDEN
939190b3 227struct bt_field *bt_field_create(struct bt_field_class *fc)
273b65be 228{
839d52a5 229 struct bt_field *field = NULL;
7b33a0e0 230
fa6cfec3 231 BT_ASSERT(fc);
5d2d8d18
PP
232
233 switch (fc->type) {
234 case BT_FIELD_CLASS_TYPE_BOOL:
235 field = create_bool_field(fc);
236 break;
237 case BT_FIELD_CLASS_TYPE_BIT_ARRAY:
238 field = create_bit_array_field(fc);
239 break;
240 case BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER:
241 case BT_FIELD_CLASS_TYPE_SIGNED_INTEGER:
242 case BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION:
243 case BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION:
244 field = create_integer_field(fc);
245 break;
246 case BT_FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL:
247 case BT_FIELD_CLASS_TYPE_DOUBLE_PRECISION_REAL:
248 field = create_real_field(fc);
249 break;
250 case BT_FIELD_CLASS_TYPE_STRING:
251 field = create_string_field(fc);
252 break;
253 case BT_FIELD_CLASS_TYPE_STRUCTURE:
254 field = create_structure_field(fc);
255 break;
256 case BT_FIELD_CLASS_TYPE_STATIC_ARRAY:
257 field = create_static_array_field(fc);
258 break;
259 case BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITHOUT_LENGTH_FIELD:
260 case BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITH_LENGTH_FIELD:
261 field = create_dynamic_array_field(fc);
262 break;
263 case BT_FIELD_CLASS_TYPE_OPTION_WITHOUT_SELECTOR_FIELD:
264 case BT_FIELD_CLASS_TYPE_OPTION_WITH_BOOL_SELECTOR_FIELD:
265 case BT_FIELD_CLASS_TYPE_OPTION_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD:
266 case BT_FIELD_CLASS_TYPE_OPTION_WITH_SIGNED_INTEGER_SELECTOR_FIELD:
267 field = create_option_field(fc);
268 break;
269 case BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR_FIELD:
270 case BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD:
271 case BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR_FIELD:
272 field = create_variant_field(fc);
273 break;
274 default:
275 abort();
276 }
277
273b65be 278 if (!field) {
a8f90e5d 279 BT_LIB_LOGE_APPEND_CAUSE("Cannot create field object from field class: "
939190b3 280 "%![fc-]+F", fc);
8deee039 281 goto end;
273b65be
JG
282 }
283
8deee039
PP
284end:
285 return field;
273b65be
JG
286}
287
7b33a0e0 288static inline
939190b3 289void init_field(struct bt_field *field, struct bt_field_class *fc,
7b33a0e0 290 struct bt_field_methods *methods)
cd95e351 291{
7b33a0e0 292 BT_ASSERT(field);
939190b3 293 BT_ASSERT(fc);
7b33a0e0
PP
294 bt_object_init_unique(&field->base);
295 field->methods = methods;
4b70020d 296 field->class = fc;
864aa43f 297 bt_object_get_ref_no_null_check(fc);
cd95e351
JG
298}
299
9414b439
PP
300static
301struct bt_field *create_bool_field(struct bt_field_class *fc)
302{
303 struct bt_field_bool *bool_field;
304
305 BT_LIB_LOGD("Creating boolean field object: %![fc-]+F", fc);
306 bool_field = g_new0(struct bt_field_bool, 1);
307 if (!bool_field) {
308 BT_LIB_LOGE_APPEND_CAUSE(
309 "Failed to allocate one boolean field.");
310 goto end;
311 }
312
313 init_field((void *) bool_field, fc, &bool_field_methods);
314 BT_LIB_LOGD("Created boolean field object: %!+f", bool_field);
315
316end:
317 return (void *) bool_field;
318}
319
6943da6a
PP
320static
321struct bt_field *create_bit_array_field(struct bt_field_class *fc)
322{
323 struct bt_field_bit_array *ba_field;
324
325 BT_LIB_LOGD("Creating bit array field object: %![fc-]+F", fc);
326 ba_field = g_new0(struct bt_field_bit_array, 1);
327 if (!ba_field) {
328 BT_LIB_LOGE_APPEND_CAUSE(
329 "Failed to allocate one bit array field.");
330 goto end;
331 }
332
333 init_field((void *) ba_field, fc, &bit_array_field_methods);
334 BT_LIB_LOGD("Created bit array field object: %!+f", ba_field);
335
336end:
337 return (void *) ba_field;
338}
339
7b33a0e0 340static
939190b3 341struct bt_field *create_integer_field(struct bt_field_class *fc)
4ebcc695 342{
7b33a0e0
PP
343 struct bt_field_integer *int_field;
344
939190b3 345 BT_LIB_LOGD("Creating integer field object: %![fc-]+F", fc);
7b33a0e0
PP
346 int_field = g_new0(struct bt_field_integer, 1);
347 if (!int_field) {
a8f90e5d
PP
348 BT_LIB_LOGE_APPEND_CAUSE(
349 "Failed to allocate one integer field.");
7b33a0e0
PP
350 goto end;
351 }
352
939190b3 353 init_field((void *) int_field, fc, &integer_field_methods);
7b33a0e0
PP
354 BT_LIB_LOGD("Created integer field object: %!+f", int_field);
355
356end:
357 return (void *) int_field;
4ebcc695
PP
358}
359
7b33a0e0 360static
939190b3 361struct bt_field *create_real_field(struct bt_field_class *fc)
fea75608 362{
7b33a0e0 363 struct bt_field_real *real_field;
18acc6f8 364
939190b3 365 BT_LIB_LOGD("Creating real field object: %![fc-]+F", fc);
7b33a0e0
PP
366 real_field = g_new0(struct bt_field_real, 1);
367 if (!real_field) {
a8f90e5d 368 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate one real field.");
7b33a0e0
PP
369 goto end;
370 }
371
939190b3 372 init_field((void *) real_field, fc, &real_field_methods);
7b33a0e0
PP
373 BT_LIB_LOGD("Created real field object: %!+f", real_field);
374
375end:
376 return (void *) real_field;
fea75608
PP
377}
378
7b33a0e0 379static
939190b3 380struct bt_field *create_string_field(struct bt_field_class *fc)
273b65be 381{
7b33a0e0 382 struct bt_field_string *string_field;
18acc6f8 383
939190b3 384 BT_LIB_LOGD("Creating string field object: %![fc-]+F", fc);
7b33a0e0
PP
385 string_field = g_new0(struct bt_field_string, 1);
386 if (!string_field) {
a8f90e5d
PP
387 BT_LIB_LOGE_APPEND_CAUSE(
388 "Failed to allocate one string field.");
7b33a0e0
PP
389 goto end;
390 }
18acc6f8 391
939190b3 392 init_field((void *) string_field, fc, &string_field_methods);
7b33a0e0
PP
393 string_field->buf = g_array_sized_new(FALSE, FALSE,
394 sizeof(char), 1);
395 if (!string_field->buf) {
a8f90e5d 396 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GArray.");
6a9bd19d
FD
397 bt_field_destroy((void *) string_field);
398 string_field = NULL;
7b33a0e0
PP
399 goto end;
400 }
18acc6f8 401
7b33a0e0
PP
402 g_array_index(string_field->buf, char, 0) = '\0';
403 BT_LIB_LOGD("Created string field object: %!+f", string_field);
18acc6f8 404
7b33a0e0
PP
405end:
406 return (void *) string_field;
407}
18acc6f8 408
7b33a0e0 409static inline
939190b3
PP
410int create_fields_from_named_field_classes(
411 struct bt_field_class_named_field_class_container *fc,
7b33a0e0
PP
412 GPtrArray **fields)
413{
414 int ret = 0;
415 uint64_t i;
18acc6f8 416
7b33a0e0
PP
417 *fields = g_ptr_array_new_with_free_func(
418 (GDestroyNotify) bt_field_destroy);
419 if (!*fields) {
a8f90e5d 420 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GPtrArray.");
7b33a0e0
PP
421 ret = -1;
422 goto end;
18acc6f8
PP
423 }
424
939190b3 425 g_ptr_array_set_size(*fields, fc->named_fcs->len);
7b33a0e0 426
939190b3 427 for (i = 0; i < fc->named_fcs->len; i++) {
7b33a0e0 428 struct bt_field *field;
02b61fe0 429 struct bt_named_field_class *named_fc = fc->named_fcs->pdata[i];
7b33a0e0 430
939190b3 431 field = bt_field_create(named_fc->fc);
7b33a0e0 432 if (!field) {
a8f90e5d
PP
433 BT_LIB_LOGE_APPEND_CAUSE(
434 "Failed to create structure member or variant option field: "
939190b3
PP
435 "name=\"%s\", %![fc-]+F",
436 named_fc->name->str, named_fc->fc);
7b33a0e0
PP
437 ret = -1;
438 goto end;
439 }
440
441 g_ptr_array_index(*fields, i) = field;
442 }
18acc6f8
PP
443
444end:
445 return ret;
273b65be
JG
446}
447
7b33a0e0 448static
939190b3 449struct bt_field *create_structure_field(struct bt_field_class *fc)
cd95e351 450{
7b33a0e0 451 struct bt_field_structure *struct_field;
18acc6f8 452
939190b3 453 BT_LIB_LOGD("Creating structure field object: %![fc-]+F", fc);
7b33a0e0
PP
454 struct_field = g_new0(struct bt_field_structure, 1);
455 if (!struct_field) {
a8f90e5d
PP
456 BT_LIB_LOGE_APPEND_CAUSE(
457 "Failed to allocate one structure field.");
7b33a0e0
PP
458 goto end;
459 }
fc25abce 460
939190b3 461 init_field((void *) struct_field, fc, &structure_field_methods);
7b33a0e0 462
939190b3 463 if (create_fields_from_named_field_classes((void *) fc,
7b33a0e0 464 &struct_field->fields)) {
a8f90e5d
PP
465 BT_LIB_LOGE_APPEND_CAUSE(
466 "Cannot create structure member fields: %![fc-]+F", fc);
6a9bd19d
FD
467 bt_field_destroy((void *) struct_field);
468 struct_field = NULL;
7b33a0e0 469 goto end;
18acc6f8
PP
470 }
471
7b33a0e0 472 BT_LIB_LOGD("Created structure field object: %!+f", struct_field);
18acc6f8 473
7b33a0e0
PP
474end:
475 return (void *) struct_field;
cd95e351
JG
476}
477
247fa9e3
PP
478static
479struct bt_field *create_option_field(struct bt_field_class *fc)
480{
481 struct bt_field_option *opt_field;
482 struct bt_field_class_option *opt_fc = (void *) fc;
483
484 BT_LIB_LOGD("Creating option field object: %![fc-]+F", fc);
485 opt_field = g_new0(struct bt_field_option, 1);
486 if (!opt_field) {
487 BT_LIB_LOGE_APPEND_CAUSE(
488 "Failed to allocate one option field.");
489 goto end;
490 }
491
492 init_field((void *) opt_field, fc, &option_field_methods);
493 opt_field->content_field = bt_field_create(opt_fc->content_fc);
494 if (!opt_field->content_field) {
495 BT_LIB_LOGE_APPEND_CAUSE(
496 "Failed to create option field's content field: "
497 "%![opt-fc-]+F, %![content-fc-]+F",
498 opt_fc, opt_fc->content_fc);
6a9bd19d
FD
499 bt_field_destroy((void *) opt_field);
500 opt_field = NULL;
247fa9e3
PP
501 goto end;
502 }
503
504 BT_LIB_LOGD("Created option field object: %!+f", opt_field);
505
506end:
507 return (void *) opt_field;
508}
509
7b33a0e0 510static
939190b3 511struct bt_field *create_variant_field(struct bt_field_class *fc)
273b65be 512{
7b33a0e0 513 struct bt_field_variant *var_field;
18acc6f8 514
939190b3 515 BT_LIB_LOGD("Creating variant field object: %![fc-]+F", fc);
7b33a0e0
PP
516 var_field = g_new0(struct bt_field_variant, 1);
517 if (!var_field) {
a8f90e5d
PP
518 BT_LIB_LOGE_APPEND_CAUSE(
519 "Failed to allocate one variant field.");
7b33a0e0
PP
520 goto end;
521 }
8b45963b 522
939190b3 523 init_field((void *) var_field, fc, &variant_field_methods);
18acc6f8 524
939190b3 525 if (create_fields_from_named_field_classes((void *) fc,
7b33a0e0 526 &var_field->fields)) {
a8f90e5d 527 BT_LIB_LOGE_APPEND_CAUSE("Cannot create variant member fields: "
939190b3 528 "%![fc-]+F", fc);
6a9bd19d
FD
529 bt_field_destroy((void *) var_field);
530 var_field = NULL;
7b33a0e0
PP
531 goto end;
532 }
273b65be 533
7b33a0e0 534 BT_LIB_LOGD("Created variant field object: %!+f", var_field);
18acc6f8 535
7b33a0e0
PP
536end:
537 return (void *) var_field;
18acc6f8
PP
538}
539
540static inline
7b33a0e0 541int init_array_field_fields(struct bt_field_array *array_field)
18acc6f8
PP
542{
543 int ret = 0;
7b33a0e0 544 uint64_t i;
939190b3 545 struct bt_field_class_array *array_fc;
18acc6f8 546
7b33a0e0 547 BT_ASSERT(array_field);
939190b3 548 array_fc = (void *) array_field->common.class;
7b33a0e0
PP
549 array_field->fields = g_ptr_array_sized_new(array_field->length);
550 if (!array_field->fields) {
a8f90e5d 551 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GPtrArray.");
18acc6f8
PP
552 ret = -1;
553 goto end;
554 }
555
7b33a0e0
PP
556 g_ptr_array_set_free_func(array_field->fields,
557 (GDestroyNotify) bt_field_destroy);
558 g_ptr_array_set_size(array_field->fields, array_field->length);
559
560 for (i = 0; i < array_field->length; i++) {
561 array_field->fields->pdata[i] = bt_field_create(
939190b3 562 array_fc->element_fc);
7b33a0e0 563 if (!array_field->fields->pdata[i]) {
a8f90e5d
PP
564 BT_LIB_LOGE_APPEND_CAUSE(
565 "Cannot create array field's element field: "
939190b3 566 "index=%" PRIu64 ", %![fc-]+F", i, array_fc);
7b33a0e0
PP
567 ret = -1;
568 goto end;
569 }
570 }
18acc6f8
PP
571
572end:
573 return ret;
3f4a108d
PP
574}
575
7b33a0e0 576static
939190b3 577struct bt_field *create_static_array_field(struct bt_field_class *fc)
f78d67fb 578{
60bbfc7c 579 struct bt_field_class_array_static *array_fc = (void *) fc;
7b33a0e0 580 struct bt_field_array *array_field;
a6918753 581
939190b3 582 BT_LIB_LOGD("Creating static array field object: %![fc-]+F", fc);
7b33a0e0
PP
583 array_field = g_new0(struct bt_field_array, 1);
584 if (!array_field) {
a8f90e5d
PP
585 BT_LIB_LOGE_APPEND_CAUSE(
586 "Failed to allocate one static array field.");
7b33a0e0
PP
587 goto end;
588 }
f78d67fb 589
939190b3
PP
590 init_field((void *) array_field, fc, &array_field_methods);
591 array_field->length = array_fc->length;
18acc6f8 592
7b33a0e0 593 if (init_array_field_fields(array_field)) {
a8f90e5d 594 BT_LIB_LOGE_APPEND_CAUSE("Cannot create static array fields: "
939190b3 595 "%![fc-]+F", fc);
6a9bd19d
FD
596 bt_field_destroy((void *) array_field);
597 array_field = NULL;
7b33a0e0
PP
598 goto end;
599 }
a6918753 600
7b33a0e0 601 BT_LIB_LOGD("Created static array field object: %!+f", array_field);
18acc6f8 602
7b33a0e0
PP
603end:
604 return (void *) array_field;
273b65be
JG
605}
606
7b33a0e0 607static
939190b3 608struct bt_field *create_dynamic_array_field(struct bt_field_class *fc)
cd95e351 609{
7b33a0e0 610 struct bt_field_array *array_field;
a6918753 611
939190b3 612 BT_LIB_LOGD("Creating dynamic array field object: %![fc-]+F", fc);
7b33a0e0
PP
613 array_field = g_new0(struct bt_field_array, 1);
614 if (!array_field) {
a8f90e5d
PP
615 BT_LIB_LOGE_APPEND_CAUSE(
616 "Failed to allocate one dynamic array field.");
7b33a0e0
PP
617 goto end;
618 }
619
939190b3 620 init_field((void *) array_field, fc, &array_field_methods);
7b33a0e0
PP
621
622 if (init_array_field_fields(array_field)) {
a8f90e5d 623 BT_LIB_LOGE_APPEND_CAUSE("Cannot create dynamic array fields: "
939190b3 624 "%![fc-]+F", fc);
6a9bd19d
FD
625 bt_field_destroy((void *) array_field);
626 array_field = NULL;
7b33a0e0 627 goto end;
18acc6f8
PP
628 }
629
7b33a0e0
PP
630 BT_LIB_LOGD("Created dynamic array field object: %!+f", array_field);
631
632end:
633 return (void *) array_field;
a6918753
PP
634}
635
9414b439
PP
636bt_bool bt_field_bool_get_value(const struct bt_field *field)
637{
638 const struct bt_field_bool *bool_field = (const void *) field;
639
640 BT_ASSERT_PRE_DEV_NON_NULL(field, "Field");
641 BT_ASSERT_PRE_DEV_FIELD_IS_SET(field, "Field");
642 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field, BT_FIELD_CLASS_TYPE_BOOL,
643 "Field");
644 return (bt_bool) bool_field->value;
645}
646
647void bt_field_bool_set_value(struct bt_field *field, bt_bool value)
648{
649 struct bt_field_bool *bool_field = (void *) field;
650
651 BT_ASSERT_PRE_DEV_NON_NULL(field, "Field");
652 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field, BT_FIELD_CLASS_TYPE_BOOL,
653 "Field");
654 BT_ASSERT_PRE_DEV_FIELD_HOT(field, "Field");
655 bool_field->value = (bool) value;
656 bt_field_set_single(field, true);
657}
658
6943da6a
PP
659uint64_t bt_field_bit_array_get_value_as_integer(const struct bt_field *field)
660{
661 const struct bt_field_bit_array *ba_field = (const void *) field;
662
663 BT_ASSERT_PRE_DEV_NON_NULL(field, "Field");
664 BT_ASSERT_PRE_DEV_FIELD_IS_SET(field, "Field");
665 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field,
666 BT_FIELD_CLASS_TYPE_BIT_ARRAY, "Field");
667 return ba_field->value_as_int;
668}
669
670void bt_field_bit_array_set_value_as_integer(struct bt_field *field,
671 uint64_t value)
672{
673 struct bt_field_bit_array *ba_field = (void *) field;
674 struct bt_field_class_bit_array *ba_fc;
675
676 BT_ASSERT_PRE_DEV_NON_NULL(field, "Field");
677 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field,
678 BT_FIELD_CLASS_TYPE_BIT_ARRAY, "Field");
679 BT_ASSERT_PRE_DEV_FIELD_HOT(field, "Field");
680 ba_fc = (void *) field->class;
681 ba_field->value_as_int = value;
682
683 if (ba_fc->length < 64) {
684 /* Apply mask */
685 ba_field->value_as_int &= ((UINT64_C(1) << ba_fc->length) - 1);
686 }
687
688 bt_field_set_single(field, true);
689}
690
60bbfc7c 691int64_t bt_field_integer_signed_get_value(const struct bt_field *field)
a6918753 692{
78cf9df6 693 const struct bt_field_integer *int_field = (const void *) field;
a6918753 694
fa6cfec3
PP
695 BT_ASSERT_PRE_DEV_NON_NULL(field, "Field");
696 BT_ASSERT_PRE_DEV_FIELD_IS_SET(field, "Field");
697 BT_ASSERT_PRE_DEV_FIELD_IS_SIGNED_INT(field, "Field");
7b33a0e0 698 return int_field->value.i;
cd95e351
JG
699}
700
60bbfc7c 701void bt_field_integer_signed_set_value(struct bt_field *field, int64_t value)
cd95e351 702{
7b33a0e0 703 struct bt_field_integer *int_field = (void *) field;
a6918753 704
fa6cfec3
PP
705 BT_ASSERT_PRE_DEV_NON_NULL(field, "Field");
706 BT_ASSERT_PRE_DEV_FIELD_IS_SIGNED_INT(field, "Field");
707 BT_ASSERT_PRE_DEV_FIELD_HOT(field, "Field");
708 BT_ASSERT_PRE_DEV(bt_util_value_is_in_range_signed(
939190b3 709 ((struct bt_field_class_integer *) field->class)->range, value),
7b33a0e0 710 "Value is out of bounds: value=%" PRId64 ", %![field-]+f, "
939190b3 711 "%![fc-]+F", value, field, field->class);
7b33a0e0
PP
712 int_field->value.i = value;
713 bt_field_set_single(field, true);
cd95e351
JG
714}
715
60bbfc7c 716uint64_t bt_field_integer_unsigned_get_value(const struct bt_field *field)
273b65be 717{
78cf9df6 718 const struct bt_field_integer *int_field = (const void *) field;
7b33a0e0 719
fa6cfec3
PP
720 BT_ASSERT_PRE_DEV_NON_NULL(field, "Field");
721 BT_ASSERT_PRE_DEV_FIELD_IS_SET(field, "Field");
722 BT_ASSERT_PRE_DEV_FIELD_IS_UNSIGNED_INT(field, "Field");
7b33a0e0 723 return int_field->value.u;
273b65be
JG
724}
725
60bbfc7c 726void bt_field_integer_unsigned_set_value(struct bt_field *field, uint64_t value)
cd95e351 727{
7b33a0e0 728 struct bt_field_integer *int_field = (void *) field;
a6918753 729
fa6cfec3
PP
730 BT_ASSERT_PRE_DEV_NON_NULL(field, "Field");
731 BT_ASSERT_PRE_DEV_FIELD_IS_UNSIGNED_INT(field, "Field");
732 BT_ASSERT_PRE_DEV_FIELD_HOT(field, "Field");
733 BT_ASSERT_PRE_DEV(bt_util_value_is_in_range_unsigned(
939190b3 734 ((struct bt_field_class_integer *) field->class)->range, value),
7b33a0e0 735 "Value is out of bounds: value=%" PRIu64 ", %![field-]+f, "
939190b3 736 "%![fc-]+F", value, field, field->class);
7b33a0e0
PP
737 int_field->value.u = value;
738 bt_field_set_single(field, true);
cd95e351
JG
739}
740
76276a81
FD
741float bt_field_real_single_precision_get_value(const struct bt_field *field)
742{
743 const struct bt_field_real *real_field = (const void *) field;
744
745 BT_ASSERT_PRE_DEV_NON_NULL(field, "Field");
746 BT_ASSERT_PRE_DEV_FIELD_IS_SET(field, "Field");
747 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field,
748 BT_FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL, "Field");
749 return (float) real_field->value;
750}
751
752double bt_field_real_double_precision_get_value(const struct bt_field *field)
273b65be 753{
78cf9df6 754 const struct bt_field_real *real_field = (const void *) field;
7b33a0e0 755
fa6cfec3
PP
756 BT_ASSERT_PRE_DEV_NON_NULL(field, "Field");
757 BT_ASSERT_PRE_DEV_FIELD_IS_SET(field, "Field");
76276a81
FD
758 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field,
759 BT_FIELD_CLASS_TYPE_DOUBLE_PRECISION_REAL, "Field");
760
7b33a0e0 761 return real_field->value;
8b45963b
PP
762}
763
76276a81
FD
764void bt_field_real_single_precision_set_value(struct bt_field *field,
765 float value)
8b45963b 766{
7b33a0e0 767 struct bt_field_real *real_field = (void *) field;
18acc6f8 768
fa6cfec3 769 BT_ASSERT_PRE_DEV_NON_NULL(field, "Field");
76276a81
FD
770 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field,
771 BT_FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL, "Field");
fa6cfec3 772 BT_ASSERT_PRE_DEV_FIELD_HOT(field, "Field");
76276a81
FD
773
774 real_field->value = (double) value;
775 bt_field_set_single(field, true);
776}
777
778void bt_field_real_double_precision_set_value(struct bt_field *field,
779 double value)
780{
781 struct bt_field_real *real_field = (void *) field;
782
783 BT_ASSERT_PRE_DEV_NON_NULL(field, "Field");
784 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field,
785 BT_FIELD_CLASS_TYPE_DOUBLE_PRECISION_REAL, "Field");
786 BT_ASSERT_PRE_DEV_FIELD_HOT(field, "Field");
787
7b33a0e0
PP
788 real_field->value = value;
789 bt_field_set_single(field, true);
790}
791
fb25b9e3 792enum bt_field_enumeration_get_mapping_labels_status
60bbfc7c 793bt_field_enumeration_unsigned_get_mapping_labels(
78cf9df6 794 const struct bt_field *field,
939190b3 795 bt_field_class_enumeration_mapping_label_array *label_array,
7b33a0e0
PP
796 uint64_t *count)
797{
78cf9df6 798 const struct bt_field_integer *int_field = (const void *) field;
7b33a0e0 799
fa6cfec3
PP
800 BT_ASSERT_PRE_DEV_NON_NULL(field, "Field");
801 BT_ASSERT_PRE_DEV_NON_NULL(label_array, "Label array (output)");
802 BT_ASSERT_PRE_DEV_NON_NULL(label_array, "Count (output)");
803 BT_ASSERT_PRE_DEV_FIELD_IS_SET(field, "Field");
804 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field,
af0c18e3 805 BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION, "Field");
937c4e48 806 return (int)
60bbfc7c 807 bt_field_class_enumeration_unsigned_get_mapping_labels_for_value(
937c4e48 808 field->class, int_field->value.u, label_array, count);
273b65be
JG
809}
810
fb25b9e3 811enum bt_field_enumeration_get_mapping_labels_status
60bbfc7c 812bt_field_enumeration_signed_get_mapping_labels(
78cf9df6 813 const struct bt_field *field,
939190b3 814 bt_field_class_enumeration_mapping_label_array *label_array,
7b33a0e0 815 uint64_t *count)
cd95e351 816{
78cf9df6 817 const struct bt_field_integer *int_field = (const void *) field;
18acc6f8 818
fa6cfec3
PP
819 BT_ASSERT_PRE_DEV_NON_NULL(field, "Field");
820 BT_ASSERT_PRE_DEV_NON_NULL(label_array, "Label array (output)");
821 BT_ASSERT_PRE_DEV_NON_NULL(label_array, "Count (output)");
822 BT_ASSERT_PRE_DEV_FIELD_IS_SET(field, "Field");
823 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field,
af0c18e3 824 BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION, "Field");
937c4e48 825 return (int)
60bbfc7c 826 bt_field_class_enumeration_signed_get_mapping_labels_for_value(
937c4e48 827 field->class, int_field->value.i, label_array, count);
8b45963b 828}
fc25abce 829
78cf9df6 830const char *bt_field_string_get_value(const struct bt_field *field)
8b45963b 831{
78cf9df6 832 const struct bt_field_string *string_field = (const void *) field;
7b33a0e0 833
fa6cfec3
PP
834 BT_ASSERT_PRE_DEV_NON_NULL(field, "Field");
835 BT_ASSERT_PRE_DEV_FIELD_IS_SET(field, "Field");
836 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field, BT_FIELD_CLASS_TYPE_STRING,
7b33a0e0
PP
837 "Field");
838 return (const char *) string_field->buf->data;
839}
840
78cf9df6 841uint64_t bt_field_string_get_length(const struct bt_field *field)
7b33a0e0 842{
78cf9df6 843 const struct bt_field_string *string_field = (const void *) field;
18acc6f8 844
fa6cfec3
PP
845 BT_ASSERT_PRE_DEV_NON_NULL(field, "Field");
846 BT_ASSERT_PRE_DEV_FIELD_IS_SET(field, "Field");
847 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field, BT_FIELD_CLASS_TYPE_STRING,
7b33a0e0
PP
848 "Field");
849 return string_field->length;
cd95e351
JG
850}
851
937c4e48
PP
852static inline
853void clear_string_field(struct bt_field *field)
854{
855 struct bt_field_string *string_field = (void *) field;
856
ec4a3354 857 BT_ASSERT_DBG(field);
937c4e48
PP
858 string_field->length = 0;
859 bt_field_set_single(field, true);
860}
861
fb25b9e3
PP
862enum bt_field_string_set_value_status bt_field_string_set_value(
863 struct bt_field *field, const char *value)
273b65be 864{
fa6cfec3
PP
865 BT_ASSERT_PRE_DEV_NON_NULL(field, "Field");
866 BT_ASSERT_PRE_DEV_NON_NULL(value, "Value");
867 BT_ASSERT_PRE_DEV_FIELD_HOT(field, "Field");
868 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field, BT_FIELD_CLASS_TYPE_STRING,
7b33a0e0 869 "Field");
937c4e48 870 clear_string_field(field);
fb25b9e3 871 return (int) bt_field_string_append_with_length(field, value,
7b33a0e0 872 (uint64_t) strlen(value));
273b65be
JG
873}
874
fb25b9e3
PP
875enum bt_field_string_append_status bt_field_string_append(
876 struct bt_field *field, const char *value)
cd95e351 877{
78cf9df6 878 return bt_field_string_append_with_length(field,
9e550e5f 879 value, (uint64_t) strlen(value));
cd95e351
JG
880}
881
fb25b9e3
PP
882enum bt_field_string_append_status bt_field_string_append_with_length(
883 struct bt_field *field, const char *value, uint64_t length)
273b65be 884{
18acc6f8
PP
885 struct bt_field_string *string_field = (void *) field;
886 char *data;
7b33a0e0 887 uint64_t new_length;
273b65be 888
fa6cfec3
PP
889 BT_ASSERT_PRE_DEV_NON_NULL(field, "Field");
890 BT_ASSERT_PRE_DEV_NON_NULL(value, "Value");
891 BT_ASSERT_PRE_DEV_FIELD_HOT(field, "Field");
892 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field,
af0c18e3 893 BT_FIELD_CLASS_TYPE_STRING, "Field");
a6918753 894
18acc6f8 895 /* Make sure no null bytes are appended */
8e01f2d9 896 BT_ASSERT_PRE_DEV(!memchr(value, '\0', length),
18acc6f8 897 "String value to append contains a null character: "
7b33a0e0 898 "partial-value=\"%.32s\", length=%" PRIu64, value, length);
c6f9c5a3 899
7b33a0e0 900 new_length = length + string_field->length;
18acc6f8 901
85e7137b 902 if (G_UNLIKELY(new_length + 1 > string_field->buf->len)) {
7b33a0e0 903 g_array_set_size(string_field->buf, new_length + 1);
c6f9c5a3
PP
904 }
905
18acc6f8 906 data = string_field->buf->data;
7b33a0e0
PP
907 memcpy(data + string_field->length, value, length);
908 ((char *) string_field->buf->data)[new_length] = '\0';
909 string_field->length = new_length;
910 bt_field_set_single(field, true);
fb25b9e3 911 return BT_FUNC_STATUS_OK;
18acc6f8 912}
8deee039 913
fb25b9e3 914void bt_field_string_clear(struct bt_field *field)
18acc6f8 915{
fa6cfec3
PP
916 BT_ASSERT_PRE_DEV_NON_NULL(field, "Field");
917 BT_ASSERT_PRE_DEV_FIELD_HOT(field, "Field");
918 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field,
af0c18e3 919 BT_FIELD_CLASS_TYPE_STRING, "Field");
937c4e48 920 clear_string_field(field);
18acc6f8
PP
921}
922
78cf9df6 923uint64_t bt_field_array_get_length(const struct bt_field *field)
18acc6f8 924{
78cf9df6 925 const struct bt_field_array *array_field = (const void *) field;
c6f9c5a3 926
fa6cfec3
PP
927 BT_ASSERT_PRE_DEV_NON_NULL(field, "Field");
928 BT_ASSERT_PRE_DEV_FIELD_IS_ARRAY(field, "Field");
7b33a0e0 929 return array_field->length;
8deee039 930}
f98c6554 931
60bbfc7c 932enum bt_field_array_dynamic_set_length_status bt_field_array_dynamic_set_length(
fb25b9e3 933 struct bt_field *field, uint64_t length)
8deee039 934{
fb25b9e3 935 int ret = BT_FUNC_STATUS_OK;
7b33a0e0 936 struct bt_field_array *array_field = (void *) field;
f98c6554 937
fa6cfec3 938 BT_ASSERT_PRE_DEV_NON_NULL(field, "Field");
b8ddb4f0 939 BT_ASSERT_PRE_DEV_FIELD_IS_DYNAMIC_ARRAY(field, "Field");
fa6cfec3 940 BT_ASSERT_PRE_DEV_FIELD_HOT(field, "Field");
273b65be 941
85e7137b 942 if (G_UNLIKELY(length > array_field->fields->len)) {
7b33a0e0 943 /* Make more room */
939190b3 944 struct bt_field_class_array *array_fc;
7b33a0e0
PP
945 uint64_t cur_len = array_field->fields->len;
946 uint64_t i;
18acc6f8 947
7b33a0e0 948 g_ptr_array_set_size(array_field->fields, length);
939190b3 949 array_fc = (void *) field->class;
18acc6f8 950
7b33a0e0
PP
951 for (i = cur_len; i < array_field->fields->len; i++) {
952 struct bt_field *elem_field = bt_field_create(
939190b3 953 array_fc->element_fc);
273b65be 954
7b33a0e0 955 if (!elem_field) {
a8f90e5d
PP
956 BT_LIB_LOGE_APPEND_CAUSE(
957 "Cannot create element field for "
7b33a0e0
PP
958 "dynamic array field: "
959 "index=%" PRIu64 ", "
960 "%![array-field-]+f", i, field);
fb25b9e3 961 ret = BT_FUNC_STATUS_MEMORY_ERROR;
7b33a0e0
PP
962 goto end;
963 }
9be89173 964
ec4a3354 965 BT_ASSERT_DBG(!array_field->fields->pdata[i]);
7b33a0e0 966 array_field->fields->pdata[i] = elem_field;
9be89173 967 }
9be89173
JG
968 }
969
7b33a0e0 970 array_field->length = length;
8deee039 971
273b65be 972end:
9be89173 973 return ret;
273b65be
JG
974}
975
78cf9df6
PP
976static inline
977struct bt_field *borrow_array_field_element_field_by_index(
7b33a0e0 978 struct bt_field *field, uint64_t index)
a6918753 979{
7b33a0e0 980 struct bt_field_array *array_field = (void *) field;
a6918753 981
fa6cfec3
PP
982 BT_ASSERT_PRE_DEV_NON_NULL(field, "Field");
983 BT_ASSERT_PRE_DEV_FIELD_IS_ARRAY(field, "Field");
984 BT_ASSERT_PRE_DEV_VALID_INDEX(index, array_field->length);
7b33a0e0 985 return array_field->fields->pdata[index];
a6918753
PP
986}
987
78cf9df6
PP
988struct bt_field *bt_field_array_borrow_element_field_by_index(
989 struct bt_field *field, uint64_t index)
9e550e5f 990{
78cf9df6 991 return borrow_array_field_element_field_by_index(field, index);
9e550e5f
PP
992}
993
78cf9df6
PP
994const struct bt_field *
995bt_field_array_borrow_element_field_by_index_const(
996 const struct bt_field *field, uint64_t index)
997{
998 return borrow_array_field_element_field_by_index((void *) field, index);
999}
1000
1001static inline
1002struct bt_field *borrow_structure_field_member_field_by_index(
7b33a0e0 1003 struct bt_field *field, uint64_t index)
e42dd763 1004{
7b33a0e0 1005 struct bt_field_structure *struct_field = (void *) field;
e42dd763 1006
fa6cfec3
PP
1007 BT_ASSERT_PRE_DEV_NON_NULL(field, "Field");
1008 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field,
af0c18e3 1009 BT_FIELD_CLASS_TYPE_STRUCTURE, "Field");
fa6cfec3 1010 BT_ASSERT_PRE_DEV_VALID_INDEX(index, struct_field->fields->len);
7b33a0e0 1011 return struct_field->fields->pdata[index];
e42dd763
PP
1012}
1013
78cf9df6
PP
1014struct bt_field *bt_field_structure_borrow_member_field_by_index(
1015 struct bt_field *field, uint64_t index)
1016{
1017 return borrow_structure_field_member_field_by_index(field,
1018 index);
1019}
1020
1021const struct bt_field *
1022bt_field_structure_borrow_member_field_by_index_const(
1023 const struct bt_field *field, uint64_t index)
9e550e5f 1024{
78cf9df6 1025 return borrow_structure_field_member_field_by_index(
9e550e5f
PP
1026 (void *) field, index);
1027}
1028
78cf9df6
PP
1029static inline
1030struct bt_field *borrow_structure_field_member_field_by_name(
7b33a0e0 1031 struct bt_field *field, const char *name)
273b65be 1032{
7b33a0e0 1033 struct bt_field *ret_field = NULL;
939190b3 1034 struct bt_field_class_structure *struct_fc;
7b33a0e0
PP
1035 struct bt_field_structure *struct_field = (void *) field;
1036 gpointer orig_key;
1037 gpointer index;
fc25abce 1038
fa6cfec3
PP
1039 BT_ASSERT_PRE_DEV_NON_NULL(field, "Field");
1040 BT_ASSERT_PRE_DEV_NON_NULL(name, "Field name");
1041 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field,
af0c18e3 1042 BT_FIELD_CLASS_TYPE_STRUCTURE, "Field");
939190b3 1043 struct_fc = (void *) field->class;
a6918753 1044
939190b3 1045 if (!g_hash_table_lookup_extended(struct_fc->common.name_to_index, name,
7b33a0e0 1046 &orig_key, &index)) {
a6918753 1047 goto end;
fc25abce
PP
1048 }
1049
7b33a0e0 1050 ret_field = struct_field->fields->pdata[GPOINTER_TO_UINT(index)];
ec4a3354 1051 BT_ASSERT_DBG(ret_field);
a6918753
PP
1052
1053end:
7b33a0e0 1054 return ret_field;
273b65be
JG
1055}
1056
78cf9df6
PP
1057struct bt_field *bt_field_structure_borrow_member_field_by_name(
1058 struct bt_field *field, const char *name)
1059{
1060 return borrow_structure_field_member_field_by_name(field, name);
1061}
1062
1063const struct bt_field *bt_field_structure_borrow_member_field_by_name_const(
1064 const struct bt_field *field, const char *name)
9e550e5f 1065{
78cf9df6 1066 return borrow_structure_field_member_field_by_name(
9e550e5f
PP
1067 (void *) field, name);
1068}
1069
247fa9e3
PP
1070void bt_field_option_set_has_field(struct bt_field *field, bt_bool has_field)
1071{
1072 struct bt_field_option *opt_field = (void *) field;
1073
1074 BT_ASSERT_PRE_DEV_NON_NULL(field, "Field");
467673c1 1075 BT_ASSERT_PRE_DEV_FIELD_IS_OPTION(field, "Field");
247fa9e3
PP
1076 BT_ASSERT_PRE_DEV_FIELD_HOT(field, "Field");
1077
1078 if (has_field) {
1079 opt_field->selected_field = opt_field->content_field;
1080 } else {
1081 opt_field->selected_field = NULL;
1082 }
1083}
1084
1085struct bt_field *bt_field_option_borrow_field(struct bt_field *field)
1086{
1087 struct bt_field_option *opt_field = (void *) field;
1088
1089 BT_ASSERT_PRE_DEV_NON_NULL(field, "Field");
467673c1 1090 BT_ASSERT_PRE_DEV_FIELD_IS_OPTION(field, "Field");
247fa9e3
PP
1091 return opt_field->selected_field;
1092}
1093
1094const struct bt_field *bt_field_option_borrow_field_const(
1095 const struct bt_field *field)
1096{
1097 return (const void *) bt_field_option_borrow_field((void *) field);
1098}
1099
78cf9df6
PP
1100static inline
1101struct bt_field *borrow_variant_field_selected_option_field(
7b33a0e0 1102 struct bt_field *field)
273b65be 1103{
7b33a0e0 1104 struct bt_field_variant *var_field = (void *) field;
273b65be 1105
fa6cfec3 1106 BT_ASSERT_PRE_DEV_NON_NULL(field, "Field");
02b61fe0 1107 BT_ASSERT_PRE_DEV_FIELD_IS_VARIANT(field, "Field");
fa6cfec3 1108 BT_ASSERT_PRE_DEV(var_field->selected_field,
7b33a0e0
PP
1109 "Variant field has no selected field: %!+f", field);
1110 return var_field->selected_field;
273b65be
JG
1111}
1112
78cf9df6
PP
1113struct bt_field *bt_field_variant_borrow_selected_option_field(
1114 struct bt_field *field)
1115{
1116 return borrow_variant_field_selected_option_field(field);
1117}
1118
1119const struct bt_field *bt_field_variant_borrow_selected_option_field_const(
1120 const struct bt_field *field)
273b65be 1121{
78cf9df6 1122 return borrow_variant_field_selected_option_field((void *) field);
9e550e5f
PP
1123}
1124
02b61fe0
PP
1125static
1126const struct bt_field_class_variant_option *
1127borrow_variant_field_selected_class_option(const struct bt_field *field)
1128{
1129 const struct bt_field_class_named_field_class_container *container_fc;
1130 const struct bt_field_variant *var_field = (const void *) field;
1131
ec4a3354 1132 BT_ASSERT_DBG(field);
02b61fe0
PP
1133 BT_ASSERT_PRE_DEV(var_field->selected_field,
1134 "Variant field has no selected field: %!+f", field);
1135 container_fc = (const void *) field->class;
1136 return container_fc->named_fcs->pdata[var_field->selected_index];
1137}
1138
1139const struct bt_field_class_variant_option *
1140bt_field_variant_borrow_selected_class_option_const(
1141 const struct bt_field *field)
1142{
1143 BT_ASSERT_PRE_DEV_NON_NULL(field, "Field");
1144 BT_ASSERT_PRE_DEV_FIELD_IS_VARIANT(field, "Field");
1145 return borrow_variant_field_selected_class_option(field);
1146}
1147
8bc207af 1148const struct bt_field_class_variant_with_selector_field_integer_unsigned_option *
0822832b 1149bt_field_variant_with_unsigned_integer_selector_borrow_selected_class_option_const(
02b61fe0
PP
1150 const struct bt_field *field)
1151{
1152 BT_ASSERT_PRE_DEV_NON_NULL(field, "Field");
1153 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field,
8bc207af 1154 BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD, "Field");
02b61fe0
PP
1155 return (const void *) borrow_variant_field_selected_class_option(field);
1156}
1157
8bc207af 1158const struct bt_field_class_variant_with_selector_field_integer_signed_option *
0822832b 1159bt_field_variant_with_signed_integer_selector_borrow_selected_class_option_const(
02b61fe0
PP
1160 const struct bt_field *field)
1161{
1162 BT_ASSERT_PRE_DEV_NON_NULL(field, "Field");
1163 BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field,
8bc207af 1164 BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR_FIELD, "Field");
02b61fe0
PP
1165 return (const void *) borrow_variant_field_selected_class_option(field);
1166}
1167
1168enum bt_field_variant_select_option_field_by_index_status
1169bt_field_variant_select_option_field_by_index(
78cf9df6 1170 struct bt_field *field, uint64_t index)
9e550e5f 1171{
7b33a0e0 1172 struct bt_field_variant *var_field = (void *) field;
fc25abce 1173
fa6cfec3 1174 BT_ASSERT_PRE_DEV_NON_NULL(field, "Field");
02b61fe0 1175 BT_ASSERT_PRE_DEV_FIELD_IS_VARIANT(field, "Field");
fa6cfec3
PP
1176 BT_ASSERT_PRE_DEV_FIELD_HOT(field, "Field");
1177 BT_ASSERT_PRE_DEV_VALID_INDEX(index, var_field->fields->len);
7b33a0e0
PP
1178 var_field->selected_field = var_field->fields->pdata[index];
1179 var_field->selected_index = index;
fb25b9e3 1180 return BT_FUNC_STATUS_OK;
273b65be
JG
1181}
1182
7b33a0e0 1183uint64_t bt_field_variant_get_selected_option_field_index(
78cf9df6 1184 const struct bt_field *field)
a6918753 1185{
78cf9df6 1186 const struct bt_field_variant *var_field = (const void *) field;
a6918753 1187
fa6cfec3 1188 BT_ASSERT_PRE_DEV_NON_NULL(field, "Field");
02b61fe0 1189 BT_ASSERT_PRE_DEV_FIELD_IS_VARIANT(field, "Field");
fa6cfec3 1190 BT_ASSERT_PRE_DEV(var_field->selected_field,
7b33a0e0
PP
1191 "Variant field has no selected field: %!+f", field);
1192 return var_field->selected_index;
a6918753
PP
1193}
1194
7b33a0e0
PP
1195static inline
1196void bt_field_finalize(struct bt_field *field)
273b65be 1197{
7b33a0e0 1198 BT_ASSERT(field);
939190b3 1199 BT_LOGD_STR("Putting field's class.");
1248f5ea 1200 BT_OBJECT_PUT_REF_AND_RESET(field->class);
273b65be
JG
1201}
1202
9414b439
PP
1203static
1204void destroy_bool_field(struct bt_field *field)
1205{
1206 BT_ASSERT(field);
1207 BT_LIB_LOGD("Destroying boolean field object: %!+f", field);
1208 bt_field_finalize(field);
1209 g_free(field);
1210}
1211
6943da6a
PP
1212static
1213void destroy_bit_array_field(struct bt_field *field)
1214{
1215 BT_ASSERT(field);
1216 BT_LIB_LOGD("Destroying bit array field object: %!+f", field);
1217 bt_field_finalize(field);
1218 g_free(field);
1219}
1220
273b65be 1221static
7b33a0e0 1222void destroy_integer_field(struct bt_field *field)
273b65be 1223{
7b33a0e0
PP
1224 BT_ASSERT(field);
1225 BT_LIB_LOGD("Destroying integer field object: %!+f", field);
1226 bt_field_finalize(field);
1227 g_free(field);
273b65be
JG
1228}
1229
18acc6f8 1230static
7b33a0e0 1231void destroy_real_field(struct bt_field *field)
273b65be 1232{
7b33a0e0
PP
1233 BT_ASSERT(field);
1234 BT_LIB_LOGD("Destroying real field object: %!+f", field);
1235 bt_field_finalize(field);
1236 g_free(field);
273b65be
JG
1237}
1238
18acc6f8 1239static
7b33a0e0 1240void destroy_structure_field(struct bt_field *field)
273b65be 1241{
7b33a0e0 1242 struct bt_field_structure *struct_field = (void *) field;
273b65be 1243
8b45963b 1244 BT_ASSERT(field);
7b33a0e0
PP
1245 BT_LIB_LOGD("Destroying structure field object: %!+f", field);
1246 bt_field_finalize(field);
8b45963b 1247
7b33a0e0
PP
1248 if (struct_field->fields) {
1249 g_ptr_array_free(struct_field->fields, TRUE);
1248f5ea 1250 struct_field->fields = NULL;
273b65be 1251 }
8b45963b 1252
7b33a0e0 1253 g_free(field);
273b65be
JG
1254}
1255
247fa9e3
PP
1256static
1257void destroy_option_field(struct bt_field *field)
1258{
1259 struct bt_field_option *opt_field = (void *) field;
1260
1261 BT_ASSERT(field);
1262 BT_LIB_LOGD("Destroying option field object: %!+f", field);
1263 bt_field_finalize(field);
1264
1265 if (opt_field->content_field) {
1266 bt_field_destroy(opt_field->content_field);
1267 }
1268
1269 g_free(field);
1270}
1271
18acc6f8 1272static
7b33a0e0 1273void destroy_variant_field(struct bt_field *field)
273b65be 1274{
7b33a0e0 1275 struct bt_field_variant *var_field = (void *) field;
273b65be 1276
8b45963b 1277 BT_ASSERT(field);
7b33a0e0
PP
1278 BT_LIB_LOGD("Destroying variant field object: %!+f", field);
1279 bt_field_finalize(field);
a6918753 1280
7b33a0e0
PP
1281 if (var_field->fields) {
1282 g_ptr_array_free(var_field->fields, TRUE);
1248f5ea 1283 var_field->fields = NULL;
fc25abce 1284 }
8b45963b 1285
7b33a0e0 1286 g_free(field);
273b65be
JG
1287}
1288
18acc6f8 1289static
7b33a0e0 1290void destroy_array_field(struct bt_field *field)
273b65be 1291{
7b33a0e0 1292 struct bt_field_array *array_field = (void *) field;
273b65be 1293
8b45963b 1294 BT_ASSERT(field);
7b33a0e0
PP
1295 BT_LIB_LOGD("Destroying array field object: %!+f", field);
1296 bt_field_finalize(field);
8deee039 1297
7b33a0e0
PP
1298 if (array_field->fields) {
1299 g_ptr_array_free(array_field->fields, TRUE);
1248f5ea 1300 array_field->fields = NULL;
273b65be 1301 }
8b45963b 1302
7b33a0e0 1303 g_free(field);
273b65be
JG
1304}
1305
18acc6f8 1306static
7b33a0e0 1307void destroy_string_field(struct bt_field *field)
273b65be 1308{
7b33a0e0 1309 struct bt_field_string *string_field = (void *) field;
273b65be 1310
8b45963b 1311 BT_ASSERT(field);
7b33a0e0
PP
1312 BT_LIB_LOGD("Destroying string field object: %!+f", field);
1313 bt_field_finalize(field);
8deee039 1314
7b33a0e0
PP
1315 if (string_field->buf) {
1316 g_array_free(string_field->buf, TRUE);
1248f5ea 1317 string_field->buf = NULL;
273b65be 1318 }
7b33a0e0
PP
1319
1320 g_free(field);
273b65be
JG
1321}
1322
7b33a0e0
PP
1323BT_HIDDEN
1324void bt_field_destroy(struct bt_field *field)
12c8a1a3 1325{
8b45963b 1326 BT_ASSERT(field);
5d2d8d18
PP
1327
1328 switch (field->class->type) {
1329 case BT_FIELD_CLASS_TYPE_BOOL:
1330 destroy_bool_field(field);
1331 break;
1332 case BT_FIELD_CLASS_TYPE_BIT_ARRAY:
1333 destroy_bit_array_field(field);
1334 break;
1335 case BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER:
1336 case BT_FIELD_CLASS_TYPE_SIGNED_INTEGER:
1337 case BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION:
1338 case BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION:
1339 destroy_integer_field(field);
1340 break;
1341 case BT_FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL:
1342 case BT_FIELD_CLASS_TYPE_DOUBLE_PRECISION_REAL:
1343 destroy_real_field(field);
1344 break;
1345 case BT_FIELD_CLASS_TYPE_STRING:
1346 destroy_string_field(field);
1347 break;
1348 case BT_FIELD_CLASS_TYPE_STRUCTURE:
1349 destroy_structure_field(field);
1350 break;
1351 case BT_FIELD_CLASS_TYPE_STATIC_ARRAY:
1352 case BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITHOUT_LENGTH_FIELD:
1353 case BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITH_LENGTH_FIELD:
1354 destroy_array_field(field);
1355 break;
1356 case BT_FIELD_CLASS_TYPE_OPTION_WITHOUT_SELECTOR_FIELD:
1357 case BT_FIELD_CLASS_TYPE_OPTION_WITH_BOOL_SELECTOR_FIELD:
1358 case BT_FIELD_CLASS_TYPE_OPTION_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD:
1359 case BT_FIELD_CLASS_TYPE_OPTION_WITH_SIGNED_INTEGER_SELECTOR_FIELD:
1360 destroy_option_field(field);
1361 break;
1362 case BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR_FIELD:
1363 case BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD:
1364 case BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR_FIELD:
1365 destroy_variant_field(field);
1366 break;
1367 default:
1368 abort();
1369 }
12c8a1a3
JG
1370}
1371
18acc6f8 1372static
7b33a0e0 1373void reset_single_field(struct bt_field *field)
12c8a1a3 1374{
ec4a3354 1375 BT_ASSERT_DBG(field);
7b33a0e0 1376 field->is_set = false;
12c8a1a3
JG
1377}
1378
18acc6f8 1379static
7b33a0e0 1380void reset_structure_field(struct bt_field *field)
12c8a1a3 1381{
7b33a0e0
PP
1382 uint64_t i;
1383 struct bt_field_structure *struct_field = (void *) field;
12c8a1a3 1384
ec4a3354 1385 BT_ASSERT_DBG(field);
7b33a0e0
PP
1386
1387 for (i = 0; i < struct_field->fields->len; i++) {
1388 bt_field_reset(struct_field->fields->pdata[i]);
1389 }
12c8a1a3
JG
1390}
1391
247fa9e3
PP
1392static
1393void reset_option_field(struct bt_field *field)
1394{
1395 struct bt_field_option *opt_field = (void *) field;
1396
ec4a3354 1397 BT_ASSERT_DBG(opt_field);
247fa9e3
PP
1398 bt_field_reset(opt_field->content_field);
1399 opt_field->selected_field = NULL;
1400}
1401
18acc6f8 1402static
7b33a0e0 1403void reset_variant_field(struct bt_field *field)
12c8a1a3 1404{
7b33a0e0
PP
1405 uint64_t i;
1406 struct bt_field_variant *var_field = (void *) field;
12c8a1a3 1407
ec4a3354 1408 BT_ASSERT_DBG(field);
8b45963b 1409
7b33a0e0
PP
1410 for (i = 0; i < var_field->fields->len; i++) {
1411 bt_field_reset(var_field->fields->pdata[i]);
12c8a1a3 1412 }
12c8a1a3
JG
1413}
1414
18acc6f8 1415static
7b33a0e0 1416void reset_array_field(struct bt_field *field)
12c8a1a3 1417{
a6918753 1418 uint64_t i;
7b33a0e0 1419 struct bt_field_array *array_field = (void *) field;
12c8a1a3 1420
ec4a3354 1421 BT_ASSERT_DBG(field);
8b45963b 1422
7b33a0e0
PP
1423 for (i = 0; i < array_field->fields->len; i++) {
1424 bt_field_reset(array_field->fields->pdata[i]);
12c8a1a3 1425 }
12c8a1a3
JG
1426}
1427
18acc6f8 1428static
7b33a0e0 1429void set_single_field_is_frozen(struct bt_field *field, bool is_frozen)
918be005 1430{
a6918753 1431 field->frozen = is_frozen;
918be005
PP
1432}
1433
18acc6f8 1434static
7b33a0e0 1435void set_structure_field_is_frozen(struct bt_field *field, bool is_frozen)
918be005 1436{
a6918753 1437 uint64_t i;
7b33a0e0 1438 struct bt_field_structure *struct_field = (void *) field;
918be005 1439
7b33a0e0
PP
1440 BT_LIB_LOGD("Setting structure field's frozen state: "
1441 "%![field-]+f, is-frozen=%d", field, is_frozen);
fc25abce 1442
7b33a0e0
PP
1443 for (i = 0; i < struct_field->fields->len; i++) {
1444 struct bt_field *member_field = struct_field->fields->pdata[i];
918be005 1445
7b33a0e0
PP
1446 BT_LIB_LOGD("Setting structure field's member field's "
1447 "frozen state: %![field-]+f, index=%" PRIu64,
1448 member_field, i);
247fa9e3 1449 _bt_field_set_is_frozen(member_field, is_frozen);
918be005
PP
1450 }
1451
7b33a0e0 1452 set_single_field_is_frozen(field, is_frozen);
918be005
PP
1453}
1454
247fa9e3
PP
1455static
1456void set_option_field_is_frozen(struct bt_field *field, bool is_frozen)
1457{
1458 struct bt_field_option *opt_field = (void *) field;
1459
1460 BT_LIB_LOGD("Setting option field's frozen state: "
1461 "%![field-]+f, is-frozen=%d", field, is_frozen);
1462 _bt_field_set_is_frozen(opt_field->content_field, is_frozen);
1463 set_single_field_is_frozen(field, is_frozen);
1464}
1465
18acc6f8 1466static
7b33a0e0 1467void set_variant_field_is_frozen(struct bt_field *field, bool is_frozen)
918be005 1468{
a6918753 1469 uint64_t i;
7b33a0e0 1470 struct bt_field_variant *var_field = (void *) field;
918be005 1471
7b33a0e0
PP
1472 BT_LIB_LOGD("Setting variant field's frozen state: "
1473 "%![field-]+f, is-frozen=%d", field, is_frozen);
a6918753 1474
7b33a0e0
PP
1475 for (i = 0; i < var_field->fields->len; i++) {
1476 struct bt_field *option_field = var_field->fields->pdata[i];
a6918753 1477
7b33a0e0
PP
1478 BT_LIB_LOGD("Setting variant field's option field's "
1479 "frozen state: %![field-]+f, index=%" PRIu64,
1480 option_field, i);
247fa9e3 1481 _bt_field_set_is_frozen(option_field, is_frozen);
a6918753
PP
1482 }
1483
7b33a0e0 1484 set_single_field_is_frozen(field, is_frozen);
918be005
PP
1485}
1486
18acc6f8 1487static
7b33a0e0 1488void set_array_field_is_frozen(struct bt_field *field, bool is_frozen)
918be005 1489{
7b33a0e0 1490 uint64_t i;
18acc6f8 1491 struct bt_field_array *array_field = (void *) field;
918be005 1492
7b33a0e0
PP
1493 BT_LIB_LOGD("Setting array field's frozen state: "
1494 "%![field-]+f, is-frozen=%d", field, is_frozen);
fc25abce 1495
7b33a0e0
PP
1496 for (i = 0; i < array_field->fields->len; i++) {
1497 struct bt_field *elem_field = array_field->fields->pdata[i];
918be005 1498
7b33a0e0
PP
1499 BT_LIB_LOGD("Setting array field's element field's "
1500 "frozen state: %![field-]+f, index=%" PRIu64,
fc25abce 1501 elem_field, i);
247fa9e3 1502 _bt_field_set_is_frozen(elem_field, is_frozen);
918be005
PP
1503 }
1504
7b33a0e0 1505 set_single_field_is_frozen(field, is_frozen);
918be005
PP
1506}
1507
1508BT_HIDDEN
78cf9df6 1509void _bt_field_set_is_frozen(const struct bt_field *field,
a6918753 1510 bool is_frozen)
918be005 1511{
ec4a3354 1512 BT_ASSERT_DBG(field);
7b33a0e0 1513 BT_LIB_LOGD("Setting field object's frozen state: %!+f, is-frozen=%d",
a6918753 1514 field, is_frozen);
ec4a3354 1515 BT_ASSERT_DBG(field->methods->set_is_frozen);
78cf9df6 1516 field->methods->set_is_frozen((void *) field, is_frozen);
918be005 1517}
76f869ab 1518
18acc6f8 1519static
78cf9df6 1520bool single_field_is_set(const struct bt_field *field)
76f869ab 1521{
ec4a3354 1522 BT_ASSERT_DBG(field);
7b33a0e0 1523 return field->is_set;
76f869ab
JG
1524}
1525
18acc6f8 1526static
78cf9df6 1527bool structure_field_is_set(const struct bt_field *field)
76f869ab 1528{
7b33a0e0
PP
1529 bool is_set = true;
1530 uint64_t i;
78cf9df6 1531 const struct bt_field_structure *struct_field = (const void *) field;
76f869ab 1532
ec4a3354 1533 BT_ASSERT_DBG(field);
8deee039 1534
7b33a0e0
PP
1535 for (i = 0; i < struct_field->fields->len; i++) {
1536 is_set = bt_field_is_set(struct_field->fields->pdata[i]);
53d65c1d 1537 if (!is_set) {
76f869ab
JG
1538 goto end;
1539 }
1540 }
8deee039 1541
76f869ab 1542end:
53d65c1d 1543 return is_set;
76f869ab
JG
1544}
1545
247fa9e3
PP
1546static
1547bool option_field_is_set(const struct bt_field *field)
1548{
1549 const struct bt_field_option *opt_field = (const void *) field;
1550 bool is_set = false;
1551
ec4a3354 1552 BT_ASSERT_DBG(field);
247fa9e3
PP
1553
1554 if (opt_field->selected_field) {
1555 is_set = bt_field_is_set(opt_field->selected_field);
1556 }
1557
1558 return is_set;
1559}
1560
18acc6f8 1561static
78cf9df6 1562bool variant_field_is_set(const struct bt_field *field)
76f869ab 1563{
78cf9df6 1564 const struct bt_field_variant *var_field = (const void *) field;
7b33a0e0 1565 bool is_set = false;
76f869ab 1566
ec4a3354 1567 BT_ASSERT_DBG(field);
8deee039 1568
7b33a0e0
PP
1569 if (var_field->selected_field) {
1570 is_set = bt_field_is_set(var_field->selected_field);
76f869ab 1571 }
8deee039 1572
53d65c1d 1573 return is_set;
76f869ab
JG
1574}
1575
18acc6f8 1576static
78cf9df6 1577bool array_field_is_set(const struct bt_field *field)
76f869ab 1578{
7b33a0e0
PP
1579 bool is_set = true;
1580 uint64_t i;
78cf9df6 1581 const struct bt_field_array *array_field = (const void *) field;
76f869ab 1582
ec4a3354 1583 BT_ASSERT_DBG(field);
8deee039 1584
7b33a0e0
PP
1585 for (i = 0; i < array_field->length; i++) {
1586 is_set = bt_field_is_set(array_field->fields->pdata[i]);
53d65c1d 1587 if (!is_set) {
76f869ab
JG
1588 goto end;
1589 }
1590 }
8deee039 1591
76f869ab 1592end:
53d65c1d 1593 return is_set;
76f869ab 1594}
This page took 0.165412 seconds and 4 git commands to generate.