Fix: allow NULL (unnamed) in bt_ctf_stream_class_{get,set}_name()
[babeltrace.git] / include / babeltrace / ctf-ir / stream-class.h
index 233801475124917c88555873f5f2fd0c93f0e5c8..64400f5201e794bf17c300ae6f66f60a4f664c3d 100644 (file)
@@ -42,9 +42,13 @@ extern "C" {
 @ingroup ctfir
 @brief CTF IR stream class.
 
+@code
+#include <babeltrace/ctf-ir/stream-class.h>
+@endcode
+
 @note
-See \ref ctfirwriterstreamclass which documents additional CTF IR stream
-class functions exclusive to the CTF IR writer mode.
+See \ref ctfwriterstreamclass which documents additional CTF IR stream
+class functions exclusive to the CTF writer mode.
 
 A CTF IR <strong><em>stream class</em></strong> is a template that you
 can use to create concrete \link ctfirstream CTF IR streams\endlink.
@@ -100,19 +104,22 @@ success:
 - bt_ctf_trace_add_stream_class()
 - bt_ctf_event_create()
 - bt_ctf_writer_create_stream()
-  (\link ctfirwriter CTF IR writer\endlink mode only)
+  (\link ctfwriter CTF writer\endlink mode only)
 
 You cannot modify a frozen stream class: it is considered immutable,
 except for:
 
 - Adding an event class to it with
-  bt_ctf_stream_class_add_event_class().
+  bt_ctf_stream_class_add_event_class(). If the stream class's parent
+  \link ctfirtraceclass trace class\endlink is static, however,
+  you cannot call bt_ctf_stream_class_add_event_class()
+  (see bt_ctf_trace_is_static() and bt_ctf_trace_set_is_static()).
 - \link refs Reference counting\endlink.
 
 @sa ctfirstream
 @sa ctfireventclass
 @sa ctfirtraceclass
-@sa ctfirwriterstreamclass
+@sa ctfwriterstreamclass
 
 @file
 @brief CTF IR stream class type and functions.
@@ -136,6 +143,28 @@ struct bt_ctf_clock;
 @{
 */
 
+/**
+@brief Creates an empty CTF IR stream class named \p name, or an
+       unnamed empty stream class if \p name is \c NULL.
+
+On success, the packet context, event header, and event context field
+types are empty structure field types. You can modify those default
+field types after the stream class is created with
+bt_ctf_stream_class_set_packet_context_type(),
+bt_ctf_stream_class_set_event_header_type(), and
+bt_ctf_stream_class_set_event_context_type().
+
+@param[in] name        Name of the stream class to create (copied on success),
+               or \c NULL to create an unnamed stream class.
+@returns       Created empty stream class, or \c NULL on error.
+
+@postsuccessrefcountret1
+
+@sa bt_ctf_stream_class_create(): Creates a default stream class.
+*/
+extern struct bt_ctf_stream_class *bt_ctf_stream_class_create_empty(
+               const char *name);
+
 /**
 @brief Creates a default CTF IR stream class named \p nameĀ­, or a
        default unnamed stream class if \p name is \c NULL.
@@ -159,11 +188,13 @@ You can modify those default field types after the stream class is
 created with bt_ctf_stream_class_set_packet_context_type() and
 bt_ctf_stream_class_set_event_header_type().
 
-@param[in] name        Name of the stream class to create (can be \c NULL to
-               create an unnamed stream class).
-@returns       Created stream class, or \c NULL on error.
+@param[in] name        Name of the stream class to create (copied on success),
+               or \c NULL to create an unnamed stream class.
+@returns       Created default stream class, or \c NULL on error.
 
 @postsuccessrefcountret1
+
+@sa bt_ctf_stream_class_create_empty(): Creates an empty stream class.
 */
 extern struct bt_ctf_stream_class *bt_ctf_stream_class_create(const char *name);
 
@@ -183,6 +214,7 @@ bt_ctf_trace_add_stream_class().
                        added to a trace class yet or on error.
 
 @prenotnull{stream_class}
+@postrefcountsame{stream_class}
 @postsuccessrefcountretinc
 
 @sa bt_ctf_trace_add_stream_class(): Add a stream class to
@@ -220,17 +252,20 @@ extern const char *bt_ctf_stream_class_get_name(
 
 /**
 @brief Sets the name of the CTF IR stream class
-       \p stream_class to \p name.
+       \p stream_class to \p name, or resets the name of
+       \p stream_class.
 
-\p name must be unique amongst the names of all the stream classes
-of the trace class to which you eventually add \p stream_class.
+If \p name is not \c NULL, it must be unique amongst the names of all
+the stream classes of the trace class to which you eventually add
+\p stream_class.
 
 @param[in] stream_class        Stream class of which to set the name.
-@param[in] name                Name of the stream class (copied on success).
+@param[in] name                Name of the stream class (copied on success), or
+                       \c NULL to reset the name of \p stream_class
+                       (make it unnamed).
 @returns               0 on success, or a negative value on error.
 
 @prenotnull{stream_class}
-@prenotnull{name}
 @prehot{stream_class}
 @postrefcountsame{stream_class}
 
@@ -269,13 +304,14 @@ of the trace class to which you eventually add \p stream_class.
 
 @prenotnull{stream_class}
 @prehot{stream_class}
+@pre \p id is lesser than or equal to 9223372036854775807 (\c INT64_MAX).
 @postrefcountsame{stream_class}
 
 @sa bt_ctf_stream_class_get_id(): Returns the numeric ID of a given
        stream class.
 */
 extern int bt_ctf_stream_class_set_id(
-               struct bt_ctf_stream_class *stream_class, uint32_t id);
+               struct bt_ctf_stream_class *stream_class, uint64_t id);
 
 /** @} */
 
@@ -291,10 +327,13 @@ extern int bt_ctf_stream_class_set_id(
 @param[in] stream_class        Stream class of which to get the packet
                        context field type.
 @returns               Packet context field type of \p stream_class,
-                       or \c NULL on error.
+                       or \c NULL if \p stream_class has no packet context
+                       field type or on error.
 
 @prenotnull{stream_class}
-@postsuccessrefcountretinc
+@postrefcountsame{stream_class}
+@post <strong>On success, if the return value is a field type</strong>, its
+       reference count is incremented.
 
 @sa bt_ctf_stream_class_set_packet_context_type(): Sets the packet
        context field type of a given stream class.
@@ -304,22 +343,29 @@ extern struct bt_ctf_field_type *bt_ctf_stream_class_get_packet_context_type(
 
 /**
 @brief Sets the packet context field type of the CTF IR stream class
-       \p stream_class to \p packet_context_type.
+       \p stream_class to \p packet_context_type, or unsets the current packet
+       context field type from \p stream_class.
+
+If \p packet_context_type is \c NULL, then this function unsets the current
+packet context field type from \p stream_class, effectively making
+\p stream_class a stream class without a packet context field type.
 
-As of Babeltrace \btversion, \p packet_context_type \em must be a
-CTF IR structure field type object.
+As of Babeltrace \btversion, if \p packet_context_type is not \c NULL,
+\p packet_context_type \em must be a CTF IR structure field type object.
 
 @param[in] stream_class                Stream class of which to set the packet
                                context field type.
-@param[in] packet_context_type Packet context field type.
+@param[in] packet_context_type Packet context field type, or \c NULL to unset
+                               the current packet context field type.
 @returns                       0 on success, or a negative value on error.
 
 @prenotnull{stream_class}
-@prenotnull{packet_context_type}
 @prehot{stream_class}
-@preisstructft{packet_context_type}
+@pre <strong>\p packet_context_type, if not \c NULL</strong>, is a CTF IR
+       structure field type.
 @postrefcountsame{stream_class}
-@postsuccessrefcountinc{packet_context_type}
+@post <strong>On success, if \p packet_context_type is not \c NULL</strong>,
+       the reference count of \p packet_context_type is incremented.
 
 @sa bt_ctf_stream_class_get_packet_context_type(): Returns the packet
        context field type of a given stream class.
@@ -335,10 +381,13 @@ extern int bt_ctf_stream_class_set_packet_context_type(
 @param[in] stream_class        Stream class of which to get the event header
                        field type.
 @returns               Event header field type of \p stream_class,
-                       or \c NULL on error.
+                       or \c NULL if \p stream_class has no event header field
+                       type or on error.
 
 @prenotnull{stream_class}
-@postsuccessrefcountretinc
+@postrefcountsame{stream_class}
+@post <strong>On success, if the return value is a field type</strong>, its
+       reference count is incremented.
 
 @sa bt_ctf_stream_class_set_event_header_type(): Sets the event
        header field type of a given stream class.
@@ -349,22 +398,29 @@ bt_ctf_stream_class_get_event_header_type(
 
 /**
 @brief Sets the event header field type of the CTF IR stream class
-       \p stream_class to \p event_header_type.
+       \p stream_class to \p event_header_type, or unsets the current event
+       header field type from \p stream_class.
+
+If \p event_header_type is \c NULL, then this function unsets the current
+event header field type from \p stream_class, effectively making \p stream_class
+a stream class without a event header field type.
 
-As of Babeltrace \btversion, \p event_header_type \em must be a
-CTF IR structure field type object.
+As of Babeltrace \btversion, if \p event_header_type is not \c NULL,
+\p event_header_type \em must be a CTF IR structure field type object.
 
 @param[in] stream_class                Stream class of which to set the event
                                header field type.
-@param[in] event_header_type   Event header field type.
+@param[in] event_header_type   Event header field type, or \c NULL to unset
+                               the current event header field type.
 @returns                       0 on success, or a negative value on error.
 
 @prenotnull{stream_class}
-@prenotnull{event_header_type}
 @prehot{stream_class}
-@preisstructft{event_header_type}
+@pre <strong>\p event_header_type, if not \c NULL</strong>, is a CTF IR
+       structure field type.
 @postrefcountsame{stream_class}
-@postsuccessrefcountinc{event_header_type}
+@post <strong>On success, if \p event_header_type is not \c NULL</strong>,
+       the reference count of \p event_header_type is incremented.
 
 @sa bt_ctf_stream_class_get_event_header_type(): Returns the event
        header field type of a given stream class.
@@ -374,47 +430,56 @@ extern int bt_ctf_stream_class_set_event_header_type(
                struct bt_ctf_field_type *event_header_type);
 
 /**
-@brief Returns the per-stream class event context field type of the
-       CTF IR stream class \p stream_class.
+@brief Returns the event context field type of the CTF IR stream class
+       \p stream_class.
 
-@param[in] stream_class        Stream class of which to get the per-stream
-                       class event context field type.
-@returns               Per-stream class event context field type of
-                       \p stream_class, or \c NULL on error.
+@param[in] stream_class        Stream class of which to get the event context
+                       field type.
+@returns               Event context field type of \p stream_class,
+                       or \c NULL if \p stream_class has no event context field
+                       type or on error.
 
 @prenotnull{stream_class}
-@postsuccessrefcountretinc
+@postrefcountsame{stream_class}
+@post <strong>On success, if the return value is a field type</strong>,
+       its reference count is incremented.
+
 
-@sa bt_ctf_stream_class_set_event_context_type(): Sets the per-stream
-       class event context field type of a given stream class.
+@sa bt_ctf_stream_class_set_event_context_type(): Sets the event
+       context field type of a given stream class.
 */
 extern struct bt_ctf_field_type *
 bt_ctf_stream_class_get_event_context_type(
                struct bt_ctf_stream_class *stream_class);
 
 /**
-@brief Sets the per-stream class event context field type of the CTF
-       IR stream class \p stream_class to \p event_context_type.
+@brief Sets the event context field type of the CTF IR stream class
+       \p stream_class to \p event_context_type, or unsets the current event
+       context field type from \p stream_class.
+
+If \p event_context_type is \c NULL, then this function unsets the current
+event context field type from \p stream_class, effectively making \p
+stream_class a stream class without a event context field type.
 
-As of Babeltrace \btversion, \p event_context_type \em must be a
-CTF IR structure field type object.
+As of Babeltrace \btversion, if \p event_context_type is not \c NULL,
+\p event_context_type \em must be a CTF IR structure field type object.
 
-@param[in] stream_class                Stream class of which to set the
-                               per-stream class event context
-                               field type.
-@param[in] event_context_type  Per-stream class event context context
-                               field type.
+@param[in] stream_class                Stream class of which to set the packet
+                               context field type.
+@param[in] event_context_type  Event context field type, or \c NULL to unset
+                               the current event context field type.
 @returns                       0 on success, or a negative value on error.
 
 @prenotnull{stream_class}
-@prenotnull{event_context_type}
 @prehot{stream_class}
-@preisstructft{event_context_type}
+@pre <strong>\p event_context_type, if not \c NULL</strong>, is a CTF IR
+       structure field type.
 @postrefcountsame{stream_class}
-@postsuccessrefcountinc{event_context_type}
+@post <strong>On success, if \p event_context_type is not \c NULL</strong>,
+       the reference count of \p event_context_type is incremented.
 
-@sa bt_ctf_stream_class_get_event_context_type(): Returns the per-stream
-       class event context field type of a given stream class.
+@sa bt_ctf_stream_class_get_event_context_type(): Returns the event context
+       field type of a given stream class.
 */
 extern int bt_ctf_stream_class_set_event_context_type(
                struct bt_ctf_stream_class *stream_class,
@@ -440,7 +505,7 @@ extern int bt_ctf_stream_class_set_event_context_type(
 @prenotnull{stream_class}
 @postrefcountsame{stream_class}
 */
-extern int bt_ctf_stream_class_get_event_class_count(
+extern int64_t bt_ctf_stream_class_get_event_class_count(
                struct bt_ctf_stream_class *stream_class);
 
 /**
@@ -459,33 +524,11 @@ extern int bt_ctf_stream_class_get_event_class_count(
 @postrefcountsame{stream_class}
 @postsuccessrefcountretinc
 
-@sa bt_ctf_stream_class_get_event_class_by_id(): Finds an event class
-       by ID.
-@sa bt_ctf_stream_class_get_event_class_by_name(): Finds an event class
-       by name.
-*/
-extern struct bt_ctf_event_class *bt_ctf_stream_class_get_event_class(
-               struct bt_ctf_stream_class *stream_class, int index);
-
-/**
-@brief  Returns the event class named \c name found in the CTF IR stream
-       class \p stream_class.
-
-@param[in] stream_class        Stream class of which to get the event class.
-@param[in] name                Name of the event class to find.
-@returns               Event class named \p name, or \c NULL
-                       on error.
-
-@prenotnull{stream_class}
-@prenotnull{name}
-@postrefcountsame{stream_class}
-@postsuccessrefcountretinc
-
 @sa bt_ctf_stream_class_get_event_class_by_id(): Finds an event class
        by ID.
 */
-extern struct bt_ctf_event_class *bt_ctf_stream_class_get_event_class_by_name(
-               struct bt_ctf_stream_class *stream_class, const char *name);
+extern struct bt_ctf_event_class *bt_ctf_stream_class_get_event_class_by_index(
+               struct bt_ctf_stream_class *stream_class, uint64_t index);
 
 /**
 @brief  Returns the event class with ID \c id found in the CTF IR stream
@@ -499,12 +542,9 @@ extern struct bt_ctf_event_class *bt_ctf_stream_class_get_event_class_by_name(
 @prenotnull{stream_class}
 @postrefcountsame{stream_class}
 @postsuccessrefcountretinc
-
-@sa bt_ctf_stream_class_get_event_class_by_name(): Finds an event class
-       by name.
 */
 extern struct bt_ctf_event_class *bt_ctf_stream_class_get_event_class_by_id(
-               struct bt_ctf_stream_class *stream_class, uint32_t id);
+               struct bt_ctf_stream_class *stream_class, uint64_t id);
 
 /**
 @brief Adds the CTF IR event class \p event_class to the
@@ -518,6 +558,20 @@ You can call this function even if \p stream_class is frozen. Adding
 event classes is the only operation that is permitted
 on a frozen stream class.
 
+This function tries to resolve the needed
+\link ctfirfieldtypes CTF IR field type\endlink of the dynamic field
+types that are found anywhere in the context or payload field
+types of \p event_class. If any automatic resolving fails:
+
+- If the needed field type should be found in one of the root field
+  types of \p event_class or \p stream_class, this function fails.
+- If \p stream_class is the child of a
+  \link ctfirtraceclass CTF IR trace class\endlink (it was added
+  with bt_ctf_trace_add_stream_class()), this function fails.
+- If \p stream_class is not the child of a trace class yet, the
+  automatic resolving is reported to the next call to
+  bt_ctf_trace_add_stream_class() with \p stream_class.
+
 @param[in] stream_class        Stream class to which to add \p event_class.
 @param[in] event_class Event class to add to \p stream_class.
 @returns               0 on success, or a negative value on error.
@@ -527,6 +581,7 @@ on a frozen stream class.
 @prehot{event_class}
 @postrefcountsame{stream_class}
 @postsuccessrefcountinc{event_class}
+@postsuccessfrozen{event_class}
 */
 extern int bt_ctf_stream_class_add_event_class(
                struct bt_ctf_stream_class *stream_class,
@@ -564,10 +619,6 @@ extern int bt_ctf_stream_class_visit(struct bt_ctf_stream_class *stream_class,
 
 /** @} */
 
-// TODO: document for writer
-extern struct bt_ctf_clock *bt_ctf_stream_class_get_clock(
-               struct bt_ctf_stream_class *stream_class);
-
 #ifdef __cplusplus
 }
 #endif
This page took 0.033318 seconds and 4 git commands to generate.