Fix: src.ctf.fs: initialize the other_entry variable
[babeltrace.git] / src / plugins / ctf / common / metadata / ctf-meta-update-meanings.c
CommitLineData
44c440bc
PP
1/*
2 * Copyright 2018 - Philippe Proulx <pproulx@efficios.com>
3 *
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:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 */
14
3fadfbc0 15#include <babeltrace2/babeltrace.h>
91d81473 16#include "common/macros.h"
578e048b 17#include "common/assert.h"
44c440bc
PP
18#include <glib.h>
19#include <stdint.h>
20#include <string.h>
21#include <inttypes.h>
22
23#include "ctf-meta-visitors.h"
24
25static
5cd6d0e5 26int set_int_field_class_meaning_by_name(struct ctf_field_class *fc,
44c440bc 27 const char *field_name, const char *id_name,
5cd6d0e5 28 enum ctf_field_class_meaning meaning)
44c440bc
PP
29{
30 int ret = 0;
31 uint64_t i;
32
5cd6d0e5 33 if (!fc) {
44c440bc
PP
34 goto end;
35 }
36
864cad70
PP
37 switch (fc->type) {
38 case CTF_FIELD_CLASS_TYPE_INT:
39 case CTF_FIELD_CLASS_TYPE_ENUM:
44c440bc 40 {
5cd6d0e5 41 struct ctf_field_class_int *int_fc = (void *) fc;
44c440bc
PP
42
43 if (field_name && strcmp(field_name, id_name) == 0) {
5cd6d0e5 44 int_fc->meaning = meaning;
44c440bc
PP
45 }
46
47 break;
48 }
864cad70 49 case CTF_FIELD_CLASS_TYPE_STRUCT:
44c440bc 50 {
5cd6d0e5 51 struct ctf_field_class_struct *struct_fc = (void *) fc;
44c440bc 52
5cd6d0e5
PP
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(
56 struct_fc, i);
44c440bc 57
5cd6d0e5
PP
58 ret = set_int_field_class_meaning_by_name(named_fc->fc,
59 named_fc->name->str, id_name, meaning);
44c440bc
PP
60 if (ret) {
61 goto end;
62 }
63 }
64
65 break;
66 }
864cad70 67 case CTF_FIELD_CLASS_TYPE_VARIANT:
44c440bc 68 {
5cd6d0e5 69 struct ctf_field_class_variant *var_fc = (void *) fc;
44c440bc 70
5cd6d0e5
PP
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(
74 var_fc, i);
44c440bc 75
5cd6d0e5 76 ret = set_int_field_class_meaning_by_name(named_fc->fc,
44c440bc
PP
77 NULL, id_name, meaning);
78 if (ret) {
79 goto end;
80 }
81 }
82
83 break;
84 }
864cad70
PP
85 case CTF_FIELD_CLASS_TYPE_ARRAY:
86 case CTF_FIELD_CLASS_TYPE_SEQUENCE:
44c440bc 87 {
5cd6d0e5 88 struct ctf_field_class_array_base *array_fc = (void *) fc;
44c440bc 89
5cd6d0e5 90 ret = set_int_field_class_meaning_by_name(array_fc->elem_fc,
44c440bc
PP
91 NULL, id_name, meaning);
92 if (ret) {
93 goto end;
94 }
95
96 break;
97 }
98 default:
99 break;
100 }
101
102end:
103 return ret;
104}
105
106static
107int update_stream_class_meanings(struct ctf_stream_class *sc)
108{
109 int ret = 0;
5cd6d0e5 110 struct ctf_field_class_int *int_fc;
44c440bc
PP
111 uint64_t i;
112
113 if (!sc->is_translated) {
a8291ae7
PP
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");
117 if (int_fc) {
118 int_fc->meaning = CTF_FIELD_CLASS_MEANING_PACKET_BEGINNING_TIME;
119 }
44c440bc 120
a8291ae7
PP
121 int_fc = ctf_field_class_struct_borrow_member_int_field_class_by_name(
122 (void *) sc->packet_context_fc, "timestamp_end");
123 if (int_fc) {
124 int_fc->meaning = CTF_FIELD_CLASS_MEANING_PACKET_END_TIME;
44c440bc 125
a8291ae7
PP
126 /*
127 * Remove mapped clock class to avoid updating
128 * the clock immediately when decoding.
129 */
130 int_fc->mapped_clock_class = NULL;
131 }
44c440bc 132
a8291ae7
PP
133 int_fc = ctf_field_class_struct_borrow_member_int_field_class_by_name(
134 (void *) sc->packet_context_fc, "events_discarded");
135 if (int_fc) {
136 int_fc->meaning = CTF_FIELD_CLASS_MEANING_DISC_EV_REC_COUNTER_SNAPSHOT;
137 }
44c440bc 138
a8291ae7
PP
139 int_fc = ctf_field_class_struct_borrow_member_int_field_class_by_name(
140 (void *) sc->packet_context_fc, "packet_seq_num");
141 if (int_fc) {
142 int_fc->meaning = CTF_FIELD_CLASS_MEANING_PACKET_COUNTER_SNAPSHOT;
44c440bc 143
a8291ae7 144 }
44c440bc 145
a8291ae7
PP
146 int_fc = ctf_field_class_struct_borrow_member_int_field_class_by_name(
147 (void *) sc->packet_context_fc, "packet_size");
148 if (int_fc) {
149 int_fc->meaning = CTF_FIELD_CLASS_MEANING_EXP_PACKET_TOTAL_SIZE;
150 }
151
152 int_fc = ctf_field_class_struct_borrow_member_int_field_class_by_name(
153 (void *) sc->packet_context_fc, "content_size");
154 if (int_fc) {
155 int_fc->meaning = CTF_FIELD_CLASS_MEANING_EXP_PACKET_CONTENT_SIZE;
156 }
44c440bc
PP
157 }
158
a8291ae7
PP
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);
163 if (ret) {
164 goto end;
165 }
44c440bc
PP
166 }
167 }
168
169 for (i = 0; i < sc->event_classes->len; i++) {
170 struct ctf_event_class *ec = sc->event_classes->pdata[i];
171
172 if (ec->is_translated) {
173 continue;
174 }
175 }
176
177end:
178 return ret;
179}
180
181BT_HIDDEN
182int ctf_trace_class_update_meanings(struct ctf_trace_class *ctf_tc)
183{
184 int ret = 0;
5cd6d0e5
PP
185 struct ctf_field_class_int *int_fc;
186 struct ctf_named_field_class *named_fc;
44c440bc
PP
187 uint64_t i;
188
a8291ae7 189 if (!ctf_tc->is_translated && ctf_tc->packet_header_fc) {
5cd6d0e5
PP
190 int_fc = ctf_field_class_struct_borrow_member_int_field_class_by_name(
191 (void *) ctf_tc->packet_header_fc, "magic");
192 if (int_fc) {
193 int_fc->meaning = CTF_FIELD_CLASS_MEANING_MAGIC;
44c440bc
PP
194 }
195
5cd6d0e5
PP
196 int_fc = ctf_field_class_struct_borrow_member_int_field_class_by_name(
197 (void *) ctf_tc->packet_header_fc, "stream_id");
198 if (int_fc) {
199 int_fc->meaning = CTF_FIELD_CLASS_MEANING_STREAM_CLASS_ID;
44c440bc
PP
200 }
201
5cd6d0e5
PP
202 int_fc = ctf_field_class_struct_borrow_member_int_field_class_by_name(
203 (void *) ctf_tc->packet_header_fc,
44c440bc 204 "stream_instance_id");
5cd6d0e5
PP
205 if (int_fc) {
206 int_fc->meaning = CTF_FIELD_CLASS_MEANING_DATA_STREAM_ID;
44c440bc
PP
207 }
208
5cd6d0e5
PP
209 named_fc = ctf_field_class_struct_borrow_member_by_name(
210 (void *) ctf_tc->packet_header_fc, "uuid");
864cad70 211 if (named_fc && named_fc->fc->type == CTF_FIELD_CLASS_TYPE_ARRAY) {
5cd6d0e5
PP
212 struct ctf_field_class_array *array_fc =
213 (void *) named_fc->fc;
44c440bc 214
5cd6d0e5 215 array_fc->meaning = CTF_FIELD_CLASS_MEANING_UUID;
44c440bc
PP
216 }
217 }
218
219 for (i = 0; i < ctf_tc->stream_classes->len; i++) {
220 ret = update_stream_class_meanings(
221 ctf_tc->stream_classes->pdata[i]);
222 if (ret) {
223 goto end;
224 }
225 }
226
227end:
228 return ret;
229}
This page took 0.06282 seconds and 4 git commands to generate.