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