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