1 #ifndef BABELTRACE_TRACE_IR_FIELDS_INTERNAL_H
2 #define BABELTRACE_TRACE_IR_FIELDS_INTERNAL_H
5 * Babeltrace - Trace IR: Event Fields internal
7 * Copyright 2013, 2014 Jérémie Galarneau <jeremie.galarneau@efficios.com>
9 * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com>
11 * Permission is hereby granted, free of charge, to any person obtaining a copy
12 * of this software and associated documentation files (the "Software"), to deal
13 * in the Software without restriction, including without limitation the rights
14 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 * copies of the Software, and to permit persons to whom the Software is
16 * furnished to do so, subject to the following conditions:
18 * The above copyright notice and this permission notice shall be included in
19 * all copies or substantial portions of the Software.
21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 #include <babeltrace/assert-pre-internal.h>
31 #include <babeltrace/common-internal.h>
32 #include <babeltrace/trace-ir/field-classes-internal.h>
33 #include <babeltrace/trace-ir/utils-internal.h>
34 #include <babeltrace/object-internal.h>
35 #include <babeltrace/babeltrace-internal.h>
36 #include <babeltrace/types.h>
43 #define BT_ASSERT_PRE_FIELD_HAS_CLASS_TYPE(_field, _cls_type, _name) \
44 BT_ASSERT_PRE(((struct bt_field *) (_field))->class->type == (_cls_type), \
45 _name " has the wrong class type: expected-class-type=%s, " \
47 bt_common_field_class_type_string(_cls_type), (_field))
49 #define BT_ASSERT_PRE_FIELD_IS_UNSIGNED_INT(_field, _name) \
51 ((struct bt_field *) (_field))->class->type == BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER || \
52 ((struct bt_field *) (_field))->class->type == BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION, \
53 _name " is not an unsigned integer field: %![field-]+f", \
56 #define BT_ASSERT_PRE_FIELD_IS_SIGNED_INT(_field, _name) \
58 ((struct bt_field *) (_field))->class->type == BT_FIELD_CLASS_TYPE_SIGNED_INTEGER || \
59 ((struct bt_field *) (_field))->class->type == BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION, \
60 _name " is not a signed integer field: %![field-]+f", \
63 #define BT_ASSERT_PRE_FIELD_IS_ARRAY(_field, _name) \
65 ((struct bt_field *) (_field))->class->type == BT_FIELD_CLASS_TYPE_STATIC_ARRAY || \
66 ((struct bt_field *) (_field))->class->type == BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY, \
67 _name " is not an array field: %![field-]+f", (_field))
69 #define BT_ASSERT_PRE_FIELD_IS_SET(_field, _name) \
70 BT_ASSERT_PRE(bt_field_is_set(_field), \
71 _name " is not set: %!+f", (_field))
73 #define BT_ASSERT_PRE_FIELD_HOT(_field, _name) \
74 BT_ASSERT_PRE_HOT((struct bt_field *) (_field), (_name), \
79 typedef struct bt_field
*(* bt_field_create_func
)(struct bt_field_class
*);
80 typedef void (*bt_field_method_set_is_frozen
)(struct bt_field
*, bool);
81 typedef bool (*bt_field_method_is_set
)(struct bt_field
*);
82 typedef void (*bt_field_method_reset
)(struct bt_field
*);
84 struct bt_field_methods
{
85 bt_field_method_set_is_frozen set_is_frozen
;
86 bt_field_method_is_set is_set
;
87 bt_field_method_reset reset
;
91 struct bt_object base
;
94 struct bt_field_class
*class;
96 /* Virtual table for slow path (dev mode) operations */
97 struct bt_field_methods
*methods
;
103 struct bt_field_integer
{
104 struct bt_field common
;
112 struct bt_field_real
{
113 struct bt_field common
;
117 struct bt_field_structure
{
118 struct bt_field common
;
120 /* Array of `struct bt_field *`, owned by this */
124 struct bt_field_variant
{
125 struct bt_field common
;
127 /* Weak: belongs to `fields` below */
128 struct bt_field
*selected_field
;
130 /* Index of currently selected field */
131 uint64_t selected_index
;
133 /* Array of `struct bt_field *`, owned by this */
137 struct bt_field_array
{
138 struct bt_field common
;
140 /* Array of `struct bt_field *`, owned by this */
143 /* Current effective length */
147 struct bt_field_string
{
148 struct bt_field common
;
154 # define bt_field_set_is_frozen _bt_field_set_is_frozen
155 # define bt_field_is_set _bt_field_is_set
156 # define bt_field_reset _bt_field_reset
157 # define bt_field_set_single _bt_field_set_single
159 # define bt_field_set_is_frozen(_field, _is_frozen)
160 # define bt_field_is_set(_field) (BT_FALSE)
161 # define bt_field_reset(_field)
162 # define bt_field_set_single(_field, _val)
166 void _bt_field_set_is_frozen(struct bt_field
*field
, bool is_frozen
);
169 void _bt_field_reset(struct bt_field
*field
)
172 BT_ASSERT(field
->methods
->reset
);
173 field
->methods
->reset(field
);
177 void _bt_field_set_single(struct bt_field
*field
, bool value
)
180 field
->is_set
= value
;
184 bt_bool
_bt_field_is_set(struct bt_field
*field
)
186 bt_bool is_set
= BT_FALSE
;
192 BT_ASSERT(bt_field_class_has_known_type(field
->class));
193 BT_ASSERT(field
->methods
->is_set
);
194 is_set
= field
->methods
->is_set(field
);
201 struct bt_field
*bt_field_create(struct bt_field_class
*class);
204 void bt_field_destroy(struct bt_field
*field
);
206 #endif /* BABELTRACE_TRACE_IR_FIELDS_INTERNAL_H */