Rename: field type -> field class
[babeltrace.git] / plugins / ctf / common / metadata / ctf-meta-update-meanings.c
CommitLineData
7b33a0e0
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
15#define BT_LOG_TAG "PLUGIN-CTF-METADATA-META-UPDATE-MEANINGS"
16#include "logging.h"
17
18#include <babeltrace/babeltrace.h>
19#include <babeltrace/babeltrace-internal.h>
20#include <babeltrace/assert-internal.h>
21#include <glib.h>
22#include <stdint.h>
23#include <string.h>
24#include <inttypes.h>
25
26#include "ctf-meta-visitors.h"
27
28static
939190b3 29int set_int_field_class_meaning_by_name(struct ctf_field_class *fc,
7b33a0e0 30 const char *field_name, const char *id_name,
939190b3 31 enum ctf_field_class_meaning meaning)
7b33a0e0
PP
32{
33 int ret = 0;
34 uint64_t i;
35
939190b3 36 if (!fc) {
7b33a0e0
PP
37 goto end;
38 }
39
939190b3
PP
40 switch (fc->id) {
41 case CTF_FIELD_CLASS_ID_INT:
42 case CTF_FIELD_CLASS_ID_ENUM:
7b33a0e0 43 {
939190b3 44 struct ctf_field_class_int *int_fc = (void *) fc;
7b33a0e0
PP
45
46 if (field_name && strcmp(field_name, id_name) == 0) {
939190b3 47 int_fc->meaning = meaning;
7b33a0e0
PP
48 }
49
50 break;
51 }
939190b3 52 case CTF_FIELD_CLASS_ID_STRUCT:
7b33a0e0 53 {
939190b3 54 struct ctf_field_class_struct *struct_fc = (void *) fc;
7b33a0e0 55
939190b3
PP
56 for (i = 0; i < struct_fc->members->len; i++) {
57 struct ctf_named_field_class *named_fc =
58 ctf_field_class_struct_borrow_member_by_index(
59 struct_fc, i);
7b33a0e0 60
939190b3
PP
61 ret = set_int_field_class_meaning_by_name(named_fc->fc,
62 named_fc->name->str, id_name, meaning);
7b33a0e0
PP
63 if (ret) {
64 goto end;
65 }
66 }
67
68 break;
69 }
939190b3 70 case CTF_FIELD_CLASS_ID_VARIANT:
7b33a0e0 71 {
939190b3 72 struct ctf_field_class_variant *var_fc = (void *) fc;
7b33a0e0 73
939190b3
PP
74 for (i = 0; i < var_fc->options->len; i++) {
75 struct ctf_named_field_class *named_fc =
76 ctf_field_class_variant_borrow_option_by_index(
77 var_fc, i);
7b33a0e0 78
939190b3 79 ret = set_int_field_class_meaning_by_name(named_fc->fc,
7b33a0e0
PP
80 NULL, id_name, meaning);
81 if (ret) {
82 goto end;
83 }
84 }
85
86 break;
87 }
939190b3
PP
88 case CTF_FIELD_CLASS_ID_ARRAY:
89 case CTF_FIELD_CLASS_ID_SEQUENCE:
7b33a0e0 90 {
939190b3 91 struct ctf_field_class_array_base *array_fc = (void *) fc;
7b33a0e0 92
939190b3 93 ret = set_int_field_class_meaning_by_name(array_fc->elem_fc,
7b33a0e0
PP
94 NULL, id_name, meaning);
95 if (ret) {
96 goto end;
97 }
98
99 break;
100 }
101 default:
102 break;
103 }
104
105end:
106 return ret;
107}
108
109static
110int update_stream_class_meanings(struct ctf_stream_class *sc)
111{
112 int ret = 0;
939190b3 113 struct ctf_field_class_int *int_fc;
7b33a0e0
PP
114 uint64_t i;
115
116 if (!sc->is_translated) {
939190b3
PP
117 int_fc = ctf_field_class_struct_borrow_member_int_field_class_by_name(
118 (void *) sc->packet_context_fc, "timestamp_begin");
119 if (int_fc) {
120 int_fc->meaning = CTF_FIELD_CLASS_MEANING_PACKET_BEGINNING_TIME;
7b33a0e0
PP
121 }
122
939190b3
PP
123 int_fc = ctf_field_class_struct_borrow_member_int_field_class_by_name(
124 (void *) sc->packet_context_fc, "timestamp_end");
125 if (int_fc) {
126 int_fc->meaning = CTF_FIELD_CLASS_MEANING_PACKET_END_TIME;
7b33a0e0
PP
127
128 /*
129 * Remove mapped clock class to avoid updating
130 * the clock immediately when decoding.
131 */
939190b3 132 int_fc->mapped_clock_class = NULL;
7b33a0e0
PP
133 }
134
939190b3
PP
135 int_fc = ctf_field_class_struct_borrow_member_int_field_class_by_name(
136 (void *) sc->packet_context_fc, "events_discarded");
137 if (int_fc) {
138 int_fc->meaning = CTF_FIELD_CLASS_MEANING_DISC_EV_REC_COUNTER_SNAPSHOT;
7b33a0e0
PP
139 }
140
939190b3
PP
141 int_fc = ctf_field_class_struct_borrow_member_int_field_class_by_name(
142 (void *) sc->packet_context_fc, "packet_seq_num");
143 if (int_fc) {
144 int_fc->meaning = CTF_FIELD_CLASS_MEANING_PACKET_COUNTER_SNAPSHOT;
7b33a0e0
PP
145
146 }
147
939190b3
PP
148 int_fc = ctf_field_class_struct_borrow_member_int_field_class_by_name(
149 (void *) sc->packet_context_fc, "packet_size");
150 if (int_fc) {
151 int_fc->meaning = CTF_FIELD_CLASS_MEANING_EXP_PACKET_TOTAL_SIZE;
7b33a0e0
PP
152 }
153
939190b3
PP
154 int_fc = ctf_field_class_struct_borrow_member_int_field_class_by_name(
155 (void *) sc->packet_context_fc, "content_size");
156 if (int_fc) {
157 int_fc->meaning = CTF_FIELD_CLASS_MEANING_EXP_PACKET_CONTENT_SIZE;
7b33a0e0
PP
158 }
159
939190b3
PP
160 ret = set_int_field_class_meaning_by_name(
161 sc->event_header_fc, NULL, "id",
162 CTF_FIELD_CLASS_MEANING_EVENT_CLASS_ID);
7b33a0e0
PP
163 if (ret) {
164 goto end;
165 }
166 }
167
168 for (i = 0; i < sc->event_classes->len; i++) {
169 struct ctf_event_class *ec = sc->event_classes->pdata[i];
170
171 if (ec->is_translated) {
172 continue;
173 }
174 }
175
176end:
177 return ret;
178}
179
180BT_HIDDEN
181int ctf_trace_class_update_meanings(struct ctf_trace_class *ctf_tc)
182{
183 int ret = 0;
939190b3
PP
184 struct ctf_field_class_int *int_fc;
185 struct ctf_named_field_class *named_fc;
7b33a0e0
PP
186 uint64_t i;
187
188 if (!ctf_tc->is_translated) {
939190b3
PP
189 int_fc = ctf_field_class_struct_borrow_member_int_field_class_by_name(
190 (void *) ctf_tc->packet_header_fc, "magic");
191 if (int_fc) {
192 int_fc->meaning = CTF_FIELD_CLASS_MEANING_MAGIC;
7b33a0e0
PP
193 }
194
939190b3
PP
195 int_fc = ctf_field_class_struct_borrow_member_int_field_class_by_name(
196 (void *) ctf_tc->packet_header_fc, "stream_id");
197 if (int_fc) {
198 int_fc->meaning = CTF_FIELD_CLASS_MEANING_STREAM_CLASS_ID;
7b33a0e0
PP
199 }
200
939190b3
PP
201 int_fc = ctf_field_class_struct_borrow_member_int_field_class_by_name(
202 (void *) ctf_tc->packet_header_fc,
7b33a0e0 203 "stream_instance_id");
939190b3
PP
204 if (int_fc) {
205 int_fc->meaning = CTF_FIELD_CLASS_MEANING_DATA_STREAM_ID;
7b33a0e0
PP
206 }
207
939190b3
PP
208 named_fc = ctf_field_class_struct_borrow_member_by_name(
209 (void *) ctf_tc->packet_header_fc, "uuid");
210 if (named_fc && named_fc->fc->id == CTF_FIELD_CLASS_ID_ARRAY) {
211 struct ctf_field_class_array *array_fc =
212 (void *) named_fc->fc;
7b33a0e0 213
939190b3 214 array_fc->meaning = CTF_FIELD_CLASS_MEANING_UUID;
7b33a0e0
PP
215 }
216 }
217
218 for (i = 0; i < ctf_tc->stream_classes->len; i++) {
219 ret = update_stream_class_meanings(
220 ctf_tc->stream_classes->pdata[i]);
221 if (ret) {
222 goto end;
223 }
224 }
225
226end:
227 return ret;
228}
This page took 0.033678 seconds and 4 git commands to generate.