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 GST_EXPORT GType _gst_object_type;
35 #define GST_TYPE_OBJECT (_gst_object_type)
36 #define GST_IS_OBJECT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_OBJECT))
37 #define GST_IS_OBJECT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_OBJECT))
38 #define GST_OBJECT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_OBJECT, GstObjectClass))
39 #define GST_OBJECT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_OBJECT, GstObject))
40 #define GST_OBJECT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_OBJECT, GstObjectClass))
41 #define GST_OBJECT_CAST(obj) ((GstObject*)(obj))
42 #define GST_OBJECT_CLASS_CAST(klass) ((GstObjectClass*)(klass))
44 /* make sure we don't change the object size but stil make it compile
46 #ifdef GST_DISABLE_LOADSAVE_REGISTRY
47 #define xmlNodePtr gpointer
52 GST_OBJECT_DISPOSING = 0,
55 GST_OBJECT_FLAG_LAST = 4
58 #ifdef GST_HAVE_GLIB_2_8
59 #define GST_OBJECT_REFCOUNT(obj) (((GObject*)(obj))->ref_count)
60 #define GST_OBJECT_REFCOUNT_VALUE(obj) (g_atomic_int_get (&((GObject*)(obj))->ref_count))
62 #define GST_OBJECT_REFCOUNT(obj) ((GST_OBJECT_CAST(obj))->refcount)
63 #define GST_OBJECT_REFCOUNT_VALUE(obj) (g_atomic_int_get (&(GST_OBJECT_CAST(obj))->refcount))
64 #endif /* GST_HAVE_GLIB_2_8 */
66 /* we do a GST_OBJECT_CAST to avoid type checking, better call these
67 * function with a valid object! */
68 #define GST_LOCK(obj) g_mutex_lock(GST_OBJECT_CAST(obj)->lock)
69 #define GST_TRYLOCK(obj) g_mutex_trylock(GST_OBJECT_CAST(obj)->lock)
70 #define GST_UNLOCK(obj) g_mutex_unlock(GST_OBJECT_CAST(obj)->lock)
71 #define GST_GET_LOCK(obj) (GST_OBJECT_CAST(obj)->lock)
73 #define GST_OBJECT_NAME(obj) (GST_OBJECT_CAST(obj)->name)
74 #define GST_OBJECT_PARENT(obj) (GST_OBJECT_CAST(obj)->parent)
76 /* for the flags we double-not to make them comparable to TRUE and FALSE */
77 #define GST_FLAGS(obj) (GST_OBJECT_CAST (obj)->flags)
78 #define GST_FLAG_IS_SET(obj,flag) (!!(GST_FLAGS (obj) & (1<<(flag))))
79 #define GST_FLAG_SET(obj,flag) G_STMT_START{ (GST_FLAGS (obj) |= (1<<(flag))); }G_STMT_END
80 #define GST_FLAG_UNSET(obj,flag) G_STMT_START{ (GST_FLAGS (obj) &= ~(1<<(flag))); }G_STMT_END
82 #define GST_OBJECT_IS_DISPOSING(obj) (GST_FLAG_IS_SET (obj, GST_OBJECT_DISPOSING))
83 #define GST_OBJECT_IS_FLOATING(obj) (GST_FLAG_IS_SET (obj, GST_OBJECT_FLOATING))
85 typedef struct _GstObject GstObject;
86 typedef struct _GstObjectClass GstObjectClass;
92 gint refcount; /* only used ifndef GST_HAVE_GLIB_0_8 */
94 /*< public >*/ /* with LOCK */
95 GMutex *lock; /* object LOCK */
96 gchar *name; /* object name */
97 gchar *name_prefix; /* used for debugging */
98 GstObject *parent; /* this object's parent, weak ref */
102 gpointer _gst_reserved[GST_PADDING];
105 #define GST_CLASS_LOCK(obj) (g_static_rec_mutex_lock(GST_OBJECT_CLASS_CAST(obj)->lock))
106 #define GST_CLASS_TRYLOCK(obj) (g_static_rec_mutex_trylock(GST_OBJECT_CLASS_CAST(obj)->lock))
107 #define GST_CLASS_UNLOCK(obj) (g_static_rec_mutex_unlock(GST_OBJECT_CLASS_CAST(obj)->lock))
108 #define GST_CLASS_GET_LOCK(obj) (GST_OBJECT_CLASS_CAST(obj)->lock)
110 /* signal_object is used to signal to the whole class */
111 struct _GstObjectClass {
112 GObjectClass parent_class;
114 gchar *path_string_separator;
115 GObject *signal_object;
117 GStaticRecMutex *lock;
120 void (*parent_set) (GstObject *object, GstObject *parent);
121 void (*parent_unset) (GstObject *object, GstObject *parent);
122 void (*object_saved) (GstObject *object, xmlNodePtr parent);
123 void (*deep_notify) (GstObject *object, GstObject *orig, GParamSpec *pspec);
126 xmlNodePtr (*save_thyself) (GstObject *object, xmlNodePtr parent);
127 void (*restore_thyself) (GstObject *object, xmlNodePtr self);
130 gpointer _gst_reserved[GST_PADDING];
133 /* normal GObject stuff */
134 GType gst_object_get_type (void);
137 gboolean gst_object_set_name (GstObject *object, const gchar *name);
138 gchar* gst_object_get_name (GstObject *object);
139 void gst_object_set_name_prefix (GstObject *object, const gchar *name_prefix);
140 gchar* gst_object_get_name_prefix (GstObject *object);
142 /* parentage routines */
143 gboolean gst_object_set_parent (GstObject *object, GstObject *parent);
144 GstObject* gst_object_get_parent (GstObject *object);
145 void gst_object_unparent (GstObject *object);
147 void gst_object_default_deep_notify (GObject *object, GstObject *orig,
148 GParamSpec *pspec, gchar **excluded_props);
150 /* refcounting + life cycle */
151 gpointer gst_object_ref (gpointer object);
152 void gst_object_unref (gpointer object);
153 void gst_object_sink (gpointer object);
155 /* replace object pointer */
156 void gst_object_replace (GstObject **oldobj, GstObject *newobj);
158 /* printing out the 'path' of the object */
159 gchar * gst_object_get_path_string (GstObject *object);
162 gboolean gst_object_check_uniqueness (GList *list, const gchar *name);
165 #ifndef GST_DISABLE_LOADSAVE_REGISTRY
166 xmlNodePtr gst_object_save_thyself (GstObject *object, xmlNodePtr parent);
167 void gst_object_restore_thyself (GstObject *object, xmlNodePtr self);
169 #if defined _GNUC_ && _GNUC_ >= 3
170 #pragma GCC poison gst_object_save_thyself
171 #pragma GCC poison gst_object_restore_thyself
175 /* class signal stuff */
176 guint gst_class_signal_connect (GstObjectClass *klass,
181 #ifndef GST_DISABLE_LOADSAVE_REGISTRY
182 void gst_class_signal_emit_by_name (GstObject *object,
186 #if defined _GNUC_ && _GNUC_ >= 3
187 #pragma GCC poison gst_class_signal_emit_by_name
194 #endif /* __GST_OBJECT_H__ */