Commit | Line | Data |
---|---|---|
8deee039 PP |
1 | #ifndef BABELTRACE_CTF_WRITER_EVENT_INTERNAL_H |
2 | #define BABELTRACE_CTF_WRITER_EVENT_INTERNAL_H | |
3 | ||
4 | /* | |
8deee039 PP |
5 | * Copyright 2013, 2014 Jérémie Galarneau <jeremie.galarneau@efficios.com> |
6 | * | |
7 | * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com> | |
8 | * | |
9 | * Permission is hereby granted, free of charge, to any person obtaining a copy | |
10 | * of this software and associated documentation files (the "Software"), to deal | |
11 | * in the Software without restriction, including without limitation the rights | |
12 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
13 | * copies of the Software, and to permit persons to whom the Software is | |
14 | * furnished to do so, subject to the following conditions: | |
15 | * | |
16 | * The above copyright notice and this permission notice shall be included in | |
17 | * all copies or substantial portions of the Software. | |
18 | * | |
19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
20 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
21 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
22 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
23 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
24 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
25 | * SOFTWARE. | |
26 | * | |
27 | * The Common Trace Format (CTF) Specification is available at | |
28 | * http://www.efficios.com/ctf | |
29 | */ | |
30 | ||
086dc475 PP |
31 | #include <babeltrace/assert-internal.h> |
32 | #include <babeltrace/assert-pre-internal.h> | |
8deee039 | 33 | #include <babeltrace/babeltrace-internal.h> |
086dc475 PP |
34 | #include <babeltrace/ctf-writer/event-class-internal.h> |
35 | #include <babeltrace/ctf-writer/event-internal.h> | |
8deee039 | 36 | #include <babeltrace/ctf-writer/field-types.h> |
086dc475 PP |
37 | #include <babeltrace/ctf-writer/field-wrapper-internal.h> |
38 | #include <babeltrace/ctf-writer/fields-internal.h> | |
39 | #include <babeltrace/ctf-writer/fields.h> | |
40 | #include <babeltrace/ctf-writer/stream-class.h> | |
41 | #include <babeltrace/ctf-writer/stream-internal.h> | |
42 | #include <babeltrace/ctf-writer/stream.h> | |
43 | #include <babeltrace/ctf-writer/validation-internal.h> | |
c2606e2f | 44 | #include <babeltrace/ctf-writer/object-internal.h> |
086dc475 | 45 | #include <babeltrace/values.h> |
8deee039 PP |
46 | |
47 | struct bt_ctf_stream_class; | |
48 | struct bt_ctf_stream_pos; | |
49 | struct metadata_context; | |
50 | ||
086dc475 | 51 | struct bt_ctf_event_common { |
c2606e2f | 52 | struct bt_ctf_object base; |
086dc475 PP |
53 | struct bt_ctf_event_class_common *class; |
54 | struct bt_ctf_field_wrapper *header_field; | |
55 | struct bt_ctf_field_common *stream_event_context_field; | |
56 | struct bt_ctf_field_common *context_field; | |
57 | struct bt_ctf_field_common *payload_field; | |
58 | int frozen; | |
59 | }; | |
60 | ||
61 | BT_HIDDEN | |
62 | int _bt_ctf_event_common_validate(struct bt_ctf_event_common *event); | |
63 | ||
64 | BT_HIDDEN | |
65 | void _bt_ctf_event_common_set_is_frozen(struct bt_ctf_event_common *event, | |
66 | bool is_frozen); | |
67 | ||
68 | #ifdef BT_DEV_MODE | |
69 | # define bt_ctf_event_common_validate _bt_ctf_event_common_validate | |
70 | # define bt_ctf_event_common_set_is_frozen _bt_ctf_event_common_set_is_frozen | |
71 | #else | |
72 | # define bt_ctf_event_common_validate(_event) 0 | |
73 | # define bt_ctf_event_common_set_is_frozen(_event, _is_frozen) | |
74 | #endif | |
75 | ||
76 | #define BT_ASSERT_PRE_EVENT_COMMON_HOT(_event, _name) \ | |
77 | BT_ASSERT_PRE_HOT((_event), (_name), ": event-addr=%p", (_event)) | |
78 | ||
79 | static inline | |
80 | struct bt_ctf_event_class_common *bt_ctf_event_common_borrow_class( | |
81 | struct bt_ctf_event_common *event) | |
82 | { | |
83 | BT_ASSERT(event); | |
84 | return event->class; | |
85 | } | |
86 | ||
87 | typedef void *(*create_field_func)(void *); | |
88 | typedef void (*release_field_func)(void *); | |
89 | typedef void *(*create_header_field_func)(void *, void *); | |
90 | typedef void (*release_header_field_func)(void *, void *); | |
91 | ||
92 | BT_HIDDEN | |
93 | int bt_ctf_event_common_initialize(struct bt_ctf_event_common *event, | |
94 | struct bt_ctf_event_class_common *event_class, | |
95 | struct bt_ctf_clock_class *init_expected_clock_class, | |
c2606e2f | 96 | bool is_shared_with_parent, bt_ctf_object_release_func release_func, |
086dc475 PP |
97 | bt_ctf_validation_flag_copy_field_type_func field_type_copy_func, |
98 | bool must_be_in_trace, | |
99 | int (*map_clock_classes_func)(struct bt_ctf_stream_class_common *stream_class, | |
100 | struct bt_ctf_field_type_common *packet_context_field_type, | |
101 | struct bt_ctf_field_type_common *event_header_field_type), | |
102 | create_field_func create_field_func, | |
103 | release_field_func release_field_func, | |
104 | create_header_field_func create_header_field_func, | |
105 | release_header_field_func release_header_field_func); | |
106 | ||
107 | static inline | |
108 | struct bt_ctf_field_common *bt_ctf_event_common_borrow_payload( | |
109 | struct bt_ctf_event_common *event) | |
110 | { | |
111 | struct bt_ctf_field_common *payload = NULL; | |
112 | ||
113 | BT_ASSERT_PRE_NON_NULL(event, "Event"); | |
114 | ||
115 | if (!event->payload_field) { | |
116 | BT_LOGV("Event has no current payload field: addr=%p, " | |
117 | "event-class-name=\"%s\", event-class-id=%" PRId64, | |
118 | event, bt_ctf_event_class_common_get_name(event->class), | |
119 | bt_ctf_event_class_common_get_id(event->class)); | |
120 | goto end; | |
121 | } | |
122 | ||
123 | payload = event->payload_field; | |
124 | ||
125 | end: | |
126 | return payload; | |
127 | } | |
128 | ||
129 | static inline | |
130 | struct bt_ctf_field_common *bt_ctf_event_common_borrow_header( | |
131 | struct bt_ctf_event_common *event) | |
132 | { | |
133 | struct bt_ctf_field_common *header = NULL; | |
134 | ||
135 | BT_ASSERT_PRE_NON_NULL(event, "Event"); | |
136 | ||
137 | if (!event->header_field) { | |
138 | BT_LOGV("Event has no current header field: addr=%p, " | |
139 | "event-class-name=\"%s\", event-class-id=%" PRId64, | |
140 | event, bt_ctf_event_class_common_get_name(event->class), | |
141 | bt_ctf_event_class_common_get_id(event->class)); | |
142 | goto end; | |
143 | } | |
144 | ||
145 | header = event->header_field->field; | |
146 | ||
147 | end: | |
148 | return header; | |
149 | } | |
150 | ||
151 | static inline | |
152 | struct bt_ctf_field_common *bt_ctf_event_common_borrow_context( | |
153 | struct bt_ctf_event_common *event) | |
154 | { | |
155 | struct bt_ctf_field_common *context = NULL; | |
156 | ||
157 | BT_ASSERT_PRE_NON_NULL(event, "Event"); | |
158 | ||
159 | if (!event->context_field) { | |
160 | BT_LOGV("Event has no current context field: addr=%p, " | |
161 | "event-class-name=\"%s\", event-class-id=%" PRId64, | |
162 | event, bt_ctf_event_class_common_get_name(event->class), | |
163 | bt_ctf_event_class_common_get_id(event->class)); | |
164 | goto end; | |
165 | } | |
166 | ||
167 | context = event->context_field; | |
168 | ||
169 | end: | |
170 | return context; | |
171 | } | |
172 | ||
173 | static inline | |
174 | struct bt_ctf_field_common *bt_ctf_event_common_borrow_stream_event_context( | |
175 | struct bt_ctf_event_common *event) | |
176 | { | |
177 | struct bt_ctf_field_common *stream_event_context = NULL; | |
178 | ||
179 | BT_ASSERT_PRE_NON_NULL(event, "Event"); | |
180 | ||
181 | if (!event->stream_event_context_field) { | |
182 | BT_LOGV("Event has no current stream event context field: addr=%p, " | |
183 | "event-class-name=\"%s\", event-class-id=%" PRId64, | |
184 | event, bt_ctf_event_class_common_get_name(event->class), | |
185 | bt_ctf_event_class_common_get_id(event->class)); | |
186 | goto end; | |
187 | } | |
188 | ||
189 | stream_event_context = event->stream_event_context_field; | |
190 | ||
191 | end: | |
192 | return stream_event_context; | |
193 | } | |
194 | ||
195 | static inline | |
c2606e2f | 196 | void bt_ctf_event_common_finalize(struct bt_ctf_object *obj, |
086dc475 PP |
197 | void (*field_release_func)(void *), |
198 | void (*header_field_release_func)(void *, struct bt_ctf_event_common *)) | |
199 | { | |
200 | struct bt_ctf_event_common *event = (void *) obj; | |
201 | ||
202 | BT_LOGD("Destroying event: addr=%p, " | |
203 | "event-class-name=\"%s\", event-class-id=%" PRId64, | |
204 | event, | |
205 | event->class ? bt_ctf_event_class_common_get_name(event->class) : NULL, | |
206 | event->class ? bt_ctf_event_class_common_get_id(event->class) : INT64_C(-1)); | |
207 | ||
208 | if (event->header_field) { | |
209 | BT_LOGD_STR("Releasing event's header field."); | |
210 | header_field_release_func(event->header_field, event); | |
211 | } | |
212 | ||
213 | if (event->stream_event_context_field) { | |
214 | BT_LOGD_STR("Releasing event's stream event context field."); | |
215 | field_release_func(event->stream_event_context_field); | |
216 | } | |
217 | ||
218 | if (event->context_field) { | |
219 | BT_LOGD_STR("Releasing event's context field."); | |
220 | field_release_func(event->context_field); | |
221 | } | |
222 | ||
223 | if (event->payload_field) { | |
224 | BT_LOGD_STR("Releasing event's payload field."); | |
225 | field_release_func(event->payload_field); | |
226 | } | |
227 | ||
228 | /* | |
229 | * Leave this after calling header_field_release_func() because | |
230 | * this function receives the event object and could need its | |
231 | * class to perform some cleanup. | |
232 | */ | |
233 | if (!event->base.parent) { | |
234 | /* | |
235 | * Event was keeping a reference to its class since it shared no | |
236 | * common ancestor with it to guarantee they would both have the | |
237 | * same lifetime. | |
238 | */ | |
c2606e2f | 239 | bt_ctf_object_put_ref(event->class); |
086dc475 PP |
240 | } |
241 | } | |
242 | ||
8deee039 | 243 | struct bt_ctf_event { |
086dc475 | 244 | struct bt_ctf_event_common common; |
8deee039 PP |
245 | }; |
246 | ||
247 | struct bt_ctf_event_class { | |
086dc475 | 248 | struct bt_ctf_event_class_common common; |
8deee039 PP |
249 | }; |
250 | ||
251 | BT_HIDDEN | |
252 | int bt_ctf_event_class_serialize(struct bt_ctf_event_class *event_class, | |
253 | struct metadata_context *context); | |
254 | ||
255 | BT_HIDDEN | |
256 | int bt_ctf_event_serialize(struct bt_ctf_event *event, | |
257 | struct bt_ctf_stream_pos *pos, | |
258 | enum bt_ctf_byte_order native_byte_order); | |
259 | ||
260 | static inline | |
261 | struct bt_ctf_stream_class *bt_ctf_event_class_borrow_stream_class( | |
262 | struct bt_ctf_event_class *event_class) | |
263 | { | |
086dc475 PP |
264 | return BT_CTF_FROM_COMMON(bt_ctf_event_class_common_borrow_stream_class( |
265 | BT_CTF_TO_COMMON(event_class))); | |
8deee039 PP |
266 | } |
267 | ||
268 | #endif /* BABELTRACE_CTF_WRITER_EVENT_INTERNAL_H */ |