tap-driver.sh: flush stdout after each test result
[babeltrace.git] / include / babeltrace2 / ctf-writer / event-internal.h
CommitLineData
3dca2276
PP
1#ifndef BABELTRACE_CTF_WRITER_EVENT_INTERNAL_H
2#define BABELTRACE_CTF_WRITER_EVENT_INTERNAL_H
3
4/*
3dca2276
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
3fadfbc0 31#include <babeltrace2/assert-internal.h>
67d2ce02 32#include <babeltrace2/ctf-writer/assert-pre-internal.h>
3fadfbc0
MJ
33#include <babeltrace2/babeltrace-internal.h>
34#include <babeltrace2/ctf-writer/event-class-internal.h>
35#include <babeltrace2/ctf-writer/event-internal.h>
36#include <babeltrace2/ctf-writer/field-types.h>
37#include <babeltrace2/ctf-writer/field-wrapper-internal.h>
38#include <babeltrace2/ctf-writer/fields-internal.h>
39#include <babeltrace2/ctf-writer/fields.h>
40#include <babeltrace2/ctf-writer/stream-class.h>
41#include <babeltrace2/ctf-writer/stream-internal.h>
42#include <babeltrace2/ctf-writer/stream.h>
43#include <babeltrace2/ctf-writer/validation-internal.h>
44#include <babeltrace2/ctf-writer/object-internal.h>
45#include <babeltrace2/ctf-writer/values-internal.h>
46#include <babeltrace2/ctfser-internal.h>
3dca2276
PP
47
48struct bt_ctf_stream_class;
49struct bt_ctf_stream_pos;
50struct metadata_context;
51
16ca5ff0 52struct bt_ctf_event_common {
e1e02a22 53 struct bt_ctf_object base;
16ca5ff0
PP
54 struct bt_ctf_event_class_common *class;
55 struct bt_ctf_field_wrapper *header_field;
56 struct bt_ctf_field_common *stream_event_context_field;
57 struct bt_ctf_field_common *context_field;
58 struct bt_ctf_field_common *payload_field;
59 int frozen;
60};
61
62BT_HIDDEN
63int _bt_ctf_event_common_validate(struct bt_ctf_event_common *event);
64
65BT_HIDDEN
66void _bt_ctf_event_common_set_is_frozen(struct bt_ctf_event_common *event,
67 bool is_frozen);
68
69#ifdef BT_DEV_MODE
70# define bt_ctf_event_common_validate _bt_ctf_event_common_validate
71# define bt_ctf_event_common_set_is_frozen _bt_ctf_event_common_set_is_frozen
72#else
73# define bt_ctf_event_common_validate(_event) 0
74# define bt_ctf_event_common_set_is_frozen(_event, _is_frozen)
75#endif
76
67d2ce02
MJ
77#define BT_CTF_ASSERT_PRE_EVENT_COMMON_HOT(_event, _name) \
78 BT_CTF_ASSERT_PRE_HOT((_event), (_name), ": event-addr=%p", (_event))
16ca5ff0
PP
79
80static inline
81struct bt_ctf_event_class_common *bt_ctf_event_common_borrow_class(
82 struct bt_ctf_event_common *event)
83{
84 BT_ASSERT(event);
85 return event->class;
86}
87
88typedef void *(*create_field_func)(void *);
89typedef void (*release_field_func)(void *);
90typedef void *(*create_header_field_func)(void *, void *);
91typedef void (*release_header_field_func)(void *, void *);
92
93BT_HIDDEN
94int bt_ctf_event_common_initialize(struct bt_ctf_event_common *event,
95 struct bt_ctf_event_class_common *event_class,
96 struct bt_ctf_clock_class *init_expected_clock_class,
e1e02a22 97 bool is_shared_with_parent, bt_ctf_object_release_func release_func,
16ca5ff0
PP
98 bt_ctf_validation_flag_copy_field_type_func field_type_copy_func,
99 bool must_be_in_trace,
100 int (*map_clock_classes_func)(struct bt_ctf_stream_class_common *stream_class,
101 struct bt_ctf_field_type_common *packet_context_field_type,
102 struct bt_ctf_field_type_common *event_header_field_type),
103 create_field_func create_field_func,
104 release_field_func release_field_func,
105 create_header_field_func create_header_field_func,
106 release_header_field_func release_header_field_func);
107
108static inline
109struct bt_ctf_field_common *bt_ctf_event_common_borrow_payload(
110 struct bt_ctf_event_common *event)
111{
112 struct bt_ctf_field_common *payload = NULL;
113
67d2ce02 114 BT_CTF_ASSERT_PRE_NON_NULL(event, "Event");
16ca5ff0
PP
115
116 if (!event->payload_field) {
117 BT_LOGV("Event has no current payload field: addr=%p, "
118 "event-class-name=\"%s\", event-class-id=%" PRId64,
119 event, bt_ctf_event_class_common_get_name(event->class),
120 bt_ctf_event_class_common_get_id(event->class));
121 goto end;
122 }
123
124 payload = event->payload_field;
125
126end:
127 return payload;
128}
129
130static inline
131struct bt_ctf_field_common *bt_ctf_event_common_borrow_header(
132 struct bt_ctf_event_common *event)
133{
134 struct bt_ctf_field_common *header = NULL;
135
67d2ce02 136 BT_CTF_ASSERT_PRE_NON_NULL(event, "Event");
16ca5ff0
PP
137
138 if (!event->header_field) {
139 BT_LOGV("Event has no current header field: addr=%p, "
140 "event-class-name=\"%s\", event-class-id=%" PRId64,
141 event, bt_ctf_event_class_common_get_name(event->class),
142 bt_ctf_event_class_common_get_id(event->class));
143 goto end;
144 }
145
146 header = event->header_field->field;
147
148end:
149 return header;
150}
151
152static inline
153struct bt_ctf_field_common *bt_ctf_event_common_borrow_context(
154 struct bt_ctf_event_common *event)
155{
156 struct bt_ctf_field_common *context = NULL;
157
67d2ce02 158 BT_CTF_ASSERT_PRE_NON_NULL(event, "Event");
16ca5ff0
PP
159
160 if (!event->context_field) {
161 BT_LOGV("Event has no current context field: addr=%p, "
162 "event-class-name=\"%s\", event-class-id=%" PRId64,
163 event, bt_ctf_event_class_common_get_name(event->class),
164 bt_ctf_event_class_common_get_id(event->class));
165 goto end;
166 }
167
168 context = event->context_field;
169
170end:
171 return context;
172}
173
174static inline
175struct bt_ctf_field_common *bt_ctf_event_common_borrow_stream_event_context(
176 struct bt_ctf_event_common *event)
177{
178 struct bt_ctf_field_common *stream_event_context = NULL;
179
67d2ce02 180 BT_CTF_ASSERT_PRE_NON_NULL(event, "Event");
16ca5ff0
PP
181
182 if (!event->stream_event_context_field) {
183 BT_LOGV("Event has no current stream event context field: addr=%p, "
184 "event-class-name=\"%s\", event-class-id=%" PRId64,
185 event, bt_ctf_event_class_common_get_name(event->class),
186 bt_ctf_event_class_common_get_id(event->class));
187 goto end;
188 }
189
190 stream_event_context = event->stream_event_context_field;
191
192end:
193 return stream_event_context;
194}
195
196static inline
e1e02a22 197void bt_ctf_event_common_finalize(struct bt_ctf_object *obj,
16ca5ff0
PP
198 void (*field_release_func)(void *),
199 void (*header_field_release_func)(void *, struct bt_ctf_event_common *))
200{
201 struct bt_ctf_event_common *event = (void *) obj;
202
203 BT_LOGD("Destroying event: addr=%p, "
204 "event-class-name=\"%s\", event-class-id=%" PRId64,
205 event,
206 event->class ? bt_ctf_event_class_common_get_name(event->class) : NULL,
207 event->class ? bt_ctf_event_class_common_get_id(event->class) : INT64_C(-1));
208
209 if (event->header_field) {
210 BT_LOGD_STR("Releasing event's header field.");
211 header_field_release_func(event->header_field, event);
212 }
213
214 if (event->stream_event_context_field) {
215 BT_LOGD_STR("Releasing event's stream event context field.");
216 field_release_func(event->stream_event_context_field);
217 }
218
219 if (event->context_field) {
220 BT_LOGD_STR("Releasing event's context field.");
221 field_release_func(event->context_field);
222 }
223
224 if (event->payload_field) {
225 BT_LOGD_STR("Releasing event's payload field.");
226 field_release_func(event->payload_field);
227 }
228
229 /*
230 * Leave this after calling header_field_release_func() because
231 * this function receives the event object and could need its
232 * class to perform some cleanup.
233 */
234 if (!event->base.parent) {
235 /*
236 * Event was keeping a reference to its class since it shared no
237 * common ancestor with it to guarantee they would both have the
238 * same lifetime.
239 */
e1e02a22 240 bt_ctf_object_put_ref(event->class);
16ca5ff0
PP
241 }
242}
243
3dca2276 244struct bt_ctf_event {
16ca5ff0 245 struct bt_ctf_event_common common;
3dca2276
PP
246};
247
248struct bt_ctf_event_class {
16ca5ff0 249 struct bt_ctf_event_class_common common;
3dca2276
PP
250};
251
252BT_HIDDEN
253int bt_ctf_event_class_serialize(struct bt_ctf_event_class *event_class,
254 struct metadata_context *context);
255
256BT_HIDDEN
257int bt_ctf_event_serialize(struct bt_ctf_event *event,
013f35c6 258 struct bt_ctfser *pos,
3dca2276
PP
259 enum bt_ctf_byte_order native_byte_order);
260
261static inline
262struct bt_ctf_stream_class *bt_ctf_event_class_borrow_stream_class(
263 struct bt_ctf_event_class *event_class)
264{
16ca5ff0
PP
265 return BT_CTF_FROM_COMMON(bt_ctf_event_class_common_borrow_stream_class(
266 BT_CTF_TO_COMMON(event_class)));
3dca2276
PP
267}
268
269#endif /* BABELTRACE_CTF_WRITER_EVENT_INTERNAL_H */
This page took 0.046557 seconds and 4 git commands to generate.