2 * Copyright (C) 2005 David Schleef <ds@schleef.org>
4 * gstminiobject.h: Header for GstMiniObject
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; if not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
23 #ifndef __GST_MINI_OBJECT_H__
24 #define __GST_MINI_OBJECT_H__
26 #include <gst/gstconfig.h>
28 #include <glib-object.h>
32 #define GST_IS_MINI_OBJECT_TYPE(obj,type) ((obj) && GST_MINI_OBJECT_TYPE(obj) == (type))
33 #define GST_MINI_OBJECT_CAST(obj) ((GstMiniObject*)(obj))
34 #define GST_MINI_OBJECT_CONST_CAST(obj) ((const GstMiniObject*)(obj))
35 #define GST_MINI_OBJECT(obj) (GST_MINI_OBJECT_CAST(obj))
37 typedef struct _GstMiniObject GstMiniObject;
40 * GstMiniObjectCopyFunction:
41 * @obj: MiniObject to copy
43 * Function prototype for methods to create copies of instances.
45 * Returns: reference to cloned instance.
47 typedef GstMiniObject * (*GstMiniObjectCopyFunction) (const GstMiniObject *obj);
49 * GstMiniObjectDisposeFunction:
50 * @obj: MiniObject to dispose
52 * Function prototype for when a miniobject has lost its last refcount.
53 * Implementation of the mini object are allowed to revive the
54 * passed object by doing a gst_mini_object_ref(). If the object is not
55 * revived after the dispose function, the function should return %TRUE
56 * and the memory associated with the object is freed.
58 * Returns: %TRUE if the object should be cleaned up.
60 typedef gboolean (*GstMiniObjectDisposeFunction) (GstMiniObject *obj);
62 * GstMiniObjectFreeFunction:
63 * @obj: MiniObject to free
65 * Virtual function prototype for methods to free ressources used by
68 typedef void (*GstMiniObjectFreeFunction) (GstMiniObject *obj);
71 * GstMiniObjectNotify:
72 * @user_data: data that was provided when the notify was added
73 * @obj: the mini object
75 * A #GstMiniObjectNotify function can be added to a mini object as a
76 * callback that gets triggered with gst_mini_object_notify().
78 typedef void (*GstMiniObjectNotify) (gpointer user_data, GstMiniObject * obj);
81 * GST_MINI_OBJECT_TYPE:
82 * @obj: MiniObject to return type for.
84 * This macro returns the type of the mini-object.
86 #define GST_MINI_OBJECT_TYPE(obj) (GST_MINI_OBJECT_CAST(obj)->type)
88 * GST_MINI_OBJECT_FLAGS:
89 * @obj: MiniObject to return flags for.
91 * This macro returns the entire set of flags for the mini-object.
93 #define GST_MINI_OBJECT_FLAGS(obj) (GST_MINI_OBJECT_CAST(obj)->flags)
95 * GST_MINI_OBJECT_FLAG_IS_SET:
96 * @obj: MiniObject to check for flags.
97 * @flag: Flag to check for
99 * This macro checks to see if the given flag is set.
101 #define GST_MINI_OBJECT_FLAG_IS_SET(obj,flag) !!(GST_MINI_OBJECT_FLAGS (obj) & (flag))
103 * GST_MINI_OBJECT_FLAG_SET:
104 * @obj: MiniObject to set flag in.
105 * @flag: Flag to set, can by any number of bits in guint32.
107 * This macro sets the given bits.
109 #define GST_MINI_OBJECT_FLAG_SET(obj,flag) (GST_MINI_OBJECT_FLAGS (obj) |= (flag))
111 * GST_MINI_OBJECT_FLAG_UNSET:
112 * @obj: MiniObject to unset flag in.
113 * @flag: Flag to set, must be a single bit in guint32.
115 * This macro usets the given bits.
117 #define GST_MINI_OBJECT_FLAG_UNSET(obj,flag) (GST_MINI_OBJECT_FLAGS (obj) &= ~(flag))
120 * GstMiniObjectFlags:
121 * @GST_MINI_OBJECT_FLAG_LAST: first flag that can be used by subclasses.
123 * Flags for the mini object
128 GST_MINI_OBJECT_FLAG_LAST = (1<<4)
129 } GstMiniObjectFlags;
132 * GST_MINI_OBJECT_REFCOUNT:
133 * @obj: a #GstMiniObject
135 * Get access to the reference count field of the mini-object.
137 #define GST_MINI_OBJECT_REFCOUNT(obj) ((GST_MINI_OBJECT_CAST(obj))->refcount)
139 * GST_MINI_OBJECT_REFCOUNT_VALUE:
140 * @obj: a #GstMiniObject
142 * Get the reference count value of the mini-object.
144 #define GST_MINI_OBJECT_REFCOUNT_VALUE(obj) (g_atomic_int_get (&(GST_MINI_OBJECT_CAST(obj))->refcount))
148 * @type: the GType of the object
149 * @refcount: atomic refcount
150 * @flags: extra flags.
151 * @copy: a copy function
152 * @dispose: a dispose function
153 * @free: the free function
155 * Base class for refcounted lightweight objects.
156 * Ref Func: gst_mini_object_ref
157 * Unref Func: gst_mini_object_unref
158 * Set Value Func: g_value_set_boxed
159 * Get Value Func: g_value_get_boxed
161 struct _GstMiniObject {
164 /*< public >*/ /* with COW */
168 GstMiniObjectCopyFunction copy;
169 GstMiniObjectDisposeFunction dispose;
170 GstMiniObjectFreeFunction free;
173 /* Used to keep track of weak ref notifies and qdata */
178 void gst_mini_object_init (GstMiniObject *mini_object, GType type,
179 GstMiniObjectCopyFunction copy_func,
180 GstMiniObjectDisposeFunction dispose_func,
181 GstMiniObjectFreeFunction free_func);
183 GstMiniObject * gst_mini_object_copy (const GstMiniObject *mini_object) G_GNUC_MALLOC;
184 gboolean gst_mini_object_is_writable (const GstMiniObject *mini_object);
185 GstMiniObject * gst_mini_object_make_writable (GstMiniObject *mini_object);
188 GstMiniObject * gst_mini_object_ref (GstMiniObject *mini_object);
189 void gst_mini_object_unref (GstMiniObject *mini_object);
191 void gst_mini_object_weak_ref (GstMiniObject *object,
192 GstMiniObjectNotify notify,
194 void gst_mini_object_weak_unref (GstMiniObject *object,
195 GstMiniObjectNotify notify,
198 void gst_mini_object_set_qdata (GstMiniObject *object, GQuark quark,
199 gpointer data, GDestroyNotify destroy);
200 gpointer gst_mini_object_get_qdata (GstMiniObject *object, GQuark quark);
201 gpointer gst_mini_object_steal_qdata (GstMiniObject *object, GQuark quark);
204 gboolean gst_mini_object_replace (GstMiniObject **olddata, GstMiniObject *newdata);
205 gboolean gst_mini_object_take (GstMiniObject **olddata, GstMiniObject *newdata);
206 GstMiniObject * gst_mini_object_steal (GstMiniObject **olddata);
209 * GST_DEFINE_MINI_OBJECT_TYPE:
210 * @TypeName: name of the new type in CamelCase
211 * @type_name: name of the new type
213 * Define a new mini-object type with the given name
215 #define GST_DEFINE_MINI_OBJECT_TYPE(TypeName,type_name) \
216 G_DEFINE_BOXED_TYPE(TypeName,type_name, \
217 (GBoxedCopyFunc) gst_mini_object_ref, \
218 (GBoxedFreeFunc) gst_mini_object_unref)