1 #ifndef BABELTRACE_CTF_IR_EVENT_TYPES_INTERNAL_H
2 #define BABELTRACE_CTF_IR_EVENT_TYPES_INTERNAL_H
5 * BabelTrace - CTF IR: Event 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 CTF_NODE_UNKNOWN
= -1,
47 CTF_NODE_TRACE_PACKET_HEADER
= 1,
48 CTF_NODE_STREAM_PACKET_CONTEXT
= 2,
49 CTF_NODE_STREAM_EVENT_HEADER
= 3,
50 CTF_NODE_STREAM_EVENT_CONTEXT
= 4,
51 CTF_NODE_EVENT_CONTEXT
= 5,
52 CTF_NODE_EVENT_FIELDS
= 6,
55 struct bt_ctf_field_path
{
56 enum bt_ctf_node root
;
58 * Array of integers (int) indicating the index in either
59 * structures or variants that make-up the path to a field.
64 struct bt_ctf_field_type
{
65 struct bt_object base
;
66 struct bt_declaration
*declaration
;
67 type_freeze_func freeze
;
68 type_serialize_func serialize
;
70 * A type can't be modified once it is added to an event or after a
71 * a field has been instanciated from it.
76 struct bt_ctf_field_type_integer
{
77 struct bt_ctf_field_type parent
;
78 struct declaration_integer declaration
;
79 struct bt_ctf_clock
*mapped_clock
;
82 * This is what the user sets and is never modified by internal
85 * This field must contain a `BT_CTF_BYTE_ORDER_*` value.
87 enum bt_ctf_byte_order user_byte_order
;
90 struct enumeration_mapping
{
103 struct bt_ctf_field_type_enumeration
{
104 struct bt_ctf_field_type parent
;
105 struct bt_ctf_field_type
*container
;
106 GPtrArray
*entries
; /* Array of ptrs to struct enumeration_mapping */
107 struct declaration_enum declaration
;
110 struct bt_ctf_field_type_floating_point
{
111 struct bt_ctf_field_type parent
;
112 struct declaration_float declaration
;
115 * The `declaration` field above contains 3 pointers pointing
116 * to the fields below. This avoids unnecessary dynamic
119 struct declaration_integer sign
;
120 struct declaration_integer mantissa
;
121 struct declaration_integer exp
;
124 * This is what the user sets and is never modified by internal
127 * This field must contain a `BT_CTF_BYTE_ORDER_*` value.
129 enum bt_ctf_byte_order user_byte_order
;
132 struct structure_field
{
134 struct bt_ctf_field_type
*type
;
137 struct bt_ctf_field_type_structure
{
138 struct bt_ctf_field_type parent
;
139 GHashTable
*field_name_to_index
;
140 GPtrArray
*fields
; /* Array of pointers to struct structure_field */
141 struct declaration_struct declaration
;
144 struct bt_ctf_field_type_variant
{
145 struct bt_ctf_field_type parent
;
147 struct bt_ctf_field_type_enumeration
*tag
;
148 struct bt_ctf_field_path
*tag_path
;
149 GHashTable
*field_name_to_index
;
150 GPtrArray
*fields
; /* Array of pointers to struct structure_field */
151 struct declaration_variant declaration
;
154 struct bt_ctf_field_type_array
{
155 struct bt_ctf_field_type parent
;
156 struct bt_ctf_field_type
*element_type
;
157 unsigned int length
; /* Number of elements */
158 struct declaration_array declaration
;
161 struct bt_ctf_field_type_sequence
{
162 struct bt_ctf_field_type parent
;
163 struct bt_ctf_field_type
*element_type
;
164 GString
*length_field_name
;
165 struct bt_ctf_field_path
*length_field_path
;
166 struct declaration_sequence declaration
;
169 struct bt_ctf_field_type_string
{
170 struct bt_ctf_field_type parent
;
171 struct declaration_string declaration
;
175 void bt_ctf_field_type_freeze(struct bt_ctf_field_type
*type
);
178 struct bt_ctf_field_type
*bt_ctf_field_type_variant_get_field_type_signed(
179 struct bt_ctf_field_type_variant
*variant
, int64_t tag_value
);
182 struct bt_ctf_field_type
*bt_ctf_field_type_variant_get_field_type_unsigned(
183 struct bt_ctf_field_type_variant
*variant
, uint64_t tag_value
);
186 int bt_ctf_field_type_serialize(struct bt_ctf_field_type
*type
,
187 struct metadata_context
*context
);
190 int bt_ctf_field_type_validate(struct bt_ctf_field_type
*type
);
193 const char *bt_ctf_field_type_enumeration_get_mapping_name_unsigned(
194 struct bt_ctf_field_type_enumeration
*enumeration_type
,
198 const char *bt_ctf_field_type_enumeration_get_mapping_name_signed(
199 struct bt_ctf_field_type_enumeration
*enumeration_type
,
202 /* Override field type's byte order only if it is set to "native" */
204 void bt_ctf_field_type_set_native_byte_order(
205 struct bt_ctf_field_type
*type
, int byte_order
);
207 /* Deep copy a field type */
209 struct bt_ctf_field_type
*bt_ctf_field_type_copy(
210 struct bt_ctf_field_type
*type
);
213 struct bt_ctf_field_path
*bt_ctf_field_path_create(void);
216 struct bt_ctf_field_path
*bt_ctf_field_path_copy(
217 struct bt_ctf_field_path
*path
);
220 void bt_ctf_field_path_destroy(struct bt_ctf_field_path
*path
);
223 int bt_ctf_field_type_structure_get_field_name_index(
224 struct bt_ctf_field_type
*structure
, const char *name
);
226 /* Replace an existing field's type in a structure */
228 int bt_ctf_field_type_structure_set_field_index(
229 struct bt_ctf_field_type
*structure
,
230 struct bt_ctf_field_type
*field
, int index
);
233 int bt_ctf_field_type_variant_get_field_name_index(
234 struct bt_ctf_field_type
*variant
, const char *name
);
237 int bt_ctf_field_type_sequence_set_length_field_path(
238 struct bt_ctf_field_type
*type
,
239 struct bt_ctf_field_path
*path
);
242 struct bt_ctf_field_path
*bt_ctf_field_type_sequence_get_length_field_path(
243 struct bt_ctf_field_type
*type
);
246 int bt_ctf_field_type_variant_set_tag_field_path(struct bt_ctf_field_type
*type
,
247 struct bt_ctf_field_path
*path
);
250 struct bt_ctf_field_path
*bt_ctf_field_type_variant_get_tag_field_path(
251 struct bt_ctf_field_type
*type
);
254 int bt_ctf_field_type_variant_set_tag(struct bt_ctf_field_type
*type
,
255 struct bt_ctf_field_type
*tag
);
257 /* Replace an existing field's type in a variant */
259 int bt_ctf_field_type_variant_set_field_index(
260 struct bt_ctf_field_type
*variant
,
261 struct bt_ctf_field_type
*field
, int index
);
264 int bt_ctf_field_type_array_set_element_type(struct bt_ctf_field_type
*array
,
265 struct bt_ctf_field_type
*element_type
);
268 int bt_ctf_field_type_sequence_set_element_type(struct bt_ctf_field_type
*array
,
269 struct bt_ctf_field_type
*element_type
);
271 #endif /* BABELTRACE_CTF_IR_EVENT_TYPES_INTERNAL_H */