| 1 | /* |
| 2 | * SPDX-License-Identifier: MIT |
| 3 | * |
| 4 | * Copyright 2016 Philippe Proulx <pproulx@efficios.com> |
| 5 | */ |
| 6 | |
| 7 | #ifndef BABELTRACE_CTF_WRITER_VALIDATION_H |
| 8 | #define BABELTRACE_CTF_WRITER_VALIDATION_H |
| 9 | |
| 10 | #include "common/macros.h" |
| 11 | |
| 12 | #include "values.h" |
| 13 | |
| 14 | struct bt_ctf_trace_common; |
| 15 | struct bt_ctf_stream_class_common; |
| 16 | struct bt_ctf_event_class_common; |
| 17 | struct bt_ctf_field_type_common; |
| 18 | |
| 19 | typedef struct bt_ctf_field_type_common *(*bt_ctf_validation_flag_copy_field_type_func)( |
| 20 | struct bt_ctf_field_type_common *); |
| 21 | |
| 22 | enum bt_ctf_validation_flag { |
| 23 | BT_CTF_VALIDATION_FLAG_TRACE = 1, |
| 24 | BT_CTF_VALIDATION_FLAG_STREAM = 2, |
| 25 | BT_CTF_VALIDATION_FLAG_EVENT = 4, |
| 26 | }; |
| 27 | |
| 28 | /* |
| 29 | * Validation output structure. |
| 30 | * |
| 31 | * This is where the results of the validation function go. The field |
| 32 | * types are the validated ones which should replace the original field |
| 33 | * types of a trace, a stream class, and an event class. |
| 34 | * |
| 35 | * `valid_flags` contains the results of the validation. |
| 36 | */ |
| 37 | struct bt_ctf_validation_output { |
| 38 | struct bt_ctf_field_type_common *packet_header_type; |
| 39 | struct bt_ctf_field_type_common *packet_context_type; |
| 40 | struct bt_ctf_field_type_common *event_header_type; |
| 41 | struct bt_ctf_field_type_common *stream_event_ctx_type; |
| 42 | struct bt_ctf_field_type_common *event_context_type; |
| 43 | struct bt_ctf_field_type_common *event_payload_type; |
| 44 | enum bt_ctf_validation_flag valid_flags; |
| 45 | }; |
| 46 | |
| 47 | /* |
| 48 | * This function resolves and validates the field types of an event |
| 49 | * class, a stream class, and a trace. Copies are created if needed |
| 50 | * and the resulting field types to use are placed in the `output` |
| 51 | * validation structure, which also contains the results of the |
| 52 | * validation. Copies can replace the original field types of a trace, |
| 53 | * a stream class, and an event class using |
| 54 | * bt_ctf_validation_replace_types(). |
| 55 | * |
| 56 | * The current known validity of the field types of the trace, |
| 57 | * stream class, and event class must be indicated with the |
| 58 | * `trace_valid`, `stream_class_valid`, and `event_class_valid` |
| 59 | * parameters. If a class is valid, its field types are not copied, |
| 60 | * validated, or resolved during this call. |
| 61 | * |
| 62 | * The validation flags `validate_flags` indicate which classes should |
| 63 | * have their field types validated. |
| 64 | * |
| 65 | * All parameters are owned by the caller. |
| 66 | */ |
| 67 | int bt_ctf_validate_class_types(struct bt_ctf_private_value *environment, |
| 68 | struct bt_ctf_field_type_common *packet_header_type, |
| 69 | struct bt_ctf_field_type_common *packet_context_type, |
| 70 | struct bt_ctf_field_type_common *event_header_type, |
| 71 | struct bt_ctf_field_type_common *stream_event_ctx_type, |
| 72 | struct bt_ctf_field_type_common *event_context_type, |
| 73 | struct bt_ctf_field_type_common *event_payload_type, |
| 74 | int trace_valid, int stream_class_valid, int event_class_valid, |
| 75 | struct bt_ctf_validation_output *output, |
| 76 | enum bt_ctf_validation_flag validate_flags, |
| 77 | bt_ctf_validation_flag_copy_field_type_func copy_field_type_func); |
| 78 | |
| 79 | /* |
| 80 | * This function replaces the actual field types of a trace, a stream |
| 81 | * class, and an event class with the appropriate field types contained |
| 82 | * in a validation output structure. |
| 83 | * |
| 84 | * The replace flags `replace_flags` indicate which classes should have |
| 85 | * their field types replaced. |
| 86 | * |
| 87 | * Note that the field types that are not used in the validation output |
| 88 | * structure are still owned by it at the end of this call. |
| 89 | * bt_ctf_validation_output_put_types() should be called to clean the |
| 90 | * structure. |
| 91 | * |
| 92 | * All parameters are owned by the caller. |
| 93 | */ |
| 94 | void bt_ctf_validation_replace_types(struct bt_ctf_trace_common *trace, |
| 95 | struct bt_ctf_stream_class_common *stream_class, |
| 96 | struct bt_ctf_event_class_common *event_class, |
| 97 | struct bt_ctf_validation_output *output, |
| 98 | enum bt_ctf_validation_flag replace_flags); |
| 99 | |
| 100 | /* |
| 101 | * This function puts all the field types contained in a given |
| 102 | * validation output structure. |
| 103 | * |
| 104 | * `output` is owned by the caller and is not freed here. |
| 105 | */ |
| 106 | void bt_ctf_validation_output_put_types( |
| 107 | struct bt_ctf_validation_output *output); |
| 108 | |
| 109 | #endif /* BABELTRACE_CTF_WRITER_VALIDATION_H */ |