1 #ifndef BABELTRACE_CTF_IR_STREAM_CLASS_H
2 #define BABELTRACE_CTF_IR_STREAM_CLASS_H
5 * BabelTrace - CTF IR: Stream Class
7 * Copyright 2014 Jérémie Galarneau <jeremie.galarneau@efficios.com>
9 * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com>
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:
18 * The above copyright notice and this permission notice shall be included in
19 * all copies or substantial portions of the Software.
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
29 * The Common Trace Format (CTF) Specification is available at
30 * http://www.efficios.com/ctf
36 #include <babeltrace/ctf-ir/visitor.h>
43 @defgroup ctfirstreamclass CTF IR stream class
45 @brief CTF IR stream class.
48 #include <babeltrace/ctf-ir/stream-class.h>
52 See \ref ctfwriterstreamclass which documents additional CTF IR stream
53 class functions exclusive to the CTF writer mode.
55 A CTF IR <strong><em>stream class</em></strong> is a template that you
56 can use to create concrete \link ctfirstream CTF IR streams\endlink.
58 A stream class has the following properties, both of which \em must
59 be unique amongst all the stream classes contained in the same
60 \link ctfirtraceclass CTF IR trace class\endlink:
65 In the Babeltrace CTF IR system, a \link ctfirtraceclass trace class\endlink
66 contains zero or more stream classes,
67 and a stream class contains zero or more
68 \link ctfireventclass event classes\endlink.
69 You can add an event class
70 to a stream class with bt_stream_class_add_event_class().
71 You can add a stream class to a trace class with
72 bt_trace_add_stream_class().
74 A stream class owns three \link ctfirfieldtypes field types\endlink:
76 - An optional <strong>stream packet context</strong> field type, which
77 represents the \c stream.packet.context CTF scope.
78 - An optional <strong>stream event header</strong> field type, which
79 represents the \c stream.event.header CTF scope.
80 - An optional <strong>stream event context</strong> field type, which
81 represents the \c stream.event.context CTF scope.
83 Those three field types \em must be structure field types as of
84 Babeltrace \btversion.
86 As per the CTF specification, the event header field type \em must
87 contain a field named \c id if the stream class contains more than one
90 As a reminder, here's the structure of a CTF packet:
94 Before you can create a stream from a stream class with
95 bt_stream_create(), you \em must add the prepared stream class to a
96 trace class by calling bt_trace_add_stream_class().
98 As with any Babeltrace object, CTF IR stream class objects have
99 <a href="https://en.wikipedia.org/wiki/Reference_counting">reference
100 counts</a>. See \ref refs to learn more about the reference counting
101 management of Babeltrace objects.
103 The following functions \em freeze their stream class parameter on
106 - bt_trace_add_stream_class()
108 - bt_writer_create_stream()
109 (\link ctfwriter CTF writer\endlink mode only)
111 You cannot modify a frozen stream class: it is considered immutable,
114 - Adding an event class to it with
115 bt_stream_class_add_event_class(). If the stream class's parent
116 \link ctfirtraceclass trace class\endlink is static, however,
117 you cannot call bt_stream_class_add_event_class()
118 (see bt_trace_is_static() and bt_trace_set_is_static()).
119 - \link refs Reference counting\endlink.
124 @sa ctfwriterstreamclass
127 @brief CTF IR stream class type and functions.
130 @addtogroup ctfirstreamclass
135 @struct bt_stream_class
136 @brief A CTF IR stream class.
139 struct bt_stream_class
;
140 struct bt_event_class
;
144 @name Creation and parent access functions
149 @brief Creates an empty CTF IR stream class named \p name, or an
150 unnamed empty stream class if \p name is \c NULL.
152 On success, the packet context, event header, and event context field
153 types are empty structure field types. You can modify those default
154 field types after the stream class is created with
155 bt_stream_class_set_packet_context_type(),
156 bt_stream_class_set_event_header_type(), and
157 bt_stream_class_set_event_context_type().
159 @param[in] name Name of the stream class to create (copied on success),
160 or \c NULL to create an unnamed stream class.
161 @returns Created empty stream class, or \c NULL on error.
163 @postsuccessrefcountret1
165 @sa bt_stream_class_create(): Creates a default stream class.
167 extern struct bt_stream_class
*bt_stream_class_create_empty(
171 @brief Creates a default CTF IR stream class named \p name, or a
172 default unnamed stream class if \p name is \c NULL.
174 On success, the packet context field type of the created stream class
175 has the following fields:
177 - <code>timestamp_begin</code>: a 64-bit unsigned integer field type.
178 - <code>timestamp_end</code>: a 64-bit unsigned integer field type.
179 - <code>content_size</code>: a 64-bit unsigned integer field type.
180 - <code>packet_size</code>: a 64-bit unsigned integer field type.
181 - <code>events_discarded</code>: a 64-bit unsigned integer field type.
183 On success, the event header field type of the created stream class
184 has the following fields:
186 - <code>code</code>: a 32-bit unsigned integer field type.
187 - <code>timestamp</code>: a 64-bit unsigned integer field type.
189 You can modify those default field types after the stream class is
190 created with bt_stream_class_set_packet_context_type() and
191 bt_stream_class_set_event_header_type().
193 @param[in] name Name of the stream class to create (copied on success),
194 or \c NULL to create an unnamed stream class.
195 @returns Created default stream class, or \c NULL on error.
197 @postsuccessrefcountret1
199 @sa bt_stream_class_create_empty(): Creates an empty stream class.
201 extern struct bt_stream_class
*bt_stream_class_create(const char *name
);
204 @brief Returns the parent CTF IR trace class of the CTF IR stream
205 class \p stream_class.
207 It is possible that the stream class was not added to a trace class
208 yet, in which case this function returns \c NULL. You can add a
209 stream class to a trace class with
210 bt_trace_add_stream_class().
212 @param[in] stream_class Stream class of which to get the parent
214 @returns Parent trace class of \p stream_class,
215 or \c NULL if \p stream_class was not
216 added to a trace class yet or on error.
218 @prenotnull{stream_class}
219 @postrefcountsame{stream_class}
220 @postsuccessrefcountretinc
222 @sa bt_trace_add_stream_class(): Add a stream class to
225 extern struct bt_trace
*bt_stream_class_get_trace(
226 struct bt_stream_class
*stream_class
);
231 @name Properties functions
236 @brief Returns the name of the CTF IR stream class \p stream_class.
238 On success, \p stream_class remains the sole owner of the returned
241 @param[in] stream_class Stream class of which to get the name.
242 @returns Name of stream class \p stream_class, or
243 \c NULL if \p stream_class is unnamed or
246 @prenotnull{stream_class}
247 @postrefcountsame{stream_class}
249 @sa bt_stream_class_set_name(): Sets the name of a given
252 extern const char *bt_stream_class_get_name(
253 struct bt_stream_class
*stream_class
);
256 @brief Sets the name of the CTF IR stream class
257 \p stream_class to \p name, or resets the name of
260 If \p name is not \c NULL, it must be unique amongst the names of all
261 the stream classes of the trace class to which you eventually add
264 @param[in] stream_class Stream class of which to set the name.
265 @param[in] name Name of the stream class (copied on success), or
266 \c NULL to reset the name of \p stream_class
268 @returns 0 on success, or a negative value on error.
270 @prenotnull{stream_class}
271 @prehot{stream_class}
272 @postrefcountsame{stream_class}
274 @sa bt_stream_class_get_name(): Returns the name of a given
277 extern int bt_stream_class_set_name(
278 struct bt_stream_class
*stream_class
, const char *name
);
281 @brief Returns the numeric ID of the CTF IR stream class \p stream_class.
283 @param[in] stream_class Stream class of which to get the numeric ID.
284 @returns ID of stream class \p stream_class, or a
285 negative value on error.
287 @prenotnull{stream_class}
288 @postrefcountsame{stream_class}
290 @sa bt_stream_class_set_id(): Sets the numeric ID of a given
293 extern int64_t bt_stream_class_get_id(
294 struct bt_stream_class
*stream_class
);
297 @brief Sets the numeric ID of the CTF IR stream class
298 \p stream_class to \p id.
300 \p id must be unique amongst the IDs of all the stream classes
301 of the trace class to which you eventually add \p stream_class.
303 @param[in] stream_class Stream class of which to set the numeric ID.
304 @param[in] id ID of the stream class.
305 @returns 0 on success, or a negative value on error.
307 @prenotnull{stream_class}
308 @prehot{stream_class}
309 @pre \p id is lesser than or equal to 9223372036854775807 (\c INT64_MAX).
310 @postrefcountsame{stream_class}
312 @sa bt_stream_class_get_id(): Returns the numeric ID of a given
315 extern int bt_stream_class_set_id(
316 struct bt_stream_class
*stream_class
, uint64_t id
);
321 @name Contained field types functions
326 @brief Returns the packet context field type of the CTF IR stream class
329 @param[in] stream_class Stream class of which to get the packet
331 @returns Packet context field type of \p stream_class,
332 or \c NULL if \p stream_class has no packet context
333 field type or on error.
335 @prenotnull{stream_class}
336 @postrefcountsame{stream_class}
337 @post <strong>On success, if the return value is a field type</strong>, its
338 reference count is incremented.
340 @sa bt_stream_class_set_packet_context_type(): Sets the packet
341 context field type of a given stream class.
343 extern struct bt_field_type
*bt_stream_class_get_packet_context_type(
344 struct bt_stream_class
*stream_class
);
347 @brief Sets the packet context field type of the CTF IR stream class
348 \p stream_class to \p packet_context_type, or unsets the current packet
349 context field type from \p stream_class.
351 If \p packet_context_type is \c NULL, then this function unsets the current
352 packet context field type from \p stream_class, effectively making
353 \p stream_class a stream class without a packet context field type.
355 As of Babeltrace \btversion, if \p packet_context_type is not \c NULL,
356 \p packet_context_type \em must be a CTF IR structure field type object.
358 @param[in] stream_class Stream class of which to set the packet
360 @param[in] packet_context_type Packet context field type, or \c NULL to unset
361 the current packet context field type.
362 @returns 0 on success, or a negative value on error.
364 @prenotnull{stream_class}
365 @prehot{stream_class}
366 @pre <strong>\p packet_context_type, if not \c NULL</strong>, is a CTF IR
367 structure field type.
368 @postrefcountsame{stream_class}
369 @post <strong>On success, if \p packet_context_type is not \c NULL</strong>,
370 the reference count of \p packet_context_type is incremented.
372 @sa bt_stream_class_get_packet_context_type(): Returns the packet
373 context field type of a given stream class.
375 extern int bt_stream_class_set_packet_context_type(
376 struct bt_stream_class
*stream_class
,
377 struct bt_field_type
*packet_context_type
);
380 @brief Returns the event header field type of the CTF IR stream class
383 @param[in] stream_class Stream class of which to get the event header
385 @returns Event header field type of \p stream_class,
386 or \c NULL if \p stream_class has no event header field
389 @prenotnull{stream_class}
390 @postrefcountsame{stream_class}
391 @post <strong>On success, if the return value is a field type</strong>, its
392 reference count is incremented.
394 @sa bt_stream_class_set_event_header_type(): Sets the event
395 header field type of a given stream class.
397 extern struct bt_field_type
*
398 bt_stream_class_get_event_header_type(
399 struct bt_stream_class
*stream_class
);
402 @brief Sets the event header field type of the CTF IR stream class
403 \p stream_class to \p event_header_type, or unsets the current event
404 header field type from \p stream_class.
406 If \p event_header_type is \c NULL, then this function unsets the current
407 event header field type from \p stream_class, effectively making \p stream_class
408 a stream class without a event header field type.
410 As of Babeltrace \btversion, if \p event_header_type is not \c NULL,
411 \p event_header_type \em must be a CTF IR structure field type object.
413 @param[in] stream_class Stream class of which to set the event
415 @param[in] event_header_type Event header field type, or \c NULL to unset
416 the current event header field type.
417 @returns 0 on success, or a negative value on error.
419 @prenotnull{stream_class}
420 @prehot{stream_class}
421 @pre <strong>\p event_header_type, if not \c NULL</strong>, is a CTF IR
422 structure field type.
423 @postrefcountsame{stream_class}
424 @post <strong>On success, if \p event_header_type is not \c NULL</strong>,
425 the reference count of \p event_header_type is incremented.
427 @sa bt_stream_class_get_event_header_type(): Returns the event
428 header field type of a given stream class.
430 extern int bt_stream_class_set_event_header_type(
431 struct bt_stream_class
*stream_class
,
432 struct bt_field_type
*event_header_type
);
435 @brief Returns the event context field type of the CTF IR stream class
438 @param[in] stream_class Stream class of which to get the event context
440 @returns Event context field type of \p stream_class,
441 or \c NULL if \p stream_class has no event context field
444 @prenotnull{stream_class}
445 @postrefcountsame{stream_class}
446 @post <strong>On success, if the return value is a field type</strong>,
447 its reference count is incremented.
450 @sa bt_stream_class_set_event_context_type(): Sets the event
451 context field type of a given stream class.
453 extern struct bt_field_type
*
454 bt_stream_class_get_event_context_type(
455 struct bt_stream_class
*stream_class
);
458 @brief Sets the event context field type of the CTF IR stream class
459 \p stream_class to \p event_context_type, or unsets the current event
460 context field type from \p stream_class.
462 If \p event_context_type is \c NULL, then this function unsets the current
463 event context field type from \p stream_class, effectively making \p
464 stream_class a stream class without a event context field type.
466 As of Babeltrace \btversion, if \p event_context_type is not \c NULL,
467 \p event_context_type \em must be a CTF IR structure field type object.
469 @param[in] stream_class Stream class of which to set the packet
471 @param[in] event_context_type Event context field type, or \c NULL to unset
472 the current event context field type.
473 @returns 0 on success, or a negative value on error.
475 @prenotnull{stream_class}
476 @prehot{stream_class}
477 @pre <strong>\p event_context_type, if not \c NULL</strong>, is a CTF IR
478 structure field type.
479 @postrefcountsame{stream_class}
480 @post <strong>On success, if \p event_context_type is not \c NULL</strong>,
481 the reference count of \p event_context_type is incremented.
483 @sa bt_stream_class_get_event_context_type(): Returns the event context
484 field type of a given stream class.
486 extern int bt_stream_class_set_event_context_type(
487 struct bt_stream_class
*stream_class
,
488 struct bt_field_type
*event_context_type
);
493 @name Event class children functions
498 @brief Returns the number of event classes contained in the
499 CTF IR stream class \p stream_class.
501 @param[in] stream_class Stream class of which to get the number
502 of children event classes.
503 @returns Number of children event classes
504 contained in \p stream_class, or
505 a negative value on error.
507 @prenotnull{stream_class}
508 @postrefcountsame{stream_class}
510 extern int64_t bt_stream_class_get_event_class_count(
511 struct bt_stream_class
*stream_class
);
514 @brief Returns the event class at index \p index in the CTF IR stream
515 class \p stream_class.
517 @param[in] stream_class Stream class of which to get the event class.
518 @param[in] index Index of the event class to find.
519 @returns Event class at index \p index, or \c NULL
522 @prenotnull{stream_class}
523 @pre \p index is lesser than the number of event classes contained in the
524 stream class \p stream_class (see
525 bt_stream_class_get_event_class_count()).
526 @postrefcountsame{stream_class}
527 @postsuccessrefcountretinc
529 @sa bt_stream_class_get_event_class_by_id(): Finds an event class
532 extern struct bt_event_class
*bt_stream_class_get_event_class_by_index(
533 struct bt_stream_class
*stream_class
, uint64_t index
);
536 @brief Returns the event class with ID \c id found in the CTF IR stream
537 class \p stream_class.
539 @param[in] stream_class Stream class of which to get the event class.
540 @param[in] id ID of the event class to find.
541 @returns Event class with ID \p id, or \c NULL
544 @prenotnull{stream_class}
545 @postrefcountsame{stream_class}
546 @postsuccessrefcountretinc
548 extern struct bt_event_class
*bt_stream_class_get_event_class_by_id(
549 struct bt_stream_class
*stream_class
, uint64_t id
);
552 @brief Adds the CTF IR event class \p event_class to the
553 CTF IR stream class \p stream_class.
555 On success, \p event_class becomes the child of \p stream_class.
557 You can only add a given event class to one stream class.
559 You can call this function even if \p stream_class is frozen. Adding
560 event classes is the only operation that is permitted
561 on a frozen stream class.
563 This function tries to resolve the needed
564 \link ctfirfieldtypes CTF IR field type\endlink of the dynamic field
565 types that are found anywhere in the context or payload field
566 types of \p event_class. If any automatic resolving fails:
568 - If the needed field type should be found in one of the root field
569 types of \p event_class or \p stream_class, this function fails.
570 - If \p stream_class is the child of a
571 \link ctfirtraceclass CTF IR trace class\endlink (it was added
572 with bt_trace_add_stream_class()), this function fails.
573 - If \p stream_class is not the child of a trace class yet, the
574 automatic resolving is reported to the next call to
575 bt_trace_add_stream_class() with \p stream_class.
577 @param[in] stream_class Stream class to which to add \p event_class.
578 @param[in] event_class Event class to add to \p stream_class.
579 @returns 0 on success, or a negative value on error.
581 @prenotnull{stream_class}
582 @prenotnull{event_class}
584 @postrefcountsame{stream_class}
585 @postsuccessrefcountinc{event_class}
586 @postsuccessfrozen{event_class}
588 extern int bt_stream_class_add_event_class(
589 struct bt_stream_class
*stream_class
,
590 struct bt_event_class
*event_class
);
600 @brief Accepts the visitor \p visitor to visit the hierarchy of the
601 CTF IR stream class \p stream_class.
603 This function traverses the hierarchy of \p stream_class in pre-order
604 and calls \p visitor on each element.
606 The stream class itself is visited first, and then all its children
609 @param[in] stream_class Stream class to visit.
610 @param[in] visitor Visiting function.
611 @param[in] data User data.
612 @returns 0 on success, or a negative value on error.
614 @prenotnull{stream_class}
617 extern int bt_stream_class_visit(struct bt_stream_class
*stream_class
,
618 bt_visitor visitor
, void *data
);
624 /* Pre-2.0 CTF writer compatibility */
625 #define bt_ctf_stream_class bt_stream_class
626 #define bt_ctf_stream_class_create bt_stream_class_create
627 #define bt_ctf_stream_class_add_event_class bt_stream_class_add_event_class
628 #define bt_ctf_stream_class_get_packet_context_type bt_stream_class_get_packet_context_type
634 #endif /* BABELTRACE_CTF_IR_STREAM_CLASS_H */
This page took 0.042604 seconds and 4 git commands to generate.