Blame gst/gstiterator.h

Packit Service 963350
/* GStreamer
Packit Service 963350
 * Copyright (C) 2004 Wim Taymans <wim@fluendo.com>
Packit Service 963350
 * Copyright (C) 2011 Sebastian Dröge <sebastian.droege@collabora.co.uk>
Packit Service 963350
 *
Packit Service 963350
 * gstiterator.h: Header for GstIterator
Packit Service 963350
 *
Packit Service 963350
 * This library is free software; you can redistribute it and/or
Packit Service 963350
 * modify it under the terms of the GNU Library General Public
Packit Service 963350
 * License as published by the Free Software Foundation; either
Packit Service 963350
 * version 2 of the License, or (at your option) any later version.
Packit Service 963350
 *
Packit Service 963350
 * This library is distributed in the hope that it will be useful,
Packit Service 963350
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service 963350
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit Service 963350
 * Library General Public License for more details.
Packit Service 963350
 *
Packit Service 963350
 * You should have received a copy of the GNU Library General Public
Packit Service 963350
 * License along with this library; if not, write to the
Packit Service 963350
 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
Packit Service 963350
 * Boston, MA 02110-1301, USA.
Packit Service 963350
 */
Packit Service 963350
Packit Service 963350
#ifndef __GST_ITERATOR_H__
Packit Service 963350
#define __GST_ITERATOR_H__
Packit Service 963350
Packit Service 963350
#include <glib-object.h> /* for GValue in the fold */
Packit Service 963350
#include <gst/gstconfig.h>
Packit Service 963350
Packit Service 963350
G_BEGIN_DECLS
Packit Service 963350
Packit Service 963350
#define GST_TYPE_ITERATOR (gst_iterator_get_type ())
Packit Service 963350
Packit Service 963350
/**
Packit Service 963350
 * GstIteratorResult:
Packit Service 963350
 * @GST_ITERATOR_DONE:   No more items in the iterator
Packit Service 963350
 * @GST_ITERATOR_OK:     An item was retrieved
Packit Service 963350
 * @GST_ITERATOR_RESYNC: Datastructure changed while iterating
Packit Service 963350
 * @GST_ITERATOR_ERROR:  An error happened
Packit Service 963350
 *
Packit Service 963350
 * The result of gst_iterator_next().
Packit Service 963350
 */
Packit Service 963350
typedef enum {
Packit Service 963350
  GST_ITERATOR_DONE     = 0,
Packit Service 963350
  GST_ITERATOR_OK       = 1,
Packit Service 963350
  GST_ITERATOR_RESYNC   = 2,
Packit Service 963350
  GST_ITERATOR_ERROR    = 3
Packit Service 963350
} GstIteratorResult;
Packit Service 963350
Packit Service 963350
typedef struct _GstIterator GstIterator;
Packit Service 963350
Packit Service 963350
/**
Packit Service 963350
 * GstIteratorItem:
Packit Service 963350
 * @GST_ITERATOR_ITEM_SKIP:  Skip this item
Packit Service 963350
 * @GST_ITERATOR_ITEM_PASS:  Return item
Packit Service 963350
 * @GST_ITERATOR_ITEM_END:   Stop after this item.
Packit Service 963350
 *
Packit Service 963350
 * The result of a #GstIteratorItemFunction.
Packit Service 963350
 */
Packit Service 963350
typedef enum {
Packit Service 963350
  GST_ITERATOR_ITEM_SKIP        = 0,
Packit Service 963350
  GST_ITERATOR_ITEM_PASS        = 1,
Packit Service 963350
  GST_ITERATOR_ITEM_END         = 2
Packit Service 963350
} GstIteratorItem;
Packit Service 963350
Packit Service 963350
/**
Packit Service 963350
 * GstIteratorCopyFunction:
Packit Service 963350
 * @it: The original iterator
Packit Service 963350
 * @copy: The copied iterator
Packit Service 963350
 *
Packit Service 963350
 * This function will be called when creating a copy of @it and should
Packit Service 963350
 * create a copy of all custom iterator fields or increase their
Packit Service 963350
 * reference counts.
Packit Service 963350
 */
Packit Service 963350
typedef void              (*GstIteratorCopyFunction) (const GstIterator *it, GstIterator *copy);
Packit Service 963350
Packit Service 963350
/**
Packit Service 963350
 * GstIteratorItemFunction:
Packit Service 963350
 * @it: the iterator
Packit Service 963350
 * @item: the item being retrieved.
Packit Service 963350
 *
Packit Service 963350
 * The function that will be called after the next item of the iterator
Packit Service 963350
 * has been retrieved. This function can be used to skip items or stop
Packit Service 963350
 * the iterator.
Packit Service 963350
 *
Packit Service 963350
 * The function will be called with the iterator lock held.
Packit Service 963350
 *
Packit Service 963350
 * Returns: the result of the operation.
Packit Service 963350
 */
Packit Service 963350
typedef GstIteratorItem   (*GstIteratorItemFunction)    (GstIterator *it, const GValue * item);
Packit Service 963350
Packit Service 963350
/**
Packit Service 963350
 * GstIteratorNextFunction:
Packit Service 963350
 * @it: the iterator
Packit Service 963350
 * @result: a pointer to hold the next item
Packit Service 963350
 *
Packit Service 963350
 * The function that will be called when the next element of the iterator
Packit Service 963350
 * should be retrieved.
Packit Service 963350
 *
Packit Service 963350
 * Implementors of a #GstIterator should implement this
Packit Service 963350
 * function and pass it to the constructor of the custom iterator.
Packit Service 963350
 * The function will be called with the iterator lock held.
Packit Service 963350
 *
Packit Service 963350
 * Returns: the result of the operation.
Packit Service 963350
 */
Packit Service 963350
typedef GstIteratorResult (*GstIteratorNextFunction)    (GstIterator *it, GValue *result);
Packit Service 963350
/**
Packit Service 963350
 * GstIteratorResyncFunction:
Packit Service 963350
 * @it: the iterator
Packit Service 963350
 *
Packit Service 963350
 * This function will be called whenever a concurrent update happened
Packit Service 963350
 * to the iterated datastructure. The implementor of the iterator should
Packit Service 963350
 * restart the iterator from the beginning and clean up any state it might
Packit Service 963350
 * have.
Packit Service 963350
 *
Packit Service 963350
 * Implementors of a #GstIterator should implement this
Packit Service 963350
 * function and pass it to the constructor of the custom iterator.
Packit Service 963350
 * The function will be called with the iterator lock held.
Packit Service 963350
 */
Packit Service 963350
typedef void              (*GstIteratorResyncFunction)  (GstIterator *it);
Packit Service 963350
/**
Packit Service 963350
 * GstIteratorFreeFunction:
Packit Service 963350
 * @it: the iterator
Packit Service 963350
 *
Packit Service 963350
 * This function will be called when the iterator is freed.
Packit Service 963350
 *
Packit Service 963350
 * Implementors of a #GstIterator should implement this
Packit Service 963350
 * function and pass it to the constructor of the custom iterator.
Packit Service 963350
 * The function will be called with the iterator lock held.
Packit Service 963350
 */
Packit Service 963350
typedef void              (*GstIteratorFreeFunction)    (GstIterator *it);
Packit Service 963350
Packit Service 963350
/**
Packit Service 963350
 * GstIteratorForeachFunction:
Packit Service 963350
 * @item: The item
Packit Service 963350
 * @user_data: User data
Packit Service 963350
 *
Packit Service 963350
 * A function that is called by gst_iterator_foreach() for every element.
Packit Service 963350
 */
Packit Service 963350
typedef void         (*GstIteratorForeachFunction)     (const GValue * item, gpointer user_data);
Packit Service 963350
Packit Service 963350
/**
Packit Service 963350
 * GstIteratorFoldFunction:
Packit Service 963350
 * @item: the item to fold
Packit Service 963350
 * @ret: a #GValue collecting the result
Packit Service 963350
 * @user_data: data passed to gst_iterator_fold()
Packit Service 963350
 *
Packit Service 963350
 * A function to be passed to gst_iterator_fold().
Packit Service 963350
 *
Packit Service 963350
 * Returns: %TRUE if the fold should continue, %FALSE if it should stop.
Packit Service 963350
 */
Packit Service 963350
typedef gboolean          (*GstIteratorFoldFunction)    (const GValue * item, GValue * ret, gpointer user_data);
Packit Service 963350
Packit Service 963350
/**
Packit Service 963350
 * GST_ITERATOR:
Packit Service 963350
 * @it: the #GstIterator value
Packit Service 963350
 *
Packit Service 963350
 * Macro to cast to a #GstIterator
Packit Service 963350
 */
Packit Service 963350
#define GST_ITERATOR(it)                ((GstIterator*)(it))
Packit Service 963350
/**
Packit Service 963350
 * GST_ITERATOR_LOCK:
Packit Service 963350
 * @it: the #GstIterator to get the lock of
Packit Service 963350
 *
Packit Service 963350
 * Macro to get the lock protecting the datastructure being iterated.
Packit Service 963350
 */
Packit Service 963350
#define GST_ITERATOR_LOCK(it)           (GST_ITERATOR(it)->lock)
Packit Service 963350
/**
Packit Service 963350
 * GST_ITERATOR_COOKIE:
Packit Service 963350
 * @it: the #GstIterator to get the cookie of
Packit Service 963350
 *
Packit Service 963350
 * Macro to get the cookie of a #GstIterator. The cookie of the
Packit Service 963350
 * iterator is the value of the master cookie when the iterator
Packit Service 963350
 * was created.
Packit Service 963350
 * Whenever the iterator is iterated, the value is compared to the
Packit Service 963350
 * value of the master cookie. If they are different, a concurrent
Packit Service 963350
 * modification happened to the iterator and a resync is needed.
Packit Service 963350
 */
Packit Service 963350
#define GST_ITERATOR_COOKIE(it)         (GST_ITERATOR(it)->cookie)
Packit Service 963350
/**
Packit Service 963350
 * GST_ITERATOR_ORIG_COOKIE:
Packit Service 963350
 * @it: the #GstIterator to get the master cookie of
Packit Service 963350
 *
Packit Service 963350
 * Macro to get a pointer to where the master cookie is stored. The
Packit Service 963350
 * master cookie protects the structure being iterated and gets updated
Packit Service 963350
 * whenever the datastructure changes.
Packit Service 963350
 */
Packit Service 963350
#define GST_ITERATOR_ORIG_COOKIE(it)    (GST_ITERATOR(it)->master_cookie)
Packit Service 963350
Packit Service 963350
/**
Packit Service 963350
 * GstIterator:
Packit Service 963350
 * @copy: The function to copy the iterator
Packit Service 963350
 * @next: The function to get the next item in the iterator
Packit Service 963350
 * @item: The function to be called for each item retrieved
Packit Service 963350
 * @resync: The function to call when a resync is needed.
Packit Service 963350
 * @free: The function to call when the iterator is freed
Packit Service 963350
 * @pushed: The iterator that is currently pushed with gst_iterator_push()
Packit Service 963350
 * @type: The type of the object that this iterator will return
Packit Service 963350
 * @lock: The lock protecting the data structure and the cookie.
Packit Service 963350
 * @cookie: The cookie; the value of the master_cookie when this iterator was
Packit Service 963350
 *          created.
Packit Service 963350
 * @master_cookie: A pointer to the master cookie.
Packit Service 963350
 * @size: the size of the iterator
Packit Service 963350
 *
Packit Service 963350
 * #GstIterator base structure. The values of this structure are
Packit Service 963350
 * protected for subclasses, use the methods to use the #GstIterator.
Packit Service 963350
 */
Packit Service 963350
struct _GstIterator {
Packit Service 963350
  /*< protected >*/
Packit Service 963350
  GstIteratorCopyFunction copy;
Packit Service 963350
  GstIteratorNextFunction next;
Packit Service 963350
  GstIteratorItemFunction item;
Packit Service 963350
  GstIteratorResyncFunction resync;
Packit Service 963350
  GstIteratorFreeFunction free;
Packit Service 963350
Packit Service 963350
  GstIterator *pushed;          /* pushed iterator */
Packit Service 963350
Packit Service 963350
  GType     type;
Packit Service 963350
  GMutex   *lock;
Packit Service 963350
  guint32   cookie;             /* cookie of the iterator */
Packit Service 963350
  guint32  *master_cookie;      /* pointer to guint32 holding the cookie when this
Packit Service 963350
                                   iterator was created */
Packit Service 963350
  guint     size;
Packit Service 963350
Packit Service 963350
  /*< private >*/
Packit Service 963350
  gpointer _gst_reserved[GST_PADDING];
Packit Service 963350
};
Packit Service 963350
Packit Service 963350
GST_API
Packit Service 963350
GType                   gst_iterator_get_type           (void);
Packit Service 963350
Packit Service 963350
/* creating iterators */
Packit Service 963350
Packit Service 963350
GST_API
Packit Service 963350
GstIterator*            gst_iterator_new                (guint size,
Packit Service 963350
                                                         GType type,
Packit Service 963350
                                                         GMutex *lock,
Packit Service 963350
                                                         guint32 *master_cookie,
Packit Service 963350
                                                         GstIteratorCopyFunction copy,
Packit Service 963350
                                                         GstIteratorNextFunction next,
Packit Service 963350
                                                         GstIteratorItemFunction item,
Packit Service 963350
                                                         GstIteratorResyncFunction resync,
Packit Service 963350
                                                         GstIteratorFreeFunction free) G_GNUC_MALLOC;
Packit Service 963350
GST_API
Packit Service 963350
GstIterator*            gst_iterator_new_list           (GType type,
Packit Service 963350
                                                         GMutex *lock,
Packit Service 963350
                                                         guint32 *master_cookie,
Packit Service 963350
                                                         GList **list,
Packit Service 963350
                                                         GObject * owner,
Packit Service 963350
                                                         GstIteratorItemFunction item) G_GNUC_MALLOC;
Packit Service 963350
GST_API
Packit Service 963350
GstIterator*            gst_iterator_new_single         (GType type,
Packit Service 963350
                                                         const GValue * object) G_GNUC_MALLOC;
Packit Service 963350
GST_API
Packit Service 963350
GstIterator*            gst_iterator_copy               (const GstIterator *it) G_GNUC_MALLOC;
Packit Service 963350
Packit Service 963350
/* using iterators */
Packit Service 963350
Packit Service 963350
GST_API
Packit Service 963350
GstIteratorResult       gst_iterator_next               (GstIterator *it, GValue * elem);
Packit Service 963350
Packit Service 963350
GST_API
Packit Service 963350
void                    gst_iterator_resync             (GstIterator *it);
Packit Service 963350
Packit Service 963350
GST_API
Packit Service 963350
void                    gst_iterator_free               (GstIterator *it);
Packit Service 963350
Packit Service 963350
GST_API
Packit Service 963350
void                    gst_iterator_push               (GstIterator *it, GstIterator *other);
Packit Service 963350
Packit Service 963350
/* higher-order functions that operate on iterators */
Packit Service 963350
Packit Service 963350
GST_API
Packit Service 963350
GstIterator*            gst_iterator_filter             (GstIterator *it, GCompareFunc func,
Packit Service 963350
                                                         const GValue * user_data) G_GNUC_MALLOC;
Packit Service 963350
GST_API
Packit Service 963350
GstIteratorResult       gst_iterator_fold               (GstIterator *it,
Packit Service 963350
                                                         GstIteratorFoldFunction func,
Packit Service 963350
                                                         GValue *ret, gpointer user_data);
Packit Service 963350
GST_API
Packit Service 963350
GstIteratorResult       gst_iterator_foreach            (GstIterator *it,
Packit Service 963350
                                                         GstIteratorForeachFunction func, gpointer user_data);
Packit Service 963350
GST_API
Packit Service 963350
gboolean                gst_iterator_find_custom        (GstIterator *it, GCompareFunc func,
Packit Service 963350
                                                         GValue *elem, gpointer user_data);
Packit Service 963350
Packit Service 963350
#ifdef G_DEFINE_AUTOPTR_CLEANUP_FUNC
Packit Service 963350
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GstIterator, gst_iterator_free)
Packit Service 963350
#endif
Packit Service 963350
Packit Service 963350
G_END_DECLS
Packit Service 963350
Packit Service 963350
#endif /* __GST_ITERATOR_H__ */