2 * Copyright 2018 - Philippe Proulx <pproulx@efficios.com>
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
15 #include <babeltrace2/babeltrace.h>
16 #include "common/macros.h"
17 #include "common/assert.h"
23 #include "ctf-meta-visitors.h"
26 int set_int_field_class_meaning_by_name(struct ctf_field_class
*fc
,
27 const char *field_name
, const char *id_name
,
28 enum ctf_field_class_meaning meaning
)
38 case CTF_FIELD_CLASS_TYPE_INT
:
39 case CTF_FIELD_CLASS_TYPE_ENUM
:
41 struct ctf_field_class_int
*int_fc
= (void *) fc
;
43 if (field_name
&& strcmp(field_name
, id_name
) == 0) {
44 int_fc
->meaning
= meaning
;
49 case CTF_FIELD_CLASS_TYPE_STRUCT
:
51 struct ctf_field_class_struct
*struct_fc
= (void *) fc
;
53 for (i
= 0; i
< struct_fc
->members
->len
; i
++) {
54 struct ctf_named_field_class
*named_fc
=
55 ctf_field_class_struct_borrow_member_by_index(
58 ret
= set_int_field_class_meaning_by_name(named_fc
->fc
,
59 named_fc
->name
->str
, id_name
, meaning
);
67 case CTF_FIELD_CLASS_TYPE_VARIANT
:
69 struct ctf_field_class_variant
*var_fc
= (void *) fc
;
71 for (i
= 0; i
< var_fc
->options
->len
; i
++) {
72 struct ctf_named_field_class
*named_fc
=
73 ctf_field_class_variant_borrow_option_by_index(
76 ret
= set_int_field_class_meaning_by_name(named_fc
->fc
,
77 NULL
, id_name
, meaning
);
85 case CTF_FIELD_CLASS_TYPE_ARRAY
:
86 case CTF_FIELD_CLASS_TYPE_SEQUENCE
:
88 struct ctf_field_class_array_base
*array_fc
= (void *) fc
;
90 ret
= set_int_field_class_meaning_by_name(array_fc
->elem_fc
,
91 NULL
, id_name
, meaning
);
107 int update_stream_class_meanings(struct ctf_stream_class
*sc
)
110 struct ctf_field_class_int
*int_fc
;
113 if (!sc
->is_translated
) {
114 if (sc
->packet_context_fc
) {
115 int_fc
= ctf_field_class_struct_borrow_member_int_field_class_by_name(
116 (void *) sc
->packet_context_fc
, "timestamp_begin");
118 int_fc
->meaning
= CTF_FIELD_CLASS_MEANING_PACKET_BEGINNING_TIME
;
121 int_fc
= ctf_field_class_struct_borrow_member_int_field_class_by_name(
122 (void *) sc
->packet_context_fc
, "timestamp_end");
124 int_fc
->meaning
= CTF_FIELD_CLASS_MEANING_PACKET_END_TIME
;
127 * Remove mapped clock class to avoid updating
128 * the clock immediately when decoding.
130 int_fc
->mapped_clock_class
= NULL
;
133 int_fc
= ctf_field_class_struct_borrow_member_int_field_class_by_name(
134 (void *) sc
->packet_context_fc
, "events_discarded");
136 int_fc
->meaning
= CTF_FIELD_CLASS_MEANING_DISC_EV_REC_COUNTER_SNAPSHOT
;
139 int_fc
= ctf_field_class_struct_borrow_member_int_field_class_by_name(
140 (void *) sc
->packet_context_fc
, "packet_seq_num");
142 int_fc
->meaning
= CTF_FIELD_CLASS_MEANING_PACKET_COUNTER_SNAPSHOT
;
146 int_fc
= ctf_field_class_struct_borrow_member_int_field_class_by_name(
147 (void *) sc
->packet_context_fc
, "packet_size");
149 int_fc
->meaning
= CTF_FIELD_CLASS_MEANING_EXP_PACKET_TOTAL_SIZE
;
152 int_fc
= ctf_field_class_struct_borrow_member_int_field_class_by_name(
153 (void *) sc
->packet_context_fc
, "content_size");
155 int_fc
->meaning
= CTF_FIELD_CLASS_MEANING_EXP_PACKET_CONTENT_SIZE
;
159 if (sc
->event_header_fc
) {
160 ret
= set_int_field_class_meaning_by_name(
161 sc
->event_header_fc
, NULL
, "id",
162 CTF_FIELD_CLASS_MEANING_EVENT_CLASS_ID
);
169 for (i
= 0; i
< sc
->event_classes
->len
; i
++) {
170 struct ctf_event_class
*ec
= sc
->event_classes
->pdata
[i
];
172 if (ec
->is_translated
) {
182 int ctf_trace_class_update_meanings(struct ctf_trace_class
*ctf_tc
)
185 struct ctf_field_class_int
*int_fc
;
186 struct ctf_named_field_class
*named_fc
;
189 if (!ctf_tc
->is_translated
&& ctf_tc
->packet_header_fc
) {
190 int_fc
= ctf_field_class_struct_borrow_member_int_field_class_by_name(
191 (void *) ctf_tc
->packet_header_fc
, "magic");
193 int_fc
->meaning
= CTF_FIELD_CLASS_MEANING_MAGIC
;
196 int_fc
= ctf_field_class_struct_borrow_member_int_field_class_by_name(
197 (void *) ctf_tc
->packet_header_fc
, "stream_id");
199 int_fc
->meaning
= CTF_FIELD_CLASS_MEANING_STREAM_CLASS_ID
;
202 int_fc
= ctf_field_class_struct_borrow_member_int_field_class_by_name(
203 (void *) ctf_tc
->packet_header_fc
,
204 "stream_instance_id");
206 int_fc
->meaning
= CTF_FIELD_CLASS_MEANING_DATA_STREAM_ID
;
209 named_fc
= ctf_field_class_struct_borrow_member_by_name(
210 (void *) ctf_tc
->packet_header_fc
, "uuid");
211 if (named_fc
&& named_fc
->fc
->type
== CTF_FIELD_CLASS_TYPE_ARRAY
) {
212 struct ctf_field_class_array
*array_fc
=
213 (void *) named_fc
->fc
;
215 array_fc
->meaning
= CTF_FIELD_CLASS_MEANING_UUID
;
219 for (i
= 0; i
< ctf_tc
->stream_classes
->len
; i
++) {
220 ret
= update_stream_class_meanings(
221 ctf_tc
->stream_classes
->pdata
[i
]);