lib: remove clock class priority map, use default clock value
[babeltrace.git] / include / babeltrace / ctf-ir / event.h
CommitLineData
adc315b8
JG
1#ifndef BABELTRACE_CTF_IR_EVENT_H
2#define BABELTRACE_CTF_IR_EVENT_H
3
4/*
5 * BabelTrace - CTF IR: Event
6 *
de9dd397 7 * Copyright 2013, 2014 Jérémie Galarneau <jeremie.galarneau@efficios.com>
adc315b8
JG
8 *
9 * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com>
10 *
11 * Permission is hereby granted, free of charge, to any person obtaining a copy
12 * of this software and associated documentation files (the "Software"), to deal
13 * in the Software without restriction, including without limitation the rights
14 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 * copies of the Software, and to permit persons to whom the Software is
16 * furnished to do so, subject to the following conditions:
17 *
18 * The above copyright notice and this permission notice shall be included in
19 * all copies or substantial portions of the Software.
20 *
21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27 * SOFTWARE.
28 *
29 * The Common Trace Format (CTF) Specification is available at
30 * http://www.efficios.com/ctf
31 */
32
094ff7c0
PP
33/* For bt_get() */
34#include <babeltrace/ref.h>
35
e22b45d0
PP
36/* For bt_bool */
37#include <babeltrace/types.h>
38
2f100782
JG
39#include <stdint.h>
40#include <stddef.h>
41
adc315b8
JG
42#ifdef __cplusplus
43extern "C" {
44#endif
45
9d408fca 46struct bt_value;
50842bdc 47struct bt_clock_class;
9d408fca 48
5a1d009d
PP
49/**
50@defgroup ctfirevent CTF IR event
51@ingroup ctfir
52@brief CTF IR event.
53
6dd2bd0c
PP
54@code
55#include <babeltrace/ctf-ir/event.h>
56@endcode
57
5a1d009d
PP
58A CTF IR <strong><em>event</em></strong> is a container of event
59fields:
60
61- <strong>Stream event header</strong> field, described by the
62 <em>stream event header field type</em> of a
63 \link ctfirstreamclass CTF IR stream class\endlink.
64- <strong>Stream event context</strong> field, described by the
65 <em>stream event context field type</em> of a stream class.
66- <strong>Event context</strong> field, described by the
67 <em>event context field type</em> of a
68 \link ctfireventclass CTF IR event class\endlink.
69- <strong>Event payload</strong>, described by the
70 <em>event payload field type</em> of an event class.
71
72As a reminder, here's the structure of a CTF packet:
73
74@imgpacketstructure
75
76You can create a CTF IR event \em from a
77\link ctfireventclass CTF IR event class\endlink with
50842bdc 78bt_event_create(). The event class you use to create an event
5a1d009d
PP
79object becomes its parent.
80
81If the \link ctfirtraceclass CTF IR trace class\endlink of an event
82object (parent of its \link ctfirstreamclass CTF IR stream class\endlink,
83which is the parent of its event class) was created by a
dfeca116 84\link ctfwriter CTF writer\endlink object, then the only possible
5a1d009d
PP
85action you can do with this event object is to append it to a
86\link ctfirstream CTF IR stream\endlink with
50842bdc 87bt_stream_append_event(). Otherwise, you can create an event
5a1d009d
PP
88notification with bt_notification_event_create(). The event you pass
89to this function \em must have an attached packet object first.
90
91You can attach a \link ctfirpacket CTF IR packet object\endlink to an
50842bdc 92event object with bt_event_set_packet().
5a1d009d
PP
93
94A CTF IR event has a mapping of
95\link ctfirclockvalue CTF IR clock values\endlink. A clock value is
96an instance of a specific
97\link ctfirclockclass CTF IR clock class\endlink when the event is
98emitted. You can set an event object's clock value with
50842bdc 99bt_event_set_clock_value().
5a1d009d
PP
100
101As with any Babeltrace object, CTF IR event objects have
102<a href="https://en.wikipedia.org/wiki/Reference_counting">reference
103counts</a>. See \ref refs to learn more about the reference counting
104management of Babeltrace objects.
105
106bt_notification_event_create() \em freezes its event parameter on
107success. You cannot modify a frozen event object: it is considered
108immutable, except for \link refs reference counting\endlink.
109
110@sa ctfireventclass
111@sa ctfirpacket
112
113@file
114@brief CTF IR event type and functions.
115@sa ctfirevent
116
117@addtogroup ctfirevent
118@{
119*/
120
121/**
50842bdc 122@struct bt_event
5a1d009d
PP
123@brief A CTF IR event.
124@sa ctfirevent
125*/
50842bdc 126struct bt_event;
312c056a 127struct bt_event_header_field;
50842bdc
PP
128struct bt_clock;
129struct bt_clock_value;
130struct bt_event_class;
131struct bt_field;
132struct bt_field_type;
133struct bt_stream_class;
134struct bt_packet;
adc315b8 135
5a1d009d
PP
136/**
137@name Creation and parent access functions
138@{
139*/
140
141/**
142@brief Creates a default CTF IR event from the CTF IR event class
143 \p event_class.
144
145\p event_class \em must have a parent
146\link ctfirstreamclass CTF IR stream class\endlink.
147
148On success, the four fields of the created event object are not set. You
50842bdc
PP
149can set them with bt_event_set_header(),
150bt_event_set_stream_event_context(),
3dca2276 151bt_event_set_context(), and bt_event_set_payload().
5a1d009d 152
4cdafd51
PP
153This function tries to resolve the needed
154\link ctfirfieldtypes CTF IR field type\endlink of the dynamic field
155types that are found anywhere in the context or payload field
156types of \p event_class and in the root field types of the
157parent stream class of \p event_class. If any automatic resolving fails,
158this function fails. This means that, if any dynamic field type need
159a field type which should be found in the trace packet header root
160field type, and if the parent stream class of \p event_class was not
161added to a \link ctfirtraceclass CTF IR trace class\endlink yet
50842bdc 162with bt_trace_add_stream_class(), then this function fails.
4cdafd51 163
5a1d009d
PP
164@param[in] event_class CTF IR event class to use to create the
165 CTF IR event.
166@returns Created event object, or \c NULL on error.
167
168@prenotnull{event_class}
169@pre \p event_class has a parent stream class.
170@postsuccessrefcountret1
171*/
094ff7c0
PP
172extern struct bt_event_class *bt_event_borrow_class(struct bt_event *event);
173
5a1d009d
PP
174/**
175@brief Returns the parent CTF IR event class of the CTF IR event
176 \p event.
177
178This function returns a reference to the event class which was used to
50842bdc 179create the event object in the first place with bt_event_create().
5a1d009d
PP
180
181@param[in] event Event of which to get the parent event class.
182@returns Parent event class of \p event,
183 or \c NULL on error.
184
185@prenotnull{event}
c2f29fb9 186@postrefcountsame{event}
5a1d009d
PP
187@postsuccessrefcountretinc
188*/
094ff7c0
PP
189static inline
190struct bt_event_class *bt_event_get_class(struct bt_event *event)
191{
192 return bt_get(bt_event_borrow_class(event));
193}
194
195extern struct bt_packet *bt_event_borrow_packet(struct bt_event *event);
2f100782 196
5a1d009d
PP
197/**
198@brief Returns the CTF IR packet associated to the CTF IR event
199 \p event.
200
201This function returns a reference to the event class which was set to
50842bdc 202\p event in the first place with bt_event_set_packet().
5a1d009d
PP
203
204@param[in] event Event of which to get the associated packet.
205@returns Packet associated to \p event,
206 or \c NULL if no packet is associated to
207 \p event or on error.
208
209@prenotnull{event}
c2f29fb9 210@postrefcountsame{event}
5a1d009d
PP
211@postsuccessrefcountretinc
212
50842bdc 213@sa bt_event_set_packet(): Associates a given event to a given
5a1d009d
PP
214 packet.
215*/
094ff7c0
PP
216static inline
217struct bt_packet *bt_event_get_packet(struct bt_event *event)
218{
219 return bt_get(bt_event_borrow_packet(event));
220}
5a1d009d 221
094ff7c0
PP
222extern struct bt_stream *bt_event_borrow_stream(struct bt_event *event);
223
5a1d009d
PP
224/**
225@brief Returns the parent CTF IR stream associated to the CTF IR event
226 \p event.
227
228@param[in] event Event of which to get the parent stream.
229@returns Parent stream of \p event, or \c NULL on error.
230
231@prenotnull{event}
c2f29fb9 232@postrefcountsame{event}
5a1d009d
PP
233@postsuccessrefcountretinc
234*/
094ff7c0
PP
235static inline
236struct bt_stream *bt_event_get_stream(struct bt_event *event)
237{
238 return bt_get(bt_event_borrow_stream(event));
239}
8e5003bb 240
5a1d009d
PP
241/** @} */
242
243/**
244@name Contained fields functions
245@{
246*/
247
094ff7c0
PP
248extern struct bt_field *bt_event_borrow_header(struct bt_event *event);
249
312c056a
PP
250extern int bt_event_move_header(struct bt_event *event,
251 struct bt_event_header_field *header);
5a1d009d 252
094ff7c0
PP
253extern struct bt_field *bt_event_borrow_stream_event_context(
254 struct bt_event *event);
255
094ff7c0
PP
256extern struct bt_field *bt_event_borrow_context(struct bt_event *event);
257
094ff7c0
PP
258extern struct bt_field *bt_event_borrow_payload(struct bt_event *event);
259
5a1d009d 260/** @} */
5fd2e9fd 261
5a1d009d
PP
262/**
263@name Clock value functions
264@{
265*/
5fd2e9fd 266
e22b45d0
PP
267extern int bt_event_set_clock_value(struct bt_event *event,
268 struct bt_clock_class *clock_class, uint64_t raw_value,
269 bt_bool is_default);
270
271extern struct bt_clock_value *bt_event_borrow_default_clock_value(
272 struct bt_event *event);
094ff7c0 273
5a1d009d
PP
274/** @} */
275
276/** @} */
41ac640a 277
adc315b8
JG
278#ifdef __cplusplus
279}
280#endif
281
282#endif /* BABELTRACE_CTF_IR_EVENT_H */
This page took 0.056507 seconds and 4 git commands to generate.