Move to kernel style SPDX license identifiers
[babeltrace.git] / src / plugins / ctf / common / metadata / ctf-meta-update-text-array-sequence.c
... / ...
CommitLineData
1/*
2 * SPDX-License-Identifier: MIT
3 *
4 * Copyright 2018 Philippe Proulx <pproulx@efficios.com>
5 */
6
7#include <babeltrace2/babeltrace.h>
8#include "common/macros.h"
9#include "common/assert.h"
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 inline
18int set_text_array_sequence_field_class(struct ctf_field_class *fc)
19{
20 int ret = 0;
21 uint64_t i;
22
23 if (!fc) {
24 goto end;
25 }
26
27 switch (fc->type) {
28 case CTF_FIELD_CLASS_TYPE_STRUCT:
29 {
30 struct ctf_field_class_struct *struct_fc = (void *) fc;
31
32 for (i = 0; i < struct_fc->members->len; i++) {
33 struct ctf_named_field_class *named_fc =
34 ctf_field_class_struct_borrow_member_by_index(
35 struct_fc, i);
36
37 ret = set_text_array_sequence_field_class(named_fc->fc);
38 if (ret) {
39 goto end;
40 }
41 }
42
43 break;
44 }
45 case CTF_FIELD_CLASS_TYPE_VARIANT:
46 {
47 struct ctf_field_class_variant *var_fc = (void *) fc;
48
49 for (i = 0; i < var_fc->options->len; i++) {
50 struct ctf_named_field_class *named_fc =
51 ctf_field_class_variant_borrow_option_by_index(
52 var_fc, i);
53
54 ret = set_text_array_sequence_field_class(named_fc->fc);
55 if (ret) {
56 goto end;
57 }
58 }
59
60 break;
61 }
62 case CTF_FIELD_CLASS_TYPE_ARRAY:
63 case CTF_FIELD_CLASS_TYPE_SEQUENCE:
64 {
65 struct ctf_field_class_array_base *array_fc = (void *) fc;
66
67 if (array_fc->elem_fc->type == CTF_FIELD_CLASS_TYPE_INT ||
68 array_fc->elem_fc->type == CTF_FIELD_CLASS_TYPE_ENUM) {
69 struct ctf_field_class_int *int_fc =
70 (void *) array_fc->elem_fc;
71
72 if (int_fc->base.base.alignment == 8 &&
73 int_fc->base.size == 8 &&
74 int_fc->encoding == CTF_ENCODING_UTF8) {
75 array_fc->is_text = true;
76
77 /*
78 * Force integer element to be unsigned;
79 * this makes the decoder enter a single
80 * path when reading a text
81 * array/sequence and we can safely
82 * decode bytes as characters anyway.
83 */
84 int_fc->is_signed = false;
85 }
86 }
87
88 ret = set_text_array_sequence_field_class(array_fc->elem_fc);
89 if (ret) {
90 goto end;
91 }
92
93 break;
94 }
95 default:
96 break;
97 }
98
99end:
100 return ret;
101}
102
103BT_HIDDEN
104int ctf_trace_class_update_text_array_sequence(struct ctf_trace_class *ctf_tc)
105{
106 int ret = 0;
107 uint64_t i;
108
109 if (!ctf_tc->is_translated) {
110 ret = set_text_array_sequence_field_class(
111 ctf_tc->packet_header_fc);
112 if (ret) {
113 goto end;
114 }
115 }
116
117 for (i = 0; i < ctf_tc->stream_classes->len; i++) {
118 struct ctf_stream_class *sc = ctf_tc->stream_classes->pdata[i];
119 uint64_t j;
120
121 if (!sc->is_translated) {
122 ret = set_text_array_sequence_field_class(
123 sc->packet_context_fc);
124 if (ret) {
125 goto end;
126 }
127
128 ret = set_text_array_sequence_field_class(
129 sc->event_header_fc);
130 if (ret) {
131 goto end;
132 }
133
134 ret = set_text_array_sequence_field_class(
135 sc->event_common_context_fc);
136 if (ret) {
137 goto end;
138 }
139 }
140
141 for (j = 0; j < sc->event_classes->len; j++) {
142 struct ctf_event_class *ec =
143 sc->event_classes->pdata[j];
144
145 if (ec->is_translated) {
146 continue;
147 }
148
149 ret = set_text_array_sequence_field_class(
150 ec->spec_context_fc);
151 if (ret) {
152 goto end;
153 }
154
155 ret = set_text_array_sequence_field_class(
156 ec->payload_fc);
157 if (ret) {
158 goto end;
159 }
160 }
161 }
162
163end:
164 return ret;
165}
This page took 0.022968 seconds and 4 git commands to generate.