`ctf` plugin: metadata: use local log level
[babeltrace.git] / src / plugins / ctf / common / metadata / ctf-meta-update-value-storing-indexes.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
71c5da58 15#include <babeltrace2/babeltrace.h>
85e7137b 16#include "common/macros.h"
57952005 17#include "common/assert.h"
7b33a0e0
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
939190b3 26int update_field_class_stored_value_index(struct ctf_field_class *fc,
7b33a0e0
PP
27 struct ctf_trace_class *tc,
28 struct ctf_stream_class *sc,
29 struct ctf_event_class *ec)
30{
31 int ret = 0;
32 uint64_t i;
33 struct ctf_field_path *field_path = NULL;
939190b3 34 struct ctf_field_class_int *tgt_fc = NULL;
7b33a0e0
PP
35 uint64_t *stored_value_index = NULL;
36
939190b3 37 if (!fc) {
7b33a0e0
PP
38 goto end;
39 }
40
af0c18e3
PP
41 switch (fc->type) {
42 case CTF_FIELD_CLASS_TYPE_VARIANT:
7b33a0e0 43 {
939190b3 44 struct ctf_field_class_variant *var_fc = (void *) fc;
7b33a0e0 45
939190b3
PP
46 field_path = &var_fc->tag_path;
47 stored_value_index = &var_fc->stored_tag_index;
48 tgt_fc = (void *) var_fc->tag_fc;
7b33a0e0
PP
49 break;
50 }
af0c18e3 51 case CTF_FIELD_CLASS_TYPE_SEQUENCE:
7b33a0e0 52 {
939190b3 53 struct ctf_field_class_sequence *seq_fc = (void *) fc;
7b33a0e0 54
939190b3
PP
55 field_path = &seq_fc->length_path;
56 stored_value_index = &seq_fc->stored_length_index;
57 tgt_fc = seq_fc->length_fc;
7b33a0e0
PP
58 break;
59 }
60 default:
61 break;
62 }
63
64 if (field_path) {
939190b3 65 BT_ASSERT(tgt_fc);
af0c18e3
PP
66 BT_ASSERT(tgt_fc->base.base.type == CTF_FIELD_CLASS_TYPE_INT ||
67 tgt_fc->base.base.type == CTF_FIELD_CLASS_TYPE_ENUM);
939190b3 68 if (tgt_fc->storing_index >= 0) {
7b33a0e0 69 /* Already storing its value */
939190b3 70 *stored_value_index = (uint64_t) tgt_fc->storing_index;
7b33a0e0
PP
71 } else {
72 /* Not storing its value: allocate new index */
939190b3
PP
73 tgt_fc->storing_index = tc->stored_value_count;
74 *stored_value_index = (uint64_t) tgt_fc->storing_index;
7b33a0e0
PP
75 tc->stored_value_count++;
76 }
77 }
78
af0c18e3
PP
79 switch (fc->type) {
80 case CTF_FIELD_CLASS_TYPE_STRUCT:
7b33a0e0 81 {
939190b3 82 struct ctf_field_class_struct *struct_fc = (void *) fc;
7b33a0e0 83
939190b3
PP
84 for (i = 0; i < struct_fc->members->len; i++) {
85 struct ctf_named_field_class *named_fc =
86 ctf_field_class_struct_borrow_member_by_index(
87 struct_fc, i);
7b33a0e0 88
939190b3 89 ret = update_field_class_stored_value_index(named_fc->fc,
7b33a0e0
PP
90 tc, sc, ec);
91 if (ret) {
92 goto end;
93 }
94 }
95
96 break;
97 }
af0c18e3 98 case CTF_FIELD_CLASS_TYPE_VARIANT:
7b33a0e0 99 {
939190b3 100 struct ctf_field_class_variant *var_fc = (void *) fc;
7b33a0e0 101
939190b3
PP
102 for (i = 0; i < var_fc->options->len; i++) {
103 struct ctf_named_field_class *named_fc =
104 ctf_field_class_variant_borrow_option_by_index(
105 var_fc, i);
7b33a0e0 106
939190b3 107 ret = update_field_class_stored_value_index(named_fc->fc,
7b33a0e0
PP
108 tc, sc, ec);
109 if (ret) {
110 goto end;
111 }
112 }
113
114 break;
115 }
af0c18e3
PP
116 case CTF_FIELD_CLASS_TYPE_ARRAY:
117 case CTF_FIELD_CLASS_TYPE_SEQUENCE:
7b33a0e0 118 {
939190b3 119 struct ctf_field_class_array_base *array_fc = (void *) fc;
7b33a0e0 120
939190b3 121 ret = update_field_class_stored_value_index(array_fc->elem_fc,
7b33a0e0
PP
122 tc, sc, ec);
123 if (ret) {
124 goto end;
125 }
126
127 break;
128 }
129 default:
130 break;
131 }
132
133end:
134 return ret;
135}
136
137BT_HIDDEN
138int ctf_trace_class_update_value_storing_indexes(struct ctf_trace_class *ctf_tc)
139{
140 uint64_t i;
141
142 if (!ctf_tc->is_translated) {
939190b3
PP
143 update_field_class_stored_value_index(
144 ctf_tc->packet_header_fc, ctf_tc, NULL, NULL);
7b33a0e0
PP
145 }
146
147 for (i = 0; i < ctf_tc->stream_classes->len; i++) {
148 uint64_t j;
149 struct ctf_stream_class *sc = ctf_tc->stream_classes->pdata[i];
150
151 if (!sc->is_translated) {
939190b3 152 update_field_class_stored_value_index(sc->packet_context_fc,
7b33a0e0 153 ctf_tc, sc, NULL);
939190b3 154 update_field_class_stored_value_index(sc->event_header_fc,
7b33a0e0 155 ctf_tc, sc, NULL);
939190b3
PP
156 update_field_class_stored_value_index(
157 sc->event_common_context_fc, ctf_tc, sc, NULL);
7b33a0e0
PP
158 }
159
160 for (j = 0; j < sc->event_classes->len; j++) {
161 struct ctf_event_class *ec =
162 sc->event_classes->pdata[j];
163
164 if (!ec->is_translated) {
939190b3
PP
165 update_field_class_stored_value_index(
166 ec->spec_context_fc, ctf_tc, sc, ec);
167 update_field_class_stored_value_index(
168 ec->payload_fc, ctf_tc, sc, ec);
7b33a0e0
PP
169 }
170 }
171 }
172
173 return 0;
174}
This page took 0.038403 seconds and 4 git commands to generate.