[vlc-devel] Re: CVS Commit (sam)

Samuel Hocevar sam at zoy.org
Wed Oct 16 22:00:09 CEST 2002

On Wed, Oct 16, 2002, cvs at videolan.org wrote:
>   * ./include/variables.h, ./src/misc/variables.c: implemented variable
>     callbacks.

   A few words about this. It's functional, but has severe limitations
for the moment, due to reentrancy issues. My advice until this is solved
is: do not call any var_* functions from a callback! And do not try to
acquire a mutex that may be waiting for a var_* function termination.

   Here is some sample code:

static int MyCallback( vlc_object_t *p_object, char const *psz_var,
                       vlc_value_t oldval, vlc_value_t newval, void *p_data )
    printf( "triggered! object=%p name=%s old=%i new=%i data=%p\n",
            p_object, psz_var, oldval.i_int, newval.i_int, p_data );

    return VLC_SUCCESS;

1. at some place an object does this (I used VLC_VAR_INTEGER as an example
   but it can be any other type):

    var_Create( p_object1, "glop", VLC_VAR_INTEGER );

2. at some other place we do this:

    var_AddCallback( p_object1, "glop", MyCallback, p_data );

    p_data can be any pointer; usually it's p_object2 (or whatever
   the object registering the callback is called). don't forget to
   call var_DelCallback with the same arguments to remove it when
   it is not needed anymore.

3. at some other place someone does this, which triggers the callback:

    vlc_value_t val;
    val.i_int = 12;
    var_Set( p_object1, "glop", val );

Have fun,
This is the vlc-devel mailing-list, see http://www.videolan.org/vlc/
To unsubscribe, please read http://www.videolan.org/lists.html
If you are in trouble, please contact <postmaster at videolan.org>

More information about the vlc-devel mailing list