docs: Flesh out element and object macro accessor docs a bit
[platform/upstream/gstreamer.git] / gst / gstobject.h
1 /* GStreamer
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>
5  *
6  * gstobject.h: Header for base GstObject
7  *
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.
12  *
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.
17  *
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., 51 Franklin St, Fifth Floor,
21  * Boston, MA 02110-1301, USA.
22  */
23
24 #ifndef __GST_OBJECT_H__
25 #define __GST_OBJECT_H__
26
27 #include <gst/gstconfig.h>
28
29 #include <glib-object.h>
30
31 G_BEGIN_DECLS
32
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))
41
42 /**
43  * GstObjectFlags:
44  * @GST_OBJECT_FLAG_LAST: subclasses can add additional flags starting from this flag
45  *
46  * The standard flags that an gstobject may have.
47  */
48 typedef enum
49 {
50   /* padding */
51   GST_OBJECT_FLAG_LAST = (1<<4)
52 } GstObjectFlags;
53
54 /**
55  * GST_OBJECT_REFCOUNT:
56  * @obj: a #GstObject
57  *
58  * Get access to the reference count field of the object.
59  */
60 #define GST_OBJECT_REFCOUNT(obj)                (((GObject*)(obj))->ref_count)
61 /**
62  * GST_OBJECT_REFCOUNT_VALUE:
63  * @obj: a #GstObject
64  *
65  * Get the reference count value of the object.
66  */
67 #define GST_OBJECT_REFCOUNT_VALUE(obj)          g_atomic_int_get ((gint *) &GST_OBJECT_REFCOUNT(obj))
68
69 /* we do a GST_OBJECT_CAST to avoid type checking, better call these
70  * function with a valid object! */
71
72 /**
73  * GST_OBJECT_GET_LOCK:
74  * @obj: a #GstObject
75  *
76  * Acquire a reference to the mutex of this object.
77  */
78 #define GST_OBJECT_GET_LOCK(obj)               (&GST_OBJECT_CAST(obj)->lock)
79 /**
80  * GST_OBJECT_LOCK:
81  * @obj: a #GstObject to lock
82  *
83  * This macro will obtain a lock on the object, making serialization possible.
84  * It blocks until the lock can be obtained.
85  */
86 #define GST_OBJECT_LOCK(obj)                   g_mutex_lock(GST_OBJECT_GET_LOCK(obj))
87 /**
88  * GST_OBJECT_TRYLOCK:
89  * @obj: a #GstObject.
90  *
91  * This macro will try to obtain a lock on the object, but will return with
92  * %FALSE if it can't get it immediately.
93  */
94 #define GST_OBJECT_TRYLOCK(obj)                g_mutex_trylock(GST_OBJECT_GET_LOCK(obj))
95 /**
96  * GST_OBJECT_UNLOCK:
97  * @obj: a #GstObject to unlock.
98  *
99  * This macro releases a lock on the object.
100  */
101 #define GST_OBJECT_UNLOCK(obj)                 g_mutex_unlock(GST_OBJECT_GET_LOCK(obj))
102
103
104 /**
105  * GST_OBJECT_NAME:
106  * @obj: a #GstObject
107  *
108  * Get the name of this object. This is not thread-safe by default
109  * (i.e. you will have to make sure the object lock is taken yourself).
110  * If in doubt use gst_object_get_name() instead.
111  */
112 #define GST_OBJECT_NAME(obj)            (GST_OBJECT_CAST(obj)->name)
113 /**
114  * GST_OBJECT_PARENT:
115  * @obj: a #GstObject
116  *
117  * Get the parent of this object. This is not thread-safe by default
118  * (i.e. you will have to make sure the object lock is taken yourself).
119  * If in doubt use gst_object_get_parent() instead.
120  */
121 #define GST_OBJECT_PARENT(obj)          (GST_OBJECT_CAST(obj)->parent)
122
123
124 /**
125  * GST_OBJECT_FLAGS:
126  * @obj: a #GstObject
127  *
128  * This macro returns the entire set of flags for the object.
129  */
130 #define GST_OBJECT_FLAGS(obj)                  (GST_OBJECT_CAST (obj)->flags)
131 /**
132  * GST_OBJECT_FLAG_IS_SET:
133  * @obj: a #GstObject
134  * @flag: Flag to check for
135  *
136  * This macro checks to see if the given flag is set.
137  */
138 #define GST_OBJECT_FLAG_IS_SET(obj,flag)       ((GST_OBJECT_FLAGS (obj) & (flag)) == (flag))
139 /**
140  * GST_OBJECT_FLAG_SET:
141  * @obj: a #GstObject
142  * @flag: Flag to set
143  *
144  * This macro sets the given bits.
145  */
146 #define GST_OBJECT_FLAG_SET(obj,flag)          (GST_OBJECT_FLAGS (obj) |= (flag))
147 /**
148  * GST_OBJECT_FLAG_UNSET:
149  * @obj: a #GstObject
150  * @flag: Flag to set
151  *
152  * This macro unsets the given bits.
153  */
154 #define GST_OBJECT_FLAG_UNSET(obj,flag)        (GST_OBJECT_FLAGS (obj) &= ~(flag))
155
156 typedef struct _GstObject GstObject;
157 typedef struct _GstObjectClass GstObjectClass;
158
159 /**
160  * GstObject:
161  * @lock: object LOCK
162  * @name: The name of the object
163  * @parent: this object's parent, weak ref
164  * @flags: flags for this object
165  *
166  * GStreamer base object class.
167  */
168 struct _GstObject {
169   GInitiallyUnowned object;
170
171   /*< public >*/ /* with LOCK */
172   GMutex         lock;        /* object LOCK */
173   gchar         *name;        /* object name */
174   GstObject     *parent;      /* this object's parent, weak ref */
175   guint32        flags;
176
177   /*< private >*/
178   GList         *control_bindings;  /* List of GstControlBinding */
179   guint64        control_rate;
180   guint64        last_sync;
181
182   gpointer _gst_reserved;
183 };
184
185 /**
186  * GstObjectClass:
187  * @parent_class: parent
188  * @path_string_separator: separator used by gst_object_get_path_string()
189  * @deep_notify: default signal handler
190  *
191  * GStreamer base object class.
192  */
193 struct _GstObjectClass {
194   GInitiallyUnownedClass parent_class;
195
196   const gchar   *path_string_separator;
197
198   /* signals */
199   void          (*deep_notify)      (GstObject * object, GstObject * orig, GParamSpec * pspec);
200
201   /*< public >*/
202   /* virtual methods for subclasses */
203
204   /*< private >*/
205   gpointer _gst_reserved[GST_PADDING];
206 };
207
208 /* normal GObject stuff */
209 GType           gst_object_get_type             (void);
210
211 /* name routines */
212 gboolean        gst_object_set_name             (GstObject *object, const gchar *name);
213 gchar*          gst_object_get_name             (GstObject *object);
214
215 /* parentage routines */
216 gboolean        gst_object_set_parent           (GstObject *object, GstObject *parent);
217 GstObject*      gst_object_get_parent           (GstObject *object);
218 void            gst_object_unparent             (GstObject *object);
219 gboolean        gst_object_has_as_parent                (GstObject *object, GstObject *parent);
220 gboolean        gst_object_has_as_ancestor      (GstObject *object, GstObject *ancestor);
221 #ifndef GST_DISABLE_DEPRECATED
222 gboolean        gst_object_has_ancestor         (GstObject *object, GstObject *ancestor);
223 #endif
224
225 void            gst_object_default_deep_notify  (GObject *object, GstObject *orig,
226                                                  GParamSpec *pspec, gchar **excluded_props);
227
228 /* refcounting + life cycle */
229 gpointer        gst_object_ref                  (gpointer object);
230 void            gst_object_unref                (gpointer object);
231 gpointer        gst_object_ref_sink             (gpointer object);
232
233 /* replace object pointer */
234 gboolean        gst_object_replace              (GstObject **oldobj, GstObject *newobj);
235
236 /* printing out the 'path' of the object */
237 gchar *         gst_object_get_path_string      (GstObject *object);
238
239 /* misc utils */
240 gboolean        gst_object_check_uniqueness     (GList *list, const gchar *name);
241
242 /* controller functions */
243 #include <gst/gstcontrolbinding.h>
244 #include <gst/gstcontrolsource.h>
245
246 GstClockTime    gst_object_suggest_next_sync      (GstObject * object);
247 gboolean        gst_object_sync_values            (GstObject * object, GstClockTime timestamp);
248
249 gboolean        gst_object_has_active_control_bindings   (GstObject *object);
250 void            gst_object_set_control_bindings_disabled (GstObject *object, gboolean disabled);
251 void            gst_object_set_control_binding_disabled  (GstObject *object,
252                                                           const gchar * property_name,
253                                                           gboolean disabled);
254
255 gboolean        gst_object_add_control_binding    (GstObject * object, GstControlBinding * binding);
256 GstControlBinding *
257                 gst_object_get_control_binding    (GstObject *object, const gchar * property_name);
258 gboolean        gst_object_remove_control_binding (GstObject * object, GstControlBinding * binding);
259
260 GValue *        gst_object_get_value              (GstObject * object, const gchar * property_name,
261                                                    GstClockTime timestamp);
262 gboolean        gst_object_get_value_array        (GstObject * object, const gchar * property_name,
263                                                    GstClockTime timestamp, GstClockTime interval,
264                                                    guint n_values, gpointer values);
265 gboolean        gst_object_get_g_value_array      (GstObject * object, const gchar * property_name,
266                                                    GstClockTime timestamp, GstClockTime interval,
267                                                    guint n_values, GValue *values);
268
269 GstClockTime    gst_object_get_control_rate       (GstObject * object);
270 void            gst_object_set_control_rate       (GstObject * object, GstClockTime control_rate);
271
272 #ifdef G_DEFINE_AUTOPTR_CLEANUP_FUNC
273 G_DEFINE_AUTOPTR_CLEANUP_FUNC(GstObject, gst_object_unref)
274 #endif
275
276 G_END_DECLS
277
278 #endif /* __GST_OBJECT_H__ */
279