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