Fix: lib: add NULL check for destroy_listeners in destroy_component_class
[babeltrace.git] / src / lib / trace-ir / field.h
CommitLineData
273b65be 1/*
0235b0db
MJ
2 * SPDX-License-Identifier: MIT
3 *
e2f7325d 4 * Copyright 2017-2018 Philippe Proulx <pproulx@efficios.com>
de9dd397 5 * Copyright 2013, 2014 Jérémie Galarneau <jeremie.galarneau@efficios.com>
273b65be
JG
6 */
7
0235b0db
MJ
8#ifndef BABELTRACE_TRACE_IR_FIELDS_INTERNAL_H
9#define BABELTRACE_TRACE_IR_FIELDS_INTERNAL_H
10
d98421f2 11#include "lib/assert-cond.h"
578e048b
MJ
12#include "common/common.h"
13#include "lib/object.h"
91d81473 14#include "common/macros.h"
3fadfbc0 15#include <babeltrace2/types.h>
dc3fffef 16#include <stdint.h>
4d4b475d 17#include <string.h>
3dca2276 18#include <inttypes.h>
d990a4fb 19#include <stdbool.h>
273b65be
JG
20#include <glib.h>
21
578e048b
MJ
22#include "field-class.h"
23#include "utils.h"
24
3dca2276 25struct bt_field;
3dca2276 26
5cd6d0e5 27typedef struct bt_field *(* bt_field_create_func)(struct bt_field_class *);
44c440bc 28typedef void (*bt_field_method_set_is_frozen)(struct bt_field *, bool);
40f4ba76 29typedef bool (*bt_field_method_is_set)(const struct bt_field *);
cb6f1f7d
PP
30typedef void (*bt_field_method_reset)(struct bt_field *);
31
32struct bt_field_methods {
33 bt_field_method_set_is_frozen set_is_frozen;
cb6f1f7d
PP
34 bt_field_method_is_set is_set;
35 bt_field_method_reset reset;
3dca2276
PP
36};
37
cb6f1f7d 38struct bt_field {
83509119 39 struct bt_object base;
44c440bc
PP
40
41 /* Owned by this */
5cd6d0e5 42 struct bt_field_class *class;
44c440bc
PP
43
44 /* Virtual table for slow path (dev mode) operations */
cb6f1f7d 45 struct bt_field_methods *methods;
44c440bc
PP
46
47 bool is_set;
d990a4fb 48 bool frozen;
273b65be
JG
49};
50
5cebbe7f
PP
51struct bt_field_bool {
52 struct bt_field common;
53 bool value;
54};
55
1094efa4
PP
56struct bt_field_bit_array {
57 struct bt_field common;
58 uint64_t value_as_int;
59};
60
cb6f1f7d
PP
61struct bt_field_integer {
62 struct bt_field common;
273b65be 63
44c440bc
PP
64 union {
65 uint64_t u;
66 int64_t i;
67 } value;
cb6f1f7d
PP
68};
69
44c440bc 70struct bt_field_real {
cb6f1f7d 71 struct bt_field common;
44c440bc 72 double value;
273b65be
JG
73};
74
cb6f1f7d
PP
75struct bt_field_structure {
76 struct bt_field common;
312c056a 77
cb6f1f7d 78 /* Array of `struct bt_field *`, owned by this */
312c056a 79 GPtrArray *fields;
273b65be
JG
80};
81
b38aea74
PP
82struct bt_field_option {
83 struct bt_field common;
84
85 /* Owned by this */
86 struct bt_field *content_field;
87
88 /* Weak: equal to `content_field` above or `NULL` */
89 struct bt_field *selected_field;
90};
91
cb6f1f7d
PP
92struct bt_field_variant {
93 struct bt_field common;
312c056a 94
44c440bc
PP
95 /* Weak: belongs to `fields` below */
96 struct bt_field *selected_field;
312c056a 97
44c440bc
PP
98 /* Index of currently selected field */
99 uint64_t selected_index;
312c056a 100
cb6f1f7d 101 /* Array of `struct bt_field *`, owned by this */
312c056a 102 GPtrArray *fields;
273b65be
JG
103};
104
cb6f1f7d
PP
105struct bt_field_array {
106 struct bt_field common;
312c056a 107
cb6f1f7d 108 /* Array of `struct bt_field *`, owned by this */
44c440bc 109 GPtrArray *fields;
312c056a 110
44c440bc 111 /* Current effective length */
312c056a 112 uint64_t length;
273b65be
JG
113};
114
cb6f1f7d
PP
115struct bt_field_string {
116 struct bt_field common;
4d4b475d 117 GArray *buf;
44c440bc 118 uint64_t length;
273b65be
JG
119};
120
f6ccaed9 121#ifdef BT_DEV_MODE
44c440bc
PP
122# define bt_field_set_is_frozen _bt_field_set_is_frozen
123# define bt_field_is_set _bt_field_is_set
124# define bt_field_reset _bt_field_reset
125# define bt_field_set_single _bt_field_set_single
f6ccaed9 126#else
44c440bc
PP
127# define bt_field_set_is_frozen(_field, _is_frozen)
128# define bt_field_is_set(_field) (BT_FALSE)
129# define bt_field_reset(_field)
130# define bt_field_set_single(_field, _val)
f6ccaed9 131#endif
918be005 132
cb6f1f7d 133BT_HIDDEN
40f4ba76 134void _bt_field_set_is_frozen(const struct bt_field *field, bool is_frozen);
3dca2276
PP
135
136static inline
40f4ba76 137void _bt_field_reset(const struct bt_field *field)
3dca2276 138{
98b15851
PP
139 BT_ASSERT_DBG(field);
140 BT_ASSERT_DBG(field->methods->reset);
40f4ba76 141 field->methods->reset((void *) field);
3dca2276
PP
142}
143
144static inline
44c440bc 145void _bt_field_set_single(struct bt_field *field, bool value)
3dca2276 146{
98b15851 147 BT_ASSERT_DBG(field);
44c440bc 148 field->is_set = value;
3dca2276
PP
149}
150
151static inline
40f4ba76 152bt_bool _bt_field_is_set(const struct bt_field *field)
3dca2276
PP
153{
154 bt_bool is_set = BT_FALSE;
155
156 if (!field) {
157 goto end;
158 }
159
98b15851 160 BT_ASSERT_DBG(field->methods->is_set);
3dca2276
PP
161 is_set = field->methods->is_set(field);
162
163end:
164 return is_set;
165}
166
312c056a 167BT_HIDDEN
5cd6d0e5 168struct bt_field *bt_field_create(struct bt_field_class *class);
312c056a
PP
169
170BT_HIDDEN
44c440bc 171void bt_field_destroy(struct bt_field *field);
312c056a 172
56e18c4c 173#endif /* BABELTRACE_TRACE_IR_FIELDS_INTERNAL_H */
This page took 0.124259 seconds and 4 git commands to generate.