Cleanup: remove private babeltrace.h
[babeltrace.git] / src / plugins / lttng-utils / debug-info / trace-ir-mapping.h
1 #ifndef BABELTRACE_PLUGIN_DEBUG_INFO_TRACE_IR_MAPPING_H
2 #define BABELTRACE_PLUGIN_DEBUG_INFO_TRACE_IR_MAPPING_H
3 /*
4 * Copyright 2019 Francis Deslauriers francis.deslauriers@efficios.com>
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 */
24
25 #include <glib.h>
26
27 #include "common/assert.h"
28 #include "common/macros.h"
29 #include <babeltrace2/babeltrace.h>
30
31 #include "debug-info.h"
32
33 /* Used to resolve field paths for dynamic arrays and variant field classes. */
34 struct field_class_resolving_context {
35 /* Weak reference. Owned by input stream class. */
36 const bt_field_class *packet_context;
37 /* Weak reference. Owned by input stream class. */
38 const bt_field_class *event_common_context;
39 /* Weak reference. Owned by input event class. */
40 const bt_field_class *event_specific_context;
41 /* Weak reference. Owned by input event class. */
42 const bt_field_class *event_payload;
43 };
44
45 struct trace_ir_metadata_maps {
46 const bt_trace_class *input_trace_class;
47 bt_trace_class *output_trace_class;
48
49 /*
50 * Map between input stream class and its corresponding output stream
51 * class.
52 * input stream class: weak reference. Owned by an upstream
53 * component.
54 * output stream class: owned by this structure.
55 */
56 GHashTable *stream_class_map;
57
58 /*
59 * Map between input event class and its corresponding output event
60 * class.
61 * input event class: weak reference. Owned by an upstream component.
62 * output event class: owned by this structure.
63 */
64 GHashTable *event_class_map;
65
66 /*
67 * Map between input field class and its corresponding output field
68 * class.
69 * input field class: weak reference. Owned by an upstream component.
70 * output field class: owned by this structure.
71 */
72 GHashTable *field_class_map;
73
74 /*
75 * Map between input clock class and its corresponding output clock
76 * class.
77 * input clock class: weak reference. Owned by an upstream component.
78 * output clock class: owned by this structure.
79 */
80 GHashTable *clock_class_map;
81
82 struct field_class_resolving_context *fc_resolving_ctx;
83
84 uint64_t destruction_listener_id;
85 };
86
87 struct trace_ir_data_maps {
88 const bt_trace *input_trace;
89 bt_trace *output_trace;
90
91 /*
92 * Map between input stream its corresponding output stream.
93 * input stream: weak reference. Owned by an upstream component.
94 * output stream: owned by this structure.
95 */
96 GHashTable *stream_map;
97
98 /*
99 * Map between input packet its corresponding output packet.
100 * input packet: weak reference. Owned by an upstream packet component.
101 * output packet: owned by this structure.
102 */
103 GHashTable *packet_map;
104
105 uint64_t destruction_listener_id;
106 };
107
108 struct trace_ir_maps {
109 /*
110 * input trace -> trace_ir_data_maps.
111 * input trace: weak reference. Owned by an upstream component.
112 * trace_ir_data_maps: Owned by this structure.
113 */
114 GHashTable *data_maps;
115
116 /*
117 * input trace class -> trace_ir_metadata_maps.
118 * input trace class: weak reference. Owned by an upstream component.
119 * trace_ir_metadata_maps: Owned by this structure.
120 */
121 GHashTable *metadata_maps;
122
123 char *debug_info_field_class_name;
124
125 bt_self_component *self_comp;
126 };
127
128 BT_HIDDEN
129 struct trace_ir_maps *trace_ir_maps_create(bt_self_component *self_comp,
130 const char *debug_info_field_name);
131
132 BT_HIDDEN
133 void trace_ir_maps_clear(struct trace_ir_maps *maps);
134
135 BT_HIDDEN
136 void trace_ir_maps_destroy(struct trace_ir_maps *maps);
137
138 BT_HIDDEN
139 struct trace_ir_data_maps *trace_ir_data_maps_create(
140 struct trace_ir_maps *ir_maps,
141 const bt_trace *in_trace);
142
143 BT_HIDDEN
144 void trace_ir_data_maps_destroy(struct trace_ir_data_maps *d_maps);
145
146 BT_HIDDEN
147 struct trace_ir_metadata_maps *trace_ir_metadata_maps_create(
148 struct trace_ir_maps *ir_maps,
149 const bt_trace_class *in_trace_class);
150
151 BT_HIDDEN
152 void trace_ir_metadata_maps_destroy(struct trace_ir_metadata_maps *md_maps);
153
154 BT_HIDDEN
155 bt_stream *trace_ir_mapping_create_new_mapped_stream(
156 struct trace_ir_maps *ir_maps,
157 const bt_stream *in_stream);
158
159 BT_HIDDEN
160 bt_stream *trace_ir_mapping_borrow_mapped_stream(
161 struct trace_ir_maps *ir_maps,
162 const bt_stream *in_stream);
163
164 BT_HIDDEN
165 void trace_ir_mapping_remove_mapped_stream(
166 struct trace_ir_maps *ir_maps,
167 const bt_stream *in_stream);
168
169 BT_HIDDEN
170 bt_event_class *trace_ir_mapping_create_new_mapped_event_class(
171 struct trace_ir_maps *ir_maps,
172 const bt_event_class *in_event_class);
173
174 BT_HIDDEN
175 bt_event_class *trace_ir_mapping_borrow_mapped_event_class(
176 struct trace_ir_maps *ir_maps,
177 const bt_event_class *in_event_class);
178
179 BT_HIDDEN
180 bt_packet *trace_ir_mapping_create_new_mapped_packet(
181 struct trace_ir_maps *ir_maps,
182 const bt_packet *in_packet);
183
184 BT_HIDDEN
185 bt_packet *trace_ir_mapping_borrow_mapped_packet(
186 struct trace_ir_maps *ir_maps,
187 const bt_packet *in_packet);
188
189 BT_HIDDEN
190 void trace_ir_mapping_remove_mapped_packet(
191 struct trace_ir_maps *ir_maps,
192 const bt_packet *in_packet);
193
194 static inline
195 struct trace_ir_data_maps *borrow_data_maps_from_input_trace(
196 struct trace_ir_maps *ir_maps, const bt_trace *in_trace)
197 {
198 BT_ASSERT(ir_maps);
199 BT_ASSERT(in_trace);
200
201 struct trace_ir_data_maps *d_maps =
202 g_hash_table_lookup(ir_maps->data_maps, (gpointer) in_trace);
203 if (!d_maps) {
204 d_maps = trace_ir_data_maps_create(ir_maps, in_trace);
205 g_hash_table_insert(ir_maps->data_maps, (gpointer) in_trace, d_maps);
206 }
207
208 return d_maps;
209 }
210
211 static inline
212 struct trace_ir_data_maps *borrow_data_maps_from_input_stream(
213 struct trace_ir_maps *ir_maps, const bt_stream *in_stream)
214 {
215 BT_ASSERT(ir_maps);
216 BT_ASSERT(in_stream);
217
218 return borrow_data_maps_from_input_trace(ir_maps,
219 bt_stream_borrow_trace_const(in_stream));
220 }
221
222 static inline
223 struct trace_ir_data_maps *borrow_data_maps_from_input_packet(
224 struct trace_ir_maps *ir_maps, const bt_packet *in_packet)
225 {
226 BT_ASSERT(ir_maps);
227 BT_ASSERT(in_packet);
228
229 return borrow_data_maps_from_input_stream(ir_maps,
230 bt_packet_borrow_stream_const(in_packet));
231 }
232
233 static inline
234 struct trace_ir_metadata_maps *borrow_metadata_maps_from_input_trace_class(
235 struct trace_ir_maps *ir_maps,
236 const bt_trace_class *in_trace_class)
237 {
238 BT_ASSERT(ir_maps);
239 BT_ASSERT(in_trace_class);
240
241 struct trace_ir_metadata_maps *md_maps =
242 g_hash_table_lookup(ir_maps->metadata_maps,
243 (gpointer) in_trace_class);
244 if (!md_maps) {
245 md_maps = trace_ir_metadata_maps_create(ir_maps, in_trace_class);
246 g_hash_table_insert(ir_maps->metadata_maps,
247 (gpointer) in_trace_class, md_maps);
248 }
249
250 return md_maps;
251 }
252
253 static inline
254 struct trace_ir_metadata_maps *borrow_metadata_maps_from_input_stream_class(
255 struct trace_ir_maps *ir_maps,
256 const bt_stream_class *in_stream_class) {
257
258 BT_ASSERT(in_stream_class);
259
260 return borrow_metadata_maps_from_input_trace_class(ir_maps,
261 bt_stream_class_borrow_trace_class_const(in_stream_class));
262 }
263
264 static inline
265 struct trace_ir_metadata_maps *borrow_metadata_maps_from_input_event_class(
266 struct trace_ir_maps *ir_maps,
267 const bt_event_class *in_event_class) {
268
269 BT_ASSERT(in_event_class);
270
271 return borrow_metadata_maps_from_input_stream_class(ir_maps,
272 bt_event_class_borrow_stream_class_const(in_event_class));
273 }
274
275 #endif /* BABELTRACE_PLUGIN_DEBUG_INFO_TRACE_IR_MAPPING_H */
This page took 0.034323 seconds and 4 git commands to generate.