Commit | Line | Data |
---|---|---|
16ca5ff0 | 1 | /* |
0235b0db | 2 | * SPDX-License-Identifier: MIT |
16ca5ff0 PP |
3 | * |
4 | * Copyright 2016-2018 Philippe Proulx <pproulx@efficios.com> | |
5 | * | |
0235b0db | 6 | * Babeltrace - CTF writer: Validation of trace, stream class, and event class |
16ca5ff0 PP |
7 | */ |
8 | ||
350ad6c1 | 9 | #define BT_LOG_TAG "CTF-WRITER/VALIDATION" |
67d2ce02 | 10 | #include "logging.h" |
16ca5ff0 | 11 | |
217cf9d3 | 12 | #include <babeltrace2-ctf-writer/object.h> |
578e048b | 13 | |
91d81473 | 14 | #include "common/macros.h" |
578e048b MJ |
15 | |
16 | #include "assert-pre.h" | |
17 | #include "event-class.h" | |
18 | #include "field-types.h" | |
19 | #include "field-types.h" | |
20 | #include "resolve.h" | |
21 | #include "stream-class.h" | |
22 | #include "trace.h" | |
23 | #include "validation.h" | |
24 | #include "values.h" | |
16ca5ff0 PP |
25 | |
26 | /* | |
27 | * This function resolves and validates the field types of an event | |
28 | * class. Only `event_context_type` and `event_payload_type` are | |
29 | * resolved and validated; the other field types are used as eventual | |
30 | * resolving targets. | |
31 | * | |
32 | * All parameters are owned by the caller. | |
33 | */ | |
34 | static | |
e1e02a22 | 35 | int validate_event_class_types(struct bt_ctf_private_value *environment, |
16ca5ff0 PP |
36 | struct bt_ctf_field_type_common *packet_header_type, |
37 | struct bt_ctf_field_type_common *packet_context_type, | |
38 | struct bt_ctf_field_type_common *event_header_type, | |
39 | struct bt_ctf_field_type_common *stream_event_ctx_type, | |
40 | struct bt_ctf_field_type_common *event_context_type, | |
41 | struct bt_ctf_field_type_common *event_payload_type) | |
42 | { | |
43 | int ret = 0; | |
44 | ||
ef267d12 | 45 | BT_LOGT("Validating event class field types: " |
16ca5ff0 PP |
46 | "packet-header-ft-addr=%p, " |
47 | "packet-context-ft-addr=%p, " | |
48 | "event-header-ft-addr=%p, " | |
49 | "stream-event-context-ft-addr=%p, " | |
50 | "event-context-ft-addr=%p, " | |
51 | "event-payload-ft-addr=%p", | |
52 | packet_header_type, packet_context_type, event_header_type, | |
53 | stream_event_ctx_type, event_context_type, event_payload_type); | |
54 | ||
55 | /* Resolve sequence type lengths and variant type tags first */ | |
56 | ret = bt_ctf_resolve_types(environment, packet_header_type, | |
57 | packet_context_type, event_header_type, stream_event_ctx_type, | |
58 | event_context_type, event_payload_type, | |
59 | BT_CTF_RESOLVE_FLAG_EVENT_CONTEXT | | |
60 | BT_CTF_RESOLVE_FLAG_EVENT_PAYLOAD); | |
61 | if (ret) { | |
62 | BT_LOGW("Cannot resolve event class field types: ret=%d", | |
63 | ret); | |
64 | goto end; | |
65 | } | |
66 | ||
67 | /* Validate field types individually */ | |
68 | if (event_context_type) { | |
69 | ret = bt_ctf_field_type_common_validate(event_context_type); | |
70 | if (ret) { | |
71 | BT_LOGW("Invalid event class's context field type: " | |
72 | "ret=%d", ret); | |
73 | goto end; | |
74 | } | |
75 | } | |
76 | ||
77 | if (event_payload_type) { | |
78 | ret = bt_ctf_field_type_common_validate(event_payload_type); | |
79 | if (ret) { | |
80 | BT_LOGW("Invalid event class's payload field type: " | |
81 | "ret=%d", ret); | |
82 | goto end; | |
83 | } | |
84 | } | |
85 | ||
86 | end: | |
87 | return ret; | |
88 | } | |
89 | ||
90 | /* | |
91 | * This function resolves and validates the field types of a stream | |
92 | * class. Only `packet_context_type`, `event_header_type`, and | |
93 | * `stream_event_ctx_type` are resolved and validated; the other field | |
94 | * type is used as an eventual resolving target. | |
95 | * | |
96 | * All parameters are owned by the caller. | |
97 | */ | |
98 | static | |
e1e02a22 | 99 | int validate_stream_class_types(struct bt_ctf_private_value *environment, |
16ca5ff0 PP |
100 | struct bt_ctf_field_type_common *packet_header_type, |
101 | struct bt_ctf_field_type_common *packet_context_type, | |
102 | struct bt_ctf_field_type_common *event_header_type, | |
103 | struct bt_ctf_field_type_common *stream_event_ctx_type) | |
104 | { | |
105 | int ret = 0; | |
106 | ||
ef267d12 | 107 | BT_LOGT("Validating stream class field types: " |
16ca5ff0 PP |
108 | "packet-header-ft-addr=%p, " |
109 | "packet-context-ft-addr=%p, " | |
110 | "event-header-ft-addr=%p, " | |
111 | "stream-event-context-ft-addr=%p", | |
112 | packet_header_type, packet_context_type, event_header_type, | |
113 | stream_event_ctx_type); | |
114 | ||
115 | /* Resolve sequence type lengths and variant type tags first */ | |
116 | ret = bt_ctf_resolve_types(environment, packet_header_type, | |
117 | packet_context_type, event_header_type, stream_event_ctx_type, | |
118 | NULL, NULL, | |
119 | BT_CTF_RESOLVE_FLAG_PACKET_CONTEXT | | |
120 | BT_CTF_RESOLVE_FLAG_EVENT_HEADER | | |
121 | BT_CTF_RESOLVE_FLAG_STREAM_EVENT_CTX); | |
122 | if (ret) { | |
123 | BT_LOGW("Cannot resolve stream class field types: ret=%d", | |
124 | ret); | |
125 | goto end; | |
126 | } | |
127 | ||
128 | /* Validate field types individually */ | |
129 | if (packet_context_type) { | |
130 | ret = bt_ctf_field_type_common_validate(packet_context_type); | |
131 | if (ret) { | |
132 | BT_LOGW("Invalid stream class's packet context field type: " | |
133 | "ret=%d", ret); | |
134 | goto end; | |
135 | } | |
136 | } | |
137 | ||
138 | if (event_header_type) { | |
139 | ret = bt_ctf_field_type_common_validate(event_header_type); | |
140 | if (ret) { | |
141 | BT_LOGW("Invalid stream class's event header field type: " | |
142 | "ret=%d", ret); | |
143 | goto end; | |
144 | } | |
145 | } | |
146 | ||
147 | if (stream_event_ctx_type) { | |
148 | ret = bt_ctf_field_type_common_validate( | |
149 | stream_event_ctx_type); | |
150 | if (ret) { | |
151 | BT_LOGW("Invalid stream class's event context field type: " | |
152 | "ret=%d", ret); | |
153 | goto end; | |
154 | } | |
155 | } | |
156 | ||
157 | end: | |
158 | return ret; | |
159 | } | |
160 | ||
161 | /* | |
162 | * This function resolves and validates the field types of a trace. | |
163 | * | |
164 | * All parameters are owned by the caller. | |
165 | */ | |
166 | static | |
e1e02a22 | 167 | int validate_trace_types(struct bt_ctf_private_value *environment, |
16ca5ff0 PP |
168 | struct bt_ctf_field_type_common *packet_header_type) |
169 | { | |
170 | int ret = 0; | |
171 | ||
ef267d12 | 172 | BT_LOGT("Validating event class field types: " |
16ca5ff0 PP |
173 | "packet-header-ft-addr=%p", packet_header_type); |
174 | ||
175 | /* Resolve sequence type lengths and variant type tags first */ | |
176 | ret = bt_ctf_resolve_types(environment, packet_header_type, | |
177 | NULL, NULL, NULL, NULL, NULL, | |
178 | BT_CTF_RESOLVE_FLAG_PACKET_HEADER); | |
179 | if (ret) { | |
180 | BT_LOGW("Cannot resolve trace field types: ret=%d", | |
181 | ret); | |
182 | goto end; | |
183 | } | |
184 | ||
185 | /* Validate field types individually */ | |
186 | if (packet_header_type) { | |
187 | ret = bt_ctf_field_type_common_validate(packet_header_type); | |
188 | if (ret) { | |
189 | BT_LOGW("Invalid trace's packet header field type: " | |
190 | "ret=%d", ret); | |
191 | goto end; | |
192 | } | |
193 | } | |
194 | ||
195 | end: | |
196 | return ret; | |
197 | } | |
198 | ||
199 | /* | |
200 | * Checks whether or not `field_type` contains a variant or a sequence | |
201 | * field type, recursively. Returns 1 if it's the case. | |
202 | * | |
203 | * `field_type` is owned by the caller. | |
204 | */ | |
205 | static | |
206 | int field_type_contains_sequence_or_variant_ft(struct bt_ctf_field_type_common *type) | |
207 | { | |
208 | int ret = 0; | |
209 | enum bt_ctf_field_type_id type_id = bt_ctf_field_type_common_get_type_id(type); | |
210 | ||
211 | switch (type_id) { | |
212 | case BT_CTF_FIELD_TYPE_ID_SEQUENCE: | |
213 | case BT_CTF_FIELD_TYPE_ID_VARIANT: | |
214 | ret = 1; | |
215 | goto end; | |
216 | case BT_CTF_FIELD_TYPE_ID_ARRAY: | |
217 | case BT_CTF_FIELD_TYPE_ID_STRUCT: | |
218 | { | |
219 | int i; | |
220 | int field_count = bt_ctf_field_type_common_get_field_count(type); | |
221 | ||
222 | if (field_count < 0) { | |
223 | ret = -1; | |
224 | goto end; | |
225 | } | |
226 | ||
227 | for (i = 0; i < field_count; ++i) { | |
228 | struct bt_ctf_field_type_common *child_type = | |
229 | bt_ctf_field_type_common_borrow_field_at_index( | |
230 | type, i); | |
231 | ||
232 | ret = field_type_contains_sequence_or_variant_ft( | |
233 | child_type); | |
234 | if (ret != 0) { | |
235 | goto end; | |
236 | } | |
237 | } | |
238 | break; | |
239 | } | |
240 | default: | |
241 | break; | |
242 | } | |
243 | ||
244 | end: | |
245 | return ret; | |
246 | } | |
247 | ||
248 | BT_HIDDEN | |
e1e02a22 | 249 | int bt_ctf_validate_class_types(struct bt_ctf_private_value *environment, |
16ca5ff0 PP |
250 | struct bt_ctf_field_type_common *packet_header_type, |
251 | struct bt_ctf_field_type_common *packet_context_type, | |
252 | struct bt_ctf_field_type_common *event_header_type, | |
253 | struct bt_ctf_field_type_common *stream_event_ctx_type, | |
254 | struct bt_ctf_field_type_common *event_context_type, | |
255 | struct bt_ctf_field_type_common *event_payload_type, | |
256 | int trace_valid, int stream_class_valid, int event_class_valid, | |
257 | struct bt_ctf_validation_output *output, | |
258 | enum bt_ctf_validation_flag validate_flags, | |
259 | bt_ctf_validation_flag_copy_field_type_func copy_field_type_func) | |
260 | { | |
261 | int ret = 0; | |
262 | int contains_seq_var; | |
263 | int valid_ret; | |
264 | ||
ef267d12 | 265 | BT_LOGT("Validating field types: " |
16ca5ff0 PP |
266 | "packet-header-ft-addr=%p, " |
267 | "packet-context-ft-addr=%p, " | |
268 | "event-header-ft-addr=%p, " | |
269 | "stream-event-context-ft-addr=%p, " | |
270 | "event-context-ft-addr=%p, " | |
271 | "event-payload-ft-addr=%p, " | |
272 | "trace-is-valid=%d, stream-class-is-valid=%d, " | |
273 | "event-class-is-valid=%d, validation-flags=%x", | |
274 | packet_header_type, packet_context_type, event_header_type, | |
275 | stream_event_ctx_type, event_context_type, event_payload_type, | |
276 | trace_valid, stream_class_valid, event_class_valid, | |
277 | (unsigned int) validate_flags); | |
278 | ||
279 | /* Clean output values */ | |
280 | memset(output, 0, sizeof(*output)); | |
281 | ||
282 | /* Set initial valid flags according to valid parameters */ | |
283 | if (trace_valid) { | |
284 | output->valid_flags |= BT_CTF_VALIDATION_FLAG_TRACE; | |
285 | } | |
286 | ||
287 | if (stream_class_valid) { | |
288 | output->valid_flags |= BT_CTF_VALIDATION_FLAG_STREAM; | |
289 | } | |
290 | ||
291 | if (event_class_valid) { | |
292 | output->valid_flags |= BT_CTF_VALIDATION_FLAG_EVENT; | |
293 | } | |
294 | ||
295 | /* Own the type parameters */ | |
e1e02a22 PP |
296 | bt_ctf_object_get_ref(packet_header_type); |
297 | bt_ctf_object_get_ref(packet_context_type); | |
298 | bt_ctf_object_get_ref(event_header_type); | |
299 | bt_ctf_object_get_ref(stream_event_ctx_type); | |
300 | bt_ctf_object_get_ref(event_context_type); | |
301 | bt_ctf_object_get_ref(event_payload_type); | |
16ca5ff0 PP |
302 | |
303 | /* Validate trace */ | |
304 | if ((validate_flags & BT_CTF_VALIDATION_FLAG_TRACE) && !trace_valid) { | |
305 | struct bt_ctf_field_type_common *packet_header_type_copy = NULL; | |
306 | ||
307 | /* Create field type copies */ | |
308 | if (packet_header_type) { | |
309 | contains_seq_var = | |
310 | field_type_contains_sequence_or_variant_ft( | |
311 | packet_header_type); | |
312 | if (contains_seq_var < 0) { | |
313 | ret = contains_seq_var; | |
314 | goto error; | |
315 | } else if (!contains_seq_var) { | |
316 | /* No copy is needed */ | |
317 | packet_header_type_copy = packet_header_type; | |
e1e02a22 | 318 | bt_ctf_object_get_ref(packet_header_type_copy); |
16ca5ff0 PP |
319 | goto skip_packet_header_type_copy; |
320 | } | |
321 | ||
ef267d12 | 322 | BT_LOGT_STR("Copying packet header field type because it contains at least one sequence or variant field type."); |
16ca5ff0 PP |
323 | packet_header_type_copy = |
324 | copy_field_type_func(packet_header_type); | |
325 | if (!packet_header_type_copy) { | |
326 | ret = -1; | |
327 | BT_LOGE_STR("Cannot copy packet header field type."); | |
328 | goto error; | |
329 | } | |
330 | ||
331 | /* | |
332 | * Freeze this copy: if it's returned to the | |
333 | * caller, it cannot be modified any way since | |
334 | * it will be resolved. | |
335 | */ | |
336 | bt_ctf_field_type_common_freeze(packet_header_type_copy); | |
337 | } | |
338 | ||
339 | skip_packet_header_type_copy: | |
340 | /* Put original reference and move copy */ | |
e1e02a22 | 341 | BT_CTF_OBJECT_MOVE_REF(packet_header_type, packet_header_type_copy); |
16ca5ff0 PP |
342 | |
343 | /* Validate trace field types */ | |
344 | valid_ret = validate_trace_types(environment, | |
345 | packet_header_type); | |
346 | if (valid_ret == 0) { | |
347 | /* Trace is valid */ | |
348 | output->valid_flags |= BT_CTF_VALIDATION_FLAG_TRACE; | |
349 | } | |
350 | } | |
351 | ||
352 | /* Validate stream class */ | |
353 | if ((validate_flags & BT_CTF_VALIDATION_FLAG_STREAM) && | |
354 | !stream_class_valid) { | |
355 | struct bt_ctf_field_type_common *packet_context_type_copy = NULL; | |
356 | struct bt_ctf_field_type_common *event_header_type_copy = NULL; | |
357 | struct bt_ctf_field_type_common *stream_event_ctx_type_copy = NULL; | |
358 | ||
359 | if (packet_context_type) { | |
360 | contains_seq_var = | |
361 | field_type_contains_sequence_or_variant_ft( | |
362 | packet_context_type); | |
363 | if (contains_seq_var < 0) { | |
364 | ret = contains_seq_var; | |
365 | goto error; | |
366 | } else if (!contains_seq_var) { | |
367 | /* No copy is needed */ | |
368 | packet_context_type_copy = packet_context_type; | |
e1e02a22 | 369 | bt_ctf_object_get_ref(packet_context_type_copy); |
16ca5ff0 PP |
370 | goto skip_packet_context_type_copy; |
371 | } | |
372 | ||
ef267d12 | 373 | BT_LOGT_STR("Copying packet context field type because it contains at least one sequence or variant field type."); |
16ca5ff0 PP |
374 | packet_context_type_copy = |
375 | copy_field_type_func(packet_context_type); | |
376 | if (!packet_context_type_copy) { | |
377 | BT_LOGE_STR("Cannot copy packet context field type."); | |
378 | goto sc_validation_error; | |
379 | } | |
380 | ||
381 | /* | |
382 | * Freeze this copy: if it's returned to the | |
383 | * caller, it cannot be modified any way since | |
384 | * it will be resolved. | |
385 | */ | |
386 | bt_ctf_field_type_common_freeze(packet_context_type_copy); | |
387 | } | |
388 | ||
389 | skip_packet_context_type_copy: | |
390 | if (event_header_type) { | |
391 | contains_seq_var = | |
392 | field_type_contains_sequence_or_variant_ft( | |
393 | event_header_type); | |
394 | if (contains_seq_var < 0) { | |
395 | ret = contains_seq_var; | |
396 | goto error; | |
397 | } else if (!contains_seq_var) { | |
398 | /* No copy is needed */ | |
399 | event_header_type_copy = event_header_type; | |
e1e02a22 | 400 | bt_ctf_object_get_ref(event_header_type_copy); |
16ca5ff0 PP |
401 | goto skip_event_header_type_copy; |
402 | } | |
403 | ||
ef267d12 | 404 | BT_LOGT_STR("Copying event header field type because it contains at least one sequence or variant field type."); |
16ca5ff0 PP |
405 | event_header_type_copy = |
406 | copy_field_type_func(event_header_type); | |
407 | if (!event_header_type_copy) { | |
408 | BT_LOGE_STR("Cannot copy event header field type."); | |
409 | goto sc_validation_error; | |
410 | } | |
411 | ||
412 | /* | |
413 | * Freeze this copy: if it's returned to the | |
414 | * caller, it cannot be modified any way since | |
415 | * it will be resolved. | |
416 | */ | |
417 | bt_ctf_field_type_common_freeze(event_header_type_copy); | |
418 | } | |
419 | ||
420 | skip_event_header_type_copy: | |
421 | if (stream_event_ctx_type) { | |
422 | contains_seq_var = | |
423 | field_type_contains_sequence_or_variant_ft( | |
424 | stream_event_ctx_type); | |
425 | if (contains_seq_var < 0) { | |
426 | ret = contains_seq_var; | |
427 | goto error; | |
428 | } else if (!contains_seq_var) { | |
429 | /* No copy is needed */ | |
430 | stream_event_ctx_type_copy = | |
431 | stream_event_ctx_type; | |
e1e02a22 | 432 | bt_ctf_object_get_ref(stream_event_ctx_type_copy); |
16ca5ff0 PP |
433 | goto skip_stream_event_ctx_type_copy; |
434 | } | |
435 | ||
ef267d12 | 436 | BT_LOGT_STR("Copying stream event context field type because it contains at least one sequence or variant field type."); |
16ca5ff0 PP |
437 | stream_event_ctx_type_copy = |
438 | copy_field_type_func(stream_event_ctx_type); | |
439 | if (!stream_event_ctx_type_copy) { | |
440 | BT_LOGE_STR("Cannot copy stream event context field type."); | |
441 | goto sc_validation_error; | |
442 | } | |
443 | ||
444 | /* | |
445 | * Freeze this copy: if it's returned to the | |
446 | * caller, it cannot be modified any way since | |
447 | * it will be resolved. | |
448 | */ | |
449 | bt_ctf_field_type_common_freeze(stream_event_ctx_type_copy); | |
450 | } | |
451 | ||
452 | skip_stream_event_ctx_type_copy: | |
453 | /* Put original references and move copies */ | |
e1e02a22 PP |
454 | BT_CTF_OBJECT_MOVE_REF(packet_context_type, packet_context_type_copy); |
455 | BT_CTF_OBJECT_MOVE_REF(event_header_type, event_header_type_copy); | |
456 | BT_CTF_OBJECT_MOVE_REF(stream_event_ctx_type, stream_event_ctx_type_copy); | |
16ca5ff0 PP |
457 | |
458 | /* Validate stream class field types */ | |
459 | valid_ret = validate_stream_class_types(environment, | |
460 | packet_header_type, packet_context_type, | |
461 | event_header_type, stream_event_ctx_type); | |
462 | if (valid_ret == 0) { | |
463 | /* Stream class is valid */ | |
464 | output->valid_flags |= BT_CTF_VALIDATION_FLAG_STREAM; | |
465 | } | |
466 | ||
467 | goto sc_validation_done; | |
468 | ||
469 | sc_validation_error: | |
e1e02a22 PP |
470 | BT_CTF_OBJECT_PUT_REF_AND_RESET(packet_context_type_copy); |
471 | BT_CTF_OBJECT_PUT_REF_AND_RESET(event_header_type_copy); | |
472 | BT_CTF_OBJECT_PUT_REF_AND_RESET(stream_event_ctx_type_copy); | |
16ca5ff0 PP |
473 | ret = -1; |
474 | goto error; | |
475 | } | |
476 | ||
477 | sc_validation_done: | |
478 | /* Validate event class */ | |
479 | if ((validate_flags & BT_CTF_VALIDATION_FLAG_EVENT) && | |
480 | !event_class_valid) { | |
481 | struct bt_ctf_field_type_common *event_context_type_copy = NULL; | |
482 | struct bt_ctf_field_type_common *event_payload_type_copy = NULL; | |
483 | ||
484 | if (event_context_type) { | |
485 | contains_seq_var = | |
486 | field_type_contains_sequence_or_variant_ft( | |
487 | event_context_type); | |
488 | if (contains_seq_var < 0) { | |
489 | ret = contains_seq_var; | |
490 | goto error; | |
491 | } else if (!contains_seq_var) { | |
492 | /* No copy is needed */ | |
493 | event_context_type_copy = event_context_type; | |
e1e02a22 | 494 | bt_ctf_object_get_ref(event_context_type_copy); |
16ca5ff0 PP |
495 | goto skip_event_context_type_copy; |
496 | } | |
497 | ||
ef267d12 | 498 | BT_LOGT_STR("Copying event context field type because it contains at least one sequence or variant field type."); |
16ca5ff0 PP |
499 | event_context_type_copy = |
500 | copy_field_type_func(event_context_type); | |
501 | if (!event_context_type_copy) { | |
502 | BT_LOGE_STR("Cannot copy event context field type."); | |
503 | goto ec_validation_error; | |
504 | } | |
505 | ||
506 | /* | |
507 | * Freeze this copy: if it's returned to the | |
508 | * caller, it cannot be modified any way since | |
509 | * it will be resolved. | |
510 | */ | |
511 | bt_ctf_field_type_common_freeze(event_context_type_copy); | |
512 | } | |
513 | ||
514 | skip_event_context_type_copy: | |
515 | if (event_payload_type) { | |
516 | contains_seq_var = | |
517 | field_type_contains_sequence_or_variant_ft( | |
518 | event_payload_type); | |
519 | if (contains_seq_var < 0) { | |
520 | ret = contains_seq_var; | |
521 | goto error; | |
522 | } else if (!contains_seq_var) { | |
523 | /* No copy is needed */ | |
524 | event_payload_type_copy = event_payload_type; | |
e1e02a22 | 525 | bt_ctf_object_get_ref(event_payload_type_copy); |
16ca5ff0 PP |
526 | goto skip_event_payload_type_copy; |
527 | } | |
528 | ||
ef267d12 | 529 | BT_LOGT_STR("Copying event payload field type because it contains at least one sequence or variant field type."); |
16ca5ff0 PP |
530 | event_payload_type_copy = |
531 | copy_field_type_func(event_payload_type); | |
532 | if (!event_payload_type_copy) { | |
533 | BT_LOGE_STR("Cannot copy event payload field type."); | |
534 | goto ec_validation_error; | |
535 | } | |
536 | ||
537 | /* | |
538 | * Freeze this copy: if it's returned to the | |
539 | * caller, it cannot be modified any way since | |
540 | * it will be resolved. | |
541 | */ | |
542 | bt_ctf_field_type_common_freeze(event_payload_type_copy); | |
543 | } | |
544 | ||
545 | skip_event_payload_type_copy: | |
546 | /* Put original references and move copies */ | |
e1e02a22 PP |
547 | BT_CTF_OBJECT_MOVE_REF(event_context_type, event_context_type_copy); |
548 | BT_CTF_OBJECT_MOVE_REF(event_payload_type, event_payload_type_copy); | |
16ca5ff0 PP |
549 | |
550 | /* Validate event class field types */ | |
551 | valid_ret = validate_event_class_types(environment, | |
552 | packet_header_type, packet_context_type, | |
553 | event_header_type, stream_event_ctx_type, | |
554 | event_context_type, event_payload_type); | |
555 | if (valid_ret == 0) { | |
556 | /* Event class is valid */ | |
557 | output->valid_flags |= BT_CTF_VALIDATION_FLAG_EVENT; | |
558 | } | |
559 | ||
560 | goto ec_validation_done; | |
561 | ||
562 | ec_validation_error: | |
e1e02a22 PP |
563 | BT_CTF_OBJECT_PUT_REF_AND_RESET(event_context_type_copy); |
564 | BT_CTF_OBJECT_PUT_REF_AND_RESET(event_payload_type_copy); | |
16ca5ff0 PP |
565 | ret = -1; |
566 | goto error; | |
567 | } | |
568 | ||
569 | ec_validation_done: | |
570 | /* | |
571 | * Validation is complete. Move the field types that were used | |
572 | * to validate (and that were possibly altered by the validation | |
573 | * process) to the output values. | |
574 | */ | |
e1e02a22 PP |
575 | BT_CTF_OBJECT_MOVE_REF(output->packet_header_type, packet_header_type); |
576 | BT_CTF_OBJECT_MOVE_REF(output->packet_context_type, packet_context_type); | |
577 | BT_CTF_OBJECT_MOVE_REF(output->event_header_type, event_header_type); | |
578 | BT_CTF_OBJECT_MOVE_REF(output->stream_event_ctx_type, stream_event_ctx_type); | |
579 | BT_CTF_OBJECT_MOVE_REF(output->event_context_type, event_context_type); | |
580 | BT_CTF_OBJECT_MOVE_REF(output->event_payload_type, event_payload_type); | |
16ca5ff0 PP |
581 | return ret; |
582 | ||
583 | error: | |
e1e02a22 PP |
584 | BT_CTF_OBJECT_PUT_REF_AND_RESET(packet_header_type); |
585 | BT_CTF_OBJECT_PUT_REF_AND_RESET(packet_context_type); | |
586 | BT_CTF_OBJECT_PUT_REF_AND_RESET(event_header_type); | |
587 | BT_CTF_OBJECT_PUT_REF_AND_RESET(stream_event_ctx_type); | |
588 | BT_CTF_OBJECT_PUT_REF_AND_RESET(event_context_type); | |
589 | BT_CTF_OBJECT_PUT_REF_AND_RESET(event_payload_type); | |
16ca5ff0 PP |
590 | return ret; |
591 | } | |
592 | ||
593 | BT_HIDDEN | |
594 | void bt_ctf_validation_replace_types(struct bt_ctf_trace_common *trace, | |
595 | struct bt_ctf_stream_class_common *stream_class, | |
596 | struct bt_ctf_event_class_common *event_class, | |
597 | struct bt_ctf_validation_output *output, | |
598 | enum bt_ctf_validation_flag replace_flags) | |
599 | { | |
600 | if ((replace_flags & BT_CTF_VALIDATION_FLAG_TRACE) && trace) { | |
601 | bt_ctf_field_type_common_freeze(trace->packet_header_field_type); | |
e1e02a22 | 602 | BT_CTF_OBJECT_MOVE_REF(trace->packet_header_field_type, |
16ca5ff0 PP |
603 | output->packet_header_type); |
604 | } | |
605 | ||
606 | if ((replace_flags & BT_CTF_VALIDATION_FLAG_STREAM) && stream_class) { | |
607 | bt_ctf_field_type_common_freeze(stream_class->packet_context_field_type); | |
608 | bt_ctf_field_type_common_freeze(stream_class->event_header_field_type); | |
609 | bt_ctf_field_type_common_freeze(stream_class->event_context_field_type); | |
e1e02a22 | 610 | BT_CTF_OBJECT_MOVE_REF(stream_class->packet_context_field_type, |
16ca5ff0 | 611 | output->packet_context_type); |
e1e02a22 | 612 | BT_CTF_OBJECT_MOVE_REF(stream_class->event_header_field_type, |
16ca5ff0 | 613 | output->event_header_type); |
e1e02a22 | 614 | BT_CTF_OBJECT_MOVE_REF(stream_class->event_context_field_type, |
16ca5ff0 PP |
615 | output->stream_event_ctx_type); |
616 | } | |
617 | ||
618 | if ((replace_flags & BT_CTF_VALIDATION_FLAG_EVENT) && event_class) { | |
619 | bt_ctf_field_type_common_freeze(event_class->context_field_type); | |
620 | bt_ctf_field_type_common_freeze(event_class->payload_field_type); | |
e1e02a22 PP |
621 | BT_CTF_OBJECT_MOVE_REF(event_class->context_field_type, output->event_context_type); |
622 | BT_CTF_OBJECT_MOVE_REF(event_class->payload_field_type, output->event_payload_type); | |
16ca5ff0 PP |
623 | } |
624 | } | |
625 | ||
626 | BT_HIDDEN | |
627 | void bt_ctf_validation_output_put_types( | |
628 | struct bt_ctf_validation_output *output) | |
629 | { | |
e1e02a22 PP |
630 | BT_CTF_OBJECT_PUT_REF_AND_RESET(output->packet_header_type); |
631 | BT_CTF_OBJECT_PUT_REF_AND_RESET(output->packet_context_type); | |
632 | BT_CTF_OBJECT_PUT_REF_AND_RESET(output->event_header_type); | |
633 | BT_CTF_OBJECT_PUT_REF_AND_RESET(output->stream_event_ctx_type); | |
634 | BT_CTF_OBJECT_PUT_REF_AND_RESET(output->event_context_type); | |
635 | BT_CTF_OBJECT_PUT_REF_AND_RESET(output->event_payload_type); | |
16ca5ff0 | 636 | } |