Commit | Line | Data |
---|---|---|
56e18c4c PP |
1 | #ifndef BABELTRACE_TRACE_IR_FIELDS_INTERNAL_H |
2 | #define BABELTRACE_TRACE_IR_FIELDS_INTERNAL_H | |
273b65be JG |
3 | |
4 | /* | |
56e18c4c | 5 | * Babeltrace - Trace IR: Event Fields internal |
273b65be | 6 | * |
de9dd397 | 7 | * Copyright 2013, 2014 Jérémie Galarneau <jeremie.galarneau@efficios.com> |
273b65be JG |
8 | * |
9 | * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com> | |
10 | * | |
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: | |
17 | * | |
18 | * The above copyright notice and this permission notice shall be included in | |
19 | * all copies or substantial portions of the Software. | |
20 | * | |
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 | |
27 | * SOFTWARE. | |
28 | */ | |
29 | ||
3dca2276 PP |
30 | #include <babeltrace/assert-pre-internal.h> |
31 | #include <babeltrace/common-internal.h> | |
5cd6d0e5 | 32 | #include <babeltrace/trace-ir/field-classes-internal.h> |
56e18c4c | 33 | #include <babeltrace/trace-ir/utils-internal.h> |
83509119 | 34 | #include <babeltrace/object-internal.h> |
273b65be | 35 | #include <babeltrace/babeltrace-internal.h> |
c55a9f58 | 36 | #include <babeltrace/types.h> |
dc3fffef | 37 | #include <stdint.h> |
4d4b475d | 38 | #include <string.h> |
3dca2276 | 39 | #include <inttypes.h> |
d990a4fb | 40 | #include <stdbool.h> |
273b65be JG |
41 | #include <glib.h> |
42 | ||
864cad70 PP |
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, " \ | |
44c440bc | 46 | "%![field-]+f", \ |
864cad70 | 47 | bt_common_field_class_type_string(_cls_type), (_field)) |
44c440bc PP |
48 | |
49 | #define BT_ASSERT_PRE_FIELD_IS_UNSIGNED_INT(_field, _name) \ | |
50 | BT_ASSERT_PRE( \ | |
864cad70 PP |
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, \ | |
44c440bc PP |
53 | _name " is not an unsigned integer field: %![field-]+f", \ |
54 | (_field)) | |
55 | ||
56 | #define BT_ASSERT_PRE_FIELD_IS_SIGNED_INT(_field, _name) \ | |
57 | BT_ASSERT_PRE( \ | |
864cad70 PP |
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, \ | |
44c440bc PP |
60 | _name " is not a signed integer field: %![field-]+f", \ |
61 | (_field)) | |
62 | ||
63 | #define BT_ASSERT_PRE_FIELD_IS_ARRAY(_field, _name) \ | |
64 | BT_ASSERT_PRE( \ | |
864cad70 PP |
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, \ | |
44c440bc PP |
67 | _name " is not an array field: %![field-]+f", (_field)) |
68 | ||
69 | #define BT_ASSERT_PRE_FIELD_IS_SET(_field, _name) \ | |
70 | BT_ASSERT_PRE(bt_field_is_set(_field), \ | |
cb6f1f7d | 71 | _name " is not set: %!+f", (_field)) |
3dca2276 | 72 | |
44c440bc PP |
73 | #define BT_ASSERT_PRE_FIELD_HOT(_field, _name) \ |
74 | BT_ASSERT_PRE_HOT((struct bt_field *) (_field), (_name), \ | |
75 | ": %!+f", (_field)) | |
3dca2276 PP |
76 | |
77 | struct bt_field; | |
3dca2276 | 78 | |
5cd6d0e5 | 79 | typedef struct bt_field *(* bt_field_create_func)(struct bt_field_class *); |
44c440bc PP |
80 | typedef void (*bt_field_method_set_is_frozen)(struct bt_field *, bool); |
81 | typedef bool (*bt_field_method_is_set)(struct bt_field *); | |
cb6f1f7d PP |
82 | typedef void (*bt_field_method_reset)(struct bt_field *); |
83 | ||
84 | struct bt_field_methods { | |
85 | bt_field_method_set_is_frozen set_is_frozen; | |
cb6f1f7d PP |
86 | bt_field_method_is_set is_set; |
87 | bt_field_method_reset reset; | |
3dca2276 PP |
88 | }; |
89 | ||
cb6f1f7d | 90 | struct bt_field { |
83509119 | 91 | struct bt_object base; |
44c440bc PP |
92 | |
93 | /* Owned by this */ | |
5cd6d0e5 | 94 | struct bt_field_class *class; |
44c440bc PP |
95 | |
96 | /* Virtual table for slow path (dev mode) operations */ | |
cb6f1f7d | 97 | struct bt_field_methods *methods; |
44c440bc PP |
98 | |
99 | bool is_set; | |
d990a4fb | 100 | bool frozen; |
273b65be JG |
101 | }; |
102 | ||
cb6f1f7d PP |
103 | struct bt_field_integer { |
104 | struct bt_field common; | |
273b65be | 105 | |
44c440bc PP |
106 | union { |
107 | uint64_t u; | |
108 | int64_t i; | |
109 | } value; | |
cb6f1f7d PP |
110 | }; |
111 | ||
44c440bc | 112 | struct bt_field_real { |
cb6f1f7d | 113 | struct bt_field common; |
44c440bc | 114 | double value; |
273b65be JG |
115 | }; |
116 | ||
cb6f1f7d PP |
117 | struct bt_field_structure { |
118 | struct bt_field common; | |
312c056a | 119 | |
cb6f1f7d | 120 | /* Array of `struct bt_field *`, owned by this */ |
312c056a | 121 | GPtrArray *fields; |
273b65be JG |
122 | }; |
123 | ||
cb6f1f7d PP |
124 | struct bt_field_variant { |
125 | struct bt_field common; | |
312c056a | 126 | |
44c440bc PP |
127 | /* Weak: belongs to `fields` below */ |
128 | struct bt_field *selected_field; | |
312c056a | 129 | |
44c440bc PP |
130 | /* Index of currently selected field */ |
131 | uint64_t selected_index; | |
312c056a | 132 | |
cb6f1f7d | 133 | /* Array of `struct bt_field *`, owned by this */ |
312c056a | 134 | GPtrArray *fields; |
273b65be JG |
135 | }; |
136 | ||
cb6f1f7d PP |
137 | struct bt_field_array { |
138 | struct bt_field common; | |
312c056a | 139 | |
cb6f1f7d | 140 | /* Array of `struct bt_field *`, owned by this */ |
44c440bc | 141 | GPtrArray *fields; |
312c056a | 142 | |
44c440bc | 143 | /* Current effective length */ |
312c056a | 144 | uint64_t length; |
273b65be JG |
145 | }; |
146 | ||
cb6f1f7d PP |
147 | struct bt_field_string { |
148 | struct bt_field common; | |
4d4b475d | 149 | GArray *buf; |
44c440bc | 150 | uint64_t length; |
273b65be JG |
151 | }; |
152 | ||
f6ccaed9 | 153 | #ifdef BT_DEV_MODE |
44c440bc PP |
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 | |
f6ccaed9 | 158 | #else |
44c440bc PP |
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) | |
f6ccaed9 | 163 | #endif |
918be005 | 164 | |
cb6f1f7d | 165 | BT_HIDDEN |
44c440bc | 166 | void _bt_field_set_is_frozen(struct bt_field *field, bool is_frozen); |
3dca2276 PP |
167 | |
168 | static inline | |
44c440bc | 169 | void _bt_field_reset(struct bt_field *field) |
3dca2276 PP |
170 | { |
171 | BT_ASSERT(field); | |
172 | BT_ASSERT(field->methods->reset); | |
173 | field->methods->reset(field); | |
174 | } | |
175 | ||
176 | static inline | |
44c440bc | 177 | void _bt_field_set_single(struct bt_field *field, bool value) |
3dca2276 PP |
178 | { |
179 | BT_ASSERT(field); | |
44c440bc | 180 | field->is_set = value; |
3dca2276 PP |
181 | } |
182 | ||
183 | static inline | |
44c440bc | 184 | bt_bool _bt_field_is_set(struct bt_field *field) |
3dca2276 PP |
185 | { |
186 | bt_bool is_set = BT_FALSE; | |
187 | ||
188 | if (!field) { | |
189 | goto end; | |
190 | } | |
191 | ||
864cad70 | 192 | BT_ASSERT(bt_field_class_has_known_type(field->class)); |
3dca2276 PP |
193 | BT_ASSERT(field->methods->is_set); |
194 | is_set = field->methods->is_set(field); | |
195 | ||
196 | end: | |
197 | return is_set; | |
198 | } | |
199 | ||
312c056a | 200 | BT_HIDDEN |
5cd6d0e5 | 201 | struct bt_field *bt_field_create(struct bt_field_class *class); |
312c056a PP |
202 | |
203 | BT_HIDDEN | |
44c440bc | 204 | void bt_field_destroy(struct bt_field *field); |
312c056a | 205 | |
56e18c4c | 206 | #endif /* BABELTRACE_TRACE_IR_FIELDS_INTERNAL_H */ |