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