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