Fix: src.ctf.fs: initialize the other_entry variable
[babeltrace.git] / src / plugins / ctf / common / metadata / ctf-meta-update-default-clock-classes.c
CommitLineData
44c440bc
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
f7b785ac
PP
15#define BT_COMP_LOG_SELF_COMP (log_cfg->self_comp)
16#define BT_LOG_OUTPUT_LEVEL (log_cfg->log_level)
350ad6c1 17#define BT_LOG_TAG "PLUGIN/CTF/META/UPDATE-DEF-CC"
d9c39b0a 18#include "logging/comp-logging.h"
44c440bc 19
3fadfbc0 20#include <babeltrace2/babeltrace.h>
91d81473 21#include "common/macros.h"
578e048b 22#include "common/assert.h"
44c440bc
PP
23#include <glib.h>
24#include <stdint.h>
25#include <string.h>
26#include <inttypes.h>
27
28#include "ctf-meta-visitors.h"
f7b785ac 29#include "logging.h"
44c440bc
PP
30
31static inline
5cd6d0e5 32int find_mapped_clock_class(struct ctf_field_class *fc,
0746848c 33 struct ctf_clock_class **clock_class,
f7b785ac 34 struct meta_log_config *log_cfg)
44c440bc
PP
35{
36 int ret = 0;
37 uint64_t i;
38
5cd6d0e5 39 if (!fc) {
44c440bc
PP
40 goto end;
41 }
42
864cad70
PP
43 switch (fc->type) {
44 case CTF_FIELD_CLASS_TYPE_INT:
45 case CTF_FIELD_CLASS_TYPE_ENUM:
44c440bc 46 {
5cd6d0e5 47 struct ctf_field_class_int *int_fc = (void *) fc;
44c440bc 48
5cd6d0e5 49 if (int_fc->mapped_clock_class) {
44c440bc 50 if (*clock_class && *clock_class !=
5cd6d0e5 51 int_fc->mapped_clock_class) {
f7b785ac 52 BT_COMP_LOGE("Stream class contains more than one "
44c440bc
PP
53 "clock class: expected-cc-name=\"%s\", "
54 "other-cc-name=\"%s\"",
0f2d58c9
PP
55 (*clock_class)->name->str,
56 int_fc->mapped_clock_class->name->str);
44c440bc
PP
57 ret = -1;
58 goto end;
59 }
60
5cd6d0e5 61 *clock_class = int_fc->mapped_clock_class;
44c440bc
PP
62 }
63
64 break;
65 }
864cad70 66 case CTF_FIELD_CLASS_TYPE_STRUCT:
44c440bc 67 {
5cd6d0e5 68 struct ctf_field_class_struct *struct_fc = (void *) fc;
44c440bc 69
5cd6d0e5
PP
70 for (i = 0; i < struct_fc->members->len; i++) {
71 struct ctf_named_field_class *named_fc =
72 ctf_field_class_struct_borrow_member_by_index(
73 struct_fc, i);
44c440bc 74
5cd6d0e5 75 ret = find_mapped_clock_class(named_fc->fc,
f7b785ac 76 clock_class, log_cfg);
44c440bc
PP
77 if (ret) {
78 goto end;
79 }
80 }
81
82 break;
83 }
864cad70 84 case CTF_FIELD_CLASS_TYPE_VARIANT:
44c440bc 85 {
5cd6d0e5 86 struct ctf_field_class_variant *var_fc = (void *) fc;
44c440bc 87
5cd6d0e5
PP
88 for (i = 0; i < var_fc->options->len; i++) {
89 struct ctf_named_field_class *named_fc =
90 ctf_field_class_variant_borrow_option_by_index(
91 var_fc, i);
44c440bc 92
5cd6d0e5 93 ret = find_mapped_clock_class(named_fc->fc,
f7b785ac 94 clock_class, log_cfg);
44c440bc
PP
95 if (ret) {
96 goto end;
97 }
98 }
99
100 break;
101 }
864cad70
PP
102 case CTF_FIELD_CLASS_TYPE_ARRAY:
103 case CTF_FIELD_CLASS_TYPE_SEQUENCE:
44c440bc 104 {
5cd6d0e5 105 struct ctf_field_class_array_base *array_fc = (void *) fc;
44c440bc 106
0746848c 107 ret = find_mapped_clock_class(array_fc->elem_fc, clock_class,
f7b785ac 108 log_cfg);
44c440bc
PP
109 if (ret) {
110 goto end;
111 }
112
113 break;
114 }
115 default:
116 break;
117 }
118
119end:
120 return ret;
121}
122
123static inline
124int update_stream_class_default_clock_class(
0746848c 125 struct ctf_stream_class *stream_class,
f7b785ac 126 struct meta_log_config *log_cfg)
44c440bc
PP
127{
128 int ret = 0;
0f2d58c9 129 struct ctf_clock_class *clock_class =
e5be10ef 130 stream_class->default_clock_class;
44c440bc
PP
131 uint64_t i;
132
5cd6d0e5 133 ret = find_mapped_clock_class(stream_class->packet_context_fc,
f7b785ac 134 &clock_class, log_cfg);
44c440bc
PP
135 if (ret) {
136 goto end;
137 }
138
5cd6d0e5 139 ret = find_mapped_clock_class(stream_class->event_header_fc,
f7b785ac 140 &clock_class, log_cfg);
44c440bc
PP
141 if (ret) {
142 goto end;
143 }
144
5cd6d0e5 145 ret = find_mapped_clock_class(stream_class->event_common_context_fc,
f7b785ac 146 &clock_class, log_cfg);
44c440bc
PP
147 if (ret) {
148 goto end;
149 }
150
151 for (i = 0; i < stream_class->event_classes->len; i++) {
152 struct ctf_event_class *event_class =
153 stream_class->event_classes->pdata[i];
154
5cd6d0e5 155 ret = find_mapped_clock_class(event_class->spec_context_fc,
f7b785ac 156 &clock_class, log_cfg);
44c440bc
PP
157 if (ret) {
158 goto end;
159 }
160
5cd6d0e5 161 ret = find_mapped_clock_class(event_class->payload_fc,
f7b785ac 162 &clock_class, log_cfg);
44c440bc
PP
163 if (ret) {
164 goto end;
165 }
166 }
167
168 if (!stream_class->default_clock_class) {
398454ed 169 stream_class->default_clock_class = clock_class;
44c440bc
PP
170 }
171
172end:
173 return ret;
174}
175
176BT_HIDDEN
0746848c 177int ctf_trace_class_update_default_clock_classes(struct ctf_trace_class *ctf_tc,
f7b785ac 178 struct meta_log_config *log_cfg)
44c440bc
PP
179{
180 uint64_t i;
181 int ret = 0;
0f2d58c9 182 struct ctf_clock_class *clock_class = NULL;
44c440bc 183
0746848c 184 ret = find_mapped_clock_class(ctf_tc->packet_header_fc, &clock_class,
f7b785ac 185 log_cfg);
44c440bc
PP
186 if (ret) {
187 goto end;
188 }
189
190 if (clock_class) {
191 ret = -1;
192 goto end;
193 }
194
195 for (i = 0; i < ctf_tc->stream_classes->len; i++) {
196 struct ctf_stream_class *sc =
197 ctf_tc->stream_classes->pdata[i];
198
199 ret = update_stream_class_default_clock_class(
f7b785ac 200 ctf_tc->stream_classes->pdata[i], log_cfg);
44c440bc 201 if (ret) {
f7b785ac 202 BT_COMP_LOGE("Stream class contains more than one "
44c440bc
PP
203 "clock class: stream-class-id=%" PRIu64,
204 sc->id);
205 goto end;
206 }
207 }
208
209end:
210 return ret;
211}
This page took 0.065152 seconds and 4 git commands to generate.