Document field-path.h (API)
[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
144@param[in] event_class CTF IR event class to use to create the
145 CTF IR event.
146@returns Created event object, or \c NULL on error.
147
148@prenotnull{event_class}
149@pre \p event_class has a parent stream class.
150@postsuccessrefcountret1
151*/
adc315b8
JG
152extern struct bt_ctf_event *bt_ctf_event_create(
153 struct bt_ctf_event_class *event_class);
154
5a1d009d
PP
155/**
156@brief Returns the parent CTF IR event class of the CTF IR event
157 \p event.
158
159This function returns a reference to the event class which was used to
160create the event object in the first place with bt_ctf_event_create().
161
162@param[in] event Event of which to get the parent event class.
163@returns Parent event class of \p event,
164 or \c NULL on error.
165
166@prenotnull{event}
c2f29fb9 167@postrefcountsame{event}
5a1d009d
PP
168@postsuccessrefcountretinc
169*/
2f100782
JG
170extern struct bt_ctf_event_class *bt_ctf_event_get_class(
171 struct bt_ctf_event *event);
172
5a1d009d
PP
173/**
174@brief Returns the CTF IR packet associated to the CTF IR event
175 \p event.
176
177This function returns a reference to the event class which was set to
178\p event in the first place with bt_ctf_event_set_packet().
179
180@param[in] event Event of which to get the associated packet.
181@returns Packet associated to \p event,
182 or \c NULL if no packet is associated to
183 \p event or on error.
184
185@prenotnull{event}
c2f29fb9 186@postrefcountsame{event}
5a1d009d
PP
187@postsuccessrefcountretinc
188
189@sa bt_ctf_event_set_packet(): Associates a given event to a given
190 packet.
191*/
192extern struct bt_ctf_packet *bt_ctf_event_get_packet(
193 struct bt_ctf_event *event);
194
195/**
196@brief Associates the CTF IR event \p event to the CTF IR packet
197 \p packet.
198
199The \link ctfirstreamclass CTF IR stream class\endlink of the
200parent \link ctfirstream CTF IR stream\endlink of \p packet \em must
201be the same as the parent stream class of the
202\link ctfireventclass CTF IR event class\endlink returned
203by bt_ctf_event_get_class() for \p event.
204
205You \em must call this function to create an event-packet association
206before you call bt_notification_event_create() with \p event.
207
208On success, this function also sets the parent stream object of
209\p event to the parent stream of \p packet.
210
211@param[in] event Event to which to associate \p packet.
7113dedb 212@param[in] packet Packet to associate to \p event.
5a1d009d
PP
213@returns 0 on success, or a negative value on error.
214
215@prenotnull{event}
216@prenotnull{packet}
217@prehot{event}
218@pre The parent stream class of \p packet is the same as the parent
219 stream class of \p event.
220@postsuccessrefcountretinc
221
222@sa bt_ctf_event_get_packet(): Returns the associated packet of a
223 given event object.
224*/
225extern int bt_ctf_event_set_packet(struct bt_ctf_event *event,
226 struct bt_ctf_packet *packet);
227
228/**
229@brief Returns the parent CTF IR stream associated to the CTF IR event
230 \p event.
231
232@param[in] event Event of which to get the parent stream.
233@returns Parent stream of \p event, or \c NULL on error.
234
235@prenotnull{event}
c2f29fb9 236@postrefcountsame{event}
5a1d009d
PP
237@postsuccessrefcountretinc
238*/
8e5003bb
JG
239extern struct bt_ctf_stream *bt_ctf_event_get_stream(
240 struct bt_ctf_event *event);
241
5a1d009d
PP
242/** @} */
243
244/**
245@name Contained fields functions
246@{
247*/
248
249/**
250@brief Returns the stream event header field of the CTF IR event
251 \p event.
252
253@param[in] event Event of which to get the stream event header
254 field.
255@returns Stream event header field of \p event,
256 or \c NULL if the stream event header
257 field is not set or on error.
258
259@prenotnull{event}
c2f29fb9 260@postrefcountsame{event}
5a1d009d
PP
261@postsuccessrefcountretinc
262
263@sa bt_ctf_event_get_header(): Sets the stream event header
264 field of a given event.
265*/
266extern struct bt_ctf_field *bt_ctf_event_get_header(
267 struct bt_ctf_event *event);
268
269/**
270@brief Sets the stream event header field of the CTF IR event
271 \p event to \p header.
272
273The field type of \p header, as returned by bt_ctf_field_get_type(),
274\em must be equivalent to the field type returned by
275bt_ctf_stream_class_get_event_header_type() for the parent stream class
276of \p event.
277
278@param[in] event Event of which to set the stream event header
279 field.
280@param[in] header Stream event header field.
281@returns 0 on success, or a negative value on error.
282
283@prenotnull{event}
284@prenotnull{header}
285@prehot{event}
286@pre \p header has a field type equivalent to the field type returned by
287 bt_ctf_stream_class_get_event_header_type() for the parent
288 stream class of \p event.
289@postrefcountsame{event}
290@postsuccessrefcountinc{header}
291
292@sa bt_ctf_event_get_header(): Returns the stream event header field
293 of a given event.
294*/
295extern int bt_ctf_event_set_header(struct bt_ctf_event *event,
296 struct bt_ctf_field *header);
297
298/**
299@brief Returns the stream event context field of the CTF IR event
300 \p event.
301
302@param[in] event Event of which to get the stream event context
303 field.
304@returns Stream event context field of \p event,
305 or \c NULL if the stream event context
306 field is not set or on error.
307
308@prenotnull{event}
c2f29fb9 309@postrefcountsame{event}
5a1d009d
PP
310@postsuccessrefcountretinc
311
312@sa bt_ctf_event_set_stream_event_context(): Sets the stream event
313 context field of a given event.
314*/
315extern struct bt_ctf_field *bt_ctf_event_get_stream_event_context(
316 struct bt_ctf_event *event);
317
318/**
319@brief Sets the stream event context field of the CTF IR event
320 \p event to \p context.
321
322The field type of \p context, as returned by bt_ctf_field_get_type(),
323\em must be equivalent to the field type returned by
324bt_ctf_stream_class_get_event_context_type() for the parent stream class
325of \p event.
326
327@param[in] event Event of which to set the stream event context
328 field.
329@param[in] context Stream event context field.
330@returns 0 on success, or a negative value on error.
331
332@prenotnull{event}
333@prenotnull{context}
334@prehot{event}
335@pre \p context has a field type equivalent to the field type returned
336 by bt_ctf_stream_class_get_event_context_type() for the parent
337 stream class of \p event.
338@postrefcountsame{event}
339@postsuccessrefcountinc{context}
340
341@sa bt_ctf_event_get_stream_event_context(): Returns the stream event
342 context field of a given event.
343*/
344extern int bt_ctf_event_set_stream_event_context(struct bt_ctf_event *event,
345 struct bt_ctf_field *context);
346
347/**
348@brief Returns the event context field of the CTF IR event
349 \p event.
350
351@param[in] event Event of which to get the event context
352 field.
353@returns Event context field of \p event, or \c NULL if
354 the event context field is not set or on error.
355
356@prenotnull{event}
c2f29fb9 357@postrefcountsame{event}
5a1d009d
PP
358@postsuccessrefcountretinc
359
360@sa bt_ctf_event_set_event_context(): Sets the event context field of a
361 given event.
362*/
363extern struct bt_ctf_field *bt_ctf_event_get_event_context(
364 struct bt_ctf_event *event);
365
366/**
367@brief Sets the event context field of the CTF IR event
368 \p event to \p context.
369
370The field type of \p context, as returned by bt_ctf_field_get_type(),
371\em must be equivalent to the field type returned by
372bt_ctf_event_class_get_context_type() for the parent event class
373of \p event.
374
375@param[in] event Event of which to set the event context field.
376@param[in] context Event context field.
377@returns 0 on success, or a negative value on error.
378
379@prenotnull{event}
380@prenotnull{context}
381@prehot{event}
382@pre \p context has a field type equivalent to the field type returned
383 by bt_ctf_event_class_get_context_type() for the parent
384 event class of \p event.
385@postrefcountsame{event}
386@postsuccessrefcountinc{context}
387
388@sa bt_ctf_event_get_event_context(): Returns the event context field of
389 a given event.
390*/
391extern int bt_ctf_event_set_event_context(struct bt_ctf_event *event,
392 struct bt_ctf_field *context);
393
394/**
395@brief Returns the event payload field of the CTF IR event
396 \p event.
397
398@param[in] event Event of which to get the event payload
399 field.
400@returns Event payload field of \p event, or \c NULL if
401 the event payload field is not set or on error.
402
403@prenotnull{event}
c2f29fb9 404@postrefcountsame{event}
5a1d009d
PP
405@postsuccessrefcountretinc
406
407@sa bt_ctf_event_set_payload_field(): Sets the event payload field of a
408 given event.
409*/
71362d53
PP
410extern struct bt_ctf_field *bt_ctf_event_get_payload_field(
411 struct bt_ctf_event *event);
412
5a1d009d
PP
413/**
414@brief Sets the event payload field of the CTF IR event
415 \p event to \p payload.
416
417The field type of \p payload, as returned by bt_ctf_field_get_type(),
418\em must be equivalent to the field type returned by
419bt_ctf_event_class_get_payload_type() for the parent event class
420of \p event.
421
422@param[in] event Event of which to set the event payload field.
423@param[in] payload Event payload field.
424@returns 0 on success, or a negative value on error.
425
426@prenotnull{event}
427@prenotnull{payload}
428@prehot{event}
429@pre \p payload has a field type equivalent to the field type returned
430 by bt_ctf_event_class_get_payload_type() for the parent
431 event class of \p event.
432@postrefcountsame{event}
433@postsuccessrefcountinc{payload}
434
435@sa bt_ctf_event_get_payload_field(): Returns the event payload field of
436 a given event.
437*/
e5e6eb3a
JG
438extern int bt_ctf_event_set_payload_field(struct bt_ctf_event *event,
439 struct bt_ctf_field *payload);
440
5a1d009d
PP
441/**
442@cond DOCUMENT
443*/
444
2f100782 445/*
5a1d009d
PP
446 * TODO: Doxygenize.
447 *
2f100782
JG
448 * bt_ctf_event_get_payload: get an event's field.
449 *
51865548 450 * Returns the field matching "name". bt_put() must be called on the
2f100782
JG
451 * returned value.
452 *
453 * @param event Event instance.
c5a9aa19 454 * @param name Event field name, see notes.
2f100782
JG
455 *
456 * Returns a field instance on success, NULL on error.
c5a9aa19
JG
457 *
458 * Note: Passing a name will cause the function to perform a look-up by
459 * name assuming the event's payload is a structure. This will return
460 * the raw payload instance if name is NULL.
2f100782
JG
461 */
462extern struct bt_ctf_field *bt_ctf_event_get_payload(struct bt_ctf_event *event,
463 const char *name);
464
adc315b8 465/*
5a1d009d 466 * TODO: Doxygenize.
c5a9aa19 467 *
2f100782 468 * bt_ctf_event_get_payload_by_index: Get event's field by index.
adc315b8 469 *
51865548 470 * Returns the field associated with the provided index. bt_put()
2f100782
JG
471 * must be called on the returned value. The indexes to be provided are
472 * the same as can be retrieved from the event class.
adc315b8 473 *
2f100782
JG
474 * @param event Event.
475 * @param index Index of field.
adc315b8 476 *
2f100782 477 * Returns the event's field, NULL on error.
c5a9aa19
JG
478 *
479 * Note: Will return an error if the payload's type is not a structure.
adc315b8 480 */
2f100782 481extern struct bt_ctf_field *bt_ctf_event_get_payload_by_index(
074ee56d 482 struct bt_ctf_event *event, int index);
adc315b8 483
662e778c 484/*
5a1d009d 485 * TODO: Doxygenize.
662e778c 486 *
5a1d009d 487 * bt_ctf_event_set_payload: set an event's field.
662e778c 488 *
5a1d009d
PP
489 * Set a manually allocated field as an event's payload. The event will share
490 * the field's ownership by using its reference count.
491 * bt_put() must be called on the returned value.
662e778c
JG
492 *
493 * @param event Event instance.
5a1d009d
PP
494 * @param name Event field name, see notes.
495 * @param value Instance of a field whose type corresponds to the event's field.
f655a84d 496 *
5a1d009d 497 * Returns 0 on success, a negative value on error.
f655a84d 498 *
5a1d009d
PP
499 * Note: The function will return an error if a name is provided and the payload
500 * type is not a structure. If name is NULL, the payload field will be set
501 * directly and must match the event class' payload's type.
f655a84d 502 */
5a1d009d
PP
503extern int bt_ctf_event_set_payload(struct bt_ctf_event *event,
504 const char *name,
505 struct bt_ctf_field *value);
f655a84d 506
5a1d009d
PP
507/**
508@endcond
509*/
f655a84d 510
5a1d009d 511/** @} */
5fd2e9fd 512
5a1d009d
PP
513/**
514@name Clock value functions
515@{
516*/
5fd2e9fd 517
5a1d009d
PP
518/**
519@brief Returns the value, as of the CTF IR event \p event, of the
520 clock described by the
521 \link ctfirclockclass CTF IR clock class\endlink \p clock_class.
5c0f40f4 522
5a1d009d
PP
523@param[in] event Event of which to get the value of the clock
524 described by \p clock_class.
525@param[in] clock_class Class of the clock of which to get the value.
526@returns Value of the clock described by \p clock_class
527 as of \p event.
5c3b707d 528
5a1d009d
PP
529@prenotnull{event}
530@prenotnull{clock_class}
531@postrefcountsame{event}
532@postrefcountsame{clock_class}
533@postsuccessrefcountretinc
534
535@sa bt_ctf_event_set_clock_value(): Sets the clock value of a given event.
536*/
1556a1af 537extern struct bt_ctf_clock_value *bt_ctf_event_get_clock_value(
5a1d009d
PP
538 struct bt_ctf_event *event, struct bt_ctf_clock *clock_class);
539
540/**
541@brief Sets the value, as of the CTF IR event \p event, of the
542 clock described by the
543 \link ctfirclockclass CTF IR clock class\endlink \p clock_class.
544
545@param[in] event Event of which to set the value of the clock
546 described by \p clock_class.
547@param[in] clock_class Class of the clock of which to set the value
548 for \p event.
549@param[in] clock_value Value of the clock described by \p clock_class
550 as of \p event.
551@returns 0 on success, or a negative value on error.
1556a1af 552
5a1d009d
PP
553@prenotnull{event}
554@prenotnull{clock_class}
555@prenotnull{clock_value}
556@prehot{event}
557@postrefcountsame{event}
558@postrefcountsame{clock_class}
559
560@sa bt_ctf_event_get_clock_value(): Returns the clock value of
561 a given event.
562*/
1556a1af 563extern int bt_ctf_event_set_clock_value(
5a1d009d
PP
564 struct bt_ctf_event *event, struct bt_ctf_clock *clock_class,
565 struct bt_ctf_clock_value *clock_value);
566
567/** @} */
568
569/** @} */
41ac640a 570
adc315b8
JG
571#ifdef __cplusplus
572}
573#endif
574
575#endif /* BABELTRACE_CTF_IR_EVENT_H */
This page took 0.055255 seconds and 4 git commands to generate.