gstreamer_core/gst/gstiterator.c
branchRCL_3
changeset 30 7e817e7e631c
parent 29 567bb019e3e3
equal deleted inserted replaced
29:567bb019e3e3 30:7e817e7e631c
    28  * A GstIterator is used to retrieve multiple objects from another object in
    28  * A GstIterator is used to retrieve multiple objects from another object in
    29  * a threadsafe way.
    29  * a threadsafe way.
    30  *
    30  *
    31  * Various GStreamer objects provide access to their internal structures using
    31  * Various GStreamer objects provide access to their internal structures using
    32  * an iterator.
    32  * an iterator.
    33  *
       
    34  * In general, whenever calling a GstIterator function results in your code
       
    35  * receiving a refcounted object, the refcount for that object will have been
       
    36  * increased.  Your code is responsible for unrefing that object after use.
       
    37  *
    33  *
    38  * The basic use pattern of an iterator is as follows:
    34  * The basic use pattern of an iterator is as follows:
    39  *
    35  *
    40  * <example>
    36  * <example>
    41  * <title>Using an iterator</title>
    37  * <title>Using an iterator</title>
    51  *        case GST_ITERATOR_RESYNC:
    47  *        case GST_ITERATOR_RESYNC:
    52  *          ...rollback changes to items...
    48  *          ...rollback changes to items...
    53  *          gst_iterator_resync (it);
    49  *          gst_iterator_resync (it);
    54  *          break;
    50  *          break;
    55  *        case GST_ITERATOR_ERROR:
    51  *        case GST_ITERATOR_ERROR:
    56  *          ...wrong parameters were given...
    52  *          ...wrong parameter were given...
    57  *          done = TRUE;
    53  *          done = TRUE;
    58  *          break;
    54  *          break;
    59  *        case GST_ITERATOR_DONE:
    55  *        case GST_ITERATOR_DONE:
    60  *          done = TRUE;
    56  *          done = TRUE;
    61  *          break;
    57  *          break;
    63  *    }
    59  *    }
    64  *    gst_iterator_free (it);
    60  *    gst_iterator_free (it);
    65  *   </programlisting>
    61  *   </programlisting>
    66  * </example>
    62  * </example>
    67  *
    63  *
    68  * Last reviewed on 2009-06-16 (0.10.24)
    64  * Last reviewed on 2005-11-09 (0.9.4)
    69  */
    65  */
    70 
    66 
    71 #include "gst_private.h"
    67 #include "gst_private.h"
    72 #include <gst/gstiterator.h>
    68 #include <gst/gstiterator.h>
    73 
    69 
    98 /**
    94 /**
    99  * gst_iterator_new:
    95  * gst_iterator_new:
   100  * @size: the size of the iterator structure
    96  * @size: the size of the iterator structure
   101  * @type: #GType of children
    97  * @type: #GType of children
   102  * @lock: pointer to a #GMutex.
    98  * @lock: pointer to a #GMutex.
   103  * @master_cookie: pointer to a guint32 that is changed when the items in the
    99  * @master_cookie: pointer to a guint32 to protect the iterated object.
   104  *    iterator changed.
       
   105  * @next: function to get next item
   100  * @next: function to get next item
   106  * @item: function to call on each item retrieved
   101  * @item: function to call on each item retrieved
   107  * @resync: function to resync the iterator
   102  * @resync: function to resync the iterator
   108  * @free: function to free the iterator
   103  * @free: function to free the iterator
   109  *
   104  *
   153 {
   148 {
   154   GstIterator iterator;
   149   GstIterator iterator;
   155   gpointer owner;
   150   gpointer owner;
   156   GList **orig;
   151   GList **orig;
   157   GList *list;                  /* pointer in list */
   152   GList *list;                  /* pointer in list */
       
   153   GType *type;
   158   GstIteratorDisposeFunction freefunc;
   154   GstIteratorDisposeFunction freefunc;
   159 } GstListIterator;
   155 } GstListIterator;
   160 
   156 
   161 static GstIteratorResult
   157 static GstIteratorResult
   162 gst_list_iterator_next (GstListIterator * it, gpointer * elem)
   158 gst_list_iterator_next (GstListIterator * it, gpointer * elem)
   187 
   183 
   188 /**
   184 /**
   189  * gst_iterator_new_list:
   185  * gst_iterator_new_list:
   190  * @type: #GType of elements
   186  * @type: #GType of elements
   191  * @lock: pointer to a #GMutex protecting the list.
   187  * @lock: pointer to a #GMutex protecting the list.
   192  * @master_cookie: pointer to a guint32 that is incremented when the list
   188  * @master_cookie: pointer to a guint32 to protect the list.
   193  *     is changed.
       
   194  * @list: pointer to the list
   189  * @list: pointer to the list
   195  * @owner: object owning the list
   190  * @owner: object owning the list
   196  * @item: function to call for each item
   191  * @item: function to call for each item
   197  * @free: function to call when the iterator is freed
   192  * @free: function to call when the iterator is freed
   198  *
   193  *
   199  * Create a new iterator designed for iterating @list.
   194  * Create a new iterator designed for iterating @list.
   200  *
       
   201  * The list you iterate is usually part of a data structure @owner and is
       
   202  * protected with @lock. 
       
   203  *
       
   204  * The iterator will use @lock to retrieve the next item of the list and it
       
   205  * will then call the @item function before releasing @lock again.
       
   206  *
       
   207  * The @item function usualy makes sure that the item remains alive while
       
   208  * @lock is released and the application is using the item. The application is
       
   209  * responsible for freeing/
       
   210 #ifdef __SYMBIAN32__
       
   211 EXPORT_C
       
   212 #endif
       
   213 unreffing the item after usage as explained in
       
   214  * gst_iterator_next().
       
   215  *
       
   216  * When a concurrent update to the list is performed, usually by @owner while
       
   217  * holding @lock, @master_cookie will be updated. The iterator implementation
       
   218  * will notice the update of the cookie and will return %GST_ITERATOR_RESYNC to
       
   219  * the user of the iterator in the next call to gst_iterator_next().
       
   220  *
       
   221  * @owner will be passed to the @free function when the iterator is freed.
       
   222  *
   195  *
   223  * Returns: the new #GstIterator for @list.
   196  * Returns: the new #GstIterator for @list.
   224  *
   197  *
   225  * MT safe.
   198  * MT safe.
   226  */
   199  */
   268 /**
   241 /**
   269  * gst_iterator_next:
   242  * gst_iterator_next:
   270  * @it: The #GstIterator to iterate
   243  * @it: The #GstIterator to iterate
   271  * @elem: pointer to hold next element
   244  * @elem: pointer to hold next element
   272  *
   245  *
   273  * Get the next item from the iterator in @elem. 
   246  * Get the next item from the iterator. For iterators that return
   274  *
   247  * refcounted objects, the returned object will have its refcount
   275  * Only when this function returns %GST_ITERATOR_OK, @elem will contain a valid
   248  * increased and should therefore be unreffed after usage.
   276  * value. For iterators that return refcounted objects, the returned object
   249  *
   277  * will have its refcount increased and should therefore be unreffed after
   250  * Returns: The result of the iteration. Unref after usage if this is
   278  * usage.
   251  * a refcounted object.
   279  *
       
   280  * When this function returns %GST_ITERATOR_DONE, no more elements can be
       
   281  * retrieved from @it.
       
   282  *
       
   283  * A return value of %GST_ITERATOR_RESYNC indicates that the element list was
       
   284  * concurrently updated. The user of @it should call gst_iterator_resync() to
       
   285  * get the newly updated list. 
       
   286  *
       
   287  * A return value of %GST_ITERATOR_ERROR indicates an unrecoverable fatal error.
       
   288  *
       
   289  * Returns: The result of the iteration. Unref @elem after usage if this
       
   290  * is a refcounted object.
       
   291  *
   252  *
   292  * MT safe.
   253  * MT safe.
   293  */
   254  */
   294 #ifdef __SYMBIAN32__
   255 #ifdef __SYMBIAN32__
   295 EXPORT_C
   256 EXPORT_C
   353  * @it: The #GstIterator to resync
   314  * @it: The #GstIterator to resync
   354  *
   315  *
   355  * Resync the iterator. this function is mostly called
   316  * Resync the iterator. this function is mostly called
   356  * after gst_iterator_next() returned %GST_ITERATOR_RESYNC.
   317  * after gst_iterator_next() returned %GST_ITERATOR_RESYNC.
   357  *
   318  *
   358  * When an iterator was pushed on @it, it will automatically be popped again
       
   359  * with this function.
       
   360  *
       
   361  * MT safe.
   319  * MT safe.
   362  */
   320  */
   363 #ifdef __SYMBIAN32__
   321 #ifdef __SYMBIAN32__
   364 EXPORT_C
   322 EXPORT_C
   365 #endif
   323 #endif
   405  * gst_iterator_push:
   363  * gst_iterator_push:
   406  * @it: The #GstIterator to use
   364  * @it: The #GstIterator to use
   407  * @other: The #GstIterator to push
   365  * @other: The #GstIterator to push
   408  *
   366  *
   409  * Pushes @other iterator onto @it. All calls performed on @it are
   367  * Pushes @other iterator onto @it. All calls performed on @it are
   410  * forwarded to @other. If @other returns %GST_ITERATOR_DONE, it is
   368  * forwarded tot @other. If @other returns #GST_ITERATOR_DONE, it is
   411  * popped again and calls are handled by @it again.
   369  * popped again and calls are handled by @it again.
   412  *
   370  *
   413  * This function is mainly used by objects implementing the iterator
   371  * This function is mainly used by objects implementing the iterator
   414  * next function to recurse into substructures.
   372  * next function to recurse into substructures.
   415  *
       
   416  * When gst_iterator_resync() is called on @it, @other will automatically be
       
   417  * popped.
       
   418  *
   373  *
   419  * MT safe.
   374  * MT safe.
   420  */
   375  */
   421 #ifdef __SYMBIAN32__
   376 #ifdef __SYMBIAN32__
   422 EXPORT_C
   377 EXPORT_C
   543  * @it: The #GstIterator to fold over
   498  * @it: The #GstIterator to fold over
   544  * @func: the fold function
   499  * @func: the fold function
   545  * @ret: the seed value passed to the fold function
   500  * @ret: the seed value passed to the fold function
   546  * @user_data: user data passed to the fold function
   501  * @user_data: user data passed to the fold function
   547  *
   502  *
   548  * Folds @func over the elements of @iter. That is to say, @func will be called
   503  * Folds @func over the elements of @iter. That is to say, @proc will be called
   549  * as @func (object, @ret, @user_data) for each object in @it. The normal use
   504  * as @proc (object, @ret, @user_data) for each object in @iter. The normal use
   550  * of this procedure is to accumulate the results of operating on the objects in
   505  * of this procedure is to accumulate the results of operating on the objects in
   551  * @ret.  If object is a refcounted object its refcount will be increased 
   506  * @ret.
   552  * before @func is called, and it should be unrefed after use in @func.
   507  *
   553  *
   508  * This procedure can be used (and is used internally) to implement the foreach
   554  * This procedure can be used (and is used internally) to implement the
   509  * and find_custom operations.
   555  * gst_iterator_foreach() and gst_iterator_find_custom() operations.
       
   556  *
   510  *
   557  * The fold will proceed as long as @func returns TRUE. When the iterator has no
   511  * The fold will proceed as long as @func returns TRUE. When the iterator has no
   558  * more arguments, %GST_ITERATOR_DONE will be returned. If @func returns FALSE,
   512  * more arguments, #GST_ITERATOR_DONE will be returned. If @func returns FALSE,
   559  * the fold will stop, and %GST_ITERATOR_OK will be returned. Errors or resyncs
   513  * the fold will stop, and #GST_ITERATOR_OK will be returned. Errors or resyncs
   560  * will cause fold to return %GST_ITERATOR_ERROR or %GST_ITERATOR_RESYNC as
   514  * will cause fold to return #GST_ITERATOR_ERROR or #GST_ITERATOR_RESYNC as
   561  * appropriate.
   515  * appropriate.
   562  *
   516  *
   563  * The iterator will not be freed.
   517  * The iterator will not be freed.
   564  *
   518  *
   565  * Returns: A #GstIteratorResult, as described above.
   519  * Returns: A #GstIteratorResult, as described above.
   616  * @it: The #GstIterator to iterate
   570  * @it: The #GstIterator to iterate
   617  * @func: the function to call for each element.
   571  * @func: the function to call for each element.
   618  * @user_data: user data passed to the function
   572  * @user_data: user data passed to the function
   619  *
   573  *
   620  * Iterate over all element of @it and call the given function @func for
   574  * Iterate over all element of @it and call the given function @func for
   621  * each element.  As in gst_iterator_fold(), the refcount of a refcounted 
   575  * each element.
   622  * object will be increased before @func is called, and should be unrefed
       
   623  * after use.
       
   624  *
   576  *
   625  * Returns: the result call to gst_iterator_fold(). The iterator will not be
   577  * Returns: the result call to gst_iterator_fold(). The iterator will not be
   626  * freed.
   578  * freed.
   627  *
   579  *
   628  * MT safe.
   580  * MT safe.
   665  * @it: The #GstIterator to iterate
   617  * @it: The #GstIterator to iterate
   666  * @func: the compare function to use
   618  * @func: the compare function to use
   667  * @user_data: user data passed to the compare function
   619  * @user_data: user data passed to the compare function
   668  *
   620  *
   669  * Find the first element in @it that matches the compare function @func.
   621  * Find the first element in @it that matches the compare function @func.
   670  * @func should return 0 when the element is found.  As in gst_iterator_fold(),
   622  * @func should return 0 when the element is found.
   671  * the refcount of a refcounted object will be increased before @func is 
       
   672  * called, and should be unrefed after use.
       
   673  *
   623  *
   674  * The iterator will not be freed.
   624  * The iterator will not be freed.
   675  *
   625  *
   676  * This function will return NULL if an error or resync happened to
   626  * This function will return NULL if an error or resync happened to
   677  * the iterator.
   627  * the iterator.