2 * Copyright (C) 2004 Wim Taymans <wim@fluendo.com>
4 * gstiterator.h: Header for GstIterator
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.
22 #ifndef __GST_ITERATOR_H__
23 #define __GST_ITERATOR_H__
25 #include <glib-object.h> /* for GValue in the fold */
26 #include <gst/gstconfig.h>
31 GST_ITERATOR_DONE = 0, /* no more items in the iterator */
32 GST_ITERATOR_OK = 1, /* item retrieved */
33 GST_ITERATOR_RESYNC = 2, /* datastructures changed while iterating */
34 GST_ITERATOR_ERROR = 3, /* some error happened */
37 typedef struct _GstIterator GstIterator;
40 GST_ITERATOR_ITEM_SKIP = 0, /* skip item */
41 GST_ITERATOR_ITEM_PASS = 1, /* return item */
42 GST_ITERATOR_ITEM_END = 2, /* stop after this item */
45 typedef void (*GstIteratorDisposeFunction) (gpointer owner);
47 typedef GstIteratorResult (*GstIteratorNextFunction) (GstIterator *it, gpointer *result);
48 typedef GstIteratorItem (*GstIteratorItemFunction) (GstIterator *it, gpointer item);
49 typedef void (*GstIteratorResyncFunction) (GstIterator *it);
50 typedef void (*GstIteratorFreeFunction) (GstIterator *it);
52 typedef gboolean (*GstIteratorFoldFunction) (gpointer item, GValue *ret, gpointer user_data);
54 #define GST_ITERATOR(it) ((GstIterator*)(it))
55 #define GST_ITERATOR_LOCK(it) (GST_ITERATOR(it)->lock)
56 #define GST_ITERATOR_COOKIE(it) (GST_ITERATOR(it)->cookie)
57 #define GST_ITERATOR_ORIG_COOKIE(it) (GST_ITERATOR(it)->master_cookie)
60 GstIteratorNextFunction next;
61 GstIteratorItemFunction item;
62 GstIteratorResyncFunction resync;
63 GstIteratorFreeFunction free;
65 GstIterator *pushed; /* pushed iterator */
68 guint32 cookie; /* cookie of the iterator */
69 guint32 *master_cookie; /* pointer to guint32 holding the cookie when this
70 iterator was created */
73 gpointer _gst_reserved[GST_PADDING];
76 /* creating iterators */
77 GstIterator* gst_iterator_new (guint size,
79 guint32 *master_cookie,
80 GstIteratorNextFunction next,
81 GstIteratorItemFunction item,
82 GstIteratorResyncFunction resync,
83 GstIteratorFreeFunction free);
85 GstIterator* gst_iterator_new_list (GMutex *lock,
86 guint32 *master_cookie,
89 GstIteratorItemFunction item,
90 GstIteratorDisposeFunction free);
93 GstIteratorResult gst_iterator_next (GstIterator *it, gpointer *result);
94 void gst_iterator_resync (GstIterator *it);
95 void gst_iterator_free (GstIterator *it);
97 void gst_iterator_push (GstIterator *it, GstIterator *other);
99 /* higher-order functions that operate on iterators */
100 GstIterator* gst_iterator_filter (GstIterator *it, GCompareFunc func,
102 GstIteratorResult gst_iterator_fold (GstIterator *iter,
103 GstIteratorFoldFunction func,
104 GValue *ret, gpointer user_data);
105 GstIteratorResult gst_iterator_foreach (GstIterator *iter,
106 GFunc func, gpointer user_data);
107 gpointer gst_iterator_find_custom (GstIterator *it, GCompareFunc func,
112 #endif /* __GST_ITERATOR_H__ */