include/babeltrace/graph: fix some include guards
[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
2f100782
JG
33#include <stdint.h>
34#include <stddef.h>
35
adc315b8
JG
36#ifdef __cplusplus
37extern "C" {
38#endif
39
9d408fca 40struct bt_value;
50842bdc 41struct bt_clock_class;
9d408fca 42
5a1d009d
PP
43/**
44@defgroup ctfirevent CTF IR event
45@ingroup ctfir
46@brief CTF IR event.
47
6dd2bd0c
PP
48@code
49#include <babeltrace/ctf-ir/event.h>
50@endcode
51
5a1d009d
PP
52A CTF IR <strong><em>event</em></strong> is a container of event
53fields:
54
55- <strong>Stream event header</strong> field, described by the
56 <em>stream event header field type</em> of a
57 \link ctfirstreamclass CTF IR stream class\endlink.
58- <strong>Stream event context</strong> field, described by the
59 <em>stream event context field type</em> of a stream class.
60- <strong>Event context</strong> field, described by the
61 <em>event context field type</em> of a
62 \link ctfireventclass CTF IR event class\endlink.
63- <strong>Event payload</strong>, described by the
64 <em>event payload field type</em> of an event class.
65
66As a reminder, here's the structure of a CTF packet:
67
68@imgpacketstructure
69
70You can create a CTF IR event \em from a
71\link ctfireventclass CTF IR event class\endlink with
50842bdc 72bt_event_create(). The event class you use to create an event
5a1d009d
PP
73object becomes its parent.
74
75If the \link ctfirtraceclass CTF IR trace class\endlink of an event
76object (parent of its \link ctfirstreamclass CTF IR stream class\endlink,
77which is the parent of its event class) was created by a
dfeca116 78\link ctfwriter CTF writer\endlink object, then the only possible
5a1d009d
PP
79action you can do with this event object is to append it to a
80\link ctfirstream CTF IR stream\endlink with
50842bdc 81bt_stream_append_event(). Otherwise, you can create an event
5a1d009d
PP
82notification with bt_notification_event_create(). The event you pass
83to this function \em must have an attached packet object first.
84
85You can attach a \link ctfirpacket CTF IR packet object\endlink to an
50842bdc 86event object with bt_event_set_packet().
5a1d009d
PP
87
88A CTF IR event has a mapping of
89\link ctfirclockvalue CTF IR clock values\endlink. A clock value is
90an instance of a specific
91\link ctfirclockclass CTF IR clock class\endlink when the event is
92emitted. You can set an event object's clock value with
50842bdc 93bt_event_set_clock_value().
5a1d009d
PP
94
95As with any Babeltrace object, CTF IR event objects have
96<a href="https://en.wikipedia.org/wiki/Reference_counting">reference
97counts</a>. See \ref refs to learn more about the reference counting
98management of Babeltrace objects.
99
100bt_notification_event_create() \em freezes its event parameter on
101success. You cannot modify a frozen event object: it is considered
102immutable, except for \link refs reference counting\endlink.
103
104@sa ctfireventclass
105@sa ctfirpacket
106
107@file
108@brief CTF IR event type and functions.
109@sa ctfirevent
110
111@addtogroup ctfirevent
112@{
113*/
114
115/**
50842bdc 116@struct bt_event
5a1d009d
PP
117@brief A CTF IR event.
118@sa ctfirevent
119*/
50842bdc
PP
120struct bt_event;
121struct bt_clock;
122struct bt_clock_value;
123struct bt_event_class;
124struct bt_field;
125struct bt_field_type;
126struct bt_stream_class;
127struct bt_packet;
adc315b8 128
5a1d009d
PP
129/**
130@name Creation and parent access functions
131@{
132*/
133
134/**
135@brief Creates a default CTF IR event from the CTF IR event class
136 \p event_class.
137
138\p event_class \em must have a parent
139\link ctfirstreamclass CTF IR stream class\endlink.
140
141On success, the four fields of the created event object are not set. You
50842bdc
PP
142can set them with bt_event_set_header(),
143bt_event_set_stream_event_context(),
3dca2276 144bt_event_set_context(), and bt_event_set_payload().
5a1d009d 145
4cdafd51
PP
146This function tries to resolve the needed
147\link ctfirfieldtypes CTF IR field type\endlink of the dynamic field
148types that are found anywhere in the context or payload field
149types of \p event_class and in the root field types of the
150parent stream class of \p event_class. If any automatic resolving fails,
151this function fails. This means that, if any dynamic field type need
152a field type which should be found in the trace packet header root
153field type, and if the parent stream class of \p event_class was not
154added to a \link ctfirtraceclass CTF IR trace class\endlink yet
50842bdc 155with bt_trace_add_stream_class(), then this function fails.
4cdafd51 156
5a1d009d
PP
157@param[in] event_class CTF IR event class to use to create the
158 CTF IR event.
159@returns Created event object, or \c NULL on error.
160
161@prenotnull{event_class}
162@pre \p event_class has a parent stream class.
163@postsuccessrefcountret1
164*/
3dca2276 165extern struct bt_event *bt_event_create(struct bt_event_class *event_class);
adc315b8 166
5a1d009d
PP
167/**
168@brief Returns the parent CTF IR event class of the CTF IR event
169 \p event.
170
171This function returns a reference to the event class which was used to
50842bdc 172create the event object in the first place with bt_event_create().
5a1d009d
PP
173
174@param[in] event Event of which to get the parent event class.
175@returns Parent event class of \p event,
176 or \c NULL on error.
177
178@prenotnull{event}
c2f29fb9 179@postrefcountsame{event}
5a1d009d
PP
180@postsuccessrefcountretinc
181*/
3dca2276 182extern struct bt_event_class *bt_event_get_class(struct bt_event *event);
2f100782 183
5a1d009d
PP
184/**
185@brief Returns the CTF IR packet associated to the CTF IR event
186 \p event.
187
188This function returns a reference to the event class which was set to
50842bdc 189\p event in the first place with bt_event_set_packet().
5a1d009d
PP
190
191@param[in] event Event of which to get the associated packet.
192@returns Packet associated to \p event,
193 or \c NULL if no packet is associated to
194 \p event or on error.
195
196@prenotnull{event}
c2f29fb9 197@postrefcountsame{event}
5a1d009d
PP
198@postsuccessrefcountretinc
199
50842bdc 200@sa bt_event_set_packet(): Associates a given event to a given
5a1d009d
PP
201 packet.
202*/
3dca2276 203extern struct bt_packet *bt_event_get_packet(struct bt_event *event);
5a1d009d
PP
204
205/**
206@brief Associates the CTF IR event \p event to the CTF IR packet
207 \p packet.
208
209The \link ctfirstreamclass CTF IR stream class\endlink of the
210parent \link ctfirstream CTF IR stream\endlink of \p packet \em must
211be the same as the parent stream class of the
212\link ctfireventclass CTF IR event class\endlink returned
50842bdc 213by bt_event_get_class() for \p event.
5a1d009d
PP
214
215You \em must call this function to create an event-packet association
216before you call bt_notification_event_create() with \p event.
217
218On success, this function also sets the parent stream object of
219\p event to the parent stream of \p packet.
220
221@param[in] event Event to which to associate \p packet.
7113dedb 222@param[in] packet Packet to associate to \p event.
5a1d009d
PP
223@returns 0 on success, or a negative value on error.
224
225@prenotnull{event}
226@prenotnull{packet}
227@prehot{event}
228@pre The parent stream class of \p packet is the same as the parent
229 stream class of \p event.
230@postsuccessrefcountretinc
231
50842bdc 232@sa bt_event_get_packet(): Returns the associated packet of a
5a1d009d
PP
233 given event object.
234*/
50842bdc
PP
235extern int bt_event_set_packet(struct bt_event *event,
236 struct bt_packet *packet);
5a1d009d
PP
237
238/**
239@brief Returns the parent CTF IR stream associated to the CTF IR event
240 \p event.
241
242@param[in] event Event of which to get the parent stream.
243@returns Parent stream of \p event, or \c NULL on error.
244
245@prenotnull{event}
c2f29fb9 246@postrefcountsame{event}
5a1d009d
PP
247@postsuccessrefcountretinc
248*/
3dca2276 249extern struct bt_stream *bt_event_get_stream(struct bt_event *event);
8e5003bb 250
5a1d009d
PP
251/** @} */
252
253/**
254@name Contained fields functions
255@{
256*/
257
258/**
259@brief Returns the stream event header field of the CTF IR event
260 \p event.
261
262@param[in] event Event of which to get the stream event header
263 field.
264@returns Stream event header field of \p event,
265 or \c NULL if the stream event header
266 field is not set or on error.
267
268@prenotnull{event}
c2f29fb9 269@postrefcountsame{event}
5a1d009d
PP
270@postsuccessrefcountretinc
271
50842bdc 272@sa bt_event_get_header(): Sets the stream event header
5a1d009d
PP
273 field of a given event.
274*/
3dca2276 275extern struct bt_field *bt_event_get_header(struct bt_event *event);
5a1d009d
PP
276
277/**
278@brief Sets the stream event header field of the CTF IR event
6b783f49
JG
279 \p event to \p header, or unsets the current stream event header field
280 from \p event.
5a1d009d 281
6b783f49 282If \p header is not \c NULL, the field type of \p header, as returned by
50842bdc
PP
283bt_field_get_type(), \em must be equivalent to the field type returned by
284bt_stream_class_get_event_header_type() for the parent stream class
5a1d009d
PP
285of \p event.
286
287@param[in] event Event of which to set the stream event header
288 field.
289@param[in] header Stream event header field.
290@returns 0 on success, or a negative value on error.
291
292@prenotnull{event}
5a1d009d 293@prehot{event}
6b783f49 294@pre <strong>\p header, if not \c NULL</strong>, has a field type equivalent to
50842bdc 295 the field type returned by bt_stream_class_get_event_header_type()
6b783f49 296 for the parent stream class of \p event.
5a1d009d 297@postrefcountsame{event}
6b783f49
JG
298@post <strong>On success, if \p header is not \c NULL</strong>,
299 the reference count of \p header is incremented.
5a1d009d 300
50842bdc 301@sa bt_event_get_header(): Returns the stream event header field
5a1d009d
PP
302 of a given event.
303*/
50842bdc
PP
304extern int bt_event_set_header(struct bt_event *event,
305 struct bt_field *header);
5a1d009d
PP
306
307/**
308@brief Returns the stream event context field of the CTF IR event
309 \p event.
310
311@param[in] event Event of which to get the stream event context
312 field.
313@returns Stream event context field of \p event,
314 or \c NULL if the stream event context
315 field is not set or on error.
316
317@prenotnull{event}
c2f29fb9 318@postrefcountsame{event}
5a1d009d
PP
319@postsuccessrefcountretinc
320
50842bdc 321@sa bt_event_set_stream_event_context(): Sets the stream event context
6b783f49 322 field of a given event.
5a1d009d 323*/
50842bdc
PP
324extern struct bt_field *bt_event_get_stream_event_context(
325 struct bt_event *event);
5a1d009d
PP
326
327/**
328@brief Sets the stream event context field of the CTF IR event
6b783f49
JG
329 \p event to \p context, or unsets the current stream event context field
330 from \p event.
5a1d009d 331
6b783f49 332If \p context is not \c NULL, the field type of \p context, as returned by
50842bdc
PP
333bt_field_get_type(), \em must be equivalent to the field type returned by
334bt_stream_class_get_event_context_type() for the parent stream class
5a1d009d
PP
335of \p event.
336
6b783f49 337@param[in] event Event of which to set the stream event context field.
5a1d009d
PP
338@param[in] context Stream event context field.
339@returns 0 on success, or a negative value on error.
340
341@prenotnull{event}
5a1d009d 342@prehot{event}
6b783f49 343@pre <strong>\p context, if not \c NULL</strong>, has a field type equivalent to
50842bdc 344 the field type returned by bt_stream_class_get_event_context_type()
6b783f49 345 for the parent stream class of \p event.
5a1d009d 346@postrefcountsame{event}
6b783f49
JG
347@post <strong>On success, if \p context is not \c NULL</strong>, the reference
348 count of \p context is incremented.
5a1d009d 349
50842bdc 350@sa bt_event_get_stream_event_context(): Returns the stream event context
6b783f49 351 field of a given event.
5a1d009d 352*/
50842bdc
PP
353extern int bt_event_set_stream_event_context(struct bt_event *event,
354 struct bt_field *context);
5a1d009d
PP
355
356/**
6b783f49 357@brief Returns the event context field of the CTF IR event \p event.
5a1d009d 358
6b783f49
JG
359@param[in] event Event of which to get the context field.
360@returns Event context field of \p event, or \c NULL if the
361 event context field is not set or on error.
5a1d009d
PP
362
363@prenotnull{event}
c2f29fb9 364@postrefcountsame{event}
5a1d009d
PP
365@postsuccessrefcountretinc
366
3dca2276 367@sa bt_event_set_context(): Sets the event context field of a given
6b783f49 368 event.
5a1d009d 369*/
3dca2276 370extern struct bt_field *bt_event_get_context(struct bt_event *event);
5a1d009d
PP
371
372/**
6b783f49
JG
373@brief Sets the event context field of the CTF IR event \p event to \p context,
374 or unsets the current event context field from \p event.
5a1d009d 375
6b783f49 376If \p context is not \c NULL, the field type of \p context, as returned by
50842bdc
PP
377bt_field_get_type(), \em must be equivalent to the field type returned by
378bt_event_class_get_context_type() for the parent class of \p event.
5a1d009d 379
6b783f49 380@param[in] event Event of which to set the context field.
5a1d009d
PP
381@param[in] context Event context field.
382@returns 0 on success, or a negative value on error.
383
384@prenotnull{event}
5a1d009d 385@prehot{event}
6b783f49 386@pre <strong>\p context, if not \c NULL</strong>, has a field type equivalent to
50842bdc 387 the field type returned by bt_event_class_get_context_type() for the
6b783f49 388 parent class of \p event.
5a1d009d 389@postrefcountsame{event}
6b783f49
JG
390@post <strong>On success, if \p context is not \c NULL</strong>, the reference
391 count of \p context is incremented.
5a1d009d 392
50842bdc 393@sa bt_event_get_context(): Returns the context field of a given event.
5a1d009d 394*/
3dca2276 395extern int bt_event_set_context(struct bt_event *event,
50842bdc 396 struct bt_field *context);
5a1d009d
PP
397
398/**
6b783f49 399@brief Returns the payload field of the CTF IR event \p event.
5a1d009d 400
6b783f49
JG
401@param[in] event Event of which to get the payload field.
402@returns Payload field of \p event, or \c NULL if the payload
403 field is not set or on error.
5a1d009d
PP
404
405@prenotnull{event}
c2f29fb9 406@postrefcountsame{event}
5a1d009d
PP
407@postsuccessrefcountretinc
408
3dca2276 409@sa bt_event_set_payload(): Sets the payload field of a given
6b783f49 410 event.
5a1d009d 411*/
3dca2276 412extern struct bt_field *bt_event_get_payload(struct bt_event *event);
71362d53 413
5a1d009d 414/**
6b783f49
JG
415@brief Sets the payload field of the CTF IR event \p event to \p payload,
416 or unsets the current event payload field from \p event.
5a1d009d 417
6b783f49 418If \p payload is not \c NULL, the field type of \p payload, as returned by
50842bdc
PP
419bt_field_get_type(), \em must be equivalent to the field type returned by
420bt_event_class_get_payload_type() for the parent class of \p event.
5a1d009d 421
6b783f49 422@param[in] event Event of which to set the payload field.
5a1d009d
PP
423@param[in] payload Event payload field.
424@returns 0 on success, or a negative value on error.
425
426@prenotnull{event}
5a1d009d 427@prehot{event}
6b783f49 428@pre <strong>\p payload, if not \c NULL</strong>, has a field type equivalent to
50842bdc 429 the field typereturned by bt_event_class_get_payload_type() for the
6b783f49 430 parent class of \p event.
5a1d009d 431@postrefcountsame{event}
6b783f49
JG
432@post <strong>On success, if \p payload is not \c NULL</strong>, the reference
433 count of \p payload is incremented.
5a1d009d 434
50842bdc 435@sa bt_event_get_payload(): Returns the payload field of a given event.
5a1d009d 436*/
50842bdc 437extern int bt_event_set_payload(struct bt_event *event,
3dca2276 438 struct bt_field *payload);
f655a84d 439
5a1d009d 440/** @} */
5fd2e9fd 441
5a1d009d
PP
442/**
443@name Clock value functions
444@{
445*/
5fd2e9fd 446
5a1d009d
PP
447/**
448@brief Returns the value, as of the CTF IR event \p event, of the
449 clock described by the
450 \link ctfirclockclass CTF IR clock class\endlink \p clock_class.
5c0f40f4 451
5a1d009d
PP
452@param[in] event Event of which to get the value of the clock
453 described by \p clock_class.
454@param[in] clock_class Class of the clock of which to get the value.
455@returns Value of the clock described by \p clock_class
456 as of \p event.
5c3b707d 457
5a1d009d
PP
458@prenotnull{event}
459@prenotnull{clock_class}
460@postrefcountsame{event}
461@postrefcountsame{clock_class}
462@postsuccessrefcountretinc
463
50842bdc 464@sa bt_event_set_clock_value(): Sets the clock value of a given event.
5a1d009d 465*/
50842bdc
PP
466extern struct bt_clock_value *bt_event_get_clock_value(
467 struct bt_event *event,
468 struct bt_clock_class *clock_class);
5a1d009d
PP
469
470/**
471@brief Sets the value, as of the CTF IR event \p event, of the
3f3c46b8
PP
472 clock described by its \link ctfirclockclass CTF IR
473 clock class\endlink.
5a1d009d
PP
474
475@param[in] event Event of which to set the value of the clock
3f3c46b8
PP
476 described by the clock class of \p clock_value.
477@param[in] clock_value Value of the clock described by its clock class
5a1d009d
PP
478 as of \p event.
479@returns 0 on success, or a negative value on error.
1556a1af 480
5a1d009d 481@prenotnull{event}
5a1d009d
PP
482@prenotnull{clock_value}
483@prehot{event}
484@postrefcountsame{event}
5a1d009d 485
50842bdc 486@sa bt_event_get_clock_value(): Returns the clock value of
5a1d009d
PP
487 a given event.
488*/
50842bdc
PP
489extern int bt_event_set_clock_value(
490 struct bt_event *event,
491 struct bt_clock_value *clock_value);
5a1d009d
PP
492
493/** @} */
494
495/** @} */
41ac640a 496
adc315b8
JG
497#ifdef __cplusplus
498}
499#endif
500
501#endif /* BABELTRACE_CTF_IR_EVENT_H */
This page took 0.066502 seconds and 4 git commands to generate.