API doc: add notes about automatic resolving
[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>
dac5c838 35#include <babeltrace/values.h>
2f100782 36
adc315b8
JG
37#ifdef __cplusplus
38extern "C" {
39#endif
40
5a1d009d
PP
41/**
42@defgroup ctfirevent CTF IR event
43@ingroup ctfir
44@brief CTF IR event.
45
6dd2bd0c
PP
46@code
47#include <babeltrace/ctf-ir/event.h>
48@endcode
49
5a1d009d
PP
50A CTF IR <strong><em>event</em></strong> is a container of event
51fields:
52
53- <strong>Stream event header</strong> field, described by the
54 <em>stream event header field type</em> of a
55 \link ctfirstreamclass CTF IR stream class\endlink.
56- <strong>Stream event context</strong> field, described by the
57 <em>stream event context field type</em> of a stream class.
58- <strong>Event context</strong> field, described by the
59 <em>event context field type</em> of a
60 \link ctfireventclass CTF IR event class\endlink.
61- <strong>Event payload</strong>, described by the
62 <em>event payload field type</em> of an event class.
63
64As a reminder, here's the structure of a CTF packet:
65
66@imgpacketstructure
67
68You can create a CTF IR event \em from a
69\link ctfireventclass CTF IR event class\endlink with
70bt_ctf_event_create(). The event class you use to create an event
71object becomes its parent.
72
73If the \link ctfirtraceclass CTF IR trace class\endlink of an event
74object (parent of its \link ctfirstreamclass CTF IR stream class\endlink,
75which is the parent of its event class) was created by a
76\link ctfirwriter CTF IR writer\endlink object, then the only possible
77action you can do with this event object is to append it to a
78\link ctfirstream CTF IR stream\endlink with
79bt_ctf_stream_append_event(). Otherwise, you can create an event
80notification with bt_notification_event_create(). The event you pass
81to this function \em must have an attached packet object first.
82
83You can attach a \link ctfirpacket CTF IR packet object\endlink to an
84event object with bt_ctf_event_set_packet().
85
86A CTF IR event has a mapping of
87\link ctfirclockvalue CTF IR clock values\endlink. A clock value is
88an instance of a specific
89\link ctfirclockclass CTF IR clock class\endlink when the event is
90emitted. You can set an event object's clock value with
91bt_ctf_event_set_clock_value().
92
93As with any Babeltrace object, CTF IR event objects have
94<a href="https://en.wikipedia.org/wiki/Reference_counting">reference
95counts</a>. See \ref refs to learn more about the reference counting
96management of Babeltrace objects.
97
98bt_notification_event_create() \em freezes its event parameter on
99success. You cannot modify a frozen event object: it is considered
100immutable, except for \link refs reference counting\endlink.
101
102@sa ctfireventclass
103@sa ctfirpacket
104
105@file
106@brief CTF IR event type and functions.
107@sa ctfirevent
108
109@addtogroup ctfirevent
110@{
111*/
112
113/**
114@struct bt_ctf_event
115@brief A CTF IR event.
116@sa ctfirevent
117*/
118struct bt_ctf_event;
1556a1af
JG
119struct bt_ctf_clock;
120struct bt_ctf_clock_value;
adc315b8 121struct bt_ctf_event_class;
adc315b8
JG
122struct bt_ctf_field;
123struct bt_ctf_field_type;
2f100782 124struct bt_ctf_stream_class;
5c3b707d 125struct bt_ctf_packet;
adc315b8 126
5a1d009d
PP
127/**
128@name Creation and parent access functions
129@{
130*/
131
132/**
133@brief Creates a default CTF IR event from the CTF IR event class
134 \p event_class.
135
136\p event_class \em must have a parent
137\link ctfirstreamclass CTF IR stream class\endlink.
138
139On success, the four fields of the created event object are not set. You
140can set them with bt_ctf_event_set_header(),
141bt_ctf_event_set_stream_event_context(),
142bt_ctf_event_set_event_context(), and bt_ctf_event_set_payload_field().
143
4cdafd51
PP
144This function tries to resolve the needed
145\link ctfirfieldtypes CTF IR field type\endlink of the dynamic field
146types that are found anywhere in the context or payload field
147types of \p event_class and in the root field types of the
148parent stream class of \p event_class. If any automatic resolving fails,
149this function fails. This means that, if any dynamic field type need
150a field type which should be found in the trace packet header root
151field type, and if the parent stream class of \p event_class was not
152added to a \link ctfirtraceclass CTF IR trace class\endlink yet
153with bt_ctf_trace_add_stream_class(), then this function fails.
154
5a1d009d
PP
155@param[in] event_class CTF IR event class to use to create the
156 CTF IR event.
157@returns Created event object, or \c NULL on error.
158
159@prenotnull{event_class}
160@pre \p event_class has a parent stream class.
161@postsuccessrefcountret1
162*/
adc315b8
JG
163extern struct bt_ctf_event *bt_ctf_event_create(
164 struct bt_ctf_event_class *event_class);
165
5a1d009d
PP
166/**
167@brief Returns the parent CTF IR event class of the CTF IR event
168 \p event.
169
170This function returns a reference to the event class which was used to
171create the event object in the first place with bt_ctf_event_create().
172
173@param[in] event Event of which to get the parent event class.
174@returns Parent event class of \p event,
175 or \c NULL on error.
176
177@prenotnull{event}
c2f29fb9 178@postrefcountsame{event}
5a1d009d
PP
179@postsuccessrefcountretinc
180*/
2f100782
JG
181extern struct bt_ctf_event_class *bt_ctf_event_get_class(
182 struct bt_ctf_event *event);
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
189\p event in the first place with bt_ctf_event_set_packet().
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
200@sa bt_ctf_event_set_packet(): Associates a given event to a given
201 packet.
202*/
203extern struct bt_ctf_packet *bt_ctf_event_get_packet(
204 struct bt_ctf_event *event);
205
206/**
207@brief Associates the CTF IR event \p event to the CTF IR packet
208 \p packet.
209
210The \link ctfirstreamclass CTF IR stream class\endlink of the
211parent \link ctfirstream CTF IR stream\endlink of \p packet \em must
212be the same as the parent stream class of the
213\link ctfireventclass CTF IR event class\endlink returned
214by bt_ctf_event_get_class() for \p event.
215
216You \em must call this function to create an event-packet association
217before you call bt_notification_event_create() with \p event.
218
219On success, this function also sets the parent stream object of
220\p event to the parent stream of \p packet.
221
222@param[in] event Event to which to associate \p packet.
7113dedb 223@param[in] packet Packet to associate to \p event.
5a1d009d
PP
224@returns 0 on success, or a negative value on error.
225
226@prenotnull{event}
227@prenotnull{packet}
228@prehot{event}
229@pre The parent stream class of \p packet is the same as the parent
230 stream class of \p event.
231@postsuccessrefcountretinc
232
233@sa bt_ctf_event_get_packet(): Returns the associated packet of a
234 given event object.
235*/
236extern int bt_ctf_event_set_packet(struct bt_ctf_event *event,
237 struct bt_ctf_packet *packet);
238
239/**
240@brief Returns the parent CTF IR stream associated to the CTF IR event
241 \p event.
242
243@param[in] event Event of which to get the parent stream.
244@returns Parent stream of \p event, or \c NULL on error.
245
246@prenotnull{event}
c2f29fb9 247@postrefcountsame{event}
5a1d009d
PP
248@postsuccessrefcountretinc
249*/
8e5003bb
JG
250extern struct bt_ctf_stream *bt_ctf_event_get_stream(
251 struct bt_ctf_event *event);
252
5a1d009d
PP
253/** @} */
254
255/**
256@name Contained fields functions
257@{
258*/
259
260/**
261@brief Returns the stream event header field of the CTF IR event
262 \p event.
263
264@param[in] event Event of which to get the stream event header
265 field.
266@returns Stream event header field of \p event,
267 or \c NULL if the stream event header
268 field is not set or on error.
269
270@prenotnull{event}
c2f29fb9 271@postrefcountsame{event}
5a1d009d
PP
272@postsuccessrefcountretinc
273
274@sa bt_ctf_event_get_header(): Sets the stream event header
275 field of a given event.
276*/
277extern struct bt_ctf_field *bt_ctf_event_get_header(
278 struct bt_ctf_event *event);
279
280/**
281@brief Sets the stream event header field of the CTF IR event
282 \p event to \p header.
283
284The field type of \p header, as returned by bt_ctf_field_get_type(),
285\em must be equivalent to the field type returned by
286bt_ctf_stream_class_get_event_header_type() for the parent stream class
287of \p event.
288
289@param[in] event Event of which to set the stream event header
290 field.
291@param[in] header Stream event header field.
292@returns 0 on success, or a negative value on error.
293
294@prenotnull{event}
295@prenotnull{header}
296@prehot{event}
297@pre \p header has a field type equivalent to the field type returned by
298 bt_ctf_stream_class_get_event_header_type() for the parent
299 stream class of \p event.
300@postrefcountsame{event}
301@postsuccessrefcountinc{header}
302
303@sa bt_ctf_event_get_header(): Returns the stream event header field
304 of a given event.
305*/
306extern int bt_ctf_event_set_header(struct bt_ctf_event *event,
307 struct bt_ctf_field *header);
308
309/**
310@brief Returns the stream event context field of the CTF IR event
311 \p event.
312
313@param[in] event Event of which to get the stream event context
314 field.
315@returns Stream event context field of \p event,
316 or \c NULL if the stream event context
317 field is not set or on error.
318
319@prenotnull{event}
c2f29fb9 320@postrefcountsame{event}
5a1d009d
PP
321@postsuccessrefcountretinc
322
323@sa bt_ctf_event_set_stream_event_context(): Sets the stream event
324 context field of a given event.
325*/
326extern struct bt_ctf_field *bt_ctf_event_get_stream_event_context(
327 struct bt_ctf_event *event);
328
329/**
330@brief Sets the stream event context field of the CTF IR event
331 \p event to \p context.
332
333The field type of \p context, as returned by bt_ctf_field_get_type(),
334\em must be equivalent to the field type returned by
335bt_ctf_stream_class_get_event_context_type() for the parent stream class
336of \p event.
337
338@param[in] event Event of which to set the stream event context
339 field.
340@param[in] context Stream event context field.
341@returns 0 on success, or a negative value on error.
342
343@prenotnull{event}
344@prenotnull{context}
345@prehot{event}
346@pre \p context has a field type equivalent to the field type returned
347 by bt_ctf_stream_class_get_event_context_type() for the parent
348 stream class of \p event.
349@postrefcountsame{event}
350@postsuccessrefcountinc{context}
351
352@sa bt_ctf_event_get_stream_event_context(): Returns the stream event
353 context field of a given event.
354*/
355extern int bt_ctf_event_set_stream_event_context(struct bt_ctf_event *event,
356 struct bt_ctf_field *context);
357
358/**
359@brief Returns the event context field of the CTF IR event
360 \p event.
361
362@param[in] event Event of which to get the event context
363 field.
364@returns Event context field of \p event, or \c NULL if
365 the event context field is not set or on error.
366
367@prenotnull{event}
c2f29fb9 368@postrefcountsame{event}
5a1d009d
PP
369@postsuccessrefcountretinc
370
371@sa bt_ctf_event_set_event_context(): Sets the event context field of a
372 given event.
373*/
374extern struct bt_ctf_field *bt_ctf_event_get_event_context(
375 struct bt_ctf_event *event);
376
377/**
378@brief Sets the event context field of the CTF IR event
379 \p event to \p context.
380
381The field type of \p context, as returned by bt_ctf_field_get_type(),
382\em must be equivalent to the field type returned by
383bt_ctf_event_class_get_context_type() for the parent event class
384of \p event.
385
386@param[in] event Event of which to set the event context field.
387@param[in] context Event context field.
388@returns 0 on success, or a negative value on error.
389
390@prenotnull{event}
391@prenotnull{context}
392@prehot{event}
393@pre \p context has a field type equivalent to the field type returned
394 by bt_ctf_event_class_get_context_type() for the parent
395 event class of \p event.
396@postrefcountsame{event}
397@postsuccessrefcountinc{context}
398
399@sa bt_ctf_event_get_event_context(): Returns the event context field of
400 a given event.
401*/
402extern int bt_ctf_event_set_event_context(struct bt_ctf_event *event,
403 struct bt_ctf_field *context);
404
405/**
406@brief Returns the event payload field of the CTF IR event
407 \p event.
408
409@param[in] event Event of which to get the event payload
410 field.
411@returns Event payload field of \p event, or \c NULL if
412 the event payload field is not set or on error.
413
414@prenotnull{event}
c2f29fb9 415@postrefcountsame{event}
5a1d009d
PP
416@postsuccessrefcountretinc
417
418@sa bt_ctf_event_set_payload_field(): Sets the event payload field of a
419 given event.
420*/
71362d53
PP
421extern struct bt_ctf_field *bt_ctf_event_get_payload_field(
422 struct bt_ctf_event *event);
423
5a1d009d
PP
424/**
425@brief Sets the event payload field of the CTF IR event
426 \p event to \p payload.
427
428The field type of \p payload, as returned by bt_ctf_field_get_type(),
429\em must be equivalent to the field type returned by
430bt_ctf_event_class_get_payload_type() for the parent event class
431of \p event.
432
433@param[in] event Event of which to set the event payload field.
434@param[in] payload Event payload field.
435@returns 0 on success, or a negative value on error.
436
437@prenotnull{event}
438@prenotnull{payload}
439@prehot{event}
440@pre \p payload has a field type equivalent to the field type returned
441 by bt_ctf_event_class_get_payload_type() for the parent
442 event class of \p event.
443@postrefcountsame{event}
444@postsuccessrefcountinc{payload}
445
446@sa bt_ctf_event_get_payload_field(): Returns the event payload field of
447 a given event.
448*/
e5e6eb3a
JG
449extern int bt_ctf_event_set_payload_field(struct bt_ctf_event *event,
450 struct bt_ctf_field *payload);
451
5a1d009d
PP
452/**
453@cond DOCUMENT
454*/
455
2f100782 456/*
5a1d009d
PP
457 * TODO: Doxygenize.
458 *
2f100782
JG
459 * bt_ctf_event_get_payload: get an event's field.
460 *
51865548 461 * Returns the field matching "name". bt_put() must be called on the
2f100782
JG
462 * returned value.
463 *
464 * @param event Event instance.
c5a9aa19 465 * @param name Event field name, see notes.
2f100782
JG
466 *
467 * Returns a field instance on success, NULL on error.
c5a9aa19
JG
468 *
469 * Note: Passing a name will cause the function to perform a look-up by
470 * name assuming the event's payload is a structure. This will return
471 * the raw payload instance if name is NULL.
2f100782
JG
472 */
473extern struct bt_ctf_field *bt_ctf_event_get_payload(struct bt_ctf_event *event,
474 const char *name);
475
adc315b8 476/*
5a1d009d 477 * TODO: Doxygenize.
c5a9aa19 478 *
2f100782 479 * bt_ctf_event_get_payload_by_index: Get event's field by index.
adc315b8 480 *
51865548 481 * Returns the field associated with the provided index. bt_put()
2f100782
JG
482 * must be called on the returned value. The indexes to be provided are
483 * the same as can be retrieved from the event class.
adc315b8 484 *
2f100782
JG
485 * @param event Event.
486 * @param index Index of field.
adc315b8 487 *
2f100782 488 * Returns the event's field, NULL on error.
c5a9aa19
JG
489 *
490 * Note: Will return an error if the payload's type is not a structure.
adc315b8 491 */
2f100782 492extern struct bt_ctf_field *bt_ctf_event_get_payload_by_index(
074ee56d 493 struct bt_ctf_event *event, int index);
adc315b8 494
662e778c 495/*
5a1d009d 496 * TODO: Doxygenize.
662e778c 497 *
5a1d009d 498 * bt_ctf_event_set_payload: set an event's field.
662e778c 499 *
5a1d009d
PP
500 * Set a manually allocated field as an event's payload. The event will share
501 * the field's ownership by using its reference count.
502 * bt_put() must be called on the returned value.
662e778c
JG
503 *
504 * @param event Event instance.
5a1d009d
PP
505 * @param name Event field name, see notes.
506 * @param value Instance of a field whose type corresponds to the event's field.
f655a84d 507 *
5a1d009d 508 * Returns 0 on success, a negative value on error.
f655a84d 509 *
5a1d009d
PP
510 * Note: The function will return an error if a name is provided and the payload
511 * type is not a structure. If name is NULL, the payload field will be set
512 * directly and must match the event class' payload's type.
f655a84d 513 */
5a1d009d
PP
514extern int bt_ctf_event_set_payload(struct bt_ctf_event *event,
515 const char *name,
516 struct bt_ctf_field *value);
f655a84d 517
5a1d009d
PP
518/**
519@endcond
520*/
f655a84d 521
5a1d009d 522/** @} */
5fd2e9fd 523
5a1d009d
PP
524/**
525@name Clock value functions
526@{
527*/
5fd2e9fd 528
5a1d009d
PP
529/**
530@brief Returns the value, as of the CTF IR event \p event, of the
531 clock described by the
532 \link ctfirclockclass CTF IR clock class\endlink \p clock_class.
5c0f40f4 533
5a1d009d
PP
534@param[in] event Event of which to get the value of the clock
535 described by \p clock_class.
536@param[in] clock_class Class of the clock of which to get the value.
537@returns Value of the clock described by \p clock_class
538 as of \p event.
5c3b707d 539
5a1d009d
PP
540@prenotnull{event}
541@prenotnull{clock_class}
542@postrefcountsame{event}
543@postrefcountsame{clock_class}
544@postsuccessrefcountretinc
545
546@sa bt_ctf_event_set_clock_value(): Sets the clock value of a given event.
547*/
1556a1af 548extern struct bt_ctf_clock_value *bt_ctf_event_get_clock_value(
5a1d009d
PP
549 struct bt_ctf_event *event, struct bt_ctf_clock *clock_class);
550
551/**
552@brief Sets the value, as of the CTF IR event \p event, of the
553 clock described by the
554 \link ctfirclockclass CTF IR clock class\endlink \p clock_class.
555
556@param[in] event Event of which to set the value of the clock
557 described by \p clock_class.
558@param[in] clock_class Class of the clock of which to set the value
559 for \p event.
560@param[in] clock_value Value of the clock described by \p clock_class
561 as of \p event.
562@returns 0 on success, or a negative value on error.
1556a1af 563
5a1d009d
PP
564@prenotnull{event}
565@prenotnull{clock_class}
566@prenotnull{clock_value}
567@prehot{event}
568@postrefcountsame{event}
569@postrefcountsame{clock_class}
570
571@sa bt_ctf_event_get_clock_value(): Returns the clock value of
572 a given event.
573*/
1556a1af 574extern int bt_ctf_event_set_clock_value(
5a1d009d
PP
575 struct bt_ctf_event *event, struct bt_ctf_clock *clock_class,
576 struct bt_ctf_clock_value *clock_value);
577
578/** @} */
579
580/** @} */
41ac640a 581
adc315b8
JG
582#ifdef __cplusplus
583}
584#endif
585
586#endif /* BABELTRACE_CTF_IR_EVENT_H */
This page took 0.056998 seconds and 4 git commands to generate.