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/babeltrace-internal.h>
35 #include <babeltrace/object-internal.h>
36 #include <babeltrace/types.h>
37 #include <babeltrace/ctf/events.h>
40 typedef void (*type_freeze_func
)(struct bt_ctf_field_type
*);
41 typedef int (*type_serialize_func
)(struct bt_ctf_field_type
*,
42 struct metadata_context
*);
45 BT_CTF_TYPE_ID_UNKNOWN
= CTF_TYPE_UNKNOWN
,
46 BT_CTF_TYPE_ID_INTEGER
= CTF_TYPE_INTEGER
,
47 BT_CTF_TYPE_ID_FLOAT
= CTF_TYPE_FLOAT
,
48 BT_CTF_TYPE_ID_ENUM
= CTF_TYPE_ENUM
,
49 BT_CTF_TYPE_ID_STRING
= CTF_TYPE_STRING
,
50 BT_CTF_TYPE_ID_STRUCT
= CTF_TYPE_STRUCT
,
51 BT_CTF_TYPE_ID_UNTAGGED_VARIANT
= CTF_TYPE_UNTAGGED_VARIANT
,
52 BT_CTF_TYPE_ID_VARIANT
= CTF_TYPE_VARIANT
,
53 BT_CTF_TYPE_ID_ARRAY
= CTF_TYPE_ARRAY
,
54 BT_CTF_TYPE_ID_SEQUENCE
= CTF_TYPE_SEQUENCE
,
58 enum bt_ctf_ir_scope
{
59 BT_CTF_SCOPE_UNKNOWN
= -1,
61 BT_CTF_SCOPE_TRACE_PACKET_HEADER
= 1,
62 BT_CTF_SCOPE_STREAM_PACKET_CONTEXT
= 2,
63 BT_CTF_SCOPE_STREAM_EVENT_HEADER
= 3,
64 BT_CTF_SCOPE_STREAM_EVENT_CONTEXT
= 4,
65 BT_CTF_SCOPE_EVENT_CONTEXT
= 5,
66 BT_CTF_SCOPE_EVENT_FIELDS
= 6,
69 struct bt_ctf_field_type
{
70 struct bt_object base
;
71 struct bt_declaration
*declaration
;
72 type_freeze_func freeze
;
73 type_serialize_func serialize
;
75 * A type can't be modified once it is added to an event or after a
76 * a field has been instanciated from it.
81 * This flag indicates if the field type is valid. A valid
82 * field type is _always_ frozen. All the nested field types of
83 * a valid field type are also valid (and thus frozen).
88 struct bt_ctf_field_type_integer
{
89 struct bt_ctf_field_type parent
;
90 struct declaration_integer declaration
;
91 struct bt_ctf_clock
*mapped_clock
;
94 * This is what the user sets and is never modified by internal
97 * This field must contain a `BT_CTF_BYTE_ORDER_*` value.
99 enum bt_ctf_byte_order user_byte_order
;
102 struct enumeration_mapping
{
115 struct bt_ctf_field_type_enumeration
{
116 struct bt_ctf_field_type parent
;
117 struct bt_ctf_field_type
*container
;
118 GPtrArray
*entries
; /* Array of ptrs to struct enumeration_mapping */
119 struct declaration_enum declaration
;
122 struct bt_ctf_field_type_floating_point
{
123 struct bt_ctf_field_type parent
;
124 struct declaration_float declaration
;
127 * The `declaration` field above contains 3 pointers pointing
128 * to the fields below. This avoids unnecessary dynamic
131 struct declaration_integer sign
;
132 struct declaration_integer mantissa
;
133 struct declaration_integer exp
;
136 * This is what the user sets and is never modified by internal
139 * This field must contain a `BT_CTF_BYTE_ORDER_*` value.
141 enum bt_ctf_byte_order user_byte_order
;
144 struct structure_field
{
146 struct bt_ctf_field_type
*type
;
149 struct bt_ctf_field_type_structure
{
150 struct bt_ctf_field_type parent
;
151 GHashTable
*field_name_to_index
;
152 GPtrArray
*fields
; /* Array of pointers to struct structure_field */
153 struct declaration_struct declaration
;
156 struct bt_ctf_field_type_variant
{
157 struct bt_ctf_field_type parent
;
159 struct bt_ctf_field_type_enumeration
*tag
;
160 struct bt_ctf_field_path
*tag_field_path
;
161 GHashTable
*field_name_to_index
;
162 GPtrArray
*fields
; /* Array of pointers to struct structure_field */
163 struct declaration_variant declaration
;
166 struct bt_ctf_field_type_array
{
167 struct bt_ctf_field_type parent
;
168 struct bt_ctf_field_type
*element_type
;
169 unsigned int length
; /* Number of elements */
170 struct declaration_array declaration
;
173 struct bt_ctf_field_type_sequence
{
174 struct bt_ctf_field_type parent
;
175 struct bt_ctf_field_type
*element_type
;
176 GString
*length_field_name
;
177 struct bt_ctf_field_path
*length_field_path
;
178 struct declaration_sequence declaration
;
181 struct bt_ctf_field_type_string
{
182 struct bt_ctf_field_type parent
;
183 struct declaration_string declaration
;
187 void bt_ctf_field_type_freeze(struct bt_ctf_field_type
*type
);
190 struct bt_ctf_field_type
*bt_ctf_field_type_variant_get_field_type_signed(
191 struct bt_ctf_field_type_variant
*variant
, int64_t tag_value
);
194 struct bt_ctf_field_type
*bt_ctf_field_type_variant_get_field_type_unsigned(
195 struct bt_ctf_field_type_variant
*variant
, uint64_t tag_value
);
198 int bt_ctf_field_type_serialize(struct bt_ctf_field_type
*type
,
199 struct metadata_context
*context
);
202 int bt_ctf_field_type_validate(struct bt_ctf_field_type
*type
);
205 const char *bt_ctf_field_type_enumeration_get_mapping_name_unsigned(
206 struct bt_ctf_field_type_enumeration
*enumeration_type
,
210 const char *bt_ctf_field_type_enumeration_get_mapping_name_signed(
211 struct bt_ctf_field_type_enumeration
*enumeration_type
,
214 /* Override field type's byte order only if it is set to "native" */
216 void bt_ctf_field_type_set_native_byte_order(
217 struct bt_ctf_field_type
*type
, int byte_order
);
219 /* Deep copy a field type */
221 struct bt_ctf_field_type
*bt_ctf_field_type_copy(
222 struct bt_ctf_field_type
*type
);
225 int bt_ctf_field_type_structure_get_field_name_index(
226 struct bt_ctf_field_type
*structure
, const char *name
);
228 /* Replace an existing field's type in a structure */
230 int bt_ctf_field_type_structure_set_field_index(
231 struct bt_ctf_field_type
*structure
,
232 struct bt_ctf_field_type
*field
, int index
);
235 int bt_ctf_field_type_variant_get_field_name_index(
236 struct bt_ctf_field_type
*variant
, const char *name
);
239 int bt_ctf_field_type_sequence_set_length_field_path(
240 struct bt_ctf_field_type
*type
,
241 struct bt_ctf_field_path
*path
);
244 int bt_ctf_field_type_variant_set_tag_field_path(struct bt_ctf_field_type
*type
,
245 struct bt_ctf_field_path
*path
);
248 int bt_ctf_field_type_variant_set_tag_field_type(struct bt_ctf_field_type
*type
,
249 struct bt_ctf_field_type
*tag_type
);
251 /* Replace an existing field's type in a variant */
253 int bt_ctf_field_type_variant_set_field_index(
254 struct bt_ctf_field_type
*variant
,
255 struct bt_ctf_field_type
*field
, int index
);
258 int bt_ctf_field_type_array_set_element_type(struct bt_ctf_field_type
*array
,
259 struct bt_ctf_field_type
*element_type
);
262 int bt_ctf_field_type_sequence_set_element_type(struct bt_ctf_field_type
*array
,
263 struct bt_ctf_field_type
*element_type
);
266 int bt_ctf_field_type_get_field_count(struct bt_ctf_field_type
*type
);
269 struct bt_ctf_field_type
*bt_ctf_field_type_get_field_at_index(
270 struct bt_ctf_field_type
*type
, int index
);
273 int bt_ctf_field_type_get_field_index(struct bt_ctf_field_type
*type
,
276 #endif /* BABELTRACE_CTF_IR_FIELD_TYPES_INTERNAL_H */