diff options
author | Sebastian Dröge <sebastian.droege@collabora.co.uk> | 2011-03-16 10:50:39 +0100 |
---|---|---|
committer | Sebastian Dröge <sebastian.droege@collabora.co.uk> | 2011-05-05 15:33:29 +0200 |
commit | 348563bc192cc24941e583452e6243ff61aac51e (patch) | |
tree | 480d959f3527554da2b5e3cbfc9807de5f145634 /gst/gstiterator.h | |
parent | 62c7339847e4bb7ea31a6c960322c42b7eaf67a9 (diff) |
iterator: Refactor GstIterator to be more binding friendly and have saner refcounting
Fixes bug #638987.
Diffstat (limited to 'gst/gstiterator.h')
-rw-r--r-- | gst/gstiterator.h | 91 |
1 files changed, 45 insertions, 46 deletions
diff --git a/gst/gstiterator.h b/gst/gstiterator.h index 701c267be..4a8a5a0bc 100644 --- a/gst/gstiterator.h +++ b/gst/gstiterator.h @@ -1,5 +1,6 @@ /* GStreamer * Copyright (C) 2004 Wim Taymans <wim@fluendo.com> + * Copyright (C) 2011 Sebastian Dröge <sebastian.droege@collabora.co.uk> * * gstiterator.h: Header for GstIterator * @@ -62,37 +63,38 @@ typedef enum { } GstIteratorItem; /** - * GstIteratorDisposeFunction: - * @owner: the owner of the iterator + * GstIteratorCopyFunction: + * @it: The original iterator + * @copy: The copied iterator * - * The function that will be called when a #GList iterator is freed. The - * owner of the #GList iterator can then clean up its resources. + * This function will be called when creating a copy of @it and should + * create a copy of all custom iterator fields or increase their + * reference counts. */ -typedef void (*GstIteratorDisposeFunction) (gpointer owner); +typedef void (*GstIteratorCopyFunction) (const GstIterator *it, GstIterator *copy); /** - * GstIteratorNextFunction: + * GstIteratorItemFunction: * @it: the iterator - * @result: a pointer to hold the next item + * @item: the item being retrieved. * - * The function that will be called when the next element of the iterator - * should be retrieved. + * The function that will be called after the next item of the iterator + * has been retrieved. This function can be used to skip items or stop + * the iterator. * - * Implementors of a #GstIterator should implement this - * function and pass it to the constructor of the custom iterator. * The function will be called with the iterator lock held. * * Returns: the result of the operation. */ -typedef GstIteratorResult (*GstIteratorNextFunction) (GstIterator *it, gpointer *result); +typedef GstIteratorItem (*GstIteratorItemFunction) (GstIterator *it, const GValue * item); + /** - * GstIteratorItemFunction: + * GstIteratorNextFunction: * @it: the iterator - * @item: the item being retrieved. + * @result: a pointer to hold the next item * - * The function that will be called after the next item of the iterator - * has been retrieved. This function will typically increase the refcount - * of the item or make a copy. + * The function that will be called when the next element of the iterator + * should be retrieved. * * Implementors of a #GstIterator should implement this * function and pass it to the constructor of the custom iterator. @@ -100,7 +102,7 @@ typedef GstIteratorResult (*GstIteratorNextFunction) (GstIterator *it, gpointer * * Returns: the result of the operation. */ -typedef GstIteratorItem (*GstIteratorItemFunction) (GstIterator *it, gpointer item); +typedef GstIteratorResult (*GstIteratorNextFunction) (GstIterator *it, GValue *result); /** * GstIteratorResyncFunction: * @it: the iterator @@ -128,6 +130,15 @@ typedef void (*GstIteratorResyncFunction) (GstIterator *it); typedef void (*GstIteratorFreeFunction) (GstIterator *it); /** + * GstIteratorForeachFunction: + * @item: The item + * @user_data: User data + * + * A function that is called by gst_iterator_foreach() for every element. + */ +typedef void (*GstIteratorForeachFunction) (const GValue * item, gpointer user_data); + +/** * GstIteratorFoldFunction: * @item: the item to fold * @ret: a #GValue collecting the result @@ -137,20 +148,7 @@ typedef void (*GstIteratorFreeFunction) (GstIterator *it); * * Returns: TRUE if the fold should continue, FALSE if it should stop. */ -typedef gboolean (*GstIteratorFoldFunction) (gpointer item, GValue *ret, gpointer user_data); - -/** - * GstCopyFunction: - * @object: The object to copy - * - * A function to create a copy of some object or - * increase its reference count. - * - * Returns: a copy of the object or the same object with increased reference count - * - * Since: 0.10.25 - */ -typedef gpointer (*GstCopyFunction) (gpointer object); +typedef gboolean (*GstIteratorFoldFunction) (const GValue * item, GValue * ret, gpointer user_data); /** * GST_ITERATOR: @@ -206,6 +204,7 @@ typedef gpointer (*GstCopyFunction) (gpointer object); */ struct _GstIterator { /*< protected >*/ + GstIteratorCopyFunction copy; GstIteratorNextFunction next; GstIteratorItemFunction item; GstIteratorResyncFunction resync; @@ -221,7 +220,7 @@ struct _GstIterator { guint size; /*< private >*/ - gpointer _gst_reserved[GST_PADDING-1]; + gpointer _gst_reserved[GST_PADDING]; }; GType gst_iterator_get_type (void); @@ -231,26 +230,26 @@ GstIterator* gst_iterator_new (guint size, GType type, GMutex *lock, guint32 *master_cookie, + GstIteratorCopyFunction copy, GstIteratorNextFunction next, - GstIteratorItemFunction item, + GstIteratorItemFunction item, GstIteratorResyncFunction resync, GstIteratorFreeFunction free); -GstIterator* gst_iterator_new_list (GType type, +GstIterator* gst_iterator_new_list (GType type, GMutex *lock, guint32 *master_cookie, GList **list, - gpointer owner, - GstIteratorItemFunction item, - GstIteratorDisposeFunction free); + GObject * owner, + GstIteratorItemFunction item); GstIterator* gst_iterator_new_single (GType type, - gpointer object, - GstCopyFunction copy, - GFreeFunc free); + const GValue * object); + +GstIterator* gst_iterator_copy (const GstIterator *it); /* using iterators */ -GstIteratorResult gst_iterator_next (GstIterator *it, gpointer *elem); +GstIteratorResult gst_iterator_next (GstIterator *it, GValue * elem); void gst_iterator_resync (GstIterator *it); void gst_iterator_free (GstIterator *it); @@ -258,14 +257,14 @@ void gst_iterator_push (GstIterator *it, GstIterator *other); /* higher-order functions that operate on iterators */ GstIterator* gst_iterator_filter (GstIterator *it, GCompareFunc func, - gpointer user_data); + const GValue * user_data); GstIteratorResult gst_iterator_fold (GstIterator *it, GstIteratorFoldFunction func, GValue *ret, gpointer user_data); GstIteratorResult gst_iterator_foreach (GstIterator *it, - GFunc func, gpointer user_data); -gpointer gst_iterator_find_custom (GstIterator *it, GCompareFunc func, - gpointer user_data); + GstIteratorForeachFunction func, gpointer user_data); +gboolean gst_iterator_find_custom (GstIterator *it, GCompareFunc func, + GValue *elem, gpointer user_data); G_END_DECLS |