context: add foreach function
[platform/upstream/gstreamer.git] / gst / gstcontext.h
1 /* GStreamer
2  * Copyright (C) 2011 Wim Taymans <wim.taymans@gmail.com>
3  *
4  * gstcontext.h: Header for GstContext subsystem
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_CONTEXT_H__
24 #define __GST_CONTEXT_H__
25
26 #include <gst/gstminiobject.h>
27 #include <gst/gstevent.h>
28
29 G_BEGIN_DECLS
30
31 #define GST_CONTEXT_TRACE_NAME    "GstContext"
32
33 typedef struct _GstContext GstContext;
34
35 #define GST_TYPE_CONTEXT                (gst_context_get_type())
36 #define GST_IS_CONTEXT(obj)             (GST_IS_MINI_OBJECT_TYPE (obj, GST_TYPE_CONTEXT))
37 #define GST_CONTEXT(obj)                ((GstContext *)(obj))
38 #define GST_CONTEXT_CAST(obj)           ((GstContext *)(obj))
39
40
41 /**
42  * gst_context_is_writable:
43  * @ctx: a #GstContext
44  *
45  * Tests if you can safely update @ctx with new events.
46  */
47 #define         gst_context_is_writable(ctx)     gst_mini_object_is_writable (GST_MINI_OBJECT_CAST (ctx))
48
49 /**
50  * gst_context_make_writable:
51  * @ctx: (transfer full): a #GstContext
52  *
53  * Makes a writable context from the given context. If the source context is
54  * already writable, this will simply return the same context. A copy will
55  * otherwise be made using gst_context_copy().
56  *
57  * Returns: (transfer full): a writable context which may or may not be the
58  *     same as @ctx
59  */
60 #define         gst_context_make_writable(ctx)   GST_CONTEXT_CAST (gst_mini_object_make_writable (GST_MINI_OBJECT_CAST (ctx)))
61
62 /**
63  * gst_context_replace:
64  * @old_ctx: (inout) (transfer full): pointer to a pointer to a #GstContext
65  *     to be replaced.
66  * @new_ctx: (allow-none) (transfer none): pointer to a #GstContext that will
67  *     replace the context pointed to by @old_context.
68  *
69  * Modifies a pointer to a #GstContext to point to a different #GstContext. The
70  * modification is done atomically (so this is useful for ensuring thread safety
71  * in some cases), and the reference counts are updated appropriately (the old
72  * context is unreffed, the new one is reffed).
73  *
74  * Either @new_context or the #GstContext pointed to by @old_context may be NULL.
75  */
76 #define         gst_context_replace(old_ctx,new_ctx) \
77     gst_mini_object_replace ((GstMiniObject **)(old_ctx), GST_MINI_OBJECT_CAST (new_ctx))
78
79 GType           gst_context_get_type              (void);
80
81 /* refcounting */
82 /**
83  * gst_context_ref:
84  * @context: The context to refcount
85  *
86  * Increase the refcount of this context.
87  *
88  * Returns: (transfer full): @context (for convenience when doing assignments)
89  */
90 #ifdef _FOOL_GTK_DOC_
91 G_INLINE_FUNC GstContext * gst_context_ref (GstContext * context);
92 #endif
93
94 static inline GstContext *
95 gst_context_ref (GstContext * context)
96 {
97   return (GstContext *) gst_mini_object_ref (GST_MINI_OBJECT_CAST (context));
98 }
99
100 /**
101  * gst_context_unref:
102  * @context: (transfer full): the context to refcount
103  *
104  * Decrease the refcount of an context, freeing it if the refcount reaches 0.
105  */
106 #ifdef _FOOL_GTK_DOC_
107 G_INLINE_FUNC void gst_context_unref (GstContext * context);
108 #endif
109
110 static inline void
111 gst_context_unref (GstContext * context)
112 {
113   gst_mini_object_unref (GST_MINI_OBJECT_CAST (context));
114 }
115
116 /* copy context */
117 /**
118  * gst_context_copy:
119  * @context: The context to copy
120  *
121  * Copy the context using the context specific copy function.
122  *
123  * Returns: (transfer full): the new context
124  */
125 #ifdef _FOOL_GTK_DOC_
126 G_INLINE_FUNC GstContext * gst_context_copy (const GstContext * context);
127 #endif
128
129 static inline GstContext *
130 gst_context_copy (const GstContext * context)
131 {
132   return GST_CONTEXT_CAST (gst_mini_object_copy (GST_MINI_OBJECT_CONST_CAST (context)));
133 }
134
135 GstContext *   gst_context_new         (void);
136
137 /* updating and setting events */
138 void           gst_context_update      (GstContext *context, GstEvent *event);
139 GstEvent *     gst_context_get         (GstContext *context, GstEventType type);
140
141 void           gst_context_clear       (GstContext *context);
142
143 /* foreach */
144 void           gst_context_foreach     (GstContext *context, GFunc func, gpointer user_data);
145
146 G_END_DECLS
147
148 #endif /* __GST_CONTEXT_H__ */