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