API doc: add #include line in the detailed description
[babeltrace.git] / include / babeltrace / ctf-ir / event-class.h
CommitLineData
272df73e
PP
1#ifndef BABELTRACE_CTF_IR_EVENT_CLASS_H
2#define BABELTRACE_CTF_IR_EVENT_CLASS_H
3
4/*
5 * BabelTrace - CTF IR: Event class
6 *
7 * Copyright 2013, 2014 Jérémie Galarneau <jeremie.galarneau@efficios.com>
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
33#include <stdint.h>
34#include <stddef.h>
35#include <babeltrace/values.h>
36
37#ifdef __cplusplus
38extern "C" {
39#endif
40
d5a28207
PP
41/**
42@defgroup ctfireventclass CTF IR event class
43@ingroup ctfir
44@brief CTF IR event class.
45
6dd2bd0c
PP
46@code
47#include <babeltrace/ctf-ir/event-class.h>
48@endcode
49
d5a28207
PP
50A CTF IR <strong><em>event class</em></strong> is a template that you
51can use to create concrete \link ctfirevent CTF IR events\endlink.
52
53An event class has the following properties, both of which \em must
54be unique amongst all the event classes contained in the same
55\link ctfirstreamclass CTF IR stream class\endlink:
56
57- A \b name.
58- A numeric \b ID.
59
60A CTF IR event class owns two
61\link ctfirfieldtypes field types\endlink:
62
63- An optional <strong>event context</strong> field type, which
64 represents the \c event.context CTF scope.
65- A mandatory <strong>event payload</strong> field type, which
66 represents the \c event.fields CTF scope.
67
68Both field types \em must be structure field types as of
69Babeltrace \btversion.
70The event payload field type <em>must not</em> be empty.
71
72As a reminder, here's the structure of a CTF packet:
73
74@imgpacketstructure
75
76In the Babeltrace CTF IR system, a \link ctfirtraceclass trace
77class\endlink contains zero or more \link ctfirstreamclass stream
78classes\endlink, and a stream class contains zero or more event classes.
79
80Before you can create an event from an event class with
81bt_ctf_event_create(), you \em must add the prepared event class to a
82stream class by calling bt_ctf_stream_class_add_event_class(). This
83function, when successful, \em freezes the event class, disallowing any
84future modification of its properties and field types by the user.
85
86As with any Babeltrace object, CTF IR event class objects have
87<a href="https://en.wikipedia.org/wiki/Reference_counting">reference
88counts</a>. See \ref refs to learn more about the reference counting
89management of Babeltrace objects.
90
91bt_ctf_stream_class_add_event_class() \em freezes its event class
92parameter on success. You cannot modify a frozen event class: it is
93considered immutable, except for \link refs reference counting\endlink.
94
95@sa ctfirevent
96@sa ctfirstreamclass
97
98@file
99@brief CTF IR event class type and functions.
100@sa ctfireventclass
101
102@addtogroup ctfireventclass
103@{
104*/
105
106/**
107@struct bt_ctf_event_class
108@brief A CTF IR event class.
109@sa ctfireventclass
110*/
272df73e
PP
111struct bt_ctf_event_class;
112struct bt_ctf_field;
113struct bt_ctf_field_type;
114struct bt_ctf_stream_class;
115
d5a28207
PP
116/**
117@name Creation and parent access functions
118@{
119*/
120
121/**
122@brief Creates a default CTF IR event class named \p name­.
123
124The event class is created \em without an event context
125\link ctfirfieldtypes field type\endlink and with an empty event
126payload field type.
127
128Upon creation, the event class's ID is <em>not set</em>. You
129can set it to a specific value with bt_ctf_event_class_set_id(). If it
130is still unset when you call bt_ctf_stream_class_add_event_class(), then
131the stream class assigns a unique ID to this event class before
132freezing it.
133
134@param[in] name Name of the event class to create (copied on success).
135@returns Created event class, or \c NULL on error.
136
137@prenotnull{name}
138@postsuccessrefcountret1
139*/
272df73e
PP
140extern struct bt_ctf_event_class *bt_ctf_event_class_create(const char *name);
141
d5a28207
PP
142/**
143@brief Returns the parent CTF IR stream class of the CTF IR event
144 class \p event_class.
145
146It is possible that the event class was not added to a stream class
147yet, in which case this function returns \c NULL. You can add an
148event class to a stream class with
149bt_ctf_stream_class_add_event_class().
150
151@param[in] event_class Event class of which to get the parent
152 stream class.
153@returns Parent stream class of \p event_class,
154 or \c NULL if \p event_class was not
155 added to a stream class yet or on error.
156
157@prenotnull{event_class}
158@postsuccessrefcountretinc
159
160@sa bt_ctf_stream_class_add_event_class(): Add an event class to
161 a stream class.
162*/
163extern struct bt_ctf_stream_class *bt_ctf_event_class_get_stream_class(
164 struct bt_ctf_event_class *event_class);
165
166/** @} */
167
168/**
169@name Attribute functions
170@{
171*/
172
173/**
174@brief Returns the name of the CTF IR event class \p event_class.
175
176On success, \p event_class remains the sole owner of the returned
177string.
178
179@param[in] event_class Event class of which to get the name.
180@returns Name of event class \p event_class, or
181 \c NULL on error.
182
183@prenotnull{event_class}
184@postrefcountsame{event_class}
185*/
272df73e
PP
186extern const char *bt_ctf_event_class_get_name(
187 struct bt_ctf_event_class *event_class);
188
d5a28207
PP
189/**
190@brief Returns the numeric ID of the CTF IR event class \p event_class.
191
192@param[in] event_class Event class of which to get the numeric ID.
193@returns ID of event class \p event_class, or a
194 negative value on error.
195
196@prenotnull{event_class}
197@postrefcountsame{event_class}
198
199@sa bt_ctf_event_class_set_id(): Sets the numeric ID of a given
200 event class.
201*/
272df73e
PP
202extern int64_t bt_ctf_event_class_get_id(
203 struct bt_ctf_event_class *event_class);
204
d5a28207
PP
205/**
206@brief Sets the numeric ID of the CTF IR event class
207 \p event_class to \p id.
208
209\p id must be unique amongst the IDs of all the event classes
210of the stream class to which you eventually add \p event_class.
211
212@param[in] event_class Event class of which to set the numeric ID.
213@param[in] id ID of the event class.
214@returns 0 on success, or a negative value on error.
215
216@prenotnull{event_class}
217@prehot{event_class}
218@postrefcountsame{event_class}
219
220@sa bt_ctf_event_class_get_id(): Returns the numeric ID of a given
221 event class.
222*/
272df73e
PP
223extern int bt_ctf_event_class_set_id(
224 struct bt_ctf_event_class *event_class, uint32_t id);
225
d5a28207
PP
226/**
227@brief Returns the number of attributes contained in the CTF IR event
228 class \p event_class.
272df73e 229
d5a28207
PP
230@param[in] event_class Event class of which to get the number
231 of contained attributes.
232@returns Number of contained attributes in
233 \p event_class, or a negative value on error.
234
235@prenotnull{event_class}
236@postrefcountsame{event_class}
237
238@sa bt_ctf_event_class_get_attribute_name(): Returns the name of
239 the attribute of a given event class at a given index.
240@sa bt_ctf_event_class_get_attribute_value(): Returns the value of
241 the attribute of a given event class at a given index.
242*/
272df73e
PP
243extern int bt_ctf_event_class_get_attribute_count(
244 struct bt_ctf_event_class *event_class);
245
d5a28207
PP
246/**
247@brief Returns the name of the attribute at the index \p index of the
248 CTF IR event class \p event_class.
249
250On success, \p event_class remains the sole owner of the returned
251string.
252
253@param[in] event_class Event class of which to get the name
254 of an attribute.
255@param[in] index Index of the attribute of which to get the name.
256@returns Attribute name, or \c NULL on error.
257
258@prenotnull{event_class}
259@pre \p index is lesser than the number of attributes contained by
260 \p event_class.
261@postrefcountsame{event_class}
262
263@sa bt_ctf_event_class_get_attribute_value(): Returns the value of
264 the attribute of a given event class at a given index.
265*/
272df73e
PP
266extern const char *
267bt_ctf_event_class_get_attribute_name(
268 struct bt_ctf_event_class *event_class, int index);
269
d5a28207
PP
270/**
271@brief Returns the value of the attribute at the index \p index of the
272 CTF IR event class \p event_class.
273
274@param[in] event_class Event class of which to get the value
275 of an attribute.
276@param[in] index Index of the attribute of which to get the value.
277@returns Attribute value, or \c NULL on error.
278
279@prenotnull{event_class}
280@pre \p index is lesser than the number of attributes contained by
281 \p event_class.
282@postsuccessrefcountretinc
283@postrefcountsame{event_class}
284
285@sa bt_ctf_event_class_get_attribute_name(): Returns the name of
286 the attribute of a given event class at a given index.
287*/
272df73e
PP
288extern struct bt_value *
289bt_ctf_event_class_get_attribute_value(struct bt_ctf_event_class *event_class,
290 int index);
291
d5a28207
PP
292/**
293@brief Returns the value of the attribute named \p name of the CTF IR
294 event class \p event_class.
295
296On success, the reference count of the returned value object is
297incremented.
298
299@param[in] event_class Event class of which to get the value
300 of an attribute.
301@param[in] name Name of the attribute to get.
302@returns Attribute value, or \c NULL on error.
303
304@prenotnull{event_class}
305@prenotnull{name}
306@postsuccessrefcountretinc
307@postrefcountsame{event_class}
308*/
272df73e
PP
309extern struct bt_value *
310bt_ctf_event_class_get_attribute_value_by_name(
311 struct bt_ctf_event_class *event_class, const char *name);
312
d5a28207
PP
313/**
314@brief Sets the attribute named \p name of the CTF IR event class
315 \p event_class to the value \p value.
272df73e 316
d5a28207
PP
317Valid attributes, as of Babeltrace \btversion, are:
318
319- <code>id</code>: \em must be an integer value object with a raw value
320 that is greater than or equal to 0. This represents the event class's
321 numeric ID and you can also set it with bt_ctf_event_class_set_id().
322
323- <code>name</code>: must be a string value object. This represents
324 the name of the event class.
325
326- <code>loglevel</code>: must be an integer value object with a raw
327 value greater than or equal to 0. This represents the numeric log level
328 associated with this event class. Log level values
329 are application-specific.
330
331- <code>model.emf.uri</code>: must be a string value object. This
332 represents the application-specific Eclipse Modeling Framework URI
333 of the event class.
334
335@param[in] event_class Event class of which to set an
336 attribute.
337@param[in] name Attribute name (copied on success).
338@param[in] value Attribute value.
339@returns 0 on success, or a negative value on error.
340
341@prenotnull{event_class}
342@prenotnull{name}
343@prenotnull{value}
344@prehot{event_class}
345@postrefcountsame{event_class}
346@postsuccessrefcountinc{value}
347
348@sa bt_ctf_event_class_get_attribute_value_by_name(): Returns the
349 attribute of a given event class having a given name.
350*/
351extern int bt_ctf_event_class_set_attribute(
352 struct bt_ctf_event_class *event_class, const char *name,
353 struct bt_value *value);
354
355/** @} */
356
357/**
358@name Contained field types functions
359@{
360*/
361
29620c97
PP
362/**
363@brief Returns the context field type of the CTF IR event class
364 \p event_class.
365
366@param[in] event_class Event class of which to get the
367 context field type.
368@returns Context field type of \p event_class,
369 or \c NULL on error.
370
371@prenotnull{event_class}
372@postsuccessrefcountretinc
373
374@sa bt_ctf_event_class_set_context_type(): Sets the context field
375 type of a given event class.
376*/
377extern struct bt_ctf_field_type *bt_ctf_event_class_get_context_type(
378 struct bt_ctf_event_class *event_class);
379
380/**
381@brief Sets the context field type of the CTF IR event class
382 \p event_class to \p context_type.
383
384As of Babeltrace \btversion, \p context_type \em must be a
385CTF IR structure field type object.
386
387@param[in] event_class Event class of which to set the context
388 field type.
389@param[in] context_type Context field type.
390@returns 0 on success, or a negative value on error.
391
392@prenotnull{event_class}
393@prenotnull{context_type}
394@prehot{event_class}
395@preisstructft{context_type}
396@postrefcountsame{event_class}
397@postsuccessrefcountinc{context_type}
398
399@sa bt_ctf_event_class_get_context_type(): Returns the context field
400 type of a given event class.
401*/
402extern int bt_ctf_event_class_set_context_type(
403 struct bt_ctf_event_class *event_class,
404 struct bt_ctf_field_type *context_type);
405
d5a28207
PP
406/**
407@brief Returns the payload field type of the CTF IR event class
408 \p event_class.
409
410@param[in] event_class Event class of which to get the
411 payload field type.
412@returns Payload field type of \p event_class,
413 or \c NULL on error.
414
415@prenotnull{event_class}
416@postsuccessrefcountretinc
417
418@sa bt_ctf_event_class_set_payload_type(): Sets the payload field
419 type of a given event class.
420*/
272df73e
PP
421extern struct bt_ctf_field_type *bt_ctf_event_class_get_payload_type(
422 struct bt_ctf_event_class *event_class);
423
d5a28207
PP
424/**
425@brief Sets the payload field type of the CTF IR event class
426 \p event_class to \p payload_type.
427
428As of Babeltrace \btversion, \p payload_type \em must be a
429CTF IR structure field type object.
430
431@param[in] event_class Event class of which to set the payload
432 field type.
433@param[in] payload_type Payload field type.
434@returns 0 on success, or a negative value on error.
435
436@prenotnull{event_class}
437@prenotnull{payload_type}
438@prehot{event_class}
439@preisstructft{payload_type}
440@postrefcountsame{event_class}
441@postsuccessrefcountinc{payload_type}
442
443@sa bt_ctf_event_class_get_payload_type(): Returns the payload field
444 type of a given event class.
445*/
272df73e
PP
446extern int bt_ctf_event_class_set_payload_type(
447 struct bt_ctf_event_class *event_class,
d5a28207 448 struct bt_ctf_field_type *payload_type);
272df73e 449
d5a28207
PP
450/**
451@brief Returns the number of fields contained in the
452 payload field type of the CTF IR event class \p event_class.
272df73e 453
d5a28207
PP
454@remarks
455Calling this function is the equivalent of getting the payload field
456type of \p event_class with bt_ctf_event_class_get_payload_type() and
457getting its field count with
458bt_ctf_field_type_structure_get_field_count().
459
460@param[in] event_class Event class of which to get the number
461 of fields contained in its payload field type.
462@returns Number of fields in the payload field type
463 of \p event_class, or a negative value on error.
464
465@prenotnull{event_class}
466@postrefcountsame{event_class}
467*/
272df73e
PP
468extern int bt_ctf_event_class_get_field_count(
469 struct bt_ctf_event_class *event_class);
470
d5a28207
PP
471/**
472@brief Returns the type and the name of the field at index \p index
473 in the payload field type of the CTF IR event class
474 \p event_class.
475
476On success, the field's type is placed in \p *field_type if
477\p field_type is not \c NULL. The field's name is placed in
478\p *name if \p name is not \c NULL. \p event_class remains the sole
479owner of \p *name.
480
481Both \p name and \p field_type can be \c NULL if the caller is not
482interested in one of them.
483
484@remarks
485Calling this function is the equivalent of getting the payload field
486type of \p event_class with bt_ctf_event_class_get_payload_type() and
487getting the type and name of one of its field with
488bt_ctf_field_type_structure_get_field().
489
490@param[in] event_class Event class of which to get the type and name
491 of a field in its payload field type.
492@param[out] field_name Name of the field at the index
493 \p index in the payload field type of
494 \p event_class (can be \c NULL).
495@param[out] field_type Type of the field at the index \p index in the
496 payload field type of \p event_class
497 (can be \c NULL).
498@param[in] index Index of the payload field type's field to find.
499@returns 0 on success, or a negative value on error.
500
501@prenotnull{event_class}
502@pre \p index is lesser than the number of fields contained in the
503 payload field type of \p event_class (see
504 bt_ctf_event_class_get_field_count()).
505@postrefcountsame{event_class}
506@post <strong>On success, if \p field_type is not \c NULL</strong>, the
507 reference count of \p *field_type is incremented.
508*/
272df73e
PP
509extern int bt_ctf_event_class_get_field(struct bt_ctf_event_class *event_class,
510 const char **field_name, struct bt_ctf_field_type **field_type,
511 int index);
512
d5a28207
PP
513/**
514@brief Returns the type of the field named \p name in the payload
515 field type of the CTF IR event class \p event_class.
516
517@remarks
518Calling this function is the equivalent of getting the payload field
519type of \p event_class with bt_ctf_event_class_get_payload_type() and
520getting the type of one of its field with
521bt_ctf_field_type_structure_get_field_type_by_name().
522
523@param[in] event_class Event class of which to get the type of a
524 payload field type's field.
525@param[in] name Name of the payload field type's field to get.
526@returns Type of the field named \p name in the payload
527 field type of \p event_class, or \c NULL if
528 the function cannot find the field or
529 on error.
530
531@prenotnull{event_class}
532@prenotnull{name}
533@postrefcountsame{event_class}
534@postsuccessrefcountretinc
535
536*/
272df73e
PP
537extern struct bt_ctf_field_type *bt_ctf_event_class_get_field_by_name(
538 struct bt_ctf_event_class *event_class, const char *name);
539
d5a28207
PP
540/**
541@brief Adds a field named \p name with the type \p field_type to the
542 payload field type of the CTF IR event class \p event_class.
543
544@remarks
545Calling this function is the equivalent of getting the payload field
546type of \p event_class with bt_ctf_event_class_get_payload_type() and
547adding a field to it with bt_ctf_field_type_structure_add_field().
548
549@param[in] event_class Event class containing the payload field
550 type in which to add a field.
551@param[in] field_type Type of the field to add.
552@param[in] name Name of the field to add (copied on
553 success).
554@returns 0 on success, or a negative value on error.
555
556@prenotnull{event_class}
557@prenotnull{type}
558@prenotnull{name}
559@prehot{event_class}
560@postrefcountsame{event_class}
561@postsuccessrefcountinc{field_type}
562*/
563extern int bt_ctf_event_class_add_field(struct bt_ctf_event_class *event_class,
564 struct bt_ctf_field_type *field_type,
565 const char *name);
566
d5a28207
PP
567/** @} */
568
569/** @} */
272df73e 570
272df73e
PP
571#ifdef __cplusplus
572}
573#endif
574
575#endif /* BABELTRACE_CTF_IR_EVENT_CLASS_H */
This page took 0.051214 seconds and 4 git commands to generate.