1 #ifndef BABELTRACE_CTF_IR_FIELD_TYPES_INTERNAL_H
2 #define BABELTRACE_CTF_IR_FIELD_TYPES_INTERNAL_H
5 * BabelTrace - CTF IR: Event field types 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/ctf-writer/event-types.h>
31 #include <babeltrace/ctf-writer/event-fields.h>
32 #include <babeltrace/ctf-writer/writer.h>
33 #include <babeltrace/ctf-ir/trace-internal.h>
34 #include <babeltrace/ctf-ir/clock-class.h>
35 #include <babeltrace/babeltrace-internal.h>
36 #include <babeltrace/object-internal.h>
37 #include <babeltrace/types.h>
38 #include <babeltrace/ctf/events.h>
41 typedef void (*type_freeze_func
)(struct bt_ctf_field_type
*);
42 typedef int (*type_serialize_func
)(struct bt_ctf_field_type
*,
43 struct metadata_context
*);
45 struct bt_ctf_field_type
{
46 struct bt_object base
;
47 struct bt_declaration
*declaration
;
48 type_freeze_func freeze
;
49 type_serialize_func serialize
;
51 * A type can't be modified once it is added to an event or after a
52 * a field has been instanciated from it.
57 * This flag indicates if the field type is valid. A valid
58 * field type is _always_ frozen. All the nested field types of
59 * a valid field type are also valid (and thus frozen).
64 struct bt_ctf_field_type_integer
{
65 struct bt_ctf_field_type parent
;
66 struct declaration_integer declaration
;
67 struct bt_ctf_clock_class
*mapped_clock
;
70 * This is what the user sets and is never modified by internal
73 * This field must contain a `BT_CTF_BYTE_ORDER_*` value.
75 enum bt_ctf_byte_order user_byte_order
;
78 struct enumeration_mapping
{
91 struct bt_ctf_field_type_enumeration
{
92 struct bt_ctf_field_type parent
;
93 struct bt_ctf_field_type
*container
;
94 GPtrArray
*entries
; /* Array of ptrs to struct enumeration_mapping */
95 struct declaration_enum declaration
;
98 struct bt_ctf_field_type_floating_point
{
99 struct bt_ctf_field_type parent
;
100 struct declaration_float declaration
;
103 * The `declaration` field above contains 3 pointers pointing
104 * to the fields below. This avoids unnecessary dynamic
107 struct declaration_integer sign
;
108 struct declaration_integer mantissa
;
109 struct declaration_integer exp
;
112 * This is what the user sets and is never modified by internal
115 * This field must contain a `BT_CTF_BYTE_ORDER_*` value.
117 enum bt_ctf_byte_order user_byte_order
;
120 struct structure_field
{
122 struct bt_ctf_field_type
*type
;
125 struct bt_ctf_field_type_structure
{
126 struct bt_ctf_field_type parent
;
127 GHashTable
*field_name_to_index
;
128 GPtrArray
*fields
; /* Array of pointers to struct structure_field */
129 struct declaration_struct declaration
;
132 struct bt_ctf_field_type_variant
{
133 struct bt_ctf_field_type parent
;
135 struct bt_ctf_field_type_enumeration
*tag
;
136 struct bt_ctf_field_path
*tag_field_path
;
137 GHashTable
*field_name_to_index
;
138 GPtrArray
*fields
; /* Array of pointers to struct structure_field */
139 struct declaration_variant declaration
;
142 struct bt_ctf_field_type_array
{
143 struct bt_ctf_field_type parent
;
144 struct bt_ctf_field_type
*element_type
;
145 unsigned int length
; /* Number of elements */
146 struct declaration_array declaration
;
149 struct bt_ctf_field_type_sequence
{
150 struct bt_ctf_field_type parent
;
151 struct bt_ctf_field_type
*element_type
;
152 GString
*length_field_name
;
153 struct bt_ctf_field_path
*length_field_path
;
154 struct declaration_sequence declaration
;
157 struct bt_ctf_field_type_string
{
158 struct bt_ctf_field_type parent
;
159 struct declaration_string declaration
;
163 void bt_ctf_field_type_freeze(struct bt_ctf_field_type
*type
);
166 struct bt_ctf_field_type
*bt_ctf_field_type_variant_get_field_type_signed(
167 struct bt_ctf_field_type_variant
*variant
, int64_t tag_value
);
170 struct bt_ctf_field_type
*bt_ctf_field_type_variant_get_field_type_unsigned(
171 struct bt_ctf_field_type_variant
*variant
, uint64_t tag_value
);
174 int bt_ctf_field_type_serialize(struct bt_ctf_field_type
*type
,
175 struct metadata_context
*context
);
178 int bt_ctf_field_type_validate(struct bt_ctf_field_type
*type
);
181 const char *bt_ctf_field_type_enumeration_get_mapping_name_unsigned(
182 struct bt_ctf_field_type_enumeration
*enumeration_type
,
186 const char *bt_ctf_field_type_enumeration_get_mapping_name_signed(
187 struct bt_ctf_field_type_enumeration
*enumeration_type
,
190 /* Override field type's byte order only if it is set to "native" */
192 void bt_ctf_field_type_set_native_byte_order(
193 struct bt_ctf_field_type
*type
, int byte_order
);
196 int bt_ctf_field_type_structure_get_field_name_index(
197 struct bt_ctf_field_type
*structure
, const char *name
);
199 /* Replace an existing field's type in a structure */
201 int bt_ctf_field_type_structure_set_field_index(
202 struct bt_ctf_field_type
*structure
,
203 struct bt_ctf_field_type
*field
, int index
);
206 int bt_ctf_field_type_variant_get_field_name_index(
207 struct bt_ctf_field_type
*variant
, const char *name
);
210 int bt_ctf_field_type_sequence_set_length_field_path(
211 struct bt_ctf_field_type
*type
,
212 struct bt_ctf_field_path
*path
);
215 int bt_ctf_field_type_variant_set_tag_field_path(struct bt_ctf_field_type
*type
,
216 struct bt_ctf_field_path
*path
);
219 int bt_ctf_field_type_variant_set_tag_field_type(struct bt_ctf_field_type
*type
,
220 struct bt_ctf_field_type
*tag_type
);
222 /* Replace an existing field's type in a variant */
224 int bt_ctf_field_type_variant_set_field_index(
225 struct bt_ctf_field_type
*variant
,
226 struct bt_ctf_field_type
*field
, int index
);
229 int bt_ctf_field_type_array_set_element_type(struct bt_ctf_field_type
*array
,
230 struct bt_ctf_field_type
*element_type
);
233 int bt_ctf_field_type_sequence_set_element_type(struct bt_ctf_field_type
*array
,
234 struct bt_ctf_field_type
*element_type
);
237 int bt_ctf_field_type_get_field_count(struct bt_ctf_field_type
*type
);
240 struct bt_ctf_field_type
*bt_ctf_field_type_get_field_at_index(
241 struct bt_ctf_field_type
*type
, int index
);
244 int bt_ctf_field_type_get_field_index(struct bt_ctf_field_type
*type
,
247 #endif /* BABELTRACE_CTF_IR_FIELD_TYPES_INTERNAL_H */