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