Commit | Line | Data |
---|---|---|
086dc475 PP |
1 | #ifndef BABELTRACE_CTF_WRITER_VALIDATION_INTERNAL_H |
2 | #define BABELTRACE_CTF_WRITER_VALIDATION_INTERNAL_H | |
3 | ||
4 | /* | |
086dc475 PP |
5 | * Copyright 2016 Philippe Proulx <pproulx@efficios.com> |
6 | * | |
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy | |
8 | * of this software and associated documentation files (the "Software"), to deal | |
9 | * in the Software without restriction, including without limitation the rights | |
10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
11 | * copies of the Software, and to permit persons to whom the Software is | |
12 | * furnished to do so, subject to the following conditions: | |
13 | * | |
14 | * The above copyright notice and this permission notice shall be included in | |
15 | * all copies or substantial portions of the Software. | |
16 | * | |
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
23 | * SOFTWARE. | |
24 | */ | |
25 | ||
85e7137b | 26 | #include "common/macros.h" |
57952005 MJ |
27 | |
28 | #include "values.h" | |
086dc475 PP |
29 | |
30 | struct bt_ctf_trace_common; | |
31 | struct bt_ctf_stream_class_common; | |
32 | struct bt_ctf_event_class_common; | |
33 | struct bt_ctf_field_type_common; | |
34 | ||
35 | typedef struct bt_ctf_field_type_common *(*bt_ctf_validation_flag_copy_field_type_func)( | |
36 | struct bt_ctf_field_type_common *); | |
37 | ||
38 | enum bt_ctf_validation_flag { | |
39 | BT_CTF_VALIDATION_FLAG_TRACE = 1, | |
40 | BT_CTF_VALIDATION_FLAG_STREAM = 2, | |
41 | BT_CTF_VALIDATION_FLAG_EVENT = 4, | |
42 | }; | |
43 | ||
44 | /* | |
45 | * Validation output structure. | |
46 | * | |
47 | * This is where the results of the validation function go. The field | |
48 | * types are the validated ones which should replace the original field | |
49 | * types of a trace, a stream class, and an event class. | |
50 | * | |
51 | * `valid_flags` contains the results of the validation. | |
52 | */ | |
53 | struct bt_ctf_validation_output { | |
54 | struct bt_ctf_field_type_common *packet_header_type; | |
55 | struct bt_ctf_field_type_common *packet_context_type; | |
56 | struct bt_ctf_field_type_common *event_header_type; | |
57 | struct bt_ctf_field_type_common *stream_event_ctx_type; | |
58 | struct bt_ctf_field_type_common *event_context_type; | |
59 | struct bt_ctf_field_type_common *event_payload_type; | |
60 | enum bt_ctf_validation_flag valid_flags; | |
61 | }; | |
62 | ||
63 | /* | |
64 | * This function resolves and validates the field types of an event | |
65 | * class, a stream class, and a trace. Copies are created if needed | |
66 | * and the resulting field types to use are placed in the `output` | |
67 | * validation structure, which also contains the results of the | |
68 | * validation. Copies can replace the original field types of a trace, | |
69 | * a stream class, and an event class using | |
70 | * bt_ctf_validation_replace_types(). | |
71 | * | |
72 | * The current known validity of the field types of the trace, | |
73 | * stream class, and event class must be indicated with the | |
74 | * `trace_valid`, `stream_class_valid`, and `event_class_valid` | |
75 | * parameters. If a class is valid, its field types are not copied, | |
76 | * validated, or resolved during this call. | |
77 | * | |
78 | * The validation flags `validate_flags` indicate which classes should | |
79 | * have their field types validated. | |
80 | * | |
81 | * All parameters are owned by the caller. | |
82 | */ | |
83 | BT_HIDDEN | |
c2606e2f | 84 | int bt_ctf_validate_class_types(struct bt_ctf_private_value *environment, |
086dc475 PP |
85 | struct bt_ctf_field_type_common *packet_header_type, |
86 | struct bt_ctf_field_type_common *packet_context_type, | |
87 | struct bt_ctf_field_type_common *event_header_type, | |
88 | struct bt_ctf_field_type_common *stream_event_ctx_type, | |
89 | struct bt_ctf_field_type_common *event_context_type, | |
90 | struct bt_ctf_field_type_common *event_payload_type, | |
91 | int trace_valid, int stream_class_valid, int event_class_valid, | |
92 | struct bt_ctf_validation_output *output, | |
93 | enum bt_ctf_validation_flag validate_flags, | |
94 | bt_ctf_validation_flag_copy_field_type_func copy_field_type_func); | |
95 | ||
96 | /* | |
97 | * This function replaces the actual field types of a trace, a stream | |
98 | * class, and an event class with the appropriate field types contained | |
99 | * in a validation output structure. | |
100 | * | |
101 | * The replace flags `replace_flags` indicate which classes should have | |
102 | * their field types replaced. | |
103 | * | |
104 | * Note that the field types that are not used in the validation output | |
105 | * structure are still owned by it at the end of this call. | |
106 | * bt_ctf_validation_output_put_types() should be called to clean the | |
107 | * structure. | |
108 | * | |
109 | * All parameters are owned by the caller. | |
110 | */ | |
111 | BT_HIDDEN | |
112 | void bt_ctf_validation_replace_types(struct bt_ctf_trace_common *trace, | |
113 | struct bt_ctf_stream_class_common *stream_class, | |
114 | struct bt_ctf_event_class_common *event_class, | |
115 | struct bt_ctf_validation_output *output, | |
116 | enum bt_ctf_validation_flag replace_flags); | |
117 | ||
118 | /* | |
119 | * This function puts all the field types contained in a given | |
120 | * validation output structure. | |
121 | * | |
122 | * `output` is owned by the caller and is not freed here. | |
123 | */ | |
124 | BT_HIDDEN | |
125 | void bt_ctf_validation_output_put_types( | |
126 | struct bt_ctf_validation_output *output); | |
127 | ||
128 | #endif /* BABELTRACE_CTF_WRITER_VALIDATION_INTERNAL_H */ |