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
34 #include <babeltrace/ctf-ir/visitor.h>
41 @defgroup ctfirstreamclass CTF IR stream class
43 @brief CTF IR stream class.
46 #include <babeltrace/ctf-ir/stream-class.h>
50 See \ref ctfirwriterstreamclass which documents additional CTF IR stream
51 class functions exclusive to the CTF IR writer mode.
53 A CTF IR <strong><em>stream class</em></strong> is a template that you
54 can use to create concrete \link ctfirstream CTF IR streams\endlink.
56 A stream class has the following properties, both of which \em must
57 be unique amongst all the stream classes contained in the same
58 \link ctfirtraceclass CTF IR trace class\endlink:
63 In the Babeltrace CTF IR system, a \link ctfirtraceclass trace class\endlink
64 contains zero or more stream classes,
65 and a stream class contains zero or more
66 \link ctfireventclass event classes\endlink.
67 You can add an event class
68 to a stream class with bt_ctf_stream_class_add_event_class().
69 You can add a stream class to a trace class with
70 bt_ctf_trace_add_stream_class().
72 A stream class owns three \link ctfirfieldtypes field types\endlink:
74 - An optional <strong>stream packet context</strong> field type, which
75 represents the \c stream.packet.context CTF scope.
76 - An optional <strong>stream event header</strong> field type, which
77 represents the \c stream.event.header CTF scope.
78 - An optional <strong>stream event context</strong> field type, which
79 represents the \c stream.event.context CTF scope.
81 Those three field types \em must be structure field types as of
82 Babeltrace \btversion.
84 As per the CTF specification, the event header field type \em must
85 contain a field named \c id if the stream class contains more than one
88 As a reminder, here's the structure of a CTF packet:
92 Before you can create a stream from a stream class with
93 bt_ctf_stream_create(), you \em must add the prepared stream class to a
94 trace class by calling bt_ctf_trace_add_stream_class().
96 As with any Babeltrace object, CTF IR stream class objects have
97 <a href="https://en.wikipedia.org/wiki/Reference_counting">reference
98 counts</a>. See \ref refs to learn more about the reference counting
99 management of Babeltrace objects.
101 The following functions \em freeze their stream class parameter on
104 - bt_ctf_trace_add_stream_class()
105 - bt_ctf_event_create()
106 - bt_ctf_writer_create_stream()
107 (\link ctfirwriter CTF IR writer\endlink mode only)
109 You cannot modify a frozen stream class: it is considered immutable,
112 - Adding an event class to it with
113 bt_ctf_stream_class_add_event_class().
114 - \link refs Reference counting\endlink.
119 @sa ctfirwriterstreamclass
122 @brief CTF IR stream class type and functions.
125 @addtogroup ctfirstreamclass
130 @struct bt_ctf_stream_class
131 @brief A CTF IR stream class.
134 struct bt_ctf_stream_class
;
135 struct bt_ctf_event_class
;
139 @name Creation and parent access functions
144 @brief Creates a default CTF IR stream class named \p name, or a
145 default unnamed stream class if \p name is \c NULL.
147 On success, the packet context field type of the created stream class
148 has the following fields:
150 - <code>timestamp_begin</code>: a 64-bit unsigned integer field type.
151 - <code>timestamp_end</code>: a 64-bit unsigned integer field type.
152 - <code>content_size</code>: a 64-bit unsigned integer field type.
153 - <code>packet_size</code>: a 64-bit unsigned integer field type.
154 - <code>events_discarded</code>: a 64-bit unsigned integer field type.
156 On success, the event header field type of the created stream class
157 has the following fields:
159 - <code>code</code>: a 32-bit unsigned integer field type.
160 - <code>timestamp</code>: a 64-bit unsigned integer field type.
162 You can modify those default field types after the stream class is
163 created with bt_ctf_stream_class_set_packet_context_type() and
164 bt_ctf_stream_class_set_event_header_type().
166 @param[in] name Name of the stream class to create (can be \c NULL to
167 create an unnamed stream class).
168 @returns Created stream class, or \c NULL on error.
170 @postsuccessrefcountret1
172 extern struct bt_ctf_stream_class
*bt_ctf_stream_class_create(const char *name
);
175 @brief Returns the parent CTF IR trace class of the CTF IR stream
176 class \p stream_class.
178 It is possible that the stream class was not added to a trace class
179 yet, in which case this function returns \c NULL. You can add a
180 stream class to a trace class with
181 bt_ctf_trace_add_stream_class().
183 @param[in] stream_class Stream class of which to get the parent
185 @returns Parent trace class of \p stream_class,
186 or \c NULL if \p stream_class was not
187 added to a trace class yet or on error.
189 @prenotnull{stream_class}
190 @postrefcountsame{stream_class}
191 @postsuccessrefcountretinc
193 @sa bt_ctf_trace_add_stream_class(): Add a stream class to
196 extern struct bt_ctf_trace
*bt_ctf_stream_class_get_trace(
197 struct bt_ctf_stream_class
*stream_class
);
202 @name Properties functions
207 @brief Returns the name of the CTF IR stream class \p stream_class.
209 On success, \p stream_class remains the sole owner of the returned
212 @param[in] stream_class Stream class of which to get the name.
213 @returns Name of stream class \p stream_class, or
214 \c NULL if \p stream_class is unnamed or
217 @prenotnull{stream_class}
218 @postrefcountsame{stream_class}
220 @sa bt_ctf_stream_class_set_name(): Sets the name of a given
223 extern const char *bt_ctf_stream_class_get_name(
224 struct bt_ctf_stream_class
*stream_class
);
227 @brief Sets the name of the CTF IR stream class
228 \p stream_class to \p name.
230 \p name must be unique amongst the names of all the stream classes
231 of the trace class to which you eventually add \p stream_class.
233 @param[in] stream_class Stream class of which to set the name.
234 @param[in] name Name of the stream class (copied on success).
235 @returns 0 on success, or a negative value on error.
237 @prenotnull{stream_class}
239 @prehot{stream_class}
240 @postrefcountsame{stream_class}
242 @sa bt_ctf_stream_class_get_name(): Returns the name of a given
245 extern int bt_ctf_stream_class_set_name(
246 struct bt_ctf_stream_class
*stream_class
, const char *name
);
249 @brief Returns the numeric ID of the CTF IR stream class \p stream_class.
251 @param[in] stream_class Stream class of which to get the numeric ID.
252 @returns ID of stream class \p stream_class, or a
253 negative value on error.
255 @prenotnull{stream_class}
256 @postrefcountsame{stream_class}
258 @sa bt_ctf_stream_class_set_id(): Sets the numeric ID of a given
261 extern int64_t bt_ctf_stream_class_get_id(
262 struct bt_ctf_stream_class
*stream_class
);
265 @brief Sets the numeric ID of the CTF IR stream class
266 \p stream_class to \p id.
268 \p id must be unique amongst the IDs of all the stream classes
269 of the trace class to which you eventually add \p stream_class.
271 @param[in] stream_class Stream class of which to set the numeric ID.
272 @param[in] id ID of the stream class.
273 @returns 0 on success, or a negative value on error.
275 @prenotnull{stream_class}
276 @prehot{stream_class}
277 @postrefcountsame{stream_class}
279 @sa bt_ctf_stream_class_get_id(): Returns the numeric ID of a given
282 extern int bt_ctf_stream_class_set_id(
283 struct bt_ctf_stream_class
*stream_class
, uint32_t id
);
288 @name Contained field types functions
293 @brief Returns the packet context field type of the CTF IR stream class
296 @param[in] stream_class Stream class of which to get the packet
298 @returns Packet context field type of \p stream_class,
301 @prenotnull{stream_class}
302 @postrefcountsame{stream_class}
303 @postsuccessrefcountretinc
305 @sa bt_ctf_stream_class_set_packet_context_type(): Sets the packet
306 context field type of a given stream class.
308 extern struct bt_ctf_field_type
*bt_ctf_stream_class_get_packet_context_type(
309 struct bt_ctf_stream_class
*stream_class
);
312 @brief Sets the packet context field type of the CTF IR stream class
313 \p stream_class to \p packet_context_type.
315 As of Babeltrace \btversion, \p packet_context_type \em must be a
316 CTF IR structure field type object.
318 @param[in] stream_class Stream class of which to set the packet
320 @param[in] packet_context_type Packet context field type.
321 @returns 0 on success, or a negative value on error.
323 @prenotnull{stream_class}
324 @prenotnull{packet_context_type}
325 @prehot{stream_class}
326 @preisstructft{packet_context_type}
327 @postrefcountsame{stream_class}
328 @postsuccessrefcountinc{packet_context_type}
330 @sa bt_ctf_stream_class_get_packet_context_type(): Returns the packet
331 context field type of a given stream class.
333 extern int bt_ctf_stream_class_set_packet_context_type(
334 struct bt_ctf_stream_class
*stream_class
,
335 struct bt_ctf_field_type
*packet_context_type
);
338 @brief Returns the event header field type of the CTF IR stream class
341 @param[in] stream_class Stream class of which to get the event header
343 @returns Event header field type of \p stream_class,
346 @prenotnull{stream_class}
347 @postrefcountsame{stream_class}
348 @postsuccessrefcountretinc
350 @sa bt_ctf_stream_class_set_event_header_type(): Sets the event
351 header field type of a given stream class.
353 extern struct bt_ctf_field_type
*
354 bt_ctf_stream_class_get_event_header_type(
355 struct bt_ctf_stream_class
*stream_class
);
358 @brief Sets the event header field type of the CTF IR stream class
359 \p stream_class to \p event_header_type.
361 As of Babeltrace \btversion, \p event_header_type \em must be a
362 CTF IR structure field type object.
364 @param[in] stream_class Stream class of which to set the event
366 @param[in] event_header_type Event header field type.
367 @returns 0 on success, or a negative value on error.
369 @prenotnull{stream_class}
370 @prenotnull{event_header_type}
371 @prehot{stream_class}
372 @preisstructft{event_header_type}
373 @postrefcountsame{stream_class}
374 @postsuccessrefcountinc{event_header_type}
376 @sa bt_ctf_stream_class_get_event_header_type(): Returns the event
377 header field type of a given stream class.
379 extern int bt_ctf_stream_class_set_event_header_type(
380 struct bt_ctf_stream_class
*stream_class
,
381 struct bt_ctf_field_type
*event_header_type
);
384 @brief Returns the per-stream class event context field type of the
385 CTF IR stream class \p stream_class.
387 @param[in] stream_class Stream class of which to get the per-stream
388 class event context field type.
389 @returns Per-stream class event context field type of
390 \p stream_class, or \c NULL on error.
392 @prenotnull{stream_class}
393 @postrefcountsame{stream_class}
394 @postsuccessrefcountretinc
396 @sa bt_ctf_stream_class_set_event_context_type(): Sets the per-stream
397 class event context field type of a given stream class.
399 extern struct bt_ctf_field_type
*
400 bt_ctf_stream_class_get_event_context_type(
401 struct bt_ctf_stream_class
*stream_class
);
404 @brief Sets the per-stream class event context field type of the CTF
405 IR stream class \p stream_class to \p event_context_type.
407 As of Babeltrace \btversion, \p event_context_type \em must be a
408 CTF IR structure field type object.
410 @param[in] stream_class Stream class of which to set the
411 per-stream class event context
413 @param[in] event_context_type Per-stream class event context context
415 @returns 0 on success, or a negative value on error.
417 @prenotnull{stream_class}
418 @prenotnull{event_context_type}
419 @prehot{stream_class}
420 @preisstructft{event_context_type}
421 @postrefcountsame{stream_class}
422 @postsuccessrefcountinc{event_context_type}
424 @sa bt_ctf_stream_class_get_event_context_type(): Returns the per-stream
425 class event context field type of a given stream class.
427 extern int bt_ctf_stream_class_set_event_context_type(
428 struct bt_ctf_stream_class
*stream_class
,
429 struct bt_ctf_field_type
*event_context_type
);
434 @name Event class children functions
439 @brief Returns the number of event classes contained in the
440 CTF IR stream class \p stream_class.
442 @param[in] stream_class Stream class of which to get the number
443 of children event classes.
444 @returns Number of children event classes
445 contained in \p stream_class, or
446 a negative value on error.
448 @prenotnull{stream_class}
449 @postrefcountsame{stream_class}
451 extern int bt_ctf_stream_class_get_event_class_count(
452 struct bt_ctf_stream_class
*stream_class
);
455 @brief Returns the event class at index \p index in the CTF IR stream
456 class \p stream_class.
458 @param[in] stream_class Stream class of which to get the event class.
459 @param[in] index Index of the event class to find.
460 @returns Event class at index \p index, or \c NULL
463 @prenotnull{stream_class}
464 @pre \p index is lesser than the number of event classes contained in the
465 stream class \p stream_class (see
466 bt_ctf_stream_class_get_event_class_count()).
467 @postrefcountsame{stream_class}
468 @postsuccessrefcountretinc
470 @sa bt_ctf_stream_class_get_event_class_by_id(): Finds an event class
472 @sa bt_ctf_stream_class_get_event_class_by_name(): Finds an event class
475 extern struct bt_ctf_event_class
*bt_ctf_stream_class_get_event_class(
476 struct bt_ctf_stream_class
*stream_class
, int index
);
479 @brief Returns the event class named \c name found in the CTF IR stream
480 class \p stream_class.
482 @param[in] stream_class Stream class of which to get the event class.
483 @param[in] name Name of the event class to find.
484 @returns Event class named \p name, or \c NULL
487 @prenotnull{stream_class}
489 @postrefcountsame{stream_class}
490 @postsuccessrefcountretinc
492 @sa bt_ctf_stream_class_get_event_class_by_id(): Finds an event class
495 extern struct bt_ctf_event_class
*bt_ctf_stream_class_get_event_class_by_name(
496 struct bt_ctf_stream_class
*stream_class
, const char *name
);
499 @brief Returns the event class with ID \c id found in the CTF IR stream
500 class \p stream_class.
502 @param[in] stream_class Stream class of which to get the event class.
503 @param[in] id ID of the event class to find.
504 @returns Event class with ID \p id, or \c NULL
507 @prenotnull{stream_class}
508 @postrefcountsame{stream_class}
509 @postsuccessrefcountretinc
511 @sa bt_ctf_stream_class_get_event_class_by_name(): Finds an event class
514 extern struct bt_ctf_event_class
*bt_ctf_stream_class_get_event_class_by_id(
515 struct bt_ctf_stream_class
*stream_class
, uint32_t id
);
518 @brief Adds the CTF IR event class \p event_class to the
519 CTF IR stream class \p stream_class.
521 On success, \p event_class becomes the child of \p stream_class.
523 You can only add a given event class to one stream class.
525 You can call this function even if \p stream_class is frozen. Adding
526 event classes is the only operation that is permitted
527 on a frozen stream class.
529 This function tries to resolve the needed
530 \link ctfirfieldtypes CTF IR field type\endlink of the dynamic field
531 types that are found anywhere in the context or payload field
532 types of \p event_class. If any automatic resolving fails:
534 - If the needed field type should be found in one of the root field
535 types of \p event_class or \p stream_class, this function fails.
536 - If \p stream_class is the child of a
537 \link ctfirtraceclass CTF IR trace class\endlink (it was added
538 with bt_ctf_trace_add_stream_class()), this function fails.
539 - If \p stream_class is not the child of a trace class yet, the
540 automatic resolving is reported to the next call to
541 bt_ctf_trace_add_stream_class() with \p stream_class.
543 @param[in] stream_class Stream class to which to add \p event_class.
544 @param[in] event_class Event class to add to \p stream_class.
545 @returns 0 on success, or a negative value on error.
547 @prenotnull{stream_class}
548 @prenotnull{event_class}
550 @postrefcountsame{stream_class}
551 @postsuccessrefcountinc{event_class}
552 @postsuccessfrozen{event_class}
554 extern int bt_ctf_stream_class_add_event_class(
555 struct bt_ctf_stream_class
*stream_class
,
556 struct bt_ctf_event_class
*event_class
);
566 @brief Accepts the visitor \p visitor to visit the hierarchy of the
567 CTF IR stream class \p stream_class.
569 This function traverses the hierarchy of \p stream_class in pre-order
570 and calls \p visitor on each element.
572 The stream class itself is visited first, and then all its children
575 @param[in] stream_class Stream class to visit.
576 @param[in] visitor Visiting function.
577 @param[in] data User data.
578 @returns 0 on success, or a negative value on error.
580 @prenotnull{stream_class}
583 extern int bt_ctf_stream_class_visit(struct bt_ctf_stream_class
*stream_class
,
584 bt_ctf_visitor visitor
, void *data
);
590 // TODO: document for writer
591 extern struct bt_ctf_clock
*bt_ctf_stream_class_get_clock(
592 struct bt_ctf_stream_class
*stream_class
);
598 #endif /* BABELTRACE_CTF_IR_STREAM_CLASS_H */
This page took 0.051639 seconds and 6 git commands to generate.