Move to kernel style SPDX license identifiers
[babeltrace.git] / src / plugins / ctf / common / metadata / ctf-meta-update-value-storing-indexes.c
CommitLineData
44c440bc 1/*
0235b0db 2 * SPDX-License-Identifier: MIT
44c440bc 3 *
0235b0db 4 * Copyright 2018 Philippe Proulx <pproulx@efficios.com>
44c440bc
PP
5 */
6
3fadfbc0 7#include <babeltrace2/babeltrace.h>
91d81473 8#include "common/macros.h"
578e048b 9#include "common/assert.h"
44c440bc
PP
10#include <glib.h>
11#include <stdint.h>
12#include <string.h>
13#include <inttypes.h>
14
15#include "ctf-meta-visitors.h"
16
17static
5cd6d0e5 18int update_field_class_stored_value_index(struct ctf_field_class *fc,
44c440bc
PP
19 struct ctf_trace_class *tc,
20 struct ctf_stream_class *sc,
21 struct ctf_event_class *ec)
22{
23 int ret = 0;
24 uint64_t i;
25 struct ctf_field_path *field_path = NULL;
5cd6d0e5 26 struct ctf_field_class_int *tgt_fc = NULL;
44c440bc
PP
27 uint64_t *stored_value_index = NULL;
28
5cd6d0e5 29 if (!fc) {
44c440bc
PP
30 goto end;
31 }
32
864cad70
PP
33 switch (fc->type) {
34 case CTF_FIELD_CLASS_TYPE_VARIANT:
44c440bc 35 {
5cd6d0e5 36 struct ctf_field_class_variant *var_fc = (void *) fc;
44c440bc 37
5cd6d0e5
PP
38 field_path = &var_fc->tag_path;
39 stored_value_index = &var_fc->stored_tag_index;
40 tgt_fc = (void *) var_fc->tag_fc;
44c440bc
PP
41 break;
42 }
864cad70 43 case CTF_FIELD_CLASS_TYPE_SEQUENCE:
44c440bc 44 {
5cd6d0e5 45 struct ctf_field_class_sequence *seq_fc = (void *) fc;
44c440bc 46
5cd6d0e5
PP
47 field_path = &seq_fc->length_path;
48 stored_value_index = &seq_fc->stored_length_index;
49 tgt_fc = seq_fc->length_fc;
44c440bc
PP
50 break;
51 }
52 default:
53 break;
54 }
55
56 if (field_path) {
5cd6d0e5 57 BT_ASSERT(tgt_fc);
864cad70
PP
58 BT_ASSERT(tgt_fc->base.base.type == CTF_FIELD_CLASS_TYPE_INT ||
59 tgt_fc->base.base.type == CTF_FIELD_CLASS_TYPE_ENUM);
5cd6d0e5 60 if (tgt_fc->storing_index >= 0) {
44c440bc 61 /* Already storing its value */
5cd6d0e5 62 *stored_value_index = (uint64_t) tgt_fc->storing_index;
44c440bc
PP
63 } else {
64 /* Not storing its value: allocate new index */
5cd6d0e5
PP
65 tgt_fc->storing_index = tc->stored_value_count;
66 *stored_value_index = (uint64_t) tgt_fc->storing_index;
44c440bc
PP
67 tc->stored_value_count++;
68 }
69 }
70
864cad70
PP
71 switch (fc->type) {
72 case CTF_FIELD_CLASS_TYPE_STRUCT:
44c440bc 73 {
5cd6d0e5 74 struct ctf_field_class_struct *struct_fc = (void *) fc;
44c440bc 75
5cd6d0e5
PP
76 for (i = 0; i < struct_fc->members->len; i++) {
77 struct ctf_named_field_class *named_fc =
78 ctf_field_class_struct_borrow_member_by_index(
79 struct_fc, i);
44c440bc 80
5cd6d0e5 81 ret = update_field_class_stored_value_index(named_fc->fc,
44c440bc
PP
82 tc, sc, ec);
83 if (ret) {
84 goto end;
85 }
86 }
87
88 break;
89 }
864cad70 90 case CTF_FIELD_CLASS_TYPE_VARIANT:
44c440bc 91 {
5cd6d0e5 92 struct ctf_field_class_variant *var_fc = (void *) fc;
44c440bc 93
5cd6d0e5
PP
94 for (i = 0; i < var_fc->options->len; i++) {
95 struct ctf_named_field_class *named_fc =
96 ctf_field_class_variant_borrow_option_by_index(
97 var_fc, i);
44c440bc 98
5cd6d0e5 99 ret = update_field_class_stored_value_index(named_fc->fc,
44c440bc
PP
100 tc, sc, ec);
101 if (ret) {
102 goto end;
103 }
104 }
105
106 break;
107 }
864cad70
PP
108 case CTF_FIELD_CLASS_TYPE_ARRAY:
109 case CTF_FIELD_CLASS_TYPE_SEQUENCE:
44c440bc 110 {
5cd6d0e5 111 struct ctf_field_class_array_base *array_fc = (void *) fc;
44c440bc 112
5cd6d0e5 113 ret = update_field_class_stored_value_index(array_fc->elem_fc,
44c440bc
PP
114 tc, sc, ec);
115 if (ret) {
116 goto end;
117 }
118
119 break;
120 }
121 default:
122 break;
123 }
124
125end:
126 return ret;
127}
128
129BT_HIDDEN
130int ctf_trace_class_update_value_storing_indexes(struct ctf_trace_class *ctf_tc)
131{
132 uint64_t i;
133
134 if (!ctf_tc->is_translated) {
5cd6d0e5
PP
135 update_field_class_stored_value_index(
136 ctf_tc->packet_header_fc, ctf_tc, NULL, NULL);
44c440bc
PP
137 }
138
139 for (i = 0; i < ctf_tc->stream_classes->len; i++) {
140 uint64_t j;
141 struct ctf_stream_class *sc = ctf_tc->stream_classes->pdata[i];
142
143 if (!sc->is_translated) {
5cd6d0e5 144 update_field_class_stored_value_index(sc->packet_context_fc,
44c440bc 145 ctf_tc, sc, NULL);
5cd6d0e5 146 update_field_class_stored_value_index(sc->event_header_fc,
44c440bc 147 ctf_tc, sc, NULL);
5cd6d0e5
PP
148 update_field_class_stored_value_index(
149 sc->event_common_context_fc, ctf_tc, sc, NULL);
44c440bc
PP
150 }
151
152 for (j = 0; j < sc->event_classes->len; j++) {
153 struct ctf_event_class *ec =
154 sc->event_classes->pdata[j];
155
156 if (!ec->is_translated) {
5cd6d0e5
PP
157 update_field_class_stored_value_index(
158 ec->spec_context_fc, ctf_tc, sc, ec);
159 update_field_class_stored_value_index(
160 ec->payload_fc, ctf_tc, sc, ec);
44c440bc
PP
161 }
162 }
163 }
164
165 return 0;
166}
This page took 0.060927 seconds and 4 git commands to generate.