2 * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
3 * 2000 Wim Taymans <wtay@chello.be>
4 * 2005 Wim Taymans <wim@fluendo.com>
6 * gstobject.h: Header for base GstObject
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
18 * You should have received a copy of the GNU Library General Public
19 * License along with this library; if not, write to the
20 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 * Boston, MA 02111-1307, USA.
24 #ifndef __GST_OBJECT_H__
25 #define __GST_OBJECT_H__
27 #include <gst/gstconfig.h>
29 #include <glib-object.h>
33 #define GST_TYPE_OBJECT (gst_object_get_type ())
34 #define GST_IS_OBJECT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_OBJECT))
35 #define GST_IS_OBJECT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_OBJECT))
36 #define GST_OBJECT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_OBJECT, GstObjectClass))
37 #define GST_OBJECT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_OBJECT, GstObject))
38 #define GST_OBJECT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_OBJECT, GstObjectClass))
39 #define GST_OBJECT_CAST(obj) ((GstObject*)(obj))
40 #define GST_OBJECT_CLASS_CAST(klass) ((GstObjectClass*)(klass))
42 /* make sure we don't change the object size but still make it compile
44 #ifdef GST_DISABLE_LOADSAVE_REGISTRY
45 #define xmlNodePtr gpointer
50 * @GST_OBJECT_DISPOSING: the object is been destroyed, do use it anymore
51 * @GST_OBJECT_FLOATING: the object has a floating reference count (e.g. its
52 * not assigned to a bin)
53 * @GST_OBJECT_FLAG_LAST: subclasses can add additional flags starting from this flag
55 * The standard flags that an gstobject may have.
59 GST_OBJECT_DISPOSING = (1<<0),
60 GST_OBJECT_FLOATING = (1<<1),
62 GST_OBJECT_FLAG_LAST = (1<<4)
66 * GST_OBJECT_REFCOUNT:
69 * Get access to the reference count field of the object.
71 #define GST_OBJECT_REFCOUNT(obj) (((GObject*)(obj))->ref_count)
73 * GST_OBJECT_REFCOUNT_VALUE:
76 * Get the reference count value of the object.
78 #define GST_OBJECT_REFCOUNT_VALUE(obj) g_atomic_int_get ((gint *) &GST_OBJECT_REFCOUNT(obj))
80 /* we do a GST_OBJECT_CAST to avoid type checking, better call these
81 * function with a valid object! */
84 * GST_OBJECT_GET_LOCK:
87 * Acquire a reference to the mutex of this object.
89 #define GST_OBJECT_GET_LOCK(obj) (GST_OBJECT_CAST(obj)->lock)
92 * @obj: a #GstObject to lock
94 * This macro will obtain a lock on the object, making serialization possible.
95 * It blocks until the lock can be obtained.
97 #define GST_OBJECT_LOCK(obj) g_mutex_lock(GST_OBJECT_GET_LOCK(obj))
102 * This macro will try to obtain a lock on the object, but will return with
103 * FALSE if it can't get it immediately.
105 #define GST_OBJECT_TRYLOCK(obj) g_mutex_trylock(GST_OBJECT_GET_LOCK(obj))
108 * @obj: a #GstObject to unlock.
110 * This macro releases a lock on the object.
112 #define GST_OBJECT_UNLOCK(obj) g_mutex_unlock(GST_OBJECT_GET_LOCK(obj))
119 * Get the name of this object
121 #define GST_OBJECT_NAME(obj) (GST_OBJECT_CAST(obj)->name)
126 * Get the parent of this object
128 #define GST_OBJECT_PARENT(obj) (GST_OBJECT_CAST(obj)->parent)
135 * This macro returns the entire set of flags for the object.
137 #define GST_OBJECT_FLAGS(obj) (GST_OBJECT_CAST (obj)->flags)
139 * GST_OBJECT_FLAG_IS_SET:
141 * @flag: Flag to check for
143 * This macro checks to see if the given flag is set.
145 #define GST_OBJECT_FLAG_IS_SET(obj,flag) ((GST_OBJECT_FLAGS (obj) & (flag)) == (flag))
147 * GST_OBJECT_FLAG_SET:
151 * This macro sets the given bits.
153 #define GST_OBJECT_FLAG_SET(obj,flag) (GST_OBJECT_FLAGS (obj) |= (flag))
155 * GST_OBJECT_FLAG_UNSET:
159 * This macro usets the given bits.
161 #define GST_OBJECT_FLAG_UNSET(obj,flag) (GST_OBJECT_FLAGS (obj) &= ~(flag))
165 * GST_OBJECT_IS_DISPOSING:
168 * Check if the given object is beeing destroyed.
170 #define GST_OBJECT_IS_DISPOSING(obj) (GST_OBJECT_FLAG_IS_SET (obj, GST_OBJECT_DISPOSING))
172 * GST_OBJECT_IS_FLOATING:
175 * Check if the given object is floating (has no owner).
177 #define GST_OBJECT_IS_FLOATING(obj) (GST_OBJECT_FLAG_IS_SET (obj, GST_OBJECT_FLOATING))
179 typedef struct _GstObject GstObject;
180 typedef struct _GstObjectClass GstObjectClass;
186 * @name: The name of the object
187 * @name_prefix: used for debugging
188 * @parent: this object's parent, weak ref
189 * @flags: use GST_OBJECT_IS_XXX macros to access the flags
191 * GStreamer base object class.
199 /*< public >*/ /* with LOCK */
200 GMutex *lock; /* object LOCK */
201 gchar *name; /* object name */
202 gchar *name_prefix; /* used for debugging */
203 GstObject *parent; /* this object's parent, weak ref */
207 gpointer _gst_reserved;
211 * GST_CLASS_GET_LOCK:
212 * @obj: a #GstObjectClass
214 * This macro will return the class lock used to protect deep_notify signal
215 * emission on thread-unsafe glib versions (glib < 2.8).
217 #define GST_CLASS_GET_LOCK(obj) (GST_OBJECT_CLASS_CAST(obj)->lock)
220 * @obj: a #GstObjectClass
224 #define GST_CLASS_LOCK(obj) (g_static_rec_mutex_lock(GST_CLASS_GET_LOCK(obj)))
227 * @obj: a #GstObjectClass
229 * Try to lock the class, returns TRUE if class could be locked.
231 #define GST_CLASS_TRYLOCK(obj) (g_static_rec_mutex_trylock(GST_CLASS_GET_LOCK(obj)))
234 * @obj: a #GstObjectClass
238 #define GST_CLASS_UNLOCK(obj) (g_static_rec_mutex_unlock(GST_CLASS_GET_LOCK(obj)))
243 * @signal_object: is used to signal to the whole class
244 * @save_thyself: xml serialisation
245 * @restore_thyself: xml de-serialisation
247 struct _GstObjectClass {
248 GObjectClass parent_class;
250 gchar *path_string_separator;
251 GObject *signal_object;
253 GStaticRecMutex *lock;
256 void (*parent_set) (GstObject *object, GstObject *parent);
257 void (*parent_unset) (GstObject *object, GstObject *parent);
258 void (*object_saved) (GstObject *object, xmlNodePtr parent);
259 void (*deep_notify) (GstObject *object, GstObject *orig, GParamSpec *pspec);
262 /* virtual methods for subclasses */
263 xmlNodePtr (*save_thyself) (GstObject *object, xmlNodePtr parent);
264 void (*restore_thyself) (GstObject *object, xmlNodePtr self);
267 gpointer _gst_reserved[GST_PADDING];
270 /* normal GObject stuff */
271 GType gst_object_get_type (void);
274 gboolean gst_object_set_name (GstObject *object, const gchar *name);
275 gchar* gst_object_get_name (GstObject *object);
276 void gst_object_set_name_prefix (GstObject *object, const gchar *name_prefix);
277 gchar* gst_object_get_name_prefix (GstObject *object);
279 /* parentage routines */
280 gboolean gst_object_set_parent (GstObject *object, GstObject *parent);
281 GstObject* gst_object_get_parent (GstObject *object);
282 void gst_object_unparent (GstObject *object);
283 gboolean gst_object_has_ancestor (GstObject *object, GstObject *ancestor);
285 void gst_object_default_deep_notify (GObject *object, GstObject *orig,
286 GParamSpec *pspec, gchar **excluded_props);
288 /* refcounting + life cycle */
289 gpointer gst_object_ref (gpointer object);
290 void gst_object_unref (gpointer object);
291 void gst_object_sink (gpointer object);
293 /* replace object pointer */
294 void gst_object_replace (GstObject **oldobj, GstObject *newobj);
296 /* printing out the 'path' of the object */
297 gchar * gst_object_get_path_string (GstObject *object);
300 gboolean gst_object_check_uniqueness (GList *list, const gchar *name);
303 #ifndef GST_DISABLE_LOADSAVE_REGISTRY
304 xmlNodePtr gst_object_save_thyself (GstObject *object, xmlNodePtr parent);
305 void gst_object_restore_thyself (GstObject *object, xmlNodePtr self);
307 #if defined _GNUC_ && _GNUC_ >= 3
308 #pragma GCC poison gst_object_save_thyself
309 #pragma GCC poison gst_object_restore_thyself
313 /* class signal stuff */
314 guint gst_class_signal_connect (GstObjectClass *klass,
319 #ifndef GST_DISABLE_LOADSAVE_REGISTRY
320 void gst_class_signal_emit_by_name (GstObject *object,
324 #if defined _GNUC_ && _GNUC_ >= 3
325 #pragma GCC poison gst_class_signal_emit_by_name
332 #endif /* __GST_OBJECT_H__ */