gstobject: add CONSTRUCTED flag

This can be used later by base class APIs to know whether they're
called from a subclass instance init function (where the object
isn't properly constructed yet and one should only really poke
at the instance structure but not much else) or after object
construction has been finished.

Fix up GstBin unit test for CONSTRUCTED flag addition.

See https://gitlab.freedesktop.org/gstreamer/gstreamer/-/issues/2794

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/6150>
This commit is contained in:
Tim-Philipp Müller 2024-01-29 19:47:11 +00:00 committed by GStreamer Marge Bot
parent dc5b866d87
commit 59c09eb029
4 changed files with 31 additions and 1 deletions

View file

@ -27929,6 +27929,14 @@ the elements contained in that bin.</doc>
<doc xml:space="preserve" filename="../subprojects/gstreamer/gst/gstobject.h">the object is expected to stay alive even
after gst_deinit() has been called and so should be ignored by leak
detection tools. (Since: 1.10)</doc>
</member>
<member name="constructed" value="2" c:identifier="GST_OBJECT_FLAG_CONSTRUCTED" version="1.24" glib:nick="constructed">
<doc xml:space="preserve" filename="../subprojects/gstreamer/gst/gstobject.h">Flag that's set when the object has been constructed. This can be used by
API such as base class setters to differentiate between the case where
they're called from a subclass's instance init function (and where the
object isn't fully constructed yet, and so one shouldn't do anything but
set values in the instance structure), and the case where the object is
constructed.</doc>
</member>
<member name="last" value="16" c:identifier="GST_OBJECT_FLAG_LAST" glib:nick="last">
<doc xml:space="preserve" filename="../subprojects/gstreamer/gst/gstobject.h">subclasses can add additional flags starting from this flag</doc>

View file

@ -138,6 +138,8 @@ G_DEFINE_ABSTRACT_TYPE (GstObject, gst_object, G_TYPE_INITIALLY_UNOWNED);
static void
gst_object_constructed (GObject * object)
{
GST_OBJECT_FLAG_SET (object, GST_OBJECT_FLAG_CONSTRUCTED);
GST_TRACER_OBJECT_CREATED (GST_OBJECT_CAST (object));
((GObjectClass *) gst_object_parent_class)->constructed (object);

View file

@ -39,11 +39,30 @@ G_BEGIN_DECLS
#define GST_OBJECT_CAST(obj) ((GstObject*)(obj))
#define GST_OBJECT_CLASS_CAST(klass) ((GstObjectClass*)(klass))
/**
* GST_OBJECT_FLAG_CONSTRUCTED:
*
* Flag that's set when the object has been constructed. This can be used by
* API such as base class setters to differentiate between the case where
* they're called from a subclass's instance init function (and where the
* object isn't fully constructed yet, and so one shouldn't do anything but
* set values in the instance structure), and the case where the object is
* constructed.
*
* Since: 1.24
*/
/**
* GstObjectFlags:
* @GST_OBJECT_FLAG_MAY_BE_LEAKED: the object is expected to stay alive even
* after gst_deinit() has been called and so should be ignored by leak
* detection tools. (Since: 1.10)
* @GST_OBJECT_FLAG_CONSTRUCTED: flag that's set when the object has been
* constructed. This can be used by API such as base class setters to
* differentiate between the case where they're called from a subclass's
* instance init function (and where the object isn't fully constructed yet,
* and so one shouldn't do anything but set values in the instance structure),
* and the case where the object is constructed. (Since: 1.24)
* @GST_OBJECT_FLAG_LAST: subclasses can add additional flags starting from this flag
*
* The standard flags that an gstobject may have.
@ -51,6 +70,7 @@ G_BEGIN_DECLS
typedef enum
{
GST_OBJECT_FLAG_MAY_BE_LEAKED = (1 << 0),
GST_OBJECT_FLAG_CONSTRUCTED = (1 << 1),
/* padding */
GST_OBJECT_FLAG_LAST = (1<<4)
} GstObjectFlags;

View file

@ -1919,7 +1919,7 @@ G_STMT_START { \
gst_bin_set_suppressed_flags (bin, suppressed_flags); \
gst_bin_add (bin, element); \
fail_unless ((natural_flags | GST_OBJECT_FLAGS (bin)) \
== expected_flags); \
== (expected_flags | GST_OBJECT_FLAG_CONSTRUCTED)); \
gst_object_unref (bin); \
} G_STMT_END