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