Imported Upstream version 0.10.36
[profile/ivi/gstreamer.git] / gst / gstminiobject.h
1 /* GStreamer
2  * Copyright (C) 2005 David Schleef <ds@schleef.org>
3  *
4  * gstminiobject.h: Header for GstMiniObject
5  *
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.
10  *
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.
15  *
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.
20  */
21
22
23 #ifndef __GST_MINI_OBJECT_H__
24 #define __GST_MINI_OBJECT_H__
25
26 #include <gst/gstconfig.h>
27
28 #include <glib-object.h>
29
30 G_BEGIN_DECLS
31
32 #define GST_TYPE_MINI_OBJECT          (gst_mini_object_get_type())
33 #define GST_IS_MINI_OBJECT(obj)       (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_MINI_OBJECT))
34 #define GST_IS_MINI_OBJECT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_MINI_OBJECT))
35 #define GST_MINI_OBJECT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_MINI_OBJECT, GstMiniObjectClass))
36 #define GST_MINI_OBJECT(obj)          (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_MINI_OBJECT, GstMiniObject))
37 #define GST_MINI_OBJECT_CLASS(klass)  (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_MINI_OBJECT, GstMiniObjectClass))
38 #define GST_MINI_OBJECT_CAST(obj)     ((GstMiniObject*)(obj))
39 #define GST_MINI_OBJECT_CONST_CAST(obj) ((const GstMiniObject*)(obj))
40
41 typedef struct _GstMiniObject GstMiniObject;
42 typedef struct _GstMiniObjectClass GstMiniObjectClass;
43
44 /**
45  * GstMiniObjectCopyFunction:
46  * @obj: MiniObject to copy
47  *
48  * Virtual function prototype for methods to create copies of instances.
49  *
50  * Returns: reference to cloned instance.
51  */
52 typedef GstMiniObject * (*GstMiniObjectCopyFunction) (const GstMiniObject *obj);
53 /**
54  * GstMiniObjectFinalizeFunction:
55  * @obj: MiniObject to finalize
56  *
57  * Virtual function prototype for methods to free ressources used by
58  * mini-objects. Subclasses of the mini object are allowed to revive the
59  * passed object by doing a gst_mini_object_ref(). If the object is not
60  * revived after the finalize function, the memory associated with the
61  * object is freed.
62  */
63 typedef void (*GstMiniObjectFinalizeFunction) (GstMiniObject *obj);
64
65 /**
66  * GST_MINI_OBJECT_FLAGS:
67  * @obj: MiniObject to return flags for.
68  *
69  * This macro returns the entire set of flags for the mini-object.
70  */
71 #define GST_MINI_OBJECT_FLAGS(obj)  (GST_MINI_OBJECT_CAST(obj)->flags)
72 /**
73  * GST_MINI_OBJECT_FLAG_IS_SET:
74  * @obj: MiniObject to check for flags.
75  * @flag: Flag to check for
76  *
77  * This macro checks to see if the given flag is set.
78  */
79 #define GST_MINI_OBJECT_FLAG_IS_SET(obj,flag)        !!(GST_MINI_OBJECT_FLAGS (obj) & (flag))
80 /**
81  * GST_MINI_OBJECT_FLAG_SET:
82  * @obj: MiniObject to set flag in.
83  * @flag: Flag to set, can by any number of bits in guint32.
84  *
85  * This macro sets the given bits.
86  */
87 #define GST_MINI_OBJECT_FLAG_SET(obj,flag)           (GST_MINI_OBJECT_FLAGS (obj) |= (flag))
88 /**
89  * GST_MINI_OBJECT_FLAG_UNSET:
90  * @obj: MiniObject to unset flag in.
91  * @flag: Flag to set, must be a single bit in guint32.
92  *
93  * This macro usets the given bits.
94  */
95 #define GST_MINI_OBJECT_FLAG_UNSET(obj,flag)         (GST_MINI_OBJECT_FLAGS (obj) &= ~(flag))
96
97 /**
98  * GST_VALUE_HOLDS_MINI_OBJECT:
99  * @value: the #GValue to check
100  *
101  * Checks if the given #GValue contains a #GST_TYPE_MINI_OBJECT value.
102  */
103 #define GST_VALUE_HOLDS_MINI_OBJECT(value)  (G_VALUE_HOLDS(value, GST_TYPE_MINI_OBJECT))
104
105 /**
106  * GstMiniObjectFlags:
107  * @GST_MINI_OBJECT_FLAG_READONLY: is the miniobject readonly or writable
108  * @GST_MINI_OBJECT_FLAG_RESERVED1: a flag reserved for internal use e.g. as
109  *     GST_BUFFER_FLAG_MEDIA4. Since: 0.10.33.
110  * @GST_MINI_OBJECT_FLAG_LAST: first flag that can be used by subclasses.
111  *
112  * Flags for the mini object
113  */
114
115 typedef enum
116 {
117   GST_MINI_OBJECT_FLAG_READONLY = (1<<0),
118   GST_MINI_OBJECT_FLAG_RESERVED1 = (1<<1),
119   /* padding */
120   GST_MINI_OBJECT_FLAG_LAST = (1<<4)
121 } GstMiniObjectFlags;
122
123 /**
124  * GST_MINI_OBJECT_REFCOUNT:
125  * @obj: a #GstMiniObject
126  *
127  * Get access to the reference count field of the mini-object.
128  */
129 #define GST_MINI_OBJECT_REFCOUNT(obj)           ((GST_MINI_OBJECT_CAST(obj))->refcount)
130 /**
131  * GST_MINI_OBJECT_REFCOUNT_VALUE:
132  * @obj: a #GstMiniObject
133  *
134  * Get the reference count value of the mini-object.
135  */
136 #define GST_MINI_OBJECT_REFCOUNT_VALUE(obj)     (g_atomic_int_get (&(GST_MINI_OBJECT_CAST(obj))->refcount))
137
138 /**
139  * GstMiniObjectWeakNotify:
140  * @data: data that was provided when the weak reference was established
141  * @where_the_mini_object_was: the mini object being finalized
142  * 
143  * A #GstMiniObjectWeakNotify function can be added to a mini object as a
144  * callback that gets triggered when the mini object is finalized. Since the
145  * mini object is already being finalized when the #GstMiniObjectWeakNotify is
146  * called, there's not much you could do with the object, apart from e.g. using
147  * its adress as hash-index or the like. 
148  *
149  * Since: 0.10.35
150  *
151  */
152 typedef void (*GstMiniObjectWeakNotify) (gpointer data,
153     GstMiniObject * where_the_mini_object_was);
154
155 typedef struct _GstMiniObjectPrivate GstMiniObjectPrivate;
156
157 /**
158  * GstMiniObject:
159  * @instance: type instance
160  * @refcount: atomic refcount
161  * @flags: extra flags.
162  * 
163  * Base class for refcounted lightweight objects.
164  * Ref Func: gst_mini_object_ref
165  * Unref Func: gst_mini_object_unref
166  * Set Value Func: gst_value_set_mini_object
167  * Get Value Func: gst_value_get_mini_object
168  */
169 struct _GstMiniObject {
170   GTypeInstance instance;
171   /*< public >*/ /* with COW */
172   gint refcount;
173   guint flags;
174
175   /*< private >*/
176   GstMiniObjectPrivate *priv;
177 };
178
179 struct _GstMiniObjectClass {
180   GTypeClass type_class;
181
182   GstMiniObjectCopyFunction copy;
183   GstMiniObjectFinalizeFunction finalize;
184
185   /*< private >*/
186   gpointer _gst_reserved;
187 };
188
189 GType           gst_mini_object_get_type        (void);
190
191 GstMiniObject*  gst_mini_object_new             (GType type) G_GNUC_MALLOC;
192 GstMiniObject*  gst_mini_object_copy            (const GstMiniObject *mini_object) G_GNUC_MALLOC;
193 gboolean        gst_mini_object_is_writable     (const GstMiniObject *mini_object);
194 GstMiniObject*  gst_mini_object_make_writable   (GstMiniObject *mini_object);
195
196 /* refcounting */
197 GstMiniObject*  gst_mini_object_ref             (GstMiniObject *mini_object);
198 void            gst_mini_object_unref           (GstMiniObject *mini_object);
199 void            gst_mini_object_weak_ref        (GstMiniObject *object,
200                                                  GstMiniObjectWeakNotify notify,
201                                                  gpointer data);
202 void            gst_mini_object_weak_unref      (GstMiniObject *object,
203                                                  GstMiniObjectWeakNotify notify,
204                                                  gpointer data);
205 void            gst_mini_object_replace         (GstMiniObject **olddata, GstMiniObject *newdata);
206
207 /* GParamSpec */
208
209 #define GST_TYPE_PARAM_MINI_OBJECT              (gst_param_spec_mini_object_get_type())
210 #define GST_IS_PARAM_SPEC_MINI_OBJECT(pspec)    (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), \
211                                                  GST_TYPE_PARAM_MINI_OBJECT))
212 #define GST_PARAM_SPEC_MINI_OBJECT(pspec)       (G_TYPE_CHECK_INSTANCE_CAST ((pspec), \
213                                                  GST_TYPE_PARAM_MINI_OBJECT, \
214                                                  GstParamSpecMiniObject))
215
216 typedef struct _GstParamSpecMiniObject GstParamSpecMiniObject;
217
218 /**
219  * GstParamSpecMiniObject:
220  * @parent_instance: private %GParamSpec portion
221  * 
222  * A %GParamSpec derived structure that contains the meta data
223  * for %GstMiniObject properties.
224  */
225 struct _GstParamSpecMiniObject
226 {
227   GParamSpec parent_instance;
228 };
229
230
231 GType gst_param_spec_mini_object_get_type (void);
232
233 GParamSpec*     gst_param_spec_mini_object      (const char *name, const char *nick,
234                                                  const char *blurb, GType object_type, 
235                                                  GParamFlags flags) G_GNUC_MALLOC;
236
237 /* GValue stuff */
238
239 void            gst_value_set_mini_object       (GValue *value, GstMiniObject *mini_object);
240 void            gst_value_take_mini_object      (GValue *value, GstMiniObject *mini_object);
241 GstMiniObject*  gst_value_get_mini_object       (const GValue *value);
242 GstMiniObject*  gst_value_dup_mini_object       (const GValue *value);
243
244
245 G_END_DECLS
246
247 #endif
248