2 * SPDX-License-Identifier: MIT
4 * Copyright 2018 Philippe Proulx <pproulx@efficios.com>
10 #include "ctf-meta-visitors.hpp"
12 static int set_int_field_class_meaning_by_name(struct ctf_field_class
*fc
, const char *field_name
,
14 enum ctf_field_class_meaning meaning
)
24 case CTF_FIELD_CLASS_TYPE_INT
:
25 case CTF_FIELD_CLASS_TYPE_ENUM
:
27 struct ctf_field_class_int
*int_fc
= ctf_field_class_as_int(fc
);
29 if (field_name
&& strcmp(field_name
, id_name
) == 0) {
30 int_fc
->meaning
= meaning
;
35 case CTF_FIELD_CLASS_TYPE_STRUCT
:
37 struct ctf_field_class_struct
*struct_fc
= ctf_field_class_as_struct(fc
);
39 for (i
= 0; i
< struct_fc
->members
->len
; i
++) {
40 struct ctf_named_field_class
*named_fc
=
41 ctf_field_class_struct_borrow_member_by_index(struct_fc
, i
);
43 ret
= set_int_field_class_meaning_by_name(named_fc
->fc
, named_fc
->name
->str
, id_name
,
52 case CTF_FIELD_CLASS_TYPE_VARIANT
:
54 struct ctf_field_class_variant
*var_fc
= ctf_field_class_as_variant(fc
);
56 for (i
= 0; i
< var_fc
->options
->len
; i
++) {
57 struct ctf_named_field_class
*named_fc
=
58 ctf_field_class_variant_borrow_option_by_index(var_fc
, i
);
60 ret
= set_int_field_class_meaning_by_name(named_fc
->fc
, NULL
, id_name
, meaning
);
68 case CTF_FIELD_CLASS_TYPE_ARRAY
:
69 case CTF_FIELD_CLASS_TYPE_SEQUENCE
:
71 struct ctf_field_class_array_base
*array_fc
= ctf_field_class_as_array_base(fc
);
73 ret
= set_int_field_class_meaning_by_name(array_fc
->elem_fc
, NULL
, id_name
, meaning
);
88 static int update_stream_class_meanings(struct ctf_stream_class
*sc
)
91 struct ctf_field_class_int
*int_fc
;
94 if (!sc
->is_translated
) {
95 if (sc
->packet_context_fc
) {
96 int_fc
= ctf_field_class_struct_borrow_member_int_field_class_by_name(
97 ctf_field_class_as_struct(sc
->packet_context_fc
), "timestamp_begin");
99 int_fc
->meaning
= CTF_FIELD_CLASS_MEANING_PACKET_BEGINNING_TIME
;
102 int_fc
= ctf_field_class_struct_borrow_member_int_field_class_by_name(
103 ctf_field_class_as_struct(sc
->packet_context_fc
), "timestamp_end");
105 int_fc
->meaning
= CTF_FIELD_CLASS_MEANING_PACKET_END_TIME
;
108 * Remove mapped clock class to avoid updating
109 * the clock immediately when decoding.
111 int_fc
->mapped_clock_class
= NULL
;
114 int_fc
= ctf_field_class_struct_borrow_member_int_field_class_by_name(
115 ctf_field_class_as_struct(sc
->packet_context_fc
), "events_discarded");
117 int_fc
->meaning
= CTF_FIELD_CLASS_MEANING_DISC_EV_REC_COUNTER_SNAPSHOT
;
120 int_fc
= ctf_field_class_struct_borrow_member_int_field_class_by_name(
121 ctf_field_class_as_struct(sc
->packet_context_fc
), "packet_seq_num");
123 int_fc
->meaning
= CTF_FIELD_CLASS_MEANING_PACKET_COUNTER_SNAPSHOT
;
126 int_fc
= ctf_field_class_struct_borrow_member_int_field_class_by_name(
127 ctf_field_class_as_struct(sc
->packet_context_fc
), "packet_size");
129 int_fc
->meaning
= CTF_FIELD_CLASS_MEANING_EXP_PACKET_TOTAL_SIZE
;
132 int_fc
= ctf_field_class_struct_borrow_member_int_field_class_by_name(
133 ctf_field_class_as_struct(sc
->packet_context_fc
), "content_size");
135 int_fc
->meaning
= CTF_FIELD_CLASS_MEANING_EXP_PACKET_CONTENT_SIZE
;
139 if (sc
->event_header_fc
) {
140 ret
= set_int_field_class_meaning_by_name(sc
->event_header_fc
, NULL
, "id",
141 CTF_FIELD_CLASS_MEANING_EVENT_CLASS_ID
);
148 for (i
= 0; i
< sc
->event_classes
->len
; i
++) {
149 struct ctf_event_class
*ec
= (ctf_event_class
*) sc
->event_classes
->pdata
[i
];
151 if (ec
->is_translated
) {
160 int ctf_trace_class_update_meanings(struct ctf_trace_class
*ctf_tc
)
163 struct ctf_field_class_int
*int_fc
;
164 struct ctf_named_field_class
*named_fc
;
167 if (!ctf_tc
->is_translated
&& ctf_tc
->packet_header_fc
) {
168 int_fc
= ctf_field_class_struct_borrow_member_int_field_class_by_name(
169 ctf_field_class_as_struct(ctf_tc
->packet_header_fc
), "magic");
171 int_fc
->meaning
= CTF_FIELD_CLASS_MEANING_MAGIC
;
174 int_fc
= ctf_field_class_struct_borrow_member_int_field_class_by_name(
175 ctf_field_class_as_struct(ctf_tc
->packet_header_fc
), "stream_id");
177 int_fc
->meaning
= CTF_FIELD_CLASS_MEANING_STREAM_CLASS_ID
;
180 int_fc
= ctf_field_class_struct_borrow_member_int_field_class_by_name(
181 ctf_field_class_as_struct(ctf_tc
->packet_header_fc
), "stream_instance_id");
183 int_fc
->meaning
= CTF_FIELD_CLASS_MEANING_DATA_STREAM_ID
;
186 named_fc
= ctf_field_class_struct_borrow_member_by_name(
187 ctf_field_class_as_struct(ctf_tc
->packet_header_fc
), "uuid");
188 if (named_fc
&& named_fc
->fc
->type
== CTF_FIELD_CLASS_TYPE_ARRAY
) {
189 struct ctf_field_class_array
*array_fc
= ctf_field_class_as_array(named_fc
->fc
);
191 array_fc
->meaning
= CTF_FIELD_CLASS_MEANING_UUID
;
195 for (i
= 0; i
< ctf_tc
->stream_classes
->len
; i
++) {
196 ret
= update_stream_class_meanings((ctf_stream_class
*) ctf_tc
->stream_classes
->pdata
[i
]);